]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/Controller/SugarController.php
Release 6.4.1
[Github/sugarcrm.git] / include / MVC / Controller / SugarController.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 require_once('include/MVC/View/SugarView.php');
38
39 /**
40  * Main SugarCRM controller
41  * @api
42  */
43 class SugarController{
44         /**
45          * remap actions in here
46          * e.g. make all detail views go to edit views
47          * $action_remap = array('detailview'=>'editview');
48          */
49         protected $action_remap = array('index'=>'listview');
50         /**
51          * The name of the current module.
52          */
53         public $module = 'Home';
54         /**
55          * The name of the target module.
56          */
57         public $target_module = null;
58         /**
59          * The name of the current action.
60          */
61         public $action = 'index';
62         /**
63          * The id of the current record.
64          */
65         public $record = '';
66         /**
67          * The name of the return module.
68          */
69         public $return_module = null;
70         /**
71          * The name of the return action.
72          */
73         public $return_action = null;
74         /**
75          * The id of the return record.
76          */
77         public $return_id = null;
78         /**
79          * If the action was remapped it will be set to do_action and then we will just
80          * use do_action for the actual action to perform.
81          */
82         protected $do_action = 'index';
83         /**
84          * If a bean is present that set it.
85          */
86         public $bean = null;
87         /**
88          * url to redirect to
89          */
90         public $redirect_url = '';
91         /**
92          * any subcontroller can modify this to change the view
93          */
94         public $view = 'classic';
95         /**
96          * this array will hold the mappings between a key and an object for use within the view.
97          */
98         public $view_object_map = array();
99
100         /**
101          * This array holds the methods that handleAction() will invoke, in sequence.
102          */
103         protected $tasks = array(
104                                            'pre_action',
105                                            'do_action',
106                                            'post_action'
107                                            );
108         /**
109          * List of options to run through within the process() method.
110          * This list is meant to easily allow additions for new functionality as well as
111          * the ability to add a controller's own handling.
112          */
113         public $process_tasks = array(
114                                                 'blockFileAccess',
115                                                 'handleEntryPoint',
116                                                 'callLegacyCode',
117                                                 'remapAction',
118                                                 'handle_action',
119                                                 'handleActionMaps',
120                                         );
121         /**
122          * Whether or not the action has been handled by $process_tasks
123          *
124          * @var bool
125          */
126         protected $_processed = false;
127         /**
128          * Map an action directly to a file
129          */
130         /**
131          * Map an action directly to a file. This will be loaded from action_file_map.php
132          */
133         protected $action_file_map = array();
134         /**
135          * Map an action directly to a view
136          */
137         /**
138          * Map an action directly to a view. This will be loaded from action_view_map.php
139          */
140         protected $action_view_map = array();
141
142         /**
143          * This can be set from the application to tell us whether we have authorization to
144          * process the action. If this is set we will default to the noaccess view.
145          */
146         public $hasAccess = true;
147
148         /**
149          * Map case sensitive filenames to action.  This is used for linux/unix systems
150          * where filenames are case sensitive
151          */
152         public static $action_case_file = array(
153                                                                                 'editview'=>'EditView',
154                                                                                 'detailview'=>'DetailView',
155                                                                                 'listview'=>'ListView'
156                                                                           );
157
158         /**
159          * Constructor. This ie meant tot load up the module, action, record as well
160          * as the mapping arrays.
161          */
162         function SugarController(){
163         }
164
165         /**
166          * Called from SugarApplication and is meant to perform the setup operations
167          * on the controller.
168          *
169          */
170         public function setup($module = ''){
171                 if(empty($module) && !empty($_REQUEST['module']))
172                         $module = $_REQUEST['module'];
173                 //set the module
174                 if(!empty($module))
175                         $this->setModule($module);
176
177                 if(!empty($_REQUEST['target_module']) && $_REQUEST['target_module'] != 'undefined') {
178                         $this->target_module = $_REQUEST['target_module'];
179                 }
180                 //set properties on the controller from the $_REQUEST
181                 $this->loadPropertiesFromRequest();
182                 //load the mapping files
183                 $this->loadMappings();
184         }
185         /**
186          * Set the module on the Controller
187          *
188          * @param object $module
189          */
190         public function setModule($module){
191                 $this->module = $module;
192         }
193
194         /**
195          * Set properties on the Controller from the $_REQUEST
196          *
197          */
198         private function loadPropertiesFromRequest(){
199                 if(!empty($_REQUEST['action']))
200                         $this->action = $_REQUEST['action'];
201                 if(!empty($_REQUEST['record']))
202                         $this->record = $_REQUEST['record'];
203                 if(!empty($_REQUEST['view']))
204                         $this->view = $_REQUEST['view'];
205                 if(!empty($_REQUEST['return_module']))
206                         $this->return_module = $_REQUEST['return_module'];
207                 if(!empty($_REQUEST['return_action']))
208                         $this->return_action = $_REQUEST['return_action'];
209                 if(!empty($_REQUEST['return_id']))
210                         $this->return_id = $_REQUEST['return_id'];
211         }
212
213         /**
214          * Load map files for use within the Controller
215          *
216          */
217         private function loadMappings(){
218                 $this->loadMapping('action_view_map');
219                 $this->loadMapping('action_file_map');
220                 $this->loadMapping('action_remap', true);
221         }
222
223         /**
224          * Given a record id load the bean. This bean is accessible from any sub controllers.
225          */
226         public function loadBean()
227         {
228                 if(!empty($GLOBALS['beanList'][$this->module])){
229                         $class = $GLOBALS['beanList'][$this->module];
230                         if(!empty($GLOBALS['beanFiles'][$class])){
231                                 require_once($GLOBALS['beanFiles'][$class]);
232                                 $this->bean = new $class();
233                                 if(!empty($this->record)){
234                                         $this->bean->retrieve($this->record);
235                                         if($this->bean)
236                                                 $GLOBALS['FOCUS'] = $this->bean;
237                                 }
238                         }
239                 }
240         }
241
242         /**
243          * Generic load method to load mapping arrays.
244          */
245         private function loadMapping($var, $merge = false){
246                 $$var = sugar_cache_retrieve("CONTROLLER_". $var . "_".$this->module);
247                 if(!$$var){
248                         if($merge && !empty($this->$var)){
249                                 $$var = $this->$var;
250                         }else{
251                                 $$var = array();
252                         }
253                         if(file_exists('include/MVC/Controller/'. $var . '.php')){
254                                 require('include/MVC/Controller/'. $var . '.php');
255                         }
256                         if(file_exists('modules/'.$this->module.'/'. $var . '.php')){
257                                 require('modules/'.$this->module.'/'. $var . '.php');
258                         }
259                         if(file_exists('custom/modules/'.$this->module.'/'. $var . '.php')){
260                                 require('custom/modules/'.$this->module.'/'. $var . '.php');
261                         }
262                         if(file_exists('custom/include/MVC/Controller/'. $var . '.php')){
263                                 require('custom/include/MVC/Controller/'. $var . '.php');
264                         }
265
266             // entry_point_registry -> EntryPointRegistry
267
268                         $varname = str_replace(" ","",ucwords(str_replace("_"," ", $var)));
269             if(file_exists("custom/application/Ext/$varname/$var.ext.php")){
270                                 require("custom/application/Ext/$varname/$var.ext.php");
271                 }
272                         if(file_exists("custom/modules/{$this->module}/Ext/$varname/$var.ext.php")){
273                                 require("custom/modules/{$this->module}/Ext/$varname/$var.ext.php");
274                         }
275
276                         sugar_cache_put("CONTROLLER_". $var . "_".$this->module, $$var);
277                 }
278                 $this->$var = $$var;
279         }
280
281         /**
282          * This method is called from SugarApplication->execute and it will bootstrap the entire controller process
283          */
284         final public function execute(){
285                 $this->process();
286                 if(!empty($this->view)){
287                         $this->processView();
288                 }elseif(!empty($this->redirect_url)){
289                         $this->redirect();
290                 }
291         }
292
293         /**
294          * Display the appropriate view.
295          */
296         private function processView(){
297                 if(!isset($this->view_object_map['remap_action']) && isset($this->action_view_map[strtolower($this->action)]))
298                 {
299                   $this->view_object_map['remap_action'] = $this->action_view_map[strtolower($this->action)];
300                 }
301                 $view = ViewFactory::loadView($this->view, $this->module, $this->bean, $this->view_object_map, $this->target_module);
302                 $GLOBALS['current_view'] = $view;
303                 if(!empty($this->bean) && !$this->bean->ACLAccess($view->type) && $view->type != 'list'){
304                         ACLController::displayNoAccess(true);
305                         sugar_cleanup(true);
306                 }
307                 if(isset($this->errors)){
308                   $view->errors = $this->errors;
309                 }
310                 $view->process();
311         }
312
313         /**
314          * Meant to be overridden by a subclass and allows for specific functionality to be
315          * injected prior to the process() method being called.
316          */
317         public function preProcess()
318         {}
319
320         /**
321          * if we have a function to support the action use it otherwise use the default action
322          *
323          * 1) check for file
324          * 2) check for action
325          */
326         public function process(){
327                 $GLOBALS['action'] = $this->action;
328                 $GLOBALS['module'] = $this->module;
329
330                 //check to ensure we have access to the module.
331                 if($this->hasAccess){
332                         $this->do_action = $this->action;
333
334                         $file = self::getActionFilename($this->do_action);
335
336                         $this->loadBean();
337
338                         $processed = false;
339                         foreach($this->process_tasks as $process){
340                                 $this->$process();
341                                 if($this->_processed)
342                                         break;
343                         }
344
345                         $this->redirect();
346                 }else{
347                         $this->no_access();
348                 }
349         }
350
351         /**
352          * This method is called from the process method. I could also be called within an action_* method.
353          * It allows a developer to override any one of these methods contained within,
354          * or if the developer so chooses they can override the entire action_* method.
355          *
356          * @return true if any one of the pre_, do_, or post_ methods have been defined,
357          * false otherwise.  This is important b/c if none of these methods exists, then we will run the
358          * action_default() method.
359          */
360         protected function handle_action(){
361                 $processed = false;
362                 foreach($this->tasks as $task){
363                         $processed = ($this->$task() || $processed);
364                 }
365                 $this->_processed = $processed;
366         }
367
368         /**
369          * Perform an action prior to the specified action.
370          * This can be overridde in a sub-class
371          */
372         private function pre_action(){
373                 $function = 'pre_' . $this->action;
374                 if($this->hasFunction($function)){
375                         $GLOBALS['log']->debug('Performing pre_action');
376                         $this->$function();
377                         return true;
378                 }
379                 return false;
380         }
381
382         /**
383          * Perform the specified action.
384          * This can be overridde in a sub-class
385          */
386         private function do_action(){
387                 $function =  'action_'. strtolower($this->do_action);
388                 if($this->hasFunction($function)){
389                         $GLOBALS['log']->debug('Performing action: '.$function.' MODULE: '.$this->module);
390                         $this->$function();
391                         return true;
392                 }
393                 return false;
394         }
395
396         /**
397          * Perform an action after to the specified action has occurred.
398          * This can be overridde in a sub-class
399          */
400         private function post_action(){
401                 $function = 'post_' . $this->action;
402                 if($this->hasFunction($function)){
403                         $GLOBALS['log']->debug('Performing post_action');
404                         $this->$function();
405                         return true;
406                 }
407                 return false;
408         }
409
410         /**
411          * If there is no action found then display an error to the user.
412          */
413         protected function no_action(){
414                 sugar_die($GLOBALS['app_strings']['LBL_NO_ACTION']);
415         }
416
417         /**
418          * The default action handler for instances where we do not have access to process.
419          */
420         protected function no_access(){
421                 $this->view = 'noaccess';
422         }
423
424         ///////////////////////////////////////////////
425         /////// HELPER FUNCTIONS
426         ///////////////////////////////////////////////
427
428         /**
429          * Determine if a given function exists on the objects
430          * @param function - the function to check
431          * @return true if the method exists on the object, false otherwise
432          */
433         protected function hasFunction($function){
434                 return method_exists($this, $function);
435         }
436
437
438         /**
439          * Set the url to which we will want to redirect
440          *
441          * @param string url - the url to which we will want to redirect
442          */
443         protected function set_redirect($url){
444                 $this->redirect_url = $url;
445         }
446
447         /**
448          * Perform redirection based on the redirect_url
449          *
450          */
451         protected function redirect(){
452
453                 if(!empty($this->redirect_url))
454                         SugarApplication::redirect($this->redirect_url);
455         }
456
457         ////////////////////////////////////////////////////////
458         ////// DEFAULT ACTIONS
459         ///////////////////////////////////////////////////////
460
461         /*
462          * Save a bean
463          */
464
465         /**
466          * Do some processing before saving the bean to the database.
467          */
468         public function pre_save(){
469                 if(!empty($_POST['assigned_user_id']) && $_POST['assigned_user_id'] != $this->bean->assigned_user_id && $_POST['assigned_user_id'] != $GLOBALS['current_user']->id && empty($GLOBALS['sugar_config']['exclude_notifications'][$this->bean->module_dir])){
470                         $this->bean->notify_on_save = true;
471                 }
472                 $GLOBALS['log']->debug("SugarController:: performing pre_save.");
473         require_once('include/SugarFields/SugarFieldHandler.php');
474         $sfh = new SugarFieldHandler();
475                 foreach($this->bean->field_defs as $field => $properties) {
476                         $type = !empty($properties['custom_type']) ? $properties['custom_type'] : $properties['type'];
477                     $sf = $sfh->getSugarField(ucfirst($type), true);
478                         if(isset($_POST[$field])) {
479                                 if(is_array($_POST[$field]) && !empty($properties['isMultiSelect'])) {
480                                         if(empty($_POST[$field][0])) {
481                                                 unset($_POST[$field][0]);
482                                         }
483                                         $_POST[$field] = encodeMultienumValue($_POST[$field]);
484                                 }
485                                 $this->bean->$field = $_POST[$field];
486                         } else if(!empty($properties['isMultiSelect']) && !isset($_POST[$field]) && isset($_POST[$field . '_multiselect'])) {
487                                 $this->bean->$field = '';
488                         }
489             if($sf != null){
490                 $sf->save($this->bean, $_POST, $field, $properties);
491             }
492                 }
493
494                 foreach($this->bean->relationship_fields as $field=>$link){
495                         if(!empty($_POST[$field])){
496                                 $this->bean->$field = $_POST[$field];
497                         }
498                 }
499                 if(!$this->bean->ACLAccess('save')){
500                         ACLController::displayNoAccess(true);
501                         sugar_cleanup(true);
502                 }
503                 $this->bean->unformat_all_fields();
504         }
505
506         /**
507          * Perform the actual save
508          */
509         public function action_save(){
510                 $this->bean->save(!empty($this->bean->notify_on_save));
511         }
512
513         /**
514          * Specify what happens after the save has occurred.
515          */
516         protected function post_save(){
517                 $module = (!empty($this->return_module) ? $this->return_module : $this->module);
518                 $action = (!empty($this->return_action) ? $this->return_action : 'DetailView');
519                 $id = (!empty($this->return_id) ? $this->return_id : $this->bean->id);
520
521                 $url = "index.php?module=".$module."&action=".$action."&record=".$id;
522                 $this->set_redirect($url);
523         }
524
525         /*
526          * Delete a bean
527          */
528
529         /**
530          * Perform the actual deletion.
531          */
532         protected function action_delete(){
533                 //do any pre delete processing
534                 //if there is some custom logic for deletion.
535                 if(!empty($_REQUEST['record'])){
536                         if(!$this->bean->ACLAccess('Delete')){
537                                 ACLController::displayNoAccess(true);
538                                 sugar_cleanup(true);
539                         }
540                         $this->bean->mark_deleted($_REQUEST['record']);
541                 }else{
542                         sugar_die("A record number must be specified to delete");
543                 }
544         }
545
546         /**
547          * Specify what happens after the deletion has occurred.
548          */
549         protected function post_delete(){
550                 $return_module = isset($_REQUEST['return_module']) ?
551                         $_REQUEST['return_module'] :
552                         $GLOBALS['sugar_config']['default_module'];
553                 $return_action = isset($_REQUEST['return_action']) ?
554                         $_REQUEST['return_action'] :
555                         $GLOBALS['sugar_config']['default_action'];
556                 $return_id = isset($_REQUEST['return_id']) ?
557                         $_REQUEST['return_id'] :
558                         '';
559                 $url = "index.php?module=".$return_module."&action=".$return_action."&record=".$return_id;
560
561                 //eggsurplus Bug 23816: maintain VCR after an edit/save. If it is a duplicate then don't worry about it. The offset is now worthless.
562                 if(isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) {
563                     $url .= "&offset=".$_REQUEST['offset'];
564                 }
565
566                 $this->set_redirect($url);
567         }
568         /**
569          * Perform the actual massupdate.
570          */
571         protected function action_massupdate(){
572                 if(!empty($_REQUEST['massupdate']) && $_REQUEST['massupdate'] == 'true' && (!empty($_REQUEST['uid']) || !empty($_REQUEST['entire']))){
573                         if(!empty($_REQUEST['Delete']) && $_REQUEST['Delete']=='true' && !$this->bean->ACLAccess('delete')
574                 || (empty($_REQUEST['Delete']) || $_REQUEST['Delete']!='true') && !$this->bean->ACLAccess('save')){
575                                 ACLController::displayNoAccess(true);
576                                 sugar_cleanup(true);
577                         }
578
579             set_time_limit(0);//I'm wondering if we will set it never goes timeout here.
580             // until we have more efficient way of handling MU, we have to disable the limit
581             $GLOBALS['db']->setQueryLimit(0);
582             require_once("include/MassUpdate.php");
583             require_once('modules/MySettings/StoreQuery.php');
584             $seed = loadBean($_REQUEST['module']);
585             $mass = new MassUpdate();
586             $mass->setSugarBean($seed);
587             if(isset($_REQUEST['entire']) && empty($_POST['mass'])) {
588                 $mass->generateSearchWhere($_REQUEST['module'], $_REQUEST['current_query_by_page']);
589             }
590             $mass->handleMassUpdate();
591             $storeQuery = new StoreQuery();//restore the current search. to solve bug 24722 for multi tabs massupdate.
592             $temp_req = array('current_query_by_page' => $_REQUEST['current_query_by_page'], 'return_module' => $_REQUEST['return_module'], 'return_action' => $_REQUEST['return_action']);
593             if($_REQUEST['return_module'] == 'Emails') {
594                 if(!empty($_REQUEST['type']) && !empty($_REQUEST['ie_assigned_user_id'])) {
595                     $this->req_for_email = array('type' => $_REQUEST['type'], 'ie_assigned_user_id' => $_REQUEST['ie_assigned_user_id']); //specificly for My Achieves
596                 }
597             }
598             $_REQUEST = array();
599             $_REQUEST = unserialize(base64_decode($temp_req['current_query_by_page']));
600             unset($_REQUEST[$seed->module_dir.'2_'.strtoupper($seed->object_name).'_offset']);//after massupdate, the page should redirect to no offset page
601             $storeQuery->saveFromRequest($_REQUEST['module']);
602             $_REQUEST = array('return_module' => $temp_req['return_module'], 'return_action' => $temp_req['return_action']);//for post_massupdate, to go back to original page.
603                 }else{
604                         sugar_die("You must massupdate at least one record");
605                 }
606         }
607         /**
608          * Specify what happens after the massupdate has occurred.
609          */
610         protected function post_massupdate(){
611                 $return_module = isset($_REQUEST['return_module']) ?
612                         $_REQUEST['return_module'] :
613                         $GLOBALS['sugar_config']['default_module'];
614                 $return_action = isset($_REQUEST['return_action']) ?
615                         $_REQUEST['return_action'] :
616                         $GLOBALS['sugar_config']['default_action'];
617                 $url = "index.php?module=".$return_module."&action=".$return_action;
618                 if($return_module == 'Emails'){//specificly for My Achieves
619                         if(!empty($this->req_for_email['type']) && !empty($this->req_for_email['ie_assigned_user_id'])) {
620                                 $url = $url . "&type=".$this->req_for_email['type']."&assigned_user_id=".$this->req_for_email['ie_assigned_user_id'];
621                         }
622                 }
623                 $this->set_redirect($url);
624         }
625         /**
626          * Perform the listview action
627          */
628         protected function action_listview(){
629                 $this->view_object_map['bean'] = $this->bean;
630                 $this->view = 'list';
631         }
632
633 /*
634
635         //THIS IS HANDLED IN ACTION_REMAP WHERE INDEX IS SET TO LISTVIEW
636         function action_index(){
637         }
638 */
639
640         /**
641          * Action to handle when using a file as was done in previous versions of Sugar.
642          */
643         protected function action_default(){
644                 $this->view = 'classic';
645         }
646
647         /**
648          * this method id used within a Dashlet when performing an ajax call
649          */
650         protected function action_callmethoddashlet(){
651                 if(!empty($_REQUEST['id'])) {
652                     $id = $_REQUEST['id'];
653                     $requestedMethod = $_REQUEST['method'];
654                     $dashletDefs = $GLOBALS['current_user']->getPreference('dashlets', 'Home'); // load user's dashlets config
655                     if(!empty($dashletDefs[$id])) {
656                         require_once($dashletDefs[$id]['fileLocation']);
657
658                         $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
659
660                         if(method_exists($dashlet, $requestedMethod) || method_exists($dashlet, '__call')) {
661                             echo $dashlet->$requestedMethod();
662                         }
663                         else {
664                             echo 'no method';
665                         }
666                     }
667                 }
668         }
669
670         /**
671          * this method is used within a Dashlet when the options configuration is posted
672          */
673         protected function action_configuredashlet(){
674                 global $current_user, $mod_strings;
675
676                 if(!empty($_REQUEST['id'])) {
677                     $id = $_REQUEST['id'];
678                     $dashletDefs = $current_user->getPreference('dashlets', $_REQUEST['module']); // load user's dashlets config
679                     require_once($dashletDefs[$id]['fileLocation']);
680
681                     $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
682                     if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
683                         $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
684                         $current_user->setPreference('dashlets', $dashletDefs, 0, $_REQUEST['module']);
685                     }
686                     else { // display options
687                         $json = getJSONobj();
688                         return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $mod_strings['LBL_OPTIONS'],
689                                                                  'body'  => $dashlet->displayOptions())));
690
691                     }
692                 }
693                 else {
694                     return '0';
695                 }
696         }
697
698         /**
699          * getActionFilename
700          */
701         public static function getActionFilename($action) {
702            if(isset(self::$action_case_file[$action])) {
703                   return self::$action_case_file[$action];
704            }
705            return $action;
706         }
707
708         /********************************************************************/
709         //                              PROCESS TASKS
710         /********************************************************************/
711
712         /**
713          * Given the module and action, determine whether the super/admin has prevented access
714          * to this url. In addition if any links specified for this module, load the links into
715          * GLOBALS
716          *
717          * @return true if we want to stop processing, false if processing should continue
718          */
719         private function blockFileAccess(){
720                 //check if the we have enabled file_access_control and if so then check the mappings on the request;
721                 if(!empty($GLOBALS['sugar_config']['admin_access_control']) && $GLOBALS['sugar_config']['admin_access_control']){
722                         $this->loadMapping('file_access_control_map');
723                         //since we have this turned on, check the mapping file
724                         $module = strtolower($this->module);
725                         $action = strtolower($this->do_action);
726                         if(!empty($this->file_access_control_map['modules'][$module]['links'])){
727                                 $GLOBALS['admin_access_control_links'] = $this->file_access_control_map['modules'][$module]['links'];
728                         }
729
730                         if(!empty($this->file_access_control_map['modules'][$module]['actions']) && (in_array($action, $this->file_access_control_map['modules'][$module]['actions']) || !empty($this->file_access_control_map['modules'][$module]['actions'][$action]))){
731                                 //check params
732                                 if(!empty($this->file_access_control_map['modules'][$module]['actions'][$action]['params'])){
733                                         $block = true;
734                                         $params = $this->file_access_control_map['modules'][$module]['actions'][$action]['params'];
735                                         foreach($params as $param => $paramVals){
736                                                 if(!empty($_REQUEST[$param])){
737                                                         if(!in_array($_REQUEST[$param], $paramVals)){
738                                                                 $block = false;
739                                                                 break;
740                                                         }
741                                                 }
742                                         }
743                                         if($block){
744                                                 $this->_processed = true;
745                                                 $this->no_access();
746                                         }
747                                 }else{
748                                         $this->_processed = true;
749                                         $this->no_access();
750                                 }
751                         }
752                 }else
753                         $this->_processed = false;
754         }
755
756         /**
757          * This code is part of the entry points reworking. We have consolidated all
758          * entry points to go through index.php. Now in order to bring up an entry point
759          * it will follow the format:
760          * 'index.php?entryPoint=download'
761          * the download entry point is mapped in the following file: entry_point_registry.php
762          *
763          */
764         private function handleEntryPoint(){
765                 if(!empty($_REQUEST['entryPoint'])){
766                         $this->loadMapping('entry_point_registry');
767                         $entryPoint = $_REQUEST['entryPoint'];
768
769                         if(!empty($this->entry_point_registry[$entryPoint])){
770                                 require_once($this->entry_point_registry[$entryPoint]['file']);
771                                 $this->_processed = true;
772                                 $this->view = '';
773                         }
774                 }
775         }
776
777     /**
778      * Checks to see if the requested entry point requires auth
779      *
780      * @param  $entrypoint string name of the entrypoint
781      * @return bool true if auth is required, false if not
782      */
783     public function checkEntryPointRequiresAuth($entryPoint)
784     {
785         $this->loadMapping('entry_point_registry');
786
787         if ( isset($this->entry_point_registry[$entryPoint]['auth'])
788                 && !$this->entry_point_registry[$entryPoint]['auth'] )
789             return false;
790         return true;
791     }
792
793         /**
794          * Meant to handle old views e.g. DetailView.php.
795          *
796          */
797         protected function callLegacyCode()
798         {
799                 $file = self::getActionFilename($this->do_action);
800                 if ( isset($this->action_view_map[strtolower($this->do_action)]) ) {
801                 $action = $this->action_view_map[strtolower($this->do_action)];
802             }
803             else {
804                 $action = $this->do_action;
805             }
806             // index actions actually maps to the view.list.php view
807             if ( $action == 'index' ) {
808                 $action = 'list';
809             }
810
811                 if ((file_exists('modules/' . $this->module . '/'. $file . '.php')
812                 && !file_exists('modules/' . $this->module . '/views/view.'. $action . '.php'))
813             || (file_exists('custom/modules/' . $this->module . '/'. $file . '.php')
814                 && !file_exists('custom/modules/' . $this->module . '/views/view.'. $action . '.php'))
815             ) {
816                         // A 'classic' module, using the old pre-MVC display files
817                         // We should now discard the bean we just obtained for tracking as the pre-MVC module will instantiate its own
818                         unset($GLOBALS['FOCUS']);
819                         $GLOBALS['log']->debug('Module:' . $this->module . ' using file: '. $file);
820                         $this->action_default();
821                         $this->_processed = true;
822                 }
823         }
824
825         /**
826          * If the action has been remapped to a different action as defined in
827          * action_file_map.php or action_view_map.php load those maps here.
828          *
829          */
830         private function handleActionMaps(){
831                 if(!empty($this->action_file_map[strtolower($this->do_action)])){
832                         $this->view = '';
833                         $GLOBALS['log']->debug('Using Action File Map:' . $this->action_file_map[strtolower($this->do_action)]);
834                         require_once($this->action_file_map[strtolower($this->do_action)]);
835                         $this->_processed = true;
836                 }elseif(!empty($this->action_view_map[strtolower($this->do_action)])){
837                         $GLOBALS['log']->debug('Using Action View Map:' . $this->action_view_map[strtolower($this->do_action)]);
838                         $this->view = $this->action_view_map[strtolower($this->do_action)];
839                         $this->_processed = true;
840                 }else
841                         $this->no_action();
842         }
843
844         /**
845          * Actually remap the action if required.
846          *
847          */
848         protected function remapAction(){
849                 if(!empty($this->action_remap[$this->do_action])){
850                         $this->action = $this->action_remap[$this->do_action];
851                         $this->do_action = $this->action;
852                 }
853         }
854
855 }
856 ?>