- 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>
144 lines
7 KiB
PHP
144 lines
7 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'] ?? '');
|
||
|
||
$raidId = (int) ($input['raid_id'] ?? 0);
|
||
if ($raidId <= 0) {
|
||
json_response(false, 'Ungültige Anfrage.');
|
||
}
|
||
|
||
// Stand vor der Aenderung: fuer unveraenderte Altwerte (siehe unten) und fuers Audit-Log (alt -> neu)
|
||
try {
|
||
$before = fetch_raid_by_id($raidId);
|
||
$beforePoints = raid_settings_get($raidId);
|
||
} catch (Throwable $e) {
|
||
$before = null;
|
||
$beforePoints = null;
|
||
}
|
||
|
||
$fields = [];
|
||
foreach (['title', 'date_raw', 'requirements', 'group_names'] as $key) {
|
||
if (isset($input[$key]) && trim((string) $input[$key]) !== '') {
|
||
$fields[$key] = trim((string) $input[$key]);
|
||
}
|
||
}
|
||
// Unveraenderte Gruppen nicht erneut schicken: Premades benennen Gruppen um, dabei kann die Liste
|
||
// laenger werden, als die API beim Speichern erlaubt - das soll andere Aenderungen nicht blockieren.
|
||
$groupNamesOf = static fn (string $names): array => array_values(array_filter(array_map('trim', explode(',', $names)), static fn (string $n): bool => $n !== ''));
|
||
if (isset($fields['group_names']) && $before !== null && $groupNamesOf($fields['group_names']) === $groupNamesOf((string) ($before['groups'] ?? ''))) {
|
||
unset($fields['group_names']);
|
||
}
|
||
// Der Gearscore ist optional - ein geleertes Feld entfernt ihn. Ein unveraenderter alter Wert
|
||
// (frueher war Freitext erlaubt) blockiert das Speichern anderer Aenderungen nicht.
|
||
if (isset($input['gearscore'])) {
|
||
$rawGearscore = trim((string) $input['gearscore']);
|
||
if ($before === null || $rawGearscore !== trim((string) ($before['gearscore'] ?? ''))) {
|
||
[$gearscore, $gearscoreError] = raid_normalize_gearscore($rawGearscore);
|
||
if ($gearscoreError !== null) {
|
||
json_response(false, $gearscoreError);
|
||
}
|
||
$fields['gearscore'] = $gearscore;
|
||
}
|
||
}
|
||
// Max. Spieler haengt an der Zahl der Gruppen (je 5 Plaetze) - geprueft wird, sobald sich eins
|
||
// von beiden aendert.
|
||
$beforeGroupCount = $before !== null ? raid_group_count((string) ($before['groups'] ?? '')) : 0;
|
||
$groupCount = isset($fields['group_names']) ? raid_group_count($fields['group_names']) : $beforeGroupCount;
|
||
if (isset($fields['group_names']) && $groupCount > RAID_MAX_GROUPS) {
|
||
json_response(false, 'Höchstens ' . RAID_MAX_GROUPS . ' Gruppen pro Raid.');
|
||
}
|
||
if (isset($input['max_slots'])) {
|
||
$rawSlots = trim((string) $input['max_slots']);
|
||
$unchanged = $before !== null && $groupCount === $beforeGroupCount
|
||
&& $rawSlots === (string) (int) ($before['max_slots'] ?? 0);
|
||
if (!$unchanged) {
|
||
$slotsError = raid_slots_error($rawSlots, $groupCount);
|
||
if ($slotsError !== null) {
|
||
json_response(false, $slotsError);
|
||
}
|
||
$fields['max_slots'] = (int) $rawSlots;
|
||
}
|
||
}
|
||
if (isset($input['locked_groups']) && is_array($input['locked_groups'])) {
|
||
$fields['locked_groups'] = array_values(array_map('intval', $input['locked_groups']));
|
||
}
|
||
|
||
// Lumipunkte aendert nur, wer raids.points hat - alle anderen lassen die Einstellung unangetastet.
|
||
$pointsPresent = null;
|
||
$pointsAbsent = null;
|
||
if (user_has_permission('raids.points') && (isset($input['points_present']) || isset($input['points_absent']))) {
|
||
$pointsPresent = raid_points_input($input['points_present'] ?? 0);
|
||
$pointsAbsent = raid_points_input($input['points_absent'] ?? 0);
|
||
$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);
|
||
}
|
||
}
|
||
$pointsChanged = $pointsPresent !== null
|
||
&& ($beforePoints === null || $pointsPresent !== $beforePoints['points_present'] || $pointsAbsent !== $beforePoints['points_absent']);
|
||
|
||
if (empty($fields) && !$pointsChanged) {
|
||
json_response(false, 'Keine Änderungen übermittelt.');
|
||
}
|
||
$fieldError = raid_fields_error($fields);
|
||
if ($fieldError !== null) {
|
||
json_response(false, $fieldError);
|
||
}
|
||
|
||
try {
|
||
$result = !empty($fields) ? update_raid($raidId, $fields) : ['raid_id' => $raidId];
|
||
$newRaidId = (int) ($result['raid_id'] ?? $raidId);
|
||
|
||
// Einstellungen, Anwesenheit und Vergaben haengen an der raid_id - ggf. mit umziehen.
|
||
raid_rename_id($raidId, $newRaidId);
|
||
if ($pointsChanged) {
|
||
raid_settings_save_points($newRaidId, $pointsPresent, $pointsAbsent);
|
||
}
|
||
|
||
$groupList = static fn ($groups): string => $groups ? implode(', ', array_map('intval', (array) $groups)) : 'keine';
|
||
$logFields = ['Raid' => admin_log_raid($newRaidId)];
|
||
if ($before !== null) {
|
||
$logFields += [
|
||
'Titel' => isset($fields['title']) ? admin_log_change($before['title'] ?? '', $fields['title']) : '',
|
||
'Termin' => isset($fields['date_raw']) ? admin_log_change($before['date'] ?? '', $fields['date_raw']) : '',
|
||
'Anforderungen' => isset($fields['requirements']) ? admin_log_change($before['requirements'] ?? '', $fields['requirements']) : '',
|
||
'Gearscore' => isset($fields['gearscore']) ? admin_log_change($before['gearscore'] ?? '', $fields['gearscore']) : '',
|
||
'Gruppen' => isset($fields['group_names']) ? admin_log_change($before['groups'] ?? '', $fields['group_names'], 300) : '',
|
||
'Plätze' => isset($fields['max_slots']) ? admin_log_change($before['max_slots'] ?? '', $fields['max_slots']) : '',
|
||
'Gesperrte Gruppen' => isset($fields['locked_groups'])
|
||
? admin_log_change($groupList($before['locked_groups'] ?? []), $groupList($fields['locked_groups'])) : '',
|
||
];
|
||
} else {
|
||
$logFields['Geändert'] = implode(', ', array_keys($fields));
|
||
}
|
||
if ($pointsChanged) {
|
||
$logFields['Lumipunkte'] = admin_log_change(
|
||
$beforePoints !== null ? '+' . $beforePoints['points_present'] . ' anwesend / −' . $beforePoints['points_absent'] . ' abwesend' : '',
|
||
'+' . $pointsPresent . ' anwesend / −' . $pointsAbsent . ' abwesend'
|
||
);
|
||
}
|
||
if ($newRaidId !== $raidId) {
|
||
$logFields['Hinweis'] = 'Discord-Nachricht war gelöscht und wurde neu gepostet';
|
||
}
|
||
if (count(array_filter($logFields, static fn ($v) => $v !== '')) <= 1) {
|
||
$logFields['Änderung'] = 'keine inhaltliche Änderung';
|
||
}
|
||
admin_log('⚔️ Raid bearbeitet', $logFields);
|
||
|
||
// Die API postet die Discord-Nachricht automatisch neu, falls sie zwischenzeitlich
|
||
// manuell geloescht wurde - die raid_id (= Discord-Message-ID) aendert sich dann.
|
||
if ($newRaidId !== $raidId) {
|
||
json_response(true, 'Raid wurde aktualisiert. Die Discord-Nachricht war nicht mehr auffindbar und wurde neu gepostet.', ['raid_id' => $newRaidId]);
|
||
} else {
|
||
json_response(true, 'Raid wurde aktualisiert.', ['raid_id' => $newRaidId]);
|
||
}
|
||
} catch (Throwable $e) {
|
||
json_response(false, 'Speichern fehlgeschlagen: ' . $e->getMessage());
|
||
}
|