LuminaWebsite/calendar_action.php
Maaxxs 5aaf44eaec Consilium Elyseum: allied legions get their own view - own raids, calendar entries, member tab and shared live map sessions
Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.

- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
  dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
  area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
  legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
  users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
  (dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
  Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
  Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
  subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
  legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
  The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
  the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
  shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
  areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
  Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
  (guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
  database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 01:36:49 +02:00

180 lines
9.2 KiB
PHP
Raw 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
/**
* Termine der Mitglieder im Kalender: eintragen, bearbeiten, loeschen, "Bin dabei".
* Es gelten dieselben Schutzregeln wie bei Kommentaren (Schimpfwortfilter, Links und neue
* Mitglieder erst nach Freigabe, Tempolimit).
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/calendar_audience.php';
require_login();
// Die Legion - und Mitglieder verbuendeter Legionen fuer Consilium-Termine (calendar_audience_input(), calendar_can_view())
if (!user_has_permission('members.view') && !consilium_only()) {
show_not_found();
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/calendar.php');
}
verify_csrf();
const CALENDAR_TITLE_MAX = 100;
const CALENDAR_DESCRIPTION_MAX = 1000;
$action = (string) ($_POST['action'] ?? '');
$me = current_user();
$myId = (int) $me['id'];
$canLead = calendar_can_lead();
$pdo = db();
/** Zurueck in den Monat des Termins, direkt zum Eintrag. */
$backTo = static function (?string $startsAt, int $entryId = 0): string {
return '/calendar.php' . ($startsAt ? '?month=' . date('Y-m', strtotime($startsAt)) : '') . ($entryId > 0 ? '#termin-' . $entryId : '');
};
/** Datum aus einem datetime-local-Feld (2026-09-24T19:30), null wenn leer/ungueltig. */
$parseTime = static function (string $value): ?string {
$time = DateTimeImmutable::createFromFormat('Y-m-d\TH:i', trim($value), new DateTimeZone('Europe/Berlin'));
return $time ? $time->format('Y-m-d H:i:s') : null;
};
/** Eingaben pruefen - bei Fehlern mit Meldung zurueck. @return array{0:string,1:?string,2:string,3:?string,4:?string} */
$readInput = static function () use ($parseTime, $backTo): array {
$title = trim((string) preg_replace('/\s+/u', ' ', (string) ($_POST['title'] ?? '')));
$description = trim(str_replace("\r\n", "\n", (string) ($_POST['description'] ?? '')));
$startsAt = $parseTime((string) ($_POST['starts_at'] ?? ''));
$endsAt = trim((string) ($_POST['ends_at'] ?? '')) !== '' ? $parseTime((string) $_POST['ends_at']) : null;
$locationInput = trim((string) ($_POST['location'] ?? ''));
$location = $locationInput !== '' ? map_link_parse($locationInput) : null;
$error = null;
if ($title === '') {
$error = 'Bitte einen Titel eingeben.';
} elseif (mb_strlen($title) > CALENDAR_TITLE_MAX) {
$error = 'Der Titel ist zu lang (höchstens ' . CALENDAR_TITLE_MAX . ' Zeichen).';
} elseif (mb_strlen($description) > CALENDAR_DESCRIPTION_MAX) {
$error = 'Die Beschreibung ist zu lang (höchstens ' . CALENDAR_DESCRIPTION_MAX . ' Zeichen).';
} elseif ($startsAt === null) {
$error = 'Bitte Datum und Uhrzeit angeben.';
} elseif (strtotime($startsAt) < strtotime('-1 day') || strtotime($startsAt) > strtotime('+1 year')) {
$error = 'Der Termin muss zwischen heute und in einem Jahr liegen.';
} elseif (trim((string) ($_POST['ends_at'] ?? '')) !== '' && ($endsAt === null || $endsAt <= $startsAt)) {
$error = 'Das Ende muss nach dem Beginn liegen.';
} elseif ($endsAt !== null && strtotime($endsAt) - strtotime($startsAt) > 7 * 86400) {
$error = 'Ein Termin darf höchstens eine Woche dauern.';
} elseif ($locationInput !== '' && $location === null) {
$error = 'Der Ort ist kein gültiger Link auf unsere Karte - bitte über „Ort auf der Karte wählen“ aussuchen.';
}
if ($error !== null) {
set_flash('error', $error);
redirect($backTo($startsAt));
}
return [$title, $description !== '' ? $description : null, (string) $startsAt, $endsAt, $location['path'] ?? null];
};
/** Termin laden (oder zurueck zum Kalender). */
$loadEntry = static function (int $id) use ($pdo, $backTo): array {
$stmt = $pdo->prepare('SELECT * FROM calendar_entries WHERE id = ?');
$stmt->execute([$id]);
$entry = $stmt->fetch();
if (!$entry) {
set_flash('error', 'Diesen Termin gibt es nicht (mehr).');
redirect($backTo(null));
}
return $entry;
};
switch ($action) {
case 'create':
[$title, $description, $startsAt, $endsAt, $locationPath] = $readInput();
$text = $title . "\n" . (string) $description;
if (moderation_blocks($text, 'Kalender-Termin')) {
set_flash('error', 'Der Termin enthält ein Wort, das hier nicht erlaubt ist.');
redirect($backTo($startsAt));
}
if (!security_throttle('calendar')) {
set_flash('error', 'Du hast in der letzten Stunde schon viele Termine eingetragen. Bitte warte etwas.');
redirect($backTo($startsAt));
}
[$status, $note] = moderation_initial_status('calendar', $text);
$audience = calendar_audience_input(null, $canLead);
$pdo->prepare(
'INSERT INTO calendar_entries (user_id, title, description, starts_at, ends_at, location_path, audience, status, moderation_note) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'
)->execute([$myId, $title, $description, $startsAt, $endsAt, $locationPath, $audience, $status, $note]);
$entryId = (int) $pdo->lastInsertId();
// Wer einlaedt, ist natuerlich dabei
$pdo->prepare('INSERT INTO calendar_participants (entry_id, user_id) VALUES (?, ?)')->execute([$entryId, $myId]);
set_flash('success', $status === 'pending'
? 'Termin eingetragen. Für alle sichtbar nach einer kurzen Freigabe durch die Moderation (' . mb_strtolower((string) $note) . ').'
: 'Termin eingetragen.');
redirect($backTo($startsAt, $entryId));
case 'update':
$entry = $loadEntry((int) ($_POST['id'] ?? 0));
if ((int) $entry['user_id'] !== $myId) {
set_flash('error', 'Nur wer den Termin eingetragen hat, kann ihn bearbeiten.');
redirect($backTo($entry['starts_at'], (int) $entry['id']));
}
[$title, $description, $startsAt, $endsAt, $locationPath] = $readInput();
$text = $title . "\n" . (string) $description;
if (moderation_blocks($text, 'Kalender-Termin')) {
set_flash('error', 'Der Termin enthält ein Wort, das hier nicht erlaubt ist.');
redirect($backTo($startsAt, (int) $entry['id']));
}
// Wartet er schon auf Freigabe, bleibt das so; sonst neu pruefen (Links, Filterwoerter)
[$status, $note] = moderation_initial_status('calendar', $text);
if ($entry['status'] === 'pending') {
[$status, $note] = ['pending', $entry['moderation_note']];
}
$audience = calendar_audience_input((string) ($entry['audience'] ?? 'all'), $canLead);
$pdo->prepare(
'UPDATE calendar_entries SET title = ?, description = ?, starts_at = ?, ends_at = ?, location_path = ?, audience = ?, status = ?, moderation_note = ?, updated_at = ? WHERE id = ?'
)->execute([$title, $description, $startsAt, $endsAt, $locationPath, $audience, $status, $note, date('Y-m-d H:i:s'), (int) $entry['id']]);
set_flash('success', $status === 'pending' ? 'Termin gespeichert - für alle sichtbar nach der Freigabe.' : 'Termin gespeichert.');
redirect($backTo($startsAt, (int) $entry['id']));
case 'delete':
$entry = $loadEntry((int) ($_POST['id'] ?? 0));
$isAuthor = (int) $entry['user_id'] === $myId;
if (!$isAuthor && (!moderation_can() || !calendar_can_view($entry, $canLead, $myId))) {
set_flash('error', 'Diesen Termin darfst du nicht löschen.');
redirect($backTo($entry['starts_at'], (int) $entry['id']));
}
$pdo->prepare('DELETE FROM calendar_entries WHERE id = ?')->execute([(int) $entry['id']]);
moderation_clear_reports('calendar', (int) $entry['id']);
if (!$isAuthor) {
admin_log('🗓️ Kalender-Termin gelöscht (Moderation)', [
'Von' => admin_log_user((int) $entry['user_id']),
'Termin' => $entry['title'] . ' – ' . date('d.m.Y H:i', strtotime((string) $entry['starts_at'])) . ' Uhr',
], 'warning', 'events');
}
set_flash('success', 'Termin gelöscht.');
redirect($backTo($entry['starts_at']));
case 'join':
case 'leave':
$entry = $loadEntry((int) ($_POST['id'] ?? 0));
$canSee = ($entry['status'] === 'visible' || (int) $entry['user_id'] === $myId || moderation_can())
&& calendar_can_view($entry, $canLead, $myId);
if (!$canSee) {
set_flash('error', 'Diesen Termin gibt es nicht (mehr).');
redirect($backTo(null));
}
if ($action === 'join' && !calendar_can_join($entry, $canLead)) {
set_flash('error', 'Bei diesem Termin tragen sich nur die Sedes Luminis ein.');
redirect($backTo($entry['starts_at'], (int) $entry['id']));
}
if ($action === 'join') {
try {
$pdo->prepare('INSERT INTO calendar_participants (entry_id, user_id) VALUES (?, ?)')->execute([(int) $entry['id'], $myId]);
} catch (PDOException $e) {
// schon dabei
}
} else {
$pdo->prepare('DELETE FROM calendar_participants WHERE entry_id = ? AND user_id = ?')->execute([(int) $entry['id'], $myId]);
}
redirect($backTo($entry['starts_at'], (int) $entry['id']));
default:
set_flash('error', 'Unbekannte Aktion.');
redirect('/calendar.php');
}