LuminaWebsite/raid_attendance_action.php
Maaxxs 2623236173 Members create raids as raid lead; points, restore and deletion stay with the leadership
- New permission raids.create (granted on update to every group that has raids.view): whoever
  creates a raid on the website becomes its raid lead (raid_settings.lead_user_id, schema v49),
  shown with a crown on the raid card and in the signup list.
- The raid lead manages their own raid: edit, move players, invite premades, fill in the attendance
  list and archive it. Restoring, deleting for good and the Lumipunkte stay with the leadership
  (raids.manage, raids.points). Checked on the server via raid_can_manage() in every raid action.
- Raids created by a member without raids.points bring no automatic points (0/0) until the
  leadership sets them when editing; raids of the leadership keep the fixed +1.
- The attendance reminder of the bot (bot_api.php) goes to the raid lead, even if not signed up;
  raids without a lead (created in Discord) remind the signed-up raids.manage members as before.
- Core permission descriptions are cut to the 255 characters of the column when synced - a longer
  one made the schema sync throw on every request (found while testing this change).
- Privacy policy (raid lead is visible to all), data export, patch notes, README and the tour updated;
  raid_created_at() folded into raid_posted_at().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 00:04:53 +02:00

82 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raid_attendance.php';
require_login();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/raids.php');
}
verify_csrf();
$raidId = (int) ($_POST['raid_id'] ?? 0);
if ($raidId <= 0) {
redirect('/raids.php');
}
// Die Leitung fuer jeden Raid, der Raid-Lead fuer seinen eigenen
if (!raid_can_manage($raidId)) {
set_flash('error', 'Die Anwesenheit dieses Raids darfst du nicht eintragen.');
redirect('/raids.php');
}
$userId = (int) current_user()['id'];
// Eigene Einstellungen (fester Punkt) vor dem "kontrolliert"-Haken anlegen.
raid_settings_ensure_defaults([$raidId]);
$statuses = (array) ($_POST['status'] ?? []);
$names = (array) ($_POST['names'] ?? []);
// Nachgetragenes Mitglied kommt als anwesend dazu.
$addDiscordId = trim((string) ($_POST['add_discord_id'] ?? ''));
if ($addDiscordId !== '' && ctype_digit($addDiscordId)) {
$stmt = db()->prepare("SELECT COALESCE(NULLIF(display_name, ''), username) FROM users WHERE discord_id = ?");
$stmt->execute([$addDiscordId]);
$name = $stmt->fetchColumn();
if ($name !== false) {
$statuses[$addDiscordId] = 'present';
$names[$addDiscordId] = (string) $name;
}
}
$pdo = db();
$pdo->beginTransaction();
$upsert = $pdo->prepare(
'INSERT INTO raid_attendance (raid_id, discord_id, name, status, updated_by, updated_at) VALUES (?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE name = VALUES(name), status = VALUES(status), updated_by = VALUES(updated_by), updated_at = NOW()'
);
$delete = $pdo->prepare('DELETE FROM raid_attendance WHERE raid_id = ? AND discord_id = ?');
$counts = array_fill_keys(array_keys(RAID_ATTENDANCE_STATUSES), 0);
foreach ($statuses as $discordId => $status) {
$discordId = (string) $discordId;
if (!ctype_digit($discordId)) {
continue;
}
$status = (string) $status;
if (isset(RAID_ATTENDANCE_STATUSES[$status])) {
$upsert->execute([$raidId, $discordId, mb_substr((string) ($names[$discordId] ?? ''), 0, 100), $status, $userId]);
$counts[$status]++;
} else {
$delete->execute([$raidId, $discordId]); // "–" = nicht erfasst
}
}
if (!empty($_POST['mark_checked'])) {
$pdo->prepare(
'INSERT INTO raid_settings (raid_id, attendance_checked_at, attendance_checked_by) VALUES (?, NOW(), ?)
ON DUPLICATE KEY UPDATE attendance_checked_at = NOW(), attendance_checked_by = VALUES(attendance_checked_by)'
)->execute([$raidId, $userId]);
}
$pdo->commit();
admin_log('📋 Anwesenheit eingetragen', [
'Raid' => admin_log_raid($raidId),
'Anwesend' => $counts['present'],
'Abwesend' => $counts['absent'],
'Nachgetragen' => $addDiscordId !== '' && isset($names[$addDiscordId]) ? admin_log_discord($addDiscordId, (string) $names[$addDiscordId]) : '',
'Kontrolliert' => !empty($_POST['mark_checked']) ? 'ja, Liste abgeschlossen' : '',
], 'success');
set_flash('success', sprintf(
'Anwesenheit gespeichert: %d anwesend, %d abwesend%s.',
$counts['present'], $counts['absent'],
!empty($_POST['mark_checked']) ? ' - als kontrolliert markiert' : ''
));
redirect('/raid_attendance.php?raid=' . $raidId);