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