LuminaWebsite/reports.php
Maaxxs 17ccd3e26f Discord bot as overview: everything is managed on the website, raid signup in one click
The bot (Aion2_RaidPlaner, deployed 2026-09-25) has no slash commands any more. Raids,
premades, events, activity checks and reports are created and managed only here; in Discord
members sign up for raids, answer invitations and activity checks and report players.

- Raid signup works the same in Discord and here: the bot assigns the group (perform_signup),
  the website only sends the wish (raid_signup(..., $wish)) and shows the reason when it did
  not fit (locked, role full, raid full). raid_wish_is_sensible() and the role constants are
  gone. Declining ("Abmelden") now keeps the player under "Abgemeldet" (raid_decline, new bot
  endpoint .../decline) like in Discord; the raid card shows "Du hast dich abgemeldet" with
  "Doch anmelden". Class input is checked against AION_CLASSES.
- The Discord message shows the raid lead and the Lumipunkte: raid_create_action/raid_edit_action
  send lead_id/lead_name/points_text, raid_sync_extras() on raids.php pushes them for raids
  where the bot is missing them (at most 3 per page view, follows changed raid IDs).
- bot_api.php?action=member: main class (profile choice) and whether the person has an
  (active) account - the bot preselects the class and hints that Lumipunkte need an account.
- New page Verwaltung -> Discord-Bot (admin/bot.php, includes/discord_bot.php, permission
  bot.manage, on update granted to groups with raids.manage; schema 53): raid, log and report
  channel, post the premade overview (updates itself) and the report panel (the bot replaces
  the previous one), resync all raid messages (reposted raids move their settings via
  raid_rename_id). Audit area "Discord-Bot", sidebar entry with a new bot icon.
- Reports: after picking a player in the filter, delete all of their reports at once
  (DELETE /api/reports/user/{id}), which also lifts the auto-mute.
- Calendar and raid logs no longer count declined players as signed up / on the bench.
- Texts that mentioned bot commands (events, activity check, config example, README) updated;
  privacy policy mentions the main-class lookup and that declines stay visible. Patch notes.

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

