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>
160 lines
6.1 KiB
PHP
160 lines
6.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raids_api.php';
|
|
require_permission('dashboard.view');
|
|
|
|
$user = current_user();
|
|
$canViewUsers = user_has_permission('users.view');
|
|
$canManageRoles = user_has_permission('roles.manage');
|
|
$canViewRaids = user_has_permission('raids.view');
|
|
$discordId = $user['discord_id'] ?? null;
|
|
|
|
$roleStmt = db()->prepare(
|
|
"SELECT COALESCE(NULLIF(r.display_name, ''), r.name) AS name
|
|
FROM roles r JOIN user_roles ur ON ur.role_id = r.id WHERE ur.user_id = ? ORDER BY r.name"
|
|
);
|
|
$roleStmt->execute([$user['id']]);
|
|
$roleNames = array_column($roleStmt->fetchAll(), 'name');
|
|
|
|
$upcomingRaids = [];
|
|
$raidsError = null;
|
|
if ($canViewRaids) {
|
|
try {
|
|
$upcomingRaids = fetch_raids('active');
|
|
usort($upcomingRaids, static fn (array $a, array $b): int
|
|
=> ($a['timestamp'] ?? PHP_INT_MAX) <=> ($b['timestamp'] ?? PHP_INT_MAX));
|
|
|
|
foreach ($upcomingRaids as &$raid) {
|
|
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
|
$raid['_my_signup'] = null;
|
|
foreach ($signups as $signup) {
|
|
if ($discordId && (string) ($signup['user_id'] ?? '') === (string) $discordId && (int) ($signup['group'] ?? 0) >= 0) {
|
|
$raid['_my_signup'] = $signup;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
unset($raid);
|
|
} catch (Throwable $e) {
|
|
$raidsError = $e->getMessage();
|
|
}
|
|
}
|
|
$nextRaids = array_slice($upcomingRaids, 0, 3);
|
|
|
|
$memberCount = $canViewUsers ? (int) db()->query("SELECT COUNT(*) FROM users WHERE status = 'active'")->fetchColumn() : null;
|
|
$roleCount = $canManageRoles ? (int) db()->query('SELECT COUNT(*) FROM roles')->fetchColumn() : null;
|
|
|
|
$pageTitle = 'Dashboard';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<div class="profile-header">
|
|
<?= avatar_html($user, 100) ?>
|
|
<div>
|
|
<h1>Willkommen, <?= e($user['display_name'] !== '' ? $user['display_name'] : $user['username']) ?>!</h1>
|
|
<p class="text-muted">Hier ist dein Überblick über die Gilde.</p>
|
|
<div class="badge-group">
|
|
<?php foreach ($roleNames as $roleName): ?>
|
|
<span class="badge"><?= e($roleName) ?></span>
|
|
<?php endforeach; ?>
|
|
<?php if ($discordId): ?>
|
|
<span class="badge badge-active">Discord verbunden</span>
|
|
<?php else: ?>
|
|
<span class="badge badge-disabled">Discord nicht verbunden</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel">
|
|
<div class="card-grid">
|
|
<?php if ($canViewRaids): ?>
|
|
<div class="panel stat-card">
|
|
<div class="icon-badge"><?= icon('calendar') ?></div>
|
|
<div>
|
|
<h3><?= count($upcomingRaids) ?></h3>
|
|
<p class="text-muted">Anstehende Raids</p>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($canViewUsers): ?>
|
|
<div class="panel stat-card">
|
|
<div class="icon-badge"><?= icon('users') ?></div>
|
|
<div>
|
|
<h3><?= $memberCount ?></h3>
|
|
<p class="text-muted">Mitglieder</p>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($canManageRoles): ?>
|
|
<div class="panel stat-card">
|
|
<div class="icon-badge"><?= icon('shield') ?></div>
|
|
<div>
|
|
<h3><?= $roleCount ?></h3>
|
|
<p class="text-muted">Berechtigungsgruppen</p>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($canViewRaids): ?>
|
|
<div class="panel">
|
|
<div class="raid-header">
|
|
<h2>Nächste Raids</h2>
|
|
<a href="/raids.php">Alle Raids ansehen →</a>
|
|
</div>
|
|
<?php if ($raidsError): ?>
|
|
<div class="flash flash-error">Raid-Daten konnten nicht geladen werden: <?= e($raidsError) ?></div>
|
|
<?php elseif (empty($nextRaids)): ?>
|
|
<p class="text-muted">Aktuell sind keine aktiven Raids geplant.</p>
|
|
<?php else: ?>
|
|
<div class="table-scroll">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Raid</th>
|
|
<th>Termin</th>
|
|
<th>Anmeldungen</th>
|
|
<th>Mein Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($nextRaids as $raid): ?>
|
|
<?php
|
|
$title = (string) ($raid['title'] ?? 'Raid');
|
|
$dateLabel = !empty($raid['timestamp']) ? date('d.m.Y H:i', (int) $raid['timestamp']) . ' Uhr' : (string) ($raid['date'] ?? '');
|
|
$maxSlots = (int) ($raid['max_slots'] ?? 0);
|
|
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
|
|
$activeCount = 0;
|
|
foreach ($signups as $signup) {
|
|
if ((int) ($signup['group'] ?? 0) >= 1 && ($signup['class'] ?? '') !== 'Ausstehend') {
|
|
$activeCount++;
|
|
}
|
|
}
|
|
$mySignup = $raid['_my_signup'] ?? null;
|
|
?>
|
|
<tr>
|
|
<td><a href="/raids.php"><?= e($title) ?></a></td>
|
|
<td class="text-muted"><?= e($dateLabel) ?></td>
|
|
<td><?= $activeCount ?> / <?= $maxSlots ?></td>
|
|
<td>
|
|
<?php if ($mySignup): ?>
|
|
<span class="badge badge-active">Angemeldet (<?= e((string) ($mySignup['class'] ?? '')) ?>)</span>
|
|
<?php elseif (!$discordId): ?>
|
|
<span class="badge badge-disabled">Discord fehlt</span>
|
|
<?php else: ?>
|
|
<span class="badge">Nicht angemeldet</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|