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 $can_manage_account = $user->can('manage_own_account');
43 if ($request->isPost()) {
44 $cl_name = trim($request->getParameter('name'));
45 $cl_login = trim($request->getParameter('login'));
46 if (!$auth->isPasswordExternal()) {
47 $cl_password1 = $request->getParameter('password1');
48 $cl_password2 = $request->getParameter('password2');
50 $cl_email = trim($request->getParameter('email'));
52 $cl_name = $user->name;
53 $cl_login = $user->login;
54 $cl_email = $user->email;
57 $form = new Form('profileForm');
58 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name,'enable'=>$can_manage_account));
59 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login,'enable'=>$can_manage_account));
60 if (!$auth->isPasswordExternal()) {
61 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
62 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
64 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email,'enable'=>$can_manage_account));
65 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
67 if ($request->isPost()) {
68 // Validate user input.
69 if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.person_name'));
70 if (!ttValidString($cl_login)) $err->add($i18n->get('error.field'), $i18n->get('label.login'));
72 // New login must be unique.
73 if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
74 $err->add($i18n->get('error.user_exists'));
76 if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
77 if (!ttValidString($cl_password1)) $err->add($i18n->get('error.field'), $i18n->get('label.password'));
78 if (!ttValidString($cl_password2)) $err->add($i18n->get('error.field'), $i18n->get('label.confirm_password'));
79 if ($cl_password1 !== $cl_password2)
80 $err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password'));
82 if (!ttValidEmail($cl_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.email'));
83 // Finished validating user input.
86 $update_result = ttUserHelper::update($user->id, array(
89 'password' => $cl_password1,
93 header('Location: time.php');
96 $err->add($i18n->get('error.db'));
100 $smarty->assign('auth_external', $auth->isPasswordExternal());
101 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
102 $smarty->assign('title', $i18n->get('title.profile'));
103 $smarty->assign('content_page_name', 'profile_edit.tpl');
104 $smarty->display('index.tpl');