Roles at the default weight (1) are no longer listed - only roles with
an explicit, non-default point value show up, each editable/removable
inline. A new green "+ Rolle hinzufuegen" button opens a two-step popup:
pick one or more still-unconfigured roles, then set a single point
value applied to all of them at once (new report_action.php action
add_weights). Fixed two CSS specificity bugs while building this
(input[type=text] beating a plain class on width, and the generic
form{flex-direction:column} rule leaking into the inline edit row).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
279 lines
14 KiB
PHP
279 lines
14 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;
|
|
}
|
|
}
|
|
|
|
$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 = [];
|
|
$settingsError = null;
|
|
if ($canManageReports) {
|
|
try {
|
|
$muteThreshold = fetch_mute_threshold();
|
|
$roleWeights = fetch_report_weights();
|
|
} catch (Throwable $e) {
|
|
$settingsError = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$pageTitle = 'Reports';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<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>
|
|
</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="panel">
|
|
<div class="table-scroll">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Gemeldet</th>
|
|
<th>Melder</th>
|
|
<th>Zeitpunkt</th>
|
|
<th>Grund</th>
|
|
<th>Punkte</th>
|
|
<th>Status</th>
|
|
<?php if ($canManageReports): ?><th></th><?php endif; ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?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);
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<div style="display:flex;align-items:center;gap:0.5rem;">
|
|
<?= avatar_html($reportedUser, 28) ?>
|
|
<strong><?= e($reportedName) ?></strong>
|
|
</div>
|
|
</td>
|
|
<td class="text-muted"><?= e($reporterName) ?></td>
|
|
<td class="text-muted">
|
|
<?= e($incidentTime) ?>
|
|
<?php if ($timestamp): ?><br><span style="font-size:0.75rem;">gemeldet: <?= date('d.m.Y H:i', $timestamp) ?></span><?php endif; ?>
|
|
</td>
|
|
<td style="max-width:320px;white-space:pre-wrap;">
|
|
<?= e($reason) ?>
|
|
<?php if ($evidence !== ''): ?><br><a href="<?= e($evidence) ?>" target="_blank" rel="noopener noreferrer">Beweis-Link</a><?php endif; ?>
|
|
</td>
|
|
<td><span class="badge"><?= $points ?> Pkt.</span></td>
|
|
<td>
|
|
<?php if ($isArchived): ?>
|
|
<span class="badge badge-disabled">Archiviert</span>
|
|
<?php else: ?>
|
|
<span class="badge badge-active">Aktiv</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<?php if ($canManageReports): ?>
|
|
<td 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" onsubmit="return confirm('Diesen Report wirklich endgültig 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>
|
|
</td>
|
|
<?php endif; ?>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<?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" id="report-add-role-btn" style="margin-top:1rem;">+ 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>
|
|
<script src="/assets/js/reports.js"></script>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|