Templatize admin/settings.php
[bugdar.git] / admin / settings.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 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 $fetchtemplates = array(
23 'settings'
24 );
25
26 require_once('./global.php');
27 require_once('./includes/class_sort.php');
28 require_once('./includes/functions_datastore.php');
29
30 if (!can_perform('canadmintools'))
31 {
32 admin_login();
33 }
34
35 // ###################################################################
36
37 if (empty($_REQUEST['do']))
38 {
39 $_REQUEST['do'] = 'modify';
40 }
41
42 // ###################################################################
43
44 if ($_POST['do'] == 'update')
45 {
46 $updates = array();
47 foreach ($input->in['settings'] as $varname => $value)
48 {
49 if (is_array($value))
50 {
51 if ($varname == 'columnoptions')
52 {
53 $value = serialize($value);
54 }
55 else
56 {
57 $value = implode(',', $value);
58 }
59 }
60
61 $updates[] = "('" . $input->escape($varname) . "', '" . $input->escape($value) . "')";
62 }
63
64 $db->query("REPLACE INTO " . TABLE_PREFIX . "setting (varname, value) VALUES " . implode(',', $updates));
65
66 build_settings();
67
68 $admin->redirect('settings.php');
69 }
70
71 // ###################################################################
72
73 if ($_REQUEST['do'] == 'modify')
74 {
75 $admin = new BSTemplate('settings');
76
77 // authmethod
78 $methods = BSFunctions::scan_directory('./includes/auth/');
79 $admin->vars['authmethods'] = '';
80 foreach ($methods AS $path)
81 {
82 if (preg_match('#auth_(.*)\.php#', $path, $matches))
83 {
84 $admin->vars['authmethods'] .= '<option value="' . $matches[1] . '"' . ($matches[1] == bugdar::$options['authmethod'] ? ' selected="selected"' : '') . '>' . ucwords(str_replace('_', ' ', $matches[1])) . '</option>';
85 }
86 }
87
88 $admin->evaluate()->flush();
89 }
90
91 // ###################################################################
92 /**
93 * Helper function for the bugdar::$options['columnoptions'] setting
94 *
95 * @return string Setting HTML code
96 */
97 function ConstructColumnOptionsSetting()
98 {
99 global $bugsys;
100
101 require_once('./includes/class_sort.php');
102
103 $array = (bugdar::$options['columnoptions'] == null ? array('bugid' => 1, 'summary' => 2, 'userid' => 2, 'product' => 3, 'version' => 3, 'component' => 0, 'status' => 4, 'resolution' => 4, 'priority' => 5, 'severity' => 5, 'lastpost' => 6, 'votes' => 0) : bugdar::$options['columnoptions']);
104
105 $return = '<table cellspacing="2" cellpadding="1" border="0">';
106 foreach (ListSorter::fetch_by_text(false, false) AS $column => $name)
107 {
108 $return .= '<tr><td><strong>' . $name . '</strong></td><td><input type="text" name="setting[columnoptions][' . $column . ']" size="2" maxlength="2" class="input" value="' . intval($array["$column"]) . '" /></td></tr>';
109 }
110 $return .= '</table>';
111 return $return;
112 }
113
114 ?>