From 873cee05ecd24aa9066b467b2c90132ee08a99a1 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 9 Sep 2018 17:46:27 +0000 Subject: [PATCH] Work in progress on separate page for plugins config. --- WEB-INF/templates/group_edit.tpl | 2 +- WEB-INF/templates/plugins.tpl | 147 ++++++++++++++++++++++++++++++ plugins.php | 151 +++++++++++++++++++++++++++++++ 3 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 WEB-INF/templates/plugins.tpl create mode 100644 plugins.php diff --git a/WEB-INF/templates/group_edit.tpl b/WEB-INF/templates/group_edit.tpl index db66201c..d2a9476a 100644 --- a/WEB-INF/templates/group_edit.tpl +++ b/WEB-INF/templates/group_edit.tpl @@ -16,7 +16,7 @@ function handleTaskRequiredCheckbox() { } -// handleControls - controls visibility of controls. +// handlePluginCheckboxes - controls visibility of controls. function handlePluginCheckboxes() { var clientsCheckbox = document.getElementById("clients"); var invoicesCheckbox = document.getElementById("invoices"); diff --git a/WEB-INF/templates/plugins.tpl b/WEB-INF/templates/plugins.tpl new file mode 100644 index 00000000..f72d5699 --- /dev/null +++ b/WEB-INF/templates/plugins.tpl @@ -0,0 +1,147 @@ + + +{$forms.pluginsForm.open} + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{$forms.pluginsForm.charts.control}
{$forms.pluginsForm.clients.control} {$forms.pluginsForm.client_required.control}
{$forms.pluginsForm.invoices.control}
{$forms.pluginsForm.paid_status.control}
{$forms.pluginsForm.custom_fields.control} {$i18n.label.configure}
{$forms.pluginsForm.expenses.control} {$forms.pluginsForm.tax_expenses.control} {$i18n.label.configure}
{$forms.pluginsForm.notifications.control} {$i18n.label.configure}
{$forms.pluginsForm.locking.control} {$i18n.label.configure}
{$forms.pluginsForm.quotas.control} {$i18n.label.configure}
{$forms.pluginsForm.week_view.control} {$i18n.label.configure}
{$forms.pluginsForm.work_units.control} {$i18n.label.configure}
 
{$forms.pluginsForm.btn_save.control}
+
+{$forms.pluginsForm.close} diff --git a/plugins.php b/plugins.php new file mode 100644 index 00000000..fce36a7e --- /dev/null +++ b/plugins.php @@ -0,0 +1,151 @@ +config); + + +if ($request->isPost()) { + // Plugin checkboxes. + $cl_charts = $request->getParameter('charts'); + $cl_clients = $request->getParameter('clients'); + $cl_client_required = $request->getParameter('client_required'); + $cl_invoices = $request->getParameter('invoices'); + $cl_paid_status = $request->getParameter('paid_status'); + $cl_custom_fields = $request->getParameter('custom_fields'); + $cl_expenses = $request->getParameter('expenses'); + $cl_tax_expenses = $request->getParameter('tax_expenses'); + $cl_notifications = $request->getParameter('notifications'); + $cl_locking = $request->getParameter('locking'); + $cl_quotas = $request->getParameter('quotas'); + $cl_week_view = $request->getParameter('week_view'); + $cl_work_units = $request->getParameter('work_units'); +} else { + // Which plugins do we have enabled? + $plugins = explode(',', $user->plugins); + $cl_charts = in_array('ch', $plugins); + $cl_clients = in_array('cl', $plugins); + $cl_client_required = in_array('cm', $plugins); + $cl_invoices = in_array('iv', $plugins); + $cl_paid_status = in_array('ps', $plugins); + $cl_custom_fields = in_array('cf', $plugins); + $cl_expenses = in_array('ex', $plugins); + $cl_tax_expenses = in_array('et', $plugins); + $cl_notifications = in_array('no', $plugins); + $cl_locking = in_array('lk', $plugins); + $cl_quotas = in_array('mq', $plugins); + $cl_week_view = in_array('wv', $plugins); + $cl_work_units = in_array('wu', $plugins); +} + +$form = new Form('pluginsForm'); + +// Plugin checkboxes. +$form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts)); +$form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required)); +$form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices)); +$form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status)); +$form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses)); +$form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()')); +$form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_units,'onchange'=>'handlePluginCheckboxes()')); + +$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save'))); + +if ($request->isPost()) { + + // Validate user input. Do we have to? + + if ($err->no()) { + // Prepare plugins string. + if ($cl_charts) + $plugins .= ',ch'; + if ($cl_clients) + $plugins .= ',cl'; + if ($cl_client_required) + $plugins .= ',cm'; + if ($cl_invoices) + $plugins .= ',iv'; + if ($cl_paid_status) + $plugins .= ',ps'; + if ($cl_custom_fields) + $plugins .= ',cf'; + if ($cl_expenses) + $plugins .= ',ex'; + if ($cl_tax_expenses) + $plugins .= ',et'; + if ($cl_notifications) + $plugins .= ',no'; + if ($cl_locking) + $plugins .= ',lk'; + if ($cl_quotas) + $plugins .= ',mq'; + if ($cl_week_view) + $plugins .= ',wv'; + if ($cl_work_units) + $plugins .= ',wu'; + + // Recycle week view plugin options as they are not configured on this page. + $existing_plugins = explode(',', $user->plugins); + if (in_array('wvn', $existing_plugins)) + $plugins .= ',wvn'; + if (in_array('wvl', $existing_plugins)) + $plugins .= ',wvl'; + if (in_array('wvns', $existing_plugins)) + $plugins .= ',wvns'; + + $plugins = trim($plugins, ','); + + if ($user->updateGroup(array( + 'plugins' => $plugins))) { + header('Location: time.php'); + exit(); + } else + $err->add($i18n->get('error.db')); + } +} // isPost + +$smarty->assign('forms', array($form->getName()=>$form->toArray())); +$smarty->assign('onload', 'onLoad="handlePluginCheckboxes();"'); +$smarty->assign('title', $i18n->get('form.group_edit.plugins')); // TODO: fix this in transl;ation files. +$smarty->assign('content_page_name', 'plugins.tpl'); +$smarty->display('index.tpl'); -- 2.20.1