Gear planner: - Personal gear sets (18 slots) with enchant, exceed, soul imprint and manastones, stat totals by source and side-by-side comparison of 2-4 sets - Sets can be shown on the own profile page (read-only for other members) - Admin catalog: import items from aion2hub.com (Global client), compare stored values with the source one by one or all at once, at most one request per second - New permissions gear.view (all with dashboard access) and gear.manage Dashboard: - Role badges ordered like the member list (roster_order) - Stronger hover effect on "Rangliste & Verlauf" / "Zum Lumishop", no more blue hover on secondary buttons - "Anstehende Raids" box links to the raids page, next raids link to the raid and to the calendar day - Raid attendance only knows present/absent (old "excused" entries count as unset) Bug reports: - Up to 5 images per report, pasting copied images with Ctrl+V (also for the gallery) - Images are only served to the reporter and bugs.manage via bug_image.php Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
184 lines
6.2 KiB
PHP
184 lines
6.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Fehlermeldungen: Mitglieder melden im Dashboard Bugs der Website, die Leitung bearbeitet
|
|
* sie unter /bugs.php (Berechtigung bugs.manage).
|
|
*/
|
|
|
|
// Status => [Anzeigename, Badge-Klasse]
|
|
const BUG_STATUSES = [
|
|
'open' => ['Offen', 'badge-pending'],
|
|
'in_progress' => ['In Arbeit', 'bug-badge-progress'],
|
|
'done' => ['Behoben', 'badge-active'],
|
|
'rejected' => ['Abgelehnt', 'badge-disabled'],
|
|
];
|
|
|
|
// Bereiche der Website, in denen der Fehler aufgetreten ist.
|
|
const BUG_AREAS = [
|
|
'dashboard' => 'Dashboard',
|
|
'profile' => 'Mein Profil',
|
|
'contributions' => 'Lumipunkte',
|
|
'shop' => 'Lumishop',
|
|
'members' => 'Mitglieder',
|
|
'raids' => 'Raids',
|
|
'premades' => 'Premades',
|
|
'events' => 'Events',
|
|
'map' => 'Karte',
|
|
'warehouse' => 'Lagerhaus',
|
|
'login' => 'Login / Discord',
|
|
'home' => 'Startseite',
|
|
'admin' => 'Admin-Bereich',
|
|
'other' => 'Sonstiges',
|
|
];
|
|
|
|
// Schutz gegen versehentliches Mehrfach-Absenden bzw. Spam.
|
|
const BUG_MAX_PER_HOUR = 10;
|
|
|
|
function bug_status_label(string $status): string
|
|
{
|
|
return BUG_STATUSES[$status][0] ?? $status;
|
|
}
|
|
|
|
function bug_status_badge(string $status): string
|
|
{
|
|
return '<span class="badge ' . e(BUG_STATUSES[$status][1] ?? '') . '">' . e(bug_status_label($status)) . '</span>';
|
|
}
|
|
|
|
function bug_area_label(string $area): string
|
|
{
|
|
return BUG_AREAS[$area] ?? BUG_AREAS['other'];
|
|
}
|
|
|
|
/** Anzahl offener Meldungen (fuer das Abzeichen in der Seitenleiste). */
|
|
function bug_open_count(): int
|
|
{
|
|
try {
|
|
return (int) db()->query("SELECT COUNT(*) FROM bug_reports WHERE status = 'open'")->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// ---- Bilder an Fehlermeldungen ----
|
|
// Liegen NICHT oeffentlich abrufbar im Webroot-Ordner (eigene .htaccess sperrt ihn), sondern
|
|
// werden ueber /bug_image.php nur an den Melder und die Leitung ausgeliefert - Screenshots
|
|
// koennen Privates zeigen (Nachrichten, Namen, ...).
|
|
|
|
const BUG_UPLOAD_DIR = __DIR__ . '/../assets/uploads/bugs/';
|
|
const BUG_MAX_IMAGES = 5;
|
|
const BUG_MAX_UPLOAD = 8 * 1024 * 1024;
|
|
|
|
/**
|
|
* Hochgeladenes Bild pruefen, neu speichern (entfernt EXIF/angehaengten Code, verkleinert auf
|
|
* hoechstens 1920 px) und den Dateinamen zurueckgeben.
|
|
*
|
|
* @param array<string, mixed> $file Eintrag aus $_FILES
|
|
* @throws RuntimeException mit verstaendlicher Meldung
|
|
*/
|
|
function bug_store_upload(array $file, int $userId): string
|
|
{
|
|
if (($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
|
|
throw new RuntimeException(in_array($file['error'] ?? 0, [UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE], true)
|
|
? 'Ein Bild ist zu groß.' : 'Ein Bild konnte nicht hochgeladen werden.');
|
|
}
|
|
if ((int) $file['size'] > BUG_MAX_UPLOAD) {
|
|
throw new RuntimeException('Ein Bild ist zu groß (höchstens 8 MB).');
|
|
}
|
|
$info = @getimagesize((string) $file['tmp_name']);
|
|
$types = [IMAGETYPE_PNG => 'png', IMAGETYPE_JPEG => 'jpg', IMAGETYPE_GIF => 'gif', IMAGETYPE_WEBP => 'webp'];
|
|
if ($info === false || !isset($types[$info[2]])) {
|
|
throw new RuntimeException('Nur PNG, JPG, GIF oder WEBP sind als Bild erlaubt.');
|
|
}
|
|
if (!is_dir(BUG_UPLOAD_DIR)) {
|
|
@mkdir(BUG_UPLOAD_DIR, 0755, true);
|
|
}
|
|
$name = 'bug' . $userId . '_' . bin2hex(random_bytes(8)) . '.' . $types[$info[2]];
|
|
$error = store_uploaded_image((string) $file['tmp_name'], BUG_UPLOAD_DIR . $name, $info[2], 1920);
|
|
if ($error !== null) {
|
|
throw new RuntimeException($error);
|
|
}
|
|
return $name;
|
|
}
|
|
|
|
/** Die Eintraege aus $_FILES['images'] als Liste einzelner Dateien (leere Felder weggelassen). */
|
|
function bug_uploaded_files(): array
|
|
{
|
|
$files = [];
|
|
foreach ((array) ($_FILES['images']['name'] ?? []) as $i => $name) {
|
|
$error = (int) ($_FILES['images']['error'][$i] ?? UPLOAD_ERR_NO_FILE);
|
|
if ($error === UPLOAD_ERR_NO_FILE) {
|
|
continue;
|
|
}
|
|
$files[] = [
|
|
'name' => (string) $name,
|
|
'error' => $error,
|
|
'size' => (int) ($_FILES['images']['size'][$i] ?? 0),
|
|
'tmp_name' => (string) ($_FILES['images']['tmp_name'][$i] ?? ''),
|
|
];
|
|
}
|
|
return $files;
|
|
}
|
|
|
|
/** @return array<int, array<int, array>> Bilder je Meldung */
|
|
function bug_images_for(array $bugIds): array
|
|
{
|
|
$bugIds = array_values(array_unique(array_map('intval', $bugIds)));
|
|
if (!$bugIds) {
|
|
return [];
|
|
}
|
|
try {
|
|
$stmt = db()->prepare(
|
|
'SELECT id, bug_id, filename FROM bug_report_images WHERE bug_id IN (' . implode(',', array_fill(0, count($bugIds), '?')) . ') ORDER BY id'
|
|
);
|
|
$stmt->execute($bugIds);
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
$images = [];
|
|
foreach ($stmt->fetchAll() as $row) {
|
|
$images[(int) $row['bug_id']][] = $row;
|
|
}
|
|
return $images;
|
|
}
|
|
|
|
function bug_image_url(int $imageId): string
|
|
{
|
|
return '/bug_image.php?id=' . $imageId;
|
|
}
|
|
|
|
/** Vorschaubilder einer Meldung (Klick oeffnet die Grossansicht, siehe assets/js/lightbox.js). */
|
|
function bug_images_html(array $images, int $bugId): string
|
|
{
|
|
if (!$images) {
|
|
return '';
|
|
}
|
|
$html = '<div class="bug-images">';
|
|
foreach ($images as $i => $image) {
|
|
$url = e(bug_image_url((int) $image['id']));
|
|
$html .= '<a href="' . $url . '" data-lightbox="bug-' . $bugId . '" data-caption="Bild ' . ($i + 1) . ' von ' . count($images) . '">'
|
|
. '<img src="' . $url . '" alt="Bild ' . ($i + 1) . ' zur Fehlermeldung" loading="lazy"></a>';
|
|
}
|
|
return $html . '</div>';
|
|
}
|
|
|
|
/** Dateien der Bilder einer (oder aller) Meldungen loeschen - die Zeilen fallen per Fremdschluessel weg. */
|
|
function bug_delete_image_files(?int $bugId = null): void
|
|
{
|
|
try {
|
|
$stmt = $bugId === null
|
|
? db()->query('SELECT filename FROM bug_report_images')
|
|
: db()->prepare('SELECT filename FROM bug_report_images WHERE bug_id = ?');
|
|
if ($bugId !== null) {
|
|
$stmt->execute([$bugId]);
|
|
}
|
|
$filenames = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
} catch (PDOException $e) {
|
|
return;
|
|
}
|
|
foreach ($filenames as $filename) {
|
|
if (strpos((string) $filename, '/') === false && is_file(BUG_UPLOAD_DIR . $filename)) {
|
|
@unlink(BUG_UPLOAD_DIR . $filename);
|
|
}
|
|
}
|
|
}
|