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('ttTeamHelper'); // TODO: remove this?
32 import('ttTaskHelper'); // TODO: remove this?
33 import('ttRoleHelper');
36 if (!ttAccessCheck(right_manage_team)) {
37 header('Location: access_denied.php');
41 $cl_role_id = (int)$request->getParameter('id');
43 if ($request->isPost()) {
44 $cl_name = trim($request->getParameter('name'));
45 $cl_description = trim($request->getParameter('description'));
46 $cl_status = $request->getParameter('status');
48 $role = ttRoleHelper::get($cl_role_id);
49 $cl_name = $role['name'];
50 $cl_description = $role['description'];
51 $cl_status = $role['status'];
54 $form = new Form('roleForm');
55 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_role_id));
56 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','style'=>'width: 250px;','value'=>$cl_name));
57 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
58 $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status,
59 'data'=>array(ACTIVE=>$i18n->getKey('dropdown.status_active'),INACTIVE=>$i18n->getKey('dropdown.status_inactive'))));
60 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
62 if ($request->isPost()) {
63 // Validate user input.
64 if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.thing_name'));
65 if (!ttValidString($cl_description, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.description'));
68 $existing_role = ttRoleHelper::getRoleByName($cl_name);
69 if (!$existing_role || ($cl_role_id == $existing_role['id'])) {
70 // Update role information.
71 if (ttRoleHelper::update(array(
74 'description' => $cl_description,
75 'status' => $cl_status))) {
76 header('Location: roles.php');
79 $err->add($i18n->getKey('error.db'));
81 $err->add($i18n->getKey('error.object_exists'));
85 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
86 $smarty->assign('title', $i18n->getKey('title.edit_role'));
87 $smarty->assign('content_page_name', 'role_edit.tpl');
88 $smarty->display('index.tpl');