]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/views/view.wizard.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Users / views / view.wizard.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
40  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
41  * All Rights Reserved.
42  * Contributor(s): ______________________________________..
43  ********************************************************************************/
44
45 require_once('modules/Users/Forms.php');
46 require_once('modules/Configurator/Configurator.php');
47
48 /**
49  * ViewWireless_Login extends SugarWirelessView and is the login view.
50  */
51 class ViewWizard extends SugarView
52 {
53         /**
54          * Constructor for the view, it runs the constructor of SugarWirelessView and
55          * sets the footer option to true (it is off in the SugarWirelessView constructor)
56          */
57         public function __construct()
58         {
59                 parent::SugarView();
60
61         $this->options['show_header'] = false;
62         $this->options['show_footer'] = false;
63         $this->options['show_javascript'] = false;
64         }
65
66         /**
67          * @see SugarView::display()
68          */
69         public function display()
70     {
71         global $mod_strings, $current_user, $locale, $sugar_config, $app_list_strings, $sugar_version;
72
73                 $themeObject = SugarThemeRegistry::current();
74                 $css = $themeObject->getCSS();
75                 $this->ss->assign('SUGAR_CSS', $css);
76         $favicon = $themeObject->getImageURL('sugar_icon.ico',false);
77         $this->ss->assign('FAVICON_URL',getJSPath($favicon));
78         $this->ss->assign('CSS', '<link rel="stylesheet" type="text/css" href="'.SugarThemeRegistry::current()->getCSSURL('wizard.css').'" />');
79             $this->ss->assign('JAVASCRIPT',user_get_validate_record_js().user_get_chooser_js().user_get_confsettings_js());
80                 $this->ss->assign('PRINT_URL', 'index.php?'.$GLOBALS['request_string']);
81                 $this->ss->assign('SKIP_WELCOME',isset($_REQUEST['skipwelcome']) && $_REQUEST['skipwelcome'] == 1);
82                 $this->ss->assign('ID', $current_user->id);
83                 $this->ss->assign('USER_NAME', $current_user->user_name);
84                 $this->ss->assign('FIRST_NAME', $current_user->first_name);
85                 $this->ss->assign('SUGAR_VERSION', $sugar_version);
86                 $this->ss->assign('LAST_NAME', $current_user->last_name);
87                 $this->ss->assign('TITLE', $current_user->title);
88                 $this->ss->assign('DEPARTMENT', $current_user->department);
89                 $this->ss->assign('REPORTS_TO_ID', $current_user->reports_to_id);
90                 $this->ss->assign('REPORTS_TO_NAME', $current_user->reports_to_name);
91                 $this->ss->assign('PHONE_HOME', $current_user->phone_home);
92                 $this->ss->assign('PHONE_MOBILE', $current_user->phone_mobile);
93                 $this->ss->assign('PHONE_WORK', $current_user->phone_work);
94                 $this->ss->assign('PHONE_OTHER', $current_user->phone_other);
95                 $this->ss->assign('PHONE_FAX', $current_user->phone_fax);
96                 $this->ss->assign('EMAIL1', $current_user->email1);
97                 $this->ss->assign('EMAIL2', $current_user->email2);
98                 $this->ss->assign('ADDRESS_STREET', $current_user->address_street);
99                 $this->ss->assign('ADDRESS_CITY', $current_user->address_city);
100                 $this->ss->assign('ADDRESS_STATE', $current_user->address_state);
101                 $this->ss->assign('ADDRESS_POSTALCODE', $current_user->address_postalcode);
102                 $this->ss->assign('ADDRESS_COUNTRY', $current_user->address_country);
103                 $configurator = new Configurator();
104                 if ( $configurator->config['passwordsetting']['SystemGeneratedPasswordON']
105                         || $configurator->config['passwordsetting']['forgotpasswordON'] )
106                     $this->ss->assign('REQUIRED_EMAIL_ADDRESS','1');
107         else
108             $this->ss->assign('REQUIRED_EMAIL_ADDRESS','0');
109
110                 // get javascript
111         ob_start();
112         $this->options['show_javascript'] = true;
113         $this->renderJavascript();
114         $this->options['show_javascript'] = false;
115         $this->ss->assign("SUGAR_JS",ob_get_contents().$themeObject->getJS());
116         ob_end_clean();
117
118                 $messenger_type = '<select tabindex="5" name="messenger_type">';
119         $messenger_type .= get_select_options_with_id($app_list_strings['messenger_type_dom'], $current_user->messenger_type);
120         $messenger_type .= '</select>';
121         $this->ss->assign('MESSENGER_TYPE_OPTIONS', $messenger_type);
122         $this->ss->assign('MESSENGER_ID', $current_user->messenger_id);
123
124         // set default settings
125         $use_real_names = $current_user->getPreference('use_real_names');
126         if ( empty($use_real_names) )
127             $current_user->setPreference('use_real_names', 'on');
128         $current_user->setPreference('reminder_time', 1800);
129         $current_user->setPreference('mailmerge_on', 'on');
130
131                 //// Timezone
132         if(empty($current_user->id)) { // remove default timezone for new users(set later)
133             $current_user->user_preferences['timezone'] = '';
134         }
135
136         $userTZ = $current_user->getPreference('timezone');
137         if(empty($userTZ) && !$current_user->is_group && !$current_user->portal_only) {
138             $userTZ = TimeDate::guessTimezone();
139             $current_user->setPreference('timezone', $userTZ);
140         }
141
142         if(!$current_user->getPreference('ut')) {
143                         $this->ss->assign('PROMPTTZ', ' checked');
144         }
145
146         $this->ss->assign('TIMEZONE_CURRENT', $userTZ);
147         $this->ss->assign('TIMEZONEOPTIONS', TimeDate::getTimezoneList());
148
149         //// Numbers and Currency display
150         require_once('modules/Currencies/ListCurrency.php');
151         $currency = new ListCurrency();
152
153         // 10/13/2006 Collin - Changed to use Localization.getConfigPreference
154         // This was the problem- Previously, the "-99" currency id always assumed
155         // to be defaulted to US Dollars.  However, if someone set their install to use
156         // Euro or other type of currency then this setting would not apply as the
157         // default because it was being overridden by US Dollars.
158         $cur_id = $locale->getPrecedentPreference('currency', $current_user);
159         if($cur_id) {
160             $selectCurrency = $currency->getSelectOptions($cur_id);
161                         $this->ss->assign("CURRENCY", $selectCurrency);
162         } else {
163             $selectCurrency = $currency->getSelectOptions();
164                         $this->ss->assign("CURRENCY", $selectCurrency);
165         }
166
167         $currenciesArray = $locale->currencies;
168         $currenciesVars = $this->correctCurrenciesSymbolsSort($currenciesArray);
169
170         $currencySymbolsJs = <<<eoq
171 var currencies = new Object;
172 {$currenciesVars}
173 function setSymbolValue(id) {
174         document.getElementById('symbol').value = currencies[id];
175 }
176 eoq;
177                 $this->ss->assign('currencySymbolJs', $currencySymbolsJs);
178
179
180         // fill significant digits dropdown
181         $significantDigits = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
182         $sigDigits = '';
183         for($i=0; $i<=6; $i++) {
184             if($significantDigits == $i) {
185                $sigDigits .= "<option value=\"$i\" selected=\"true\">$i</option>";
186             } else {
187                $sigDigits .= "<option value=\"$i\">{$i}</option>";
188             }
189         }
190
191                 $this->ss->assign('sigDigits', $sigDigits);
192
193                 $num_grp_sep = $current_user->getPreference('num_grp_sep');
194                 $dec_sep = $current_user->getPreference('dec_sep');
195                 $this->ss->assign("NUM_GRP_SEP",(empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep));
196                 $this->ss->assign("DEC_SEP",(empty($dec_sep) ? $sugar_config['default_decimal_seperator'] : $dec_sep));
197                 $this->ss->assign('getNumberJs', $locale->getNumberJs());
198
199                 //// Name display format
200                 $this->ss->assign('default_locale_name_format', $locale->getLocaleFormatMacro($current_user));
201                 $this->ss->assign('getNameJs', $locale->getNameJs());
202
203                 $this->ss->assign('TIMEOPTIONS', get_select_options_with_id($sugar_config['time_formats'], $current_user->_userPreferenceFocus->getDefaultPreference('default_time_format')));
204                 $this->ss->assign('DATEOPTIONS', get_select_options_with_id($sugar_config['date_formats'], $current_user->_userPreferenceFocus->getDefaultPreference('default_date_format')));
205                 $this->ss->assign("MAIL_SENDTYPE", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $current_user->getPreference('mail_sendtype')));
206                 $this->ss->assign("NEW_EMAIL", $current_user->emailAddress->getEmailAddressWidgetEditView($current_user->id, $current_user->module_dir));
207                 $this->ss->assign('EMAIL_LINK_TYPE', get_select_options_with_id($app_list_strings['dom_email_link_type'], $current_user->getPreference('email_link_type')));
208
209         $selectedLocaleNameFormat = $current_user->_userPreferenceFocus->getDefaultPreference('default_locale_name_format');
210         if (array_key_exists($selectedLocaleNameFormat, $sugar_config['name_formats'])) {
211             $selectedLocaleNameFormat = $sugar_config['default_locale_name_format'];
212         }
213         $this->ss->assign('NAMEOPTIONS', get_select_options_with_id($locale->getUsableLocaleNameOptions($sugar_config['name_formats']), $selectedLocaleNameFormat));
214
215                 // email smtp
216                 $systemOutboundEmail = new OutboundEmail();
217         $systemOutboundEmail = $systemOutboundEmail->getSystemMailerSettings();
218         $mail_smtpserver = $systemOutboundEmail->mail_smtpserver;
219         $mail_smtptype = $systemOutboundEmail->mail_smtptype;
220         $mail_smtpport = $systemOutboundEmail->mail_smtpport;
221         $mail_smtpssl = $systemOutboundEmail->mail_smtpssl;
222         $mail_smtpdisplay = $systemOutboundEmail->mail_smtpdisplay;
223         $mail_smtpuser = "";
224         $mail_smtppass = "";
225         $hide_if_can_use_default = true;
226         $mail_smtpauth_req=true;
227         if(!empty($mail_smtpserver) && !empty($mail_smtptype)) {
228             if( !$systemOutboundEmail->isAllowUserAccessToSystemDefaultOutbound() )
229             {
230
231                 $mail_smtpauth_req = $systemOutboundEmail->mail_smtpauth_req;
232                 $userOverrideOE = $systemOutboundEmail->getUsersMailerForSystemOverride($current_user->id);
233                 if($userOverrideOE != null) {
234                     $mail_smtpuser = $userOverrideOE->mail_smtpuser;
235                     $mail_smtppass = $userOverrideOE->mail_smtppass;
236                 }
237                 if(!$mail_smtpauth_req &&
238                     (empty($systemOutboundEmail->mail_smtpserver) || empty($systemOutboundEmail->mail_smtpuser)
239                      || empty($systemOutboundEmail->mail_smtppass)))
240                {
241                     $hide_if_can_use_default = true;
242                 }
243                 else{
244                     $hide_if_can_use_default = false;
245                 }
246             }
247         }
248
249         $isAdmin = is_admin($current_user);
250         $this->ss->assign('IS_ADMIN', $isAdmin);
251
252         $this->ss->assign("mail_smtpdisplay", $mail_smtpdisplay);
253         $this->ss->assign("mail_smtpuser", $mail_smtpuser);
254         $this->ss->assign("mail_smtppass", $mail_smtppass);
255         $this->ss->assign('mail_smtpserver',$mail_smtpserver);
256         $this->ss->assign("mail_smtpauth_req", $mail_smtpauth_req);
257         $this->ss->assign('MAIL_SMTPPORT',$mail_smtpport);
258         $this->ss->assign('MAIL_SMTPSSL',$mail_smtpssl);
259
260         $this->ss->assign('HIDE_IF_CAN_USE_DEFAULT_OUTBOUND',$hide_if_can_use_default);
261         $this->ss->assign('langHeader', get_language_header());
262                 $this->ss->display($this->getCustomFilePathIfExists('modules/Users/tpls/wizard.tpl'));
263         }
264
265     /**
266      * Function to sort currencies in array alphabetically, except for US Dollar which must remain as first element
267      * in the array.
268      *
269      * @param array $currenciesArray Array of currencies to sort
270      * @return array|string Array of sorted currencies with the US Dollar as the first
271      */
272     public function correctCurrenciesSymbolsSort($currenciesArray)
273     {
274         $baseCurrencyId = '-99';
275         $newCurrenciesArray = array ();
276
277         $newCurrenciesArray[] = $currenciesArray[$baseCurrencyId]['symbol'];
278         array_shift($currenciesArray);
279         $currenciesArray = array_csort($currenciesArray);
280         foreach ($currenciesArray as $value)
281         {
282             $newCurrenciesArray[] = $value['symbol'];
283         }
284         return $this->pushCurrencyArrayToString($newCurrenciesArray);
285     }
286
287     /**
288      * Generates javascript array from a php array
289      *
290      * @see correctCurrenciesSymbolsSort
291      * @param $array
292      * @return array|string Javascript code snippet of currencies array
293      */
294     public function pushCurrencyArrayToString($array)
295     {
296         $return = '';
297         foreach($array as $key => $value)
298         {
299             $return .= "currencies[{$key}] = '{$value}';\n";
300         }
301         return $return;
302     }
303 }
304