get($moduleName);
$error = null;
$notice = null;
require_admin();
if (!$module) {
http_response_code(404);
echo '
Modul nicht gefunden.
';
return;
}
$fields = (array)($module['setup']['fields'] ?? []);
$fieldTypes = [];
$fieldMeta = [];
foreach ($fields as $field) {
$fname = (string)($field['name'] ?? '');
if ($fname === '') {
continue;
}
$fieldTypes[$fname] = (string)($field['type'] ?? 'text');
$fieldMeta[$fname] = $field;
}
$current = modules()->settings($moduleName);
$defaults = $module['db_defaults'] ?? [];
if (empty($current['db']) && is_array($defaults)) {
$current['db'] = $defaults;
}
$metadataDefaults = $module['metadata_db_defaults'] ?? [];
if (empty($current['metadata_db']) && is_array($metadataDefaults)) {
$current['metadata_db'] = $metadataDefaults;
}
$setNested = function (array &$target, string $path, mixed $value): void {
$parts = explode('.', $path);
$last = array_pop($parts);
$node = &$target;
foreach ($parts as $part) {
if (!isset($node[$part]) || !is_array($node[$part])) {
$node[$part] = [];
}
$node = &$node[$part];
}
if ($last !== null && $last !== '') {
$node[$last] = $value;
}
};
$getNested = function (array $source, string $path): mixed {
$node = $source;
foreach (explode('.', $path) as $part) {
if (!is_array($node) || !array_key_exists($part, $node)) {
return null;
}
$node = $node[$part];
}
return $node;
};
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$payload = [];
foreach ($fields as $field) {
$name = (string)($field['name'] ?? '');
if ($name === '') {
continue;
}
$type = (string)($field['type'] ?? 'text');
$postKey = str_replace('.', '_', $name);
$value = $_POST[$postKey] ?? null;
if ($type === 'checkbox') {
$value = isset($_POST[$postKey]) ? '1' : '0';
}
if (is_array($value)) {
continue;
}
$value = is_string($value) ? trim($value) : $value;
if ($name === 'kea_auto_init') {
$payload[$name] = $value === '1';
continue;
}
if (str_contains($name, '.')) {
$setNested($payload, $name, $value);
continue;
}
$payload[$name] = $value;
}
modules()->saveSettings($moduleName, $payload);
modules()->saveAuth($moduleName, [
'required' => isset($_POST['auth_required']),
'users' => (string)($_POST['auth_users'] ?? ''),
'groups' => (string)($_POST['auth_groups'] ?? ''),
]);
$notice = 'Setup gespeichert.';
$current = array_replace_recursive($current, $payload);
$module = modules()->get($moduleName) ?: $module;
}
$authConfig = is_array($module['auth'] ?? null) ? $module['auth'] : ['required' => false, 'users' => [], 'groups' => []];
?>
Setup
= e($module['title']) ?> – Einrichtung
Trage die benötigten Informationen für das Modul ein.
= e($error) ?>
= e($notice) ?>