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.
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');
43 function is_system_tabs_in_db(){
45 $administration = new Administration();
46 $administration->retrieveSettings('MySettings');
47 if(isset($administration->settings) && isset($administration->settings['MySettings_tab']))
57 function get_system_tabs(){
60 static $system_tabs_result = null;
62 // if the value is not already cached, then retrieve it.
63 if(empty($system_tabs_result))
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))
80 ACLController :: filterModuleList($tabs);
81 $tabs = $this->get_key_array($tabs);
82 $system_tabs_result = $tabs;
84 $system_tabs_result = $this->get_key_array($moduleList);
89 $system_tabs_result = $this->get_key_array($moduleList);
93 return $system_tabs_result;
96 function get_tabs_system(){
98 $tabs = $this->get_system_tabs();
99 $unsetTabs = $this->get_key_array($moduleList);
100 foreach($tabs as $tab){
101 unset($unsetTabs[$tab]);
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']);
113 return array($tabs,$unsetTabs);
119 function set_system_tabs($tabs){
121 $administration = new Administration();
122 $serialized = base64_encode(serialize($tabs));
123 $administration->saveSetting('MySettings', 'tab', $serialized);
126 function get_users_can_edit(){
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'){
138 function set_users_can_edit($boolean){
139 global $current_user;
140 if(is_admin($current_user)){
142 $administration = new Administration();
144 $administration->saveSetting('MySettings', 'disable_useredit', 'no');
146 $administration->saveSetting('MySettings', 'disable_useredit', 'yes');
152 function get_key_array($arr){
155 foreach($arr as $val){
162 function set_user_tabs($tabs, &$user, $type='display'){
164 global $current_user;
165 $current_user->setPreference($type .'_tabs', $tabs);
167 $user->setPreference($type .'_tabs', $tabs);
172 function get_user_tabs(&$user, $type='display'){
173 $system_tabs = $this->get_system_tabs();
174 $tabs = $user->getPreference($type .'_tabs');
176 $tabs = $this->get_key_array($tabs);
177 if($type == 'display')
178 $tabs['Home'] = 'Home';
183 if($type == 'display')
192 function get_unset_tabs($user){
194 $tabs = $this->get_user_tabs($user);
195 $unsetTabs = $this->get_key_array($moduleList);
196 foreach($tabs as $tab){
197 unset($unsetTabs[$tab]);
204 function get_old_user_tabs($user){
205 $system_tabs = $this->get_system_tabs();
207 $tabs = $user->getPreference('tabs');
211 $tabs = $this->get_key_array($tabs);
212 $tabs['Home'] = 'Home';
213 foreach($tabs as $tab)
215 if(!isset($system_tabs[$tab]))
230 function get_old_tabs($user)
233 $tabs = $this->get_old_user_tabs($user);
234 $system_tabs = $this->get_system_tabs();
235 foreach($tabs as $tab)
237 unset($system_tabs[$tab]);
240 return array($tabs,$system_tabs);
243 function get_tabs($user)
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();
250 // remove access to tabs that roles do not give them permission to
252 foreach($system_tabs as $key=>$value)
254 if(!isset($display_tabs[$key]))
255 $display_tabs[$key] = $value;
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.
264 //$roleCheck = query_user_has_roles($user->id);
266 ////////////////////////////////////////////////////////////////////
269 //grabs modules a user has access to via roles
270 $role_tabs = get_user_allowed_modules($user->id);
272 // adds modules to display_tabs if existant in roles
273 foreach($role_tabs as $key=>$value)
275 if(!isset($display_tabs[$key]))
276 $display_tabs[$key] = $value;
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)
286 if(!isset($role_tabs[$key]))
287 unset($display_tabs[$key]);
290 if(!isset($system_tabs[$key]))
291 unset($display_tabs[$key]);
292 if(isset($hide_tabs[$key]))
293 unset($display_tabs[$key]);
296 // removes tabs from hide_tabs if not existant in roles
297 foreach($hide_tabs as $key=>$value)
301 if(!isset($role_tabs[$key]))
302 unset($hide_tabs[$key]);
305 if(!isset($system_tabs[$key]))
306 unset($hide_tabs[$key]);
309 // remove tabs from user if admin has removed specific tabs
310 foreach($remove_tabs as $key=>$value)
312 if(isset($display_tabs[$key]))
313 unset($display_tabs[$key]);
314 if(isset($hide_tabs[$key]))
315 unset($hide_tabs[$key]);
318 return array($display_tabs, $hide_tabs, $remove_tabs);
321 function restore_tabs($user){
323 $this->set_user_tabs($moduleList, $user);
327 function restore_system_tabs(){
329 $this->set_system_tabs($moduleList);