Two changes to the raid editor (raids.php/raids.js): - Moving a member via drag&drop no longer reloads the page. It now patches the DOM in place (moves the list item, updates each group's member count/empty-state, and adjusts the header's "X / Y angemeldet" badge when bench vs. a real group is involved), so the editor panel stays open and multiple members can be reshuffled without re-entering edit mode each time. The form's own "Speichern" still reloads on success, since that's the point where the edit is actually committed. - Replaces the single comma-separated "Gruppennamen" text field and the separate "Gruppen sperren" checkbox grid with one row per group (name input + inline lock toggle + remove button), plus a "+ Gruppe hinzufügen" button to append a new row. Group names and locked_groups are now read from these rows on submit instead of parsing a comma-separated string. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
355 lines
18 KiB
PHP
355 lines
18 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/raids_api.php';
|
||
require_permission('raids.view');
|
||
|
||
function render_signup_list(array $members, bool $draggable): 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; ?>
|
||
<?= 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();
|
||
}
|
||
|
||
$premades = [];
|
||
if ($canManageRaids) {
|
||
try {
|
||
$premades = fetch_premades();
|
||
} catch (Throwable $e) {
|
||
$premades = [];
|
||
}
|
||
}
|
||
|
||
$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
|
||
$raidId = (int) ($raid['raid_id'] ?? 0);
|
||
$title = (string) ($raid['title'] ?? 'Raid');
|
||
$dateRaw = (string) ($raid['date'] ?? '');
|
||
$dateLabel = $dateRaw;
|
||
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;
|
||
$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'] ?? '')))));
|
||
$canEditThis = $canManageRaids && !$isArchived;
|
||
|
||
// 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++;
|
||
}
|
||
}
|
||
}
|
||
|
||
$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' : '' ?>"
|
||
data-raid-id="<?= $raidId ?>"
|
||
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 ?? '' ?>">
|
||
<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 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): ?>
|
||
<?php if ($isArchived): ?>
|
||
<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="text-button">Wiederherstellen</button>
|
||
</form>
|
||
<form method="post" action="/raid_delete_action.php" class="inline-form" onsubmit="return confirm('Diesen Raid wirklich ENDGÜLTIG löschen? Das kann nicht rückgängig gemacht werden.');">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="raid_id" value="<?= $raidId ?>">
|
||
<input type="hidden" name="status" value="<?= e($status) ?>">
|
||
<button type="submit" class="text-button">Endgültig löschen</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="<?= $raidId ?>">
|
||
<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 ($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) ?>">
|
||
</div>
|
||
<div>
|
||
<label>Datum & Uhrzeit</label>
|
||
<input type="text" name="date_raw" value="<?= e($dateRaw) ?>" placeholder="TT.MM.JJJJ HH:MM">
|
||
</div>
|
||
<div>
|
||
<label>Max. Spieler</label>
|
||
<input type="text" name="max_slots" value="<?= (int) $maxSlots ?>">
|
||
</div>
|
||
<div>
|
||
<label>Gearscore</label>
|
||
<input type="text" name="gearscore" value="<?= e($gearscore) ?>">
|
||
</div>
|
||
<div>
|
||
<label>Anforderungen</label>
|
||
<input type="text" name="requirements" value="<?= e($requirements) ?>">
|
||
</div>
|
||
</div>
|
||
<div class="group-editor">
|
||
<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); ?>
|
||
<div class="raid-group raid-drop-zone<?= $isLockedGroup ? ' raid-group-locked' : '' ?>" data-group="<?= $index + 1 ?>" data-locked="<?= $isLockedGroup ? '1' : '0' ?>">
|
||
<h3><?= 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); ?>
|
||
<?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); ?>
|
||
<?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($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: ?>
|
||
<button type="button" class="button raid-open-signup">Anmelden</button>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
|
||
<!-- Gemeinsames Anmelde-Popup fuer alle Raids auf dieser Seite -->
|
||
<div id="raid-signup-modal" class="modal-overlay" 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): ?>
|
||
<button type="button" class="class-picker-option" data-class="<?= e($classOption) ?>">
|
||
<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="/assets/js/raids.js"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|