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 // End of access checks.
42 $config = new ttConfigHelper($user->config);
44 $advanced_settings = $user->can('manage_advanced_settings');
45 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
47 if ($request->isPost()) {
48 $cl_group = trim($request->getParameter('group_name'));
49 $cl_currency = trim($request->getParameter('currency'));
50 if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
51 $cl_lang = $request->getParameter('lang');
52 $cl_decimal_mark = $request->getParameter('decimal_mark');
53 $cl_date_format = $request->getParameter('date_format');
54 $cl_time_format = $request->getParameter('time_format');
55 $cl_start_week = $request->getParameter('start_week');
56 $cl_show_holidays = $request->getParameter('show_holidays');
57 $cl_tracking_mode = $request->getParameter('tracking_mode');
58 $cl_project_required = $request->getParameter('project_required');
59 $cl_task_required = $request->getParameter('task_required');
60 $cl_record_type = $request->getParameter('record_type');
61 $cl_punch_mode = $request->getParameter('punch_mode');
62 $cl_allow_overlap = $request->getParameter('allow_overlap');
63 $cl_future_entries = $request->getParameter('future_entries');
64 $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
65 $cl_bcc_email = trim($request->getParameter('bcc_email'));
66 $cl_allow_ip = trim($request->getParameter('allow_ip'));
68 $cl_group = $user->group;
69 $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
70 $cl_lang = $user->lang;
71 $cl_decimal_mark = $user->decimal_mark;
72 $cl_date_format = $user->date_format;
73 $cl_time_format = $user->time_format;
74 $cl_start_week = $user->week_start;
75 $cl_show_holidays = $user->show_holidays;
76 $cl_tracking_mode = $user->tracking_mode;
77 $cl_project_required = $user->project_required;
78 $cl_task_required = $user->task_required;
79 $cl_record_type = $user->record_type;
80 $cl_punch_mode = $user->punch_mode;
81 $cl_allow_overlap = $user->allow_overlap;
82 $cl_future_entries = $user->future_entries;
83 $cl_uncompleted_indicators = $user->uncompleted_indicators;
84 $cl_bcc_email = $user->bcc_email;
85 $cl_allow_ip = $user->allow_ip;
88 $form = new Form('groupForm');
89 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
90 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
92 // Prepare an array of available languages.
93 $lang_files = I18n::getLangFileList();
94 foreach ($lang_files as $lfile) {
95 $content = file(RESOURCE_DIR."/".$lfile);
97 foreach ($content as $line) {
98 if (strstr($line, 'i18n_language')) {
99 $a = explode('=', $line);
100 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
105 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
107 $longname_lang = mu_sort($longname_lang, 'name');
108 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
110 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
111 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
112 'onchange'=>'adjustDecimalPreview()'));
114 $DATE_FORMAT_OPTIONS = array(
115 array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
116 array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
117 array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
118 array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
119 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
120 'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
121 $TIME_FORMAT_OPTIONS = array(
122 array('id'=>'%H:%M','name'=>$i18n->get('form.group_edit.24_hours')),
123 array('id'=>'%I:%M %p','name'=>$i18n->get('form.group_edit.12_hours')));
124 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
125 'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
127 // Prepare week start choices.
128 $week_start_options = array();
129 foreach ($i18n->weekdayNames as $id => $week_dn) {
130 $week_start_options[] = array('id' => $id, 'name' => $week_dn);
132 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
134 // Show holidays checkbox.
135 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
137 // Prepare tracking mode choices.
138 $tracking_mode_options = array();
139 $tracking_mode_options[MODE_TIME] = $i18n->get('form.group_edit.mode_time');
140 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.group_edit.mode_projects');
141 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.group_edit.mode_projects_and_tasks');
142 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
143 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
144 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
146 // Prepare record type choices.
147 $record_type_options = array();
148 $record_type_options[TYPE_ALL] = $i18n->get('form.group_edit.type_all');
149 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.group_edit.type_start_finish');
150 $record_type_options[TYPE_DURATION] = $i18n->get('form.group_edit.type_duration');
151 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
153 // Punch mode checkbox.
154 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
156 // Allow overlap checkbox.
157 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
159 // Future entries checkbox.
160 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
162 // Uncompleted indicators checkbox.
163 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
165 // Add bcc email control.
166 if ($advanced_settings) {
167 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
168 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
171 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
172 if ($user->can('delete_group')) $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('button.delete')));
174 if ($request->isPost()) {
176 if ($request->getParameter('btn_delete')) {
177 // Delete button pressed, redirect.
178 header('Location: group_delete.php?id='.$user->group_id);
182 // Validate user input.
183 if (!ttValidString($cl_group, true)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
184 if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
185 if ($advanced_settings) {
186 if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
187 if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.group_edit.allow_ip'));
189 // Finished validating user input.
193 $config->setDefinedValue('show_holidays', $cl_show_holidays);
194 $config->setDefinedValue('punch_mode', $cl_punch_mode);
195 $config->setDefinedValue('allow_overlap', $cl_allow_overlap);
196 $config->setDefinedValue('future_entries', $cl_future_entries);
197 $config->setDefinedValue('uncompleted_indicators', $cl_uncompleted_indicators);
199 if ($user->updateGroup(array(
201 'currency' => $cl_currency,
203 'decimal_mark' => $cl_decimal_mark,
204 'date_format' => $cl_date_format,
205 'time_format' => $cl_time_format,
206 'week_start' => $cl_start_week,
207 'tracking_mode' => $cl_tracking_mode,
208 'project_required' => $cl_project_required,
209 'task_required' => $cl_task_required,
210 'record_type' => $cl_record_type,
211 'uncompleted_indicators' => $cl_uncompleted_indicators,
212 'bcc_email' => $cl_bcc_email,
213 'allow_ip' => $cl_allow_ip,
214 'config' => $config->getConfig()))) {
215 header('Location: time.php');
218 $err->add($i18n->get('error.db'));
222 $smarty->assign('auth_external', $auth->isPasswordExternal());
223 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
224 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
225 $smarty->assign('title', $i18n->get('title.group'));
226 $smarty->assign('content_page_name', 'group_edit.tpl');
227 $smarty->display('index.tpl');