LuminaWebsite/admin/users.php
Maaxxs 0eb8816ef8 Admin: switch for unlinking Discord, keep table actions in view
The user list gets a switch "Mitglieder dürfen ihre Discord-Verknüpfung im
Profil lösen" (users.edit, default on). Turned off, the profile shows a note
instead of the button and discord_unlink.php refuses the request. The value
lives in a new settings table, created automatically like the other schema
additions (SCHEMA_VERSION 2).

The user and group tables were wider than the 1100px content column, so the
actions column (edit/delete/approve) scrolled out of view. Both pages now
use the wide container and the actions column sticks to the right edge.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 08:00:06 +02:00

124 lines
5.6 KiB
PHP

<?php
require_once __DIR__ . '/../includes/bootstrap.php';
require_permission('users.view');
$canCreate = user_has_permission('users.create');
$canEdit = user_has_permission('users.edit');
$canDelete = user_has_permission('users.delete');
$currentUser = current_user();
// Wer auf die Freischaltung wartet, steht oben - das ist die Liste, die man abarbeitet.
$users = db()->query(
"SELECT u.id, u.username, u.display_name, u.status, u.last_login, u.created_at, u.must_change_password,
u.password_login, u.discord_id, u.discord_username,
GROUP_CONCAT(COALESCE(NULLIF(r.display_name, ''), r.name) ORDER BY r.name SEPARATOR ', ') AS role_names
FROM users u
LEFT JOIN user_roles ur ON ur.user_id = u.id
LEFT JOIN roles r ON r.id = ur.role_id
GROUP BY u.id
ORDER BY u.status = 'pending' DESC, u.username"
)->fetchAll();
$statusLabels = [
'active' => ['Aktiv', 'badge-active'],
'disabled' => ['Deaktiviert', 'badge-disabled'],
'pending' => ['Wartet auf Freischaltung', 'badge-pending'],
];
$pageTitle = 'Benutzerverwaltung';
// Die Tabelle hat viele Spalten - volle Breite statt der schmalen Inhaltsspalte.
$containerWide = true;
include __DIR__ . '/../includes/header.php';
?>
<div class="panel">
<h1>Benutzerverwaltung</h1>
<p class="text-muted">
Wer sich zum ersten Mal über Discord anmeldet, bekommt automatisch ein Konto, das erst
freigeschaltet werden muss. Berechtigungsgruppen mit verknüpfter Discord-Rolle werden
automatisch vergeben und entzogen.
</p>
<?php if ($canCreate): ?>
<p><a class="button" href="/admin/user_form.php">Neuen Benutzer anlegen</a></p>
<?php endif; ?>
<?php if ($canEdit): ?>
<form class="settings-toggle" method="post" action="/admin/settings_action.php">
<?= csrf_field() ?>
<input type="hidden" name="setting" value="discord_unlink_allowed">
<label>
<input type="checkbox" name="value" value="1" <?= discord_unlink_allowed() ? 'checked' : '' ?> onchange="this.form.submit()">
Mitglieder dürfen ihre Discord-Verknüpfung im Profil lösen
</label>
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
</form>
<?php endif; ?>
<div class="table-scroll">
<table class="table-actions">
<thead>
<tr>
<th>Benutzername</th>
<th>Anzeigename</th>
<th>Discord</th>
<th>Berechtigungsgruppen</th>
<th>Status</th>
<th>Letzter Login</th>
<?php if ($canEdit || $canDelete): ?><th>Aktionen</th><?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<?php [$statusLabel, $statusClass] = $statusLabels[$u['status']] ?? [$u['status'], '']; ?>
<tr<?= $u['status'] === 'pending' ? ' class="row-pending"' : '' ?>>
<td><?= e($u['username']) ?></td>
<td><?= e($u['display_name']) ?></td>
<td>
<?php if (!empty($u['discord_id'])): ?>
<span class="discord-inline"><?= discord_logo(14) ?> <?= e((string) $u['discord_username']) ?></span>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</td>
<td><?= e($u['role_names'] ?: '-') ?></td>
<td>
<div class="badge-group">
<span class="badge <?= e($statusClass) ?>"><?= e($statusLabel) ?></span>
<?php if (empty($u['password_login'])): ?>
<span class="badge" title="Anmeldung nur über Discord möglich">Nur Discord</span>
<?php elseif ($u['must_change_password']): ?>
<span class="badge" title="Benutzer muss beim nächsten Login das Passwort ändern">Passwortänderung ausstehend</span>
<?php endif; ?>
</div>
</td>
<td><?= e($u['last_login'] ?? 'nie') ?></td>
<?php if ($canEdit || $canDelete): ?>
<td>
<div class="actions">
<?php if ($canEdit && $u['status'] === 'pending'): ?>
<form class="inline-form" method="post" action="/admin/user_approve.php">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">
<button type="submit" class="button-success button-small">Freischalten</button>
</form>
<?php endif; ?>
<?php if ($canEdit): ?>
<a href="/admin/user_form.php?id=<?= (int) $u['id'] ?>">Bearbeiten</a>
<?php endif; ?>
<?php if ($canDelete && (int) $u['id'] !== (int) $currentUser['id']): ?>
<form class="inline-form" method="post" action="/admin/user_delete.php" onsubmit="return confirm('Diesen Benutzer wirklich löschen?');">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">
<button type="submit" class="text-button">Löschen</button>
</form>
<?php endif; ?>
</div>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>