- 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>
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Live-Aktualisierung der Raid-Seite (assets/js/raids.js fragt hier regelmaessig nach).
|
|
*
|
|
* GET /raids_live.php?status=active&known=<raid_id>:<rev>,<raid_id>:<rev>,...
|
|
*
|
|
* Antwort: Reihenfolge der Raids, ihr aktueller Fingerabdruck (rev) und fertig gerenderte Karten
|
|
* fuer alle Raids, deren Fingerabdruck sich gegenueber "known" geaendert hat. Aenderungen aus dem
|
|
* Discord kommen so ebenfalls an, weil die Daten wie auf der Seite live von der Raid-API stammen.
|
|
*/
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raid_card.php';
|
|
|
|
// Wird per fetch() aufgerufen - Fehler deshalb als JSON statt Weiterleitung auf die Login-Seite.
|
|
if (!current_user()) {
|
|
http_response_code(401);
|
|
json_response(false, 'Bitte neu anmelden.');
|
|
}
|
|
if (!user_has_permission('raids.view')) {
|
|
http_response_code(403);
|
|
json_response(false, 'Dir fehlt die Berechtigung, Raids zu sehen.');
|
|
}
|
|
|
|
$status = (string) ($_GET['status'] ?? 'active');
|
|
if (!in_array($status, RAID_STATUSES, true)) {
|
|
$status = 'active';
|
|
}
|
|
$known = [];
|
|
foreach (explode(',', (string) ($_GET['known'] ?? '')) as $pair) {
|
|
$parts = explode(':', trim($pair), 2);
|
|
if (count($parts) === 2 && ctype_digit($parts[0])) {
|
|
$known[$parts[0]] = $parts[1];
|
|
}
|
|
}
|
|
|
|
$currentUser = current_user();
|
|
$canManageRaids = user_has_permission('raids.manage');
|
|
$canSetRaidPoints = $canManageRaids && user_has_permission('raids.points');
|
|
$canCreateRaids = $canManageRaids || user_has_permission('raids.create');
|
|
// Die Formulare in den Karten brauchen das CSRF-Token der Sitzung - danach die Sitzung freigeben,
|
|
// damit eine langsame Raid-API andere Tabs derselben Person nicht blockiert.
|
|
csrf_token();
|
|
session_write_close();
|
|
|
|
try {
|
|
$raids = fetch_raids($status);
|
|
} catch (Throwable $e) {
|
|
http_response_code(502);
|
|
json_response(false, 'Raid-Daten konnten nicht geladen werden.');
|
|
}
|
|
try {
|
|
$raidSettings = raid_settings_all();
|
|
} catch (PDOException $e) {
|
|
$raidSettings = [];
|
|
}
|
|
|
|
$order = [];
|
|
$revs = [];
|
|
$changed = [];
|
|
foreach ($raids as $raid) {
|
|
$raidId = (string) (int) ($raid['raid_id'] ?? 0);
|
|
$rev = raid_card_rev($raid, $raidSettings[$raidId] ?? null);
|
|
$order[] = $raidId;
|
|
$revs[$raidId] = $rev;
|
|
if (isset($known[$raidId]) && $known[$raidId] !== $rev) {
|
|
$changed[$raidId] = $raid;
|
|
}
|
|
}
|
|
|
|
$cards = [];
|
|
if (!empty($changed)) {
|
|
$premades = [];
|
|
if ($canCreateRaids) {
|
|
try {
|
|
$premades = fetch_premades();
|
|
} catch (Throwable $e) {
|
|
$premades = [];
|
|
}
|
|
}
|
|
$context = [
|
|
'status' => $status,
|
|
'current_discord_id' => $currentUser['discord_id'] ?? null,
|
|
'current_user_id' => (int) $currentUser['id'],
|
|
'can_manage' => $canManageRaids,
|
|
'can_set_points' => $canSetRaidPoints,
|
|
'settings' => $raidSettings,
|
|
'premades' => $premades,
|
|
'new_since' => isset($_SESSION['raids_new_since']) ? (int) $_SESSION['raids_new_since'] : null,
|
|
];
|
|
foreach ($changed as $raidId => $raid) {
|
|
ob_start();
|
|
render_raid_card($raid, $context);
|
|
$cards[$raidId] = trim((string) ob_get_clean());
|
|
}
|
|
}
|
|
|
|
header('Cache-Control: no-store');
|
|
json_response(true, '', ['order' => $order, 'revs' => $revs, 'cards' => (object) $cards]);
|