More progress on removing dependency on canManageTeam().
[timetracker.git] / admin_group_edit.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 checks.
35 if (!ttAccessAllowed('administer_site')) {
36   header('Location: access_denied.php');
37   exit();
38 }
39 // End of access checks.
40
41 $group_id = $request->getParameter('id');
42
43 $admin = new ttAdmin();
44 $group_details = $admin->getGroupDetails($group_id);
45
46 if ($request->isPost()) {
47   $cl_group_name = trim($request->getParameter('group_name'));
48   $cl_manager_name = trim($request->getParameter('manager_name'));
49   $cl_manager_login = trim($request->getParameter('manager_login'));
50   if (!$auth->isPasswordExternal()) {
51     $cl_password1 = $request->getParameter('password1');
52     $cl_password2 = $request->getParameter('password2');
53   }
54   $cl_manager_email = trim($request->getParameter('manager_email'));
55 } else {
56   $cl_group_name = $group_details['group_name'];
57   $cl_manager_name = $group_details['manager_name'];
58   $cl_manager_login = $group_details['manager_login'];
59   if (!$auth->isPasswordExternal()) {
60     $cl_password1 = $cl_password2 = '';
61   }
62   $cl_manager_email = $group_details['manager_email'];
63 }
64
65 $form = new Form('groupForm');
66 $form->addInput(array('type'=>'text','maxlength'=>'80','name'=>'group_name','value'=>$cl_group_name));
67 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
68 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
69 if (!$auth->isPasswordExternal()) {
70   $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
71   $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
72 }
73 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email','value'=>$cl_manager_email));
74 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$group_id));
75 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
76 $form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get('button.cancel')));
77
78 if ($request->isPost()) {
79   if ($request->getParameter('btn_save')) {
80     // Create fields array for ttAdmin instance.
81     $fields = array(
82       'old_group_name' => $group_details['group_name'],
83       'new_group_name' => $cl_group_name,
84       'user_id' => $group_details['manager_id'],
85       'user_name' => $cl_manager_name,
86       'old_login' => $group_details['manager_login'],
87       'new_login' => $cl_manager_login,
88       'password1' => $cl_password1,
89       'password2' => $cl_password2,
90       'email' => $cl_manager_email);
91
92     import('ttAdmin');
93     $admin = new ttAdmin($err);
94     $result = $admin->updateGroup($group_id, $fields);
95     if ($result) {
96       header('Location: admin_groups.php');
97       exit();
98     }
99   }
100
101   if ($request->getParameter('btn_cancel')) {
102     header('Location: admin_groups.php');
103     exit();
104   }
105 } // isPost
106
107 $smarty->assign('auth_external', $auth->isPasswordExternal());
108 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
109 $smarty->assign('onload', 'onLoad="document.groupForm.manager_name.focus()"');
110 $smarty->assign('title', $i18n->get('title.edit_group'));
111 $smarty->assign('content_page_name', 'admin_group_edit.tpl');
112 $smarty->display('index.tpl');