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');
34 if (!ttAccessCheck(right_data_entry|right_view_reports)) {
35 header('Location: access_denied.php');
39 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
40 $can_change_login = $user->canManageTeam();
42 if ($request->isPost()) {
43 $cl_name = trim($request->getParameter('name'));
44 $cl_login = trim($request->getParameter('login'));
45 if (!$auth->isPasswordExternal()) {
46 $cl_password1 = $request->getParameter('password1');
47 $cl_password2 = $request->getParameter('password2');
49 $cl_email = trim($request->getParameter('email'));
51 if ($user->canManageTeam()) {
52 $cl_team = trim($request->getParameter('team_name'));
53 $cl_currency = trim($request->getParameter('currency'));
54 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
55 $cl_lang = $request->getParameter('lang');
56 $cl_decimal_mark = $request->getParameter('decimal_mark');
57 $cl_date_format = $request->getParameter('date_format');
58 $cl_time_format = $request->getParameter('time_format');
59 $cl_start_week = $request->getParameter('start_week');
60 $cl_show_holidays = $request->getParameter('show_holidays');
61 $cl_tracking_mode = $request->getParameter('tracking_mode');
62 $cl_project_required = $request->getParameter('project_required');
63 $cl_task_required = $request->getParameter('task_required');
64 $cl_record_type = $request->getParameter('record_type');
65 $cl_punch_mode = $request->getParameter('punch_mode');
66 $cl_allow_overlap = $request->getParameter('allow_overlap');
67 $cl_future_entries = $request->getParameter('future_entries');
68 $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
69 $cl_bcc_email = trim($request->getParameter('bcc_email'));
72 $cl_charts = $request->getParameter('charts');
73 $cl_clients = $request->getParameter('clients');
74 $cl_client_required = $request->getParameter('client_required');
75 $cl_invoices = $request->getParameter('invoices');
76 $cl_paid_status = $request->getParameter('paid_status');
77 $cl_custom_fields = $request->getParameter('custom_fields');
78 $cl_expenses = $request->getParameter('expenses');
79 $cl_tax_expenses = $request->getParameter('tax_expenses');
80 $cl_notifications = $request->getParameter('notifications');
81 $cl_locking = $request->getParameter('locking');
82 $cl_quotas = $request->getParameter('quotas');
83 $cl_week_view = $request->getParameter('week_view');
86 $cl_name = $user->name;
87 $cl_login = $user->login;
88 $cl_email = $user->email;
89 if ($user->canManageTeam()) {
90 $cl_team = $user->team;
91 $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
92 $cl_lang = $user->lang;
93 $cl_decimal_mark = $user->decimal_mark;
94 $cl_date_format = $user->date_format;
95 $cl_time_format = $user->time_format;
96 $cl_start_week = $user->week_start;
97 $cl_show_holidays = $user->show_holidays;
98 $cl_tracking_mode = $user->tracking_mode;
99 $cl_project_required = $user->project_required;
100 $cl_task_required = $user->task_required;
101 $cl_record_type = $user->record_type;
102 $cl_punch_mode = $user->punch_mode;
103 $cl_allow_overlap = $user->allow_overlap;
104 $cl_future_entries = $user->future_entries;
105 $cl_uncompleted_indicators = $user->uncompleted_indicators;
106 $cl_bcc_email = $user->bcc_email;
108 // Which plugins do we have enabled?
109 $plugins = explode(',', $user->plugins);
110 $cl_charts = in_array('ch', $plugins);
111 $cl_clients = in_array('cl', $plugins);
112 $cl_client_required = in_array('cm', $plugins);
113 $cl_invoices = in_array('iv', $plugins);
114 $cl_paid_status = in_array('ps', $plugins);
115 $cl_custom_fields = in_array('cf', $plugins);
116 $cl_expenses = in_array('ex', $plugins);
117 $cl_tax_expenses = in_array('et', $plugins);
118 $cl_notifications = in_array('no', $plugins);
119 $cl_locking = in_array('lk', $plugins);
120 $cl_quotas = in_array('mq', $plugins);
121 $cl_week_view = in_array('wv', $plugins);
125 $form = new Form('profileForm');
126 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name));
127 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login,'enable'=>$can_change_login));
128 if (!$auth->isPasswordExternal()) {
129 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
130 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
132 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email,'enable'=>$can_change_login));
133 if ($user->canManageTeam()) {
134 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team));
135 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
137 // Prepare an array of available languages.
138 $lang_files = I18n::getLangFileList();
139 foreach ($lang_files as $lfile) {
140 $content = file(RESOURCE_DIR."/".$lfile);
142 foreach ($content as $line) {
143 if (strstr($line, 'i18n_language')) {
144 $a = explode('=', $line);
145 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
150 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
152 $longname_lang = mu_sort($longname_lang, 'name');
153 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 150px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
155 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
156 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
157 'onchange'=>'adjustDecimalPreview()'));
159 $DATE_FORMAT_OPTIONS = array(
160 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
161 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
162 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
163 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
164 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
165 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
166 $TIME_FORMAT_OPTIONS = array(
167 array('id'=>'%H:%M','name'=>$i18n->getKey('form.profile.24_hours')),
168 array('id'=>'%I:%M %p','name'=>$i18n->getKey('form.profile.12_hours')));
169 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
170 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
172 // Prepare week start choices.
173 $week_start_options = array();
174 foreach ($i18n->weekdayNames as $id => $week_dn) {
175 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
177 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
179 // Show holidays checkbox.
180 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
182 // Prepare tracking mode choices.
183 $tracking_mode_options = array();
184 $tracking_mode_options[MODE_TIME] = $i18n->getKey('form.profile.mode_time');
185 $tracking_mode_options[MODE_PROJECTS] = $i18n->getKey('form.profile.mode_projects');
186 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->getKey('form.profile.mode_projects_and_tasks');
187 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
188 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
189 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
191 // Prepare record type choices.
192 $record_type_options = array();
193 $record_type_options[TYPE_ALL] = $i18n->getKey('form.profile.type_all');
194 $record_type_options[TYPE_START_FINISH] = $i18n->getKey('form.profile.type_start_finish');
195 $record_type_options[TYPE_DURATION] = $i18n->getKey('form.profile.type_duration');
196 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
198 // Punch mode checkbox.
199 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
201 // Allow overlap checkbox.
202 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
204 // Future entries checkbox.
205 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
207 // Uncompleted indicators checkbox.
208 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
210 // Add bcc email control, for manager only.
211 if ($user->isManager()) {
212 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
215 // Plugin checkboxes.
216 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
217 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
218 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
219 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
220 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
221 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
222 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
223 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
224 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
225 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
226 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
227 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
229 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
231 if ($request->isPost()) {
232 // Validate user input.
233 if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name'));
234 if ($can_change_login) {
235 if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login'));
237 // New login must be unique.
238 if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
239 $err->add($i18n->getKey('error.user_exists'));
241 if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
242 if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
243 if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
244 if ($cl_password1 !== $cl_password2)
245 $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));
247 if (!ttValidEmail($cl_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
248 if ($user->canManageTeam()) {
249 if (!ttValidString($cl_team, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name'));
250 if (!ttValidString($cl_currency, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency'));
251 if ($user->isManager()) {
252 if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.bcc'));
255 // Finished validating user input.
258 $update_result = true;
259 if ($user->canManageTeam()) {
261 // Prepare plugins string.
266 if ($cl_client_required)
272 if ($cl_custom_fields)
276 if ($cl_tax_expenses)
278 if ($cl_notifications)
287 // Recycle week view plugin options as they are not configured on this page.
288 $existing_plugins = explode(',', $user->plugins);
289 if (in_array('wvn', $existing_plugins))
291 if (in_array('wvl', $existing_plugins))
293 if (in_array('wvns', $existing_plugins))
296 $plugins = trim($plugins, ',');
298 // Prepare config string.
299 if ($cl_show_holidays)
300 $config .= ',show_holidays';
302 $config .= ',punch_mode';
303 if ($cl_allow_overlap)
304 $config .= ',allow_overlap';
305 if ($cl_future_entries)
306 $config .= ',future_entries';
307 if ($cl_uncompleted_indicators)
308 $config .= ',uncompleted_indicators';
309 $config = trim($config, ',');
311 $update_result = ttTeamHelper::update($user->team_id, array(
313 'currency' => $cl_currency,
315 'decimal_mark' => $cl_decimal_mark,
316 'date_format' => $cl_date_format,
317 'time_format' => $cl_time_format,
318 'week_start' => $cl_start_week,
319 'tracking_mode' => $cl_tracking_mode,
320 'project_required' => $cl_project_required,
321 'task_required' => $cl_task_required,
322 'record_type' => $cl_record_type,
323 'uncompleted_indicators' => $cl_uncompleted_indicators,
324 'bcc_email' => $cl_bcc_email,
325 'plugins' => $plugins,
326 'config' => $config));
328 if ($update_result) {
329 $update_result = ttUserHelper::update($user->id, array(
331 'login' => $cl_login,
332 'password' => $cl_password1,
333 'email' => $cl_email,
334 'status' => ACTIVE));
336 if ($update_result) {
337 header('Location: time.php');
340 $err->add($i18n->getKey('error.db'));
344 $smarty->assign('auth_external', $auth->isPasswordExternal());
345 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
346 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
347 $smarty->assign('title', $i18n->getKey('title.profile'));
348 $smarty->assign('content_page_name', 'profile_edit.tpl');
349 $smarty->display('index.tpl');