Roles get a new optional display_name (roles.display_name): everywhere a role name is shown to users (dashboard badges, member list section headers/badges, admin user list, role checkboxes in user_form.php), it's now COALESCE(NULLIF(display_name,''), name) - falls back to the existing internal name when unset. The name field keeps its original role as the unique technical identifier; admin/role_form.php's label now says so explicitly, and admin/roles.php lists both columns since that's the one screen actually managing the identifier. Also drops "aktiven" from the member list's count line, since the page already only lists active accounts without needing to say so. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
82 lines
3.2 KiB
PHP
82 lines
3.2 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();
|
|
|
|
$users = db()->query(
|
|
"SELECT u.id, u.username, u.display_name, u.status, u.last_login, u.must_change_password,
|
|
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.username"
|
|
)->fetchAll();
|
|
|
|
$pageTitle = 'Benutzerverwaltung';
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<h1>Benutzerverwaltung</h1>
|
|
<p class="text-muted">Nur für Administratoren sichtbar.</p>
|
|
|
|
<?php if ($canCreate): ?>
|
|
<p><a class="button" href="/admin/user_form.php">Neuen Benutzer anlegen</a></p>
|
|
<?php endif; ?>
|
|
|
|
<div class="table-scroll">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Benutzername</th>
|
|
<th>Anzeigename</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): ?>
|
|
<tr>
|
|
<td><?= e($u['username']) ?></td>
|
|
<td><?= e($u['display_name']) ?></td>
|
|
<td><?= e($u['role_names'] ?: '-') ?></td>
|
|
<td>
|
|
<div class="badge-group">
|
|
<span class="badge <?= $u['status'] === 'active' ? 'badge-active' : 'badge-disabled' ?>">
|
|
<?= $u['status'] === 'active' ? 'Aktiv' : 'Deaktiviert' ?>
|
|
</span>
|
|
<?php if ($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): ?>
|
|
<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'; ?>
|