]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/UserViewHelper.php
Release 6.4.0beta3
[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-2011 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->setupEmailSettings();
93         $this->setupPasswordTab();
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='ADMIN';
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 = "";
170         if (!$this->bean->is_group){
171             if ($this->bean->id == $current_user->id) {
172                 $reset_pref_warning = translate('LBL_RESET_PREFERENCES_WARNING','Users');
173                 $reset_home_warning = translate('LBL_RESET_HOMEPAGE_WARNING','Users');
174             }
175             else {
176                 $reset_pref_warning = translate('LBL_RESET_PREFERENCES_WARNING_USER','Users');
177                 $reset_home_warning = translate('LBL_RESET_HOMEPAGE_WARNING_USER','Users');
178             }
179             $buttons .="<input type='button' class='button' onclick='if(confirm(\"{$reset_pref_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$the_query_string."&reset_preferences=true\";' value='".translate('LBL_RESET_PREFERENCES','Users')."' />";
180             $buttons .="&nbsp;<input type='button' class='button' onclick='if(confirm(\"{$reset_home_warning}\"))window.location=\"".$_SERVER['PHP_SELF'] .'?'.$the_query_string."&reset_homepage=true\";' value='".translate('LBL_RESET_HOMEPAGE','Users')."' />";
181         }
182         if (isset($buttons)) $this->ss->assign("BUTTONS", $buttons);
183         
184
185
186         if (isset($this->bean->id)) {
187             $this->ss->assign('ID',$this->bean->id);
188         }
189         
190     }
191     protected function setupUserTypeDropdown() {
192         global $current_user;
193         
194
195         if ( !isset($this->bean->user_type) ) {
196             $this->bean->user_type = 'RegularUser';
197         }
198         $userType = $this->bean->user_type;
199         if ( $this->usertype == 'GROUP' || $this->usertype == 'PORTAL_ONLY' ) {
200             $userType = $this->usertype;
201         }
202
203
204         $availableUserTypes = array();
205         $userTypes = array(
206             'RegularUser' => array(
207                 'label' => translate('LBL_REGULAR_USER','Users'),
208                 'description' => translate('LBL_REGULAR_DESC','Users'),
209             ),
210             'GROUP' => array(
211                 'label' => translate('LBL_GROUP_USER','Users'),
212                 'description' => translate('LBL_GROUP_DESC','Users'),
213             ),
214             'Administrator' => array(
215                 'label' => translate('LBL_ADMIN_USER','Users'),
216                 'description' => translate('LBL_ADMIN_DESC','Users'),
217             ),
218         );
219
220         if ( $userType == 'GROUP' || $userType == 'PORTAL_ONLY' ) {
221             $availableUserTypes = array($this->usertype);
222         } else {
223             if ( $this->ss->get_template_vars('USER_ADMIN') ) {
224                 $availableUserTypes = array('RegularUser');
225             } elseif($this->ss->get_template_vars('ADMIN_EDIT_SELF')) {
226                 $availableUserTypes = array('Administrator');
227             } elseif($this->ss->get_template_vars('IS_SUPER_ADMIN')) {
228                 $availableUserTypes = array(
229                     'RegularUser',
230                     'Administrator',
231                     );
232             } else {
233                 $availableUserTypes = array($userType);
234             }
235         }
236
237         $userTypeDropdown = '<select id="UserType" name="UserType" onchange="user_status_display(this);" ';
238         if ( count($availableUserTypes) == 1 ) {
239             $userTypeDropdown .= ' disabled ';
240         }
241         $userTypeDropdown .= '>';
242      
243         $userTypeDescription = '';
244    
245         foreach ( $availableUserTypes as $currType ) {
246             $selected = '';
247             if ( $currType == $userType ) {
248                 $selected = 'SELECTED';
249             }
250             $userTypeDropdown .= '<option value="'.$currType.'" '.$selected.'>'.$userTypes[$currType]['label'].'</option>';
251         }
252         $userTypeDropdown .= '</select><div id="UserTypeDesc">&nbsp;</div>';
253         
254         $this->ss->assign('USER_TYPE_DROPDOWN',$userTypeDropdown);
255         $this->ss->assign('USER_TYPE_READONLY',$userTypes[$userType]['label']);
256         
257     }
258
259     protected function setupPasswordTab() {
260         global $current_user;
261         
262         $this->ss->assign('PWDSETTINGS', isset($GLOBALS['sugar_config']['passwordsetting']) ? $GLOBALS['sugar_config']['passwordsetting'] : array());
263
264
265         $enable_syst_generate_pwd=false;
266         if(isset($GLOBALS['sugar_config']['passwordsetting']) && isset($GLOBALS['sugar_config']['passwordsetting']['SystemGeneratedPasswordON'])){
267             $enable_syst_generate_pwd=$GLOBALS['sugar_config']['passwordsetting']['SystemGeneratedPasswordON'];
268         }
269
270         // If new regular user without system generated password or new portal user
271         if(((isset($enable_syst_generate_pwd) && !$enable_syst_generate_pwd && $this->usertype!='GROUP') || $this->usertype =='PORTAL_ONLY') && empty($this->bean->id)) {
272             $this->ss->assign('REQUIRED_PASSWORD','1');
273         } else {
274             $this->ss->assign('REQUIRED_PASSWORD','0');
275         }
276
277         // If my account page or portal only user or regular user without system generated password or a duplicate user
278         if((($current_user->id == $this->bean->id) || $this->usertype=='PORTAL_ONLY' || (($this->usertype=='REGULAR' || $this->usertype == 'ADMIN' || (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true' && $this->usertype!='GROUP')) && !$enable_syst_generate_pwd)) && !$this->bean->external_auth_only ) {
279             $this->ss->assign('CHANGE_PWD', '1');
280         } else {
281             $this->ss->assign('CHANGE_PWD', '0');
282         }
283         
284         // Make sure group users don't get a password change prompt
285         if ( $this->usertype == 'GROUP' ) {
286             $this->ss->assign('CHANGE_PWD', '0');
287         }
288
289         $configurator = new Configurator();
290         if ( isset($configurator->config['passwordsetting']) 
291              && ($configurator->config['passwordsetting']['SystemGeneratedPasswordON']
292                  || $configurator->config['passwordsetting']['forgotpasswordON'])
293              && $this->usertype != 'GROUP' && $this->usertype != 'PORTAL_ONLY' ) {
294             $this->ss->assign('REQUIRED_EMAIL_ADDRESS','1');
295         } else {
296             $this->ss->assign('REQUIRED_EMAIL_ADDRESS','0');
297         }
298         if($this->usertype=='GROUP' || $this->usertype=='PORTAL_ONLY') {
299             $this->ss->assign('HIDE_FOR_GROUP_AND_PORTAL', 'none');
300             $this->ss->assign('HIDE_CHANGE_USERTYPE','none');
301         } else {
302             $this->ss->assign('HIDE_FOR_NORMAL_AND_ADMIN','none');
303             if (!$this->is_current_admin) {
304                 $this->ss->assign('HIDE_CHANGE_USERTYPE','none');
305             } else {
306                 $this->ss->assign('HIDE_STATIC_USERTYPE','none');
307             }
308         }
309         
310     }
311
312     protected function setupThemeTab() {
313         $user_theme = $this->bean->getPreference('user_theme');
314         if(isset($user_theme)) {
315             $this->ss->assign("THEMES", get_select_options_with_id(SugarThemeRegistry::availableThemes(), $user_theme));
316         } else {
317             $this->ss->assign("THEMES", get_select_options_with_id(SugarThemeRegistry::availableThemes(), $GLOBALS['sugar_config']['default_theme']));
318         }
319         $this->ss->assign("SHOW_THEMES",count(SugarThemeRegistry::availableThemes()) > 1);
320         $this->ss->assign("USER_THEME_COLOR", $this->bean->getPreference('user_theme_color'));
321         $this->ss->assign("USER_THEME_FONT", $this->bean->getPreference('user_theme_font'));
322         $this->ss->assign("USER_THEME", $user_theme);
323         
324 // Build a list of themes that support group modules
325         $this->ss->assign("DISPLAY_GROUP_TAB", 'none');
326         
327         $selectedTheme = $user_theme;
328         if(!isset($user_theme)) {
329             $selectedTheme = $GLOBALS['sugar_config']['default_theme'];
330         }
331         
332         $themeList = SugarThemeRegistry::availableThemes();
333         $themeGroupList = array();
334         
335         foreach ( $themeList as $themeId => $themeName ) {
336             $currThemeObj = SugarThemeRegistry::get($themeId);
337             if ( isset($currThemeObj->group_tabs) && $currThemeObj->group_tabs == 1 ) {
338                 $themeGroupList[$themeId] = true;
339                 if ( $themeId == $selectedTheme ) {
340                     $this->ss->assign("DISPLAY_GROUP_TAB", '');
341                 }
342             } else {
343                 $themeGroupList[$themeId] = false;
344             }
345         }
346         $this->ss->assign("themeGroupListJSON",json_encode($themeGroupList));
347         
348     }
349     
350     protected function setupAdvancedTab() {
351         $this->setupAdvancedTabUserSettings();
352         $this->setupAdvancedTabTeamSettings();
353         $this->setupAdvancedTabNavSettings();
354         $this->setupAdvancedTabLocaleSettings();
355         $this->setupAdvancedTabPdfSettings();
356     }
357
358     protected function setupAdvancedTabUserSettings() {
359         global $current_user, $locale, $app_strings, $app_list_strings, $sugar_config;
360         // This is for the "Advanced" tab, it's not controlled by the metadata UI so we have to do more for it.
361
362         $this->ss->assign('EXPORT_DELIMITER', $this->bean->getPreference('export_delimiter'));
363
364         if($this->bean->receive_notifications ||(!isset($this->bean->id) && $admin->settings['notify_send_by_default'])) $this->ss->assign("RECEIVE_NOTIFICATIONS", "checked");
365
366         //jc:12293 - modifying to use the accessor method which will translate the
367         //available character sets using the translation files
368         $export_charset = $locale->getExportCharset('', $this->bean);
369         $export_charset_options = $locale->getCharsetSelect();
370         $this->ss->assign('EXPORT_CHARSET', get_select_options_with_id($export_charset_options, $export_charset));
371         $this->ss->assign('EXPORT_CHARSET_DISPLAY', $export_charset);
372         //end:12293
373
374         if( $this->bean->getPreference('use_real_names') == 'on' 
375             || ( empty($this->bean->id) 
376                  && isset($GLOBALS['sugar_config']['use_real_names']) 
377                  && $GLOBALS['sugar_config']['use_real_names'] 
378                  && $this->bean->getPreference('use_real_names') != 'off') ) {
379             $this->ss->assign('USE_REAL_NAMES', 'CHECKED');
380         }
381
382         if($this->bean->getPreference('mailmerge_on') == 'on') {
383             $this->ss->assign('MAILMERGE_ON', 'checked');
384         }
385
386         if($this->bean->getPreference('no_opps') == 'on') {
387             $this->ss->assign('NO_OPPS', 'CHECKED');
388         }
389
390         $reminder_time = $this->bean->getPreference('reminder_time');
391         if(empty($reminder_time)){
392             $reminder_time = -1;
393         }
394         $this->ss->assign("REMINDER_TIME_OPTIONS", get_select_options_with_id($app_list_strings['reminder_time_options'],$reminder_time));
395         if($reminder_time > -1){
396             $this->ss->assign("REMINDER_TIME_DISPLAY", 'inline');
397             $this->ss->assign("REMINDER_CHECKED", 'checked');
398             $this->ss->assign("REMINDER_TIME", $app_list_strings['reminder_time_options'][$reminder_time]);
399         }else{
400             $this->ss->assign("REMINDER_TIME_DISPLAY", 'none');
401         }
402         $this->ss->assign('CALENDAR_PUBLISH_KEY', $this->bean->getPreference('calendar_publish_key' ));
403
404         $publish_url = $sugar_config['site_url'].'/vcal_server.php';
405         $token = "/";
406         //determine if the web server is running IIS
407         //if so then change the publish url
408         if(isset($_SERVER) && !empty($_SERVER['SERVER_SOFTWARE'])){
409             $position = strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'iis');
410             if($position !== false){
411                 $token = '?parms=';
412             }
413         }
414         
415         $publish_url .= $token.'type=vfb&source=outlook&key='.$this->bean->getPreference('calendar_publish_key' );
416         if (! empty($this->bean->email1)) {
417             $publish_url .= '&email='.$this->bean->email1;
418         } else {
419             $publish_url .= '&user_name='.$this->bean->user_name;
420         }
421         $this->ss->assign("CALENDAR_PUBLISH_URL", $publish_url);
422         $this->ss->assign("CALENDAR_SEARCH_URL", $sugar_config['site_url'].'/vcal_server.php/type=vfb&email=%NAME%@%SERVER%');
423         
424
425         $this->ss->assign("SETTINGS_URL", $sugar_config['site_url']);
426
427     }
428
429     protected function setupAdvancedTabTeamSettings() {
430         global $sugar_config;
431
432         $authclass = '';
433         if(!empty($sugar_config['authenticationClass'])){
434             $this->ss->assign('EXTERNAL_AUTH_CLASS_1', $sugar_config['authenticationClass']);
435             $this->ss->assign('EXTERNAL_AUTH_CLASS', $sugar_config['authenticationClass']);
436             $authclass = $sugar_config['authenticationClass'];
437         }else{
438             if(!empty($GLOBALS['system_config']->settings['system_ldap_enabled'])){
439                 $this->ss->assign('EXTERNAL_AUTH_CLASS_1', translate('LBL_LDAP','Users'));
440                 $this->ss->assign('EXTERNAL_AUTH_CLASS', translate('LBL_LDAP_AUTHENTICATION','Users'));
441                 $authclass = 'LDAPAuthenticate';
442             }
443         }
444         if(!empty($this->bean->external_auth_only)) {
445             $this->ss->assign('EXTERNAL_AUTH_ONLY_CHECKED', 'CHECKED');
446         }
447         
448         if($this->is_super_admin && !empty($authclass)) {
449             $this->ss->assign('DISPLAY_EXTERNAL_AUTH',true);
450         }
451         
452     }
453
454     protected function setupAdvancedTabNavSettings() {
455         global $app_list_strings;
456
457         // Grouped tabs?
458         $useGroupTabs = $this->bean->getPreference('navigation_paradigm');
459         if ( ! isset($useGroupTabs) ) {
460             if ( ! isset($GLOBALS['sugar_config']['default_navigation_paradigm']) ) {
461                 $GLOBALS['sugar_config']['default_navigation_paradigm'] = 'gm';
462             }
463             $useGroupTabs = $GLOBALS['sugar_config']['default_navigation_paradigm'];
464         }
465         $this->ss->assign("USE_GROUP_TABS",($useGroupTabs=='gm')?'checked':'');
466         
467         $user_max_tabs = $this->bean->getPreference('max_tabs');
468         if(isset($user_max_tabs) && $user_max_tabs > 0) {
469             $this->ss->assign("MAX_TAB", $user_max_tabs);
470         } elseif(SugarThemeRegistry::current()->maxTabs > 0) {
471             $this->ss->assign("MAX_TAB", SugarThemeRegistry::current()->maxTabs);
472         } else {
473             $this->ss->assign("MAX_TAB", $GLOBALS['sugar_config']['default_max_tabs']);
474         }
475         $this->ss->assign("MAX_TAB_OPTIONS", range(1, ((!empty($GLOBALS['sugar_config']['default_max_tabs']) && $GLOBALS['sugar_config']['default_max_tabs'] > 10 ) ? $GLOBALS['sugar_config']['default_max_tabs'] : 10)));
476         
477         $user_subpanel_tabs = $this->bean->getPreference('subpanel_tabs');
478         if(isset($user_subpanel_tabs)) {
479             $this->ss->assign("SUBPANEL_TABS", $user_subpanel_tabs?'checked':'');
480         } else {
481             $this->ss->assign("SUBPANEL_TABS", $GLOBALS['sugar_config']['default_subpanel_tabs']?'checked':'');
482         }
483
484         /* Module Tab Chooser */
485         require_once('include/templates/TemplateGroupChooser.php');
486         require_once('modules/MySettings/TabController.php');
487         $chooser = new TemplateGroupChooser();
488         $controller = new TabController();
489         
490         
491         if($this->is_current_admin || $controller->get_users_can_edit()) {
492             $chooser->display_hide_tabs = true;
493         } else {
494             $chooser->display_hide_tabs = false;
495         }
496
497         $chooser->args['id'] = 'edit_tabs';
498         $chooser->args['values_array'] = $controller->get_tabs($this->bean);
499         foreach($chooser->args['values_array'][0] as $key=>$value) {
500             $chooser->args['values_array'][0][$key] = $app_list_strings['moduleList'][$key];
501         }
502         
503         foreach($chooser->args['values_array'][1] as $key=>$value) {
504             $chooser->args['values_array'][1][$key] = $app_list_strings['moduleList'][$key];
505         }
506         
507         foreach($chooser->args['values_array'][2] as $key=>$value) {
508             $chooser->args['values_array'][2][$key] = $app_list_strings['moduleList'][$key];
509         }
510         
511         $chooser->args['left_name'] = 'display_tabs';
512         $chooser->args['right_name'] = 'hide_tabs';
513         
514         $chooser->args['left_label'] =  translate('LBL_DISPLAY_TABS','Users');
515         $chooser->args['right_label'] =  translate('LBL_HIDE_TABS','Users');
516         $chooser->args['title'] =  translate('LBL_EDIT_TABS','Users').' <!--not_in_theme!--><img border="0" src="themes/default/images/helpInline.gif" onmouseover="return overlib(\'Choose which tabs are displayed.\', FGCLASS, \'olFgClass\', CGCLASS, \'olCgClass\', BGCLASS, \'olBgClass\', TEXTFONTCLASS, \'olFontClass\', CAPTIONFONTCLASS, \'olCapFontClass\', CLOSEFONTCLASS, \'olCloseFontClass\', WIDTH, -1, NOFOLLOW, \'ol_nofollow\' );" onmouseout="return nd();"/>';
517         
518         $this->ss->assign('TAB_CHOOSER', $chooser->display());
519         $this->ss->assign('CHOOSER_SCRIPT','set_chooser();');
520         $this->ss->assign('CHOOSE_WHICH', translate('LBL_CHOOSE_WHICH','Users'));
521         
522     }
523
524     protected function setupAdvancedTabLocaleSettings() {
525         global $locale, $sugar_config, $app_list_strings;
526
527         ///////////////////////////////////////////////////////////////////////////////
528         ////    LOCALE SETTINGS
529         ////    Date/time format
530         $dformat = $locale->getPrecedentPreference($this->bean->id?'datef':'default_date_format', $this->bean);
531         $tformat = $locale->getPrecedentPreference($this->bean->id?'timef':'default_time_format', $this->bean);
532         $nformat = $locale->getPrecedentPreference('default_locale_name_format', $this->bean);
533         $timeOptions = get_select_options_with_id($sugar_config['time_formats'], $tformat);
534         $dateOptions = get_select_options_with_id($sugar_config['date_formats'], $dformat);
535         $nameOptions = get_select_options_with_id($locale->getPrettyLocaleNameOptions($sugar_config['name_formats']), $nformat);
536         $this->ss->assign('TIMEOPTIONS', $timeOptions);
537         $this->ss->assign('DATEOPTIONS', $dateOptions);
538         $this->ss->assign('NAMEOPTIONS', $nameOptions);
539         $this->ss->assign('DATEFORMAT', $sugar_config['date_formats'][$dformat]);
540         $this->ss->assign('TIMEFORMAT', $sugar_config['time_formats'][$tformat]);
541         $this->ss->assign('NAMEFORMAT', $sugar_config['name_formats'][$nformat]);
542
543         //// Timezone
544         if(empty($this->bean->id)) { // remove default timezone for new users(set later)
545             $this->bean->user_preferences['timezone'] = '';
546         }
547         
548         $userTZ = $this->bean->getPreference('timezone');
549         
550         if(empty($userTZ) && !$this->bean->is_group && !$this->bean->portal_only) {
551             $userTZ = TimeDate::guessTimezone();
552             $this->bean->setPreference('timezone', $userTZ);
553         }
554         
555         if(!$this->bean->getPreference('ut')) {
556             $this->ss->assign('PROMPTTZ', ' checked');
557         }
558         $this->ss->assign('TIMEZONE_CURRENT', $userTZ);
559         $this->ss->assign('TIMEZONEOPTIONS', TimeDate::getTimezoneList());
560         $this->ss->assign("TIMEZONE", TimeDate::tzName($userTZ));
561
562         
563         // FG - Bug 4236 - Managed First Day of Week
564         $fdowDays = array();
565         foreach ($app_list_strings['dom_cal_day_long'] as $d) {
566             if ($d != "") {
567                 $fdowDays[] = $d;
568             }
569         }
570         $this->ss->assign("FDOWOPTIONS", $fdowDays);
571         $currentFDOW = $this->bean->get_first_day_of_week();
572
573         if (!isset($currentFDOW)) {$currentFDOW = 0;}
574         $this->ss->assign("FDOWCURRENT", $currentFDOW);
575         $this->ss->assign("FDOWDISPLAY", $app_list_strings['dom_cal_day_long'][$currentFDOW]);
576
577         //// Numbers and Currency display
578         require_once('modules/Currencies/ListCurrency.php');
579         $currency = new ListCurrency();
580         
581         // 10/13/2006 Collin - Changed to use Localization.getConfigPreference
582         // This was the problem- Previously, the "-99" currency id always assumed
583         // to be defaulted to US Dollars.  However, if someone set their install to use
584         // Euro or other type of currency then this setting would not apply as the
585         // default because it was being overridden by US Dollars.
586         $cur_id = $locale->getPrecedentPreference('currency', $this->bean);
587         if($cur_id) {
588             $selectCurrency = $currency->getSelectOptions($cur_id);
589             $this->ss->assign("CURRENCY", $selectCurrency);
590         } else {
591             $selectCurrency = $currency->getSelectOptions();
592             $this->ss->assign("CURRENCY", $selectCurrency);
593         }
594         
595         $currencyList = array();
596         foreach($locale->currencies as $id => $val ) {
597             $currencyList[$id] = $val['symbol'];
598         }
599         $currencySymbolJSON = json_encode($currencyList);
600         $this->ss->assign('currencySymbolJSON', $currencySymbolJSON);
601         
602         $currencyDisplay = new Currency();
603         if(isset($cur_id) ) {
604             $currencyDisplay->retrieve($cur_id);
605             $this->ss->assign('CURRENCY_DISPLAY', $currencyDisplay->iso4217 .' '.$currencyDisplay->symbol );
606         } else {
607             $this->ss->assign("CURRENCY_DISPLAY", $currencyDisplay->getDefaultISO4217() .' '.$currencyDisplay->getDefaultCurrencySymbol() );
608         }
609         
610         // fill significant digits dropdown
611         $significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $this->bean);
612         $sigDigits = '';
613         for($i=0; $i<=6; $i++) {
614             if($significantDigits == $i) {
615                 $sigDigits .= "<option value=\"$i\" selected=\"true\">$i</option>";
616             } else {
617                 $sigDigits .= "<option value=\"$i\">{$i}</option>";
618             }
619         }
620         
621         $this->ss->assign('sigDigits', $sigDigits);
622         $this->ss->assign('CURRENCY_SIG_DIGITS', $significantDigits);
623         
624         $num_grp_sep = $this->bean->getPreference('num_grp_sep');
625         $dec_sep = $this->bean->getPreference('dec_sep');
626         $this->ss->assign("NUM_GRP_SEP",(empty($num_grp_sep) ? $GLOBALS['sugar_config']['default_number_grouping_seperator'] : $num_grp_sep));
627         $this->ss->assign("DEC_SEP",(empty($dec_sep) ? $GLOBALS['sugar_config']['default_decimal_seperator'] : $dec_sep));
628         $this->ss->assign('getNumberJs', $locale->getNumberJs());
629         
630         //// Name display format
631         $this->ss->assign('default_locale_name_format', $locale->getLocaleFormatMacro($this->bean));
632         $this->ss->assign('getNameJs', $locale->getNameJs());
633         $this->ss->assign('NAME_FORMAT', $this->bean->getLocaleFormatDesc());
634         ////    END LOCALE SETTINGS
635     }
636
637     protected function setupAdvancedTabPdfSettings() {
638     }
639     
640     protected function setupEmailSettings() {
641         global $current_user, $app_list_strings;
642
643         $this->ss->assign("MAIL_SENDTYPE", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $this->bean->getPreference('mail_sendtype')));
644
645         ///////////////////////////////////////////////////////////////////////////////
646         ////    EMAIL OPTIONS
647         // We need to turn off the requiredness of emails if it is a group or portal user
648         if ($this->usertype == 'GROUP' || $this->usertype == 'PORTAL_ONLY' ) {
649             global $dictionary;
650             $dictionary['User']['fields']['email1']['required'] = false;
651         }
652         // hack to disable email field being required if it shouldn't be required
653         if ( $this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0' ) {
654             $GLOBALS['dictionary']['User']['fields']['email1']['required'] = false;
655         }
656         $this->ss->assign("NEW_EMAIL", getEmailAddressWidget($this->bean, "email1", $this->bean->email1, $this->viewType));
657         // hack to undo that previous hack
658         if ( $this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0' ) {
659             $GLOBALS['dictionary']['User']['fields']['email1']['required'] = true;
660         }
661         $raw_email_link_type = $this->bean->getPreference('email_link_type');
662         if ( $this->viewType == 'EditView' ) {
663             $this->ss->assign('EMAIL_LINK_TYPE', get_select_options_with_id($app_list_strings['dom_email_link_type'], $raw_email_link_type));
664         } else {
665             $this->ss->assign('EMAIL_LINK_TYPE', $app_list_strings['dom_email_link_type'][$raw_email_link_type]);
666         }
667         
668         /////   END EMAIL OPTIONS
669         ///////////////////////////////////////////////////////////////////////////////
670         
671
672         /////////////////////////////////////////////
673         /// Handle email account selections for users
674         /////////////////////////////////////////////
675         $hide_if_can_use_default = true;
676         if( !($this->usertype=='GROUP' || $this->usertype=='PORTAL_ONLY') ) {
677             // email smtp
678             $systemOutboundEmail = new OutboundEmail();
679             $systemOutboundEmail = $systemOutboundEmail->getSystemMailerSettings();
680             $mail_smtpserver = $systemOutboundEmail->mail_smtpserver;
681             $mail_smtptype = $systemOutboundEmail->mail_smtptype;
682             $mail_smtpport = $systemOutboundEmail->mail_smtpport;
683             $mail_smtpssl = $systemOutboundEmail->mail_smtpssl;
684             $mail_smtpuser = "";
685             $mail_smtppass = "";
686             $mail_smtpdisplay = $systemOutboundEmail->mail_smtpdisplay;
687             $hide_if_can_use_default = true;
688             $mail_smtpauth_req=true;
689             
690             if( !$systemOutboundEmail->isAllowUserAccessToSystemDefaultOutbound() ) {
691                 $mail_smtpauth_req = $systemOutboundEmail->mail_smtpauth_req;
692                 $userOverrideOE = $systemOutboundEmail->getUsersMailerForSystemOverride($this->bean->id);
693                 if($userOverrideOE != null) {
694                     $mail_smtpuser = $userOverrideOE->mail_smtpuser;
695                     $mail_smtppass = $userOverrideOE->mail_smtppass;
696                 }
697                 
698                 
699                 if(!$mail_smtpauth_req &&
700                    ( empty($systemOutboundEmail->mail_smtpserver) || empty($systemOutboundEmail->mail_smtpuser)
701                      || empty($systemOutboundEmail->mail_smtppass))) {
702                     $hide_if_can_use_default = true;
703                 } else{
704                     $hide_if_can_use_default = false;
705                 }
706             }
707             
708             $this->ss->assign("mail_smtpdisplay", $mail_smtpdisplay);
709             $this->ss->assign("mail_smtpserver", $mail_smtpserver);
710             $this->ss->assign("mail_smtpuser", $mail_smtpuser);
711             $this->ss->assign("mail_smtppass", "");
712             $this->ss->assign("mail_haspass", empty($systemOutboundEmail->mail_smtppass)?0:1);
713             $this->ss->assign("mail_smtpauth_req", $mail_smtpauth_req);
714             $this->ss->assign('MAIL_SMTPPORT',$mail_smtpport);
715             $this->ss->assign('MAIL_SMTPSSL',$mail_smtpssl);
716         }
717         $this->ss->assign('HIDE_IF_CAN_USE_DEFAULT_OUTBOUND',$hide_if_can_use_default );
718         
719     }
720 }