setup
This commit is contained in:
@@ -60,6 +60,8 @@ $getNested = function (array $source, string $path): mixed {
|
||||
};
|
||||
|
||||
$dbGroups = [];
|
||||
$fieldsByDbGroup = [];
|
||||
$generalFields = [];
|
||||
foreach ($fields as $field) {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if (!str_contains($name, '.')) {
|
||||
@@ -77,6 +79,68 @@ foreach ($fields as $field) {
|
||||
$dbGroups[$group] = $label;
|
||||
}
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if (str_contains($name, '.')) {
|
||||
[$group] = explode('.', $name, 2);
|
||||
if (array_key_exists($group, $dbGroups)) {
|
||||
$fieldsByDbGroup[$group][] = $field;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$generalFields[] = $field;
|
||||
}
|
||||
|
||||
$driverOptions = [
|
||||
'pgsql' => 'PostgreSQL',
|
||||
'mysql' => 'MySQL / MariaDB',
|
||||
'sqlite' => 'SQLite',
|
||||
];
|
||||
|
||||
$renderField = function (array $field) use ($current, $getNested, $driverOptions): void {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if ($name === '') {
|
||||
return;
|
||||
}
|
||||
$label = (string)($field['label'] ?? $name);
|
||||
$type = (string)($field['type'] ?? 'text');
|
||||
$required = !empty($field['required']);
|
||||
$help = (string)($field['help'] ?? $field['description'] ?? '');
|
||||
$postKey = str_replace('.', '_', $name);
|
||||
|
||||
$value = '';
|
||||
if ($name === 'kea_auto_init') {
|
||||
$value = !empty($current[$name]) ? '1' : '0';
|
||||
} elseif (str_contains($name, '.')) {
|
||||
$value = (string)($getNested($current, $name) ?? '');
|
||||
} else {
|
||||
$value = (string)($current[$name] ?? '');
|
||||
}
|
||||
?>
|
||||
<label class="setup-field muted">
|
||||
<span><?= e($label) ?></span>
|
||||
<?php if (str_ends_with($name, '.driver')): ?>
|
||||
<select name="<?= e($postKey) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<option value="">Bitte waehlen</option>
|
||||
<?php foreach ($driverOptions as $driver => $driverLabel): ?>
|
||||
<option value="<?= e($driver) ?>" <?= $value === $driver ? 'selected' : '' ?>><?= e($driverLabel) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php elseif ($type === 'textarea'): ?>
|
||||
<textarea name="<?= e($postKey) ?>" rows="3" <?= $required ? 'required' : '' ?>><?= e($value) ?></textarea>
|
||||
<?php elseif ($type === 'checkbox'): ?>
|
||||
<input type="checkbox" name="<?= e($postKey) ?>" value="1" <?= $value === '1' ? 'checked' : '' ?>>
|
||||
<?php else: ?>
|
||||
<input type="<?= e($type) ?>" name="<?= e($postKey) ?>" value="<?= e($value) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<?php endif; ?>
|
||||
<?php if ($help !== ''): ?>
|
||||
<small class="muted"><?= e($help) ?></small>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$payload = [];
|
||||
|
||||
@@ -142,9 +206,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="card">
|
||||
<div class="setup-shell">
|
||||
<div class="pill">Setup</div>
|
||||
<h1 style="margin-top:.75rem;"><?= e($module['title']) ?> – Einrichtung</h1>
|
||||
<h1 class="setup-title"><?= e($module['title']) ?> – Einrichtung</h1>
|
||||
<p class="muted">Trage die benötigten Informationen für das Modul ein.</p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
@@ -152,60 +216,66 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<?= e($error) ?>
|
||||
</div>
|
||||
<?php elseif ($notice): ?>
|
||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||
<div class="setup-notice">
|
||||
<?= e($notice) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" style="margin-top:1rem; display:grid; gap:14px; max-width:520px;">
|
||||
<?php foreach ($fields as $field): ?>
|
||||
<?php
|
||||
$name = (string)($field['name'] ?? '');
|
||||
$label = (string)($field['label'] ?? $name);
|
||||
$type = (string)($field['type'] ?? 'text');
|
||||
$required = !empty($field['required']);
|
||||
$help = (string)($field['help'] ?? $field['description'] ?? '');
|
||||
$postKey = str_replace('.', '_', $name);
|
||||
|
||||
$value = '';
|
||||
if ($name === 'kea_auto_init') {
|
||||
$value = !empty($current[$name]) ? '1' : '0';
|
||||
} elseif (str_contains($name, '.')) {
|
||||
$value = (string)($getNested($current, $name) ?? '');
|
||||
} else {
|
||||
$value = (string)($current[$name] ?? '');
|
||||
}
|
||||
?>
|
||||
<label class="muted" style="display:grid; gap:6px;">
|
||||
<span><?= e($label) ?></span>
|
||||
<?php if ($type === 'textarea'): ?>
|
||||
<textarea name="<?= e($postKey) ?>" rows="3" <?= $required ? 'required' : '' ?>><?= e($value) ?></textarea>
|
||||
<?php elseif ($type === 'checkbox'): ?>
|
||||
<input type="checkbox" name="<?= e($postKey) ?>" value="1" <?= $value === '1' ? 'checked' : '' ?>>
|
||||
<?php else: ?>
|
||||
<input type="<?= e($type) ?>" name="<?= e($postKey) ?>" value="<?= e($value) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<?php endif; ?>
|
||||
<?php if ($help !== ''): ?>
|
||||
<small class="muted"><?= e($help) ?></small>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($dbGroups !== []): ?>
|
||||
<div class="card" style="padding:14px; background:var(--panel-2); display:grid; gap:10px;">
|
||||
<strong>Datenbankverbindungen testen</strong>
|
||||
<small class="muted">Der Test nutzt die aktuell eingetragenen Werte aus diesem Formular und speichert sie nicht.</small>
|
||||
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<button class="nav-link" type="submit" name="test_db" value="<?= e($group) ?>" formnovalidate>
|
||||
<?= e($label) ?> testen
|
||||
</button>
|
||||
<form method="post" class="setup-form">
|
||||
<?php if ($generalFields !== []): ?>
|
||||
<section class="setup-panel">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill">Allgemein</span>
|
||||
<h2>Moduleinstellungen</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setup-grid">
|
||||
<?php foreach ($generalFields as $field): ?>
|
||||
<?php $renderField($field); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<div style="display:flex; gap:10px;">
|
||||
<?php if ($dbGroups !== []): ?>
|
||||
<section class="setup-panel setup-panel--flat">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill">Datenbanken</span>
|
||||
<h2>Verbindungen</h2>
|
||||
<p class="muted">Jede Verbindung kann getrennt konfiguriert und getestet werden.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setup-tabs" aria-label="Datenbankbereiche">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<a class="nav-link" href="#setup-db-<?= e($group) ?>"><?= e($label) ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="setup-db-panels">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<section class="setup-db-panel" id="setup-db-<?= e($group) ?>">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill"><?= e($label) ?></span>
|
||||
<h3><?= e($label) ?> konfigurieren</h3>
|
||||
</div>
|
||||
<button class="nav-link" type="submit" name="test_db" value="<?= e($group) ?>" formnovalidate>
|
||||
Verbindung testen
|
||||
</button>
|
||||
</div>
|
||||
<div class="setup-grid">
|
||||
<?php foreach (($fieldsByDbGroup[$group] ?? []) as $field): ?>
|
||||
<?php $renderField($field); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="setup-actions">
|
||||
<button class="cta-button" type="submit">Speichern</button>
|
||||
<a class="nav-link" href="/modules/access/<?= e($moduleName) ?>">Zugriff verwalten</a>
|
||||
<a class="nav-link" href="/modules">Zurück</a>
|
||||
|
||||
Reference in New Issue
Block a user