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');
 
  35 if (!(ttAccessAllowed('manage_basic_settings') || ttAccessAllowed('manage_advanced_settings'))) {
 
  36   header('Location: access_denied.php');
 
  39 // End of access checks.
 
  41 $advanced_settings = $user->can('manage_advanced_settings');
 
  42 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
 
  44 if ($request->isPost()) {
 
  45   $cl_group = trim($request->getParameter('group_name'));
 
  46   $cl_currency = trim($request->getParameter('currency'));
 
  47   if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
 
  48   $cl_lang = $request->getParameter('lang');
 
  49   $cl_decimal_mark = $request->getParameter('decimal_mark');
 
  50   $cl_date_format = $request->getParameter('date_format');
 
  51   $cl_time_format = $request->getParameter('time_format');
 
  52   $cl_start_week = $request->getParameter('start_week');
 
  53   $cl_show_holidays = $request->getParameter('show_holidays');
 
  54   $cl_tracking_mode = $request->getParameter('tracking_mode');
 
  55   $cl_project_required = $request->getParameter('project_required');
 
  56   $cl_task_required = $request->getParameter('task_required');
 
  57   $cl_record_type = $request->getParameter('record_type');
 
  58   $cl_punch_mode = $request->getParameter('punch_mode');
 
  59   $cl_allow_overlap = $request->getParameter('allow_overlap');
 
  60   $cl_future_entries = $request->getParameter('future_entries');
 
  61   $cl_uncompleted_indicators = $request->getParameter('uncompleted_indicators');
 
  62   $cl_bcc_email = trim($request->getParameter('bcc_email'));
 
  63   $cl_allow_ip = trim($request->getParameter('allow_ip'));
 
  66   $cl_charts = $request->getParameter('charts');
 
  67   $cl_clients = $request->getParameter('clients');
 
  68   $cl_client_required = $request->getParameter('client_required');
 
  69   $cl_invoices = $request->getParameter('invoices');
 
  70   $cl_paid_status = $request->getParameter('paid_status');
 
  71   $cl_custom_fields = $request->getParameter('custom_fields');
 
  72   $cl_expenses = $request->getParameter('expenses');
 
  73   $cl_tax_expenses = $request->getParameter('tax_expenses');
 
  74   $cl_notifications = $request->getParameter('notifications');
 
  75   $cl_locking = $request->getParameter('locking');
 
  76   $cl_quotas = $request->getParameter('quotas');
 
  77   $cl_week_view = $request->getParameter('week_view');
 
  78   $cl_work_units = $request->getParameter('work_units');
 
  80   $cl_group = $user->group;
 
  81   $cl_currency = ($user->currency == ''? CURRENCY_DEFAULT : $user->currency);
 
  82   $cl_lang = $user->lang;
 
  83   $cl_decimal_mark = $user->decimal_mark;
 
  84   $cl_date_format = $user->date_format;
 
  85   $cl_time_format = $user->time_format;
 
  86   $cl_start_week = $user->week_start;
 
  87   $cl_show_holidays = $user->show_holidays;
 
  88   $cl_tracking_mode = $user->tracking_mode;
 
  89   $cl_project_required = $user->project_required;
 
  90   $cl_task_required = $user->task_required;
 
  91   $cl_record_type = $user->record_type;
 
  92   $cl_punch_mode = $user->punch_mode;
 
  93   $cl_allow_overlap = $user->allow_overlap;
 
  94   $cl_future_entries = $user->future_entries;
 
  95   $cl_uncompleted_indicators = $user->uncompleted_indicators;
 
  96   $cl_bcc_email = $user->bcc_email;
 
  97   $cl_allow_ip = $user->allow_ip;
 
  99   // Which plugins do we have enabled?
 
 100   $plugins = explode(',', $user->plugins);
 
 101   $cl_charts = in_array('ch', $plugins);
 
 102   $cl_clients = in_array('cl', $plugins);
 
 103   $cl_client_required = in_array('cm', $plugins);
 
 104   $cl_invoices = in_array('iv', $plugins);
 
 105   $cl_paid_status = in_array('ps', $plugins);
 
 106   $cl_custom_fields = in_array('cf', $plugins);
 
 107   $cl_expenses = in_array('ex', $plugins);
 
 108   $cl_tax_expenses = in_array('et', $plugins);
 
 109   $cl_notifications = in_array('no', $plugins);
 
 110   $cl_locking = in_array('lk', $plugins);
 
 111   $cl_quotas = in_array('mq', $plugins);
 
 112   $cl_week_view = in_array('wv', $plugins);
 
 113   $cl_work_units = in_array('wu', $plugins);
 
 116 $form = new Form('groupForm');
 
 117 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
 
 118 $form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
 
 120 // Prepare an array of available languages.
 
 121 $lang_files = I18n::getLangFileList();
 
 122 foreach ($lang_files as $lfile) {
 
 123   $content = file(RESOURCE_DIR."/".$lfile);
 
 125   foreach ($content as $line) {
 
 126     if (strstr($line, 'i18n_language')) {
 
 127       $a = explode('=', $line);
 
 128       $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
 
 133   $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
 
 135 $longname_lang = mu_sort($longname_lang, 'name');
 
 136 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
 
 138 $DECIMAL_MARK_OPTIONS = array(array('id'=>'.','name'=>'.'),array('id'=>',','name'=>','));
 
 139 $form->addInput(array('type'=>'combobox','name'=>'decimal_mark','style'=>'width: 150px','data'=>$DECIMAL_MARK_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_decimal_mark,
 
 140   'onchange'=>'adjustDecimalPreview()'));
 
 142 $DATE_FORMAT_OPTIONS = array(
 
 143   array('id'=>'%Y-%m-%d','name'=>'Y-m-d'),
 
 144   array('id'=>'%m/%d/%Y','name'=>'m/d/Y'),
 
 145   array('id'=>'%d.%m.%Y','name'=>'d.m.Y'),
 
 146   array('id'=>'%d.%m.%Y %a','name'=>'d.m.Y a'));
 
 147 $form->addInput(array('type'=>'combobox','name'=>'date_format','style'=>'width: 150px;','data'=>$DATE_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_date_format,
 
 148   'onchange'=>'MakeFormatPreview("date_format_preview", this);'));
 
 149 $TIME_FORMAT_OPTIONS = array(
 
 150   array('id'=>'%H:%M','name'=>$i18n->get('form.group_edit.24_hours')),
 
 151   array('id'=>'%I:%M %p','name'=>$i18n->get('form.group_edit.12_hours')));
 
 152 $form->addInput(array('type'=>'combobox','name'=>'time_format','style'=>'width: 150px;','data'=>$TIME_FORMAT_OPTIONS,'datakeys'=>array('id','name'),'value'=>$cl_time_format,
 
 153   'onchange'=>'MakeFormatPreview("time_format_preview", this);'));
 
 155 // Prepare week start choices.
 
 156 $week_start_options = array();
 
 157 foreach ($i18n->weekdayNames as $id => $week_dn) {
 
 158   $week_start_options[] = array('id' => $id, 'name' => $week_dn);
 
 160 $form->addInput(array('type'=>'combobox','name'=>'start_week','style'=>'width: 150px;','data'=>$week_start_options,'datakeys'=>array('id','name'),'value'=>$cl_start_week));
 
 162 // Show holidays checkbox.
 
 163 $form->addInput(array('type'=>'checkbox','name'=>'show_holidays','value'=>$cl_show_holidays));
 
 165 // Prepare tracking mode choices.
 
 166 $tracking_mode_options = array();
 
 167 $tracking_mode_options[MODE_TIME] = $i18n->get('form.group_edit.mode_time');
 
 168 $tracking_mode_options[MODE_PROJECTS] = $i18n->get('form.group_edit.mode_projects');
 
 169 $tracking_mode_options[MODE_PROJECTS_AND_TASKS] = $i18n->get('form.group_edit.mode_projects_and_tasks');
 
 170 $form->addInput(array('type'=>'combobox','name'=>'tracking_mode','style'=>'width: 150px;','data'=>$tracking_mode_options,'value'=>$cl_tracking_mode,'onchange'=>'handleTaskRequiredCheckbox()'));
 
 171 $form->addInput(array('type'=>'checkbox','name'=>'project_required','value'=>$cl_project_required));
 
 172 $form->addInput(array('type'=>'checkbox','name'=>'task_required','value'=>$cl_task_required));
 
 174 // Prepare record type choices.
 
 175 $record_type_options = array();
 
 176 $record_type_options[TYPE_ALL] = $i18n->get('form.group_edit.type_all');
 
 177 $record_type_options[TYPE_START_FINISH] = $i18n->get('form.group_edit.type_start_finish');
 
 178 $record_type_options[TYPE_DURATION] = $i18n->get('form.group_edit.type_duration');
 
 179 $form->addInput(array('type'=>'combobox','name'=>'record_type','style'=>'width: 150px;','data'=>$record_type_options,'value'=>$cl_record_type));
 
 181 // Punch mode checkbox.
 
 182 $form->addInput(array('type'=>'checkbox','name'=>'punch_mode','value'=>$cl_punch_mode));
 
 184 // Allow overlap checkbox.
 
 185 $form->addInput(array('type'=>'checkbox','name'=>'allow_overlap','value'=>$cl_allow_overlap));
 
 187 // Future entries checkbox.
 
 188 $form->addInput(array('type'=>'checkbox','name'=>'future_entries','value'=>$cl_future_entries));
 
 190 // Uncompleted indicators checkbox.
 
 191 $form->addInput(array('type'=>'checkbox','name'=>'uncompleted_indicators','value'=>$cl_uncompleted_indicators));
 
 193 // Add bcc email control.
 
 194 if ($advanced_settings) {
 
 195   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'bcc_email','value'=>$cl_bcc_email));
 
 196   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'allow_ip','value'=>$cl_allow_ip));
 
 199 // Plugin checkboxes.
 
 200 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
 
 201 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
 
 202 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
 
 203 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
 
 204 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
 
 205 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
 
 206 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
 
 207 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
 
 208 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
 
 209 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
 
 210 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
 
 211 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
 
 212 if (defined('WORK_UNITS_DEBUG')) {
 
 213   $form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_units,'onchange'=>'handlePluginCheckboxes()'));
 
 216 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
 
 217 if ($user->can('delete_group')) $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('button.delete')));
 
 219 if ($request->isPost()) {
 
 221   if ($request->getParameter('btn_delete')) {
 
 222     // Delete button pressed, redirect.
 
 223     header('Location: group_delete.php?id='.$user->group_id);
 
 227   // Validate user input.
 
 228   if (!ttValidString($cl_group, true)) $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
 
 229   if (!ttValidString($cl_currency, true)) $err->add($i18n->get('error.field'), $i18n->get('label.currency'));
 
 230   if ($advanced_settings) {
 
 231     if (!ttValidEmail($cl_bcc_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.bcc'));
 
 232     if (!ttValidIP($cl_allow_ip, true)) $err->add($i18n->get('error.field'), $i18n->get('form.group_edit.allow_ip'));
 
 234   // Finished validating user input.
 
 237     // Prepare plugins string.
 
 242     if ($cl_client_required)
 
 248     if ($cl_custom_fields)
 
 252     if ($cl_tax_expenses)
 
 254     if ($cl_notifications)
 
 263     // Recycle week view plugin options as they are not configured on this page.
 
 264     $existing_plugins = explode(',', $user->plugins);
 
 265     if (in_array('wvn', $existing_plugins))
 
 267     if (in_array('wvl', $existing_plugins))
 
 269     if (in_array('wvns', $existing_plugins))
 
 272     $plugins = trim($plugins, ',');
 
 274     // Prepare config string.
 
 275     if ($cl_show_holidays)
 
 276       $config .= ',show_holidays';
 
 278       $config .= ',punch_mode';
 
 279     if ($cl_allow_overlap)
 
 280       $config .= ',allow_overlap';
 
 281     if ($cl_future_entries)
 
 282       $config .= ',future_entries';
 
 283     if ($cl_uncompleted_indicators)
 
 284       $config .= ',uncompleted_indicators';
 
 285     $config = trim($config, ',');
 
 287     if ($user->updateGroup(array(
 
 289       'currency' => $cl_currency,
 
 291       'decimal_mark' => $cl_decimal_mark,
 
 292       'date_format' => $cl_date_format,
 
 293       'time_format' => $cl_time_format,
 
 294       'week_start' => $cl_start_week,
 
 295       'tracking_mode' => $cl_tracking_mode,
 
 296       'project_required' => $cl_project_required,
 
 297       'task_required' => $cl_task_required,
 
 298       'record_type' => $cl_record_type,
 
 299       'uncompleted_indicators' => $cl_uncompleted_indicators,
 
 300       'bcc_email' => $cl_bcc_email,
 
 301       'allow_ip' => $cl_allow_ip,
 
 302       'plugins' => $plugins,
 
 303       'config' => $config))) {
 
 304       header('Location: time.php');
 
 307       $err->add($i18n->get('error.db'));
 
 311 $smarty->assign('auth_external', $auth->isPasswordExternal());
 
 312 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
 313 $smarty->assign('onload', 'onLoad="handleTaskRequiredCheckbox(); handlePluginCheckboxes();"');
 
 314 $smarty->assign('title', $i18n->get('title.group'));
 
 315 $smarty->assign('content_page_name', 'group_edit.tpl');
 
 316 $smarty->display('index.tpl');