Fixed nav links visibility between day and week views.
[timetracker.git] / admin_options.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 require_once('initialize.php');
30 import('form.Form');
31 import('ttUserHelper');
32 import('ttAdmin');
33
34 // Access check.
35 if (!ttAccessAllowed('administer_site')) {
36   header('Location: access_denied.php');
37   exit();
38 }
39 // End of access checks.
40
41 if ($request->isPost()) {
42   $cl_name = trim($request->getParameter('name'));
43   $cl_login = trim($request->getParameter('login'));
44   if (!$auth->isPasswordExternal()) {
45     $cl_password1 = $request->getParameter('password1');
46     $cl_password2 = $request->getParameter('password2');
47   }
48   $cl_email = trim($request->getParameter('email'));
49 } else {
50   $cl_name = $user->name;
51   $cl_login = $user->login;
52   $cl_email = $user->email;
53 }
54
55 $form = new Form('optionsForm');
56 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name));
57 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'login','value'=>$cl_login));
58 if (!$auth->isPasswordExternal()) {
59   $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
60   $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
61 }
62 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','value'=>$cl_email));
63 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
64
65 if ($request->isPost()) {
66   // Validate user input.
67   if (!ttValidString($cl_name))
68     $err->add($i18n->get('error.field'), $i18n->get('label.person_name'));
69   if (!ttValidString($cl_login))
70     $err->add($i18n->get('error.field'), $i18n->get('label.login'));
71   // If we change login, it must be unique.
72   if ($cl_login != $user->login && ttUserHelper::getUserByLogin($cl_login))
73     $err->add($i18n->get('error.user_exists'));
74   if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) {
75       if (!ttValidString($cl_password1))
76         $err->add($i18n->get('error.field'), $i18n->get('label.password'));
77       if (!ttValidString($cl_password2))
78         $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'));
81     }
82   if (!ttValidEmail($cl_email, true))
83     $err->add($i18n->get('error.field'), $i18n->get('label.email'));
84
85   if ($err->no() && ttAdmin::updateSelf(array('name' => $cl_name,
86     'login' => $cl_login,
87     'password1' => $cl_password1,
88     'password2' => $cl_password2,
89     'email' => $cl_email))) {
90     header('Location: admin_groups.php');
91     exit();
92   }
93 } // isPost
94
95 $smarty->assign('auth_external', $auth->isPasswordExternal());
96 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
97 $smarty->assign('title', $i18n->get('title.options'));
98 $smarty->assign('content_page_name', 'admin_options.tpl');
99 $smarty->display('index.tpl');