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->getMethod() == 'POST') {
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_lock_interval = $request->getParameter('lock_interval');
57 $cl_lang = $request->getParameter('lang');
58 $cl_decimal_mark = $request->getParameter('decimal_mark');
59 $cl_custom_format_date = $request->getParameter('format_date');
60 $cl_custom_format_time = $request->getParameter('format_time');
61 $cl_start_week = $request->getParameter('start_week');
62 $cl_tracking_mode = $request->getParameter('tracking_mode');
63 $cl_record_type = $request->getParameter('record_type');
64 $cl_charts = $request->getParameter('charts');
65 $cl_clients = $request->getParameter('clients');
66 $cl_client_required = $request->getParameter('client_required');
67 $cl_invoices = $request->getParameter('invoices');
68 $cl_custom_fields = $request->getParameter('custom_fields');
69 $cl_expenses = $request->getParameter('expenses');
70 $cl_tax_expenses = $request->getParameter('tax_expenses');
71 $cl_notifications = $request->getParameter('notifications');
74 $cl_name = $user->name;
75 $cl_login = $user->login;
76 $cl_email = $user->email;
77 if ($user->canManageTeam()) {
78 $cl_team = $user->team;
79 $cl_address = $user->address;
80 $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
81 $cl_lock_interval = $user->lock_interval;
82 $cl_lang = $user->lang;
83 $cl_decimal_mark = $user->decimal_mark;
84 $cl_custom_format_date = $user->date_format;
85 $cl_custom_format_time = $user->time_format;
86 $cl_start_week = $user->week_start;
87 $cl_tracking_mode = $user->tracking_mode;
88 $cl_record_type = $user->record_type;
90 // Which plugins do we have enabled?
91 $plugins = explode(',', $user->plugins);
92 $cl_charts = in_array('ch', $plugins);
93 $cl_clients = in_array('cl', $plugins);
94 $cl_client_required = in_array('cm', $plugins);
95 $cl_invoices = in_array('iv', $plugins);
96 $cl_custom_fields = in_array('cf', $plugins);
97 $cl_expenses = in_array('ex', $plugins);
98 $cl_tax_expenses = in_array('et', $plugins);
99 $cl_notifications = in_array('no', $plugins);
103 $form = new Form('profileForm');
104 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name));
105 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login,'enable'=>$can_change_login));
106 if (!$auth->isPasswordExternal()) {
107 $form->addInput(array('type'=>'text','maxlength'=>'30','name'=>'password1','aspassword'=>true,'value'=>$cl_password1));
108 $form->addInput(array('type'=>'text','maxlength'=>'30','name'=>'password2','aspassword'=>true,'value'=>$cl_password2));
110 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email,'enable'=>$can_change_login));
111 if ($user->canManageTeam()) {
112 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team));
113 $form->addInput(array('type'=>'textarea','name'=>'address','maxlength'=>'255','style'=>'width: 350px;','cols'=>'55','rows'=>'4','value'=>$cl_address));
114 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
115 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
116 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
117 'onchange'=>'adjustDecimalPreview()'));
118 $form->addInput(array('type'=>'text','maxlength'=>'10','name'=>'lock_interval','value'=>$cl_lock_interval));
119 // Prepare an array of available languages.
120 $lang_files = I18n::getLangFileList();
121 foreach ($lang_files as $lfile) {
122 $content = file(RESOURCE_DIR."/".$lfile);
124 foreach ($content as $line) {
125 if (strstr($line, 'i18n_language')) {
126 $a = explode('=', $line);
127 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
132 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
134 $longname_lang = mu_sort($longname_lang, 'name');
135 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 150px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
136 $DATE_FORMAT_OPTIONS = array(
137 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
138 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
139 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
140 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
141 $form->addInput(array('type'=>'combobox','name'=>'format_date','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_custom_format_date,
142 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
143 $TIME_FORMAT_OPTIONS = array(
144 array('id'=>'%H:%M','name'=>$i18n->getKey('form.profile.24_hours')),
145 array('id'=>'%I:%M %p','name'=>$i18n->getKey('form.profile.12_hours')));
146 $form->addInput(array('type'=>'combobox','name'=>'format_time','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_custom_format_time,
147 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
149 // Prepare week start choices.
150 $week_start_options = array();
151 foreach ($i18n->weekdayNames as $id => $week_dn) {
152 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
154 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
156 // Prepare tracking mode choices.
157 $tracking_mode_options = array();
158 $tracking_mode_options[MODE_TIME] = $i18n->getKey('form.profile.mode_time');
159 $tracking_mode_options[MODE_PROJECTS] = $i18n->getKey('form.profile.mode_projects');
160 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->getKey('form.profile.mode_projects_and_tasks');
161 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode));
163 // Prepare record type choices.
164 $record_type_options = array();
165 $record_type_options[TYPE_ALL] = $i18n->getKey('form.profile.type_all');
166 $record_type_options[TYPE_START_FINISH] = $i18n->getKey('form.profile.type_start_finish');
167 $record_type_options[TYPE_DURATION] = $i18n->getKey('form.profile.type_duration');
168 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
170 $form->addInput(array('type'=>'checkbox','name'=>'charts','data'=>1,'value'=>$cl_charts));
171 $form->addInput(array('type'=>'checkbox','name'=>'clients','data'=>1,'value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
172 $form->addInput(array('type'=>'checkbox','name'=>'client_required','data'=>1,'value'=>$cl_client_required));
174 $form->addInput(array('type'=>'checkbox','name'=>'invoices','data'=>1,'value'=>$cl_invoices));
175 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','data'=>1,'value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
176 $form->addInput(array('type'=>'checkbox','name'=>'expenses','data'=>1,'value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
177 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','data'=>1,'value'=>$cl_tax_expenses));
178 $form->addInput(array('type'=>'checkbox','name'=>'notifications','data'=>1,'value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
180 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
182 if ($request->getMethod() == 'POST') {
183 // Validate user input.
184 if (!ttValidString($cl_name)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name'));
185 if ($can_change_login) {
186 if (!ttValidString($cl_login)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.login'));
188 // New login must be unique.
189 if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
190 $errors->add($i18n->getKey('error.user_exists'));
192 if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
193 if (!ttValidString($cl_password1)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
194 if (!ttValidString($cl_password2)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
195 if ($cl_password1 !== $cl_password2)
196 $errors->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));
198 if (!ttValidEmail($cl_email, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
199 if ($user->canManageTeam()) {
200 if (!ttValidString($cl_team, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name'));
201 if (!ttValidString($cl_address, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.address'));
202 if (!ttValidString($cl_currency, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.currency'));
203 if (!ttValidInteger($cl_lock_interval, true)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.lock_interval'));
205 // Finished validating user input.
207 if ($errors->isEmpty()) {
208 if ($cl_lock_interval == null || trim($cl_lock_interval) == '')
209 $cl_lock_interval = 0;
211 $update_result = true;
212 if ($user->canManageTeam()) {
214 // Prepare plugins string.
219 if ($cl_client_required)
223 if ($cl_custom_fields)
227 if ($cl_tax_expenses)
229 if ($cl_notifications)
231 $plugins = trim($plugins, ',');
233 $update_result = ttTeamHelper::update($user->team_id, array(
235 'address' => $cl_address,
236 'currency' => $cl_currency,
237 'locktime' => $cl_lock_interval,
239 'decimal_mark' => $cl_decimal_mark,
240 'date_format' => $cl_custom_format_date,
241 'time_format' => $cl_custom_format_time,
242 'week_start' => $cl_start_week,
243 'tracking_mode' => $cl_tracking_mode,
244 'record_type' => $cl_record_type,
245 'plugins' => $plugins));
247 if ($update_result) {
248 $update_result = ttUserHelper::update($user->id, array(
250 'login' => $cl_login,
251 'password' => $cl_password1,
252 'email' => $cl_email,
253 'status' => ACTIVE));
255 if ($update_result) {
256 header('Location: time.php');
259 $errors->add($i18n->getKey('error.db'));
263 $smarty->assign('auth_external', $auth->isPasswordExternal());
264 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
265 $smarty->assign('onload', 'onLoad="handlePluginCheckboxes()"');
266 $smarty->assign('title', $i18n->getKey('title.profile'));
267 $smarty->assign('content_page_name', 'profile_edit.tpl');
268 $smarty->display('index.tpl');