- 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>
147 lines
6.4 KiB
PHP
147 lines
6.4 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/raids_api.php';
|
||
require_once __DIR__ . '/includes/raid_attendance.php';
|
||
require_permission('raids.manage');
|
||
|
||
$input = read_json_body();
|
||
verify_csrf_token($input['csrf_token'] ?? '');
|
||
|
||
$title = trim((string) ($input['title'] ?? ''));
|
||
$dateRaw = trim((string) ($input['date_raw'] ?? ''));
|
||
$requirements = trim((string) ($input['requirements'] ?? ''));
|
||
$groupNames = trim((string) ($input['group_names'] ?? ''));
|
||
[$gearscore, $gearscoreError] = raid_normalize_gearscore((string) ($input['gearscore'] ?? ''));
|
||
|
||
if ($title === '' || $dateRaw === '' || $requirements === '' || $groupNames === '') {
|
||
json_response(false, 'Bitte Titel, Datum, Anforderungen und mindestens eine Gruppe angeben.');
|
||
}
|
||
$groupList = array_values(array_filter(array_map('trim', explode(',', $groupNames)), static fn (string $name): bool => $name !== ''));
|
||
$groupCount = count($groupList);
|
||
$slotsError = raid_slots_error($input['max_slots'] ?? '', $groupCount);
|
||
if ($slotsError !== null) {
|
||
json_response(false, $slotsError);
|
||
}
|
||
$maxSlots = (int) trim((string) $input['max_slots']);
|
||
if ($gearscoreError !== null) {
|
||
json_response(false, $gearscoreError);
|
||
}
|
||
|
||
// Lumipunkte: ohne raids.points gilt fest +1 pro Teilnahme, kein Abzug.
|
||
$pointsPresent = RAID_POINTS_DEFAULT_PRESENT;
|
||
$pointsAbsent = RAID_POINTS_DEFAULT_ABSENT;
|
||
if (user_has_permission('raids.points')) {
|
||
$pointsPresent = raid_points_input($input['points_present'] ?? RAID_POINTS_DEFAULT_PRESENT);
|
||
$pointsAbsent = raid_points_input($input['points_absent'] ?? RAID_POINTS_DEFAULT_ABSENT);
|
||
$pointsError = $pointsPresent === null || $pointsAbsent === null
|
||
? 'Lumipunkte: bitte ganze Zahlen von 0 bis ' . RAID_POINTS_MAX . ' angeben.'
|
||
: raid_points_error($pointsPresent, $pointsAbsent);
|
||
if ($pointsError !== null) {
|
||
json_response(false, $pointsError);
|
||
}
|
||
}
|
||
|
||
// Feste Premades, die direkt einer Gruppe zugeordnet werden (Gruppe => Premade-ID).
|
||
$premadeChoices = [];
|
||
foreach ((array) ($input['premades'] ?? []) as $choice) {
|
||
$group = (int) ($choice['group'] ?? 0);
|
||
$premadeId = (int) ($choice['premade_id'] ?? 0);
|
||
if ($premadeId <= 0) {
|
||
continue;
|
||
}
|
||
if ($group < 1 || $group > $groupCount || isset($premadeChoices[$group])) {
|
||
json_response(false, 'Die Zuordnung der Premades zu den Gruppen ist ungültig.');
|
||
}
|
||
if (in_array($premadeId, $premadeChoices, true)) {
|
||
json_response(false, 'Eine Premade kann nur einer Gruppe zugeordnet werden.');
|
||
}
|
||
$premadeChoices[$group] = $premadeId;
|
||
}
|
||
$premadesById = [];
|
||
if (!empty($premadeChoices)) {
|
||
try {
|
||
foreach (fetch_premades() as $premade) {
|
||
$premadesById[(int) ($premade['id'] ?? 0)] = $premade;
|
||
}
|
||
} catch (Throwable $e) {
|
||
json_response(false, 'Die Premades konnten nicht geladen werden: ' . $e->getMessage());
|
||
}
|
||
foreach ($premadeChoices as $group => $premadeId) {
|
||
if (!isset($premadesById[$premadeId])) {
|
||
json_response(false, 'Diese Premade gibt es nicht (mehr) - bitte die Seite neu laden.');
|
||
}
|
||
// Die Gruppe heisst wie die Premade (beim Einladen benennt der Bot sie ohnehin so um).
|
||
$groupList[$group - 1] = trim((string) preg_replace('/\s+/u', ' ', str_replace(',', ' ', (string) ($premadesById[$premadeId]['name'] ?? ''))))
|
||
?: 'Gruppe ' . $group;
|
||
}
|
||
$groupNames = implode(', ', $groupList);
|
||
if (mb_strlen($groupNames, 'UTF-8') > RAID_FIELD_LIMITS['group_names'][1]) {
|
||
// Zu lang fuer die API - Platzhalter schicken, die Einladung setzt den richtigen Namen.
|
||
foreach ($premadeChoices as $group => $premadeId) {
|
||
$groupList[$group - 1] = 'Gruppe ' . $group;
|
||
}
|
||
$groupNames = implode(', ', $groupList);
|
||
}
|
||
}
|
||
|
||
$fieldError = raid_fields_error(['title' => $title, 'requirements' => $requirements, 'gearscore' => $gearscore, 'group_names' => $groupNames]);
|
||
if ($fieldError !== null) {
|
||
json_response(false, $fieldError);
|
||
}
|
||
|
||
try {
|
||
$result = create_raid([
|
||
'title' => $title,
|
||
'date_raw' => $dateRaw,
|
||
'requirements' => $requirements,
|
||
'group_names' => $groupNames,
|
||
'gearscore' => $gearscore,
|
||
'max_slots' => $maxSlots,
|
||
]);
|
||
} catch (Throwable $e) {
|
||
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
|
||
}
|
||
|
||
$newRaidId = (int) ($result['raid_id'] ?? 0);
|
||
// Lumipunkte beim Archivieren kennt die Raid-API nicht - die merkt sich die Website. Auch 0/0
|
||
// wird gespeichert, damit ein bewusst punktloser Raid nicht den festen Punkt bekommt.
|
||
if ($newRaidId > 0) {
|
||
try {
|
||
raid_settings_save_points($newRaidId, $pointsPresent, $pointsAbsent);
|
||
} catch (PDOException $e) {
|
||
// Raid steht - ohne Eintrag gilt beim Anzeigen der feste Punkt.
|
||
}
|
||
}
|
||
admin_log('⚔️ Raid erstellt', [
|
||
'Raid' => $title,
|
||
'Termin' => $dateRaw,
|
||
'Plätze' => $maxSlots,
|
||
'Gruppen' => $groupNames,
|
||
'Gearscore' => $gearscore,
|
||
'Lumipunkte' => '+' . $pointsPresent . ' anwesend / -' . $pointsAbsent . ' abwesend',
|
||
], 'success');
|
||
|
||
// Premades direkt einladen - Fehler dabei machen den Raid nicht ungueltig.
|
||
$premadeMessages = [];
|
||
foreach ($newRaidId > 0 ? $premadeChoices : [] as $group => $premadeId) {
|
||
$premade = $premadesById[$premadeId];
|
||
$premadeName = (string) ($premade['name'] ?? ('#' . $premadeId));
|
||
try {
|
||
$count = invite_premade($newRaidId, $premadeId, $group);
|
||
admin_log('🤝 Premade zum Raid eingeladen', [
|
||
'Raid' => $title,
|
||
'Premade' => $premadeName,
|
||
'Zielgruppe' => 'Gruppe ' . $group . ' – umbenannt und gesperrt',
|
||
'Eingeladen' => $count . ' Mitglied(er) per DM',
|
||
'Mitglieder' => implode(', ', array_map(
|
||
static fn (array $m): string => (string) ($m['name'] ?? admin_log_discord_name((string) ($m['user_id'] ?? ''))),
|
||
array_filter((array) ($premade['members'] ?? []), static fn ($m): bool => ($m['status'] ?? '') === 'accepted')
|
||
)),
|
||
]);
|
||
$premadeMessages[] = '„' . $premadeName . '“: ' . $count . ' Mitglied(er) per DM eingeladen.';
|
||
} catch (Throwable $e) {
|
||
$premadeMessages[] = '„' . $premadeName . '“ konnte nicht eingeladen werden (' . $e->getMessage() . ') - bitte im Bearbeiten-Modus erneut versuchen.';
|
||
}
|
||
}
|
||
|
||
json_response(true, trim('Raid wurde erstellt. ' . implode(' ', $premadeMessages)), ['raid_id' => $result['raid_id'] ?? null]);
|