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_address = trim($request->getParameter('address'));
54 $cl_currency = trim($request->getParameter('currency'));
55 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
56 $cl_lang = $request->getParameter('lang');
57 $cl_decimal_mark = $request->getParameter('decimal_mark');
58 $cl_custom_format_date = $request->getParameter('format_date');
59 $cl_custom_format_time = $request->getParameter('format_time');
60 $cl_start_week = $request->getParameter('start_week');
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_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
66 $cl_charts = $request->getParameter('charts');
67 $cl_clients = $request->getParameter('clients');
68 $cl_client_required = $request->getParameter('client_required');
69 $cl_invoices = $request->getParameter('invoices');
70 $cl_custom_fields = $request->getParameter('custom_fields');
71 $cl_expenses = $request->getParameter('expenses');
72 $cl_tax_expenses = $request->getParameter('tax_expenses');
73 $cl_notifications = $request->getParameter('notifications');
74 $cl_bcc_email = trim($request->getParameter('bcc_email'));
75 $cl_locking = $request->getParameter('locking');
76 $cl_quotas = $request->getParameter('quotas');
79 $cl_name = $user->name;
80 $cl_login = $user->login;
81 $cl_email = $user->email;
82 if ($user->canManageTeam()) {
83 $cl_team = $user->team;
84 $cl_address = $user->address;
85 $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
86 $cl_lang = $user->lang;
87 $cl_decimal_mark = $user->decimal_mark;
88 $cl_custom_format_date = $user->date_format;
89 $cl_custom_format_time = $user->time_format;
90 $cl_start_week = $user->week_start;
91 $cl_tracking_mode = $user->tracking_mode;
92 $cl_project_required = $user->project_required;
93 $cl_task_required = $user->task_required;
94 $cl_record_type = $user->record_type;
95 $cl_uncompleted_indicators = $user->uncompleted_indicators;
96 $cl_bcc_email = $user->bcc_email;
98 // Which plugins do we have enabled?
99 $plugins = explode(',', $user->plugins);
100 $cl_charts = in_array('ch', $plugins);
101 $cl_clients = in_array('cl', $plugins);
102 $cl_client_required = in_array('cm', $plugins);
103 $cl_invoices = in_array('iv', $plugins);
104 $cl_custom_fields = in_array('cf', $plugins);
105 $cl_expenses = in_array('ex', $plugins);
106 $cl_tax_expenses = in_array('et', $plugins);
107 $cl_notifications = in_array('no', $plugins);
108 $cl_locking = in_array('lk', $plugins);
109 $cl_quotas = in_array('mq', $plugins);
113 $form = new Form('profileForm');
114 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name));
115 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login,'enable'=>$can_change_login));
116 if (!$auth->isPasswordExternal()) {
117 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
118 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
120 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email,'enable'=>$can_change_login));
121 if ($user->canManageTeam()) {
122 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team));
123 $form->addInput(array('type'=>'textarea','name'=>'address','maxlength'=>'255','style'=>'width: 350px;','cols'=>'55','rows'=>'4','value'=>$cl_address));
124 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
125 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
126 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
127 'onchange'=>'adjustDecimalPreview()'));
128 // Prepare an array of available languages.
129 $lang_files = I18n::getLangFileList();
130 foreach ($lang_files as $lfile) {
131 $content = file(RESOURCE_DIR."/".$lfile);
133 foreach ($content as $line) {
134 if (strstr($line, 'i18n_language')) {
135 $a = explode('=', $line);
136 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
141 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
143 $longname_lang = mu_sort($longname_lang, 'name');
144 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 150px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
145 $DATE_FORMAT_OPTIONS = array(
146 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
147 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
148 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
149 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
150 $form->addInput(array('type'=>'combobox','name'=>'format_date','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_custom_format_date,
151 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
152 $TIME_FORMAT_OPTIONS = array(
153 array('id'=>'%H:%M','name'=>$i18n->getKey('form.profile.24_hours')),
154 array('id'=>'%I:%M %p','name'=>$i18n->getKey('form.profile.12_hours')));
155 $form->addInput(array('type'=>'combobox','name'=>'format_time','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_custom_format_time,
156 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
158 // Prepare week start choices.
159 $week_start_options = array();
160 foreach ($i18n->weekdayNames as $id => $week_dn) {
161 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
163 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
165 // Prepare tracking mode choices.
166 $tracking_mode_options = array();
167 $tracking_mode_options[MODE_TIME] = $i18n->getKey('form.profile.mode_time');
168 $tracking_mode_options[MODE_PROJECTS] = $i18n->getKey('form.profile.mode_projects');
169 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->getKey('form.profile.mode_projects_and_tasks');
170 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
171 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
172 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
174 // Prepare record type choices.
175 $record_type_options = array();
176 $record_type_options[TYPE_ALL] = $i18n->getKey('form.profile.type_all');
177 $record_type_options[TYPE_START_FINISH] = $i18n->getKey('form.profile.type_start_finish');
178 $record_type_options[TYPE_DURATION] = $i18n->getKey('form.profile.type_duration');
179 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
181 // Prepare uncompleted indicators choices.
182 $uncompleted_indicators_options = array();
183 $uncompleted_indicators_options[UNCOMPLETED_INDICATORS_NONE] = $i18n->getKey('form.profile.uncompleted_indicators_none');
184 $uncompleted_indicators_options[UNCOMPLETED_INDICATORS] = $i18n->getKey('form.profile.uncompleted_indicators_show');
185 $form->addInput(array('type'=>'combobox','name'=>'uncompleted_indicators','style'=>'width: 150px;','data'=>$uncompleted_indicators_options,'value'=>$cl_uncompleted_indicators));
187 // Add bcc email control, for manager only.
188 if ($user->isManager()) {
189 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
192 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
193 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
194 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
196 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
197 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
198 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
199 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
200 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
201 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
202 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
204 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
206 if ($request->isPost()) {
207 // Validate user input.
208 if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name'));
209 if ($can_change_login) {
210 if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login'));
212 // New login must be unique.
213 if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
214 $err->add($i18n->getKey('error.user_exists'));
216 if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
217 if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
218 if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
219 if ($cl_password1 !== $cl_password2)
220 $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));
222 if (!ttValidEmail($cl_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
223 if ($user->canManageTeam()) {
224 if (!ttValidString($cl_team, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name'));
225 if (!ttValidString($cl_address, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.address'));
226 if (!ttValidString($cl_currency, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency'));
227 if ($user->isManager()) {
228 if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.bcc'));
231 // Finished validating user input.
234 $update_result = true;
235 if ($user->canManageTeam()) {
237 // Prepare plugins string.
242 if ($cl_client_required)
246 if ($cl_custom_fields)
250 if ($cl_tax_expenses)
252 if ($cl_notifications)
258 $plugins = trim($plugins, ',');
260 $update_result = ttTeamHelper::update($user->team_id, array(
262 'address' => $cl_address,
263 'currency' => $cl_currency,
265 'decimal_mark' => $cl_decimal_mark,
266 'date_format' => $cl_custom_format_date,
267 'time_format' => $cl_custom_format_time,
268 'week_start' => $cl_start_week,
269 'tracking_mode' => $cl_tracking_mode,
270 'project_required' => $cl_project_required,
271 'task_required' => $cl_task_required,
272 'record_type' => $cl_record_type,
273 'uncompleted_indicators' => $cl_uncompleted_indicators,
274 'bcc_email' => $cl_bcc_email,
275 'plugins' => $plugins));
277 if ($update_result) {
278 $update_result = ttUserHelper::update($user->id, array(
280 'login' => $cl_login,
281 'password' => $cl_password1,
282 'email' => $cl_email,
283 'status' => ACTIVE));
285 if ($update_result) {
286 header('Location: time.php');
289 $err->add($i18n->getKey('error.db'));
293 $smarty->assign('auth_external', $auth->isPasswordExternal());
294 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
295 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
296 $smarty->assign('title', $i18n->getKey('title.profile'));
297 $smarty->assign('content_page_name', 'profile_edit.tpl');
298 $smarty->display('index.tpl');