]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MySettings/TabController.php
Release 6.5.5
[Github/sugarcrm.git] / modules / MySettings / TabController.php
1 <?php
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.
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
39 class TabController{
40
41 var $required_modules = array('Home');
42
43     /**
44      * @var bool flag of validation of the cache
45      */
46     static protected $isCacheValid = false;
47
48 function is_system_tabs_in_db(){
49         
50         $administration = new Administration();
51         $administration->retrieveSettings('MySettings');
52         if(isset($administration->settings) && isset($administration->settings['MySettings_tab']))
53         {
54             return true;       
55         }
56         else
57         {
58             return false;
59         }
60 }
61
62 function get_system_tabs(){
63         global $moduleList;
64         
65         static $system_tabs_result = null;
66         
67         // if the value is not already cached, then retrieve it.
68     if (empty($system_tabs_result) || !self::$isCacheValid)
69         {
70                 
71                 $administration = new Administration();
72                 $administration->retrieveSettings('MySettings');
73                 if(isset($administration->settings) && isset($administration->settings['MySettings_tab'])){
74                         $tabs= $administration->settings['MySettings_tab'];
75                         $trimmed_tabs = trim($tabs);
76                         //make sure serialized string is not empty
77                         if (!empty($trimmed_tabs)){
78                                 $tabs = base64_decode($tabs);
79                                 $tabs = unserialize($tabs);
80                                 //Ensure modules saved in the prefences exist.
81                                 foreach($tabs as $id => $tab) {
82                                         if (!in_array($tab, $moduleList))
83                                                 unset($tabs[$id]);
84                                 }
85                                 ACLController :: filterModuleList($tabs); 
86                                 $tabs = $this->get_key_array($tabs);
87                                 $system_tabs_result = $tabs;
88                         }else{
89                                 $system_tabs_result = $this->get_key_array($moduleList);
90                         }
91                 }
92                 else
93                 {
94                         $system_tabs_result = $this->get_key_array($moduleList);
95                 }
96         self::$isCacheValid = true;
97         }
98                 
99         return $system_tabs_result;
100 }
101
102 function get_tabs_system(){
103         global $moduleList;
104         $tabs = $this->get_system_tabs();
105         $unsetTabs = $this->get_key_array($moduleList);
106         foreach($tabs as $tab){
107                 unset($unsetTabs[$tab]);
108         }
109         
110         $should_hide_iframes = !file_exists('modules/iFrames/iFrame.php');
111         if($should_hide_iframes) {
112            if(isset($unsetTabs['iFrames'])) {
113               unset($unsetTabs['iFrames']);
114            } else if(isset($tabs['iFrames'])) {
115                   unset($tabs['iFrames']);
116            }
117         } 
118
119         return array($tabs,$unsetTabs);
120 }
121
122
123
124
125 function set_system_tabs($tabs){
126     
127         $administration = new Administration();
128         $serialized = base64_encode(serialize($tabs));
129         $administration->saveSetting('MySettings', 'tab', $serialized);
130     self::$isCacheValid = false;
131 }
132
133 function get_users_can_edit(){
134         
135         $administration = new Administration();
136         $administration->retrieveSettings('MySettings');
137         if(isset($administration->settings) && isset($administration->settings['MySettings_disable_useredit'])){
138                 if($administration->settings['MySettings_disable_useredit'] == 'yes'){
139                         return false;
140                 }
141 }
142 return true;
143 }
144
145 function set_users_can_edit($boolean){
146         global $current_user;
147         if(is_admin($current_user)){
148                 
149                 $administration = new Administration();
150                 if($boolean){
151                         $administration->saveSetting('MySettings', 'disable_useredit', 'no');
152                 }else{
153                         $administration->saveSetting('MySettings', 'disable_useredit', 'yes');
154                 }
155         }
156 }
157
158
159 function get_key_array($arr){
160         $new = array();
161         if(!empty($arr)){
162         foreach($arr as $val){
163                 $new[$val] = $val;
164         }
165         }
166         return $new;
167 }
168
169 function set_user_tabs($tabs, &$user, $type='display'){
170     if(empty($user)){
171                 global $current_user;
172                 $current_user->setPreference($type .'_tabs', $tabs);
173         }else{
174                 $user->setPreference($type .'_tabs', $tabs);
175         }
176         
177 }
178
179 function get_user_tabs(&$user, $type='display'){
180         $system_tabs = $this->get_system_tabs();
181         $tabs = $user->getPreference($type .'_tabs');
182         if(!empty($tabs)){
183                 $tabs = $this->get_key_array($tabs);
184                 if($type == 'display')
185                         $tabs['Home'] =  'Home';
186                 return $tabs;
187         }
188         else
189         {
190                 if($type == 'display')
191                         return $system_tabs;
192                 else
193                         return array();
194         }
195
196
197 }
198
199 function get_unset_tabs($user){
200         global $moduleList;
201         $tabs = $this->get_user_tabs($user);
202         $unsetTabs = $this->get_key_array($moduleList);
203         foreach($tabs as $tab){
204                 unset($unsetTabs[$tab]);
205         }
206         return $unsetTabs;
207
208
209 }
210
211 function get_old_user_tabs($user){
212         $system_tabs = $this->get_system_tabs();
213         
214         $tabs = $user->getPreference('tabs');
215         
216         if(!empty($tabs))
217         {
218                 $tabs = $this->get_key_array($tabs);
219                 $tabs['Home'] =  'Home';
220                 foreach($tabs as $tab)
221                 {
222                         if(!isset($system_tabs[$tab]))
223                         {
224                                 unset($tabs[$tab]);
225                         }
226                 }
227                 return $tabs;
228         }
229         else
230         {
231                 return $system_tabs;
232         }
233
234
235 }
236
237 function get_old_tabs($user)
238 {
239         global $moduleList;
240         $tabs = $this->get_old_user_tabs($user);
241         $system_tabs = $this->get_system_tabs();
242         foreach($tabs as $tab)
243         {
244                 unset($system_tabs[$tab]);
245         }
246         
247         return array($tabs,$system_tabs);
248 }
249
250 function get_tabs($user)
251 {
252         $display_tabs = $this->get_user_tabs($user, 'display');
253         $hide_tabs = $this->get_user_tabs($user, 'hide');
254         $remove_tabs = $this->get_user_tabs($user, 'remove');
255         $system_tabs = $this->get_system_tabs();
256         
257         // remove access to tabs that roles do not give them permission to
258
259         foreach($system_tabs as $key=>$value)
260         {
261                 if(!isset($display_tabs[$key]))
262                         $display_tabs[$key] = $value;
263         }
264
265     ////////////////////////////////////////////////////////////////////
266     // Jenny - Bug 6286: If someone has "old school roles" defined (before 4.0) and upgrades, 
267     // then they can't remove those old roles through the UI. Also, when new tabs are added, 
268     // users who had any of those "old school roles" defined have no way of being able to see 
269     // those roles. We need to disable role checking.
270         
271     //$roleCheck = query_user_has_roles($user->id);
272     $roleCheck = 0;
273     ////////////////////////////////////////////////////////////////////
274                 if($roleCheck)
275                 {
276                         //grabs modules a user has access to via roles
277                         $role_tabs = get_user_allowed_modules($user->id);
278         
279                         // adds modules to display_tabs if existant in roles
280                         foreach($role_tabs as $key=>$value)
281                         {
282                                 if(!isset($display_tabs[$key]))
283                                         $display_tabs[$key] = $value;
284                         }
285                 }
286                 
287                 // removes tabs from display_tabs if not existant in roles
288                 // or exist in the hidden tabs
289                 foreach($display_tabs as $key=>$value)
290                 {
291                         if($roleCheck)
292                         {                       
293                                 if(!isset($role_tabs[$key]))
294                                         unset($display_tabs[$key]);
295                         }
296                         
297                         if(!isset($system_tabs[$key]))
298                                 unset($display_tabs[$key]);
299                         if(isset($hide_tabs[$key]))
300                                 unset($display_tabs[$key]);
301                 }
302
303                 // removes tabs from hide_tabs if not existant in roles
304                 foreach($hide_tabs as $key=>$value)
305                 {
306                         if($roleCheck)
307                         {
308                                 if(!isset($role_tabs[$key]))
309                                         unset($hide_tabs[$key]);
310                         }
311                         
312                         if(!isset($system_tabs[$key]))
313                                 unset($hide_tabs[$key]);
314                 }
315                 
316         // remove tabs from user if admin has removed specific tabs
317         foreach($remove_tabs as $key=>$value)
318         {
319                 if(isset($display_tabs[$key]))
320                         unset($display_tabs[$key]);
321                 if(isset($hide_tabs[$key]))
322                         unset($hide_tabs[$key]);
323         }
324
325         return array($display_tabs, $hide_tabs, $remove_tabs);
326 }
327
328 function restore_tabs($user){
329         global $moduleList;
330         $this->set_user_tabs($moduleList, $user);
331
332 }
333
334 function restore_system_tabs(){
335         global $moduleList;
336         $this->set_system_tabs($moduleList);
337
338 }
339
340
341 }