Work in progress on separate page for plugins config.
[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 $config = new ttConfigHelper($user->config);
40
41
42 if ($request->isPost()) {
43   // Plugin checkboxes.
44   $cl_charts = $request->getParameter('charts');
45   $cl_clients = $request->getParameter('clients');
46   $cl_client_required = $request->getParameter('client_required');
47   $cl_invoices = $request->getParameter('invoices');
48   $cl_paid_status = $request->getParameter('paid_status');
49   $cl_custom_fields = $request->getParameter('custom_fields');
50   $cl_expenses = $request->getParameter('expenses');
51   $cl_tax_expenses = $request->getParameter('tax_expenses');
52   $cl_notifications = $request->getParameter('notifications');
53   $cl_locking = $request->getParameter('locking');
54   $cl_quotas = $request->getParameter('quotas');
55   $cl_week_view = $request->getParameter('week_view');
56   $cl_work_units = $request->getParameter('work_units');
57 } else {
58   // Which plugins do we have enabled?
59   $plugins = explode(',', $user->plugins);
60   $cl_charts = in_array('ch', $plugins);
61   $cl_clients = in_array('cl', $plugins);
62   $cl_client_required = in_array('cm', $plugins);
63   $cl_invoices = in_array('iv', $plugins);
64   $cl_paid_status = in_array('ps', $plugins);
65   $cl_custom_fields = in_array('cf', $plugins);
66   $cl_expenses = in_array('ex', $plugins);
67   $cl_tax_expenses = in_array('et', $plugins);
68   $cl_notifications = in_array('no', $plugins);
69   $cl_locking = in_array('lk', $plugins);
70   $cl_quotas = in_array('mq', $plugins);
71   $cl_week_view = in_array('wv', $plugins);
72   $cl_work_units = in_array('wu', $plugins);
73 }
74
75 $form = new Form('pluginsForm');
76
77 // Plugin checkboxes.
78 $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
79 $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
80 $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
81 $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
82 $form->addInput(array('type'=>'checkbox','name'=>'paid_status','value'=>$cl_paid_status));
83 $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
84 $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
85 $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
86 $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
87 $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
88 $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
89 $form->addInput(array('type'=>'checkbox','name'=>'week_view','value'=>$cl_week_view,'onchange'=>'handlePluginCheckboxes()'));
90 $form->addInput(array('type'=>'checkbox','name'=>'work_units','value'=>$cl_work_units,'onchange'=>'handlePluginCheckboxes()'));
91
92 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save')));
93
94 if ($request->isPost()) {
95
96   // Validate user input. Do we have to?
97
98   if ($err->no()) {
99     // Prepare plugins string.
100     if ($cl_charts)
101       $plugins .= ',ch';
102     if ($cl_clients)
103       $plugins .= ',cl';
104     if ($cl_client_required)
105       $plugins .= ',cm';
106     if ($cl_invoices)
107       $plugins .= ',iv';
108     if ($cl_paid_status)
109       $plugins .= ',ps';
110     if ($cl_custom_fields)
111       $plugins .= ',cf';
112     if ($cl_expenses)
113       $plugins .= ',ex';
114     if ($cl_tax_expenses)
115       $plugins .= ',et';
116     if ($cl_notifications)
117       $plugins .= ',no';
118     if ($cl_locking)
119       $plugins .= ',lk';
120     if ($cl_quotas)
121       $plugins .= ',mq';
122     if ($cl_week_view)
123       $plugins .= ',wv';
124     if ($cl_work_units)
125       $plugins .= ',wu';
126
127     // Recycle week view plugin options as they are not configured on this page.
128     $existing_plugins = explode(',', $user->plugins);
129     if (in_array('wvn', $existing_plugins))
130       $plugins .= ',wvn';
131     if (in_array('wvl', $existing_plugins))
132       $plugins .= ',wvl';
133     if (in_array('wvns', $existing_plugins))
134       $plugins .= ',wvns';
135
136     $plugins = trim($plugins, ',');
137
138     if ($user->updateGroup(array(
139       'plugins' => $plugins))) {
140       header('Location: time.php');
141       exit();
142     } else
143       $err->add($i18n->get('error.db'));
144   }
145 } // isPost
146
147 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
148 $smarty->assign('onload', 'onLoad="handlePluginCheckboxes();"');
149 $smarty->assign('title', $i18n->get('form.group_edit.plugins')); // TODO: fix this in transl;ation files.
150 $smarty->assign('content_page_name', 'plugins.tpl');
151 $smarty->display('index.tpl');