Work in progress populating repo...
[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
33 // Access check.
34 if (!ttAccessCheck(right_administer_site)) {
35   header('Location: access_denied.php');
36   exit();
37 }
38
39 if ($request->getMethod() == 'POST') {
40   $cl_password1 = $request->getParameter('password1');
41   $cl_password2 = $request->getParameter('password2');
42 }
43
44 $form = new Form('optionsForm');
45 $form->addInput(array('type'=>'text','aspassword'=>true,'maxlength'=>'30','name'=>'password1','style'=>'width: 150px;','value'=>$cl_password1));
46 $form->addInput(array('type'=>'text','aspassword'=>true,'maxlength'=>'30','name'=>'password2','style'=>"width: 150px;",'value'=>$cl_password2));
47 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit')));
48
49 if ($request->getMethod() == 'POST') {
50   if ($cl_password1 || $cl_password2) {
51         // Validate user input.
52         if (!ttValidString($cl_password1)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.password'));
53         if (!ttValidString($cl_password2)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password'));
54     if ($cl_password1 !== $cl_password2)
55       $errors->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password'));
56   }
57
58   if ($errors->isEmpty() && $cl_password1) {
59     if (ttUserHelper::setPassword($user->id, $cl_password1)) {
60       header('Location: admin_teams.php');
61       exit();
62     } else
63       $errors->add($i18n->getKey('error.db'));
64   }
65 } // post
66
67 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
68 $smarty->assign('title', $i18n->getKey('title.options'));
69 $smarty->assign('content_page_name', 'admin_options.tpl');
70 $smarty->display('index.tpl');
71 ?>