LuminaWebsite/premades.php
Maaxxs a7efc668f7 Premades: members may lead up to three premades instead of one
Asked for: "das limit für leitung in einer premade soll bei standard leuten von 1 auf 3 gehoben werden".

- includes/raids_api.php: PREMADE_LEAD_MAX = 3 and premade_may_lead_another() - fewer than three led premades, or
  premades.lead_multiple for any number.
- premade_action.php: founding (for oneself or by the leadership with a lead) and "Leitung übertragen" use it; for
  a transfer the website tells the bot allow_multiple_lead, since the bot only knows "no other" or "any".
- premades.php: founding form, lead picker and transfer candidates follow the same rule; texts name the limit.
- premades.lead_multiple now means more than three (description in includes/permissions.php, synced on the next
  page view). Patch notes and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 01:43:04 +02:00

880 lines
65 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_once __DIR__ . '/includes/premade_banner.php';
require_once __DIR__ . '/includes/premade_applications.php';
require_once __DIR__ . '/includes/premade_order.php';
require_permission('premades.view');
$user = current_user();
$discordId = $user['discord_id'] ? (int) $user['discord_id'] : null;
$canManage = user_has_permission('premades.manage');
$premades = [];
$apiError = null;
try {
$premades = fetch_premades();
// Banner aufgeloester Premades aufraeumen, Namen fuer die Raid-Gruppen aktuell halten - ebenso die Bewerbungen
premade_banners_sync($premades);
premade_applications_sync($premades);
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
$banners = premade_banners_all();
// Bewerbungen (includes/premade_applications.php): offene je Premade fuer Lead und Leitung, die eigenen, abgeschaltete
$openApplications = premade_applications_open();
$myApplications = premade_applications_of((int) $user['id']);
$closedApplications = premade_applications_closed();
// In der Reihenfolge der Legionsleitung (includes/premade_order.php) sieht jeder die Seite beim Aufruf - ihr Platz
// steht an jeder Karte, damit die Sortierung oben zu ihr zurueckfindet
$premades = premade_order_sort($premades, premade_order_positions());
$standardRank = array_flip(array_map(static fn (array $p): int => (int) ($p['id'] ?? 0), $premades));
// Klasse vorauswaehlen, wo noch keine feststeht (z.B. im Discord beigetreten): die Main-Klasse laut
// Discord-Rollen. Das passiert einmal - danach steht sie in der Premade und laesst sich im eigenen
// Platz wechseln.
foreach ($premades as $pi => $p) {
foreach ($p['members'] ?? [] as $mi => $m) {
$memberId = (int) ($m['user_id'] ?? 0);
if ((string) ($m['class'] ?? '') !== '' || $memberId <= 0 || ($default = premade_default_class($memberId)) === null) {
continue;
}
try {
set_premade_member_class((int) $p['id'], $memberId, $default);
} catch (Throwable $e) {
break 2; // Bot antwortet nicht - dann beim naechsten Aufruf
}
$premades[$pi]['members'][$mi]['class'] = $default;
if ($memberId === (int) ($p['owner_id'] ?? 0)) {
$premades[$pi]['owner_class'] = $default;
}
}
}
// Alle vorkommenden Discord-IDs (Owner + Mitglieder) auf Website-Accounts abbilden,
// damit echte Anzeigenamen statt roher Discord-IDs gezeigt werden koennen.
$allDiscordIds = [];
foreach ($premades as $p) {
$allDiscordIds[] = (int) ($p['owner_id'] ?? 0);
foreach ($p['members'] ?? [] as $m) {
$allDiscordIds[] = (int) ($m['user_id'] ?? 0);
}
}
$allDiscordIds = array_values(array_unique(array_filter($allDiscordIds)));
$namesByDiscordId = [];
$linkedUsersByDiscordId = [];
if (!empty($allDiscordIds)) {
$placeholders = implode(',', array_fill(0, count($allDiscordIds), '?'));
$stmt = db()->prepare("SELECT id, discord_id, username, discord_username, display_name, avatar_filename, class_name FROM users WHERE discord_id IN ($placeholders)");
$stmt->execute($allDiscordIds);
foreach ($stmt->fetchAll() as $row) {
$name = $row['display_name'] !== '' ? $row['display_name'] : $row['discord_username'];
$namesByDiscordId[(int) $row['discord_id']] = $name;
$linkedUsersByDiscordId[(int) $row['discord_id']] = $row;
}
}
// Suche nach Spielern (assets/js/premades.js): je Platz der angezeigte Name, dazu Website- und Discord-Name und die
// Namen der Charaktere
try {
$charactersByUser = profile_characters_by_user();
} catch (PDOException $e) {
$charactersByUser = [];
}
$playerSearchText = static function (int $playerId, string $shownName) use ($linkedUsersByDiscordId, $charactersByUser): string {
$names = [$shownName];
if ($linked = $linkedUsersByDiscordId[$playerId] ?? null) {
array_push($names, (string) $linked['display_name'], (string) $linked['discord_username'], (string) $linked['username']);
foreach ($charactersByUser[(int) $linked['id']] ?? [] as $character) {
$names[] = (string) $character['name'];
}
}
return mb_strtolower(implode(' ', array_unique(array_filter($names, static fn (string $name): bool => $name !== ''))));
};
$myPendingInvites = $discordId ? find_my_pending_invites($premades, $discordId) : [];
// Leiten kann man bis zu PREMADE_LEAD_MAX Premades - mit premades.lead_multiple mehr. Mitglied sein in beliebig vielen.
$mayLeadAnother = static fn (int $id): bool => premade_may_lead_another($premades, $id);
$mayLeadMultiple = $discordId !== null && premade_may_lead_multiple($discordId);
// Alle verknuepften Konten fuer das Einladen-Popup - welche davon pro Gruppe infrage kommen,
// entscheidet premade_invite_candidates().
$inviteCandidates = db()->query("SELECT id, discord_id, discord_username, display_name, avatar_filename FROM users WHERE discord_id IS NOT NULL AND status = 'active' ORDER BY display_name, username")->fetchAll();
/**
* Discord-IDs, die in diese Premade eingeladen bzw. eingeteilt werden koennen: jeder, der noch nicht
* drin ist - Mitglied sein kann man in mehreren Premades.
*
* @return array<int, int>
*/
function premade_invite_candidates(array $premade, array $inviteCandidates): array
{
$ids = [];
foreach ($inviteCandidates as $row) {
$id = (int) $row['discord_id'];
if (!premade_has_user($premade, $id)) {
$ids[] = $id;
}
}
return $ids;
}
$pageTitle = 'Premades';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<h1>Premades</h1>
<p class="text-muted">Feste Gruppen für Raids: fünf Plätze und eine Reserve. Mitglied sein kannst du in beliebig vielen Premades, leiten <?= $mayLeadMultiple ? 'darfst du auch mehr als ' . PREMADE_LEAD_MAX : 'kannst du bis zu ' . PREMADE_LEAD_MAX ?>.</p>
</div>
<?php if ($apiError): ?>
<div class="panel">
<div class="flash flash-error">Premades konnten nicht geladen werden: <?= e($apiError) ?></div>
</div>
<?php else: ?>
<?php if (!empty($myPendingInvites)): ?>
<div class="panel">
<h2>Meine Einladungen</h2>
<?php foreach ($myPendingInvites as $invite): ?>
<?php
$inviteReserve = false;
foreach ($invite['members'] ?? [] as $m) {
if ((int) ($m['user_id'] ?? 0) === $discordId) {
$inviteReserve = !empty($m['reserve']);
}
}
?>
<div class="premade-invite-row">
<div>
Einladung zu <strong><?= e((string) ($invite['name'] ?? '')) ?></strong>
von <?= e(premade_name_for((int) ($invite['owner_id'] ?? 0), $namesByDiscordId, $invite['owner_name'] ?? null)) ?>
<?php if ($inviteReserve): ?><span class="text-muted">- dein Platz ist die Reserve</span><?php endif; ?>
</div>
<div class="actions">
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="accept">
<input type="hidden" name="premade_id" value="<?= (int) ($invite['id'] ?? 0) ?>">
<button type="submit">Annehmen</button>
</form>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="decline">
<input type="hidden" name="premade_id" value="<?= (int) ($invite['id'] ?? 0) ?>">
<button type="submit" class="button-secondary">Ablehnen</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($myApplications)): ?>
<div class="panel">
<h2>Meine Bewerbungen</h2>
<?php foreach ($myApplications as $application): ?>
<?php
$applicationStatus = (string) $application['status'];
$applicationState = match ($applicationStatus) {
'open' => '⏳ Wartet auf eine Antwort',
'accepted' => '✅ Angenommen – du bist dabei',
'declined' => '❌ Abgelehnt' . ((string) ($application['reason'] ?? '') !== '' ? ': ' . $application['reason'] : ''),
'withdrawn' => 'Zurückgezogen',
default => 'Erledigt – die Premade wurde aufgelöst',
};
?>
<div class="premade-invite-row">
<div>
Bewerbung bei
<?php if (in_array($applicationStatus, ['open', 'accepted'], true)): ?>
<a href="#premade-<?= (int) $application['premade_id'] ?>"><strong><?= e((string) $application['premade_name']) ?></strong></a>
<?php else: ?>
<strong><?= e((string) $application['premade_name']) ?></strong>
<?php endif; ?>
<?php if (!empty($application['class_name'])): ?><span class="text-muted">als <?= e((string) $application['class_name']) ?></span><?php endif; ?>
<?php if (!empty($application['reserve'])): ?><span class="premade-application-reserve" title="Bewerbung für den Reserveplatz">Reserve</span><?php endif; ?>
<span class="text-muted">· <?= e(date('d.m.', (int) strtotime((string) $application['created_at']))) ?></span>
<div class="premade-application-state is-<?= e($applicationStatus) ?>"><?= e($applicationState) ?></div>
</div>
<?php if ($applicationStatus === 'open'): ?>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="withdraw">
<input type="hidden" name="application_id" value="<?= (int) $application['id'] ?>">
<button type="submit" class="button-secondary button-small">Zurückziehen</button>
</form>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
// Mitglieder gruenden fuer sich selbst, solange sie weniger als PREMADE_LEAD_MAX Premades leiten (mehr nur
// mit premades.lead_multiple). Die Leitung (premades.manage) gruendet beliebig viele Gruppen - ohne Lead
// oder mit einem Lead, der noch eine leiten darf.
$canFoundSelf = $discordId && $mayLeadAnother($discordId);
$leadItems = [];
if ($canManage) {
foreach (member_picker_rows() as $row) {
if (!empty($row['discord_id']) && $mayLeadAnother((int) $row['discord_id'])) {
$leadItems[] = member_picker_item($row, 'discord_id');
}
}
}
?>
<?php if ($canFoundSelf || $canManage): ?>
<div class="panel">
<h2>Neue Premade gründen</h2>
<?php if ($canManage): ?>
<p class="text-muted">Als Leitung kannst du beliebig viele Gruppen anlegen. Ohne Auswahl entsteht die Gruppe ohne Lead - Spieler teilst du danach über die freien Plätze ein. Einen Lead kannst du später aus den Mitgliedern bestimmen.</p>
<?php endif; ?>
<form method="post" action="/premade_action.php" class="raid-premade-row">
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<input type="text" name="name" placeholder="Name der Premade-Gruppe" minlength="<?= PREMADE_NAME_MIN ?>" maxlength="<?= PREMADE_NAME_MAX ?>" required style="width:auto;flex:1;min-width:200px;">
<?php if ($canManage): ?>
<?= member_picker('lead_id', 'premade-lead-list', $leadItems, [
'input_id' => 'premade-lead-search',
'placeholder' => 'Lead (optional) …',
]) ?>
<?php endif; ?>
<button type="submit">Gründen</button>
</form>
</div>
<?php elseif (!$discordId): ?>
<div class="panel">
<p class="text-muted">Verknüpfe deinen <a href="/profile.php">Discord-Account</a>, um eine Premade zu gründen oder beizutreten.</p>
</div>
<?php endif; ?>
<?php if (empty($premades)): ?>
<div class="panel">
<p class="text-muted">Aktuell gibt es keine Premade-Gruppen.</p>
</div>
<?php else: ?>
<?php if (count($premades) > 1): ?>
<?php
// Suche nach Spielern und Sortierung (assets/js/premades.js; Suchbegriff und Sortierung stehen in der Adresse,
// beim Aufruf ueber das Menue gilt also immer die Standard-Reihenfolge, die die Legionsleitung darunter per
// Drag & Drop festlegt - assets/js/tag-order.js). Ohne JavaScript bleibt es bei ihr.
?>
<div class="panel premade-toolbar" hidden>
<div class="list-search-bar">
<label class="search-field">
<?= icon('search') ?>
<input type="search" id="premade-search" placeholder="Spieler oder Premade suchen …" aria-label="Premades nach Spielern durchsuchen"
value="<?= e(is_string($_GET['q'] ?? null) ? $_GET['q'] : '') ?>">
</label>
<span class="list-search-count text-muted" id="premade-search-count"></span>
</div>
<div class="members-filter-row">
<span class="members-filter-label"><?= icon('sort') ?> Sortieren</span>
<div class="members-chips" id="premade-sort" role="group" aria-label="Premades sortieren">
<button type="button" class="members-chip" data-value="oldest" title="In der Reihenfolge, in der sie gegründet wurden">Älteste</button>
<button type="button" class="members-chip" data-value="newest" title="Zuletzt gegründet zuerst">Neueste</button>
<button type="button" class="members-chip" data-value="name">Name</button>
<button type="button" class="members-chip" data-value="free" title="Die meisten freien Plätze in der Gruppe zuerst, dann ein freier Reserveplatz">Freie Plätze</button>
<button type="button" class="members-chip" data-value="members" title="Die meisten Mitglieder zuerst">Mitglieder</button>
</div>
</div>
<p class="field-hint premade-toolbar-hint">Ohne Auswahl stehen die Premades in der Reihenfolge der Legionsleitung – ein zweiter Klick hebt eine Sortierung wieder auf.</p>
<?php if ($canManage): ?>
<details class="premade-order">
<summary><?= icon('sort') ?> Standard-Reihenfolge festlegen</summary>
<p class="field-hint">In dieser Reihenfolge stehen die Premades für alle, die die Seite aufrufen. Zum Verschieben eine Premade am Griff (⠿) ziehen oder die Pfeile nutzen, dann speichern. Neu gegründete Premades stehen hinten, bis ihr sie einordnet.</p>
<form method="post" action="/premade_action.php" data-tag-order>
<?= csrf_field() ?>
<input type="hidden" name="action" value="order">
<ol class="tag-order-list">
<?php foreach ($premades as $i => $orderPremade): ?>
<?php
$orderName = (string) ($orderPremade['name'] ?? '');
$orderOwner = (int) ($orderPremade['owner_id'] ?? 0);
?>
<li class="tag-order-item">
<input type="hidden" name="order[]" value="<?= (int) $orderPremade['id'] ?>">
<span class="tag-order-handle" title="Ziehen zum Verschieben" aria-hidden="true">⠿</span>
<span class="premade-order-name"><?= e($orderName) ?></span>
<span class="tag-order-name text-muted"><?= $orderOwner > 0 ? 'Lead: ' . e(premade_name_for($orderOwner, $namesByDiscordId, $orderPremade['owner_name'] ?? null)) : 'ohne Lead' ?></span>
<span class="tag-order-move">
<button type="button" class="icon-button tag-order-up" data-move="up" title="Nach oben" aria-label="<?= e($orderName) ?> nach oben"<?= $i === 0 ? ' disabled' : '' ?>><?= icon('chevron-down') ?></button>
<button type="button" class="icon-button" data-move="down" title="Nach unten" aria-label="<?= e($orderName) ?> nach unten"<?= $i === count($premades) - 1 ? ' disabled' : '' ?>><?= icon('chevron-down') ?></button>
</span>
</li>
<?php endforeach; ?>
</ol>
<div class="actions">
<button type="submit">Reihenfolge speichern</button>
<span class="text-muted" data-tag-order-status hidden>Noch nicht gespeichert</span>
</div>
</form>
</details>
<?php endif; ?>
</div>
<p class="panel text-muted" id="premade-search-empty" hidden>Keine Premade passt zur Suche.</p>
<?php endif; ?>
<div id="premade-list">
<?php foreach ($premades as $premade): ?>
<?php
$premadeId = (int) ($premade['id'] ?? 0);
$premadeName = (string) ($premade['name'] ?? '');
$ownerId = (int) ($premade['owner_id'] ?? 0);
$members = is_array($premade['members'] ?? null) ? $premade['members'] : [];
$accepted = array_filter($members, fn ($m) => ($m['status'] ?? '') === 'accepted' && (int) ($m['user_id'] ?? 0) !== $ownerId);
$canManageThis = $canManage || ($discordId !== null && $ownerId === $discordId);
$memberCount = count($accepted) + ($ownerId > 0 ? 1 : 0);
$candidateIds = $canManageThis ? premade_invite_candidates($premade, $inviteCandidates) : [];
[$mainCount, $reserveCount] = premade_slot_counts($premade);
$mainFree = $mainCount < PREMADE_MAIN_SLOTS;
$reserveFree = $reserveCount < PREMADE_RESERVE_SLOTS;
$banner = $banners[$premadeId] ?? null;
$hasBanner = $banner !== null && $banner['url'] !== null;
// Offene Bewerbungen zum Entscheiden - ohne die eigene (bewirbt sich die Leitung selbst, entscheidet der
// Lead bzw. jemand anderes aus der Leitung)
$premadeApplications = $canManageThis ? array_values(array_filter($openApplications[$premadeId] ?? [],
static fn (array $application): bool => (int) $application['discord_id'] !== (int) $discordId)) : [];
$applicationsClosed = isset($closedApplications[$premadeId]);
$slots = build_premade_slots($premade, $namesByDiscordId);
// Suchtext je besetztem Platz (Lead, Mitglieder, Reserve, offene Einladungen) - die Karte findet man dazu ueber ihren Namen
$slotSearch = [];
foreach ($slots as $slot) {
if ($slot['type'] !== 'empty') {
$slotSearch[(int) $slot['id']] = $playerSearchText((int) $slot['id'], (string) $slot['name']);
}
}
?>
<?php // data-sort-*: Werte fuer die Sortierung oben (Platz in der Standard-Reihenfolge, freie Plaetze in Gruppe bzw. Reserve), data-search fuer die Suche ?>
<div class="panel premade-panel<?= $hasBanner ? ' has-banner' : '' ?>" id="premade-<?= $premadeId ?>" data-premade-id="<?= $premadeId ?>"
data-sort-name="<?= e($premadeName) ?>" data-sort-members="<?= $memberCount ?>" data-sort-free="<?= max(0, PREMADE_MAIN_SLOTS - $mainCount) ?>"
data-sort-reserve="<?= max(0, PREMADE_RESERVE_SLOTS - $reserveCount) ?>" data-sort-default="<?= $standardRank[$premadeId] ?? 0 ?>"
data-search="<?= e(mb_strtolower($premadeName) . ' ' . implode(' ', $slotSearch)) ?>">
<?php if ($hasBanner): ?><div class="premade-banner" style="<?= premade_banner_style($banner) ?>"><?php endif; ?>
<div class="raid-header">
<h2>⚔️ <?= e($premadeName) ?></h2>
<div class="badge-group">
<?php if ($canManageThis): ?>
<button type="button" class="icon-button premade-edit-toggle" title="Premade bearbeiten" aria-pressed="false"><?= icon('edit') ?></button>
<?php endif; ?>
<?php if ($premadeApplications): ?>
<a class="badge badge-pending" href="#premade-applications-<?= $premadeId ?>" title="Offene Bewerbungen – unten annehmen oder ablehnen">📝 <?= count($premadeApplications) ?> <?= count($premadeApplications) === 1 ? 'Bewerbung' : 'Bewerbungen' ?></a>
<?php endif; ?>
<?php if ($ownerId <= 0): ?><span class="badge" title="Diese Gruppe hat noch keinen Lead">Ohne Lead</span><?php endif; ?>
<span class="badge"><?= $memberCount ?> <?= $memberCount === 1 ? 'Mitglied' : 'Mitglieder' ?></span>
</div>
</div>
<?php if ($hasBanner): ?></div><?php endif; ?>
<?php
// Fuenf Plaetze in der Gruppe (Lead zuerst) und als sechster die Reserve - freie Plaetze
// werden mit ausgegrauten Platzhaltern aufgefuellt. Im Bearbeiten-Modus lassen sich die
// Spieler per Drag & Drop zwischen Gruppe und Reserve verschieben und in der Gruppe umsortieren.
// ($slots steht schon oben, fuer die Suche)
$groupOrder = array_values(array_map(static fn (array $s): int => (int) $s['id'], array_filter($slots,
static fn (array $s): bool => empty($s['reserve']) && in_array($s['type'], ['accepted', 'pending'], true))));
$movableInGroup = count($groupOrder);
?>
<div class="premade-roster">
<?php foreach ($slots as $slot): ?>
<?php
$isReserveSlot = !empty($slot['reserve']);
$slotClass = 'premade-slot premade-slot-' . $slot['type'] . ($isReserveSlot ? ' premade-slot-reserve' : '');
$slotData = ' data-slot-reserve="' . ($isReserveSlot ? '1' : '0') . '"';
$reserveTag = $isReserveSlot ? '<span class="premade-reserve-tag" title="Ersatzbank: rückt nach, wenn in der Gruppe jemand fehlt">Reserve</span>' : '';
?>
<?php if ($slot['type'] === 'empty'): ?>
<?php
// Neue Spieler kommen zuerst in die Gruppe, dann auf die Reserve - das Plus
// der Reserve gibt es deshalb erst, wenn die Gruppe voll ist.
$isInvitable = $canManageThis && !empty($candidateIds) && (!$isReserveSlot || !$mainFree);
$isDropHint = $canManageThis && $isReserveSlot && !$isInvitable && $movableInGroup > 0;
?>
<div class="<?= $slotClass ?><?= $isInvitable ? ' premade-slot-invitable' : '' ?><?= $isDropHint ? ' premade-slot-droppable' : '' ?>" data-slot-empty<?= $slotData ?>>
<div class="premade-slot-inner">
<?= $reserveTag ?>
<?php if ($isInvitable): ?>
<button type="button" class="premade-slot-invite-btn premade-edit-only" data-premade-id="<?= $premadeId ?>" data-candidates="<?= e(implode(',', $candidateIds)) ?>" data-direct="<?= $canManage ? '1' : '0' ?>" data-reserve="<?= $mainFree ? '0' : '1' ?>" title="<?= $canManage ? 'Spieler einteilen' : 'Mitglied einladen' ?><?= $mainFree ? '' : ' (auf die Reserve)' ?>">+</button>
<span class="premade-slot-placeholder premade-view-only" title="Zum Einladen oben rechts den Bearbeiten-Modus öffnen">+</span>
<?php elseif ($isDropHint): ?>
<span class="premade-slot-placeholder premade-view-only">+</span>
<span class="premade-slot-drop-hint premade-edit-only">Mitglied hierher ziehen</span>
<?php elseif (!$canManageThis): ?>
<span class="premade-slot-placeholder" title="Nur der Leiter oder Verwalter kann hier einladen">+</span>
<?php elseif ($isReserveSlot && $mainFree): ?>
<span class="premade-slot-placeholder" title="Neue Spieler kommen erst auf die Reserve, wenn die Gruppe voll ist">+</span>
<?php else: ?>
<span class="premade-slot-placeholder" title="Aktuell gibt es keine einladbaren Mitglieder">+</span>
<?php endif; ?>
</div>
</div>
<?php else: ?>
<?php
$slotUser = premade_avatar_user((int) $slot['id'], $linkedUsersByDiscordId, $slot['name']);
$isMe = $discordId !== null && (int) $slot['id'] === $discordId;
$isLead = $slot['type'] === 'lead';
$isPending = $slot['type'] === 'pending';
$slotData .= ' data-search="' . e($slotSearch[(int) $slot['id']] ?? '') . '"';
if ($canManageThis && !$isLead) {
$slotData .= ' data-slot-user="' . (int) $slot['id'] . '"';
} elseif ($isLead) {
$slotData .= ' data-slot-lead';
}
?>
<div class="<?= $slotClass ?>"<?= $slotData ?>>
<div class="premade-slot-inner">
<?= $reserveTag ?>
<?= avatar_html($slotUser, 40) ?>
<div class="premade-slot-name">
<strong><?= $isPending ? '⏳ ' : '' ?><?= e($slot['name']) ?></strong>
<?php if ($isPending): ?>
<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 elseif ($isMe): ?>
<span class="text-muted">Keine Klasse gewählt</span>
<?php endif; ?>
</div>
<?php if ($isMe && !$isPending): ?>
<button type="button" class="icon-button premade-class-switch" data-premade-id="<?= $premadeId ?>" data-current-class="<?= e((string) ($slot['class'] ?? '')) ?>" title="<?= !empty($slot['class']) ? 'Klasse wechseln' : 'Klasse wählen' ?>" aria-label="<?= !empty($slot['class']) ? 'Klasse wechseln' : 'Klasse wählen' ?>"><?= icon('swap') ?></button>
<?php endif; ?>
<?php if ($isLead): ?>
<span class="premade-crown" title="Lead der Premade"><?= icon('crown') ?></span>
<?php elseif ($canManageThis): ?>
<?php
// Ohne Drag & Drop (z.B. am Handy): auf die Reserve setzen - ein Reservist
// tauscht dabei in die Gruppe - bzw. zurueck in die Gruppe holen.
if ($isReserveSlot) {
$moveTitle = $mainFree ? 'In die Gruppe holen' : 'Die Gruppe ist voll - setz stattdessen ein Mitglied auf die Reserve, dann tauschen die beiden';
} else {
$moveTitle = $reserveCount > 0 ? 'Auf die Reserve setzen (tauscht mit dem Reservisten)' : 'Auf die Reserve setzen';
}
// Reihenfolge in der Gruppe ohne Drag & Drop: einen Platz nach vorne bzw. hinten
$orderIndex = $isReserveSlot ? false : array_search((int) $slot['id'], $groupOrder, true);
?>
<div class="premade-slot-tools premade-edit-only">
<?php if ($orderIndex !== false && $movableInGroup > 1): ?>
<div class="premade-order-btns">
<?php foreach (['up' => ['Einen Platz nach vorne', 'chevron-up', $orderIndex === 0], 'down' => ['Einen Platz nach hinten', 'chevron-down', $orderIndex === $movableInGroup - 1]] as $direction => [$orderTitle, $orderIcon, $orderDisabled]): ?>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="reorder">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="user_id" value="<?= (int) $slot['id'] ?>">
<input type="hidden" name="direction" value="<?= $direction ?>">
<button type="submit" class="icon-button" title="<?= $orderTitle ?>" aria-label="<?= $orderTitle ?>"<?= $orderDisabled ? ' disabled' : '' ?>><?= icon($orderIcon) ?></button>
</form>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="move">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="user_id" value="<?= (int) $slot['id'] ?>">
<input type="hidden" name="reserve" value="<?= $isReserveSlot ? '0' : '1' ?>">
<button type="submit" class="icon-button premade-move-btn" title="<?= e($moveTitle) ?>" aria-label="<?= e($moveTitle) ?>"<?= $isReserveSlot && !$mainFree ? ' disabled' : '' ?>><?= icon('sort') ?></button>
</form>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="remove_member">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="user_id" value="<?= (int) $slot['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="<?= $isPending ? 'Einladung zurückziehen' : 'Aus der Premade entfernen' ?>"><?= icon('x') ?></button>
</form>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php if ($premadeApplications): ?>
<?php // Offene Bewerbungen: Lead und Leitung sehen sie auch ohne Bearbeiten-Modus ?>
<div class="premade-applications" id="premade-applications-<?= $premadeId ?>">
<h3>📝 Bewerbungen</h3>
<?php foreach ($premadeApplications as $application): ?>
<?php
$applicantId = (int) $application['discord_id'];
$applicantName = (string) $application['name'];
$applicantInvited = premade_has_user($premade, $applicantId);
$applicantWantsReserve = !empty($application['reserve']);
// Wohin "Aufnehmen" fuehrt: der gewuenschte Platz, ist der belegt der andere (null = alles voll)
$applicantTarget = premade_application_target($premade, $application);
$applicantBlocked = $applicantTarget === null;
$applicantWhere = match (true) {
$applicantTarget === true => ' kommt auf die Reserve' . (!$applicantInvited && !$applicantWantsReserve ? ' (die Gruppe ist voll)' : ''),
$applicantTarget === false => ' kommt in die Gruppe' . (!$applicantInvited && $applicantWantsReserve ? ' (die Reserve ist schon besetzt)' : ''),
default => '',
};
$applicationClass = (string) ($application['class_name'] ?? '');
?>
<div class="premade-application">
<?= avatar_html(['id' => (int) $application['user_id'], 'display_name' => $applicantName, 'username' => $applicantName, 'avatar_filename' => $application['avatar_filename']], 36) ?>
<div class="premade-application-body">
<div class="premade-application-head">
<strong><?= e($applicantName) ?></strong>
<?php if ($applicationClass !== ''): ?>
<span class="premade-slot-class">
<?php if ($applicationClassIcon = class_icon_url($applicationClass)): ?><img class="premade-slot-class-icon" src="<?= e($applicationClassIcon) ?>" alt=""><?php endif; ?>
<span class="text-muted"><?= e($applicationClass) ?></span>
</span>
<?php endif; ?>
<?php if ($applicantWantsReserve): ?>
<span class="premade-application-reserve" title="Bewerbung für den Reserveplatz">Reserve</span>
<?php endif; ?>
<span class="text-muted">· <?= e(date('d.m. H:i', (int) strtotime((string) $application['created_at']))) ?></span>
</div>
<?php if ((string) ($application['message'] ?? '') !== ''): ?>
<p class="premade-application-message"><?= nl2br(e((string) $application['message'])) ?></p>
<?php endif; ?>
</div>
<div class="premade-application-actions">
<form method="post" action="/premade_action.php" class="inline-form"
data-confirm="<?= e($applicantName . $applicantWhere . ' und bekommt eine Discord-PN.') ?>"
data-confirm-title="Bewerbung annehmen?" data-confirm-ok="Aufnehmen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="application_accept">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="application_id" value="<?= (int) $application['id'] ?>">
<button type="submit" class="button-small"<?= $applicantBlocked ? ' disabled title="Die Premade ist voll – mach zuerst einen Platz frei"' : '' ?>>Aufnehmen</button>
</form>
<form method="post" action="/premade_action.php" class="inline-form"
data-confirm="<?= e($applicantName . ' bekommt eine Discord-PN. Eine Begründung ist freiwillig – sie steht dann in der PN und bei „Meine Bewerbungen“.') ?>"
data-confirm-title="Bewerbung ablehnen?" data-confirm-ok="Ablehnen" data-confirm-danger
data-confirm-input="reason" data-confirm-placeholder="Begründung (optional)">
<?= csrf_field() ?>
<input type="hidden" name="action" value="application_decline">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="application_id" value="<?= (int) $application['id'] ?>">
<input type="hidden" name="reason" value="">
<button type="submit" class="button-secondary button-small">Ablehnen</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($discordId !== null && !premade_has_user($premade, $discordId)): ?>
<?php
// Bewerben: bei jeder Premade mit freiem Platz, solange der Lead es nicht abgeschaltet hat - auch
// fuer die Leitung, die sich sonst nur direkt eintragen koennte
$applyBlocker = premade_application_blocker($premade, $discordId, $myApplications, $applicationsClosed);
?>
<div class="premade-apply">
<?php if ($applyBlocker === null): ?>
<?php // Gruppe oder Reserve waehlt man im Popup - nur freie Plaetze ?>
<span class="text-muted"><?= $mainFree ? 'Du möchtest mitspielen?' : 'Die Gruppe ist voll – der Reserveplatz ist noch frei.' ?></span>
<button type="button" class="button-secondary button-small premade-apply-btn" data-premade-id="<?= $premadeId ?>" data-premade-name="<?= e($premadeName) ?>"
data-group-free="<?= $mainFree ? '1' : '0' ?>" data-reserve-free="<?= $reserveFree ? '1' : '0' ?>">📝 <?= $mainFree ? 'Bewerben' : 'Für die Reserve bewerben' ?></button>
<?php elseif ($applyBlocker[0] === 'pending'): ?>
<?php
$myOpenApplication = array_values(array_filter($myApplications,
static fn (array $row): bool => (int) $row['premade_id'] === $premadeId && $row['status'] === 'open'))[0];
?>
<span>⏳ Deine Bewerbung<?= !empty($myOpenApplication['reserve']) ? ' für den Reserveplatz' : '' ?> wartet auf eine Antwort.</span>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="withdraw">
<input type="hidden" name="application_id" value="<?= (int) $myOpenApplication['id'] ?>">
<button type="submit" class="button-secondary button-small">Zurückziehen</button>
</form>
<?php else: ?>
<span class="text-muted"><?= e($applyBlocker[1]) ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($canManageThis): ?>
<div class="premade-manage premade-edit-only">
<p class="field-hint premade-drag-hint">Zieh Spieler zwischen Gruppe und Reserve hin und her (am Handy mit ⇅) - auf ein Mitglied gezogen, tauschen die beiden die Plätze. Die Reihenfolge in der Gruppe änderst du genauso oder mit den Pfeilen. Der Lead bleibt vorne.</p>
<form method="post" action="/premade_action.php" class="raid-premade-row">
<?= csrf_field() ?>
<input type="hidden" name="action" value="rename">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="text" name="name" value="<?= e($premadeName) ?>" minlength="<?= PREMADE_NAME_MIN ?>" maxlength="<?= PREMADE_NAME_MAX ?>" required style="width:auto;flex:1;min-width:160px;">
<button type="submit" class="button-secondary">Umbenennen</button>
</form>
<form method="post" action="/premade_action.php" class="premade-applications-toggle">
<?= csrf_field() ?>
<input type="hidden" name="action" value="applications_toggle">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="hidden" name="open" value="<?= $applicationsClosed ? '1' : '0' ?>">
<span class="field-hint"><?= $applicationsClosed
? 'Bewerbungen sind abgeschaltet – gerade kann sich niemand bei dieser Premade bewerben.'
: 'Mitglieder können sich bei dieser Premade bewerben, solange ein Platz frei ist.' ?></span>
<button type="submit" class="button-secondary"><?= $applicationsClosed ? 'Bewerbungen erlauben' : 'Bewerbungen abschalten' ?></button>
</form>
<?php
// Banner: eine der Landschaften oder ein eigenes Bild, dazu der Bildausschnitt
$upload = premade_banner_upload($premadeId);
$uploadUrl = $upload ? profile_image_url((string) $upload['filename']) : null;
$uploadValue = $upload ? 'gallery:' . (int) $upload['id'] : null;
$currentBanner = (string) ($banner['banner'] ?? '');
if ($currentBanner !== '' && str_starts_with($currentBanner, 'gallery:') && $currentBanner !== $uploadValue) {
$currentBanner = ''; // das Bild gibt es nicht mehr (z.B. von der Moderation geloescht)
}
$previewUrl = $currentBanner === $uploadValue && $uploadValue !== null ? $uploadUrl : ($banner['url'] ?? null);
$focus = (int) ($banner['focus'] ?? 50);
?>
<details class="premade-banner-edit">
<summary><?= icon('edit') ?> Banner<?= $currentBanner === '' ? ' – noch keins' : '' ?><?= !empty($banner['pending']) ? ' – wartet auf Freigabe' : '' ?></summary>
<form method="post" action="/premade_action.php" class="premade-banner-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="banner_save">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<div class="premade-banner-preview<?= $previewUrl ? '' : ' is-empty' ?>" style="<?= $previewUrl ? premade_banner_style(['url' => $previewUrl, 'focus' => $focus]) : '--banner-focus:' . $focus . '%' ?>">
<span><?= e($premadeName) ?></span>
</div>
<label class="premade-banner-focus-label">
Bildausschnitt
<input type="range" name="focus" min="0" max="100" step="1" value="<?= $focus ?>" class="premade-banner-focus" aria-label="Bildausschnitt: weiter oben oder weiter unten">
</label>
<div class="background-grid premade-banner-grid">
<label class="background-option<?= $currentBanner === '' ? ' is-selected' : '' ?>">
<input type="radio" name="banner" value="" data-url="" <?= $currentBanner === '' ? 'checked' : '' ?>>
<span class="background-thumb premade-banner-none">–</span>
<span class="background-name">Kein Banner</span>
</label>
<?php foreach (PREMADE_BANNER_PRESETS as $presetIndex => $preset): ?>
<?php $value = 'preset:' . $preset; ?>
<label class="background-option<?= $currentBanner === $value ? ' is-selected' : '' ?>">
<input type="radio" name="banner" value="<?= e($value) ?>" data-url="<?= e(premade_banner_preset_url($preset)) ?>" <?= $currentBanner === $value ? 'checked' : '' ?>>
<span class="background-thumb"><img src="/assets/images/Landscapes/web/thumbs/<?= e($preset) ?>-thumb.jpg" alt="" loading="lazy"></span>
<span class="background-name">Landschaft <?= $presetIndex + 1 ?></span>
</label>
<?php endforeach; ?>
<?php if ($upload): ?>
<label class="background-option background-own<?= $currentBanner === $uploadValue ? ' is-selected' : '' ?>">
<input type="radio" name="banner" value="<?= e($uploadValue) ?>" data-url="<?= e($uploadUrl) ?>" <?= $currentBanner === $uploadValue ? 'checked' : '' ?>>
<span class="background-thumb">
<img src="<?= e($uploadUrl) ?>" alt="" loading="lazy">
<?php if ($upload['status'] === 'pending'): ?><span class="background-pending" title="<?= e((string) $upload['moderation_note']) ?>">Wartet auf Freigabe</span><?php endif; ?>
</span>
<span class="background-name">Eigenes Bild</span>
</label>
<?php endif; ?>
</div>
<div class="actions"><button type="submit">Banner speichern</button></div>
</form>
<form method="post" action="/premade_action.php" enctype="multipart/form-data" class="premade-banner-upload">
<?= csrf_field() ?>
<input type="hidden" name="action" value="banner_upload">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<input type="file" name="banner_image" accept="image/png,image/jpeg,image/gif,image/webp" required data-max-size="<?= PREMADE_BANNER_MAX_SIDE ?>" data-paste>
<button type="submit" class="button-secondary"><?= $upload ? 'Anderes eigenes Bild hochladen' : 'Eigenes Bild hochladen' ?></button>
</form>
<p class="field-hint">
Am besten ein breites Querformat (z.B. ein Screenshot), höchstens 8 MB. Eigene Bilder gehen durch
dieselbe Freigabe wie Galeriebilder. Zu sehen ist das Banner hier, im Dashboard eurer Mitglieder
und in Raids hinter eurer Gruppe.
</p>
<?php if ($upload): ?>
<form method="post" action="/premade_action.php" class="inline-form" data-confirm="Das eigene Bild dieser Premade löschen?" data-confirm-title="Bild löschen" data-confirm-danger data-confirm-ok="Löschen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="banner_delete_upload">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<button type="submit" class="button-secondary button-small"><?= icon('trash') ?> Eigenes Bild löschen</button>
</form>
<?php endif; ?>
</details>
<?php
// Die Leitung kann nur an jemanden gehen, der noch keine PREMADE_LEAD_MAX Premades leitet
// (ausser mit premades.lead_multiple). Einer Gruppe ohne Lead kann der Reservist nur
// vorstehen, solange in der Gruppe ein Platz frei ist.
$transferCandidates = array_values(array_filter(
$accepted,
static fn (array $m): bool => $mayLeadAnother((int) ($m['user_id'] ?? 0))
&& ($ownerId > 0 || $mainFree || empty($m['reserve']))
));
?>
<?php if (!empty($accepted) && empty($transferCandidates)): ?>
<p class="field-hint">Die Leitung kann gerade an niemanden gehen: alle Mitglieder leiten schon <?= PREMADE_LEAD_MAX ?> Premades.</p>
<?php elseif (!empty($transferCandidates)): ?>
<form method="post" action="/premade_action.php" class="raid-premade-row">
<?= csrf_field() ?>
<input type="hidden" name="action" value="transfer">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<?php
// Kandidaten als Suchliste: Name wie in der Premade, Avatar vom Website-Konto
$ownerItems = array_map(static function (array $candidate) use ($namesByDiscordId, $linkedUsersByDiscordId): array {
$discordId = (int) ($candidate['user_id'] ?? 0);
$linked = $linkedUsersByDiscordId[$discordId] ?? [];
return member_picker_item([
'discord_id' => (string) $discordId,
'name' => premade_name_for($discordId, $namesByDiscordId, $candidate['name'] ?? null),
'avatar_filename' => $linked['avatar_filename'] ?? null,
'class_name' => $candidate['class'] ?? ($linked['class_name'] ?? null),
'top_role' => !empty($candidate['reserve']) ? 'Premade-Reserve' : 'Premade-Mitglied',
], 'discord_id');
}, $transferCandidates);
?>
<?= member_picker('new_owner_id', 'premade-owner-' . $premadeId, $ownerItems, [
'required' => true,
'input_id' => 'premade-owner-search-' . $premadeId,
'placeholder' => $ownerId > 0 ? 'Neue Leitung wählen …' : 'Lead aus den Mitgliedern wählen …',
]) ?>
<button type="submit" class="button-secondary"><?= $ownerId > 0 ? 'Leitung übertragen' : 'Lead bestimmen' ?></button>
</form>
<?php endif; ?>
<?php if ($canManage && $ownerId > 0 && $ownerId !== $discordId): ?>
<?php // Die Leitung loest eine fremde Gruppe nur mit Begruendung auf - der Lead bekommt sie per PN. ?>
<button type="button" class="button-danger premade-dissolve-btn" data-premade-id="<?= $premadeId ?>" data-premade-name="<?= e($premadeName) ?>">Gruppe auflösen</button>
<?php else: ?>
<form method="post" action="/premade_action.php" class="inline-form" data-confirm="<?= e('„' . $premadeName . '“ wirklich auflösen? Alle Mitglieder bekommen eine Discord-PN.') ?>" data-confirm-title="Premade auflösen" data-confirm-danger data-confirm-ok="Auflösen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="premade_id" value="<?= $premadeId ?>">
<button type="submit" class="button-danger">Gruppe auflösen</button>
</form>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<!-- Gemeinsames Einladen-Popup fuer alle Premades auf dieser Seite -->
<div id="premade-invite-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2 class="premade-invite-title">Mitglied einladen</h2>
<p class="text-muted premade-invite-hint" data-direct-text="Wähle einen Spieler für diese Premade. Er wird direkt eingeteilt und per Discord-PN benachrichtigt." data-invite-text="Wähle ein Mitglied für diese Premade. Es bekommt die Einladung per Discord-PN und muss sie dort oder hier annehmen." data-reserve-text="Die Gruppe ist voll - der Platz ist die Reserve."></p>
<div class="premade-invite-list">
<?php foreach ($inviteCandidates as $candidate): ?>
<?php $candidateName = $candidate['display_name'] !== '' ? $candidate['display_name'] : $candidate['discord_username']; ?>
<button type="button" class="premade-invite-option" data-user-id="<?= (int) $candidate['discord_id'] ?>" data-user-name="<?= e($candidateName) ?>">
<?= avatar_html(['id' => $candidate['id'], 'display_name' => $candidateName, 'username' => $candidateName, 'avatar_filename' => $candidate['avatar_filename'] ?? null], 32) ?>
<span><?= e($candidateName) ?></span>
</button>
<?php endforeach; ?>
</div>
</div>
</div>
<form id="premade-invite-form" method="post" action="/premade_action.php" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="invite">
<input type="hidden" name="premade_id" id="premade-invite-premade-id">
<input type="hidden" name="user_id" id="premade-invite-user-id">
</form>
<!-- Drag & Drop: zwischen Gruppe und Reserve (move) bzw. innerhalb der Gruppe (reorder) -->
<form id="premade-move-form" method="post" action="/premade_action.php" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="move" id="premade-move-action">
<input type="hidden" name="premade_id" id="premade-move-premade-id">
<input type="hidden" name="user_id" id="premade-move-user-id">
<input type="hidden" name="reserve" id="premade-move-reserve">
<input type="hidden" name="target_user_id" id="premade-move-target-user-id">
<input type="hidden" name="direction" id="premade-move-direction">
</form>
<?php if ($canManage): ?>
<!-- Aufloesen durch die Leitung: Begruendung fuer den Lead -->
<div id="premade-dissolve-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Premade auflösen</h2>
<p class="text-muted">Du löst <strong class="premade-dissolve-name"></strong> als Legionsleitung auf. Der Lead bekommt die Begründung per Discord-PN, die übrigen Mitglieder erfahren nur, dass die Legionsleitung die Gruppe aufgelöst hat.</p>
<form method="post" action="/premade_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="premade_id" id="premade-dissolve-premade-id">
<label for="premade-dissolve-reason">Begründung</label>
<textarea id="premade-dissolve-reason" name="reason" rows="3" minlength="<?= PREMADE_DISSOLVE_REASON_MIN ?>" maxlength="<?= PREMADE_DISSOLVE_REASON_MAX ?>" required placeholder="Warum wird die Gruppe aufgelöst?"></textarea>
<div class="actions">
<button type="button" class="button-secondary modal-cancel">Abbrechen</button>
<button type="submit" class="button-danger">Gruppe auflösen</button>
</div>
</form>
</div>
</div>
<?php endif; ?>
<!-- Bewerbung bei einer Premade: Klasse und eine kurze Nachricht an den Lead -->
<div id="premade-apply-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Bei <span class="premade-apply-name"></span> bewerben</h2>
<p class="text-muted">Der Lead bekommt deine Bewerbung per Discord-PN und nimmt sie hier an oder lehnt sie ab – die Antwort bekommst du ebenfalls per PN. Bei Gruppen ohne Lead entscheidet die Legionsleitung.</p>
<form method="post" action="/premade_action.php" class="premade-apply-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="apply">
<input type="hidden" name="premade_id" id="premade-apply-premade-id">
<label for="premade-apply-class">Als Klasse</label>
<select id="premade-apply-class" name="class">
<?php $ownApplyClasses = user_classes(current_user()); ?>
<?php foreach (class_options_for(current_user()) as $classOption): ?>
<option value="<?= e($classOption) ?>"><?= e($classOption) ?><?= $classOption === ($ownApplyClasses[0] ?? null) ? ' (Main)' : '' ?></option>
<?php endforeach; ?>
</select>
<?php // Welche Plaetze frei sind, setzt assets/js/premades.js je Premade (belegte sind ausgegraut) ?>
<fieldset class="premade-apply-slot">
<legend>Platz</legend>
<div class="premade-apply-slot-options">
<label class="premade-apply-slot-option"><input type="radio" name="slot" value="group" checked> In der Gruppe<span class="premade-apply-slot-full"> · voll</span></label>
<label class="premade-apply-slot-option"><input type="radio" name="slot" value="reserve"> Auf der Reserve<span class="premade-apply-slot-full"> · belegt</span></label>
</div>
<span class="field-hint">Die Reserve springt ein, wenn in der Gruppe jemand fehlt.</span>
</fieldset>
<label for="premade-apply-message">Nachricht an den Lead <span class="text-muted">(optional)</span></label>
<textarea id="premade-apply-message" name="message" rows="3" maxlength="<?= PREMADE_APPLICATION_MESSAGE_MAX ?>" placeholder="z. B. wann du meistens spielst oder was du dir von der Gruppe wünschst"></textarea>
<div class="actions">
<button type="button" class="button-secondary modal-cancel">Abbrechen</button>
<button type="submit">Bewerbung abschicken</button>
</div>
</form>
</div>
</div>
<!-- Gemeinsames Klassen-Popup - identisch zur Klassenauswahl bei der Raid-Anmeldung -->
<div id="premade-class-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Klasse wählen</h2>
<p class="text-muted">Welche Klasse spielst du in dieser Premade? Vorausgewählt ist deine Main-Klasse aus Discord - wechseln kannst du jederzeit.</p>
<div class="class-picker">
<?php $ownClasses = user_classes(current_user()); ?>
<?php foreach (class_options_for(current_user()) as $classOption): ?>
<button type="button" class="class-picker-option<?= in_array($classOption, $ownClasses, true) ? ' 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>
</div>
<form id="premade-class-form" method="post" action="/premade_action.php" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="set_class">
<input type="hidden" name="premade_id" id="premade-class-premade-id">
<input type="hidden" name="class" id="premade-class-value">
</form>
<script src="<?= e(asset_url('/assets/js/premades.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/image-resize.js')) ?>"></script>
<?php if ($canManage && count($premades) > 1): ?>
<?php // Standard-Reihenfolge verschieben - dieselbe Liste wie bei der Reihenfolge der Tags (admin/roles.php) ?>
<script src="<?= e(asset_url('/assets/js/tag-order.js')) ?>"></script>
<?php endif; ?>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/item-picker.js')) ?>"></script>
<?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>