LuminaWebsite/raid_create_action.php
Maaxxs fe1561f4f7 Raids: attendance list, automatic points on archive, reminder callback
Each raid gets an attendance list for raids.manage (present, absent, excused)
with quick actions, members added by hand and a "checked" mark with who and
when. The contribution form can now select a raid's present members for
points or its absent members for a deduction.

Raids can carry points for present members and a deduction for absent ones
(raid_settings). When a raid is archived - on the website or via the button
in Discord, detected on the next raid or contribution page view - the site
awards them once: by attendance if a list exists, otherwise to everyone in a
group without deduction, and not at all if points were already given for
that raid. Settings, attendance and awards follow a raid_id change when the
API re-posts a deleted message.

bot_api.php lets the bot ask which signed-up members have raids.manage when a
raid starts (shared key in config.php bot_callback.key); the bot then sends
them a DM with a link to the list. The bot side lives in the separate bot
repository (cogs/attendance.py).

Also fixes contribution_awards.raid_id being too small for Discord IDs (it
is widened automatically) and raid IDs losing precision in the contribution
form's JavaScript, which kept the raid preselection from ever matching.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 09:52:34 +02:00

40 lines
1.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'] ?? '');
$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.');
}
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);
// Beitragspunkte 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);
}
json_response(true, 'Raid wurde erstellt.', ['raid_id' => $result['raid_id'] ?? null]);
} catch (Throwable $e) {
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
}