summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-04-26 15:34:58 +0200
committerSimon Rettberg2017-04-26 15:34:58 +0200
commit2a368cb3e597e35b467a6aebbaf35d42747681f5 (patch)
treeb62b33d104200009dbd62a8272da76337e1b2054
parent[baseconfig_bwlp] Update translations (diff)
downloadslx-admin-2a368cb3e597e35b467a6aebbaf35d42747681f5.tar.gz
slx-admin-2a368cb3e597e35b467a6aebbaf35d42747681f5.tar.xz
slx-admin-2a368cb3e597e35b467a6aebbaf35d42747681f5.zip
[baseconfig] Display inherited value and source when editing module specific settings
This optionally requires a callback to find the inheritance source in the module in question. The locations module was updated accordingly. This implements #3120
-rw-r--r--modules-available/baseconfig/lang/de/template-tags.json4
-rw-r--r--modules-available/baseconfig/lang/en/template-tags.json4
-rw-r--r--modules-available/baseconfig/page.inc.php65
-rw-r--r--modules-available/baseconfig/templates/_page.html16
-rw-r--r--modules-available/locations/baseconfig/hook.json3
-rw-r--r--modules-available/locations/inc/location.inc.php16
6 files changed, 81 insertions, 27 deletions
diff --git a/modules-available/baseconfig/lang/de/template-tags.json b/modules-available/baseconfig/lang/de/template-tags.json
index cdd54f6a..7d6da790 100644
--- a/modules-available/baseconfig/lang/de/template-tags.json
+++ b/modules-available/baseconfig/lang/de/template-tags.json
@@ -1,7 +1,9 @@
{
"lang_basicConfiguration": "Basiskonfiguration",
"lang_clientRelatedConfig": "Die Optionen auf dieser Seite beziehen sich auf das Verhalten der bwLehrpool-Clients.",
+ "lang_defaultValue": "Standard",
"lang_editOverrideNotice": "Sie bearbeiten die Einstellungen f\u00fcr einen Unterbereich",
"lang_enableOverride": "\u00dcberschreiben",
- "lang_settingActive": "Einstellung aktiv"
+ "lang_inheritSource": "Geerbt von",
+ "lang_settingActive": "Einstellung aktivieren"
} \ No newline at end of file
diff --git a/modules-available/baseconfig/lang/en/template-tags.json b/modules-available/baseconfig/lang/en/template-tags.json
index 8e75e5ac..1a32cb0d 100644
--- a/modules-available/baseconfig/lang/en/template-tags.json
+++ b/modules-available/baseconfig/lang/en/template-tags.json
@@ -1,7 +1,9 @@
{
"lang_basicConfiguration": "Basic Configuration",
"lang_clientRelatedConfig": "The options on this page are related to the bwLehrpool client machines.",
+ "lang_defaultValue": "Default",
"lang_editOverrideNotice": "You're editing the settings of a sub-section",
"lang_enableOverride": "Override",
- "lang_settingActive": "Setting active"
+ "lang_inheritSource": "Inherited from",
+ "lang_settingActive": "Enable setting"
} \ No newline at end of file
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php
index 5e99f2a0..bd9d6683 100644
--- a/modules-available/baseconfig/page.inc.php
+++ b/modules-available/baseconfig/page.inc.php
@@ -124,9 +124,6 @@ class Page_BaseConfig extends Page
Util::redirect('?do=BaseConfig');
}
}
- // List config options
- $settings = array();
- $vars = BaseConfigUtil::getVariables();
// Get stuff that's set in DB already
if ($this->targetModule === false) {
$fields = ', enabled';
@@ -141,19 +138,28 @@ class Page_BaseConfig extends Page
$where = '';
$params = array();
}
+ // List config options
+ $settings = array();
+ $vars = BaseConfigUtil::getVariables();
+ // Remember missing variables
+ $missing = $vars;
// Populate structure with existing config from db
- $res = Database::simpleQuery("SELECT setting, value, displayvalue $fields FROM {$this->qry_extra['table']} "
- . " {$where} ORDER BY setting ASC", $params);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- if (!isset($vars[$row['setting']]) || !is_array($vars[$row['setting']])) {
- $unknown[] = $row['setting'];
- continue;
+ $this->fillSettings($vars, $settings, $missing, $this->qry_extra['table'], $fields, $where, $params, false);
+ if (isset($this->qry_extra['getfallback']) && !empty($missing)) {
+ $method = explode('::', $this->qry_extra['getfallback']);
+ $fieldValue = $this->qry_extra['field_value'];
+ $tries = 0;
+ while (++$tries < 100 && !empty($missing)) {
+ $ret = call_user_func($method, $fieldValue);
+ if ($ret === false)
+ break;
+ $fieldValue = $ret['value'];
+ $params = array('field_value' => $fieldValue);
+ $this->fillSettings($vars, $settings, $missing, $this->qry_extra['table'], $fields, $where, $params, $ret['display']);
}
- $row += $vars[$row['setting']];
- if (!isset($row['catid'])) {
- $row['catid'] = 'unknown';
- }
- $settings[$row['catid']]['settings'][$row['setting']] = $row;
+ }
+ if ($this->targetModule !== false && !empty($missing)) {
+ $this->fillSettings($vars, $settings, $missing, 'setting_global', '', '', array(), 'Global');
}
// Add entries that weren't in the db (global), setup override checkbox (module specific)
foreach ($vars as $key => $var) {
@@ -162,10 +168,7 @@ class Page_BaseConfig extends Page
if (!isset($settings[$var['catid']]['settings'][$key]['enabled']) || $settings[$var['catid']]['settings'][$key]['enabled'] == 1) {
$settings[$var['catid']]['settings'][$key]['checked'] = 'checked';
}
- } elseif (isset($settings[$var['catid']]['settings'][$key])) {
- // Module specific - value is set in DB
- $settings[$var['catid']]['settings'][$key]['checked'] = 'checked';
- } else {
+ } elseif (!isset($settings[$var['catid']]['settings'][$key])) {
// Module specific - value is not set in DB
$settings[$var['catid']]['settings'][$key] = $var + array(
'setting' => $key
@@ -216,6 +219,32 @@ class Page_BaseConfig extends Page
Module::isAvailable('bootstrap_switch');
}
+ private function fillSettings($vars, &$settings, &$missing, $table, $fields, $where, $params, $sourceName)
+ {
+ $res = Database::simpleQuery("SELECT setting, value, displayvalue $fields FROM $table "
+ . " {$where} ORDER BY setting ASC", $params);
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if (!isset($missing[$row['setting']]))
+ continue;
+ if (!isset($vars[$row['setting']]) || !is_array($vars[$row['setting']])) {
+ $unknown[] = $row['setting'];
+ continue;
+ }
+ unset($missing[$row['setting']]);
+ if ($sourceName !== false) {
+ $row['defaultvalue'] = '';
+ $row['defaultsource'] = $sourceName;
+ } elseif ($this->targetModule !== false) {
+ $row['checked'] = 'checked';
+ }
+ $row += $vars[$row['setting']];
+ if (!isset($row['catid'])) {
+ $row['catid'] = 'unknown';
+ }
+ $settings[$row['catid']]['settings'][$row['setting']] = $row;
+ }
+ }
+
private function getCurrentModuleName()
{
if (isset($this->qry_extra['tostring'])) {
diff --git a/modules-available/baseconfig/templates/_page.html b/modules-available/baseconfig/templates/_page.html
index 7f380495..e0be35bc 100644
--- a/modules-available/baseconfig/templates/_page.html
+++ b/modules-available/baseconfig/templates/_page.html
@@ -25,18 +25,22 @@
<div class="row">
<div class="col-md-5 slx-cfg-toggle">
<div>{{setting}}</div>
- {{^override}}
<div class="slx-default">
+ {{#defaultvalue}}{{lang_defaultValue}}:{{/defaultvalue}}
{{defaultvalue}}
</div>
- <input class="bs-switch" name="override[{{setting}}]" id="CB_{{setting}}" type="checkbox" {{checked}}> <label for="CB_{{setting}}">{{lang_settingActive}}</label>
- {{/override}}
- {{#override}}
- <input class="bs-switch" name="override[{{setting}}]" id="CB_{{setting}}" type="checkbox" {{checked}}> <label for="CB_{{setting}}">{{lang_enableOverride}}</label>
- {{/override}}
+ <input class="bs-switch" name="override[{{setting}}]" id="CB_{{setting}}" type="checkbox" {{checked}}>
+ <label for="CB_{{setting}}">
+ {{#override}}{{lang_enableOverride}}{{/override}}
+ {{^override}}{{lang_settingActive}}{{/override}}
+ </label>
</div>
<div class="col-md-5">
{{{item}}}
+ <div class="slx-default">
+ {{#defaultsource}}{{lang_inheritSource}}:{{/defaultsource}}
+ {{defaultsource}}
+ </div>
</div>
<div class="col-md-2">
<a class="btn btn-default" data-toggle="modal" data-target="#help-{{setting}}"><span class="glyphicon glyphicon-question-sign"></span></a>
diff --git a/modules-available/locations/baseconfig/hook.json b/modules-available/locations/baseconfig/hook.json
index c295e0f6..b7b3581b 100644
--- a/modules-available/locations/baseconfig/hook.json
+++ b/modules-available/locations/baseconfig/hook.json
@@ -1,5 +1,6 @@
{
"table": "setting_location",
"field": "locationid",
- "tostring": "Location::getName"
+ "tostring": "Location::getName",
+ "getfallback": "Location::getBaseconfigParent"
} \ No newline at end of file
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 73080094..9977379f 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -280,6 +280,22 @@ class Location
}
/**
+ * @param $locationId
+ * @return bool|array ('value' => x, 'display' => y), false if no parent or unknown id
+ */
+ public static function getBaseconfigParent($locationId)
+ {
+ settype($locationId, 'integer');
+ $locations = Location::getLocationsAssoc();
+ if (!isset($locations[$locationId]))
+ return false;
+ $locationId = (int)$locations[$locationId]['parentlocationid'];
+ if (!isset($locations[$locationId]))
+ return false;
+ return array('value' => $locationId, 'display' => $locations[$locationId]['locationname']);
+ }
+
+ /**
* @return array list of subnets as numeric array
*/
public static function getSubnets()