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');
33 if (!ttAccessAllowed('manage_features')) {
34 header('Location: access_denied.php');
37 if ($request->isPost()) {
38 $groupChanged = $request->getParameter('group_changed'); // Reused in multiple places below.
39 if ($groupChanged && !($user->can('manage_subgroups') && $user->isGroupValid($request->getParameter('group')))) {
40 header('Location: access_denied.php'); // Group changed, but no rght or wrong group id.
44 // End of access checks.
46 // Determine group for which we display this page.
47 if ($request->isPost() && $groupChanged) {
48 $group_id = $request->getParameter('group');
49 $user->setOnBehalfGroup($group_id);
51 $group_id = $user->getGroup();
54 if ($request->isPost() && $request->getParameter('btn_save')) {
55 // Plugins that user wants to save for the current group.
56 $cl_charts = $request->getParameter('charts');
57 $cl_clients = $request->getParameter('clients');
58 $cl_client_required = $request->getParameter('client_required');
59 $cl_invoices = $request->getParameter('invoices');
60 $cl_paid_status = $request->getParameter('paid_status');
61 $cl_custom_fields = $request->getParameter('custom_fields');
62 $cl_expenses = $request->getParameter('expenses');
63 $cl_tax_expenses = $request->getParameter('tax_expenses');
64 $cl_notifications = $request->getParameter('notifications');
65 $cl_locking = $request->getParameter('locking');
66 $cl_quotas = $request->getParameter('quotas');
67 $cl_week_view = $request->getParameter('week_view');
68 $cl_work_units = $request->getParameter('work_units');
70 // Note: we get here in get, and also in post when group changes.
71 // Which plugins do we have enabled in currently selected group?
72 $plugins = explode(',', $user->getPlugins());
73 $cl_charts = in_array('ch', $plugins);
74 $cl_clients = in_array('cl', $plugins);
75 $cl_client_required = in_array('cm', $plugins);
76 $cl_invoices = in_array('iv', $plugins);
77 $cl_paid_status = in_array('ps', $plugins);
78 $cl_custom_fields = in_array('cf', $plugins);
79 $cl_expenses = in_array('ex', $plugins);
80 $cl_tax_expenses = in_array('et', $plugins);
81 $cl_notifications = in_array('no', $plugins);
82 $cl_locking = in_array('lk', $plugins);
83 $cl_quotas = in_array('mq', $plugins);
84 $cl_week_view = in_array('wv', $plugins);
85 $cl_work_units = in_array('wu', $plugins);
88 $form = new Form('pluginsForm');
90 if ($user->can('manage_subgroups')) {
91 $groups = $user->getGroupsForDropdown();
92 if (count($groups) > 1) {
93 $form->addInput(array('type'=>'combobox',
94 'onchange'=>'document.pluginsForm.group_changed.value=1;document.pluginsForm.submit();',
96 'style'=>'width: 250px;',
99 'datakeys'=>array('id','name')));
100 $form->addInput(array('type'=>'hidden','name'=>'group_changed'));
101 $smarty->assign('group_dropdown', 1);
104 // Plugin checkboxes.
105 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
106 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
107 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
108 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
109 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
110 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
111 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
112 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
113 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
114 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
115 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
116 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
117 $form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_units,'onchange'=>'handlePluginCheckboxes()'));
119 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
121 if ($request->isPost() && $request->getParameter('btn_save')) {
122 // Note: we get here when the Save button is clicked.
123 // We update plugin list for the currently selected group.
125 // We don't get here if group changed in post.
126 // In this case the page is simply re-displayed for new group.
128 // Prepare plugins string.
133 if ($cl_client_required)
139 if ($cl_custom_fields)
143 if ($cl_tax_expenses)
145 if ($cl_notifications)
156 // Recycle week view plugin options as they are not configured on this page.
157 $existing_plugins = explode(',', $user->getPlugins());
158 if (in_array('wvn', $existing_plugins))
160 if (in_array('wvl', $existing_plugins))
162 if (in_array('wvns', $existing_plugins))
165 $plugins = trim($plugins, ',');
167 if ($user->updateGroup(array(
168 'plugins' => $plugins))) {
169 header('Location: success.php');
172 $err->add($i18n->get('error.db'));
175 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
176 $smarty->assign('onload', 'onLoad="handlePluginCheckboxes();"');
177 $smarty->assign('title', $i18n->get('title.plugins'));
178 $smarty->assign('content_page_name', 'plugins.tpl');
179 $smarty->display('index.tpl');