]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/UserViewHelper.php
Release 6.5.6
[Github/sugarcrm.git] / modules / Users / UserViewHelper.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 /**
39  * This helper handles the rest of the fields for the Users Edit and Detail views.
40  * There are a lot of fields on those views that do not map directly to being used on the metadata based UI, so they are handled here.
41  */
42 class UserViewHelper {
43     /**
44      * The smarty template handler for the template
45      * @var SugarSmarty
46      */
47     protected $ss;
48     /**
49      * The bean that we are viewing.
50      * @var SugarBean
51      */
52     protected $bean;
53     /**
54      * What type of view we are looking at, valid values are 'EditView' and 'DetailView'
55      * @var string
56      */
57     protected $viewType;
58     /**
59      * Is the current user an admin for the Users module
60      * @var bool
61      */
62     protected $is_current_admin;
63     /**
64      * Is the current user a system wide admin
65      * @var bool
66      */
67     protected $is_super_admin;
68     /**
69      * The current user type
70      * One of: REGULAR ADMIN GROUP PORTAL_ONLY
71      * @var string
72      */
73     public $usertype;
74
75
76     /**
77      * Constructor, pass in the smarty template, the bean and the viewtype
78      */
79     public function __construct(Sugar_Smarty &$smarty, SugarBean &$bean, $viewType = 'EditView' ) {
80         $this->ss = $smarty;
81         $this->bean = $bean;
82         $this->viewType = $viewType;
83     }
84
85     /**
86      * This function populates the smarty class that was passed in through the constructor
87      */
88     public function setupAdditionalFields() {
89         $this->assignUserTypes();
90         $this->setupButtonsAndTabs();
91         $this->setupUserTypeDropdown();
92         $this->setupPasswordTab();
93         $this->setupEmailSettings();
94         $this->setupThemeTab();
95         $this->setupAdvancedTab();
96
97     }
98
99     protected function assignUserTypes() {
100         global $current_user, $app_list_strings;
101
102         // There is a lot of extra stuff that needs to go in here to properly render
103         $this->is_current_admin=is_admin($current_user)
104             ||$current_user->isAdminForModule('Users');
105         $this->is_super_admin = is_admin($current_user);
106
107         $this->usertype='REGULAR';
108         if($this->is_super_admin){
109             $this->usertype='Administrator';
110         }
111
112
113         // check if the user has access to the User Management
114         $this->ss->assign('USER_ADMIN',$current_user->isAdminForModule('Users')&& !is_admin($current_user));
115
116
117         if ($this->is_current_admin) {
118             $this->ss->assign('IS_ADMIN','1');
119         } else {
120             $this->ss->assign('IS_ADMIN', '0');
121         }
122
123         if ($this->is_super_admin) {
124             $this->ss->assign('IS_SUPER_ADMIN','1');
125         } else {
126             $this->ss->assign('IS_SUPER_ADMIN', '0');
127         }
128
129         $this->ss->assign('IS_PORTALONLY', '0');
130         $this->ss->assign('IS_GROUP', '0');
131         if((!empty($this->bean->is_group) && $this->bean->is_group)  || (isset($_REQUEST['usertype']) && $_REQUEST['usertype']=='group')){
132             $this->ss->assign('IS_GROUP', '1');
133             $this->usertype='GROUP';
134         }
135
136
137
138         $edit_self = $current_user->id == $this->bean->id;
139         $admin_edit_self = is_admin($current_user) && $edit_self;
140
141
142         $this->ss->assign('IS_FOCUS_ADMIN', is_admin($this->bean));
143
144         if($edit_self) {
145             $this->ss->assign('EDIT_SELF','1');
146         }
147         if($admin_edit_self) {
148             $this->ss->assign('ADMIN_EDIT_SELF','1');
149         }
150
151     }
152
153     protected function setupButtonsAndTabs() {
154         global $current_user;
155
156         if (isset($GLOBALS['sugar_config']['show_download_tab'])) {
157             $enable_download_tab = $GLOBALS['sugar_config']['show_download_tab'];
158         }else{
159             $enable_download_tab = true;
160         }
161
162         $this->ss->assign('SHOW_DOWNLOADS_TAB', $enable_download_tab);
163
164
165         $the_query_string = 'module=Users&action=DetailView';
166         if(isset($_REQUEST['record'])) {
167             $the_query_string .= '&record='.$_REQUEST['record'];
168         }
169         $buttons_header = array();
170         $buttons_footer = array();
171         if (!$this->bean->is_group){
172             if ($this->bean->id == $current_user->id) {
173                 $reset_pref_warning = translate('LBL_RESET_PREFERENCES_WARNING','Users');
174                 $reset_home_warning = translate('LBL_RESET_HOMEPAGE_WARNING','Users');
175             }
176             else {
177                 $reset_pref_warning = translate('LBL_RESET_PREFERENCES_WARNING_USER','Users');
178                 $reset_home_warning = translate('LBL_RESET_HOMEPAGE_WARNING_USER','Users');
179             }
180
181             //bug 48170
182             $user_preference_url = "module=Users&action=resetPreferences";
183             if(isset($_REQUEST['record'])){
184                 $user_preference_url .= "&record=".$_REQUEST['record'];
185             }
186             $buttons_header[]="<input type='button' class='button' id='reset_user_preferences_header' onclick='if(confirm(\"{$reset_pref_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$user_preference_url."&reset_preferences=true\";' value='".translate('LBL_RESET_PREFERENCES','Users')."' />";
187             $buttons_header[]="<input type='button' class='button' id='reset_homepage_header' onclick='if(confirm(\"{$reset_home_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$the_query_string."&reset_homepage=true\";' value='".translate('LBL_RESET_HOMEPAGE','Users')."' />";
188
189             $buttons_footer[]="<input type='button' class='button' id='reset_user_preferences_footer' onclick='if(confirm(\"{$reset_pref_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$user_preference_url."&reset_preferences=true\";' value='".translate('LBL_RESET_PREFERENCES','Users')."' />";
190             $buttons_footer[]="<input type='button' class='button' id='reset_homepage_footer' onclick='if(confirm(\"{$reset_home_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$the_query_string."&reset_homepage=true\";' value='".translate('LBL_RESET_HOMEPAGE','Users')."' />";
191
192         }
193         if (isset($buttons_header)) $this->ss->assign("BUTTONS_HEADER", $buttons_header);
194         if (isset($buttons_footer)) $this->ss->assign("BUTTONS_FOOTER", $buttons_footer);
195
196
197
198         if (isset($this->bean->id)) {
199             $this->ss->assign('ID',$this->bean->id);
200         }
201
202     }
203
204
205     /**
206      * setupUserTypeDropdown
207      *
208      * This function handles setting up the user type dropdown field.  It determines which user types are available for the current user.
209      * At the end of the function two Smarty variables (USER_TYPE_DROPDOWN and USER_TYPE_READONLY) are assigned.
210      *
211      */
212     public function setupUserTypeDropdown() {
213         global $current_user;
214
215
216         //if this is an existing bean and the type is empty, then populate user type
217         if(!empty($this->bean->id) && empty($this->bean->user_type))
218             {
219             $this->setUserType($this->bean);
220             $userType = $this->bean->user_type;
221         } else {
222             $userType = $this->usertype;
223         }
224
225         $availableUserTypes = array();
226         $userTypes = array(
227             'RegularUser' => array(
228                 'label' => translate('LBL_REGULAR_USER','Users'),
229                 'description' => translate('LBL_REGULAR_DESC','Users'),
230             ),
231             'GROUP' => array(
232                 'label' => translate('LBL_GROUP_USER','Users'),
233                 'description' => translate('LBL_GROUP_DESC','Users'),
234             ),
235             'Administrator' => array(
236                 'label' => translate('LBL_ADMIN_USER','Users'),
237                 'description' => translate('LBL_ADMIN_DESC','Users'),
238             ),
239         );
240
241         if ( $userType == 'GROUP' || $userType == 'PORTAL_ONLY' ) {
242             $availableUserTypes = array($this->usertype);
243         } else {
244             if ( $this->ss->get_template_vars('USER_ADMIN') ) {
245                 $availableUserTypes = array('RegularUser');
246             } elseif($this->ss->get_template_vars('ADMIN_EDIT_SELF')) {
247                 $availableUserTypes = array('Administrator');
248             } elseif($this->ss->get_template_vars('IS_SUPER_ADMIN')) {
249                 $availableUserTypes = array(
250                     'RegularUser',
251                     'Administrator',
252                     );
253             } else {
254                 $availableUserTypes = array($userType);
255             }
256         }
257
258         $userTypeDropdown = '<select id="UserType" name="UserType" onchange="user_status_display(this);" ';
259         if ( count($availableUserTypes) == 1 ) {
260             $userTypeDropdown .= ' disabled ';
261         }
262         $userTypeDropdown .= '>';
263
264         $userTypeDescription = '';
265
266         $setSelected = !empty($this->bean->id);
267
268         foreach ( $availableUserTypes as $currType ) {
269             if ($setSelected && $currType == $userType ) {
270                 $userTypeDropdown .= '<option value="'.$currType.'" SELECTED>'.$userTypes[$currType]['label'].'</option>';
271             } else {
272                 $userTypeDropdown .= '<option value="'.$currType.'">'.$userTypes[$currType]['label'].'</option>';
273             }
274         }
275         $userTypeDropdown .= '</select><div id="UserTypeDesc">&nbsp;</div>';
276
277         $this->ss->assign('USER_TYPE_DROPDOWN',$userTypeDropdown);
278         $this->ss->assign('USER_TYPE_READONLY',$userTypes[$userType]['label'] . "<input type='hidden' id='UserType' value='{$userType}'><div id='UserTypeDesc'>&nbsp;</div>");
279
280     }
281
282     protected function setupPasswordTab() {
283         global $current_user;
284
285         $this->ss->assign('PWDSETTINGS', isset($GLOBALS['sugar_config']['passwordsetting']) ? $GLOBALS['sugar_config']['passwordsetting'] : array());
286
287
288         $enable_syst_generate_pwd=false;
289         if(isset($GLOBALS['sugar_config']['passwordsetting']) && isset($GLOBALS['sugar_config']['passwordsetting']['SystemGeneratedPasswordON'])){
290             $enable_syst_generate_pwd=$GLOBALS['sugar_config']['passwordsetting']['SystemGeneratedPasswordON'];
291         }
292
293         // If new regular user without system generated password or new portal user
294         if(((isset($enable_syst_generate_pwd) && !$enable_syst_generate_pwd && $this->usertype!='GROUP') || $this->usertype =='PORTAL_ONLY') && empty($this->bean->id)) {
295             $this->ss->assign('REQUIRED_PASSWORD','1');
296         } else {
297             $this->ss->assign('REQUIRED_PASSWORD','0');
298         }
299
300         // If my account page or portal only user or regular user without system generated password or a duplicate user
301         if((($current_user->id == $this->bean->id) || $this->usertype=='PORTAL_ONLY' || (($this->usertype=='REGULAR' || $this->usertype == 'Administrator' || (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true' && $this->usertype!='GROUP')) && !$enable_syst_generate_pwd)) && !$this->bean->external_auth_only ) {
302             $this->ss->assign('CHANGE_PWD', '1');
303         } else {
304             $this->ss->assign('CHANGE_PWD', '0');
305         }
306
307         // Make sure group users don't get a password change prompt
308         if ( $this->usertype == 'GROUP' ) {
309             $this->ss->assign('CHANGE_PWD', '0');
310         }
311
312         $configurator = new Configurator();
313         if ( isset($configurator->config['passwordsetting'])
314              && ($configurator->config['passwordsetting']['SystemGeneratedPasswordON']
315                  || $configurator->config['passwordsetting']['forgotpasswordON'])
316              && $this->usertype != 'GROUP' && $this->usertype != 'PORTAL_ONLY' ) {
317             $this->ss->assign('REQUIRED_EMAIL_ADDRESS','1');
318         } else {
319             $this->ss->assign('REQUIRED_EMAIL_ADDRESS','0');
320         }
321         if($this->usertype=='GROUP' || $this->usertype=='PORTAL_ONLY') {
322             $this->ss->assign('HIDE_FOR_GROUP_AND_PORTAL', 'none');
323             $this->ss->assign('HIDE_CHANGE_USERTYPE','none');
324         } else {
325             $this->ss->assign('HIDE_FOR_NORMAL_AND_ADMIN','none');
326             if (!$this->is_current_admin) {
327                 $this->ss->assign('HIDE_CHANGE_USERTYPE','none');
328             } else {
329                 $this->ss->assign('HIDE_STATIC_USERTYPE','none');
330             }
331         }
332
333     }
334
335     protected function setupThemeTab() {
336         $user_theme = $this->bean->getPreference('user_theme');
337         if(isset($user_theme)) {
338             $this->ss->assign("THEMES", get_select_options_with_id(SugarThemeRegistry::availableThemes(), $user_theme));
339         } else {
340             $this->ss->assign("THEMES", get_select_options_with_id(SugarThemeRegistry::availableThemes(), $GLOBALS['sugar_config']['default_theme']));
341         }
342         $this->ss->assign("SHOW_THEMES",count(SugarThemeRegistry::availableThemes()) > 1);
343         $this->ss->assign("USER_THEME_COLOR", $this->bean->getPreference('user_theme_color'));
344         $this->ss->assign("USER_THEME_FONT", $this->bean->getPreference('user_theme_font'));
345         $this->ss->assign("USER_THEME", $user_theme);
346
347 // Build a list of themes that support group modules
348         $this->ss->assign("DISPLAY_GROUP_TAB", 'none');
349
350         $selectedTheme = $user_theme;
351         if(!isset($user_theme)) {
352             $selectedTheme = $GLOBALS['sugar_config']['default_theme'];
353         }
354
355         $themeList = SugarThemeRegistry::availableThemes();
356         $themeGroupList = array();
357
358         foreach ( $themeList as $themeId => $themeName ) {
359             $currThemeObj = SugarThemeRegistry::get($themeId);
360             if ( isset($currThemeObj->group_tabs) && $currThemeObj->group_tabs == 1 ) {
361                 $themeGroupList[$themeId] = true;
362                 if ( $themeId == $selectedTheme ) {
363                     $this->ss->assign("DISPLAY_GROUP_TAB", '');
364                 }
365             } else {
366                 $themeGroupList[$themeId] = false;
367             }
368         }
369         $this->ss->assign("themeGroupListJSON",json_encode($themeGroupList));
370
371     }
372
373     protected function setupAdvancedTab() {
374         $this->setupAdvancedTabUserSettings();
375         $this->setupAdvancedTabTeamSettings();
376         $this->setupAdvancedTabNavSettings();
377         $this->setupAdvancedTabLocaleSettings();
378         $this->setupAdvancedTabPdfSettings();
379     }
380
381     protected function setupAdvancedTabUserSettings()
382     {
383         global $current_user, $locale, $app_strings, $app_list_strings, $sugar_config;
384         // This is for the "Advanced" tab, it's not controlled by the metadata UI so we have to do more for it.
385
386         $this->ss->assign('EXPORT_DELIMITER', $this->bean->getPreference('export_delimiter'));
387
388         if($this->bean->receive_notifications ||(!isset($this->bean->id) && $admin->settings['notify_send_by_default'])) $this->ss->assign("RECEIVE_NOTIFICATIONS", "checked");
389
390         //jc:12293 - modifying to use the accessor method which will translate the
391         //available character sets using the translation files
392         $export_charset = $locale->getExportCharset('', $this->bean);
393         $export_charset_options = $locale->getCharsetSelect();
394         $this->ss->assign('EXPORT_CHARSET', get_select_options_with_id($export_charset_options, $export_charset));
395         $this->ss->assign('EXPORT_CHARSET_DISPLAY', $export_charset);
396         //end:12293
397
398         if( $this->bean->getPreference('use_real_names') == 'on'
399             || ( empty($this->bean->id)
400                  && isset($GLOBALS['sugar_config']['use_real_names'])
401                  && $GLOBALS['sugar_config']['use_real_names']
402                  && $this->bean->getPreference('use_real_names') != 'off') ) {
403             $this->ss->assign('USE_REAL_NAMES', 'CHECKED');
404         }
405
406         if($this->bean->getPreference('mailmerge_on') == 'on') {
407             $this->ss->assign('MAILMERGE_ON', 'checked');
408         }
409
410         if($this->bean->getPreference('no_opps') == 'on') {
411             $this->ss->assign('NO_OPPS', 'CHECKED');
412         }
413
414             $reminder_time = $this->bean->getPreference('reminder_time');
415             if(empty($reminder_time)){
416                     $reminder_time = -1;
417             }
418             $email_reminder_time = $this->bean->getPreference('email_reminder_time');
419             if(empty($email_reminder_time)){
420                     $email_reminder_time = -1;
421             }
422         $this->ss->assign("REMINDER_TIME_OPTIONS", $app_list_strings['reminder_time_options']);
423         $this->ss->assign("EMAIL_REMINDER_TIME_OPTIONS", $app_list_strings['reminder_time_options']);
424             $this->ss->assign("REMINDER_TIME", $reminder_time);
425             $this->ss->assign("EMAIL_REMINDER_TIME", $email_reminder_time);
426             $this->ss->assign("REMINDER_TABINDEX", "12");
427             $publish_key = $this->bean->getPreference('calendar_publish_key' );
428         $this->ss->assign('CALENDAR_PUBLISH_KEY', $publish_key);
429
430         $publish_url = $sugar_config['site_url'].'/vcal_server.php';
431         $token = "/";
432         //determine if the web server is running IIS
433         //if so then change the publish url
434         if(isset($_SERVER) && !empty($_SERVER['SERVER_SOFTWARE'])){
435             $position = strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'iis');
436             if($position !== false){
437                 $token = '?parms=';
438             }
439         }
440
441         $publish_url .= $token."type=vfb&source=outlook&key=<span id=\"cal_pub_key_span\">$publish_key</span>";
442         if (! empty($this->bean->email1)) {
443             $publish_url .= '&email='.$this->bean->email1;
444         } else {
445             $publish_url .= '&user_name='.$this->bean->user_name;
446         }
447
448         $ical_url = $sugar_config['site_url']."/ical_server.php?type=ics&key=<span id=\"ical_pub_key_span\">$publish_key</span>";
449         if (! empty($this->bean->email1))
450         {
451             $ical_url .= '&email='.$this->bean->email1;
452         } else
453         {
454             $ical_url .= '&user_name='.$this->bean->user_name;
455         }
456
457         $this->ss->assign("CALENDAR_PUBLISH_URL", $publish_url);
458         $this->ss->assign("CALENDAR_SEARCH_URL", $sugar_config['site_url']."/vcal_server.php/type=vfb&key=<span id=\"search_pub_key_span\">$publish_key</span>&email=%NAME%@%SERVER%");
459         $this->ss->assign("CALENDAR_ICAL_URL", $ical_url);
460
461         $this->ss->assign("SETTINGS_URL", $sugar_config['site_url']);
462
463     }
464
465     protected function setupAdvancedTabTeamSettings() {
466         global $sugar_config;
467
468         $authclass = '';
469         if(!empty($sugar_config['authenticationClass'])){
470             $this->ss->assign('EXTERNAL_AUTH_CLASS_1', $sugar_config['authenticationClass']);
471             $this->ss->assign('EXTERNAL_AUTH_CLASS', $sugar_config['authenticationClass']);
472             $authclass = $sugar_config['authenticationClass'];
473         }else{
474             if(!empty($GLOBALS['system_config']->settings['system_ldap_enabled'])){
475                 $this->ss->assign('EXTERNAL_AUTH_CLASS_1', translate('LBL_LDAP','Users'));
476                 $this->ss
477                         ->assign('EXTERNAL_AUTH_CLASS', translate('LBL_LDAP_AUTHENTICATION','Users'));
478                 $authclass = 'LDAPAuthenticate';
479             }
480         }
481         if(!empty($this->bean->external_auth_only)) {
482             $this->ss->assign('EXTERNAL_AUTH_ONLY_CHECKED', 'CHECKED');
483         }
484
485         if($this->is_super_admin && !empty($authclass)) {
486             $this->ss->assign('DISPLAY_EXTERNAL_AUTH',true);
487         }
488
489     }
490
491     protected function setupAdvancedTabNavSettings() {
492         global $app_list_strings;
493
494         // Grouped tabs?
495         $useGroupTabs = $this->bean->getPreference('navigation_paradigm');
496         if ( ! isset($useGroupTabs) ) {
497             if ( ! isset($GLOBALS['sugar_config']['default_navigation_paradigm']) ) {
498                 $GLOBALS['sugar_config']['default_navigation_paradigm'] = 'gm';
499             }
500             $useGroupTabs = $GLOBALS['sugar_config']['default_navigation_paradigm'];
501         }
502         $this->ss->assign("USE_GROUP_TABS",($useGroupTabs=='gm')?'checked':'');
503
504         $user_subpanel_tabs = $this->bean->getPreference('subpanel_tabs');
505         if(isset($user_subpanel_tabs)) {
506             $this->ss->assign("SUBPANEL_TABS", $user_subpanel_tabs?'checked':'');
507         } else {
508             $this->ss->assign("SUBPANEL_TABS", $GLOBALS['sugar_config']['default_subpanel_tabs']?'checked':'');
509         }
510
511         /* Module Tab Chooser */
512         require_once('include/templates/TemplateGroupChooser.php');
513         require_once('modules/MySettings/TabController.php');
514         $chooser = new TemplateGroupChooser();
515         $controller = new TabController();
516
517
518         if($this->is_current_admin || $controller->get_users_can_edit()) {
519             $chooser->display_hide_tabs = true;
520         } else {
521             $chooser->display_hide_tabs = false;
522         }
523
524         $chooser->args['id'] = 'edit_tabs';
525         $chooser->args['values_array'] = $controller->get_tabs($this->bean);
526         foreach($chooser->args['values_array'][0] as $key=>$value) {
527             $chooser->args['values_array'][0][$key] = $app_list_strings['moduleList'][$key];
528         }
529
530         foreach($chooser->args['values_array'][1] as $key=>$value) {
531             $chooser->args['values_array'][1][$key] = $app_list_strings['moduleList'][$key];
532         }
533
534         foreach($chooser->args['values_array'][2] as $key=>$value) {
535             $chooser->args['values_array'][2][$key] = $app_list_strings['moduleList'][$key];
536         }
537
538         $chooser->args['left_name'] = 'display_tabs';
539         $chooser->args['right_name'] = 'hide_tabs';
540
541         $chooser->args['left_label'] =  translate('LBL_DISPLAY_TABS','Users');
542         $chooser->args['right_label'] =  translate('LBL_HIDE_TABS','Users');
543         require_once('include/Smarty/plugins/function.sugar_help.php');
544         $chooser->args['title'] =  translate('LBL_EDIT_TABS','Users').smarty_function_sugar_help(array("text"=>translate('LBL_CHOOSE_WHICH','Users')),$ss);
545
546         $this->ss->assign('TAB_CHOOSER', $chooser->display());
547         $this->ss->assign('CHOOSER_SCRIPT','set_chooser();');
548         $this->ss->assign('CHOOSE_WHICH', translate('LBL_CHOOSE_WHICH','Users'));
549
550     }
551
552     protected function setupAdvancedTabLocaleSettings() {
553         global $locale, $sugar_config, $app_list_strings;
554
555         ///////////////////////////////////////////////////////////////////////////////
556         ////    LOCALE SETTINGS
557         ////    Date/time format
558         $dformat = $locale->getPrecedentPreference($this->bean->id?'datef':'default_date_format', $this->bean);
559         $tformat = $locale->getPrecedentPreference($this->bean->id?'timef':'default_time_format', $this->bean);
560         $nformat = $locale->getPrecedentPreference('default_locale_name_format', $this->bean);
561         if (!array_key_exists($nformat, $sugar_config['name_formats'])) {
562             $nformat = $sugar_config['default_locale_name_format'];
563         }
564         $timeOptions = get_select_options_with_id($sugar_config['time_formats'], $tformat);
565         $dateOptions = get_select_options_with_id($sugar_config['date_formats'], $dformat);
566         $nameOptions = get_select_options_with_id($locale->getUsableLocaleNameOptions($sugar_config['name_formats']), $nformat);
567         $this->ss->assign('TIMEOPTIONS', $timeOptions);
568         $this->ss->assign('DATEOPTIONS', $dateOptions);
569         $this->ss->assign('NAMEOPTIONS', $nameOptions);
570         $this->ss->assign('DATEFORMAT', $sugar_config['date_formats'][$dformat]);
571         $this->ss->assign('TIMEFORMAT', $sugar_config['time_formats'][$tformat]);
572         $this->ss->assign('NAMEFORMAT', $sugar_config['name_formats'][$nformat]);
573
574         //// Timezone
575         if(empty($this->bean->id)) { // remove default timezone for new users(set later)
576             $this->bean->user_preferences['timezone'] = '';
577         }
578
579         $userTZ = $this->bean->getPreference('timezone');
580
581         if(empty($userTZ) && !$this->bean->is_group && !$this->bean->portal_only) {
582             $userTZ = TimeDate::guessTimezone();
583             $this->bean->setPreference('timezone', $userTZ);
584         }
585
586         if(!$this->bean->getPreference('ut')) {
587             $this->ss->assign('PROMPTTZ', ' checked');
588         }
589         $this->ss->assign('TIMEZONE_CURRENT', $userTZ);
590         $this->ss->assign('TIMEZONEOPTIONS', TimeDate::getTimezoneList());
591         $this->ss->assign("TIMEZONE", TimeDate::tzName($userTZ));
592
593
594         // FG - Bug 4236 - Managed First Day of Week
595         $fdowDays = array();
596         foreach ($app_list_strings['dom_cal_day_long'] as $d) {
597             if ($d != "") {
598                 $fdowDays[] = $d;
599             }
600         }
601         $this->ss->assign("FDOWOPTIONS", $fdowDays);
602         $currentFDOW = $this->bean->get_first_day_of_week();
603
604         if (!isset($currentFDOW)) {$currentFDOW = 0;}
605         $this->ss->assign("FDOWCURRENT", $currentFDOW);
606         $this->ss->assign("FDOWDISPLAY", $app_list_strings['dom_cal_day_long'][$currentFDOW]);
607
608         //// Numbers and Currency display
609         require_once('modules/Currencies/ListCurrency.php');
610         $currency = new ListCurrency();
611
612         // 10/13/2006 Collin - Changed to use Localization.getConfigPreference
613         // This was the problem- Previously, the "-99" currency id always assumed
614         // to be defaulted to US Dollars.  However, if someone set their install to use
615         // Euro or other type of currency then this setting would not apply as the
616         // default because it was being overridden by US Dollars.
617         $cur_id = $locale->getPrecedentPreference('currency', $this->bean);
618         if($cur_id) {
619             $selectCurrency = $currency->getSelectOptions($cur_id);
620             $this->ss->assign("CURRENCY", $selectCurrency);
621         } else {
622             $selectCurrency = $currency->getSelectOptions();
623             $this->ss->assign("CURRENCY", $selectCurrency);
624         }
625
626         $currencyList = array();
627         foreach($locale->currencies as $id => $val ) {
628             $currencyList[$id] = $val['symbol'];
629         }
630         $currencySymbolJSON = json_encode($currencyList);
631         $this->ss->assign('currencySymbolJSON', $currencySymbolJSON);
632
633         $currencyDisplay = new Currency();
634         if(isset($cur_id) ) {
635             $currencyDisplay->retrieve($cur_id);
636             $this->ss->assign('CURRENCY_DISPLAY', $currencyDisplay->iso4217 .' '.$currencyDisplay->symbol );
637         } else {
638             $this->ss->assign("CURRENCY_DISPLAY", $currencyDisplay->getDefaultISO4217() .' '.$currencyDisplay->getDefaultCurrencySymbol() );
639         }
640
641         // fill significant digits dropdown
642         $significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $this->bean);
643         $sigDigits = '';
644         for($i=0; $i<=6; $i++) {
645             if($significantDigits == $i) {
646                 $sigDigits .= "<option value=\"$i\" selected=\"true\">$i</option>";
647             } else {
648                 $sigDigits .= "<option value=\"$i\">{$i}</option>";
649             }
650         }
651
652         $this->ss->assign('sigDigits', $sigDigits);
653         $this->ss->assign('CURRENCY_SIG_DIGITS', $significantDigits);
654
655         $num_grp_sep = $this->bean->getPreference('num_grp_sep');
656         $dec_sep = $this->bean->getPreference('dec_sep');
657         $this->ss->assign("NUM_GRP_SEP",(empty($num_grp_sep) ? $GLOBALS['sugar_config']['default_number_grouping_seperator'] : $num_grp_sep));
658         $this->ss->assign("DEC_SEP",(empty($dec_sep) ? $GLOBALS['sugar_config']['default_decimal_seperator'] : $dec_sep));
659         $this->ss->assign('getNumberJs', $locale->getNumberJs());
660
661         //// Name display format
662         $this->ss->assign('default_locale_name_format', $locale->getLocaleFormatMacro($this->bean));
663         $this->ss->assign('getNameJs', $locale->getNameJs());
664         $this->ss->assign('NAME_FORMAT', $this->bean->getLocaleFormatDesc());
665         ////    END LOCALE SETTINGS
666     }
667
668     protected function setupAdvancedTabPdfSettings() {
669     }
670
671     protected function setupEmailSettings() {
672         global $current_user, $app_list_strings;
673
674         $this->ss->assign("MAIL_SENDTYPE", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $this->bean->getPreference('mail_sendtype')));
675
676         ///////////////////////////////////////////////////////////////////////////////
677         ////    EMAIL OPTIONS
678         // We need to turn off the requiredness of emails if it is a group or portal user
679         if ($this->usertype == 'GROUP' || $this->usertype == 'PORTAL_ONLY' ) {
680             global $dictionary;
681             $dictionary['User']['fields']['email1']['required'] = false;
682         }
683         // hack to disable email field being required if it shouldn't be required
684         if ( $this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0' ) {
685             $GLOBALS['dictionary']['User']['fields']['email1']['required'] = false;
686         }
687         $this->ss->assign("NEW_EMAIL",  '<span id="email_span">' . getEmailAddressWidget($this->bean, "email1", $this->bean->email1, $this->viewType) . '</span>');
688         // hack to undo that previous hack
689         if ( $this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0' ) {
690             $GLOBALS['dictionary']['User']['fields']['email1']['required'] = true;
691         }
692         $raw_email_link_type = $this->bean->getPreference('email_link_type');
693         if ( $this->viewType == 'EditView' ) {
694             $this->ss->assign('EMAIL_LINK_TYPE', get_select_options_with_id($app_list_strings['dom_email_link_type'], $raw_email_link_type));
695         } else {
696             $this->ss->assign('EMAIL_LINK_TYPE', $app_list_strings['dom_email_link_type'][$raw_email_link_type]);
697         }
698
699         /////   END EMAIL OPTIONS
700         ///////////////////////////////////////////////////////////////////////////////
701
702
703         /////////////////////////////////////////////
704         /// Handle email account selections for users
705         /////////////////////////////////////////////
706         $hide_if_can_use_default = true;
707         if( !($this->usertype=='GROUP' || $this->usertype=='PORTAL_ONLY') ) {
708             // email smtp
709             $systemOutboundEmail = new OutboundEmail();
710             $systemOutboundEmail = $systemOutboundEmail->getSystemMailerSettings();
711             $mail_smtpserver = $systemOutboundEmail->mail_smtpserver;
712             $mail_smtptype = $systemOutboundEmail->mail_smtptype;
713             $mail_smtpport = $systemOutboundEmail->mail_smtpport;
714             $mail_smtpssl = $systemOutboundEmail->mail_smtpssl;
715             $mail_smtpuser = "";
716             $mail_smtppass = "";
717             $mail_smtpdisplay = $systemOutboundEmail->mail_smtpdisplay;
718             $mail_smtpauth_req=true;
719
720             if( !$systemOutboundEmail->isAllowUserAccessToSystemDefaultOutbound() ) {
721                 $mail_smtpauth_req = $systemOutboundEmail->mail_smtpauth_req;
722                 $userOverrideOE = $systemOutboundEmail->getUsersMailerForSystemOverride($this->bean->id);
723                 if($userOverrideOE != null) {
724                     $mail_smtpuser = $userOverrideOE->mail_smtpuser;
725                     $mail_smtppass = $userOverrideOE->mail_smtppass;
726                 }
727
728
729                 if(!$mail_smtpauth_req && (empty($systemOutboundEmail->mail_smtpserver) || empty($systemOutboundEmail->mail_smtpuser) || empty($systemOutboundEmail->mail_smtppass))) {
730                     $hide_if_can_use_default = true;
731                 } else{
732                     $hide_if_can_use_default = false;
733                 }
734             }
735
736             $this->ss->assign("mail_smtpdisplay", $mail_smtpdisplay);
737             $this->ss->assign("mail_smtpserver", $mail_smtpserver);
738             $this->ss->assign("mail_smtpuser", $mail_smtpuser);
739             $this->ss->assign("mail_smtppass", "");
740             $this->ss->assign("mail_haspass", empty($systemOutboundEmail->mail_smtppass)?0:1);
741             $this->ss->assign("mail_smtpauth_req", $mail_smtpauth_req);
742             $this->ss->assign('MAIL_SMTPPORT',$mail_smtpport);
743             $this->ss->assign('MAIL_SMTPSSL',$mail_smtpssl);
744         }
745         $this->ss->assign('HIDE_IF_CAN_USE_DEFAULT_OUTBOUND',$hide_if_can_use_default );
746
747     }
748
749
750     /**
751      * setUserType
752      * This function is used to set the user_type variable for a given User instance
753      *
754      * @param Mixed $user The user instance to set the user_type variable on
755      * @return String value representing the user type
756      */
757     function setUserType($user)
758     {
759         //bug #49175: user's always regular
760         //need to get user_type from bean
761         $user->user_type = '';
762
763         if ($user->is_admin)
764         {
765             $user->user_type = 'Administrator';
766         }
767         else if ($user->is_group)
768         {
769             $user->user_type = 'GROUP';
770         }
771         else
772         {
773             $user->user_type = 'RegularUser';
774         }
775     }
776 }