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-2013 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 ********************************************************************************/
41 var $required_modules = array('Home');
44 * @var bool flag of validation of the cache
46 static protected $isCacheValid = false;
48 function is_system_tabs_in_db(){
50 $administration = new Administration();
51 $administration->retrieveSettings('MySettings');
52 if(isset($administration->settings) && isset($administration->settings['MySettings_tab']))
62 function get_system_tabs(){
65 static $system_tabs_result = null;
67 // if the value is not already cached, then retrieve it.
68 if (empty($system_tabs_result) || !self::$isCacheValid)
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))
85 ACLController :: filterModuleList($tabs);
86 $tabs = $this->get_key_array($tabs);
87 $system_tabs_result = $tabs;
89 $system_tabs_result = $this->get_key_array($moduleList);
94 $system_tabs_result = $this->get_key_array($moduleList);
96 self::$isCacheValid = true;
99 return $system_tabs_result;
102 function get_tabs_system(){
104 $tabs = $this->get_system_tabs();
105 $unsetTabs = $this->get_key_array($moduleList);
106 foreach($tabs as $tab){
107 unset($unsetTabs[$tab]);
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']);
119 return array($tabs,$unsetTabs);
125 function set_system_tabs($tabs){
127 $administration = new Administration();
128 $serialized = base64_encode(serialize($tabs));
129 $administration->saveSetting('MySettings', 'tab', $serialized);
130 self::$isCacheValid = false;
133 function get_users_can_edit(){
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'){
145 function set_users_can_edit($boolean){
146 global $current_user;
147 if(is_admin($current_user)){
149 $administration = new Administration();
151 $administration->saveSetting('MySettings', 'disable_useredit', 'no');
153 $administration->saveSetting('MySettings', 'disable_useredit', 'yes');
159 function get_key_array($arr){
162 foreach($arr as $val){
169 function set_user_tabs($tabs, &$user, $type='display'){
171 global $current_user;
172 $current_user->setPreference($type .'_tabs', $tabs);
174 $user->setPreference($type .'_tabs', $tabs);
179 function get_user_tabs(&$user, $type='display'){
180 $system_tabs = $this->get_system_tabs();
181 $tabs = $user->getPreference($type .'_tabs');
183 $tabs = $this->get_key_array($tabs);
184 if($type == 'display')
185 $tabs['Home'] = 'Home';
190 if($type == 'display')
199 function get_unset_tabs($user){
201 $tabs = $this->get_user_tabs($user);
202 $unsetTabs = $this->get_key_array($moduleList);
203 foreach($tabs as $tab){
204 unset($unsetTabs[$tab]);
211 function get_old_user_tabs($user){
212 $system_tabs = $this->get_system_tabs();
214 $tabs = $user->getPreference('tabs');
218 $tabs = $this->get_key_array($tabs);
219 $tabs['Home'] = 'Home';
220 foreach($tabs as $tab)
222 if(!isset($system_tabs[$tab]))
237 function get_old_tabs($user)
240 $tabs = $this->get_old_user_tabs($user);
241 $system_tabs = $this->get_system_tabs();
242 foreach($tabs as $tab)
244 unset($system_tabs[$tab]);
247 return array($tabs,$system_tabs);
250 function get_tabs($user)
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();
257 // remove access to tabs that roles do not give them permission to
259 foreach($system_tabs as $key=>$value)
261 if(!isset($display_tabs[$key]))
262 $display_tabs[$key] = $value;
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.
271 //$roleCheck = query_user_has_roles($user->id);
273 ////////////////////////////////////////////////////////////////////
276 //grabs modules a user has access to via roles
277 $role_tabs = get_user_allowed_modules($user->id);
279 // adds modules to display_tabs if existant in roles
280 foreach($role_tabs as $key=>$value)
282 if(!isset($display_tabs[$key]))
283 $display_tabs[$key] = $value;
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)
293 if(!isset($role_tabs[$key]))
294 unset($display_tabs[$key]);
297 if(!isset($system_tabs[$key]))
298 unset($display_tabs[$key]);
299 if(isset($hide_tabs[$key]))
300 unset($display_tabs[$key]);
303 // removes tabs from hide_tabs if not existant in roles
304 foreach($hide_tabs as $key=>$value)
308 if(!isset($role_tabs[$key]))
309 unset($hide_tabs[$key]);
312 if(!isset($system_tabs[$key]))
313 unset($hide_tabs[$key]);
316 // remove tabs from user if admin has removed specific tabs
317 foreach($remove_tabs as $key=>$value)
319 if(isset($display_tabs[$key]))
320 unset($display_tabs[$key]);
321 if(isset($hide_tabs[$key]))
322 unset($hide_tabs[$key]);
325 return array($display_tabs, $hide_tabs, $remove_tabs);
328 function restore_tabs($user){
330 $this->set_user_tabs($moduleList, $user);
334 function restore_system_tabs(){
336 $this->set_system_tabs($moduleList);