From 3fa3a7310df4477949333a495e80747edf2f3eb8 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Fri, 25 Sep 2026 12:35:02 +0200 Subject: [PATCH] Group icons: groups get an icon in front of their name, like the role icons in Discord In Berechtigungsgruppen -> Gruppe bearbeiten the new field "Symbol" takes an uploaded image or a link to one, with a checkbox to remove it and a live preview in the tag. - A link is downloaded once when saving (includes/role_icons.php): public http(s) addresses only, nothing in the local network (redirects checked one by one, the checked IP is pinned), at most 2 MB, PNG/JPG/GIF/WEBP. Like uploads the image is re-encoded, scaled to 128 px and stored under assets/uploads/roles/ (with .htaccess), so visitors never load anything from other servers and expiring links (Discord attachments) don't break the icon. - Shown in the group tags (member list, profile, group admin), the group filter chips and the rank section headings of the member list, and the group badges on the dashboard. - Replaced or removed icons and the icon of a deleted group are deleted from disk; the new file is only stored once all other fields are valid and removed again if saving fails. - New column roles.tag_icon (schema version 55, also in sql/schema.sql); README. - file-input.js: "Entfernen" fires a change event, so previews of other scripts clear too. - Live updates of the member list also react to changes of tag_bg2 and tag_icon. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 3 + README.md | 8 ++ admin/role_delete.php | 4 +- admin/role_form.php | 83 ++++++++++++++-- admin/roles.php | 4 +- assets/css/style.css | 20 ++++ assets/js/file-input.js | 4 +- assets/js/members.js | 13 ++- assets/uploads/roles/.gitkeep | 0 assets/uploads/roles/.htaccess | 17 ++++ dashboard.php | 2 +- includes/live_updates.php | 2 +- includes/permissions.php | 59 ++++++++--- includes/role_icons.php | 173 +++++++++++++++++++++++++++++++++ includes/schema.php | 4 +- members.php | 9 +- sql/schema.sql | 3 + 17 files changed, 373 insertions(+), 35 deletions(-) create mode 100644 assets/uploads/roles/.gitkeep create mode 100644 assets/uploads/roles/.htaccess create mode 100644 includes/role_icons.php diff --git a/.gitignore b/.gitignore index 410f37b..d606dd2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ assets/uploads/gear/* assets/uploads/skills/* !assets/uploads/skills/.htaccess !assets/uploads/skills/.gitkeep +assets/uploads/roles/* +!assets/uploads/roles/.htaccess +!assets/uploads/roles/.gitkeep # Kacheln, Marker und Icons der Karte (~230 MB) - werden per FTP hochgeladen, siehe README assets/map/data/ __pycache__/ diff --git a/README.md b/README.md index 30136a3..ecb7c8d 100644 --- a/README.md +++ b/README.md @@ -916,6 +916,14 @@ eine eigene Hintergrund- und Textfarbe wählen, dazu wie bei Discord ein Verlauf läuft von links nach rechts in eine zweite Farbe über (mit Vorschau; Spalten `roles.tag_bg`, `roles.tag_bg2`, `roles.tag_color`). Ohne Farbe bleibt das Standard-Tag. +Dazu kann jede Gruppe ein Symbol bekommen, das wie die Rollen-Symbole bei Discord vor ihrem Namen +steht: im Tag, in der Überschrift ihres Abschnitts und im Gruppenfilter der Mitgliederliste sowie im +Dashboard. Es wird hochgeladen oder als Link angegeben. Einen Link lädt die Website beim Speichern +einmal herunter (nur öffentliche http(s)-Adressen, keine im eigenen Netz, höchstens 2 MB), Besucher +laden also nie etwas von fremden Servern. Das Bild wird wie ein Upload neu gerechnet, auf 128 px +verkleinert und unter `assets/uploads/roles/` abgelegt (Spalte `roles.tag_icon`). Der Ordner muss +für den Webserver beschreibbar sein, seine `.htaccess` verhindert, dass dort etwas als PHP läuft. + Falls die Datenbank schon vor diesem Update existierte, fehlt die Spalte `roster_order`: ```sql ALTER TABLE roles ADD COLUMN roster_order INT NULL DEFAULT NULL AFTER is_system; diff --git a/admin/role_delete.php b/admin/role_delete.php index 6c70546..322193c 100644 --- a/admin/role_delete.php +++ b/admin/role_delete.php @@ -1,5 +1,6 @@ prepare('SELECT is_system FROM roles WHERE id = ?'); +$stmt = $pdo->prepare('SELECT is_system, tag_icon FROM roles WHERE id = ?'); $stmt->execute([$id]); $role = $stmt->fetch(); @@ -29,6 +30,7 @@ if (!$role) { $nameStmt->execute([$id]); $roleName = (string) $nameStmt->fetchColumn(); $pdo->prepare('DELETE FROM roles WHERE id = ?')->execute([$id]); + role_icon_delete($role['tag_icon']); admin_log('🗑️ Berechtigungsgruppe gelöscht', ['Gruppe' => $roleName], 'danger'); sync_role_assign_permissions(); // Vergabe-Recht der Gruppe entfernen set_flash('success', 'Berechtigungsgruppe wurde gelöscht.'); diff --git a/admin/role_form.php b/admin/role_form.php index e4bc867..b59ab95 100644 --- a/admin/role_form.php +++ b/admin/role_form.php @@ -1,6 +1,7 @@ null, 'name' => '', 'display_name' => '', 'description' => '', 'is_system' => 0, 'roster_order' => null, 'discord_role_id' => null, - 'tag_bg' => null, 'tag_bg2' => null, 'tag_color' => null]; + 'tag_bg' => null, 'tag_bg2' => null, 'tag_color' => null, 'tag_icon' => null]; $selectedPermissionIds = []; if ($isEdit) { - $stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color FROM roles WHERE id = ?'); + $stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color, tag_icon FROM roles WHERE id = ?'); $stmt->execute([$editId]); $found = $stmt->fetch(); if (!$found) { @@ -28,6 +29,9 @@ if ($isEdit) { } $error = null; +// Symbol-Felder: bleiben nach einem Fehler stehen (eine gewaehlte Datei kann der Browser nicht behalten) +$iconUrl = ''; +$iconRemove = false; /** Tag-Farben fuers Log: "#aa0000 / #ffffff" oder "Verlauf #aa0000–#0000aa / Standard". */ $tagColorsText = static fn (?string $bg, ?string $bg2, ?string $text): string => @@ -71,6 +75,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Verlauf nur zusammen mit dem Hintergrund (von dessen Farbe zur zweiten) $tagBg2 = $tagBg !== null && !empty($_POST['tag_bg2_on']) ? role_tag_color_input((string) ($_POST['tag_bg2'] ?? '')) : null; $tagColor = !empty($_POST['tag_color_on']) ? role_tag_color_input((string) ($_POST['tag_color'] ?? '')) : null; + // Symbol: neu hochgeladen oder per Link, sonst bleibt das bisherige - ausser es soll weg + $iconFile = is_array($_FILES['icon_file'] ?? null) && ($_FILES['icon_file']['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE + ? $_FILES['icon_file'] : null; + $iconUrl = trim((string) ($_POST['icon_url'] ?? '')); + $iconRemove = !empty($_POST['icon_remove']); + $oldIcon = $isEdit ? ($role['tag_icon'] ?? null) : null; + $newIcon = null; if ($name === '') { $error = 'Bitte einen Namen für die Gruppe angeben.'; @@ -80,17 +91,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $error = 'Die Reihenfolge muss eine ganze Zahl sein (z.B. 1).'; } elseif ($discordRoleId !== null && !preg_match('/^[0-9]{5,19}$/', $discordRoleId)) { $error = 'Die Discord-Rollen-ID besteht nur aus Ziffern (Rechtsklick auf die Rolle in Discord → "Rollen-ID kopieren").'; + } elseif (mb_strlen($iconUrl) > 1000) { + $error = 'Der Link zum Symbol ist zu lang (höchstens 1000 Zeichen).'; } else { + // Das neue Symbol erst speichern, wenn alles andere passt - sonst bliebe eine Datei ohne Gruppe liegen + try { + if ($iconFile !== null) { + $newIcon = role_icon_store_upload($iconFile); + } elseif ($iconUrl !== '') { + $newIcon = role_icon_store_from_url($iconUrl); + } + } catch (RuntimeException $e) { + $error = $e->getMessage(); + } + } + + if ($error === null) { + $tagIcon = $newIcon ?? ($iconRemove ? null : $oldIcon); try { $pdo->beginTransaction(); if ($isEdit) { - $pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ?, tag_bg = ?, tag_bg2 = ?, tag_color = ? WHERE id = ?') - ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $editId]); + $pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ?, tag_bg = ?, tag_bg2 = ?, tag_color = ?, tag_icon = ? WHERE id = ?') + ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $tagIcon, $editId]); $roleId = $editId; } else { - $pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color) VALUES (?, ?, ?, ?, ?, ?, ?, ?)') - ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor]); + $pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color, tag_icon) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)') + ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $tagIcon]); $roleId = (int) $pdo->lastInsertId(); } @@ -109,6 +136,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } $pdo->commit(); + // Ersetztes oder entferntes Symbol: die alte Datei braucht niemand mehr + if ($oldIcon !== null && $oldIcon !== $tagIcon) { + role_icon_delete($oldIcon); + } sync_role_assign_permissions(); // neue Gruppe bzw. neuer Name // Discord-Log: welche Berechtigungen dazu- bzw. weggekommen sind. @@ -130,6 +161,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $tagColorsText($isEdit ? $role['tag_bg'] : null, $isEdit ? $role['tag_bg2'] : null, $isEdit ? $role['tag_color'] : null), $tagColorsText($tagBg, $tagBg2, $tagColor) ), + 'Symbol' => $newIcon !== null ? ($iconFile !== null ? 'hochgeladen' : 'von ' . $iconUrl) + : ($oldIcon !== null && $tagIcon === null ? 'entfernt' : ''), 'Berechtigungen hinzugefügt' => $permList(array_diff($submittedPermissionIds, $selectedPermissionIds)), 'Berechtigungen entfernt' => $permList(array_diff($selectedPermissionIds, $submittedPermissionIds)), ], $isEdit ? 'info' : 'success'); @@ -137,6 +170,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { redirect('/admin/roles.php'); } catch (PDOException $e) { $pdo->rollBack(); + role_icon_delete($newIcon); // nicht gespeichert - das neue Symbol gehoert zu keiner Gruppe $error = 'Eine Gruppe mit diesem Namen existiert bereits.'; } } @@ -189,7 +223,7 @@ include __DIR__ . '/../includes/header.php';
-
+
@@ -201,6 +235,17 @@ include __DIR__ . '/../includes/header.php';
Wird überall angezeigt, wo diese Gruppe im Mitgliederbereich auftaucht (Dashboard, Mitgliederliste, ...). Ohne Angabe wird stattdessen der Name oben verwendet.
+
+ +
+ + + + + +
+
Steht vor dem Namen der Gruppe, wie die Rollen-Symbole bei Discord (Vorschau unten bei den Farben). PNG, JPG, GIF oder WEBP, am besten quadratisch, höchstens 2 MB. Einen Link lädt die Website beim Speichern einmal herunter und speichert das Bild selbst – der Link muss danach nicht mehr funktionieren.
+
@@ -224,7 +269,7 @@ include __DIR__ . '/../includes/header.php'; - Vorschau: + Vorschau:
So erscheint die Gruppe als Tag in der Mitgliederliste und auf den Profilseiten. Ohne Haken gilt die Standardfarbe. Mit „Verlauf zu“ läuft der Hintergrund von links nach rechts in die zweite Farbe über (wie bei Discord).
@@ -299,12 +344,18 @@ include __DIR__ . '/../includes/header.php';