Fix saving settings.
[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/action.php';
28 require_once BUGDAR_ROOT . '/includes/functions_datastore.php';
29
30 class SettingsAction extends http\Action implements TemplatePreCaching
31 {
32 public function TemplateSet()
33 {
34 return array('admin_settings');
35 }
36
37 public function Invoke(http\Request $request, http\Response $response)
38 {
39 $response->data['title'] = T('Settings');
40 $response->context['template'] = 'admin_settings';
41
42 // Save settings on POST.
43 if ($request->http_method == 'POST') {
44 $query_bits = array();
45 $values = array();
46 foreach ($request->data['_POST']['settings'] AS $varname => $value) {
47 $query_bits[] = '(?,?)';
48 array_push($values, $varname, $value);
49 }
50
51 $query = bugdar::$db->Prepare("
52 REPLACE into " . TABLE_PREFIX . "setting
53 (varname, value)
54 VALUES " . implode(', ', $query_bits));
55 $query->Execute($values);
56
57 build_settings();
58 }
59 }
60 }