The points move out of the stat cards into their own panel below the welcome panel. It shows the balance, your rank out of all members, your open or approved-but-not-delivered Lumishop orders, and buttons to the ranking and the shop. The stat card panel is hidden when there is nothing to show in it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
299 lines
13 KiB
PHP
299 lines
13 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/raids_api.php';
|
||
require_once __DIR__ . '/includes/contributions.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');
|
||
$canViewPremades = user_has_permission('premades.view');
|
||
$canViewContributions = user_has_permission('contributions.view');
|
||
$canViewShop = user_has_permission('shop.view');
|
||
$discordId = $user['discord_id'] ? (int) $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);
|
||
|
||
// Eigene Lumipunkte mit Platz in der Rangliste (gleiche Punktzahl = gleicher Platz).
|
||
$myPoints = null;
|
||
$myRank = null;
|
||
if ($canViewContributions) {
|
||
$myPoints = contribution_user_balance((int) $user['id']);
|
||
$rankStmt = db()->prepare(
|
||
"SELECT COUNT(*) + 1 FROM (
|
||
SELECT u.id, COALESCE(SUM(e.points), 0) AS points FROM users u
|
||
LEFT JOIN contribution_entries e ON e.user_id = u.id
|
||
WHERE u.status = 'active' GROUP BY u.id
|
||
) balances WHERE points > ?"
|
||
);
|
||
$rankStmt->execute([$myPoints]);
|
||
$myRank = (int) $rankStmt->fetchColumn();
|
||
$memberTotal = (int) db()->query("SELECT COUNT(*) FROM users WHERE status = 'active'")->fetchColumn();
|
||
}
|
||
|
||
// Eigene Lumishop-Antraege: offen bzw. bewilligt und noch nicht uebergeben.
|
||
$myShopOpen = 0;
|
||
$myShopReady = 0;
|
||
if ($canViewShop) {
|
||
$shopStmt = db()->prepare(
|
||
"SELECT COALESCE(SUM(status = 'pending'), 0), COALESCE(SUM(status = 'approved'), 0)
|
||
FROM shop_orders WHERE user_id = ?"
|
||
);
|
||
$shopStmt->execute([(int) $user['id']]);
|
||
[$myShopOpen, $myShopReady] = array_map('intval', $shopStmt->fetch(PDO::FETCH_NUM));
|
||
}
|
||
|
||
$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;
|
||
|
||
// Eigene Premade fuer die Dashboard-Kurzuebersicht laden (nur Anzeige, keine Verwaltung -
|
||
// dafuer verweist das Widget auf /premades.php). Faellt bei Bot-Ausfall o.ae. still weg,
|
||
// das restliche Dashboard soll trotzdem laden.
|
||
$myPremade = null;
|
||
$myPremadeNamesByDiscordId = [];
|
||
$myPremadeLinkedUsersByDiscordId = [];
|
||
if ($canViewPremades && $discordId) {
|
||
try {
|
||
$myRelation = find_my_premade(fetch_premades(), $discordId);
|
||
if ($myRelation !== null) {
|
||
$myPremade = $myRelation['premade'];
|
||
|
||
$premadeDiscordIds = [(int) ($myPremade['owner_id'] ?? 0)];
|
||
foreach ($myPremade['members'] ?? [] as $m) {
|
||
$premadeDiscordIds[] = (int) ($m['user_id'] ?? 0);
|
||
}
|
||
$premadeDiscordIds = array_values(array_unique(array_filter($premadeDiscordIds)));
|
||
if (!empty($premadeDiscordIds)) {
|
||
$placeholders = implode(',', array_fill(0, count($premadeDiscordIds), '?'));
|
||
$stmt = db()->prepare("SELECT id, discord_id, discord_username, display_name, avatar_filename FROM users WHERE discord_id IN ($placeholders)");
|
||
$stmt->execute($premadeDiscordIds);
|
||
foreach ($stmt->fetchAll() as $row) {
|
||
$name = $row['display_name'] !== '' ? $row['display_name'] : $row['discord_username'];
|
||
$myPremadeNamesByDiscordId[(int) $row['discord_id']] = $name;
|
||
$myPremadeLinkedUsersByDiscordId[(int) $row['discord_id']] = $row;
|
||
}
|
||
}
|
||
}
|
||
} catch (Throwable $e) {
|
||
$myPremade = 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>
|
||
|
||
<?php if ($myPoints !== null): ?>
|
||
<div class="panel dashboard-points">
|
||
<img class="dashboard-points-coin" src="/assets/images/lumipunkt.svg" alt="" width="64" height="64">
|
||
<div class="dashboard-points-main">
|
||
<h2>Lumipunkte</h2>
|
||
<div class="dashboard-points-value"><?= e(contribution_format($myPoints)) ?></div>
|
||
<p class="text-muted">Platz <?= (int) $myRank ?> von <?= (int) $memberTotal ?> in der Rangliste</p>
|
||
</div>
|
||
<?php if ($canViewShop && ($myShopOpen > 0 || $myShopReady > 0)): ?>
|
||
<div class="dashboard-points-shop">
|
||
<?php if ($myShopOpen > 0): ?>
|
||
<span class="badge badge-pending"><?= $myShopOpen ?> <?= $myShopOpen === 1 ? 'Antrag wartet' : 'Anträge warten' ?> auf Bewilligung</span>
|
||
<?php endif; ?>
|
||
<?php if ($myShopReady > 0): ?>
|
||
<span class="badge shop-badge-approved"><?= $myShopReady ?> bewilligt – Übergabe im Spiel ausstehend</span>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
<div class="dashboard-points-links">
|
||
<a class="button button-secondary" href="/contributions.php">Rangliste & Verlauf</a>
|
||
<?php if ($canViewShop): ?>
|
||
<a class="button" href="/shop.php">Zum Lumishop</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($canViewRaids || $canViewUsers || $canManageRoles): ?>
|
||
<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 endif; ?>
|
||
|
||
<?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 if ($myPremade): ?>
|
||
<div class="panel">
|
||
<div class="raid-header">
|
||
<h2>⚔️ Meine Premade: <?= e((string) ($myPremade['name'] ?? '')) ?></h2>
|
||
<a href="/premades.php">Zu den Premades →</a>
|
||
</div>
|
||
<div class="premade-roster">
|
||
<?php foreach (build_premade_slots($myPremade, $myPremadeNamesByDiscordId) as $slot): ?>
|
||
<?php if ($slot['type'] === 'empty'): ?>
|
||
<div class="premade-slot premade-slot-empty">
|
||
<div class="premade-slot-inner">
|
||
<span class="premade-slot-placeholder">+</span>
|
||
</div>
|
||
</div>
|
||
<?php else: ?>
|
||
<?php $slotUser = premade_avatar_user((int) $slot['id'], $myPremadeLinkedUsersByDiscordId, $slot['name']); ?>
|
||
<div class="premade-slot premade-slot-<?= e($slot['type']) ?>">
|
||
<div class="premade-slot-inner">
|
||
<?= avatar_html($slotUser, 40) ?>
|
||
<div class="premade-slot-name">
|
||
<strong><?= $slot['type'] === 'pending' ? '⏳ ' : '' ?><?= e($slot['name']) ?></strong>
|
||
<?php if ($slot['type'] === 'pending'): ?>
|
||
<span class="text-muted">Einladung offen</span>
|
||
<?php elseif (!empty($slot['class'])): ?>
|
||
<?php $slotClassIcon = class_icon_url($slot['class']); ?>
|
||
<span class="premade-slot-class">
|
||
<?php if ($slotClassIcon): ?>
|
||
<img class="premade-slot-class-icon" src="<?= e($slotClassIcon) ?>" alt="">
|
||
<?php endif; ?>
|
||
<span class="text-muted"><?= e($slot['class']) ?></span>
|
||
</span>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php if ($slot['type'] === 'lead'): ?>
|
||
<span class="premade-crown" title="Lead der Premade"><?= icon('crown') ?></span>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|