diff options
Diffstat (limited to 'modules-available/baseconfig')
-rw-r--r-- | modules-available/baseconfig/api.inc.php | 22 | ||||
-rw-r--r-- | modules-available/baseconfig/install.inc.php | 2 | ||||
-rw-r--r-- | modules-available/baseconfig/lang/de/template-tags.json | 4 | ||||
-rw-r--r-- | modules-available/baseconfig/lang/en/template-tags.json | 19 | ||||
-rw-r--r-- | modules-available/baseconfig/lang/pt/template-tags.json | 20 | ||||
-rw-r--r-- | modules-available/baseconfig/page.inc.php | 86 | ||||
-rw-r--r-- | modules-available/baseconfig/templates/_page.html | 87 |
7 files changed, 126 insertions, 114 deletions
diff --git a/modules-available/baseconfig/api.inc.php b/modules-available/baseconfig/api.inc.php index 3aac322f..000015f5 100644 --- a/modules-available/baseconfig/api.inc.php +++ b/modules-available/baseconfig/api.inc.php @@ -45,18 +45,28 @@ foreach (glob('modules/*/baseconfig/getconfig.inc.php') as $file) { $defaults = BaseConfigUtil::getVariables(); // Dump global config from DB -$res = Database::simpleQuery('SELECT setting, value FROM setting_global'); +$res = Database::simpleQuery('SELECT setting, value, enabled FROM setting_global'); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if (isset($configVars[$row['setting']]) || !isset($defaults[$row['setting']])) + if (isset($configVars[$row['setting']]) // Already set by a hook above, ignore + || !isset($defaults[$row['setting']])) // Setting is not defined in any <module>/baseconfig/settings.json continue; - $configVars[$row['setting']] = $row['value']; + if ($row['enabled'] != 1) { + // Setting is disabled + $configVars[$row['setting']] = false; + } else { + $configVars[$row['setting']] = $row['value']; + } } // Fallback to default values from json files foreach ($defaults as $setting => $value) { - if (isset($configVars[$setting])) - continue; - $configVars[$setting] = $value; + if (isset($configVars[$setting])) { + if ($configVars[$setting] === false) { + unset($configVars[$setting]); + } + } else { + $configVars[$setting] = $value['defaultvalue']; + } } // All done, now output diff --git a/modules-available/baseconfig/install.inc.php b/modules-available/baseconfig/install.inc.php index 8f1cb1e7..b4eada5d 100644 --- a/modules-available/baseconfig/install.inc.php +++ b/modules-available/baseconfig/install.inc.php @@ -6,7 +6,7 @@ $res[] = tableCreate('setting_global', " `setting` varchar(28) NOT NULL, `value` text NOT NULL, `displayvalue` text NOT NULL, - `enabled` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' + `enabled` tinyint(1) UNSIGNED NOT NULL DEFAULT '1', PRIMARY KEY (`setting`) "); diff --git a/modules-available/baseconfig/lang/de/template-tags.json b/modules-available/baseconfig/lang/de/template-tags.json index 34163ca9..cdd54f6a 100644 --- a/modules-available/baseconfig/lang/de/template-tags.json +++ b/modules-available/baseconfig/lang/de/template-tags.json @@ -1,5 +1,7 @@ { "lang_basicConfiguration": "Basiskonfiguration", "lang_clientRelatedConfig": "Die Optionen auf dieser Seite beziehen sich auf das Verhalten der bwLehrpool-Clients.", - "lang_enableOverride": "\u00dcberschreiben" + "lang_editOverrideNotice": "Sie bearbeiten die Einstellungen f\u00fcr einen Unterbereich", + "lang_enableOverride": "\u00dcberschreiben", + "lang_settingActive": "Einstellung aktiv" }
\ 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 6adfd682..8e75e5ac 100644 --- a/modules-available/baseconfig/lang/en/template-tags.json +++ b/modules-available/baseconfig/lang/en/template-tags.json @@ -1,22 +1,7 @@ { "lang_basicConfiguration": "Basic Configuration", - "lang_catPartition": "Partition Managment", - "lang_catUser": "User Managment", "lang_clientRelatedConfig": "The options on this page are related to the bwLehrpool client machines.", - "lang_confirm": "Would you like to save the settings on [ \/srv\/openslx\/www\/boot\/config ] ?", + "lang_editOverrideNotice": "You're editing the settings of a sub-section", "lang_enableOverride": "Override", - "lang_helpId": "Partition Id", - "lang_helpMountPoint": "Must be a directory: \/example\/directory\/", - "lang_helpOptions": "Currently, only option 'bootable' is available", - "lang_helpSize": "Must be in Gigabytes e.g. 15G", - "lang_newPartition": "New Partition", - "lang_newUser": "New User", - "lang_partitionId": "Id", - "lang_partitionMountPoint": "Mount Point", - "lang_partitionOptions": "Options", - "lang_partitionSize": "Size", - "lang_resetConfirm": "Do you really wish to reset the variable to their default values?", - "lang_resetDefault": "Reset Default", - "lang_userName": "Username", - "lang_userPasswd": "Password" + "lang_settingActive": "Setting active" }
\ No newline at end of file diff --git a/modules-available/baseconfig/lang/pt/template-tags.json b/modules-available/baseconfig/lang/pt/template-tags.json index 28b9cb76..14367665 100644 --- a/modules-available/baseconfig/lang/pt/template-tags.json +++ b/modules-available/baseconfig/lang/pt/template-tags.json @@ -1,21 +1,3 @@ { - "lang_basicConfiguration": "Configura\u00e7\u00e3o B\u00e1sica", - "lang_catPartition": "Gerenciamento de Parti\u00e7\u00f5es", - "lang_catUser": "Gerenciamente de Usu\u00e1rios", - "lang_confirm": "Voc\u00ea deseja salvar configura\u00e7\u00f5es em [ \/srv\/openslx\/www\/boot\/default\/config ] ?", - "lang_create": "Criar", - "lang_helpId": "Id da parti\u00e7\u00e3o", - "lang_helpMountPoint": "Precisa ser um diret\u00f3rio: \/exemplo\/diret\u00f3rio\/", - "lang_helpOptions": "Atualmente, apenas a op\u00e7\u00e3o 'bootable' est\u00e1 dispon\u00edvel", - "lang_helpSize": "Precisa estar em Gigabytes, por exemplo 15G", - "lang_newPartition": "Nova Parti\u00e7\u00e3o", - "lang_newUser": "Novo Usu\u00e1rio", - "lang_partitionId": "Id", - "lang_partitionMountPoint": "Mount Point", - "lang_partitionOptions": "Op\u00e7\u00f5es", - "lang_partitionSize": "Tamanho", - "lang_resetConfirm": "Voc\u00ea realmente deseja restaurar as vari\u00e1veis para seus valores padr\u00f5es?", - "lang_resetDefault": "Restaurar Padr\u00e3o", - "lang_userName": "Nome", - "lang_userPasswd": "Senha" + "lang_basicConfiguration": "Configura\u00e7\u00e3o B\u00e1sica" }
\ No newline at end of file diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php index d14c64ac..056dbab1 100644 --- a/modules-available/baseconfig/page.inc.php +++ b/modules-available/baseconfig/page.inc.php @@ -3,6 +3,7 @@ class Page_BaseConfig extends Page { private $qry_extra = array(); + private $categories; /** * @var bool|string in case we're in module mode, set to the id of the module @@ -23,36 +24,47 @@ class Page_BaseConfig extends Page Util::redirect('?do=baseconfig'); } // Build variables for specific sub-settings - if (empty($this->qry_extra['field'])) { + if ($this->targetModule === false) { + // We're editing global settings - use the 'enabled' field + $qry_insert = ', enabled'; + $qry_values = ', :enabled'; + $qry_update = ', enabled = :enabled'; + $params = array(); + } elseif (empty($this->qry_extra['field'])) { + // Module specific, but module doesn't have an extra field $qry_insert = ''; $qry_values = ''; - $params = array(); + $qry_update = ''; } else { + // Module with extra field $qry_insert = ', ' . $this->qry_extra['field']; $qry_values = ', :field_value'; + $qry_update = ''; $params = array('field_value' => $this->qry_extra['field_value']); $delExtra = " AND {$this->qry_extra['field']} = :field_value "; $delParams = array('field_value' => $this->qry_extra['field_value']); - } - if ($this->targetModule === false) { - $override = false; - } else { // Not editing global settings if ($this->getCurrentModuleName() === false) { Message::addError('main.value-invalid', $this->qry_extra['field'], $this->qry_extra['field_value']); Util::redirect('?do=BaseConfig'); } - // Honor override checkbox - $override = Request::post('override', array()); } + // Honor override/enabled checkbox + $override = Request::post('override', array()); // Load all existing config options to validate input $vars = BaseConfigUtil::getVariables(); foreach ($vars as $key => $var) { - if (is_array($override) && (!isset($override[$key]) || $override[$key] !== 'on')) { - // module mode - override not set - delete - $delParams['key'] = $key; - Database::exec("DELETE FROM {$this->qry_extra['table']} WHERE setting = :key $delExtra", $delParams); - continue; + if ($this->targetModule === false) { + // Global mode + $params['enabled'] = (is_array($override) && isset($override[$key]) && $override[$key] === 'on') ? 1 : 0; + } else { + // Module mode + if (is_array($override) && (!isset($override[$key]) || $override[$key] !== 'on')) { + // override not set - delete + $delParams['key'] = $key; + Database::exec("DELETE FROM {$this->qry_extra['table']} WHERE setting = :key $delExtra", $delParams); + continue; + } } $validator = $var['validator']; $displayValue = (isset($newValues[$key]) ? $newValues[$key] : ''); @@ -65,7 +77,7 @@ class Page_BaseConfig extends Page // Now put into DB Database::exec("INSERT INTO {$this->qry_extra['table']} (setting, value, displayvalue $qry_insert)" . " VALUES (:key, :value, :displayvalue $qry_values)" - . " ON DUPLICATE KEY UPDATE value = :value, displayvalue = :displayvalue", + . " ON DUPLICATE KEY UPDATE value = :value, displayvalue = :displayvalue $qry_update", array( 'key' => $key, 'value' => $mangledValue, @@ -82,6 +94,15 @@ class Page_BaseConfig extends Page Util::redirect('?do=BaseConfig&module=' . $this->targetModule . '&' . $this->qry_extra['field'] . '=' . $this->qry_extra['field_value']); } } + // Load categories so we can define them as sub menu items + $this->categories = BaseConfigUtil::getCategories(); + asort($this->categories, SORT_DESC); + foreach ($this->categories as $catid => $val) { + Dashboard::addSubmenu( + '#category_' . $catid, + Dictionary::translateFileModule($this->categories[$catid]['module'], 'config-variable-categories', $catid) + ); + } } protected function doRender() @@ -101,17 +122,22 @@ class Page_BaseConfig extends Page // List config options $settings = array(); $vars = BaseConfigUtil::getVariables(); - $cats = BaseConfigUtil::getCategories(); // Get stuff that's set in DB already - if (isset($this->qry_extra['field'])) { + if ($this->targetModule === false) { + $fields = ', enabled'; + $where = ''; + $params = array(); + } elseif (isset($this->qry_extra['field'])) { + $fields = ''; $where = " WHERE {$this->qry_extra['field']} = :field_value"; $params = array('field_value' => $this->qry_extra['field_value']); } else { + $fields = ''; $where = ''; $params = array(); } // Populate structure with existing config from db - $res = Database::simpleQuery("SELECT setting, value, displayvalue FROM {$this->qry_extra['table']} " + $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']])) { @@ -119,9 +145,6 @@ class Page_BaseConfig extends Page continue; } $row += $vars[$row['setting']]; - if (is_null($row['displayvalue'])) { - $row['displayvalue'] = $row['defaultvalue']; - } if (!isset($row['catid'])) { $row['catid'] = 'unknown'; } @@ -129,39 +152,48 @@ class Page_BaseConfig extends Page } // Add entries that weren't in the db (global), setup override checkbox (module specific) foreach ($vars as $key => $var) { - if (isset($settings[$var['catid']]['settings'][$key])) { - // Value is set in DB + if (isset($settings[$var['catid']]['settings'][$key]['enabled'])) { + // Global settings - honor enabled field in db + if ($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 { - // Value is not set in DB + // Module specific - value is not set in DB $settings[$var['catid']]['settings'][$key] = $var + array( 'setting' => $key ); } + if (!isset($settings[$var['catid']]['settings'][$key]['displayvalue'])) { + $settings[$var['catid']]['settings'][$key]['displayvalue'] = $var['defaultvalue']; + } $settings[$var['catid']]['settings'][$key] += array( - 'item' => $this->makeInput($var['validator'], $key, $var['defaultvalue']), + 'item' => $this->makeInput($var['validator'], $key, $settings[$var['catid']]['settings'][$key]['displayvalue']), 'description' => Util::markup(Dictionary::translateFileModule($var['module'], 'config-variables', $key)) ); } // Sort categories $sortvals = array(); foreach ($settings as $catid => &$setting) { - $sortvals[] = isset($cats[$catid]) ? (int)$cats[$catid]['sortpos'] : 99999; + $sortvals[] = isset($this->categories[$catid]) ? (int)$this->categories[$catid]['sortpos'] : 99999; $setting['category_id'] = $catid; - $setting['category_name'] = Dictionary::translateFileModule($cats[$catid]['module'], 'config-variable-categories', $catid); + $setting['category_name'] = Dictionary::translateFileModule($this->categories[$catid]['module'], 'config-variable-categories', $catid); if ($setting['category_name'] === false) { $setting['category_name'] = $catid; } + ksort($setting['settings']); $setting['settings'] = array_values($setting['settings']); } unset($setting); array_multisort($sortvals, SORT_ASC, SORT_NUMERIC, $settings); Render::addTemplate('_page', array( - 'userid' => User::getId(), 'override' => $this->targetModule !== false, 'categories' => array_values($settings), 'target_module' => $this->targetModule, ) + $this->qry_extra); + Module::isAvailable('bootstrap_switch'); } private function getCurrentModuleName() diff --git a/modules-available/baseconfig/templates/_page.html b/modules-available/baseconfig/templates/_page.html index d5548ae9..4d4c05aa 100644 --- a/modules-available/baseconfig/templates/_page.html +++ b/modules-available/baseconfig/templates/_page.html @@ -10,58 +10,59 @@ <input name="module" type="hidden" value="{{target_module}}"> <input name="{{field}}" type="hidden" value="{{field_value}}"> {{/override}} - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> - <input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;"> - <input type="password" name="password_fake" id="password_fake" value="" style="display:none;"> - {{#categories}} - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="heading{{category_id}}"> - <a data-toggle="collapse" data-parent="#accordion" href="#collapse{{category_id}}" aria-expanded="false" aria-controls="collapse{{category_id}}"> - {{category_name}} - </a> - </div> - <div id="collapse{{category_id}}" class="accordion-body collapse" role="tabpanel" aria-labelledby="heading{{category_id}}"> - <div class="panel-body"> - <div class="list-group"> - {{#settings}} - <div class="list-group-item"> - <div class="row"> - <div class="col-md-5 slx-cfg-toggle"> - <div>{{setting}}</div> - {{^override}} - <div class="slx-default"> - {{defaultvalue}} - </div> - {{/override}} - {{#override}} - <input name="override[{{setting}}]" id="CB_{{setting}}" type="checkbox" {{checked}}> <label for="CB_{{setting}}">{{lang_enableOverride}}</label> - {{/override}} - </div> - <div class="col-md-5"> - {{{item}}} - </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> - </div> + <input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;"> + <input type="password" name="password_fake" id="password_fake" value="" style="display:none;"> + {{#categories}} + <div class="panel panel-default"> + <div class="panel-heading" role="tab" id="heading{{category_id}}"> + <a name="category_{{category_id}}"></a> + {{category_name}} + </div> + <div class="panel-body"> + <div class="list-group"> + {{#settings}} + <div class="list-group-item"> + <div class="row"> + <div class="col-md-5 slx-cfg-toggle"> + <div>{{setting}}</div> + {{^override}} + <div class="slx-default"> + {{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}} </div> - <div class="modal fade" id="help-{{setting}}" tabindex="-1" role="dialog"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header">{{setting}}</div> - <div class="modal-body">{{{description}}}</div> - <div class="modal-footer"><a class="btn btn-primary" data-dismiss="modal">{{lang_close}}</a></div> - </div> - </div> + <div class="col-md-5"> + {{{item}}} + </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> + </div> + </div> + </div> + <div class="modal fade" id="help-{{setting}}" tabindex="-1" role="dialog"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header">{{setting}}</div> + <div class="modal-body">{{{description}}}</div> + <div class="modal-footer"><a class="btn btn-primary" data-dismiss="modal">{{lang_close}}</a></div> </div> - {{/settings}} </div> </div> + {{/settings}} </div> </div> - {{/categories}} </div> + {{/categories}} <button class="btn btn-primary" type="submit">{{lang_save}}</button> <button class="btn btn-default" type="reset">{{lang_reset}}</button> + {{^override}} <a class="btn btn-default" href="api.php?do=baseconfig&user={{userid}}">Download</a> + {{/override}} + {{#override}} + <a class="btn btn-default" href="api.php?do=baseconfig&user={{userid}}&module={{target_module}}&value={{field_value}}&force=1">Download</a> + {{/override}} </form> |