Added description field on group_edit.php.
[timetracker.git] / 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('ttRoleHelper');
33 import('ttConfigHelper');
34
35 // Access checks.
36 if (!(ttAccessAllowed('manage_basic_settings') || ttAccessAllowed('manage_advanced_settings'))) {
37   header('Location: access_denied.php');
38   exit();
39 }
40 $group_id = (int)$request->getParameter('id');
41 if ($group_id && !$user->isGroupValid($group_id)) {
42   header('Location: access_denied.php');
43   exit();
44 }
45 // End of access checks.
46
47 if (!$group_id) $group_id = $user->getActiveGroup();
48 $group = ttGroupHelper::getGroupAttrs($group_id);
49 $config = new ttConfigHelper($group['config']);
50
51 $advanced_settings = $user->can('manage_advanced_settings');
52 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
53
54 if ($request->isPost()) {
55   $cl_group = trim($request->getParameter('group_name'));
56   $cl_description = trim($request->getParameter('description'));
57   $cl_currency = trim($request->getParameter('currency'));
58   if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
59   $cl_lang = $request->getParameter('lang');
60   $cl_decimal_mark = $request->getParameter('decimal_mark');
61   $cl_date_format = $request->getParameter('date_format');
62   $cl_time_format = $request->getParameter('time_format');
63   $cl_start_week = $request->getParameter('start_week');
64   $cl_show_holidays = $request->getParameter('show_holidays');
65   $cl_tracking_mode = $request->getParameter('tracking_mode');
66   $cl_project_required = $request->getParameter('project_required');
67   $cl_task_required = $request->getParameter('task_required');
68   $cl_record_type = $request->getParameter('record_type');
69   $cl_punch_mode = $request->getParameter('punch_mode');
70   $cl_allow_overlap = $request->getParameter('allow_overlap');
71   $cl_future_entries = $request->getParameter('future_entries');
72   $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
73   $cl_bcc_email = trim($request->getParameter('bcc_email'));
74   $cl_allow_ip = trim($request->getParameter('allow_ip'));
75 } else {
76   $cl_group = $group['name'];
77   $cl_description = $group['description'];
78   $cl_currency = ($group['currency'] == ''? CURRENCY_DEFAULT : $group['currency']);
79   $cl_lang = $group['lang'];
80   $cl_decimal_mark = $group['decimal_mark'];
81   $cl_date_format = $group['date_format'];
82   $cl_time_format = $group['time_format'];
83   $cl_start_week = $group['week_start'];
84   $cl_show_holidays = $config->getDefinedValue('show_holidays');
85   $cl_tracking_mode = $group['tracking_mode'];
86   $cl_project_required = $group['project_required'];
87   $cl_task_required = $group['task_required'];
88   $cl_record_type = $group['record_type'];
89   $cl_punch_mode = $config->getDefinedValue('punch_mode');
90   $cl_allow_overlap = $config->getDefinedValue('allow_overlap');
91   $cl_future_entries = $config->getDefinedValue('future_entries');
92   $cl_uncompleted_indicators = $config->getDefinedValue('uncompleted_indicators');
93   $cl_bcc_email = $group['bcc_email'];
94   $cl_allow_ip = $group['allow_ip'];
95 }
96
97 $form = new Form('groupForm');
98 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$group_id));
99 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
100 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
101 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
102
103 // Prepare an array of available languages.
104 $lang_files = I18n::getLangFileList();
105 foreach ($lang_files as $lfile) {
106   $content = file(RESOURCE_DIR."/".$lfile);
107   $lname = '';
108   foreach ($content as $line) {
109     if (strstr($line, 'i18n_language')) {
110       $a = explode('=', $line);
111       $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
112       break;
113     }
114   }
115   unset($content);
116   $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
117 }
118 $longname_lang = mu_sort($longname_lang, 'name');
119 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
120
121 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
122 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
123   'onchange'=>'adjustDecimalPreview()'));
124
125 $DATE_FORMAT_OPTIONS = array(
126   array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
127   array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
128   array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
129   array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
130 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
131   'onchange'=>'MakeFormatPreview(&quot;date_format_preview&quot;, this);'));
132 $TIME_FORMAT_OPTIONS = array(
133   array('id'=>'%H:%M','name'=>$i18n->get('form.group_edit.24_hours')),
134   array('id'=>'%I:%M %p','name'=>$i18n->get('form.group_edit.12_hours')));
135 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
136   'onchange'=>'MakeFormatPreview(&quot;time_format_preview&quot;, this);'));
137
138 // Prepare week start choices.
139 $week_start_options = array();
140 foreach ($i18n->weekdayNames as $id => $week_dn) {
141   $week_start_options[] = array('id' => $id, 'name' => $week_dn);
142 }
143 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
144
145 // Show holidays checkbox.
146 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
147
148 // Prepare tracking mode choices.
149 $tracking_mode_options = array();
150 $tracking_mode_options[MODE_TIME] = $i18n->get('form.group_edit.mode_time');
151 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.group_edit.mode_projects');
152 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.group_edit.mode_projects_and_tasks');
153 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
154 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
155 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
156
157 // Prepare record type choices.
158 $record_type_options = array();
159 $record_type_options[TYPE_ALL] = $i18n->get('form.group_edit.type_all');
160 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.group_edit.type_start_finish');
161 $record_type_options[TYPE_DURATION] = $i18n->get('form.group_edit.type_duration');
162 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
163
164 // Punch mode checkbox.
165 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
166
167 // Allow overlap checkbox.
168 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
169
170 // Future entries checkbox.
171 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
172
173 // Uncompleted indicators checkbox.
174 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
175
176 // Add bcc email control.
177 if ($advanced_settings) {
178   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
179   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
180 }
181
182 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
183 if ($user->can('delete_group')) $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('button.delete')));
184
185 if ($request->isPost()) {
186
187   if ($request->getParameter('btn_delete')) {
188     // Delete button pressed, redirect.
189     header('Location: group_delete.php?id='.$group_id);
190     exit();
191   }
192
193   // Validate user input.
194   if (!ttValidString($cl_group, true)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
195   if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
196   if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
197   if ($advanced_settings) {
198     if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
199     if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.group_edit.allow_ip'));
200   }
201   // Finished validating user input.
202
203   if ($err->no()) {
204     // Update config.
205     $config->setDefinedValue('show_holidays', $cl_show_holidays);
206     $config->setDefinedValue('punch_mode', $cl_punch_mode);
207     $config->setDefinedValue('allow_overlap', $cl_allow_overlap);
208     $config->setDefinedValue('future_entries', $cl_future_entries);
209     $config->setDefinedValue('uncompleted_indicators', $cl_uncompleted_indicators);
210
211     if ($user->updateGroup(array(
212       'group_id' => $group_id,
213       'name' => $cl_group,
214       'description' => $cl_description,
215       'currency' => $cl_currency,
216       'lang' => $cl_lang,
217       'decimal_mark' => $cl_decimal_mark,
218       'date_format' => $cl_date_format,
219       'time_format' => $cl_time_format,
220       'week_start' => $cl_start_week,
221       'tracking_mode' => $cl_tracking_mode,
222       'project_required' => $cl_project_required,
223       'task_required' => $cl_task_required,
224       'record_type' => $cl_record_type,
225       'uncompleted_indicators' => $cl_uncompleted_indicators,
226       'bcc_email' => $cl_bcc_email,
227       'allow_ip' => $cl_allow_ip,
228       'config' => $config->getConfig()))) {
229       header('Location: success.php');
230       exit();
231     } else
232       $err->add($i18n->get('error.db'));
233   }
234 } // isPost
235
236 $smarty->assign('auth_external', $auth->isPasswordExternal());
237 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
238 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
239 $smarty->assign('title', $i18n->get('title.edit_group'));
240 $smarty->assign('content_page_name', 'group_edit.tpl');
241 $smarty->display('index.tpl');