127 lines
5.6 KiB
PHP
127 lines
5.6 KiB
PHP
<?php
|
|
$modules = modules()->all();
|
|
$error = null;
|
|
$notice = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
require_admin();
|
|
$name = (string)($_POST['module'] ?? '');
|
|
$action = (string)($_POST['action'] ?? '');
|
|
|
|
if ($name !== '' && ($action === 'enable' || $action === 'disable')) {
|
|
$enabled = $action === 'enable';
|
|
modules()->setEnabled($name, $enabled);
|
|
$notice = $enabled ? 'Modul aktiviert.' : 'Modul deaktiviert.';
|
|
$modules = modules()->all();
|
|
} elseif ($name !== '' && $action === 'migrate') {
|
|
$applied = modules()->applyPendingMigrations($name);
|
|
$notice = count($applied) . ' Migration(en) angewendet.';
|
|
$modules = modules()->all();
|
|
} else {
|
|
$error = 'Ungültige Aktion.';
|
|
}
|
|
}
|
|
?>
|
|
<div class="card">
|
|
<?php require_auth(); ?>
|
|
<div class="pill">Module</div>
|
|
<h1 style="margin-top:.75rem;">Module verwalten</h1>
|
|
<p class="muted">Hier siehst du nur aktive Module. Installierte Module kannst du unten verwalten.</p>
|
|
<p style="margin-top:.75rem;">
|
|
<a class="nav-link" href="/modules/sql-import">Zentralen SQL-Import öffnen</a>
|
|
</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="bg-red-900 border-l-4 border-red-500 text-red-100 p-4 mb-6" role="alert">
|
|
<?= e($error) ?>
|
|
</div>
|
|
<?php elseif ($notice): ?>
|
|
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
|
<?= e($notice) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="module-admin-grid">
|
|
<?php foreach ($modules as $module): ?>
|
|
<?php if (empty($module['enabled'])) { continue; } ?>
|
|
<?php
|
|
$auth = is_array($module['auth'] ?? null) ? $module['auth'] : [];
|
|
$authRequired = !empty($auth['required']);
|
|
$authUsers = is_array($auth['users'] ?? null) ? array_filter($auth['users']) : [];
|
|
$authGroups = is_array($auth['groups'] ?? null) ? array_filter($auth['groups']) : [];
|
|
$hasSpecificAccess = $authRequired && ($authUsers !== [] || $authGroups !== []);
|
|
$accessLabel = $hasSpecificAccess
|
|
? 'Spezielle Zugriffsrechte'
|
|
: ($authRequired ? 'Login erforderlich' : 'Offen ohne Modulschutz');
|
|
$migrationStatus = modules()->migrationStatus($module['name']);
|
|
$pendingMigrations = $migrationStatus['pending'] ?? [];
|
|
$changedMigrations = $migrationStatus['changed'] ?? [];
|
|
$migrationLabel = $pendingMigrations !== []
|
|
? count($pendingMigrations) . ' ausstehend'
|
|
: (($migrationStatus['available'] ?? 0) > 0 ? 'Schema aktuell' : 'Keine Migrationen');
|
|
?>
|
|
<article class="module-admin-card">
|
|
<div class="module-admin-card__head">
|
|
<div class="module-admin-card__title">
|
|
<h2><?= e($module['title']) ?></h2>
|
|
<p><?= e($module['description'] ?? '') ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="module-admin-meta">
|
|
<div class="module-admin-meta__item">
|
|
<span class="module-admin-meta__label">Status</span>
|
|
<strong class="module-admin-badge module-admin-badge--success">Aktiv</strong>
|
|
</div>
|
|
<div class="module-admin-meta__item">
|
|
<span class="module-admin-meta__label">Zugriff</span>
|
|
<strong class="module-admin-badge<?= $hasSpecificAccess ? ' module-admin-badge--warning' : '' ?>"><?= e($accessLabel) ?></strong>
|
|
</div>
|
|
<div class="module-admin-meta__item">
|
|
<span class="module-admin-meta__label">Migrationen</span>
|
|
<strong class="module-admin-badge<?= $pendingMigrations !== [] ? ' module-admin-badge--accent' : (($migrationStatus['available'] ?? 0) > 0 ? ' module-admin-badge--success' : '') ?>"><?= e($migrationLabel) ?></strong>
|
|
</div>
|
|
</div>
|
|
<?php if ($changedMigrations !== []): ?>
|
|
<div class="module-admin-warning">
|
|
Achtung: <?= e((string)count($changedMigrations)) ?> bereits angewendete Migration(en) wurden verändert.
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($hasSpecificAccess || $authRequired): ?>
|
|
<div class="module-admin-access">
|
|
<?php if ($authGroups !== []): ?>
|
|
Gruppen: <?= e(implode(', ', $authGroups)) ?>
|
|
<?php elseif ($authRequired): ?>
|
|
Anmeldung erforderlich
|
|
<?php endif; ?>
|
|
<?php if ($authGroups !== [] && $authUsers !== []): ?>
|
|
·
|
|
<?php endif; ?>
|
|
<?php if ($authUsers !== []): ?>
|
|
Benutzer: <?= e((string)count($authUsers)) ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="module-admin-actions">
|
|
<a class="nav-link" href="/module/<?= e($module['name']) ?>">Öffnen</a>
|
|
<a class="nav-link" href="/modules/setup/<?= e($module['name']) ?>">Setup</a>
|
|
<a class="nav-link" href="/modules/access/<?= e($module['name']) ?>">Zugriff</a>
|
|
<?php if ($pendingMigrations !== []): ?>
|
|
<form method="post" style="margin:0;">
|
|
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
|
|
<button class="cta-button" name="action" value="migrate">Migrationen anwenden</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
<form method="post" style="margin:0;">
|
|
<input type="hidden" name="module" value="<?= e($module['name']) ?>">
|
|
<button class="cta-button" name="action" value="disable" style="background:var(--panel); color:var(--text);">Deaktivieren</button>
|
|
</form>
|
|
</div>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div style="margin-top:1.5rem;">
|
|
<a class="nav-link" href="/modules/install">Module installieren/aktivieren</a>
|
|
</div>
|
|
</div>
|