LuminaWebsite/includes/raid_card.php
Maaxxs 8b59cb503b DACH Elyos: the Consilium Elyseum is now called DACH Elyos across the website
Asked for: "das consilium elyseum wurde umbenannt zu DACH Elyos. pass das bitte an auf der website".

- CONSILIUM_NAME is 'DACH Elyos', and every visible text follows it: sidebar, the alliance page, member tab, raid
  area, calendar audience and badge, iCal note, map live sessions and share buttons, admin pages (Verwaltung ->
  DACH Elyos, Discord-Bot, Berechtigungsgruppen), flash messages, log entries, permission descriptions (synced to
  the database by schema_sync_core_permissions()) and the privacy page.
- The name takes no article, so the sentences around it changed too: "von DACH Elyos", "in DACH Elyos", "für DACH
  Elyos" instead of "des Consiliums", "im Consilium", "für das Consilium". The bot channel label is now
  "Raid-Kanal DACH Elyos".
- Internal names stay "consilium": permission keys, tables, settings, files and URLs (?bereich=consilium,
  ?tab=consilium), so nothing in the database or in existing links changes. includes/consilium.php says so.
- README: section renamed to "DACH Elyos" (anchor #dach-elyos).
- No patch note (alliance topics stay out of them). The bot's two "Consilium" error texts in live_tactics.py never
  reach the page - the map only reads the status code - so the bot needs no update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 14:15:10 +02:00

393 lines
22 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
declare(strict_types=1);
/**
* Eine Raid-Karte der Raid-Seite. Wird von raids.php fuer die ganze Liste und von raids_live.php
* fuer einzelne, inzwischen geaenderte Raids gerendert (Live-Aktualisierung ohne Neuladen).
*
* $ctx: status (aktueller Reiter), current_discord_id, current_user_id, can_manage (raids.manage),
* can_set_points (raids.points), settings (raid_settings je raid_id, mit Raid-Lead), premades,
* new_since (optional: danach gepostete Raids sind mit "Neu" markiert, raids_mark_seen())
*
* Der Raid-Lead (hat den Raid angelegt) verwaltet seinen Raid wie die Leitung - nur ohne Wiederherstellen,
* endgueltiges Loeschen und Lumipunkte (includes/raid_attendance.php).
*/
require_once __DIR__ . '/raids_api.php';
require_once __DIR__ . '/raid_attendance.php';
require_once __DIR__ . '/premade_banner.php';
/** @param string $leadDiscordId Discord-ID des Raid-Leads - er bekommt in der Liste eine Krone */
function render_signup_list(array $members, bool $draggable, string $leadDiscordId = ''): void
{
?>
<ul class="raid-signup-list">
<?php foreach ($members as $member): ?>
<?php
$memberName = (string) ($member['name'] ?? '?');
$memberClass = (string) ($member['class'] ?? '');
$memberUserId = (string) ($member['user_id'] ?? '');
$isPending = $memberClass === 'Ausstehend';
$classIconUrl = $isPending ? null : class_icon_url($memberClass);
?>
<li class="raid-signup-item<?= $isPending ? ' raid-signup-pending' : '' ?>"
<?= $draggable ? 'draggable="true"' : '' ?>
data-user-id="<?= e($memberUserId) ?>" data-name="<?= e($memberName) ?>" data-class="<?= e($memberClass) ?>">
<?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; ?>
<span class="raid-signup-name" title="<?= e($memberName . ($memberClass !== '' && !$isPending ? ' – ' . $memberClass : '')) ?>"><?= e($memberName) ?><?php if (!$isPending && !$classIconUrl && $memberClass !== ''): ?> <span class="text-muted">(<?= e($memberClass) ?>)</span><?php endif; ?></span>
<?php if ($leadDiscordId !== '' && $memberUserId === $leadDiscordId): ?>
<span class="raid-lead-tag" title="Raid-Lead"><?= icon('crown') ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
/** Hat der Raid schon begonnen? (Davon haengt der Hinweis "noch nicht kontrolliert" ab.) */
function raid_card_started(array $raid): bool
{
return !empty($raid['timestamp']) && (int) $raid['timestamp'] <= time();
}
/**
* Fingerabdruck einer Raid-Karte: aendert er sich, rendert die Live-Aktualisierung die Karte neu.
* Enthalten ist alles, was die Karte anzeigt - Raid samt Anmeldungen (mit Anzeigenamen), die
* Punkte-Einstellungen und ob der Raid schon begonnen hat.
*/
function raid_card_rev(array $raid, ?array $setting): string
{
$settingFields = [];
foreach (['points_present', 'points_absent', 'auto_processed_at', 'auto_result', 'attendance_checked_at', 'lead_user_id', 'lead_name'] as $key) {
$settingFields[$key] = isset($setting[$key]) ? (string) $setting[$key] : null;
}
return substr(md5((string) json_encode([$raid, $settingFields, raid_card_started($raid)], JSON_UNESCAPED_UNICODE)), 0, 16);
}
/** @param array<string, mixed> $ctx siehe Dateikopf */
function render_raid_card(array $raid, array $ctx): void
{
$status = (string) $ctx['status'];
$currentDiscordId = $ctx['current_discord_id'] ?? null;
$canManageRaids = !empty($ctx['can_manage']);
$canSetRaidPoints = !empty($ctx['can_set_points']);
$premades = (array) ($ctx['premades'] ?? []);
// Banner der Premades nach Namen - eingeladene Premade-Gruppen heissen wie ihre Premade
$premadeBanners = (array) ($ctx['premade_banners'] ?? []);
$raidId = (int) ($raid['raid_id'] ?? 0);
$title = (string) ($raid['title'] ?? 'Raid');
$dateRaw = (string) ($raid['date'] ?? '');
$dateLabel = $dateRaw;
$dateLocal = '';
if (!empty($raid['timestamp'])) {
$dateLabel = date('d.m.Y H:i', (int) $raid['timestamp']) . ' Uhr';
$dateLocal = date('Y-m-d\TH:i', (int) $raid['timestamp']);
}
$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;
$lockedGroups = is_array($raid['locked_groups'] ?? null) ? array_map('intval', $raid['locked_groups']) : [];
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
// Raid-Lead: verwaltet seinen eigenen Raid wie die Leitung (ohne Wiederherstellen/Loeschen/Lumipunkte)
$raidSetting = $ctx['settings'][(string) $raidId] ?? null;
$leadUserId = (int) ($raidSetting['lead_user_id'] ?? 0);
$leadName = trim((string) ($raidSetting['lead_name'] ?? ''));
$leadDiscordId = (string) ($raidSetting['lead_discord_id'] ?? '');
$isLead = $leadUserId > 0 && $leadUserId === (int) ($ctx['current_user_id'] ?? 0);
$canManageThis = $canManageRaids || $isLead;
$canEditThis = $canManageThis && !$isArchived;
// Gruppennummern folgen der Logik des Bots: >=1 echte Gruppe, 0 Ersatzbank, -1 abgemeldet.
$signupsByGroup = [];
$benchSignups = [];
$declinedSignups = [];
$mySignup = null;
$myDeclined = false;
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) {
if ($groupNumber >= 0) {
$mySignup = $signup;
} else {
$myDeclined = true;
}
}
}
// 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++;
}
}
}
$autoPresent = (int) ($raidSetting['points_present'] ?? 0);
$autoAbsent = (int) ($raidSetting['points_absent'] ?? 0);
// Raids des Consilium Elyseum bringen keine Lumipunkte - dort ist davon nirgends die Rede
$isConsilium = raid_area($raid) === 'consilium';
$raidStarted = raid_card_started($raid);
$isNew = !$isArchived && isset($ctx['new_since']) && raid_posted_at($raidId) > (int) $ctx['new_since'];
// Suchtext fuer die Raid-Suche: Titel, Termin, Anforderungen, Gruppen, Spieler und Klassen
$searchText = mb_strtolower(implode(' ', array_merge(
[$title, $dateLabel, $requirements, $gearscore],
$groupNames,
array_map(static fn ($s) => ($s['name'] ?? '') . ' ' . ($s['class'] ?? ''), $signups)
)));
$mySignupGroupNumber = $mySignup ? (int) ($mySignup['group'] ?? 0) : null;
$mySignupGroupLabel = $mySignupGroupNumber === 0 ? 'Ersatzbank' : ($mySignupGroupNumber ? ($groupNames[$mySignupGroupNumber - 1] ?? ('#' . $mySignupGroupNumber)) : null);
?>
<div class="panel raid-card<?= $isArchived ? ' panel-archived' : '' ?>" id="raid-<?= $raidId ?>"
data-raid-id="<?= $raidId ?>"
data-rev="<?= e(raid_card_rev($raid, $raidSetting)) ?>"
data-fields-rev="<?= e(substr(md5((string) json_encode([$title, $dateRaw, $requirements, $gearscore, $groupNames, $lockedGroups, $maxSlots, $autoPresent, $autoAbsent], JSON_UNESCAPED_UNICODE)), 0, 12)) ?>"
data-groups='<?= e(json_encode($groupNames, JSON_UNESCAPED_UNICODE)) ?>'
data-locked-groups='<?= e(json_encode($lockedGroups)) ?>'
data-my-class="<?= e((string) ($mySignup['class'] ?? '')) ?>"
data-my-group="<?= $mySignupGroupNumber ?? '' ?>"
data-search="<?= e($searchText) ?>">
<div class="raid-header">
<h2><?= e($title) ?></h2>
<div class="badge-group">
<?php if ($isNew): ?>
<span class="badge raid-new-badge" title="Seit deinem letzten Besuch dazugekommen">Neu</span>
<?php endif; ?>
<?php if ($isArchived): ?>
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
<?php endif; ?>
<span class="badge raid-count-badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
<?php if ($canEditThis): ?>
<button type="button" class="icon-button raid-edit-toggle" title="Bearbeiten">
<?= icon('edit') ?>
</button>
<?php endif; ?>
<?php if ($canManageRaids && $isArchived): ?>
<?php // Wiederherstellen und endgueltig loeschen nur die Leitung - auch nicht der Raid-Lead ?>
<form method="post" action="/raid_restore.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="icon-button" title="Wiederherstellen"><?= icon('restore') ?></button>
</form>
<form method="post" action="/raid_delete_action.php" class="inline-form" data-confirm="<?= e('„' . $title . '“ wirklich ENDGÜLTIG löschen? Das kann nicht rückgängig gemacht werden.') ?>" data-confirm-title="Raid löschen" data-confirm-danger data-confirm-ok="Löschen">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="icon-button icon-button-danger" title="Endgültig löschen"><?= icon('trash') ?></button>
</form>
<?php elseif ($canEditThis): ?>
<form method="post" action="/raid_archive.php" class="inline-form" data-confirm="<?= e('„' . $title . '“ wird archiviert und kurz danach aus dem Discord-Kanal entfernt.' . ($isConsilium ? '' : ' Die Lumipunkte werden dabei automatisch vergeben.') . ($canManageRaids ? '' : ' Wiederherstellen kann ihn danach nur ' . ($isConsilium ? 'die Leitung von ' . CONSILIUM_NAME . '.' : 'die Legionsleitung.'))) ?>" data-confirm-title="Raid archivieren?" data-confirm-ok="Archivieren">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="icon-button" title="Archivieren"><?= icon('archive') ?></button>
</form>
<?php endif; ?>
</div>
</div>
<p class="text-muted"><?= e($dateLabel) ?></p>
<?php if ($leadUserId > 0): ?>
<p class="raid-lead-line">
<?= icon('crown') ?> Raid-Lead:
<?php if (($raidSetting['lead_status'] ?? '') === 'active'): ?>
<a href="/member.php?id=<?= $leadUserId ?>"><?= e($leadName) ?></a>
<?php else: ?>
<?= e($leadName !== '' ? $leadName : 'unbekannt') ?>
<?php endif; ?>
<?php if ($isLead): ?><span class="text-muted">(du - du trägst die Anwesenheit ein)</span><?php endif; ?>
</p>
<?php endif; ?>
<?php if ($canManageThis): ?>
<div class="raid-attendance-line">
<a class="button button-secondary button-small" href="/raid_attendance.php?raid=<?= $raidId ?>">Anwesenheit</a>
<?php if (!empty($raidSetting['attendance_checked_at'])): ?>
<span class="badge badge-active">kontrolliert</span>
<?php elseif ($raidStarted): ?>
<span class="badge badge-pending">noch nicht kontrolliert</span>
<?php endif; ?>
<?php if (!$isConsilium && ($autoPresent > 0 || $autoAbsent > 0)): ?>
<span class="text-muted raid-auto-points" title="Automatische Lumipunkte beim Archivieren">
<?= contribution_coin(15) ?> +<?= $autoPresent ?><?= $autoAbsent > 0 ? ' / −' . $autoAbsent : '' ?>
<?= !empty($raidSetting['auto_processed_at']) ? '· ' . e((string) $raidSetting['auto_result']) : 'beim Archivieren' ?>
</span>
<?php endif; ?>
</div>
<?php endif; ?>
<?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(raid_gearscore_label($gearscore)) ?></p>
<?php endif; ?>
<?php if ($canEditThis): ?>
<div class="raid-edit-panel">
<form class="raid-edit-form" data-raid-id="<?= $raidId ?>">
<div class="raid-edit-grid">
<div>
<label>Titel</label>
<input type="text" name="title" value="<?= e($title) ?>" maxlength="60" required>
</div>
<div>
<label>Datum &amp; Uhrzeit</label>
<input type="datetime-local" name="date_local" value="<?= e($dateLocal) ?>">
</div>
<div>
<label>Max. Spieler</label>
<input type="number" name="max_slots" value="<?= (int) $maxSlots ?>" min="1" step="1" inputmode="numeric" required>
</div>
<div>
<label>Gearscore</label>
<input type="text" name="gearscore" value="<?= e($gearscore) ?>" maxlength="50" inputmode="numeric" placeholder="optional, z. B. 2.100">
</div>
</div>
<div class="raid-edit-requirements">
<label>Anforderungen</label>
<textarea name="requirements" rows="3" maxlength="80" required><?= e($requirements) ?></textarea>
</div>
<?php if ($isConsilium): ?>
<?php // Consilium-Raid: keine Lumipunkte einzustellen ?>
<?php elseif ($canSetRaidPoints): ?>
<div class="raid-points-fields">
<div>
<label><?= contribution_coin(16) ?> Punkte für Anwesende beim Archivieren</label>
<input type="number" name="points_present" min="0" max="<?= RAID_POINTS_MAX ?>" step="1" value="<?= $autoPresent ?>">
</div>
<div>
<label>Abzug für Abwesende</label>
<input type="number" name="points_absent" min="0" max="<?= RAID_POINTS_MAX ?>" step="1" value="<?= $autoAbsent ?>">
</div>
</div>
<?php else: ?>
<p class="field-hint raid-points-fixed"><?= contribution_coin(15) ?> <?= e(raid_points_summary($autoPresent, $autoAbsent)) ?> – die Werte legt die Legionsleitung fest.</p>
<?php endif; ?>
<div class="group-editor" data-max-groups="<?= RAID_MAX_GROUPS ?>" data-group-size="<?= RAID_GROUP_SIZE ?>">
<label>Gruppen</label>
<div class="group-editor-rows">
<?php foreach ($groupNames as $index => $groupName): ?>
<div class="group-editor-row">
<input type="text" class="group-editor-name" value="<?= e($groupName) ?>" placeholder="Gruppenname">
<?php $isRowLocked = in_array($index + 1, $lockedGroups, true); ?>
<label class="group-editor-lock<?= $isRowLocked ? ' checked' : '' ?>" title="Gruppe sperren">
<input type="checkbox" class="group-editor-lock-checkbox" <?= $isRowLocked ? 'checked' : '' ?>>
<?= icon('lock') ?>
</label>
<button type="button" class="icon-button group-editor-remove" title="Gruppe entfernen"><?= icon('x') ?></button>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="button-secondary group-editor-add">+ Gruppe hinzufügen</button>
</div>
<div class="actions">
<button type="submit">Speichern</button>
<span class="raid-edit-feedback text-muted"></span>
</div>
</form>
<?php if (!empty($premades)): ?>
<form class="raid-premade-form" data-raid-id="<?= $raidId ?>">
<label>Premade einladen</label>
<div class="raid-premade-row">
<select name="premade_id">
<?php foreach ($premades as $premade): ?>
<option value="<?= (int) ($premade['id'] ?? 0) ?>"><?= e((string) ($premade['name'] ?? '')) ?></option>
<?php endforeach; ?>
</select>
<select name="group">
<?php foreach ($groupNames as $index => $groupName): ?>
<option value="<?= $index + 1 ?>"><?= e($groupName) ?></option>
<?php endforeach; ?>
</select>
<button type="submit" class="button-secondary">Einladen</button>
</div>
<span class="raid-premade-feedback text-muted"></span>
</form>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($groupNames)): ?>
<div class="raid-groups">
<?php foreach ($groupNames as $index => $groupName): ?>
<?php
$members = $signupsByGroup[$index + 1] ?? [];
$isLockedGroup = in_array($index + 1, $lockedGroups, true);
$groupBanner = $premadeBanners[mb_strtolower($groupName)] ?? null;
?>
<div class="raid-group raid-drop-zone<?= $isLockedGroup ? ' raid-group-locked' : '' ?><?= $groupBanner ? ' raid-group-premade' : '' ?>" data-group="<?= $index + 1 ?>" data-locked="<?= $isLockedGroup ? '1' : '0' ?>">
<h3<?= $groupBanner ? ' style="' . premade_banner_style($groupBanner) . '"' : '' ?>><?= e($groupName) ?> <span class="raid-group-count">(<?= count($members) ?>)</span><?= $isLockedGroup ? ' ' . icon('lock') : '' ?></h3>
<?php if (empty($members)): ?>
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
<?php else: ?>
<?php render_signup_list($members, $canEditThis, $leadDiscordId); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<div class="raid-group raid-group-bench raid-drop-zone" data-group="0">
<h3>Ersatzbank <span class="raid-group-count">(<?= count($benchSignups) ?>)</span></h3>
<?php if (empty($benchSignups)): ?>
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
<?php else: ?>
<?php render_signup_list($benchSignups, $canEditThis, $leadDiscordId); ?>
<?php endif; ?>
</div>
</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 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: ?>
<div class="raid-signup-note">
<?php if ($mySignup): ?>
<p>
Du bist angemeldet als <strong><?= e((string) ($mySignup['class'] ?? '')) ?></strong>
in <strong><?= e((string) $mySignupGroupLabel) ?></strong>.
</p>
<div class="actions">
<button type="button" class="button button-secondary raid-open-signup">Ändern</button>
<form method="post" action="/raid_unsignup.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
<input type="hidden" name="status" value="<?= e($status) ?>">
<button type="submit" class="button-secondary">Abmelden</button>
</form>
</div>
<?php else: ?>
<?php if ($myDeclined): ?>
<p>Du hast dich abgemeldet.</p>
<?php endif; ?>
<button type="button" class="button raid-open-signup"><?= $myDeclined ? 'Doch anmelden' : 'Anmelden' ?></button>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php
}