397 lines
22 KiB
PHP

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php';
require_permission('reports.view');
$canManageReports = user_has_permission('reports.manage');
$status = (string) ($_GET['status'] ?? 'active');
if (!in_array($status, ['active', 'archived', 'all'], true)) {
$status = 'active';
}
$allReports = [];
$apiError = null;
try {
$allReports = fetch_reports(true);
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
$reports = array_values(array_filter($allReports, function (array $r) use ($status) {
$isArchived = !empty($r['archived']);
if ($status === 'active') {
return !$isArchived;
}
if ($status === 'archived') {
return $isArchived;
}
return true;
}));
// Discord-IDs aus den Reports auf verknuepfte Website-Accounts abbilden, damit echte
// Avatare/Anzeigenamen statt roher Discord-Tags gezeigt werden koennen (wie bei Premades).
$allDiscordIds = [];
foreach ($allReports as $r) {
$allDiscordIds[] = (int) ($r['reported_id'] ?? 0);
$allDiscordIds[] = (int) ($r['reporter_id'] ?? 0);
}
$allDiscordIds = array_values(array_unique(array_filter($allDiscordIds)));
$namesByDiscordId = [];
$linkedUsersByDiscordId = [];
if (!empty($allDiscordIds)) {
$placeholders = implode(',', array_fill(0, count($allDiscordIds), '?'));
$stmt = db()->prepare("SELECT id, discord_id, discord_username, display_name, avatar_filename FROM users WHERE discord_id IN ($placeholders)");
$stmt->execute($allDiscordIds);
foreach ($stmt->fetchAll() as $row) {
$name = $row['display_name'] !== '' ? $row['display_name'] : $row['discord_username'];
$namesByDiscordId[(int) $row['discord_id']] = $name;
$linkedUsersByDiscordId[(int) $row['discord_id']] = $row;
}
}
// Fuer das "Nach Nutzer filtern"-Dropdown: jeder gemeldete Nutzer im aktuell gefilterten
// Status genau einmal, alphabetisch sortiert.
$reportedUsersList = [];
$seenReportedIds = [];
foreach ($reports as $r) {
$rid = (int) ($r['reported_id'] ?? 0);
if (isset($seenReportedIds[$rid])) {
continue;
}
$seenReportedIds[$rid] = true;
$reportedName = premade_name_for($rid, $namesByDiscordId, (string) ($r['reported_name'] ?? ''));
$reportedUsersList[] = [
'id' => $rid,
'name' => $reportedName,
'avatarUser' => premade_avatar_user($rid, $linkedUsersByDiscordId, $reportedName),
];
}
usort($reportedUsersList, fn (array $a, array $b): int => strcasecmp($a['name'], $b['name']));
$statusLabels = ['active' => 'Aktiv', 'archived' => 'Archiviert', 'all' => 'Alle'];
$emptyLabels = [
'active' => 'Aktuell liegen keine aktiven Reports vor.',
'archived' => 'Es sind keine archivierten Reports vorhanden.',
'all' => 'Aktuell liegen keine Reports vor.',
];
// Einstellungen nur laden, wenn sie auch angezeigt werden - unnoetige API-Calls fuer reine
// Betrachter ohne reports.manage vermeiden.
$muteThreshold = null;
$roleWeights = [];
$muteExclusions = [];
$settingsError = null;
if ($canManageReports) {
try {
$muteThreshold = fetch_mute_threshold();
$roleWeights = fetch_report_weights();
$muteExclusions = fetch_mute_exclusions();
} catch (Throwable $e) {
$settingsError = $e->getMessage();
}
}
$pageTitle = 'Reports';
include __DIR__ . '/includes/header.php';
?>
<div class="panel panel-filter-bar">
<div class="raid-header">
<h1>Reports</h1>
</div>
<p class="text-muted">Eingegangene Spieler-Meldungen aus Discord („Spieler melden“ im Melde-Panel des Bots). Reports zählen für den Auto-Mute Punkte statt einer reinen Anzahl - die Gewichtung lässt sich unten pro Rolle einstellen.</p>
<div class="filter-tabs">
<?php foreach ($statusLabels as $value => $label): ?>
<a href="/reports.php?status=<?= e($value) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
<?php endforeach; ?>
</div>
<?php if (!empty($reportedUsersList)): ?>
<div class="user-filter" id="report-user-filter">
<button type="button" class="user-filter-trigger" id="report-user-filter-trigger" aria-haspopup="listbox" aria-expanded="false">
<span class="user-filter-trigger-content" id="report-user-filter-trigger-content">
<span class="user-filter-all-icon"><?= icon('users') ?></span>
<span class="user-filter-option-name">Alle gemeldeten Nutzer</span>
</span>
<?= icon('chevron-down') ?>
</button>
<div class="user-filter-panel" id="report-user-filter-panel" role="listbox" hidden>
<button type="button" class="user-filter-option selected" data-user-id="" data-user-name="Alle gemeldeten Nutzer" role="option" aria-selected="true">
<span class="user-filter-option-visual">
<span class="user-filter-all-icon"><?= icon('users') ?></span>
<span class="user-filter-option-name">Alle gemeldeten Nutzer</span>
</span>
<?= icon('check') ?>
</button>
<?php foreach ($reportedUsersList as $reportedUserOption): ?>
<button type="button" class="user-filter-option" data-user-id="<?= (int) $reportedUserOption['id'] ?>" data-user-name="<?= e($reportedUserOption['name']) ?>" role="option" aria-selected="false">
<span class="user-filter-option-visual">
<?= avatar_html($reportedUserOption['avatarUser'], 26) ?>
<span class="user-filter-option-name"><?= e($reportedUserOption['name']) ?></span>
</span>
<?= icon('check') ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php if ($canManageReports): ?>
<?php // Erscheint, sobald oben ein Spieler gewaehlt ist (assets/js/reports.js) ?>
<form method="post" action="/report_action.php" class="report-clear-user" id="report-clear-user" hidden
data-confirm="" data-confirm-title="Alle Reports löschen" data-confirm-danger data-confirm-ok="Alle löschen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="clear_user">
<input type="hidden" name="reported_id" value="">
<button type="submit" class="button-danger button-small"><?= icon('trash') ?> <span data-label>Alle Reports löschen</span></button>
</form>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if ($apiError): ?>
<div class="panel">
<div class="flash flash-error">Reports konnten nicht geladen werden: <?= e($apiError) ?></div>
</div>
<?php elseif (empty($reports)): ?>
<div class="panel">
<p class="text-muted"><?= e($emptyLabels[$status]) ?></p>
</div>
<?php else: ?>
<div class="report-list">
<?php foreach ($reports as $report): ?>
<?php
$reportId = (int) ($report['report_id'] ?? 0);
$reportedId = (int) ($report['reported_id'] ?? 0);
$reporterId = (int) ($report['reporter_id'] ?? 0);
$reportedUser = premade_avatar_user($reportedId, $linkedUsersByDiscordId, (string) ($report['reported_name'] ?? ''));
$reportedName = premade_name_for($reportedId, $namesByDiscordId, (string) ($report['reported_name'] ?? ''));
$reporterName = premade_name_for($reporterId, $namesByDiscordId, (string) ($report['reporter_name'] ?? ''));
$incidentTime = (string) ($report['incident_time'] ?? '');
$reason = (string) ($report['reason'] ?? '');
$evidence = trim((string) ($report['evidence'] ?? ''));
$points = (int) ($report['points'] ?? 1);
$isArchived = !empty($report['archived']);
$timestamp = (int) ($report['timestamp'] ?? 0);
$evidenceIsLink = $evidence !== '' && preg_match('#^https?://#i', $evidence) === 1;
?>
<div class="report-card<?= $isArchived ? ' report-card-archived' : '' ?>" data-reported-id="<?= $reportedId ?>">
<div class="report-card-main">
<div class="report-card-user">
<?= avatar_html($reportedUser, 40) ?>
<div class="report-card-user-info">
<strong><?= e($reportedName) ?></strong>
<span class="text-muted">gemeldet von <?= e($reporterName) ?></span>
</div>
</div>
<div class="report-card-badges">
<span class="badge"><?= $points ?> Pkt.</span>
<?php if ($isArchived): ?>
<span class="badge badge-disabled">Archiviert</span>
<?php else: ?>
<span class="badge badge-active">Aktiv</span>
<?php endif; ?>
</div>
</div>
<div class="report-card-body">
<div class="report-reason-text"><?= e($reason) ?></div>
<?php if ($evidence !== ''): ?>
<div class="report-evidence">
<?= icon($evidenceIsLink ? 'link' : 'edit') ?>
<?php if ($evidenceIsLink): ?>
<a href="<?= e($evidence) ?>" target="_blank" rel="noopener noreferrer">Beweis-Link</a>
<?php else: ?>
<span class="report-evidence-text"><?= e($evidence) ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="report-card-footer">
<span class="text-muted">
Vorfall: <?= e($incidentTime) ?><?php if ($timestamp): ?> · gemeldet <?= date('d.m.Y H:i', $timestamp) ?><?php endif; ?>
</span>
<?php if ($canManageReports): ?>
<div class="actions">
<form method="post" action="/report_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="report_id" value="<?= $reportId ?>">
<input type="hidden" name="action" value="<?= $isArchived ? 'unarchive' : 'archive' ?>">
<button type="submit" class="icon-button" title="<?= $isArchived ? 'Wiederherstellen' : 'Archivieren' ?>"><?= icon($isArchived ? 'restore' : 'archive') ?></button>
</form>
<form method="post" action="/report_action.php" class="inline-form" data-confirm="Diesen Report wirklich endgültig löschen?" data-confirm-title="Report löschen" data-confirm-danger data-confirm-ok="Löschen">
<?= csrf_field() ?>
<input type="hidden" name="report_id" value="<?= $reportId ?>">
<input type="hidden" name="action" value="delete">
<button type="submit" class="icon-button icon-button-danger" title="Löschen"><?= icon('trash') ?></button>
</form>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<p class="text-muted" id="report-filter-empty" hidden>Keine Reports passen zum Filter.</p>
<?php endif; ?>
<?php if ($canManageReports): ?>
<div class="panel">
<h2>Einstellungen</h2>
<?php if ($settingsError): ?>
<div class="flash flash-error">Einstellungen konnten nicht geladen werden: <?= e($settingsError) ?></div>
<?php else: ?>
<form method="post" action="/report_action.php" class="raid-premade-row" style="margin-bottom:1.5rem;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="set_threshold">
<label style="margin:0;display:flex;align-items:center;gap:0.5rem;">
Mute-Schwelle (Punkte)
<input type="text" name="threshold" value="<?= (int) $muteThreshold ?>" style="width:100px;">
</label>
<button type="submit" class="button-secondary">Speichern</button>
</form>
<h3>Punktwert pro Discord-Rolle</h3>
<p class="text-muted">Ein Report zählt so viele Punkte, wie die höchste Rolle des Melders hier einträgt. Rollen ohne eigenen Eintrag zählen standardmäßig 1 Punkt und werden hier nicht aufgelistet.</p>
<?php if (empty($roleWeights)): ?>
<p class="text-muted">Keine Rollen gefunden - ist der Discord-Bot gerade online?</p>
<?php else: ?>
<?php
$configuredRoleWeights = array_values(array_filter($roleWeights, fn (array $r) => (int) ($r['points'] ?? 1) !== 1));
$unconfiguredRoles = array_values(array_filter($roleWeights, fn (array $r) => (int) ($r['points'] ?? 1) === 1));
?>
<?php if (!empty($configuredRoleWeights)): ?>
<div class="role-weight-list">
<?php foreach ($configuredRoleWeights as $role): ?>
<?php $roleId = (int) ($role['role_id'] ?? 0); ?>
<div class="role-weight-row">
<span class="role-weight-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
<span class="role-weight-name"><?= e((string) ($role['name'] ?? '')) ?></span>
<form method="post" action="/report_action.php" class="role-weight-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="set_weights">
<input type="text" name="weights[<?= $roleId ?>]" value="<?= (int) ($role['points'] ?? 1) ?>" class="role-weight-input">
<button type="submit" class="icon-button" title="Speichern"><?= icon('edit') ?></button>
</form>
<form method="post" action="/report_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="set_weights">
<input type="hidden" name="weights[<?= $roleId ?>]" value="1">
<button type="submit" class="icon-button icon-button-danger" title="Entfernen (zurück auf 1 Punkt)"><?= icon('x') ?></button>
</form>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="text-muted">Aktuell hat keine Rolle eine eigene Gewichtung - alle zählen 1 Punkt.</p>
<?php endif; ?>
<?php if (!empty($unconfiguredRoles)): ?>
<button type="button" class="button-success report-add-btn" id="report-add-role-btn">+ Rolle hinzufügen</button>
<div id="report-add-role-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<div class="report-role-step" data-step="1">
<h2>Rolle(n) auswählen</h2>
<p class="text-muted">Wähle eine oder mehrere Rollen, denen du eine eigene Punkte-Gewichtung geben möchtest.</p>
<div class="role-picker-list">
<?php foreach ($unconfiguredRoles as $role): ?>
<label class="role-picker-option">
<input type="checkbox" name="role_ids[]" value="<?= (int) ($role['role_id'] ?? 0) ?>" data-role-name="<?= e((string) ($role['name'] ?? '')) ?>">
<span class="role-picker-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
<span><?= e((string) ($role['name'] ?? '')) ?></span>
</label>
<?php endforeach; ?>
</div>
<div class="actions" style="margin-top:1.25rem;justify-content:flex-end;">
<button type="button" id="report-role-step1-next" disabled>Weiter</button>
</div>
</div>
<div class="report-role-step" data-step="2" hidden>
<h2>Punktwert festlegen</h2>
<p class="text-muted">Ausgewählt: <strong id="report-role-step2-summary"></strong></p>
<div>
<label>Punkte pro Report</label>
<input type="text" id="report-role-points" value="1">
</div>
<div class="actions" style="margin-top:1.25rem;justify-content:space-between;">
<button type="button" class="button-secondary" id="report-role-step2-back">Zurück</button>
<button type="button" id="report-role-step2-submit">Hinzufügen</button>
</div>
</div>
</div>
</div>
<form id="report-add-role-form" method="post" action="/report_action.php" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="add_weights">
<input type="hidden" name="points" id="report-add-role-points-field">
<div id="report-add-role-ids-container"></div>
</form>
<?php endif; ?>
<?php endif; ?>
<h3 style="margin-top:2rem;">Von der Timeout-Mechanik ausgeschlossene Rollen</h3>
<p class="text-muted">Mitglieder mit einer dieser Rollen werden nie automatisch stummgeschaltet, egal wie viele Punkte gegen sie vorliegen (der Server-Owner ist davon unabhängig immer ausgenommen). Reports/Punkte werden für sie trotzdem ganz normal weiter gezählt.</p>
<?php if (empty($muteExclusions)): ?>
<p class="text-muted">Keine Rollen gefunden - ist der Discord-Bot gerade online?</p>
<?php else: ?>
<?php
$excludedRoles = array_values(array_filter($muteExclusions, fn (array $r) => !empty($r['excluded'])));
$includableRoles = array_values(array_filter($muteExclusions, fn (array $r) => empty($r['excluded'])));
?>
<?php if (!empty($excludedRoles)): ?>
<div class="role-weight-list">
<?php foreach ($excludedRoles as $role): ?>
<div class="role-weight-row">
<span class="role-weight-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
<span class="role-weight-name"><?= e((string) ($role['name'] ?? '')) ?></span>
<form method="post" action="/report_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="remove_exclusion">
<input type="hidden" name="role_id" value="<?= (int) ($role['role_id'] ?? 0) ?>">
<button type="submit" class="icon-button icon-button-danger" title="Ausnahme entfernen"><?= icon('x') ?></button>
</form>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="text-muted">Aktuell ist keine Rolle ausgeschlossen.</p>
<?php endif; ?>
<?php if (!empty($includableRoles)): ?>
<button type="button" class="button-success report-add-btn" id="report-add-exclusion-btn">+ Rolle ausschließen</button>
<div id="report-add-exclusion-modal" class="modal-overlay" hidden>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Rolle(n) ausschließen</h2>
<p class="text-muted">Wähle eine oder mehrere Rollen, deren Mitglieder nie automatisch stummgeschaltet werden sollen.</p>
<div class="role-picker-list">
<?php foreach ($includableRoles as $role): ?>
<label class="role-picker-option">
<input type="checkbox" name="role_ids[]" value="<?= (int) ($role['role_id'] ?? 0) ?>">
<span class="role-picker-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
<span><?= e((string) ($role['name'] ?? '')) ?></span>
</label>
<?php endforeach; ?>
</div>
<div class="actions" style="margin-top:1.25rem;justify-content:flex-end;">
<button type="button" id="report-exclusion-submit">Ausschließen</button>
</div>
</div>
</div>
<form id="report-add-exclusion-form" method="post" action="/report_action.php" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="add_exclusions">
<div id="report-add-exclusion-ids-container"></div>
</form>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/reports.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?>