LuminaWebsite/raid_edit_action.php
Maaxxs 338a00c21f Log all administrative website actions to the Discord log channel via the bot API
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 19:16:54 +02:00

67 lines
2.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.');
}
$fields = [];
foreach (['title', 'date_raw', 'requirements', 'gearscore', 'group_names'] as $key) {
if (isset($input[$key]) && trim((string) $input[$key]) !== '') {
$fields[$key] = trim((string) $input[$key]);
}
}
if (isset($input['max_slots']) && is_numeric($input['max_slots'])) {
$fields['max_slots'] = (int) $input['max_slots'];
}
if (isset($input['locked_groups']) && is_array($input['locked_groups'])) {
$fields['locked_groups'] = array_values(array_map('intval', $input['locked_groups']));
}
if (empty($fields)) {
json_response(false, 'Keine Änderungen übermittelt.');
}
try {
$result = update_raid($raidId, $fields);
$newRaidId = (int) ($result['raid_id'] ?? $raidId);
// Einstellungen, Anwesenheit und Vergaben haengen an der raid_id - ggf. mit umziehen.
raid_rename_id($raidId, $newRaidId);
if (isset($input['points_present']) || isset($input['points_absent'])) {
raid_settings_save_points(
$newRaidId,
max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_present'] ?? 0))),
max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_absent'] ?? 0)))
);
}
$changed = array_keys($fields);
if (isset($input['points_present']) || isset($input['points_absent'])) {
$changed[] = 'lumipunkte';
}
$fieldLabels = ['title' => 'Titel', 'date_raw' => 'Termin', 'requirements' => 'Anforderungen', 'gearscore' => 'Gearscore',
'group_names' => 'Gruppen', 'max_slots' => 'Plätze', 'locked_groups' => 'gesperrte Gruppen', 'lumipunkte' => 'Lumipunkte'];
admin_log('⚔️ Raid bearbeitet', [
'Raid' => admin_log_raid($newRaidId),
'Geändert' => implode(', ', array_map(static fn ($k) => $fieldLabels[$k] ?? $k, $changed)),
'Termin' => $fields['date_raw'] ?? '',
]);
// 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());
}