Added code to insert user custom fields after user creation.
[timetracker.git] / group_advanced_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('ttRoleHelper');
33 import('ttConfigHelper');
34
35 // Access checks.
36 if (!ttAccessAllowed('manage_advanced_settings')) {
37   header('Location: access_denied.php');
38   exit();
39 }
40 // End of access checks.
41
42 $group = ttGroupHelper::getGroupAttrs($user->getGroup());
43
44 if ($request->isPost()) {
45   $cl_group = trim($request->getParameter('group_name'));
46   $cl_description = trim($request->getParameter('description'));
47   $cl_bcc_email = trim($request->getParameter('bcc_email'));
48   $cl_allow_ip = trim($request->getParameter('allow_ip'));
49 } else {
50   $cl_group = $group['name'];
51   $cl_description = $group['description'];
52   $cl_bcc_email = $group['bcc_email'];
53   $cl_allow_ip = $group['allow_ip'];
54 }
55
56 $form = new Form('groupAdvancedForm');
57 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
58 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
59 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
60 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
61
62 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
63
64 if ($request->isPost()) {
65   if ($request->getParameter('btn_save')) {
66     // Validate user input.
67     if (!ttValidString($cl_group)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
68     if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
69     if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
70     if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.group_edit.allow_ip'));
71     // Finished validating user input.
72
73     if ($err->no()) {
74       if ($user->updateGroup(array(
75         'name' => $cl_group,
76         'description' => $cl_description,
77         'bcc_email' => $cl_bcc_email,
78         'allow_ip' => $cl_allow_ip))) {
79         header('Location: success.php');
80         exit();
81       } else
82         $err->add($i18n->get('error.db'));
83     }
84   }
85 } // isPost
86
87 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
88 $smarty->assign('title', $i18n->get('title.edit_group'));
89 $smarty->assign('content_page_name', 'group_advanced_edit.tpl');
90 $smarty->display('index.tpl');