]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ACL/ACLController.php
Release 6.1.4
[Github/sugarcrm.git] / modules / ACL / ACLController.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 require_once('modules/ACLActions/actiondefs.php');
39 require_once('modules/ACL/ACLJSController.php');
40 class ACLController {
41         
42         
43         function checkAccess($category, $action, $is_owner=false, $type='module'){
44                 
45                 global $current_user;
46                 if(is_admin($current_user))return true;
47                 //calendar is a special case since it has 3 modules in it (calls, meetings, tasks)
48                 
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);
51                 }
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);
54                 }
55                 return ACLAction::userHasAccess($current_user->id, $category, $action,$type, $is_owner);
56         }
57         
58         function requireOwner($category, $value, $type='module'){
59                         global $current_user;
60                         if(is_admin($current_user))return false;
61                         return ACLAction::userNeedsOwnership($current_user->id, $category, $value,$type);
62         }
63         
64         function filterModuleList(&$moduleList, $by_value=true){
65                 
66                 global $aclModuleList, $current_user;
67                 $actions = ACLAction::getUserActions($current_user->id, false);
68                 
69                 $compList = array();
70                 if($by_value){
71                         foreach($moduleList as $key=>$value){
72                                 $compList[$value]= $key;
73                         }
74                 }else{
75                         $compList =& $moduleList;
76                 }
77                 foreach($actions as $action_name=>$action){
78                         
79                         if(!empty($action['module'])){
80                                 $aclModuleList[$action_name] = $action_name;
81                                 if(isset($compList[$action_name])){
82                                         if($action['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
83                                                 if($by_value){
84                                                         unset($moduleList[$compList[$action_name]]);
85                                                 }else{
86                                                         unset($moduleList[$action_name]);
87                                                 }
88                                         }
89                                 }
90                         }
91                 }
92                 if(isset($compList['Calendar']) && 
93                         !( ACLController::checkModuleAllowed('Calls', $actions) || ACLController::checkModuleAllowed('Meetings', $actions) || ACLController::checkModuleAllowed('Tasks', $actions)))
94             {
95                         if($by_value){
96                                 unset($moduleList[$compList['Calendar']]);
97                         }else{
98                                 unset($moduleList['Calendar']);
99                         }
100                         if(isset($compList['Activities']) && 
101                                 !( ACLController::checkModuleAllowed('Notes', $actions) || ACLController::checkModuleAllowed('Notes', $actions))){
102                                 if($by_value){
103                                         unset($moduleList[$compList['Activities']]);
104                                 }else{
105                                         unset($moduleList['Activities']);
106                                 }
107                         }
108                 }
109                 
110         }
111         
112         /**
113          * Check to see if the module is available for this user.
114          *
115          * @param String $module_name
116          * @return true if they are allowed.  false otherwise.
117          */
118         function checkModuleAllowed($module_name, $actions)
119         {
120                 if(!empty($actions[$module_name]['module']['access']['aclaccess']) && 
121                         ACL_ALLOW_ENABLED == $actions[$module_name]['module']['access']['aclaccess'])
122                 {
123                         return true;
124                 }
125                 
126                 return false;
127         }
128         
129         function disabledModuleList($moduleList, $by_value=true,$view='list'){
130                 global $aclModuleList, $current_user;
131                 $actions = ACLAction::getUserActions($current_user->id, false);
132                 $disabled = array();
133                 $compList = array();
134
135                 if($by_value){
136                         foreach($moduleList as $key=>$value){
137                                 $compList[$value]= $key;
138                         }
139                 }else{
140                         $compList =& $moduleList;
141                 }
142                 if(isset($moduleList['ProductTemplates'])){
143                         $moduleList['Products'] ='Products';
144                 }
145                 
146                 foreach($actions as $action_name=>$action){
147                                         
148                         if(!empty($action['module'])){
149                                 $aclModuleList[$action_name] = $action_name;
150                                 if(isset($compList[$action_name])){
151                                         if($action['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED || $action['module'][$view]['aclaccess'] < 0){
152                                                 if($by_value){
153                                                         $disabled[$compList[$action_name]] =$compList[$action_name] ;
154                                                 }else{
155                                                         $disabled[$action_name] = $action_name;
156                                                 }
157                                         }
158                                 }
159                         }
160                 }
161                 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'])){
162                         if($by_value){
163                                                         $disabled[$compList['Calendar']]  = $compList['Calendar'];
164                         }else{
165                                                         $disabled['Calendar']  = 'Calendar';
166                         }
167                         if(isset($compList['Activities'])  &&!( ACL_ALLOW_ENABLED == $actions['Notes']['module']['access']['aclaccess'] || ACL_ALLOW_ENABLED == $actions['Notes']['module']['access']['aclaccess'] )){
168                                 if($by_value){
169                                                         $disabled[$compList['Activities']]  = $compList['Activities'];
170                                 }else{
171                                                         $disabled['Activities']  = 'Activities';
172                                 }
173                         }
174                 }
175                 if(isset($disabled['Products'])){
176                         $disabled['ProductTemplates'] = 'ProductTemplates';
177                 }
178                 
179                 
180                 return $disabled;
181                 
182         }
183         
184         
185         
186         function addJavascript($category,$form_name='', $is_owner=false){
187                 $jscontroller = new ACLJSController($category, $form_name, $is_owner);
188                 echo $jscontroller->getJavascript();
189         }
190         
191         function moduleSupportsACL($module){
192                 static $checkModules = array();
193                 global $beanFiles, $beanList;
194                 if(isset($checkModules[$module])){
195                         return $checkModules[$module];
196                 }
197                 if(!isset($beanList[$module])){
198                         $checkModules[$module] = false;
199                         
200                 }else{
201                         $class = $beanList[$module];
202                         require_once($beanFiles[$class]);
203                         $mod = new $class();
204                         if(!is_subclass_of($mod, 'SugarBean')){
205                                 $checkModules[$module] = false;
206                         }else{
207                                 $checkModules[$module] = $mod->bean_implements('ACL');
208                         }
209                 }
210                 return $checkModules[$module] ;
211
212         }
213         
214         function displayNoAccess($redirect_home = false){
215                 echo '<script>function set_focus(){}</script><p class="error">' . translate('LBL_NO_ACCESS', 'ACL') . '</p>';
216                 if($redirect_home)echo 'Redirect to Home in <span id="seconds_left">3</span> seconds<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>';
217         }
218         
219 }
220
221
222         
223         
224         
225
226
227
228
229 ?>