summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-06 17:48:55 +0200
committerSimon Rettberg2014-10-06 17:48:55 +0200
commit130a2d436991cc35bee5893795220b01f457a3e3 (patch)
treedff633e5156bd921f08e70ee81af1e28e8f3ac3a
parentSupport api calls via cli by using first command line option as module name (diff)
downloadslx-admin-130a2d436991cc35bee5893795220b01f457a3e3.tar.gz
slx-admin-130a2d436991cc35bee5893795220b01f457a3e3.tar.xz
slx-admin-130a2d436991cc35bee5893795220b01f457a3e3.zip
Support list type for configuration variable
-rw-r--r--inc/validator.inc.php15
-rw-r--r--modules/baseconfig.inc.php32
-rw-r--r--templates/baseconfig/_page.html7
3 files changed, 44 insertions, 10 deletions
diff --git a/inc/validator.inc.php b/inc/validator.inc.php
index 72b7fa0b..88be14f2 100644
--- a/inc/validator.inc.php
+++ b/inc/validator.inc.php
@@ -18,6 +18,8 @@ class Validator
case 'regex':
if (preg_match($data[1], $value)) return $value;
return false;
+ case 'list':
+ return self::validateList($data[1], $value);
case 'function':
return self::$data[1]($value);
default:
@@ -38,6 +40,19 @@ class Validator
if (preg_match('/^\$6\$.+\$./', $value)) return $value;
return Crypto::hash6($value);
}
+
+ /**
+ * Validate value against list.
+ * @param string $list The list as a string of items, separated by "|"
+ * @param string $value The value to validate
+ * @return boolean|string The value, if in list, false otherwise
+ */
+ private static function validateList($list, $value)
+ {
+ $list = explode('|', $list);
+ if (in_array($value, $list)) return $value;
+ return false;
+ }
}
diff --git a/modules/baseconfig.inc.php b/modules/baseconfig.inc.php
index 1e4093b2..2f62320e 100644
--- a/modules/baseconfig.inc.php
+++ b/modules/baseconfig.inc.php
@@ -75,22 +75,46 @@ class Page_BaseConfig extends Page
}
// List global config option
$settings = array();
- $res = Database::simpleQuery('SELECT cat_setting.catid, setting.setting, setting.defaultvalue, setting.permissions, tbl.value
+ $res = Database::simpleQuery('SELECT cat_setting.catid, setting.setting, setting.defaultvalue, setting.permissions, setting.validator, tbl.value
FROM setting
INNER JOIN cat_setting USING (catid)
LEFT JOIN setting_global AS tbl USING (setting)
- ORDER BY cat_setting.sortval ASC, setting.setting ASC'); // TODO: Add setting groups and sort order
+ ORDER BY cat_setting.sortval ASC, setting.setting ASC');
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$row['description'] = Util::markup(Dictionary::translate('settings/setting', $row['setting']));
if (is_null($row['value'])) $row['value'] = $row['defaultvalue'];
- $row['big'] = false;
+ $row['item'] = $this->makeInput($row['validator'], $row['setting'], $row['value']);
$settings[$row['catid']]['settings'][] = $row;
$settings[$row['catid']]['category_name'] = Dictionary::translate('settings/cat_setting', 'cat_' . $row['catid']);
}
- Render::addTemplate('page-baseconfig', array(
+ Render::addTemplate('baseconfig/_page', array(
'categories' => array_values($settings)
));
}
+
+ /**
+ * Create html snippet for setting, based on given validator
+ * @param type $validator
+ * @return boolean
+ */
+ private function makeInput($validator, $setting, $current)
+ {
+ $parts = explode(':', $validator, 2);
+ if ($parts[0] === 'list') {
+ $items = explode('|', $parts[1]);
+ $ret = '<select name="setting[' . $setting . ']" class="form-control">';
+ foreach ($items as $item) {
+ if ($item === $current) {
+ $ret .= '<option selected="selected">' . $item . '</option>';
+ } else {
+ $ret .= '<option>' . $item . '</option>';
+ }
+ }
+ return $ret . '</select>';
+ }
+ // Fallback: single line input
+ return '<input type="text" name="setting[' . $setting . ']" class="form-control" size="30" value="' . $current . '">';
+ }
}
diff --git a/templates/baseconfig/_page.html b/templates/baseconfig/_page.html
index ad51fd2f..4829d124 100644
--- a/templates/baseconfig/_page.html
+++ b/templates/baseconfig/_page.html
@@ -13,12 +13,7 @@
<div class="slx-default">{{defaultvalue}}</div>
</div>
<div class="col-md-5">
- {{#big}}
- <textarea name="setting[{{setting}}]" class="form-control" cols="30" rows="3">{{value}}</textarea>
- {{/big}}
- {{^big}}
- <input type="text" name="setting[{{setting}}]" class="form-control" size="30" value="{{value}}">
- {{/big}}
+ {{{item}}}
</div>
<div class="col-md-2">
<a class="btn btn-default" data-toggle="modal" data-target="#help-{{setting}}">{{lang_help}}</a>