51 lines
2.3 KiB
PHP
51 lines
2.3 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 = trim((string) ($input['gearscore'] ?? ''));
|
|
$maxSlots = isset($input['max_slots']) && is_numeric($input['max_slots']) ? (int) $input['max_slots'] : 12;
|
|
$pointsPresent = max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_present'] ?? 0)));
|
|
$pointsAbsent = max(0, min(CONTRIBUTION_MAX_POINTS, (int) ($input['points_absent'] ?? 0)));
|
|
|
|
if ($title === '' || $dateRaw === '' || $requirements === '' || $groupNames === '') {
|
|
json_response(false, 'Bitte Titel, Datum, Anforderungen und mindestens eine Gruppe angeben.');
|
|
}
|
|
$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,
|
|
]);
|
|
$newRaidId = (int) ($result['raid_id'] ?? 0);
|
|
// Lumipunkte beim Archivieren kennt die Raid-API nicht - die merkt sich die Website.
|
|
if ($newRaidId > 0 && ($pointsPresent > 0 || $pointsAbsent > 0)) {
|
|
raid_settings_save_points($newRaidId, $pointsPresent, $pointsAbsent);
|
|
}
|
|
admin_log('⚔️ Raid erstellt', [
|
|
'Raid' => $title,
|
|
'Termin' => $dateRaw,
|
|
'Plätze' => $maxSlots,
|
|
'Gruppen' => $groupNames,
|
|
'Lumipunkte' => $pointsPresent > 0 || $pointsAbsent > 0 ? '+' . $pointsPresent . ' anwesend / -' . $pointsAbsent . ' abwesend' : '',
|
|
], 'success');
|
|
json_response(true, 'Raid wurde erstellt.', ['raid_id' => $result['raid_id'] ?? null]);
|
|
} catch (Throwable $e) {
|
|
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
|
|
}
|