A bit more progress with renaming.
[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
34 // Access checks.
35 if (!ttAccessAllowed('manage_basic_settings')) {
36   header('Location: access_denied.php');
37   exit();
38 }
39 // End of access checks.
40
41 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
42
43 if ($request->isPost()) {
44   $cl_team = trim($request->getParameter('team_name'));
45   $cl_currency = trim($request->getParameter('currency'));
46   if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
47   $cl_lang = $request->getParameter('lang');
48   $cl_decimal_mark = $request->getParameter('decimal_mark');
49   $cl_date_format = $request->getParameter('date_format');
50   $cl_time_format = $request->getParameter('time_format');
51   $cl_start_week = $request->getParameter('start_week');
52   $cl_show_holidays = $request->getParameter('show_holidays');
53   $cl_tracking_mode = $request->getParameter('tracking_mode');
54   $cl_project_required = $request->getParameter('project_required');
55   $cl_task_required = $request->getParameter('task_required');
56   $cl_record_type = $request->getParameter('record_type');
57   $cl_punch_mode = $request->getParameter('punch_mode');
58   $cl_allow_overlap = $request->getParameter('allow_overlap');
59   $cl_future_entries = $request->getParameter('future_entries');
60   $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
61   $cl_bcc_email = trim($request->getParameter('bcc_email'));
62   $cl_allow_ip = trim($request->getParameter('allow_ip'));
63
64   // Plugin checkboxes.
65   $cl_charts = $request->getParameter('charts');
66   $cl_clients = $request->getParameter('clients');
67   $cl_client_required = $request->getParameter('client_required');
68   $cl_invoices = $request->getParameter('invoices');
69   $cl_paid_status = $request->getParameter('paid_status');
70   $cl_custom_fields = $request->getParameter('custom_fields');
71   $cl_expenses = $request->getParameter('expenses');
72   $cl_tax_expenses = $request->getParameter('tax_expenses');
73   $cl_notifications = $request->getParameter('notifications');
74   $cl_locking = $request->getParameter('locking');
75   $cl_quotas = $request->getParameter('quotas');
76   $cl_week_view = $request->getParameter('week_view');
77 } else {
78   $cl_team = $user->team;
79   $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
80   $cl_lang = $user->lang;
81   $cl_decimal_mark = $user->decimal_mark;
82   $cl_date_format = $user->date_format;
83   $cl_time_format = $user->time_format;
84   $cl_start_week = $user->week_start;
85   $cl_show_holidays = $user->show_holidays;
86   $cl_tracking_mode = $user->tracking_mode;
87   $cl_project_required = $user->project_required;
88   $cl_task_required = $user->task_required;
89   $cl_record_type = $user->record_type;
90   $cl_punch_mode = $user->punch_mode;
91   $cl_allow_overlap = $user->allow_overlap;
92   $cl_future_entries = $user->future_entries;
93   $cl_uncompleted_indicators = $user->uncompleted_indicators;
94   $cl_bcc_email = $user->bcc_email;
95   $cl_allow_ip = $user->allow_ip;
96
97   // Which plugins do we have enabled?
98   $plugins = explode(',', $user->plugins);
99   $cl_charts = in_array('ch', $plugins);
100   $cl_clients = in_array('cl', $plugins);
101   $cl_client_required = in_array('cm', $plugins);
102   $cl_invoices = in_array('iv', $plugins);
103   $cl_paid_status = in_array('ps', $plugins);
104   $cl_custom_fields = in_array('cf', $plugins);
105   $cl_expenses = in_array('ex', $plugins);
106   $cl_tax_expenses = in_array('et', $plugins);
107   $cl_notifications = in_array('no', $plugins);
108   $cl_locking = in_array('lk', $plugins);
109   $cl_quotas = in_array('mq', $plugins);
110   $cl_week_view = in_array('wv', $plugins);
111 }
112
113 $form = new Form('groupForm');
114 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team));
115 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
116
117 // Prepare an array of available languages.
118 $lang_files = I18n::getLangFileList();
119 foreach ($lang_files as $lfile) {
120   $content = file(RESOURCE_DIR."/".$lfile);
121   $lname = '';
122   foreach ($content as $line) {
123     if (strstr($line, 'i18n_language')) {
124       $a = explode('=', $line);
125       $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
126       break;
127     }
128   }
129   unset($content);
130   $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
131 }
132 $longname_lang = mu_sort($longname_lang, 'name');
133 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
134
135 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
136 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
137   'onchange'=>'adjustDecimalPreview()'));
138
139 $DATE_FORMAT_OPTIONS = array(
140   array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
141   array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
142   array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
143   array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
144 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
145   'onchange'=>'MakeFormatPreview(&quot;date_format_preview&quot;, this);'));
146 $TIME_FORMAT_OPTIONS = array(
147   array('id'=>'%H:%M','name'=>$i18n->get('form.profile.24_hours')),
148   array('id'=>'%I:%M %p','name'=>$i18n->get('form.profile.12_hours')));
149 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
150   'onchange'=>'MakeFormatPreview(&quot;time_format_preview&quot;, this);'));
151
152 // Prepare week start choices.
153 $week_start_options = array();
154 foreach ($i18n->weekdayNames as $id => $week_dn) {
155   $week_start_options[] = array('id' => $id, 'name' => $week_dn);
156 }
157 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
158
159 // Show holidays checkbox.
160 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
161
162 // Prepare tracking mode choices.
163 $tracking_mode_options = array();
164 $tracking_mode_options[MODE_TIME] = $i18n->get('form.profile.mode_time');
165 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.profile.mode_projects');
166 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.profile.mode_projects_and_tasks');
167 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
168 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
169 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
170
171 // Prepare record type choices.
172 $record_type_options = array();
173 $record_type_options[TYPE_ALL] = $i18n->get('form.profile.type_all');
174 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.profile.type_start_finish');
175 $record_type_options[TYPE_DURATION] = $i18n->get('form.profile.type_duration');
176 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
177
178 // Punch mode checkbox.
179 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
180
181 // Allow overlap checkbox.
182 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
183
184 // Future entries checkbox.
185 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
186
187 // Uncompleted indicators checkbox.
188 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
189
190 // Add bcc email control, for manager only.
191 if ($user->can('manage_advanced_settings')) {
192   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
193   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
194 }
195
196 // Plugin checkboxes.
197 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
198 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
199 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
200 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
201 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
202 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
203 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
204 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
205 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
206 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
207 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
208 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
209 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
210
211 if ($request->isPost()) {
212   // Validate user input.
213   if (!ttValidString($cl_team, true)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
214   if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
215   if ($user->can('manage_advanced_settings')) {
216     if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
217     if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.profile.allow_ip'));
218   }
219   // Finished validating user input.
220
221   if ($err->no()) {
222     $update_result = true;
223     if ($user->canManageTeam()) {
224
225       // Prepare plugins string.
226       if ($cl_charts)
227         $plugins .= ',ch';
228       if ($cl_clients)
229         $plugins .= ',cl';
230       if ($cl_client_required)
231         $plugins .= ',cm';
232       if ($cl_invoices)
233         $plugins .= ',iv';
234       if ($cl_paid_status)
235         $plugins .= ',ps';
236       if ($cl_custom_fields)
237         $plugins .= ',cf';
238       if ($cl_expenses)
239         $plugins .= ',ex';
240       if ($cl_tax_expenses)
241         $plugins .= ',et';
242       if ($cl_notifications)
243         $plugins .= ',no';
244       if ($cl_locking)
245         $plugins .= ',lk';
246       if ($cl_quotas)
247         $plugins .= ',mq';
248       if ($cl_week_view)
249         $plugins .= ',wv';
250
251       // Recycle week view plugin options as they are not configured on this page.
252       $existing_plugins = explode(',', $user->plugins);
253       if (in_array('wvn', $existing_plugins))
254         $plugins .= ',wvn';
255       if (in_array('wvl', $existing_plugins))
256         $plugins .= ',wvl';
257       if (in_array('wvns', $existing_plugins))
258         $plugins .= ',wvns';
259
260       $plugins = trim($plugins, ',');
261
262       // Prepare config string.
263       if ($cl_show_holidays)
264         $config .= ',show_holidays';
265       if ($cl_punch_mode)
266         $config .= ',punch_mode';
267       if ($cl_allow_overlap)
268         $config .= ',allow_overlap';
269       if ($cl_future_entries)
270         $config .= ',future_entries';
271       if ($cl_uncompleted_indicators)
272         $config .= ',uncompleted_indicators';
273       $config = trim($config, ',');
274
275       $update_result = ttTeamHelper::update($user->group_id, array(
276         'name' => $cl_team,
277         'currency' => $cl_currency,
278         'lang' => $cl_lang,
279         'decimal_mark' => $cl_decimal_mark,
280         'date_format' => $cl_date_format,
281         'time_format' => $cl_time_format,
282         'week_start' => $cl_start_week,
283         'tracking_mode' => $cl_tracking_mode,
284         'project_required' => $cl_project_required,
285         'task_required' => $cl_task_required,
286         'record_type' => $cl_record_type,
287         'uncompleted_indicators' => $cl_uncompleted_indicators,
288         'bcc_email' => $cl_bcc_email,
289         'allow_ip' => $cl_allow_ip,
290         'plugins' => $plugins,
291         'config' => $config));
292     }
293     if ($update_result) {
294       header('Location: time.php');
295       exit();
296     } else
297       $err->add($i18n->get('error.db'));
298   }
299 } // isPost
300
301 $smarty->assign('auth_external', $auth->isPasswordExternal());
302 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
303 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
304 $smarty->assign('title', $i18n->get('title.group'));
305 $smarty->assign('content_page_name', 'group_edit.tpl');
306 $smarty->display('index.tpl');