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