2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require_once('modules/ACLActions/actiondefs.php');
39 require_once('modules/ACL/ACLJSController.php');
43 function checkAccess($category, $action, $is_owner=false, $type='module'){
46 if(is_admin($current_user))return true;
47 //calendar is a special case since it has 3 modules in it (calls, meetings, tasks)
49 if($category == 'Calendar'){
50 return ACLAction::userHasAccess($current_user->id, 'Calls', $action,$type, $is_owner) || ACLAction::userHasAccess($current_user->id, 'Meetings', $action,'module', $is_owner) || ACLAction::userHasAccess($current_user->id, 'Tasks', $action,'module', $is_owner);
52 if($category == 'Activities'){
53 return ACLAction::userHasAccess($current_user->id, 'Calls', $action,$type, $is_owner) || ACLAction::userHasAccess($current_user->id, 'Meetings', $action,'module', $is_owner) || ACLAction::userHasAccess($current_user->id, 'Tasks', $action,'module', $is_owner)|| ACLAction::userHasAccess($current_user->id, 'Emails', $action,'module', $is_owner)|| ACLAction::userHasAccess($current_user->id, 'Notes', $action,'module', $is_owner);
55 return ACLAction::userHasAccess($current_user->id, $category, $action,$type, $is_owner);
58 function requireOwner($category, $value, $type='module'){
60 if(is_admin($current_user))return false;
61 return ACLAction::userNeedsOwnership($current_user->id, $category, $value,$type);
64 function filterModuleList(&$moduleList, $by_value=true){
66 global $aclModuleList, $current_user;
67 if(is_admin($current_user)) return;
68 $actions = ACLAction::getUserActions($current_user->id, false);
72 foreach($moduleList as $key=>$value){
73 $compList[$value]= $key;
76 $compList =& $moduleList;
78 foreach($actions as $action_name=>$action){
80 if(!empty($action['module'])){
81 $aclModuleList[$action_name] = $action_name;
82 if(isset($compList[$action_name])){
83 if($action['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
85 unset($moduleList[$compList[$action_name]]);
87 unset($moduleList[$action_name]);
93 if(isset($compList['Calendar']) &&
94 !( ACLController::checkModuleAllowed('Calls', $actions) || ACLController::checkModuleAllowed('Meetings', $actions) || ACLController::checkModuleAllowed('Tasks', $actions)))
97 unset($moduleList[$compList['Calendar']]);
99 unset($moduleList['Calendar']);
101 if(isset($compList['Activities']) &&
102 !( ACLController::checkModuleAllowed('Notes', $actions) || ACLController::checkModuleAllowed('Notes', $actions))){
104 unset($moduleList[$compList['Activities']]);
106 unset($moduleList['Activities']);
114 * Check to see if the module is available for this user.
116 * @param String $module_name
117 * @return true if they are allowed. false otherwise.
119 function checkModuleAllowed($module_name, $actions)
121 if(!empty($actions[$module_name]['module']['access']['aclaccess']) &&
122 ACL_ALLOW_ENABLED == $actions[$module_name]['module']['access']['aclaccess'])
130 function disabledModuleList($moduleList, $by_value=true,$view='list'){
131 global $aclModuleList, $current_user;
132 if(is_admin($GLOBALS['current_user'])) return array();
133 $actions = ACLAction::getUserActions($current_user->id, false);
138 foreach($moduleList as $key=>$value){
139 $compList[$value]= $key;
142 $compList =& $moduleList;
144 if(isset($moduleList['ProductTemplates'])){
145 $moduleList['Products'] ='Products';
148 foreach($actions as $action_name=>$action){
150 if(!empty($action['module'])){
151 $aclModuleList[$action_name] = $action_name;
152 if(isset($compList[$action_name])){
153 if($action['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED || $action['module'][$view]['aclaccess'] < 0){
155 $disabled[$compList[$action_name]] =$compList[$action_name] ;
157 $disabled[$action_name] = $action_name;
163 if(isset($compList['Calendar']) && !( ACL_ALLOW_ENABLED == $actions['Calls']['module']['access']['aclaccess'] || ACL_ALLOW_ENABLED == $actions['Meetings']['module']['access']['aclaccess'] || ACL_ALLOW_ENABLED == $actions['Tasks']['module']['access']['aclaccess'])){
165 $disabled[$compList['Calendar']] = $compList['Calendar'];
167 $disabled['Calendar'] = 'Calendar';
169 if(isset($compList['Activities']) &&!( ACL_ALLOW_ENABLED == $actions['Notes']['module']['access']['aclaccess'] || ACL_ALLOW_ENABLED == $actions['Notes']['module']['access']['aclaccess'] )){
171 $disabled[$compList['Activities']] = $compList['Activities'];
173 $disabled['Activities'] = 'Activities';
177 if(isset($disabled['Products'])){
178 $disabled['ProductTemplates'] = 'ProductTemplates';
188 function addJavascript($category,$form_name='', $is_owner=false){
189 $jscontroller = new ACLJSController($category, $form_name, $is_owner);
190 echo $jscontroller->getJavascript();
193 function moduleSupportsACL($module){
194 static $checkModules = array();
195 global $beanFiles, $beanList;
196 if(isset($checkModules[$module])){
197 return $checkModules[$module];
199 if(!isset($beanList[$module])){
200 $checkModules[$module] = false;
203 $class = $beanList[$module];
204 require_once($beanFiles[$class]);
206 if(!is_subclass_of($mod, 'SugarBean')){
207 $checkModules[$module] = false;
209 $checkModules[$module] = $mod->bean_implements('ACL');
212 return $checkModules[$module] ;
216 function displayNoAccess($redirect_home = false){
217 echo '<script>function set_focus(){}</script><p class="error">' . translate('LBL_NO_ACCESS', 'ACL') . '</p>';
218 if($redirect_home)echo translate('LBL_REDIRECT_TO_HOME', 'ACL') . ' <span id="seconds_left">3</span> ' . translate('LBL_SECONDS', 'ACL') . '<script> function redirect_countdown(left){document.getElementById("seconds_left").innerHTML = left; if(left == 0){document.location.href = "index.php";}else{left--; setTimeout("redirect_countdown("+ left+")", 1000)}};setTimeout("redirect_countdown(3)", 1000)</script>';