LuminaWebsite/raid_signup_action.php
Maaxxs c4f94bf84a Member feedback: raid input checks and fixed raid points, premades in the raid form, live raid page, Lumina-style dialogs, leadership calendar entries, class-based weapon picker, map and tactics fixes
- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing
- Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept
- Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name
- Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names
- Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK
- Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll
- Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set
- Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note
- Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected
- Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 16:12:18 +02:00

95 lines
4 KiB
PHP

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php';
require_permission('raids.view');
$input = read_json_body();
verify_csrf_token($input['csrf_token'] ?? '');
$user = current_user();
if (empty($user['discord_id'])) {
json_response(false, 'Bitte verknüpfe zuerst deinen Discord-Account in "Mein Profil".');
}
$raidId = (int) ($input['raid_id'] ?? 0);
$class = trim((string) ($input['class'] ?? ''));
$groupRaw = $input['group'] ?? null; // null/"auto" = automatische Zuteilung, sonst gewuenschte Gruppe (0 = Bank)
if ($raidId <= 0 || $class === '') {
json_response(false, 'Bitte eine Klasse auswählen.');
}
try {
$raid = fetch_raid_by_id($raidId);
if (!$raid) {
json_response(false, 'Raid wurde nicht gefunden.');
}
if (!empty($raid['archived'])) {
json_response(false, 'Dieser Raid ist archiviert. Anmeldungen sind geschlossen.');
}
$maxGroups = count(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
$signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : [];
$discordId = (int) $user['discord_id'];
$lockedGroups = is_array($raid['locked_groups'] ?? null) ? array_map('intval', $raid['locked_groups']) : [];
$openGroups = $maxGroups >= 1 ? array_values(array_diff(range(1, $maxGroups), $lockedGroups)) : [];
$wantsAuto = $groupRaw === null || $groupRaw === '' || $groupRaw === 'auto';
$matchedWish = true;
$wishRejectReason = null; // 'locked' | 'full'
$requestGroup = null;
if (!$wantsAuto) {
$desiredGroup = (int) $groupRaw;
if ($desiredGroup < 0 || $desiredGroup > $maxGroups) {
json_response(false, 'Ungültige Gruppe ausgewählt.');
}
if ($desiredGroup > 0 && in_array($desiredGroup, $lockedGroups, true)) {
$requestGroup = null; // Gesperrte Gruppe: wie eine nicht erfuellbare Wunschgruppe behandeln
$matchedWish = false;
$wishRejectReason = 'locked';
} elseif (raid_wish_is_sensible($signups, $discordId, $class, $desiredGroup)) {
$requestGroup = $desiredGroup;
} else {
$requestGroup = null; // Bot automatisch zuteilen lassen
$matchedWish = false;
$wishRejectReason = 'full';
}
}
// Ist keine einzige Gruppe offen (alle gesperrt oder der Raid hat gar keine
// Gruppen), landet man deterministisch auf der Ersatzbank, statt auf eine
// automatische Zuteilung in eine gesperrte Gruppe zu hoffen.
if ($requestGroup === null && empty($openGroups)) {
$requestGroup = 0;
}
// Derselbe Name wie bei einer Anmeldung im Discord: der Anzeigename auf dem Server (Nickname),
// nicht der Discord-Kontoname.
$signupName = trim((string) ($user['display_name'] ?? '')) !== '' ? (string) $user['display_name'] : (string) $user['discord_username'];
$assigned = raid_signup($raidId, $discordId, $signupName, $class, $requestGroup);
$assignedGroup = (int) ($assigned['group'] ?? 0);
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
$assignedGroupLabel = $assignedGroup === 0 ? 'Ersatzbank' : ($groupNames[$assignedGroup - 1] ?? ('Gruppe ' . $assignedGroup));
if ($matchedWish) {
json_response(true, 'Du bist angemeldet: ' . $class . ' in ' . $assignedGroupLabel . '.', [
'group' => $assignedGroup,
'matched_wish' => true,
]);
} else {
$reasonText = $wishRejectReason === 'locked'
? 'Deine Wunschgruppe ist gesperrt'
: 'Deine Wunschgruppe war schon voll besetzt für diese Rolle';
json_response(true, $reasonText . ', daher wurdest du automatisch zugeteilt: '
. $assignedGroupLabel . '. Melde dich gerne beim Raid-Lead, falls du eine Anpassung möchtest.', [
'group' => $assignedGroup,
'matched_wish' => false,
]);
}
} catch (Throwable $e) {
json_response(false, 'Anmeldung fehlgeschlagen: ' . $e->getMessage());
}