LuminaWebsite/activity.php
Maaxxs 392994e1cd Activity check (website + bot), videos in the wiki, contributor search list
- Activity check: created on the website (activity.php, activity.manage) or with /aktivitaetscheck; the bot posts "I'm in" / "I'm out" buttons; title, text, color, image and button labels are configurable with a live preview; deadline; consequences for non-responders (DM, remove/add role, optionally also for "I'm out"); close early or cancel; overview of in / out / pending
- Wiki: a video link alone on a line (YouTube incl. Shorts/start time, Twitch, Vimeo, .mp4/.webm) becomes an embedded player, plus a "Video" button in the editor
- Wiki: "Add contributor" as a search list with avatar, group and class instead of a dropdown

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 01:11:49 +02:00

319 lines
21 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
/**
* Aktivitaetschecks: im Discord einen Check mit "Ich bin da" / "Ich bin nicht da" posten,
* Rueckmeldungen verfolgen und den Check (vorzeitig) abschliessen. Den Check selbst verwaltet
* der Bot (cogs/activity.py) - diese Seite spricht mit ihm ueber includes/activity_api.php.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/activity_api.php';
require_permission('activity.manage');
$detailId = (int) ($_GET['id'] ?? 0);
$apiError = null;
$checks = [];
$detail = null;
try {
if ($detailId > 0) {
$detail = activity_api_request('GET', '/' . $detailId)['check'] ?? null;
} else {
$checks = activity_api_request('GET', '', ['guild_id' => events_guild_id()])['checks'] ?? [];
}
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
if ($detailId > 0 && !$detail && !$apiError) {
show_not_found();
}
// Kanaele und Rollen fuer das Formular
$channels = [];
$roles = [];
$pickerError = null;
if ($detailId === 0) {
try {
$channels = guilds_api_request('/channels')['channels'] ?? [];
$roles = guilds_api_request('/roles')['roles'] ?? [];
} catch (Throwable $e) {
$pickerError = $e->getMessage();
}
}
/** Discord-IDs -> Website-Konten (Name + Profilbild), fuer die Listen in der Detailansicht. */
$usersByDiscord = [];
if ($detail) {
$ids = array_merge(array_column($detail['responses'] ?? [], 'user_id'), array_column($detail['pending'] ?? [], 'user_id'),
array_column($detail['result']['missing'] ?? [], 'user_id'));
$ids = array_values(array_unique(array_map('strval', $ids)));
if ($ids) {
$stmt = db()->prepare('SELECT id, username, display_name, avatar_filename, discord_id FROM users WHERE discord_id IN ('
. implode(',', array_fill(0, count($ids), '?')) . ')');
$stmt->execute($ids);
foreach ($stmt->fetchAll() as $row) {
$usersByDiscord[(string) $row['discord_id']] = $row;
}
}
}
$person = static function (string $discordId, string $fallbackName) use ($usersByDiscord): string {
$user = $usersByDiscord[$discordId] ?? null;
$name = $user ? ($user['display_name'] !== '' ? $user['display_name'] : $user['username']) : $fallbackName;
$avatar = avatar_html($user ?: ['id' => $discordId, 'display_name' => $fallbackName], 28);
return '<li class="activity-person">' . $avatar . ($user ? '<a href="/member.php?id=' . (int) $user['id'] . '">' . e($name) . '</a>' : '<span>' . e($name) . '</span>') . '</li>';
};
/** "noch 2 Tage 4 Std." bzw. "vor 3 Std." */
$relative = static function (int $timestamp): string {
$diff = $timestamp - time();
$abs = abs($diff);
$text = $abs >= 86400 ? floor($abs / 86400) . ' Tg. ' . floor(($abs % 86400) / 3600) . ' Std.'
: ($abs >= 3600 ? floor($abs / 3600) . ' Std. ' . floor(($abs % 3600) / 60) . ' Min.' : max(1, (int) floor($abs / 60)) . ' Min.');
return $diff >= 0 ? 'noch ' . $text : 'vor ' . $text;
};
$roleOptions = static function (string $selected = '', bool $withNone = false) use ($roles): string {
$html = $withNone ? '<option value="">– keine –</option>' : '<option value="">– Rolle wählen –</option>';
foreach ($roles as $role) {
$rid = (string) ($role['role_id'] ?? '');
$html .= '<option value="' . e($rid) . '"' . ($rid === $selected ? ' selected' : '') . '>@' . e((string) ($role['name'] ?? '')) . '</option>';
}
return $html;
};
$openChecks = array_values(array_filter($checks, static fn ($c) => ($c['status'] ?? '') === 'open'));
$pastChecks = array_values(array_filter($checks, static fn ($c) => ($c['status'] ?? '') !== 'open'));
$pageTitle = $detail ? 'Aktivitätscheck: ' . $detail['title'] : 'Aktivitätschecks';
$containerWide = true;
include __DIR__ . '/includes/header.php';
?>
<?php if ($apiError): ?>
<div class="panel"><div class="flash flash-error">Der Discord-Bot ist gerade nicht erreichbar: <?= e($apiError) ?></div></div>
<?php endif; ?>
<?php if ($detail): ?>
<?php
$c = $detail['counts'] ?? [];
$isOpen = $detail['status'] === 'open';
$present = array_values(array_filter($detail['responses'] ?? [], static fn ($r) => $r['status'] === 'present'));
$absent = array_values(array_filter($detail['responses'] ?? [], static fn ($r) => $r['status'] === 'absent'));
$missing = $isOpen ? ($detail['pending'] ?? []) : ($detail['result']['missing'] ?? []);
?>
<div class="panel activity-detail-head">
<a href="/activity.php" class="text-muted">‹ Alle Aktivitätschecks</a>
<div class="raid-header">
<h1>📋 <?= e($detail['title']) ?></h1>
<span class="badge <?= $isOpen ? 'badge-active' : '' ?>"><?= $isOpen ? 'Läuft' : ($detail['status'] === 'cancelled' ? 'Abgebrochen' : 'Abgeschlossen') ?></span>
</div>
<p class="text-muted">
#<?= e((string) ($detail['channel_name'] ?? $detail['channel_id'])) ?> · für @<?= e((string) ($detail['target_role_name'] ?? '?')) ?> ·
<?= $isOpen ? 'endet ' . e(date('d.m.Y H:i', (int) $detail['deadline'])) . ' Uhr (' . e($relative((int) $detail['deadline'])) . ')'
: 'beendet ' . e(date('d.m.Y H:i', (int) $detail['closed_at'])) . ' Uhr von ' . e((string) $detail['closed_by']) ?>
<?php if (!empty($detail['jump_url'])): ?> · <a href="<?= e($detail['jump_url']) ?>" target="_blank" rel="noopener">Im Discord ansehen</a><?php endif; ?>
</p>
<?php if ($isOpen): ?>
<div class="activity-actions">
<form method="post" action="/activity_action.php" class="inline-form"
onsubmit="return confirm('Jetzt abschließen? Alle ohne Rückmeldung (<?= (int) ($c['pending'] ?? 0) ?>) bekommen sofort die eingestellten Folgen.');">
<?= csrf_field() ?><input type="hidden" name="action" value="close"><input type="hidden" name="id" value="<?= (int) $detail['check_id'] ?>">
<button type="submit" class="button-success">✓ Jetzt abschließen</button>
</form>
<form method="post" action="/activity_action.php" class="inline-form" onsubmit="return confirm('Ohne Folgen abbrechen?');">
<?= csrf_field() ?><input type="hidden" name="action" value="cancel"><input type="hidden" name="id" value="<?= (int) $detail['check_id'] ?>">
<button type="submit" class="button-secondary">Abbrechen (ohne Folgen)</button>
</form>
</div>
<?php endif; ?>
<div class="activity-consequences">
<strong>Folgen ohne Rückmeldung<?= !empty($detail['apply_to_absent']) ? ' (auch bei „nicht da“)' : '' ?>:</strong>
<?php
$parts = [];
if (!empty($detail['dm_enabled'])) $parts[] = '✉️ PN';
if (!empty($detail['remove_role_id'])) $parts[] = '➖ @' . ($detail['remove_role_name'] ?? $detail['remove_role_id']) . ' entfernen';
if (!empty($detail['add_role_id'])) $parts[] = '➕ @' . ($detail['add_role_name'] ?? $detail['add_role_id']) . ' geben';
?>
<?= $parts ? e(implode(' · ', $parts)) : '<span class="text-muted">keine - nur Liste im Log-Kanal</span>' ?>
<?php if (!$isOpen && !empty($detail['result']) && $detail['status'] === 'closed'): ?>
<br><span class="text-muted">Ergebnis: <?= (int) ($detail['result']['dm_sent'] ?? 0) ?> PN verschickt<?= !empty($detail['result']['dm_failed']) ? ' (' . (int) $detail['result']['dm_failed'] . ' mit geschlossenen PNs)' : '' ?>,
<?= (int) ($detail['result']['roles_changed'] ?? 0) ?> Rollen geändert<?= !empty($detail['result']['role_errors']) ? ', ' . (int) $detail['result']['role_errors'] . ' Fehler (fehlen dem Bot Rechte?)' : '' ?></span>
<?php endif; ?>
</div>
</div>
<div class="activity-columns">
<div class="panel activity-column activity-present">
<h2>✅ Da <span class="chip-count"><?= count($present) ?></span></h2>
<ul><?php foreach ($present as $r): ?><?= $person((string) $r['user_id'], (string) $r['user_name']) ?><?php endforeach; ?></ul>
<?php if (!$present): ?><p class="text-muted">Noch niemand.</p><?php endif; ?>
</div>
<div class="panel activity-column activity-absent">
<h2>❌ Nicht da <span class="chip-count"><?= count($absent) ?></span></h2>
<ul><?php foreach ($absent as $r): ?><?= $person((string) $r['user_id'], (string) $r['user_name']) ?><?php endforeach; ?></ul>
<?php if (!$absent): ?><p class="text-muted">Niemand.</p><?php endif; ?>
</div>
<div class="panel activity-column activity-missing">
<h2>⏳ <?= $isOpen ? 'Noch offen' : 'Ohne Rückmeldung' ?> <span class="chip-count"><?= count($missing) ?></span></h2>
<ul><?php foreach ($missing as $r): ?><?= $person((string) $r['user_id'], (string) ($r['user_name'] ?? $r['name'] ?? '?')) ?><?php endforeach; ?></ul>
<?php if (!$missing): ?><p class="text-muted"><?= $isOpen ? 'Alle haben sich gemeldet 🎉' : 'Alle haben sich gemeldet 🎉' ?></p><?php endif; ?>
</div>
</div>
<?php if (!$isOpen): ?>
<div class="panel">
<form method="post" action="/activity_action.php" onsubmit="return confirm('Diesen Check samt Nachricht im Discord endgültig löschen?');">
<?= csrf_field() ?><input type="hidden" name="action" value="delete"><input type="hidden" name="id" value="<?= (int) $detail['check_id'] ?>">
<button type="submit" class="button-danger button-small">Check löschen</button>
</form>
</div>
<?php endif; ?>
<?php elseif (!$apiError): ?>
<div class="panel">
<div class="raid-header">
<h1>📋 Aktivitätschecks</h1>
<?php if (!$pickerError): ?>
<button type="button" class="button-success" data-toggle-activity-form>+ Neuer Aktivitätscheck</button>
<?php endif; ?>
</div>
<p class="text-muted">
Der Bot postet eine Nachricht mit den Knöpfen „Ich bin da“ und „Ich bin nicht da“. Wer die Zielrolle hat, meldet sich
dort zurück. Zur Frist - oder vorher über „Jetzt abschließen“ - bekommen alle ohne Rückmeldung die eingestellten Folgen.
Im Discord geht das auch mit <code>/aktivitaetscheck</code>.
</p>
<?php if ($pickerError): ?>
<div class="flash flash-error">Kanäle/Rollen konnten nicht geladen werden: <?= e($pickerError) ?></div>
<?php endif; ?>
</div>
<?php if (!$pickerError): ?>
<div class="panel activity-create" id="activity-create" hidden>
<h2>Neuer Aktivitätscheck</h2>
<form method="post" action="/activity_action.php" class="activity-form" id="activity-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<div class="activity-form-grid">
<div class="activity-form-fields">
<fieldset>
<legend>Aussehen</legend>
<label>Titel<input type="text" name="title" maxlength="100" required value="Aktivitätscheck" data-preview="title"></label>
<label>Nachricht<textarea name="message" rows="5" maxlength="3500" required data-preview="message">Hey zusammen! 👋
Bitte meldet euch kurz zurück, ob ihr noch aktiv dabei seid. Einfach unten auf den passenden Knopf klicken.</textarea></label>
<div class="activity-color-row">
<span>Farbe</span>
<?php foreach (ACTIVITY_COLORS as $hex => $label): ?>
<label class="activity-swatch" title="<?= e($label) ?>" style="--swatch: <?= e($hex) ?>">
<input type="radio" name="color" value="<?= e($hex) ?>" <?= $hex === '#c9a227' ? 'checked' : '' ?> data-preview="color">
</label>
<?php endforeach; ?>
<input type="color" name="color_custom" value="#c9a227" title="Eigene Farbe" data-preview="color-custom">
</div>
<label><span>Bild <span class="text-muted">(optional, https-Link)</span></span><input type="url" name="image_url" maxlength="500" placeholder="https://…" data-preview="image"></label>
<div class="activity-row">
<label>Knopf „da“<input type="text" name="yes_label" maxlength="60" placeholder="Ich bin da" data-preview="yes"></label>
<label>Knopf „nicht da“<input type="text" name="no_label" maxlength="60" placeholder="Ich bin nicht da" data-preview="no"></label>
</div>
</fieldset>
<fieldset>
<legend>Wo und für wen</legend>
<label>Kanal
<select name="channel_id" required>
<option value="">– Kanal wählen –</option>
<?php foreach ($channels as $channel): ?>
<option value="<?= e((string) $channel['channel_id']) ?>" <?= empty($channel['can_post']) ? 'disabled' : '' ?>>
#<?= e((string) $channel['name']) ?><?= !empty($channel['category']) ? ' (' . e((string) $channel['category']) . ')' : '' ?><?= empty($channel['can_post']) ? ' – Bot darf hier nicht posten' : '' ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label><span>Wer soll sich melden? <span class="text-muted">(Zielrolle)</span></span>
<select name="target_role_id" required data-preview="role"><?= $roleOptions() ?></select>
</label>
<label class="checkbox-label"><input type="checkbox" name="ping_role" value="1" checked data-preview="ping"> Zielrolle beim Posten pingen</label>
<div class="activity-row">
<label>Zeit zum Zurückmelden<input type="number" name="duration_value" min="1" max="60" value="3" required data-preview="duration"></label>
<label>&nbsp;<select name="duration_unit" data-preview="duration">
<option value="hours">Stunden</option>
<option value="days" selected>Tage</option>
</select></label>
</div>
</fieldset>
<fieldset>
<legend>Was passiert ohne Rückmeldung?</legend>
<label class="checkbox-label"><input type="checkbox" name="dm_enabled" value="1" data-toggle-dm> Private Nachricht (PN) schicken</label>
<label class="activity-dm" hidden><span>Text der PN <span class="text-muted">- Platzhalter: {name}, {titel}, {server}</span></span>
<textarea name="dm_message" rows="3" maxlength="1800"><?= e(ACTIVITY_DEFAULT_DM) ?></textarea>
</label>
<div class="activity-row">
<label>Rolle entfernen<select name="remove_role_id"><?= $roleOptions('', true) ?></select></label>
<label><span>Rolle geben <span class="text-muted">(z.B. „Inaktiv“)</span></span><select name="add_role_id"><?= $roleOptions('', true) ?></select></label>
</div>
<label class="checkbox-label"><input type="checkbox" name="apply_to_absent" value="1"> Folgen auch für alle mit „Ich bin nicht da“</label>
<p class="field-hint">Die Liste aller ohne Rückmeldung landet immer im Log-Kanal. Rollen ändern kann der Bot nur bei Rollen unterhalb seiner eigenen.</p>
</fieldset>
</div>
<div class="activity-preview-wrap">
<span class="event-preview-label">Vorschau in Discord</span>
<div class="discord-preview">
<div class="discord-ping" data-out="ping">@<span data-out="role">Rolle</span></div>
<div class="discord-embed" data-out="embed">
<strong class="discord-embed-title">📋 <span data-out="title">Aktivitätscheck</span></strong>
<div class="discord-embed-text" data-out="message"></div>
<div class="discord-embed-field"><b>Rückmeldungen</b><span>✅ 0 da · ❌ 0 nicht da · ⏳ … offen</span></div>
<div class="discord-embed-field"><b>⏰ Rückmeldung bis</b><span data-out="deadline">…</span></div>
<img class="discord-embed-image" data-out="image" alt="" hidden>
<div class="discord-embed-footer">Aktivitätscheck #…</div>
</div>
<div class="discord-buttons">
<span class="discord-button discord-button-green">✅ <span data-out="yes">Ich bin da</span></span>
<span class="discord-button">❌ <span data-out="no">Ich bin nicht da</span></span>
</div>
</div>
</div>
</div>
<div class="actions">
<button type="submit" class="button-success">📋 Check jetzt posten</button>
<button type="button" class="button-secondary" data-toggle-activity-form>Abbrechen</button>
</div>
</form>
</div>
<?php endif; ?>
<div class="panel">
<h2>Laufende Checks <span class="chip-count"><?= count($openChecks) ?></span></h2>
<?php if (!$openChecks): ?><p class="text-muted">Gerade läuft kein Aktivitätscheck.</p><?php endif; ?>
<div class="activity-cards">
<?php foreach ($openChecks as $check): ?>
<?php
$c = $check['counts'] ?? [];
$total = max(1, (int) ($c['present'] ?? 0) + (int) ($c['absent'] ?? 0) + (int) ($c['pending'] ?? 0));
?>
<a class="activity-card" href="/activity.php?id=<?= (int) $check['check_id'] ?>" style="--accent: #<?= e(str_pad(dechex((int) $check['color']), 6, '0', STR_PAD_LEFT)) ?>">
<strong>📋 <?= e($check['title']) ?></strong>
<span class="text-muted">#<?= e((string) ($check['channel_name'] ?? '?')) ?> · @<?= e((string) ($check['target_role_name'] ?? '?')) ?> · <?= e($relative((int) $check['deadline'])) ?></span>
<div class="activity-bar" title="<?= (int) ($c['present'] ?? 0) ?> da, <?= (int) ($c['absent'] ?? 0) ?> nicht da, <?= (int) ($c['pending'] ?? 0) ?> offen">
<i class="bar-present" style="width: <?= round(100 * (int) ($c['present'] ?? 0) / $total, 1) ?>%"></i>
<i class="bar-absent" style="width: <?= round(100 * (int) ($c['absent'] ?? 0) / $total, 1) ?>%"></i>
</div>
<span class="activity-counts">✅ <?= (int) ($c['present'] ?? 0) ?> · ❌ <?= (int) ($c['absent'] ?? 0) ?> · ⏳ <?= (int) ($c['pending'] ?? 0) ?> offen</span>
</a>
<?php endforeach; ?>
</div>
</div>
<?php if ($pastChecks): ?>
<div class="panel">
<h2>Beendet</h2>
<ul class="activity-past">
<?php foreach ($pastChecks as $check): ?>
<?php $c = $check['counts'] ?? []; ?>
<li>
<a href="/activity.php?id=<?= (int) $check['check_id'] ?>"><strong><?= e($check['title']) ?></strong></a>
<span class="text-muted"><?= e(date('d.m.Y', (int) ($check['closed_at'] ?: $check['deadline']))) ?> ·
<?= $check['status'] === 'cancelled' ? 'abgebrochen' : '✅ ' . (int) ($c['present'] ?? 0) . ' · ❌ ' . (int) ($c['absent'] ?? 0) . ' · ohne Rückmeldung: ' . count($check['result']['missing'] ?? []) ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/activity.js')) ?>"></script>
<?php endif; ?>
<?php include __DIR__ . '/includes/footer.php'; ?>