159 lines
6.8 KiB
PHP
159 lines
6.8 KiB
PHP
<?php
|
|
$modules = modules()->all();
|
|
$error = null;
|
|
$notice = null;
|
|
$GLOBALS['layout_header_base_title'] = 'Modulverwaltung';
|
|
$GLOBALS['layout_header_title'] = 'Modulverwaltung';
|
|
$GLOBALS['layout_header_context'] = 'Aktive Module';
|
|
$GLOBALS['layout_header_text'] = '';
|
|
$GLOBALS['layout_header_actions'] = [];
|
|
$knownAuthUsers = modules()->knownAuthUsers();
|
|
$authUserLabels = [];
|
|
foreach ($knownAuthUsers as $knownAuthUser) {
|
|
if (!is_array($knownAuthUser)) {
|
|
continue;
|
|
}
|
|
|
|
$label = trim((string) ($knownAuthUser['name'] ?? ''));
|
|
if ($label === '') {
|
|
$label = trim((string) ($knownAuthUser['username'] ?? ''));
|
|
}
|
|
if ($label === '') {
|
|
$label = trim((string) ($knownAuthUser['email'] ?? ''));
|
|
}
|
|
|
|
foreach (['sub', 'username', 'email'] as $key) {
|
|
$value = trim((string) ($knownAuthUser[$key] ?? ''));
|
|
if ($value !== '' && $label !== '') {
|
|
$authUserLabels[$value] = $label;
|
|
}
|
|
}
|
|
}
|
|
|
|
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.';
|
|
}
|
|
}
|
|
?>
|
|
<?php require_auth(); ?>
|
|
<div class="module-flow">
|
|
<?php if ($error): ?>
|
|
<div class="module-box-soft bg-red-900 border-l-4 border-red-500 text-red-100" role="alert">
|
|
<?= e($error) ?>
|
|
</div>
|
|
<?php elseif ($notice): ?>
|
|
<div class="module-box-soft" style="border-color:var(--accent-2);">
|
|
<?= e($notice) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="submenu-box">
|
|
<div class="module-hero-top module-hero-top--compact">
|
|
<nav class="module-tabs" aria-label="Modulverwaltung">
|
|
<a class="module-button module-button--tab-active" href="/modules">Aktive Module</a>
|
|
<a class="module-button module-button--tab" href="/modules/install">Module installieren/aktivieren</a>
|
|
</nav>
|
|
<div class="module-submenu-actions">
|
|
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
|
|
<a class="module-button module-button--secondary module-button--small" href="/modules/sql-import">Zentralen SQL-Import</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<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 !== []);
|
|
if ($hasSpecificAccess) {
|
|
$accessParts = [];
|
|
if ($authGroups !== []) {
|
|
$accessParts[] = 'Gruppen: ' . implode(', ', $authGroups);
|
|
}
|
|
if ($authUsers !== []) {
|
|
$userLabels = array_map(
|
|
static fn (string $user): string => $authUserLabels[$user] ?? $user,
|
|
$authUsers
|
|
);
|
|
$accessParts[] = 'Nutzer: ' . implode(', ', $userLabels);
|
|
}
|
|
$accessLabel = implode(' · ', $accessParts);
|
|
$accessClass = ' module-admin-badge--success';
|
|
} elseif ($authRequired) {
|
|
$accessLabel = 'Login erforderlich';
|
|
$accessClass = ' module-admin-badge--warning';
|
|
} else {
|
|
$accessLabel = 'Offen ohne Modulschutz';
|
|
$accessClass = ' module-admin-badge--danger';
|
|
}
|
|
$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="card-box 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<?= e($accessClass) ?>"><?= 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; ?>
|
|
<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>
|