diff options
Diffstat (limited to 'modules-available/baseconfig/page.inc.php')
-rw-r--r-- | modules-available/baseconfig/page.inc.php | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php index a931d3f3..5d684a8e 100644 --- a/modules-available/baseconfig/page.inc.php +++ b/modules-available/baseconfig/page.inc.php @@ -54,8 +54,7 @@ class Page_BaseConfig extends Page BaseConfigUtil::markShadowedVars($vars, $newValues); // Validate input foreach ($vars as $key => $var) { - if (isset($var['shadowed'])) - continue; + // Delete entries where we disabled override if ($this->targetModule !== false) { // Module mode if (is_array($override) && (!isset($override[$key]) || $override[$key] !== 'on')) { @@ -65,8 +64,11 @@ class Page_BaseConfig extends Page continue; } } + // Only after that, check if variable is shadowed (disabled) + if (isset($var['shadowed'])) + continue; $validator = $var['validator']; - $displayValue = (isset($newValues[$key]) ? $newValues[$key] : ''); + $displayValue = $newValues[$key] ?? ''; // Validate data first! $mangledValue = Validator::validate($validator, $displayValue); if ($mangledValue === false) { @@ -86,11 +88,11 @@ class Page_BaseConfig extends Page } Message::addSuccess('settings-updated'); if ($this->targetModule === false) { - Util::redirect('?do=BaseConfig'); + Util::redirect('?do=BaseConfig', true); } elseif (empty($this->qry_extra['field'])) { - Util::redirect('?do=BaseConfig&module=' . $this->targetModule); + Util::redirect('?do=BaseConfig&module=' . $this->targetModule, true); } else { - Util::redirect('?do=BaseConfig&module=' . $this->targetModule . '&' . $this->qry_extra['field'] . '=' . $this->qry_extra['field_value']); + Util::redirect('?do=BaseConfig&module=' . $this->targetModule . '&' . $this->qry_extra['field'] . '=' . $this->qry_extra['field_value'], true); } } // Load categories so we can define them as sub menu items @@ -99,7 +101,7 @@ class Page_BaseConfig extends Page foreach ($this->categories as $catid => $val) { Dashboard::addSubmenu( '#category_' . $catid, - Dictionary::translateFileModule($this->categories[$catid]['module'], 'config-variable-categories', $catid, true) + Dictionary::translateFileModule($this->categories[$catid]['module'], 'config-variable-categories', $catid) ); } } @@ -118,12 +120,11 @@ class Page_BaseConfig extends Page User::assertPermission('view', $lid); $editForbidden = !User::hasPermission('edit', $lid); // Get stuff that's set in DB already + $fields = ''; if ($this->targetModule !== false && 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(); } @@ -134,7 +135,7 @@ class Page_BaseConfig extends Page // Remember missing variables $missing = $varsFromJson; // Populate structure with existing config from db - $this->fillSettings($varsFromJson, $settings, $missing, $this->qry_extra['table'], $fields, $where, $params, false); + $this->fillSettings($varsFromJson, $settings, $missing, $this->qry_extra['table'], $fields, $where, $params); // Add entries that weren't in the db (global), setup override checkbox (module specific) foreach ($varsFromJson as $key => $var) { if ($this->targetModule !== false && !isset($settings[$var['catid']]['settings'][$key])) { @@ -152,7 +153,7 @@ class Page_BaseConfig extends Page } } if (!isset($entry['shadows'])) { - $entry['shadows'] = isset($var['shadows']) ? $var['shadows'] : null; + $entry['shadows'] = $var['shadows'] ?? null; } $entry += array( 'item' => $this->makeInput( @@ -164,7 +165,7 @@ class Page_BaseConfig extends Page ), 'description' => Util::markup(Dictionary::translateFileModule($var['module'], 'config-variables', $key)), 'setting' => $key, - 'tree' => isset($parents[$key]) ? $parents[$key] : false, + 'tree' => $parents[$key] ?? false, ); } unset($entry); @@ -189,18 +190,19 @@ class Page_BaseConfig extends Page 'categories' => array_values($settings), 'target_module' => $this->targetModule, 'edit_disabled' => $editForbidden ? 'disabled' : '', + 'redirect' => Request::get('redirect'), ) + $this->qry_extra); } - private function fillSettings($vars, &$settings, &$missing, $table, $fields, $where, $params, $sourceName) + private function fillSettings($vars, &$settings, &$missing, $table, $fields, $where, $params): void { $res = Database::simpleQuery("SELECT setting, value, displayvalue $fields FROM $table " . " {$where} ORDER BY setting ASC", $params); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (!isset($missing[$row['setting']])) continue; if (!isset($vars[$row['setting']]) || !is_array($vars[$row['setting']])) { - $unknown[] = $row['setting']; + //$unknown[] = $row['setting']; continue; } unset($missing[$row['setting']]); @@ -258,7 +260,7 @@ class Page_BaseConfig extends Page $this->qry_extra = $hook; } - private function getPermissionLocationId() + private function getPermissionLocationId(): int { if (!isset($this->qry_extra['locationResolver']) || !isset($this->qry_extra['field_value'])) return 0; @@ -278,10 +280,8 @@ class Page_BaseConfig extends Page /** * Create html snippet for setting, based on given validator - * @param string $validator - * @return boolean */ - private function makeInput($validator, $setting, $current, $shadows, $disabled) + private function makeInput(string $validator, string $setting, string $current, ?array $shadows, bool $disabled): string { /* for the html snippet we need: */ $args = array('class' => 'form-control', 'name' => "setting[$setting]", 'id' => $setting); @@ -291,7 +291,7 @@ class Page_BaseConfig extends Page if ($disabled) { $args['disabled'] = true; } - $inner = ""; + $extra = $inner = ""; /* -- */ $parts = explode(':', $validator, 2); @@ -311,6 +311,21 @@ class Page_BaseConfig extends Page unset($args['type']); $current = ''; + } elseif ($parts[0] === 'suggestions') { + + $extra = '<datalist id="list-' . $setting . '">'; + $items = explode('|', $parts[1]); + foreach ($items as $item) { + $extra .= '<option>' . htmlspecialchars($item) . '</option>'; + } + $extra .= '</datalist>'; + + $tag = 'input'; + $args['value'] = $current; + $args['type'] = 'text'; + $args['list'] = 'list-' . $setting; + $current = ''; + } elseif ($parts[0] == 'multilist') { $items = explode('|', $parts[1]); @@ -359,7 +374,7 @@ class Page_BaseConfig extends Page $output .= '>' . $inner . "</$tag>"; } - return $output; + return $output . $extra; } } |