LuminaWebsite/raids.php
Maaxxs 706cf97d64 Add a "Mein Profil" page and align raids with the real bot logic
- New profile.php (display name, password, Discord link/unlink),
  reachable from the sidebar; removed the duplicate Discord section
  from the dashboard.
- Corrected class names/icon mapping to match the actual bot config
  (Beschwörer, Kantor) instead of the guessed German terms used
  earlier.
- raids.php now understands the bot's full group model: group 0 is
  the bench ("Ersatzbank"), -1 is a decline ("Abgemeldet"), and class
  "Ausstehend" marks a pending premade invite (now shown with an
  hourglass instead of being silently dropped or mis-rendered). The
  "X / max" counter matches the bot's own active-count logic (pending
  invites don't count). Signup form also lets a member choose the
  bench explicitly.
- A few more inline icons (profile, list) for general visual polish.

Verified grouping/active-count/icon logic with synthetic bench/
declined/pending signups, and the real raids.php flow (profile
update, sidebar nav) against a local DB plus the live raids API.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-18 13:49:41 +02:00

241 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php';
require_permission('raids.view');
function render_signup_list(array $members): void
{
?>
<ul>
<?php foreach ($members as $member): ?>
<?php
$memberName = (string) ($member['name'] ?? '?');
$memberClass = (string) ($member['class'] ?? '');
$isPending = $memberClass === 'Ausstehend';
$classIconUrl = $isPending ? null : class_icon_url($memberClass);
?>
<li<?= $isPending ? ' class="raid-signup-pending"' : '' ?>>
<?php if ($isPending): ?>
<span class="class-icon-placeholder" title="Einladung ausstehend">⏳</span>
<?php elseif ($classIconUrl): ?>
<img src="<?= e($classIconUrl) ?>" alt="<?= e($memberClass) ?>" title="<?= e($memberClass) ?>" class="class-icon">
<?php endif; ?>
<?= e($memberName) ?>
<?php if (!$isPending && !$classIconUrl && $memberClass !== ''): ?>
<span class="text-muted">(<?= e($memberClass) ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
$currentUser = current_user();
$currentDiscordId = $currentUser['discord_id'] ?? null;
$canManageRaids = user_has_permission('raids.manage');
$classOptions = ['Templer', 'Gladiator', 'Assassine', 'Jäger', 'Magier', 'Beschwörer', 'Kleriker', 'Kantor'];
$status = (string) ($_GET['status'] ?? 'active');
if (!in_array($status, RAID_STATUSES, true)) {
$status = 'active';
}
$raids = [];
$apiError = null;
try {
$raids = fetch_raids($status);
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
$statusLabels = [
'active' => 'Aktiv',
'archived' => 'Archiviert',
'all' => 'Alle',
];
$emptyLabels = [
'active' => 'Aktuell sind keine aktiven Raids geplant.',
'archived' => 'Es sind keine archivierten Raids vorhanden.',
'all' => 'Aktuell sind keine Raids vorhanden.',
];
$pageTitle = 'Raids';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<h1>Raids</h1>
<p class="text-muted">Raid-Termine deiner Gilde.</p>
<div class="filter-tabs">
<?php foreach ($statusLabels as $value => $label): ?>
<a href="/raids.php?status=<?= e($value) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
<?php endforeach; ?>
</div>
</div>
<?php if ($apiError): ?>
<div class="panel">
<div class="flash flash-error">Raid-Daten konnten nicht geladen werden: <?= e($apiError) ?></div>
</div>
<?php elseif (empty($raids)): ?>
<div class="panel">
<p class="text-muted"><?= e($emptyLabels[$status]) ?></p>
</div>
<?php else: ?>
<?php foreach ($raids as $raid): ?>
<?php
$title = (string) ($raid['title'] ?? 'Raid');
$dateLabel = (string) ($raid['date'] ?? '');
if (!empty($raid['timestamp'])) {
$dateLabel = date('d.m.Y H:i', (int) $raid['timestamp']) . ' Uhr';
}
$requirements = trim((string) ($raid['requirements'] ?? ''));
$gearscore = trim((string) ($raid['gearscore'] ?? ''));
$maxSlots = (int) ($raid['max_slots'] ?? 0);
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
$isArchived = !empty($raid['archived']) || !empty($raid['archived_at']);
$archivedAt = $raid['archived_at'] ?? null;
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
// Gruppennummern folgen der Logik des Bots: >=1 echte Gruppe, 0 Ersatzbank, -1 abgemeldet.
$signupsByGroup = [];
$benchSignups = [];
$declinedSignups = [];
$mySignup = null;
foreach ($signups as $signup) {
$groupNumber = (int) ($signup['group'] ?? 0);
if ($groupNumber >= 1) {
$signupsByGroup[$groupNumber][] = $signup;
} elseif ($groupNumber === 0) {
$benchSignups[] = $signup;
} else {
$declinedSignups[] = $signup;
}
if ($currentDiscordId && (string) ($signup['user_id'] ?? '') === (string) $currentDiscordId && $groupNumber >= 0) {
$mySignup = $signup;
}
}
// Wie im Bot-Embed zaehlen nur echte, bestaetigte Anmeldungen als "aktiv".
$activeCount = 0;
foreach ($signupsByGroup as $groupMembers) {
foreach ($groupMembers as $groupMember) {
if (($groupMember['class'] ?? '') !== 'Ausstehend') {
$activeCount++;
}
}
}
?>
<div class="panel<?= $isArchived ? ' panel-archived' : '' ?>">
<div class="raid-header">
<h2><?= e($title) ?></h2>
<div class="badge-group">
<?php if ($isArchived): ?>
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
<?php endif; ?>
<span class="badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
<?php if ($canManageRaids): ?>
<?php if ($isArchived): ?>
<form method="post" action="/raid_restore.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="text-button">Wiederherstellen</button>
</form>
<?php else: ?>
<form method="post" action="/raid_archive.php" class="inline-form" onsubmit="return confirm('Diesen Raid wirklich archivieren?');">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="text-button">Archivieren</button>
</form>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<p class="text-muted"><?= e($dateLabel) ?></p>
<?php if ($requirements !== ''): ?>
<p class="raid-meta-line"><?= icon('list') ?> <strong>Anforderungen:</strong> <?= e($requirements) ?></p>
<?php endif; ?>
<?php if ($gearscore !== ''): ?>
<p><strong>Gearscore:</strong> <?= e($gearscore) ?></p>
<?php endif; ?>
<?php if (!empty($groupNames)): ?>
<div class="raid-groups">
<?php foreach ($groupNames as $index => $groupName): ?>
<?php $members = $signupsByGroup[$index + 1] ?? []; ?>
<div class="raid-group">
<h3><?= e($groupName) ?> (<?= count($members) ?>)</h3>
<?php if (empty($members)): ?>
<p class="text-muted">Keine Anmeldungen</p>
<?php else: ?>
<?php render_signup_list($members); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php if (!empty($benchSignups)): ?>
<div class="raid-group raid-group-bench">
<h3>Ersatzbank (<?= count($benchSignups) ?>)</h3>
<?php render_signup_list($benchSignups); ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($declinedSignups)): ?>
<p class="text-muted raid-declined">
Abgemeldet: <?= e(implode(', ', array_map(static fn ($s) => (string) ($s['name'] ?? '?'), $declinedSignups))) ?>
</p>
<?php endif; ?>
<?php
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
?>
<?php if ($isArchived): ?>
<p class="text-muted raid-signup-note">Dieser Raid ist archiviert – Anmeldungen sind geschlossen.</p>
<?php elseif (!$currentDiscordId): ?>
<p class="text-muted raid-signup-note">Verknüpfe deinen <a href="/profile.php">Discord-Account</a>, um dich anzumelden.</p>
<?php else: ?>
<?php if ($mySignup): ?>
<div class="raid-signup-note">
<p>
Du bist angemeldet als <strong><?= e((string) ($mySignup['class'] ?? '')) ?></strong>
in <strong><?= e($mySignupGroupLabel) ?></strong>.
</p>
<form method="post" action="/raid_unsignup.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="button button-secondary">Abmelden</button>
</form>
</div>
<?php endif; ?>
<?php if (!empty($groupNames)): ?>
<form method="post" action="/raid_signup.php" class="raid-signup-form">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= (int) ($raid['raid_id'] ?? 0) ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<select name="class" required>
<option value="">Klasse wählen…</option>
<?php foreach ($classOptions as $classOption): ?>
<option value="<?= e($classOption) ?>" <?= ($mySignup && ($mySignup['class'] ?? '') === $classOption) ? 'selected' : '' ?>><?= e($classOption) ?></option>
<?php endforeach; ?>
</select>
<select name="group" required>
<?php foreach ($groupNames as $index => $groupName): ?>
<option value="<?= $index + 1 ?>" <?= $mySignupGroupNumber === $index + 1 ? 'selected' : '' ?>><?= e($groupName) ?></option>
<?php endforeach; ?>
<option value="0" <?= $mySignupGroupNumber === 0 ? 'selected' : '' ?>>Ersatzbank</option>
</select>
<button type="submit"><?= $mySignup ? 'Aktualisieren' : 'Anmelden' ?></button>
</form>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>