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('ttUserHelper');
32 import('ttRoleHelper');
33 import('ttConfigHelper');
36 if (!(ttAccessAllowed('manage_basic_settings') || ttAccessAllowed('manage_advanced_settings'))) {
37 header('Location: access_denied.php');
40 $group_id = (int)$request->getParameter('id');
41 if ($group_id && !$user->isGroupValid($group_id)) {
42 header('Location: access_denied.php');
45 // End of access checks.
48 // We are passed a valid group_id.
49 // Set on behalf group accordingly.
50 $user->setOnBehalfGroup($group_id);
53 if (!$group_id) $group_id = $user->getGroup();
54 $groups = $user->getGroupsForDropdown();
55 $group = ttGroupHelper::getGroupAttrs($group_id);
56 $config = new ttConfigHelper($group['config']);
58 $advanced_settings = $user->can('manage_advanced_settings');
59 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
61 if ($request->isPost()) {
62 $cl_group = trim($request->getParameter('group_name'));
63 $cl_description = trim($request->getParameter('description'));
64 $cl_currency = trim($request->getParameter('currency'));
65 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
66 $cl_lang = $request->getParameter('lang');
67 $cl_decimal_mark = $request->getParameter('decimal_mark');
68 $cl_date_format = $request->getParameter('date_format');
69 $cl_time_format = $request->getParameter('time_format');
70 $cl_start_week = $request->getParameter('start_week');
71 $cl_show_holidays = $request->getParameter('show_holidays');
72 $cl_tracking_mode = $request->getParameter('tracking_mode');
73 $cl_project_required = $request->getParameter('project_required');
74 $cl_task_required = $request->getParameter('task_required');
75 $cl_record_type = $request->getParameter('record_type');
76 $cl_punch_mode = $request->getParameter('punch_mode');
77 $cl_allow_overlap = $request->getParameter('allow_overlap');
78 $cl_future_entries = $request->getParameter('future_entries');
79 $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
80 $cl_confirm_save = $request->getParameter('confirm_save');
81 $cl_bcc_email = trim($request->getParameter('bcc_email'));
82 $cl_allow_ip = trim($request->getParameter('allow_ip'));
84 $cl_group = $group['name'];
85 $cl_description = $group['description'];
86 $cl_currency = ($group['currency'] == ''? CURRENCY_DEFAULT : $group['currency']);
87 $cl_lang = $group['lang'];
88 $cl_decimal_mark = $group['decimal_mark'];
89 $cl_date_format = $group['date_format'];
90 $cl_time_format = $group['time_format'];
91 $cl_start_week = $group['week_start'];
92 $cl_show_holidays = $config->getDefinedValue('show_holidays');
93 $cl_tracking_mode = $group['tracking_mode'];
94 $cl_project_required = $group['project_required'];
95 $cl_task_required = $group['task_required'];
96 $cl_record_type = $group['record_type'];
97 $cl_punch_mode = $config->getDefinedValue('punch_mode');
98 $cl_allow_overlap = $config->getDefinedValue('allow_overlap');
99 $cl_future_entries = $config->getDefinedValue('future_entries');
100 $cl_uncompleted_indicators = $config->getDefinedValue('uncompleted_indicators');
101 $cl_confirm_save = $config->getDefinedValue('confirm_save');
102 $cl_bcc_email = $group['bcc_email'];
103 $cl_allow_ip = $group['allow_ip'];
106 $form = new Form('groupForm');
107 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$group_id));
108 if (count($groups) > 1) {
109 $form->addInput(array('type'=>'combobox',
110 'onchange'=>'document.groupForm.group_changed.value=1;document.groupForm.submit();',
112 'style'=>'width: 250px;',
115 'datakeys'=>array('id','name')));
116 $form->addInput(array('type'=>'hidden','name'=>'group_changed'));
117 $smarty->assign('group_dropdown', 1);
119 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
120 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
121 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
123 // Prepare an array of available languages.
124 $lang_files = I18n::getLangFileList();
125 foreach ($lang_files as $lfile) {
126 $content = file(RESOURCE_DIR."/".$lfile);
128 foreach ($content as $line) {
129 if (strstr($line, 'i18n_language')) {
130 $a = explode('=', $line);
131 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
136 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
138 $longname_lang = mu_sort($longname_lang, 'name');
139 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
141 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
142 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
143 'onchange'=>'adjustDecimalPreview()'));
145 $DATE_FORMAT_OPTIONS = array(
146 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
147 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
148 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
149 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
150 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
151 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
152 $TIME_FORMAT_OPTIONS = array(
153 array('id'=>'%H:%M','name'=>$i18n->get('form.group_edit.24_hours')),
154 array('id'=>'%I:%M %p','name'=>$i18n->get('form.group_edit.12_hours')));
155 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
156 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
158 // Prepare week start choices.
159 $week_start_options = array();
160 foreach ($i18n->weekdayNames as $id => $week_dn) {
161 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
163 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
165 // Show holidays checkbox.
166 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
168 // Prepare tracking mode choices.
169 $tracking_mode_options = array();
170 $tracking_mode_options[MODE_TIME] = $i18n->get('form.group_edit.mode_time');
171 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.group_edit.mode_projects');
172 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.group_edit.mode_projects_and_tasks');
173 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
174 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
175 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
177 // Prepare record type choices.
178 $record_type_options = array();
179 $record_type_options[TYPE_ALL] = $i18n->get('form.group_edit.type_all');
180 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.group_edit.type_start_finish');
181 $record_type_options[TYPE_DURATION] = $i18n->get('form.group_edit.type_duration');
182 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
184 // Punch mode checkbox.
185 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
187 // Allow overlap checkbox.
188 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
190 // Future entries checkbox.
191 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
193 // Uncompleted indicators checkbox.
194 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
196 // Confirm save checkbox.
197 $form->addInput(array('type'=>'checkbox','name'=>'confirm_save','value'=>$cl_confirm_save));
199 // Add bcc email control.
200 if ($advanced_settings) {
201 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
202 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
205 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
206 if ($user->can('delete_group')) $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('button.delete')));
208 $form->setValueByElement('group_changed','');
210 if ($request->isPost()) {
211 if ($request->getParameter('group_changed')) {
212 // User changed the group in dropdown.
213 $new_group_id = $request->getParameter('group');
215 header('Location: group_edit.php?id='.$new_group_id);
219 if ($request->getParameter('btn_delete')) {
220 // Delete button pressed, redirect.
221 header('Location: group_delete.php?id='.$group_id);
225 // Validate user input.
226 if (!ttValidString($cl_group)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
227 if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
228 if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
229 if ($advanced_settings) {
230 if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
231 if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.group_edit.allow_ip'));
233 // Finished validating user input.
237 $config->setDefinedValue('show_holidays', $cl_show_holidays);
238 $config->setDefinedValue('punch_mode', $cl_punch_mode);
239 $config->setDefinedValue('allow_overlap', $cl_allow_overlap);
240 $config->setDefinedValue('future_entries', $cl_future_entries);
241 $config->setDefinedValue('uncompleted_indicators', $cl_uncompleted_indicators);
242 $config->setDefinedValue('confirm_save', $cl_confirm_save);
244 if ($user->updateGroup(array(
245 'group_id' => $group_id,
247 'description' => $cl_description,
248 'currency' => $cl_currency,
250 'decimal_mark' => $cl_decimal_mark,
251 'date_format' => $cl_date_format,
252 'time_format' => $cl_time_format,
253 'week_start' => $cl_start_week,
254 'tracking_mode' => $cl_tracking_mode,
255 'project_required' => $cl_project_required,
256 'task_required' => $cl_task_required,
257 'record_type' => $cl_record_type,
258 'uncompleted_indicators' => $cl_uncompleted_indicators,
259 'bcc_email' => $cl_bcc_email,
260 'allow_ip' => $cl_allow_ip,
261 'config' => $config->getConfig()))) {
262 header('Location: success.php');
265 $err->add($i18n->get('error.db'));
269 $smarty->assign('auth_external', $auth->isPasswordExternal());
270 $smarty->assign('group_id', $group_id);
271 $smarty->assign('group_dropdown', count($groups) > 1);
272 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
273 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
274 $smarty->assign('title', $i18n->get('title.edit_group'));
275 $smarty->assign('content_page_name', 'group_edit.tpl');
276 $smarty->display('index.tpl');