2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
31 import('ttUserHelper');
32 import('ttRoleHelper');
35 if (!ttAccessAllowed('manage_own_settings')) {
36 header('Location: access_denied.php');
39 // End of access checks.
41 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
42 $can_manage_account = $user->can('manage_own_account');
44 if ($request->isPost()) {
45 $cl_name = trim($request->getParameter('name'));
46 $cl_login = trim($request->getParameter('login'));
47 if (!$auth->isPasswordExternal()) {
48 $cl_password1 = $request->getParameter('password1');
49 $cl_password2 = $request->getParameter('password2');
51 $cl_email = trim($request->getParameter('email'));
53 if ($user->canManageTeam()) {
54 $cl_team = trim($request->getParameter('team_name'));
55 $cl_currency = trim($request->getParameter('currency'));
56 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
57 $cl_lang = $request->getParameter('lang');
58 $cl_decimal_mark = $request->getParameter('decimal_mark');
59 $cl_date_format = $request->getParameter('date_format');
60 $cl_time_format = $request->getParameter('time_format');
61 $cl_start_week = $request->getParameter('start_week');
62 $cl_show_holidays = $request->getParameter('show_holidays');
63 $cl_tracking_mode = $request->getParameter('tracking_mode');
64 $cl_project_required = $request->getParameter('project_required');
65 $cl_task_required = $request->getParameter('task_required');
66 $cl_record_type = $request->getParameter('record_type');
67 $cl_punch_mode = $request->getParameter('punch_mode');
68 $cl_allow_overlap = $request->getParameter('allow_overlap');
69 $cl_future_entries = $request->getParameter('future_entries');
70 $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
71 $cl_bcc_email = trim($request->getParameter('bcc_email'));
74 $cl_charts = $request->getParameter('charts');
75 $cl_clients = $request->getParameter('clients');
76 $cl_client_required = $request->getParameter('client_required');
77 $cl_invoices = $request->getParameter('invoices');
78 $cl_paid_status = $request->getParameter('paid_status');
79 $cl_custom_fields = $request->getParameter('custom_fields');
80 $cl_expenses = $request->getParameter('expenses');
81 $cl_tax_expenses = $request->getParameter('tax_expenses');
82 $cl_notifications = $request->getParameter('notifications');
83 $cl_locking = $request->getParameter('locking');
84 $cl_quotas = $request->getParameter('quotas');
85 $cl_week_view = $request->getParameter('week_view');
88 $cl_name = $user->name;
89 $cl_login = $user->login;
90 $cl_email = $user->email;
91 if ($user->canManageTeam()) {
92 $cl_team = $user->team;
93 $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
94 $cl_lang = $user->lang;
95 $cl_decimal_mark = $user->decimal_mark;
96 $cl_date_format = $user->date_format;
97 $cl_time_format = $user->time_format;
98 $cl_start_week = $user->week_start;
99 $cl_show_holidays = $user->show_holidays;
100 $cl_tracking_mode = $user->tracking_mode;
101 $cl_project_required = $user->project_required;
102 $cl_task_required = $user->task_required;
103 $cl_record_type = $user->record_type;
104 $cl_punch_mode = $user->punch_mode;
105 $cl_allow_overlap = $user->allow_overlap;
106 $cl_future_entries = $user->future_entries;
107 $cl_uncompleted_indicators = $user->uncompleted_indicators;
108 $cl_bcc_email = $user->bcc_email;
110 // Which plugins do we have enabled?
111 $plugins = explode(',', $user->plugins);
112 $cl_charts = in_array('ch', $plugins);
113 $cl_clients = in_array('cl', $plugins);
114 $cl_client_required = in_array('cm', $plugins);
115 $cl_invoices = in_array('iv', $plugins);
116 $cl_paid_status = in_array('ps', $plugins);
117 $cl_custom_fields = in_array('cf', $plugins);
118 $cl_expenses = in_array('ex', $plugins);
119 $cl_tax_expenses = in_array('et', $plugins);
120 $cl_notifications = in_array('no', $plugins);
121 $cl_locking = in_array('lk', $plugins);
122 $cl_quotas = in_array('mq', $plugins);
123 $cl_week_view = in_array('wv', $plugins);
127 $form = new Form('profileForm');
128 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name,'enable'=>$can_manage_account));
129 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login,'enable'=>$can_manage_account));
130 if (!$auth->isPasswordExternal()) {
131 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
132 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
134 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email,'enable'=>$can_manage_account));
135 if ($user->canManageTeam()) {
136 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team));
137 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
139 // Prepare an array of available languages.
140 $lang_files = I18n::getLangFileList();
141 foreach ($lang_files as $lfile) {
142 $content = file(RESOURCE_DIR."/".$lfile);
144 foreach ($content as $line) {
145 if (strstr($line, 'i18n_language')) {
146 $a = explode('=', $line);
147 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
152 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
154 $longname_lang = mu_sort($longname_lang, 'name');
155 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
157 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
158 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
159 'onchange'=>'adjustDecimalPreview()'));
161 $DATE_FORMAT_OPTIONS = array(
162 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
163 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
164 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
165 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
166 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
167 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
168 $TIME_FORMAT_OPTIONS = array(
169 array('id'=>'%H:%M','name'=>$i18n->get('form.profile.24_hours')),
170 array('id'=>'%I:%M %p','name'=>$i18n->get('form.profile.12_hours')));
171 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
172 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
174 // Prepare week start choices.
175 $week_start_options = array();
176 foreach ($i18n->weekdayNames as $id => $week_dn) {
177 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
179 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
181 // Show holidays checkbox.
182 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
184 // Prepare tracking mode choices.
185 $tracking_mode_options = array();
186 $tracking_mode_options[MODE_TIME] = $i18n->get('form.profile.mode_time');
187 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.profile.mode_projects');
188 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.profile.mode_projects_and_tasks');
189 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
190 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
191 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
193 // Prepare record type choices.
194 $record_type_options = array();
195 $record_type_options[TYPE_ALL] = $i18n->get('form.profile.type_all');
196 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.profile.type_start_finish');
197 $record_type_options[TYPE_DURATION] = $i18n->get('form.profile.type_duration');
198 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
200 // Punch mode checkbox.
201 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
203 // Allow overlap checkbox.
204 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
206 // Future entries checkbox.
207 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
209 // Uncompleted indicators checkbox.
210 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
212 // Add bcc email control, for manager only.
213 if ($user->isManager()) {
214 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
217 // Plugin checkboxes.
218 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
219 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
220 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
221 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
222 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
223 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
224 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
225 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
226 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
227 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
228 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
229 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
231 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
233 if ($request->isPost()) {
234 // Validate user input.
235 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.person_name'));
236 if (!ttValidString($cl_login)) $err->add($i18n->get('error.field'), $i18n->get('label.login'));
238 // New login must be unique.
239 if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
240 $err->add($i18n->get('error.user_exists'));
242 if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
243 if (!ttValidString($cl_password1)) $err->add($i18n->get('error.field'), $i18n->get('label.password'));
244 if (!ttValidString($cl_password2)) $err->add($i18n->get('error.field'), $i18n->get('label.confirm_password'));
245 if ($cl_password1 !== $cl_password2)
246 $err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password'));
248 if (!ttValidEmail($cl_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.email'));
249 if ($user->canManageTeam()) {
250 if (!ttValidString($cl_team, true)) $err->add($i18n->get('error.field'), $i18n->get('label.team_name'));
251 if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
252 if ($user->isManager()) {
253 if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
256 // Finished validating user input.
259 $update_result = true;
260 if ($user->canManageTeam()) {
262 // Prepare plugins string.
267 if ($cl_client_required)
273 if ($cl_custom_fields)
277 if ($cl_tax_expenses)
279 if ($cl_notifications)
288 // Recycle week view plugin options as they are not configured on this page.
289 $existing_plugins = explode(',', $user->plugins);
290 if (in_array('wvn', $existing_plugins))
292 if (in_array('wvl', $existing_plugins))
294 if (in_array('wvns', $existing_plugins))
297 $plugins = trim($plugins, ',');
299 // Prepare config string.
300 if ($cl_show_holidays)
301 $config .= ',show_holidays';
303 $config .= ',punch_mode';
304 if ($cl_allow_overlap)
305 $config .= ',allow_overlap';
306 if ($cl_future_entries)
307 $config .= ',future_entries';
308 if ($cl_uncompleted_indicators)
309 $config .= ',uncompleted_indicators';
310 $config = trim($config, ',');
312 $update_result = ttTeamHelper::update($user->team_id, array(
314 'currency' => $cl_currency,
316 'decimal_mark' => $cl_decimal_mark,
317 'date_format' => $cl_date_format,
318 'time_format' => $cl_time_format,
319 'week_start' => $cl_start_week,
320 'tracking_mode' => $cl_tracking_mode,
321 'project_required' => $cl_project_required,
322 'task_required' => $cl_task_required,
323 'record_type' => $cl_record_type,
324 'uncompleted_indicators' => $cl_uncompleted_indicators,
325 'bcc_email' => $cl_bcc_email,
326 'plugins' => $plugins,
327 'config' => $config));
329 if ($update_result) {
330 $update_result = ttUserHelper::update($user->id, array(
332 'login' => $cl_login,
333 'password' => $cl_password1,
334 'email' => $cl_email,
335 'status' => ACTIVE));
337 if ($update_result) {
338 header('Location: time.php');
341 $err->add($i18n->get('error.db'));
345 $smarty->assign('auth_external', $auth->isPasswordExternal());
346 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
347 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
348 $smarty->assign('title', $i18n->get('title.profile'));
349 $smarty->assign('content_page_name', 'profile_edit.tpl');
350 $smarty->display('index.tpl');