-
Notifications
You must be signed in to change notification settings - Fork 120
/
plugins.php
145 lines (134 loc) · 6.21 KB
/
plugins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/* Copyright (c) Anuko International Ltd. https://www.anuko.com
License: See license.txt */
require_once('initialize.php');
import('form.Form');
// Access checks.
if (!ttAccessAllowed('manage_features')) {
header('Location: access_denied.php');
exit();
}
// End of access checks.
if ($request->isPost()) {
// Plugins that user wants to save for the current group.
$cl_charts = (bool)$request->getParameter('charts');
$cl_puncher = (bool)$request->getParameter('puncher');
$cl_clients = (bool)$request->getParameter('clients');
$cl_client_required = (bool)$request->getParameter('client_required');
$cl_invoices = (bool)$request->getParameter('invoices');
$cl_paid_status = (bool)$request->getParameter('paid_status');
$cl_custom_fields = (bool)$request->getParameter('custom_fields');
$cl_expenses = (bool)$request->getParameter('expenses');
$cl_tax_expenses = (bool)$request->getParameter('tax_expenses');
$cl_notifications = (bool)$request->getParameter('notifications');
$cl_locking = (bool)$request->getParameter('locking');
$cl_quotas = (bool)$request->getParameter('quotas');
$cl_week_view = (bool)$request->getParameter('week_view');
$cl_work_units = (bool)$request->getParameter('work_units');
$cl_approval = (bool)$request->getParameter('approval');
$cl_timesheets = (bool)$request->getParameter('timesheets');
$cl_templates = (bool)$request->getParameter('templates');
$cl_attachments = (bool)$request->getParameter('attachments');
} else {
// Note: we get here in get, and also in post when group changes.
// Which plugins do we have enabled in currently selected group?
$plugins = explode(',', $user->getPlugins() ?? '');
$cl_charts = in_array('ch', $plugins);
$cl_puncher = in_array('pu', $plugins);
$cl_clients = in_array('cl', $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);
$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);
$cl_approval = in_array('ap', $plugins);
$cl_timesheets = in_array('ts', $plugins);
$cl_templates = in_array('tp', $plugins);
$cl_attachments = in_array('at', $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'=>'puncher','value'=>$cl_puncher,'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'=>'checkbox','name'=>'approval','value'=>$cl_approval));
$form->addInput(array('type'=>'checkbox','name'=>'timesheets','value'=>$cl_timesheets));
$form->addInput(array('type'=>'checkbox','name'=>'templates','value'=>$cl_templates,'onchange'=>'handlePluginCheckboxes()'));
$form->addInput(array('type'=>'checkbox','name'=>'attachments','value'=>$cl_attachments,'onchange'=>'handlePluginCheckboxes()'));
// Submit button.
$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
if ($request->isPost()) {
// Note: we get here when the Save button is clicked.
// We update plugin list for the current group.
// Prepare plugins string.
$plugins = '';
if ($cl_charts)
$plugins .= ',ch';
if ($cl_puncher)
$plugins .= ',pu';
if ($cl_clients)
$plugins .= ',cl';
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';
if ($cl_approval)
$plugins .= ',ap';
if ($cl_timesheets)
$plugins .= ',ts';
if ($cl_templates)
$plugins .= ',tp';
if ($cl_attachments)
$plugins .= ',at';
$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,
'config' => $config))) {
header('Location: plugins.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('user_exists', $user->exists());
$smarty->assign('title', $i18n->get('title.plugins'));
$smarty->assign('content_page_name', 'plugins.tpl');
$smarty->display('index.tpl');