From 4334f16faa68ecaec5aceb5c16bb500d62a3688f Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 26 Apr 2019 15:54:27 +0000 Subject: [PATCH] Refactoring, moving plugin config options into config field. --- WEB-INF/lib/ttGroup.class.php | 15 +++++++---- WEB-INF/lib/ttUser.class.php | 31 ++++++++++++++++++----- WEB-INF/templates/expense_edit.tpl | 2 +- WEB-INF/templates/expenses.tpl | 2 +- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/mobile/expense_edit.tpl | 2 +- WEB-INF/templates/mobile/expenses.tpl | 2 +- WEB-INF/templates/time.tpl | 2 +- WEB-INF/templates/time_edit.tpl | 2 +- WEB-INF/templates/week.tpl | 2 +- expense_edit.php | 2 +- expenses.php | 2 +- mobile/expense_edit.php | 2 +- mobile/expenses.php | 2 +- mobile/time.php | 2 +- mobile/time_edit.php | 2 +- mobile/timer.php | 2 +- plugins.php | 12 ++++++--- time.php | 2 +- time_edit.php | 2 +- week.php | 2 +- 21 files changed, 61 insertions(+), 33 deletions(-) diff --git a/WEB-INF/lib/ttGroup.class.php b/WEB-INF/lib/ttGroup.class.php index 9c12e95b..c3a56e05 100644 --- a/WEB-INF/lib/ttGroup.class.php +++ b/WEB-INF/lib/ttGroup.class.php @@ -54,7 +54,10 @@ class ttGroup { var $password_complexity = null; // Password complexity example. var $currency = null; // Currency. var $plugins = null; // Comma-separated list of enabled plugins. + var $config = null; // Comma-separated list of miscellaneous config options. + var $configHelper = null; // An instance of ttConfigHelper class. + var $custom_logo = 0; // Whether to use a custom logo for group. var $lock_spec = null; // Cron specification for record locking. var $workday_minutes = 480; // Number of work minutes in a regular day. @@ -104,13 +107,15 @@ class ttGroup { /* $this->custom_logo = $val['custom_logo']; */ + + // TODO: refactor this. $this->config = $val['config']; - $config = new ttConfigHelper($this->config); + $this->configHelper = new ttConfigHelper($val['config']); // Set user config options. - $this->show_holidays = $config->getDefinedValue('show_holidays'); - $this->punch_mode = $config->getDefinedValue('punch_mode'); - $this->allow_overlap = $config->getDefinedValue('allow_overlap'); - $this->future_entries = $config->getDefinedValue('future_entries'); + $this->show_holidays = $this->configHelper->getDefinedValue('show_holidays'); + $this->punch_mode = $this->configHelper->getDefinedValue('punch_mode'); + $this->allow_overlap = $this->configHelper->getDefinedValue('allow_overlap'); + $this->future_entries = $this->configHelper->getDefinedValue('future_entries'); } // Determine active user count in a separate query. diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index dd4a81d5..5ee67f59 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -68,7 +68,11 @@ class ttUser { var $password_complexity = null; // Password complexity example. var $currency = null; // Currency. var $plugins = null; // Comma-separated list of enabled plugins. + + // Refactoring ongoing. Towards using helper instead of config string? var $config = null; // Comma-separated list of miscellaneous config options. + var $configHelper = null; // An instance of ttConfigHelper class. + var $custom_logo = 0; // Whether to use a custom logo for group. var $lock_spec = null; // Cron specification for record locking. var $workday_minutes = 480; // Number of work minutes in a regular day. @@ -137,13 +141,15 @@ class ttUser { $this->workday_minutes = $val['workday_minutes']; $this->custom_logo = $val['custom_logo']; + // TODO: refactor this. $this->config = $val['config']; - $config = new ttConfigHelper($this->config); + $this->configHelper = new ttConfigHelper($val['config']); + // Set user config options. - $this->show_holidays = $config->getDefinedValue('show_holidays'); - $this->punch_mode = $config->getDefinedValue('punch_mode'); - $this->allow_overlap = $config->getDefinedValue('allow_overlap'); - $this->future_entries = $config->getDefinedValue('future_entries'); + $this->show_holidays = $this->configHelper->getDefinedValue('show_holidays'); + $this->punch_mode = $this->configHelper->getDefinedValue('punch_mode'); + $this->allow_overlap = $this->configHelper->getDefinedValue('allow_overlap'); + $this->future_entries = $this->configHelper->getDefinedValue('future_entries'); // Set "on behalf" id and name (user). if (isset($_SESSION['behalf_id'])) { @@ -229,7 +235,7 @@ class ttUser { // getConfig returns config string for active group. function getConfig() { - return ($this->behalfGroup ? $this->behalfGroup->config : $this->config); + return ($this->behalfGroup ? $this->behalfGroup->configHelper->getConfig() : $this->configHelper->getConfig()); } // getConfigOption returns true if an option is defined for group. @@ -263,6 +269,19 @@ class ttUser { return in_array($plugin, explode(',', $this->getPlugins())); } + // isOptionEnabled checks whether a config option is enabled for user. + function isOptionEnabled($option) + { + return $this->behalfGroup ? $this->behalfGroup->configHelper->getDefinedValue($option) : $this->configHelper->getDefinedValue($option); + } + + // setOption sets an option inside of ttConfigHelper instance. + // Note that it does not write to the database. + function setOption($option, $enable = true) + { + return $this->behalfGroup ? $this->behalfGroup->configHelper->setDefinedValue($option, $enable) : $this->configHelper->setDefinedValue($option, $enable); + } + // getAssignedProjects - returns an array of assigned projects. function getAssignedProjects($includeFiles = false) { diff --git a/WEB-INF/templates/expense_edit.tpl b/WEB-INF/templates/expense_edit.tpl index 850e6442..671e868c 100644 --- a/WEB-INF/templates/expense_edit.tpl +++ b/WEB-INF/templates/expense_edit.tpl @@ -134,7 +134,7 @@ function recalculateCost() { {if $user->isPluginEnabled('cl')} - + {/if} diff --git a/WEB-INF/templates/expenses.tpl b/WEB-INF/templates/expenses.tpl index df0eb4d1..7272f01f 100644 --- a/WEB-INF/templates/expenses.tpl +++ b/WEB-INF/templates/expenses.tpl @@ -125,7 +125,7 @@ function recalculateCost() { {/if} {if $user->isPluginEnabled('cl')} - + {/if} diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 2edaa4b1..e806ad80 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
{$i18n.label.client} {if $user->isPluginEnabled('cm')}(*){/if}:{$i18n.label.client} {if $user->isOptionEnabled('client_required')}(*){/if}: {$forms.expenseItemForm.client.control}
{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:{$i18n.label.client}{if $user->isOptionEnabled('client_required')} (*){/if}: {$forms.expensesForm.client.control}
-
 Anuko Time Tracker 1.19.3.4986 | Copyright © Anuko | +  Anuko Time Tracker 1.19.3.4987 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/expense_edit.tpl b/WEB-INF/templates/mobile/expense_edit.tpl index 708cc23c..d4834ae1 100644 --- a/WEB-INF/templates/mobile/expense_edit.tpl +++ b/WEB-INF/templates/mobile/expense_edit.tpl @@ -134,7 +134,7 @@ function recalculateCost() { {if $user->isPluginEnabled('cl')} - + {/if} diff --git a/WEB-INF/templates/mobile/expenses.tpl b/WEB-INF/templates/mobile/expenses.tpl index 7afde73d..81d7a214 100644 --- a/WEB-INF/templates/mobile/expenses.tpl +++ b/WEB-INF/templates/mobile/expenses.tpl @@ -134,7 +134,7 @@ function recalculateCost() { {/if} {if $user->isPluginEnabled('cl')} - + {/if} diff --git a/WEB-INF/templates/time.tpl b/WEB-INF/templates/time.tpl index 0dcfd107..e3266076 100644 --- a/WEB-INF/templates/time.tpl +++ b/WEB-INF/templates/time.tpl @@ -26,7 +26,7 @@ {/if} {if $show_client} - + {/if} diff --git a/WEB-INF/templates/time_edit.tpl b/WEB-INF/templates/time_edit.tpl index 66778e17..42b1674d 100644 --- a/WEB-INF/templates/time_edit.tpl +++ b/WEB-INF/templates/time_edit.tpl @@ -24,7 +24,7 @@ function confirmSave() {
{$i18n.label.client} {if $user->isPluginEnabled('cm')}(*){/if}:{$i18n.label.client} {if $user->isOptionEnabled('client_required')}(*){/if}: {$forms.expenseItemForm.client.control}
{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:{$i18n.label.client}{if $user->isOptionEnabled('client_required')} (*){/if}: {$forms.expensesForm.client.control}
{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:{$i18n.label.client}{if $user->isOptionEnabled('client_required')} (*){/if}: {$forms.timeRecordForm.client.control}
{if $user->isPluginEnabled('cl')} - + {/if} diff --git a/WEB-INF/templates/week.tpl b/WEB-INF/templates/week.tpl index e786ba85..366762cf 100644 --- a/WEB-INF/templates/week.tpl +++ b/WEB-INF/templates/week.tpl @@ -41,7 +41,7 @@ function fillDropdowns() { {/if} {if $show_client} - + {/if} diff --git a/expense_edit.php b/expense_edit.php index 877ec663..3cebac12 100644 --- a/expense_edit.php +++ b/expense_edit.php @@ -160,7 +160,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get( if ($request->isPost()) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($show_project && !$cl_project) $err->add($i18n->get('error.project')); diff --git a/expenses.php b/expenses.php index e1eaedda..2c25bde6 100644 --- a/expenses.php +++ b/expenses.php @@ -190,7 +190,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_submit','onclick'=>'browser_ if ($request->isPost()) { if ($request->getParameter('btn_submit')) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($show_project && !$cl_project) $err->add($i18n->get('error.project')); diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index 10035a9b..654d1698 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -155,7 +155,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get( if ($request->isPost()) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($show_project && !$cl_project) $err->add($i18n->get('error.project')); diff --git a/mobile/expenses.php b/mobile/expenses.php index 1b8f7cda..3b229368 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -195,7 +195,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_submit','onclick'=>'browser_ if ($request->isPost()) { if ($request->getParameter('btn_submit')) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($show_project && !$cl_project) $err->add($i18n->get('error.project')); diff --git a/mobile/time.php b/mobile/time.php index 30c7a402..5a5c054d 100644 --- a/mobile/time.php +++ b/mobile/time.php @@ -249,7 +249,7 @@ if ($request->isPost()) { if ($request->getParameter('btn_submit')) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); diff --git a/mobile/time_edit.php b/mobile/time_edit.php index b33b0991..364ebaf8 100644 --- a/mobile/time_edit.php +++ b/mobile/time_edit.php @@ -234,7 +234,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get( if ($request->isPost()) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); diff --git a/mobile/timer.php b/mobile/timer.php index a8f708a8..66753632 100644 --- a/mobile/timer.php +++ b/mobile/timer.php @@ -186,7 +186,7 @@ if ($request->isPost()) { $cl_finish = null; // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); diff --git a/plugins.php b/plugins.php index dc3b7a5d..4d2972bf 100644 --- a/plugins.php +++ b/plugins.php @@ -62,7 +62,7 @@ if ($request->isPost()) { $plugins = explode(',', $user->getPlugins()); $cl_charts = in_array('ch', $plugins); $cl_clients = in_array('cl', $plugins); - $cl_client_required = in_array('cm', $plugins); + $cl_client_required = $user->isOptionEnabled('client_required'); $cl_invoices = in_array('iv', $plugins); $cl_paid_status = in_array('ps', $plugins); $cl_custom_fields = in_array('cf', $plugins); @@ -114,8 +114,6 @@ if ($request->isPost()) { $plugins .= ',ch'; if ($cl_clients) $plugins .= ',cl'; - if ($cl_client_required) - $plugins .= ',cm'; if ($cl_invoices) $plugins .= ',iv'; if ($cl_paid_status) @@ -158,8 +156,14 @@ if ($request->isPost()) { $plugins = trim($plugins, ','); + // Prepare a new config string. + $user->setOption('client_required', $cl_client_required); + $user->setOption('tax_expenses', $cl_tax_expenses); + $config = $user->getConfig(); + if ($user->updateGroup(array( - 'plugins' => $plugins))) { + 'plugins' => $plugins, + 'config' => $config))) { header('Location: success.php'); exit(); } else diff --git a/time.php b/time.php index e7ff10ae..ca48056a 100644 --- a/time.php +++ b/time.php @@ -306,7 +306,7 @@ if ($request->isPost()) { if ($request->getParameter('btn_submit')) { // Validate user input. - if ($showClient && $user->isPluginEnabled('cm') && !$cl_client) + if ($showClient && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); diff --git a/time_edit.php b/time_edit.php index bbc95ead..bb045738 100644 --- a/time_edit.php +++ b/time_edit.php @@ -239,7 +239,7 @@ $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get( if ($request->isPost()) { // Validate user input. - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); diff --git a/week.php b/week.php index e2aa2d9d..05d39921 100644 --- a/week.php +++ b/week.php @@ -349,7 +349,7 @@ if ($request->isPost()) { } } if ($newEntryPosted) { - if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) + if ($user->isPluginEnabled('cl') && $user->isOptionEnabled('client_required') && !$cl_client) $err->add($i18n->get('error.client')); if ($custom_fields) { if (!ttValidString($cl_cf_1, !$custom_fields->fields[0]['required'])) $err->add($i18n->get('error.field'), $custom_fields->fields[0]['label']); -- 2.20.1
{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:{$i18n.label.client}{if $user->isOptionEnabled('client_required')} (*){/if}: {$forms.timeRecordForm.client.control}
{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:{$i18n.label.client}{if $user->isOptionEnabled('client_required')} (*){/if}: {$forms.weekTimeForm.client.control}