dc3b7a5d855729309d7b6e607a2acfa215a24102
[timetracker.git] / plugins.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 require_once('initialize.php');
30 import('form.Form');
31
32 // Access checks.
33 if (!ttAccessAllowed('manage_features')) {
34   header('Location: access_denied.php');
35   exit();
36 }
37 // End of access checks.
38
39 if ($request->isPost()) {
40   // Plugins that user wants to save for the current group.
41   $cl_charts = $request->getParameter('charts');
42   $cl_clients = $request->getParameter('clients');
43   $cl_client_required = $request->getParameter('client_required');
44   $cl_invoices = $request->getParameter('invoices');
45   $cl_paid_status = $request->getParameter('paid_status');
46   $cl_custom_fields = $request->getParameter('custom_fields');
47   $cl_expenses = $request->getParameter('expenses');
48   $cl_tax_expenses = $request->getParameter('tax_expenses');
49   $cl_notifications = $request->getParameter('notifications');
50   $cl_locking = $request->getParameter('locking');
51   $cl_quotas = $request->getParameter('quotas');
52   $cl_week_view = $request->getParameter('week_view');
53   $cl_work_units = $request->getParameter('work_units');
54   $cl_approval = $request->getParameter('approval');
55   $cl_timesheets = $request->getParameter('timesheets');
56   $cl_templates = $request->getParameter('templates');
57   $cl_attachments = $request->getParameter('attachments');
58   $cl_work = $request->getParameter('work');
59 } else {
60   // Note: we get here in get, and also in post when group changes.
61   // Which plugins do we have enabled in currently selected group?
62   $plugins = explode(',', $user->getPlugins());
63   $cl_charts = in_array('ch', $plugins);
64   $cl_clients = in_array('cl', $plugins);
65   $cl_client_required = in_array('cm', $plugins);
66   $cl_invoices = in_array('iv', $plugins);
67   $cl_paid_status = in_array('ps', $plugins);
68   $cl_custom_fields = in_array('cf', $plugins);
69   $cl_expenses = in_array('ex', $plugins);
70   $cl_tax_expenses = in_array('et', $plugins);
71   $cl_notifications = in_array('no', $plugins);
72   $cl_locking = in_array('lk', $plugins);
73   $cl_quotas = in_array('mq', $plugins);
74   $cl_week_view = in_array('wv', $plugins);
75   $cl_work_units = in_array('wu', $plugins);
76   $cl_approval = in_array('ap', $plugins);
77   $cl_timesheets = in_array('ts', $plugins);
78   $cl_templates = in_array('tp', $plugins);
79   $cl_attachments = in_array('at', $plugins);
80   $cl_work = in_array('wk', $plugins);
81 }
82
83 $form = new Form('pluginsForm');
84
85 // Plugin checkboxes.
86 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
87 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
88 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
89 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
90 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
91 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
92 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
93 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
94 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
95 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
96 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
97 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
98 $form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_units,'onchange'=>'handlePluginCheckboxes()'));
99 $form->addInput(array('type'=>'checkbox','name'=>'approval','value'=>$cl_approval));
100 $form->addInput(array('type'=>'checkbox','name'=>'timesheets','value'=>$cl_timesheets));
101 $form->addInput(array('type'=>'checkbox','name'=>'templates','value'=>$cl_templates,'onchange'=>'handlePluginCheckboxes()'));
102 $form->addInput(array('type'=>'checkbox','name'=>'attachments','value'=>$cl_attachments,'onchange'=>'handlePluginCheckboxes()'));
103 $form->addInput(array('type'=>'checkbox','name'=>'work','value'=>$cl_work,'onchange'=>'handlePluginCheckboxes()'));
104
105 // Submit button.
106 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
107
108 if ($request->isPost()) {
109   // Note: we get here when the Save button is clicked.
110   // We update plugin list for the current group.
111
112   // Prepare plugins string.
113   if ($cl_charts)
114     $plugins .= ',ch';
115   if ($cl_clients)
116      $plugins .= ',cl';
117   if ($cl_client_required)
118     $plugins .= ',cm';
119   if ($cl_invoices)
120     $plugins .= ',iv';
121   if ($cl_paid_status)
122     $plugins .= ',ps';
123   if ($cl_custom_fields)
124     $plugins .= ',cf';
125   if ($cl_expenses)
126     $plugins .= ',ex';
127   if ($cl_tax_expenses)
128     $plugins .= ',et';
129   if ($cl_notifications)
130     $plugins .= ',no';
131   if ($cl_locking)
132     $plugins .= ',lk';
133   if ($cl_quotas)
134     $plugins .= ',mq';
135   if ($cl_week_view)
136     $plugins .= ',wv';
137   if ($cl_work_units)
138     $plugins .= ',wu';
139   if ($cl_approval)
140     $plugins .= ',ap';
141   if ($cl_timesheets)
142     $plugins .= ',ts';
143   if ($cl_templates)
144     $plugins .= ',tp';
145   if ($cl_attachments)
146     $plugins .= ',at';
147   if ($cl_work)
148     $plugins .= ',wk';
149
150   // Recycle week view plugin options as they are not configured on this page.
151   $existing_plugins = explode(',', $user->getPlugins());
152   if (in_array('wvn', $existing_plugins))
153     $plugins .= ',wvn';
154   if (in_array('wvl', $existing_plugins))
155     $plugins .= ',wvl';
156   if (in_array('wvns', $existing_plugins))
157     $plugins .= ',wvns';
158
159   $plugins = trim($plugins, ',');
160
161   if ($user->updateGroup(array(
162     'plugins' => $plugins))) {
163     header('Location: success.php');
164     exit();
165   } else
166     $err->add($i18n->get('error.db'));
167 } // isPost
168
169 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
170 $smarty->assign('onload', 'onLoad="handlePluginCheckboxes();"');
171 $smarty->assign('user_exists', $user->exists());
172 $smarty->assign('title', $i18n->get('title.plugins'));
173 $smarty->assign('content_page_name', 'plugins.tpl');
174 $smarty->display('index.tpl');