Modernise some of the new admin section.
[bugdar.git] / admin / settings.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2013 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 namespace bugdar\admin;
23
24 use \bugdar;
25 use \hoplite\http;
26
27 require_once HOPLITE_ROOT . '/http/rest_action.php';
28 require_once BUGDAR_ROOT . '/includes/functions_datastore.php';
29
30 class SettingsAction extends http\RestAction implements TemplatePreCaching
31 {
32 public function TemplateSet()
33 {
34 return ['admin_settings'];
35 }
36
37 public function DoGet(http\Request $request, http\Response $response)
38 {
39 // TODO(port): global.
40 global $bugsys;
41
42 $response->data['title'] = T('Settings');
43 $response->context['template'] = 'admin_settings';
44
45 $response->data['timezone_list'] = $bugsys->datef->fetch_timezone_list();
46 }
47
48 public function DoPost(http\Request $request, http\Response $response)
49 {
50 $query_bits = array();
51 $values = array();
52 foreach ($request->data['_POST']['settings'] AS $varname => $value) {
53 $query_bits[] = '(?,?)';
54 array_push($values, $varname, $value);
55 }
56
57 $query = bugdar::$db->Prepare("
58 REPLACE into " . TABLE_PREFIX . "setting
59 (varname, value)
60 VALUES " . implode(', ', $query_bits));
61 $query->Execute($values);
62
63 build_settings();
64
65 $this->controller()->StopWithRedirect($this->controller()->MakeURL('/settings'));
66 }
67 }