diff --git a/README.md b/README.md index c6b6b87..546ba34 100644 --- a/README.md +++ b/README.md @@ -740,6 +740,25 @@ Zentral in `includes/security.php` (Grenzen in `SECURITY_LIMITS`): - **Sofort eingreifen:** In der Benutzerverwaltung pro Konto „Abmelden erzwingen“ (alle Sitzungen beenden) und „Sperren und überall abmelden“ - über `users.session_epoch`. +## Kalender + +**Kalender** im Menü (`calendar.php`) zeigt Raids (gold) und Events (blau) als Monatsübersicht mit +Terminliste darunter - live aus der Bot-API, also ohne doppelte Datenhaltung: was im Discord bzw. +auf den Seiten Raids/Events angelegt wird, steht automatisch drin. Wiederkehrende Events werden im +Intervall fortgeschrieben. Klick auf einen Termin führt zum Raid bzw. zu den Events; auf dem Handy +zeigt das Raster Punkte und ein Tipp auf den Tag springt zu seinen Terminen. Man sieht, was man +sehen darf (`raids.view` / `events.view`). Mit `events.manage` lässt sich der Kalender unten auf der +Seite **öffentlich** schalten: dann auch ohne Anmeldung sichtbar (nur Titel und Uhrzeit, keine +Anmeldungen/Kanäle) und oben auf der Startseite verlinkt („Termine“). + +**Eigene Termine:** Jedes Mitglied kann über „+ Termin eintragen“ selbst etwas in den Kalender +stellen (grün, Tabelle `calendar_entries`) - z.B. „Mobs farmen um 20 Uhr mit Damaskar“, mit +optionalem Ende und Beschreibung. Andere schließen sich mit „Bin dabei“ an +(`calendar_participants`, Avatare der Teilnehmer). Bearbeiten darf der Veranstalter, löschen auch +die Moderation. Es gelten dieselben Regeln wie bei Kommentaren: Schimpfwortfilter, Termine mit +Links bzw. von neuen Mitgliedern erst nach Freigabe (Moderation → Freigabe), Melden-Knopf, +höchstens 8 neue Termine pro Stunde (`calendar_action.php`). + ## Moderation (Galeriebilder und Kommentare) `includes/moderation.php`, Seite **Admin → Moderation** (`moderation.php`, Berechtigung diff --git a/admin/settings_action.php b/admin/settings_action.php index a9baebd..e56e9f2 100644 --- a/admin/settings_action.php +++ b/admin/settings_action.php @@ -24,6 +24,7 @@ $settingLabels = [ 'discord_unlink_allowed' => 'Mitglieder dürfen ihre Discord-Verknüpfung lösen', 'contributions_history_public' => 'Lumipunkte-Verlauf für alle sichtbar', 'moderation_all' => 'Alle neuen Bilder und Kommentare manuell freigeben', + 'calendar_public' => 'Kalender öffentlich (ohne Anmeldung)', ]; admin_log('⚙️ Einstellung geändert', [ 'Einstellung' => $settingLabels[$key] ?? $key, diff --git a/assets/css/style.css b/assets/css/style.css index a8e4ae3..156dcdc 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -5308,3 +5308,131 @@ span.reaction { cursor: default; } .filter-word-form input[type="text"] { width: auto; } .filter-word select { -webkit-appearance: none; appearance: none; flex: 0 0 auto; padding: 0.05rem 0.45rem; border-radius: 999px; background: rgba(255, 255, 255, 0.06); } .filter-word select:hover { color: var(--text); } + +/* ---- Kalender ---- */ +.calendar-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; } +.calendar-head h1 { margin-bottom: 0.2rem; } +.calendar-nav { display: flex; align-items: center; gap: 0.5rem; } +.calendar-nav .icon-button { font-size: 1.3rem; line-height: 1; text-decoration: none; } +.calendar-month { min-width: 10.5rem; text-align: center; font-size: 1.15rem; color: var(--gold); } +.calendar-legend { display: flex; gap: 0.5rem; margin: 0.9rem 0 0.7rem; } +.calendar-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; } +.calendar-chip .icon { width: 14px; height: 14px; } + +.calendar-grid { + display: grid; + grid-template-columns: repeat(7, minmax(0, 1fr)); + gap: 4px; +} +.calendar-weekday { padding: 0.3rem; text-align: center; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); text-transform: uppercase; } +.calendar-day { + display: flex; + flex-direction: column; + gap: 3px; + min-height: 6.5rem; + padding: 0.35rem; + border-radius: 8px; + border: 1px solid var(--border); + background: rgba(255, 255, 255, 0.02); + min-width: 0; +} +.calendar-day.is-outside { opacity: 0.35; } +.calendar-day.is-today { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); background: rgba(201, 162, 39, 0.06); } +.calendar-date { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); } +.calendar-day.is-today .calendar-date { color: var(--gold); } +.calendar-entry { + display: block; + padding: 0.1rem 0.35rem; + border-radius: 5px; + font-size: 0.74rem; + line-height: 1.35; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + color: var(--text); +} +a.calendar-entry:hover { text-decoration: none; filter: brightness(1.25); } +.calendar-entry.is-past { opacity: 0.55; } +.calendar-time { font-weight: 700; font-variant-numeric: tabular-nums; } +.calendar-more { font-size: 0.72rem; color: var(--text-muted); padding-left: 0.35rem; } +.calendar-dots { display: none; gap: 3px; margin-top: auto; } +.calendar-dots i { width: 7px; height: 7px; border-radius: 50%; } + +/* Farben: Raid gold, Event blau */ +.calendar-raid { background: rgba(201, 162, 39, 0.2); border-left: 3px solid var(--gold); } +.calendar-event { background: rgba(88, 101, 242, 0.2); border-left: 3px solid #5865f2; } +.calendar-chip.calendar-raid, .calendar-chip.calendar-event { border-left: none; } +.calendar-dots i.calendar-raid { background: var(--gold); border: 0; } +.calendar-dots i.calendar-event { background: #5865f2; border: 0; } + +.calendar-agenda { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; } +.calendar-agenda-day { display: flex; gap: 1rem; align-items: flex-start; } +.calendar-agenda-day.is-past { opacity: 0.55; } +.calendar-agenda-date { flex: 0 0 4.5rem; display: flex; flex-direction: column; line-height: 1.15; } +.calendar-agenda-date strong { font-size: 1.35rem; } +.calendar-agenda-date span { font-size: 0.78rem; color: var(--text-muted); } +.calendar-agenda-day.is-today .calendar-agenda-date { color: var(--gold); } +.calendar-agenda-entries { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; } +.calendar-agenda-entry { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.25rem 0.8rem; + padding: 0.45rem 0.75rem; + border-radius: 8px; + color: var(--text); + font-size: 0.9rem; +} +a.calendar-agenda-entry:hover { text-decoration: none; filter: brightness(1.2); } +.calendar-agenda-title { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 600; } +.calendar-agenda-title .icon { width: 15px; height: 15px; } +.calendar-agenda-entry .text-muted { font-size: 0.8rem; } +.calendar-public-toggle { margin-top: 1.2rem; } +.navbar-calendar .icon { width: 16px; height: 16px; } + +@media (max-width: 700px) { + .calendar-day { min-height: 3.2rem; align-items: center; padding: 0.3rem 0.1rem; } + .calendar-entry, .calendar-more { display: none; } + .calendar-dots { display: flex; } + .calendar-month { min-width: 8rem; } + .calendar-agenda-date { flex-basis: 3.6rem; } +} +.calendar-day { position: relative; } +.calendar-day-link { display: none; } +.calendar-agenda-day { scroll-margin-top: 5rem; } +.calendar-agenda-day:target .calendar-agenda-entries { animation: calendar-flash 1.2s ease; } +@keyframes calendar-flash { 30% { filter: brightness(1.6); } } +@media (max-width: 700px) { .calendar-day-link { display: block; position: absolute; inset: 0; } } + +/* Kalender: Termine der Mitglieder (gruen) */ +.calendar-member { background: rgba(59, 165, 93, 0.18); border-left: 3px solid #3ba55d; } +.calendar-chip.calendar-member { border-left: none; } +.calendar-dots i.calendar-member { background: #3ba55d; border: 0; } +.calendar-new { margin: 0.9rem 0 0.2rem; } +.calendar-new > summary { list-style: none; display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; } +.calendar-new > summary::-webkit-details-marker { display: none; } +.calendar-new[open] > summary { opacity: 0.7; } +.calendar-form { margin-top: 0.8rem; padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: rgba(0, 0, 0, 0.2); max-width: 640px; } +.calendar-form label { display: flex; flex-direction: column; gap: 0.3rem; } +.calendar-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; } +.calendar-form input[type="datetime-local"] { color-scheme: dark; } +@media (max-width: 600px) { .calendar-form-row { grid-template-columns: 1fr; } } + +.calendar-member-entry { padding: 0.6rem 0.8rem; border-radius: 10px; display: flex; flex-direction: column; gap: 0.45rem; scroll-margin-top: 5rem; } +.calendar-member-entry:target { box-shadow: 0 0 0 2px #3ba55d; } +.calendar-member-entry.is-pending { border-left-style: dashed; opacity: 0.85; } +.calendar-member-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.8rem; } +.calendar-member-title { font-size: 1rem; } +.calendar-member-author { display: inline-flex; align-items: center; gap: 0.35rem; margin-left: auto; font-size: 0.85rem; } +.calendar-member-description { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; } +.calendar-member-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; } +.calendar-participants { display: flex; align-items: center; } +.calendar-participants .avatar, .calendar-participants .avatar-wrap { margin-right: -6px; border: 2px solid #232323; border-radius: 50%; } +.calendar-participants .text-muted { margin-left: 0.8rem; font-size: 0.82rem; } +.calendar-member-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; } +.calendar-edit { position: relative; } +.calendar-edit > summary { list-style: none; cursor: pointer; } +.calendar-edit > summary::-webkit-details-marker { display: none; } +.calendar-edit[open] .calendar-form { position: absolute; right: 0; z-index: 15; width: min(560px, 90vw); background: #232323; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6); } +.moderation-calendar-icon { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 8px; background: rgba(59, 165, 93, 0.15); color: #57d68d; flex-shrink: 0; } +.moderation-calendar-icon .icon { width: 28px; height: 28px; } diff --git a/calendar.php b/calendar.php new file mode 100644 index 0000000..a5803e9 --- /dev/null +++ b/calendar.php @@ -0,0 +1,312 @@ + 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']; +$monthLabel = $monthNames[(int) date('n', $monthStart)] . ' ' . date('Y', $monthStart); + +// ---- Termine sammeln: [timestamp, type, title, detail, url] ---- +$entries = []; +$errors = []; +if ($showRaids) { + try { + foreach (fetch_raids('all') as $raid) { + $time = (int) ($raid['timestamp'] ?? 0); + if ($time < $monthStart || $time >= $monthEnd) { + continue; + } + $signups = is_array($raid['signups'] ?? null) ? count($raid['signups']) : 0; + $max = (int) ($raid['max_slots'] ?? 0); + $archived = !empty($raid['archived']); + $entries[] = [ + 'time' => $time, + 'type' => 'raid', + 'title' => (string) ($raid['title'] ?? 'Raid'), + 'detail' => $loggedIn ? $signups . ($max > 0 ? ' / ' . $max : '') . ' angemeldet' : '', + 'url' => $loggedIn ? '/raids.php' . ($archived ? '?status=archived' : '') . '#raid-' . (int) $raid['raid_id'] : null, + 'past' => $time < time(), + ]; + } + } catch (Throwable $e) { + $errors[] = 'Raids konnten nicht geladen werden.'; + } +} +if ($showEvents) { + try { + foreach (fetch_events() as $event) { + $next = (int) ($event['next_run'] ?? 0); + $interval = (int) ($event['interval_seconds'] ?? 0); + if ($next <= 0) { + continue; + } + // Wiederkehrend: vom naechsten Termin an im Intervall (hoechstens 200 im Monat) + $times = []; + if ($interval > 0) { + $first = $next; + if ($first < $monthStart) { + $first += (int) ceil(($monthStart - $first) / $interval) * $interval; + } + for ($t = $first; $t < $monthEnd && count($times) < 200; $t += $interval) { + $times[] = $t; + } + } elseif ($next >= $monthStart && $next < $monthEnd) { + $times[] = $next; + } + $channel = (string) ($event['channel_name'] ?? ''); + foreach ($times as $time) { + $entries[] = [ + 'time' => $time, + 'type' => 'event', + 'title' => (string) ($event['name'] ?? 'Event'), + 'detail' => $loggedIn ? trim(($interval > 0 ? event_interval_label($interval) : 'einmalig') . ($channel !== '' ? ' · #' . $channel : '')) : '', + 'url' => $loggedIn ? '/events.php' : null, + 'past' => $time < time(), + ]; + } + } + } catch (Throwable $e) { + $errors[] = 'Events konnten nicht geladen werden.'; + } +} +// ---- Termine der Mitglieder ---- +if ($showMember) { + try { + // Noch nicht freigegebene sehen nur der Verfasser und die Moderation + $stmt = db()->prepare( + "SELECT e.*, COALESCE(NULLIF(u.display_name, ''), u.username) AS author, u.avatar_filename, u.username, u.display_name + FROM calendar_entries e JOIN users u ON u.id = e.user_id + WHERE e.starts_at >= ? AND e.starts_at < ? AND u.status = 'active' + AND (e.status = 'visible' OR e.user_id = ? OR ?) + ORDER BY e.starts_at" + ); + $stmt->execute([date('Y-m-d H:i:s', $monthStart), date('Y-m-d H:i:s', $monthEnd), $myId, $isModerator ? 1 : 0]); + $memberEntries = $stmt->fetchAll(); + + $participants = []; + if ($loggedIn && $memberEntries) { + $ids = array_map('intval', array_column($memberEntries, 'id')); + $placeholders = implode(',', array_fill(0, count($ids), '?')); + $p = db()->prepare( + "SELECT p.entry_id, u.id, u.username, u.display_name, u.avatar_filename + FROM calendar_participants p JOIN users u ON u.id = p.user_id + WHERE p.entry_id IN ($placeholders) AND u.status = 'active' ORDER BY p.created_at" + ); + $p->execute($ids); + foreach ($p->fetchAll() as $row) { + $participants[(int) $row['entry_id']][] = $row; + } + } + $reportedEntries = $loggedIn ? moderation_my_reports('calendar', array_map('intval', array_column($memberEntries, 'id'))) : []; + + foreach ($memberEntries as $row) { + $id = (int) $row['id']; + $time = strtotime((string) $row['starts_at']); + $people = $participants[$id] ?? []; + $entries[] = [ + 'time' => $time, + 'type' => 'member', + 'title' => (string) $row['title'], + 'detail' => $loggedIn ? 'von ' . $row['author'] . ' · ' . count($people) . ' dabei' : '', + 'url' => $loggedIn ? '#termin-' . $id : null, + 'past' => $time < time(), + 'id' => $id, + 'row' => $row, + 'people' => $people, + 'joined' => in_array($myId, array_map('intval', array_column($people, 'id')), true), + 'reported' => isset($reportedEntries[$id]), + ]; + } + } catch (PDOException $e) { + // Tabellen kommen erst mit dem naechsten Schema-Abgleich + } +} + +usort($entries, static fn (array $a, array $b): int => $a['time'] <=> $b['time']); +$byDay = []; +foreach ($entries as $entry) { + $byDay[date('Y-m-d', $entry['time'])][] = $entry; +} + +// Raster: volle Wochen von Montag bis Sonntag +$gridStart = strtotime('monday this week', $monthStart); +$gridEnd = strtotime('+1 day', strtotime('sunday this week', $monthEnd - 1)); +$weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']; +$today = date('Y-m-d'); +$dayNames = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']; + +/** Formularfelder fuer "Termin eintragen" und "Bearbeiten". */ +$entryFields = static function (?array $row): string { + $start = $row ? date('Y-m-d\TH:i', strtotime((string) $row['starts_at'])) : date('Y-m-d\T20:00', strtotime('+1 day')); + $end = $row && $row['ends_at'] ? date('Y-m-d\TH:i', strtotime((string) $row['ends_at'])) : ''; + return '' + . '
+ = $showRaids && $showEvents ? 'Raids und Events' : ($showRaids ? 'Raids' : 'Events') ?> der Legion im Überblick - + dieselben Termine wie im Discord, immer aktuell= $showMember ? ', dazu Termine, die Mitglieder selbst eintragen' : '' ?>. +
+In diesem Monat stehen keine Termine an.
+ += gallery_comment_html((string) $row['description']) ?>
+ +
' . e((string) $entry['title']) . '' + . (!empty($entry['description']) ? '
' + . (!empty($entry['moderation_note']) ? '' . nl2br(e((string) $entry['description']), false) : '') . '
Grund: ' . e((string) $entry['moderation_note']) . '
' : '') + . $reportList('calendar', (int) $entry['id']) + . $actions('calendar', (int) $entry['id'], $which) . '