sugarcontroller.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 780 行 · 第 1/2 页
PHP
780 行
protected function no_access(){ $this->view = 'noaccess'; } /////////////////////////////////////////////// /////// HELPER FUNCTIONS /////////////////////////////////////////////// /** * Determine if a given function exists on the objects * @param function - the function to check * @return true if the method exists on the object, false otherwise */ protected function hasFunction($function){ return method_exists($this, $function); } /** * Set the url to which we will want to redirect * * @param string url - the url to which we will want to redirect */ protected function set_redirect($url){ $this->redirect_url = $url; } /** * Perform redirection based on the redirect_url * */ protected function redirect(){ if(!empty($this->redirect_url)) SugarApplication::redirect($this->redirect_url); } //////////////////////////////////////////////////////// ////// DEFAULT ACTIONS /////////////////////////////////////////////////////// /* * Save a bean */ /** * Do some processing before saving the bean to the database. */ public function pre_save(){ 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])){ $this->bean->notify_on_save = true; } $GLOBALS['log']->debug("SugarController:: performing pre_save."); foreach($this->bean->field_defs as $field => $properties) { if(isset($_POST[$field])) { if(is_array($_POST[$field]) && !empty($properties['isMultiSelect'])) { if(empty($_POST[$field][0])) { unset($_POST[$field][0]); } if(!empty($_POST[$field][0])) { $_POST[$field] = implode('^,^', $_POST[$field]); } else { continue; } } $this->bean->$field = $_POST[$field]; }else if(!empty($properties['type']) && $properties['type'] == 'link'){ //remove this relationship since we did not find it in the $_POST } } foreach($this->bean->relationship_fields as $field=>$link){ if(!empty($_POST[$field])){ $this->bean->$field = $_POST[$field]; } } if(!$this->bean->ACLAccess('save')){ ACLController::displayNoAccess(true); sugar_cleanup(true); } $this->bean->unformat_all_fields(); } /** * Perform the actual save */ public function action_save(){ $this->bean->save(!empty($this->bean->notify_on_save)); } /** * Specify what happens after the save has occurred. */ protected function post_save(){ $module = (!empty($this->return_module) ? $this->return_module : $this->module); $action = (!empty($this->return_action) ? $this->return_action : 'DetailView'); $id = (!empty($this->return_id) ? $this->return_id : $this->bean->id); $url = "index.php?module=".$module."&action=".$action."&record=".$id; $this->set_redirect($url); } /** * Save an Ajax form. * */ protected function action_ajaxformsave(){ $this->pre_save(); $this->bean->save(); $this->view = 'multiedit'; } /* * Delete a bean */ /** * Perform the actual deletion. */ protected function action_delete(){ //do any pre delete processing //if there is some custom logic for deletion. if(!empty($_REQUEST['record'])){ if(!$this->bean->ACLAccess('Delete')){ ACLController::displayNoAccess(true); sugar_cleanup(true); } $this->bean->mark_deleted($_REQUEST['record']); }else{ sugar_die("A record number must be specified to delete"); } } /** * Specify what happens after the deletion has occurred. */ protected function post_delete(){ $return_module = isset($_REQUEST['return_module']) ? $_REQUEST['return_module'] : $GLOBALS['sugar_config']['default_module']; $return_action = isset($_REQUEST['return_action']) ? $_REQUEST['return_action'] : $GLOBALS['sugar_config']['default_action']; $return_id = isset($_REQUEST['return_id']) ? $_REQUEST['return_id'] : ''; $url = "index.php?module=".$return_module."&action=".$return_action."&record=".$return_id; $this->set_redirect($url); } /** * Perform the listview action */ protected function action_listview(){ $this->view_object_map['bean'] = $this->bean; $this->view = 'list'; } /* //THIS IS HANDLED IN ACTION_REMAP WHERE INDEX IS SET TO LISTVIEW function action_index(){ }*/ /** * Action to handle when using a file as was done in previous versions of Sugar. */ protected function action_default(){ $this->view = 'classic'; } /** * this method id used within a Dashlet when performing an ajax call */ protected function action_callmethoddashlet(){ if(!empty($_REQUEST['id'])) { $id = $_REQUEST['id']; $requestedMethod = $_REQUEST['method']; $dashletDefs = $GLOBALS['current_user']->getPreference('dashlets', 'Home'); // load user's dashlets config if(!empty($dashletDefs[$id])) { require_once($dashletDefs[$id]['fileLocation']); $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array())); if(method_exists($dashlet, $requestedMethod) || method_exists($dashlet, '__call')) { echo $dashlet->$requestedMethod(); } else { echo 'no method'; } } } } /** * this method is used within a Dashlet when the options configuration is posted */ protected function action_configuredashlet(){ global $current_user, $mod_strings; if(!empty($_REQUEST['id'])) { $id = $_REQUEST['id']; $dashletDefs = $current_user->getPreference('dashlets', $_REQUEST['module']); // load user's dashlets config require_once($dashletDefs[$id]['fileLocation']); $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array())); if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST); $current_user->setPreference('dashlets', $dashletDefs, 0, $_REQUEST['module']); } else { // display options $json = getJSONobj(); return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $mod_strings['LBL_OPTIONS'], 'body' => $dashlet->displayOptions()))); } } else { return '0'; } } /** * getActionFilename */ public static function getActionFilename($action) { if(isset(self::$action_case_file[$action])) { return self::$action_case_file[$action]; } return $action; } /********************************************************************/ // PROCESS TASKS /********************************************************************/ /** * Given the module and action, determine whether the super/admin has prevented access * to this url. In addition if any links specified for this module, load the links into * GLOBALS * * @return true if we want to stop processing, false if processing should continue */ private function blockFileAccess(){ //check if the we have enabled file_access_control and if so then check the mappings on the request; if(!empty($GLOBALS['sugar_config']['admin_access_control']) && $GLOBALS['sugar_config']['admin_access_control']){ $this->loadMapping('file_access_control_map'); //since we have this turned on, check the mapping file $module = strtolower($this->module); $action = strtolower($this->do_action); if(!empty($this->file_access_control_map['modules'][$module]['links'])){ $GLOBALS['admin_access_control_links'] = $this->file_access_control_map['modules'][$module]['links']; } 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]))){ //check params if(!empty($this->file_access_control_map['modules'][$module]['actions'][$action]['params'])){ $block = true; $params = $this->file_access_control_map['modules'][$module]['actions'][$action]['params']; foreach($params as $param => $paramVals){ if(!empty($_REQUEST[$param])){ if(!in_array($_REQUEST[$param], $paramVals)){ $block = false; break; } } } if($block){ $this->_processed = true; $this->no_access(); } }else{ $this->_processed = true; $this->no_access(); } } }else $this->_processed = false; } /** * This code is part of the entry points reworking. We have consolidated all * entry points to go through index.php. Now in order to bring up an entry point * it will follow the format: * 'index.php?entryPoint=download' * the download entry point is mapped in the following file: entry_point_registry.php * */ private function handleEntryPoint(){ if(!empty($_REQUEST['entryPoint'])){ $this->loadMapping('entry_point_registry'); $entryPoint = $_REQUEST['entryPoint']; if(!empty($this->entry_point_registry[$entryPoint])){ require_once($this->entry_point_registry[$entryPoint]['file']); $this->_processed = true; $this->view = ''; } } } /** * Checks to see if the requested entry point requires auth * * @param $entrypoint string name of the entrypoint * @return bool true if auth is required, false if not */ public function checkEntryPointRequiresAuth($entryPoint) { $this->loadMapping('entry_point_registry'); if ( isset($this->entry_point_registry[$entryPoint]['auth']) && !$this->entry_point_registry[$entryPoint]['auth'] ) return false; return true; } /** * Meant to handle old views e.g. DetailView.php. * */ protected function callLegacyCode(){ $file = self::getActionFilename($this->do_action); if(file_exists('modules/' . $this->module . '/'. $file . '.php') || file_exists('custom/modules/' . $this->module . '/'. $file . '.php')){ // A 'classic' module, using the old pre-MVC display files // We should now discard the bean we just obtained for tracking as the pre-MVC module will instantiate its own unset($GLOBALS['FOCUS']); $GLOBALS['log']->debug('Module:' . $this->module . ' using file: '. $file); $this->action_default(); $this->_processed = true; } } /** * If the action has been remapped to a different action as defined in * action_file_map.php or action_view_map.php load those maps here. * */ private function handleActionMaps(){ if(!empty($this->action_file_map[strtolower($this->do_action)])){ $this->view = ''; $GLOBALS['log']->debug('Using Action File Map:' . $this->action_file_map[strtolower($this->do_action)]); require_once($this->action_file_map[strtolower($this->do_action)]); $this->_processed = true; }elseif(!empty($this->action_view_map[strtolower($this->do_action)])){ $GLOBALS['log']->debug('Using Action View Map:' . $this->action_view_map[strtolower($this->do_action)]); $this->view = $this->action_view_map[strtolower($this->do_action)]; $this->_processed = true; }else $this->no_action(); } /** * Actually remap the action if required. * */ protected function remapAction(){ if(!empty($this->action_remap[$this->do_action])){ $this->action = $this->action_remap[$this->do_action]; $this->do_action = $this->action; } } }?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?