summaryrefslogtreecommitdiffstats
path: root/modules-available/baseconfig/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/baseconfig/page.inc.php')
-rw-r--r--modules-available/baseconfig/page.inc.php44
1 files changed, 28 insertions, 16 deletions
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php
index 1566464b..5d684a8e 100644
--- a/modules-available/baseconfig/page.inc.php
+++ b/modules-available/baseconfig/page.inc.php
@@ -68,7 +68,7 @@ class Page_BaseConfig extends Page
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) {
@@ -101,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)
);
}
}
@@ -120,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();
}
@@ -136,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])) {
@@ -154,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(
@@ -166,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);
@@ -195,15 +194,15 @@ class Page_BaseConfig extends Page
) + $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']]);
@@ -261,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;
@@ -281,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);
@@ -294,7 +291,7 @@ class Page_BaseConfig extends Page
if ($disabled) {
$args['disabled'] = true;
}
- $inner = "";
+ $extra = $inner = "";
/* -- */
$parts = explode(':', $validator, 2);
@@ -314,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]);
@@ -362,7 +374,7 @@ class Page_BaseConfig extends Page
$output .= '>' . $inner . "</$tag>";
}
- return $output;
+ return $output . $extra;
}
}