summaryrefslogtreecommitdiffstats
path: root/modules/baseconfig.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-10-30 17:53:58 +0100
committerSimon Rettberg2013-10-30 17:53:58 +0100
commitb42c3a9d4774d0f916634e7163df75cde2e8c2a9 (patch)
treedc16d2d805051fdf0989680b44815c1d49d5d55a /modules/baseconfig.inc.php
parentFirst version of basic minilinux configuration (diff)
downloadslx-admin-b42c3a9d4774d0f916634e7163df75cde2e8c2a9.tar.gz
slx-admin-b42c3a9d4774d0f916634e7163df75cde2e8c2a9.tar.xz
slx-admin-b42c3a9d4774d0f916634e7163df75cde2e8c2a9.zip
Remodel zeug mit settings und so
Diffstat (limited to 'modules/baseconfig.inc.php')
-rw-r--r--modules/baseconfig.inc.php48
1 files changed, 38 insertions, 10 deletions
diff --git a/modules/baseconfig.inc.php b/modules/baseconfig.inc.php
index 9d581624..58c6fa01 100644
--- a/modules/baseconfig.inc.php
+++ b/modules/baseconfig.inc.php
@@ -2,13 +2,41 @@
User::load();
+// Determine if we're setting global, distro or pool
+if (isset($_REQUEST['distro'])) {
+ // TODO: Everything
+ $qry_insert = ', distroid';
+ $qry_values = ', :distroid';
+ $qry_distroid = (int)$_REQUEST['distro'];
+ if (isset($_REQUEST['pool'])) {
+ // TODO: Everything
+ $qry_insert .= ', poolid';
+ $qry_values .= ', :poolid';
+ $qry_poolid .= (int)$_REQUEST['pool'];
+ }
+} else {
+ $qry_insert = '';
+ $qry_values = '';
+ $qry_distroid = '';
+ $qry_poolid = '';
+}
+
+
if (isset($_POST['setting']) && is_array($_POST['setting'])) {
if (User::hasPermission('superadmin')) {
if (Util::verifyToken()) {
- foreach ($_POST['setting'] as $key => $value) {
- Database::exec('UPDATE setting_global SET setting_global.value = :value WHERE setting_global.setting = :key LIMIT 1', array(
- 'key' => $key,
- 'value' => $value,
+ // Load all existing config options to validate input
+ $settings = array();
+ $res = Database::simpleQuery('SELECT setting FROM setting');
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $settings[$row['setting']] = true; // will contain validation regex at some point
+ }
+ foreach (array_keys($settings) as $key) {
+ $value = (isset($_POST['setting'][$key]) ? $_POST['setting'][$key] : '');
+ // use validation regex here
+ Database::exec("INSERT INTO setting_global (setting, value $qry_insert) VALUES (:key, :value $qry_values) ON DUPLICATE KEY UPDATE value = :value", array(
+ 'key' => $key,
+ 'value' => $value,
));
}
Message::addSuccess('settings-updated');
@@ -23,18 +51,18 @@ function render_module()
return;
}
// List global config option
- $rows = array();
- $res = Database::simpleQuery('SELECT setting.setting, setting_global.value, setting.permissions, setting.description
+ $settings = array();
+ $res = Database::simpleQuery('SELECT setting.setting, setting.defaultvalue, setting.permissions, setting.description, tbl.value
FROM setting
- INNER JOIN setting_global USING (setting)
- ORDER BY setting.setting ASC');
+ LEFT JOIN setting_global AS tbl USING (setting)
+ ORDER BY setting ASC'); // TODO: Add setting groups and sort order
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$row['description'] = Util::markup($row['description']);
$row['big'] = false;
- $rows[] = $row;
+ $settings[] = $row;
}
Render::addTemplate('page-baseconfig', array(
- 'settings' => $rows,
+ 'settings' => $settings,
'token' => Session::get('token'),
));
}