318 lines
17 KiB
PHP
318 lines
17 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/raids_api.php';
|
||
require_once __DIR__ . '/includes/raid_attendance.php';
|
||
require_once __DIR__ . '/includes/raid_card.php';
|
||
require_once __DIR__ . '/includes/raid_templates.php';
|
||
require_once __DIR__ . '/includes/consilium.php';
|
||
require_login();
|
||
|
||
// Zwei Bereiche: die Raids der Legion und die des Consilium Elyseum (eigener Discord-Kanal, includes/raids_api.php).
|
||
// Mitglieder verbuendeter Legionen sehen nur die Consilium-Raids.
|
||
$areas = array_values(array_filter(['legion', 'consilium'], 'raid_area_visible'));
|
||
if (!$areas) {
|
||
show_not_found();
|
||
}
|
||
$area = in_array($_GET['bereich'] ?? '', $areas, true) ? (string) $_GET['bereich'] : $areas[0];
|
||
$otherArea = count($areas) > 1 ? ($area === 'legion' ? 'consilium' : 'legion') : null;
|
||
|
||
$currentUser = current_user();
|
||
$currentDiscordId = $currentUser['discord_id'] ?? null;
|
||
// Seit dem letzten Besuch gepostete Raids sind mit "Neu" markiert, danach gelten sie als gesehen (Zahl in
|
||
// der Seitenleiste). Die Live-Aktualisierung (raids_live.php) markiert mit demselben Zeitpunkt.
|
||
$raidsNewSince = raids_mark_seen((int) $currentUser['id']);
|
||
$_SESSION['raids_new_since'] = $raidsNewSince;
|
||
// Rechte je Bereich: Legion raids.manage/raids.create, Consilium consilium.raids.manage/consilium.raids - wer anlegt,
|
||
// wird Raid-Lead (includes/raid_attendance.php). Lumipunkte gibt es nur bei Raids der Legion - festlegen darf sie,
|
||
// wer raids.points hat, auch als Raid-Lead ohne raids.manage (so pruefen es raid_create_action.php und
|
||
// raid_edit_action.php; sonst legte der Server +1 an, waehrend das Formular "keine Lumipunkte" zeigte).
|
||
$canManageRaids = raid_area_can_manage_all($area);
|
||
$canSetRaidPoints = $area === 'legion' && user_has_permission('raids.points');
|
||
$canCreateRaids = raid_area_can_create($area);
|
||
|
||
// Eigene Klassen (laut Discord) zuerst, die Main-Klasse ganz vorne - sie ist bei neuen Anmeldungen vorausgewaehlt
|
||
$classOptions = class_options_for($currentUser);
|
||
$ownClasses = user_classes($currentUser);
|
||
|
||
$status = (string) ($_GET['status'] ?? 'active');
|
||
if (!in_array($status, RAID_STATUSES, true)) {
|
||
$status = 'active';
|
||
}
|
||
|
||
$raids = [];
|
||
$apiError = null;
|
||
// IDs der Raids im anderen Bereich - ein Link wie /raids.php#raid-123 (z.B. aus dem Discord) springt dorthin
|
||
$otherAreaIds = [];
|
||
|
||
try {
|
||
$allRaids = fetch_raids($status);
|
||
$raids = raids_in_area($allRaids, $area);
|
||
if ($otherArea !== null) {
|
||
$otherAreaIds = array_map(static fn (array $raid): int => (int) ($raid['raid_id'] ?? 0), raids_in_area($allRaids, $otherArea));
|
||
}
|
||
} catch (Throwable $e) {
|
||
$apiError = $e->getMessage();
|
||
}
|
||
|
||
// Automatische Lumipunkte fuer inzwischen archivierte Raids (auch im Discord archivierte).
|
||
foreach (raid_process_auto_points($apiError ? null : $raids) as $autoMessage) {
|
||
if ($autoMessage !== '' && $canManageRaids) {
|
||
set_flash('info', $autoMessage);
|
||
}
|
||
}
|
||
try {
|
||
$raidSettings = raid_settings_all();
|
||
} catch (PDOException $e) {
|
||
$raidSettings = [];
|
||
}
|
||
// Raid-Lead und Lumipunkte in den Discord-Nachrichten nachziehen, wo sie fehlen (z.B. aeltere Raids).
|
||
// Hat der Bot dabei eine geloeschte Nachricht neu gepostet, gibt es neue IDs - dann frisch laden.
|
||
if ($apiError === null && $status !== 'archived' && raid_sync_extras($raids, $raidSettings)) {
|
||
try {
|
||
$raids = raids_in_area(fetch_raids($status), $area);
|
||
$raidSettings = raid_settings_all();
|
||
} catch (Throwable $e) {
|
||
$apiError = $e->getMessage();
|
||
}
|
||
}
|
||
|
||
// Premades fuer das Anlegen und fuers Einladen in eigene (Raid-Lead) bzw. alle Raids (Leitung)
|
||
$premades = [];
|
||
// Premades gibt es nur in der Legion - nicht bei den Raids der Elyos Allianz
|
||
if ($canCreateRaids && $area !== 'consilium') {
|
||
try {
|
||
// Versteckte Premades nur fuer ihre eigenen Leute und die Leitung (premade_visible_to)
|
||
// Kuerzer warten als sonst: ohne die Liste fehlt nur die Premade-Auswahl im Formular
|
||
$premades = premades_visible_to(fetch_premades(5), (int) ($currentUser['discord_id'] ?? 0));
|
||
} catch (Throwable $e) {
|
||
$premades = [];
|
||
}
|
||
}
|
||
|
||
// Vorlagen fuer "Neuen Raid erstellen" (includes/raid_templates.php)
|
||
// Nur fuer die Raid-Leitung - wer nur Raids erstellen darf, sieht keine Vorlagen
|
||
$showRaidTemplates = $canCreateRaids && raid_templates_allowed($area);
|
||
$raidTemplates = [];
|
||
if ($showRaidTemplates) {
|
||
try {
|
||
$raidTemplates = raid_templates_for_area($area);
|
||
} catch (PDOException $e) {
|
||
$raidTemplates = [];
|
||
}
|
||
}
|
||
|
||
$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">
|
||
<div class="raid-header">
|
||
<h1>Raids</h1>
|
||
<?php if ($canCreateRaids): ?>
|
||
<button type="button" class="button" id="raid-create-toggle">+ Neuer Raid</button>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php $areaQuery = $area === $areas[0] ? '' : '&bereich=' . $area; ?>
|
||
<?php if ($otherArea !== null): ?>
|
||
<nav class="members-segment page-tabs" aria-label="Bereiche">
|
||
<a href="/raids.php?status=<?= e($status) ?>" class="<?= $area === 'legion' ? 'active' : '' ?>">Legion</a>
|
||
<a href="/raids.php?status=<?= e($status) ?>&bereich=consilium" class="<?= $area === 'consilium' ? 'active' : '' ?>"><?= icon('shield-check') ?> <?= e(CONSILIUM_NAME) ?></a>
|
||
</nav>
|
||
<?php endif; ?>
|
||
<p class="text-muted"><?= $area === 'consilium'
|
||
? 'Raids von ' . e(CONSILIUM_NAME) . ' - gemeinsam mit den verbündeten Legionen.' . (is_legion_member() ? ' Lumipunkte gibt es dafür nicht.' : '')
|
||
: 'Raid-Termine deiner Legion.' ?></p>
|
||
<div class="filter-tabs">
|
||
<?php foreach ($statusLabels as $value => $label): ?>
|
||
<a href="/raids.php?status=<?= e($value) ?><?= e($areaQuery) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php if (!$apiError && !empty($raids)): ?>
|
||
<div class="list-search-bar">
|
||
<label class="search-field">
|
||
<?= icon('search') ?>
|
||
<input type="search" id="raid-search" placeholder="Raid, Termin, Spieler oder Klasse suchen …" aria-label="Raids durchsuchen"
|
||
value="<?= e((string) ($_GET['q'] ?? '')) ?>">
|
||
</label>
|
||
<span class="list-search-count text-muted" id="raid-search-count"></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<p class="panel text-muted" id="raid-search-empty" hidden>Kein Raid passt zur Suche.</p>
|
||
|
||
<?php if ($canCreateRaids): ?>
|
||
<div class="panel" id="raid-create-panel" style="display:none;">
|
||
<h2>Neuen Raid erstellen</h2>
|
||
<?php if (!$canManageRaids): ?>
|
||
<p class="field-hint raid-lead-hint"><?= icon('crown') ?> Du wirst Raid-Lead dieses Raids: Du kannst ihn bearbeiten, Spieler verschieben, die Anwesenheit eintragen und ihn archivieren.</p>
|
||
<?php endif; ?>
|
||
<?php if ($area === 'consilium'): ?>
|
||
<p class="field-hint"><?= icon('shield-check') ?> Der Raid erscheint im Discord-Kanal von <?= e(CONSILIUM_NAME) ?> und hier in diesem Bereich - für die verbündeten Legionen. Lumipunkte gibt es dafür nicht.</p>
|
||
<?php endif; ?>
|
||
<form id="raid-create-form">
|
||
<input type="hidden" name="bereich" value="<?= e($area) ?>">
|
||
<?php if ($showRaidTemplates): ?>
|
||
<div class="raid-template-bar" data-templates='<?= e(json_encode($raidTemplates, JSON_UNESCAPED_UNICODE)) ?>'>
|
||
<label for="raid-template-select">Vorlage</label>
|
||
<div class="raid-template-controls">
|
||
<select id="raid-template-select">
|
||
<option value="">– Vorlage laden –</option>
|
||
</select>
|
||
<button type="button" class="icon-button icon-button-danger raid-template-delete" title="Vorlage löschen" hidden><?= icon('trash') ?></button>
|
||
<button type="button" class="button-secondary raid-template-save">Als Vorlage speichern</button>
|
||
</div>
|
||
<p class="field-hint">Eine Vorlage füllt Titel, Uhrzeit, Plätze, Gearscore, Anforderungen<?= $area === 'consilium' ? '' : ', Lumipunkte' ?> und die Gruppen samt Sperren aus – das Datum wählst du selbst. Gespeichert wird der aktuelle Stand des Formulars, ohne Premades. Die Vorlagen sieht nur die Raid-Leitung.</p>
|
||
</div>
|
||
<?php endif; ?>
|
||
<div class="raid-edit-grid">
|
||
<div>
|
||
<label>Titel</label>
|
||
<input type="text" name="title" placeholder="z. B. Zauberreum HM" maxlength="60" required>
|
||
</div>
|
||
<div>
|
||
<label>Datum & Uhrzeit</label>
|
||
<input type="datetime-local" name="date_local" required>
|
||
</div>
|
||
<div>
|
||
<label>Max. Spieler</label>
|
||
<input type="number" name="max_slots" value="<?= RAID_GROUP_SIZE ?>" min="1" max="<?= RAID_GROUP_SIZE ?>" step="1" inputmode="numeric" required>
|
||
</div>
|
||
<div>
|
||
<label>Gearscore</label>
|
||
<input type="text" name="gearscore" placeholder="optional, z. B. 2.100" maxlength="6" inputmode="numeric" pattern="[0-9. ]{1,6}" title="Nur Zahlen, z. B. 2.100">
|
||
</div>
|
||
</div>
|
||
<div class="raid-edit-requirements">
|
||
<label>Anforderungen</label>
|
||
<textarea name="requirements" rows="4" placeholder="Setup / Rollenvorgabe, gern mehrzeilig" maxlength="500" required></textarea>
|
||
</div>
|
||
<?php if ($area === 'consilium'): ?>
|
||
<?php // Consilium-Raids bringen keine Lumipunkte - nichts 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="<?= RAID_POINTS_DEFAULT_PRESENT ?>">
|
||
</div>
|
||
<div>
|
||
<label>Abzug für Abwesende</label>
|
||
<input type="number" name="points_absent" min="0" max="<?= RAID_POINTS_MAX ?>" step="1" value="<?= RAID_POINTS_DEFAULT_ABSENT ?>">
|
||
</div>
|
||
<p class="field-hint">Wird beim Archivieren automatisch vergeben - außer es wurden vorher schon Punkte für den Raid verteilt. Ohne Anwesenheitsliste bekommen alle in den Gruppen die Punkte, einen Abzug gibt es dann nicht. Standard: +<?= RAID_POINTS_DEFAULT_PRESENT ?> pro Teilnahme, höchstens <?= RAID_POINTS_MAX ?>; 0 = keine Automatik.</p>
|
||
</div>
|
||
<?php else: ?>
|
||
<?php [$defaultPresent, $defaultAbsent] = raid_points_defaults_for_creator(); ?>
|
||
<p class="field-hint raid-points-fixed"><?= contribution_coin(15) ?> <?= e(raid_points_summary($defaultPresent, $defaultAbsent)) ?> – die Werte legt die Legionsleitung fest.</p>
|
||
<?php endif; ?>
|
||
<?php
|
||
$premadeOptions = array_map(static fn (array $p): array => ['id' => (int) ($p['id'] ?? 0), 'name' => (string) ($p['name'] ?? ''),
|
||
'hidden' => premade_is_hidden($p)], $premades);
|
||
?>
|
||
<div class="group-editor" data-max-groups="<?= RAID_MAX_GROUPS ?>" data-group-size="<?= RAID_GROUP_SIZE ?>"
|
||
<?php if (!empty($premadeOptions)): ?>data-premades='<?= e(json_encode($premadeOptions, JSON_UNESCAPED_UNICODE)) ?>'<?php endif; ?>>
|
||
<label>Gruppen</label>
|
||
<p class="field-hint">Jede Gruppe hat <?= RAID_GROUP_SIZE ?> Plätze (1 Tank, 1 Heiler, 3 DPS) und füllt sich über die Anmeldungen. In eine gesperrte Gruppe (Schloss) kann sich niemand selbst eintragen – dort teilst du ein.<?php if (!empty($premadeOptions)): ?> Eine feste Premade kannst du direkt einer Gruppe zuordnen – die Gruppe heißt dann wie die Premade, wird gesperrt und die Mitglieder bekommen eine Einladung per Discord-PN.<?php endif; ?></p>
|
||
<div class="group-editor-rows">
|
||
<div class="group-editor-row">
|
||
<input type="text" class="group-editor-name" value="Gruppe 1" placeholder="Gruppenname">
|
||
<label class="group-editor-lock" title="Gruppe sperren">
|
||
<input type="checkbox" class="group-editor-lock-checkbox">
|
||
<?= icon('lock') ?>
|
||
</label>
|
||
<button type="button" class="icon-button group-editor-remove" title="Gruppe entfernen"><?= icon('x') ?></button>
|
||
</div>
|
||
</div>
|
||
<button type="button" class="button-secondary group-editor-add">+ Gruppe hinzufügen</button>
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit">Raid erstellen</button>
|
||
<span class="raid-create-feedback text-muted"></span>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?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 id="raid-list" data-status="<?= e($status) ?>" data-area="<?= e($area) ?>">
|
||
<div class="panel">
|
||
<p class="text-muted"><?= e($emptyLabels[$status]) ?></p>
|
||
</div>
|
||
</div>
|
||
<?php else: ?>
|
||
<?php
|
||
$cardContext = [
|
||
'status' => $status,
|
||
'current_discord_id' => $currentDiscordId,
|
||
'current_user_id' => (int) $currentUser['id'],
|
||
'can_manage' => $canManageRaids,
|
||
'can_set_points' => $canSetRaidPoints,
|
||
'settings' => $raidSettings,
|
||
'premades' => $premades,
|
||
'premade_banners' => premade_banners_by_name(),
|
||
'new_since' => $raidsNewSince,
|
||
'area' => $area,
|
||
];
|
||
?>
|
||
<div id="raid-list" data-status="<?= e($status) ?>" data-area="<?= e($area) ?>">
|
||
<?php foreach ($raids as $raid): ?>
|
||
<?php render_raid_card($raid, $cardContext); ?>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<!-- Gemeinsames Anmelde-Popup fuer alle Raids auf dieser Seite -->
|
||
<div id="raid-signup-modal" class="modal-overlay" data-main-class="<?= e((string) ($currentUser['class_name'] ?? '')) ?>" hidden>
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2>Zum Raid anmelden</h2>
|
||
<p class="text-muted">Wähle deine Klasse. Die Gruppe ist optional – ohne Auswahl teilt der Bot dich automatisch sinnvoll ein.</p>
|
||
<div class="class-picker">
|
||
<?php foreach ($classOptions as $classOption): ?>
|
||
<?php $isOwnClass = in_array($classOption, $ownClasses, true); ?>
|
||
<button type="button" class="class-picker-option<?= $isOwnClass ? ' is-own' : '' ?>" data-class="<?= e($classOption) ?>">
|
||
<?php if ($classOption === ($ownClasses[0] ?? null)): ?><span class="class-picker-tag">Main</span><?php endif; ?>
|
||
<span class="class-icon-frame"><img src="<?= e(class_icon_url($classOption)) ?>" alt=""></span>
|
||
<span class="class-picker-label"><?= e($classOption) ?></span>
|
||
</button>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div>
|
||
<label>Wunschgruppe (optional)</label>
|
||
<div class="group-picker" id="raid-signup-group-picker"></div>
|
||
</div>
|
||
<div id="raid-signup-feedback" class="raid-modal-feedback"></div>
|
||
<div class="actions">
|
||
<button type="button" id="raid-signup-confirm">Anmelden</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script src="<?= e(asset_url('/assets/js/raids.js')) ?>"></script>
|
||
<script src="<?= e(asset_url('/assets/js/raid-search.js')) ?>"></script>
|
||
<?php if ($otherAreaIds): ?>
|
||
<script>
|
||
// Link auf einen Raid im anderen Bereich (z.B. /raids.php#raid-123 aus dem Discord): dorthin wechseln
|
||
(function () {
|
||
var match = /^#raid-(\d+)$/.exec(location.hash);
|
||
var other = <?= json_encode(array_map('strval', $otherAreaIds)) ?>;
|
||
if (match && !document.getElementById('raid-' + match[1]) && other.indexOf(match[1]) !== -1) {
|
||
location.replace('/raids.php?status=<?= e($status) ?><?= $otherArea === $areas[0] ? '' : '&bereich=' . e((string) $otherArea) ?>' + location.hash);
|
||
}
|
||
})();
|
||
</script>
|
||
<?php endif; ?>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|