LuminaWebsite/reports.php
Maaxxs c4f94bf84a Member feedback: raid input checks and fixed raid points, premades in the raid form, live raid page, Lumina-style dialogs, leadership calendar entries, class-based weapon picker, map and tactics fixes
- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing
- Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept
- Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name
- Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names
- Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK
- Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll
- Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set
- Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note
- Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected
- Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 16:12:18 +02:00

387 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. 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 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'; ?>