From 6f19ca29a4eefbe975195616dceb7be8e6e22593 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Wed, 23 Sep 2026 17:46:24 +0200 Subject: [PATCH] Group tags: optional custom background and text colour per permission group, no dot in front of the tags - Berechtigungsgruppen -> edit: "Farben des Tags (optional)" with separate background/text colour (each only with its checkbox, otherwise the default), live preview, change recorded in the admin log - Tags in the member list, on profile pages and in the group overview use the colours (CSS variables --tag-bg / --tag-color, only #rrggbb values are stored) - The gold dot in front of the tags is gone - Schema version 37 (roles.tag_bg, roles.tag_color), README Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++ admin/role_form.php | 69 ++++++++++++++++++++++++++++++++++++---- admin/roles.php | 4 +-- assets/css/style.css | 22 ++++++------- includes/permissions.php | 50 +++++++++++++++++++++++++++++ includes/schema.php | 5 ++- member.php | 2 +- members.php | 2 +- sql/schema.sql | 3 ++ 9 files changed, 140 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 790aa77..ddc69f8 100644 --- a/README.md +++ b/README.md @@ -729,6 +729,11 @@ mit einer Zahl bekommen dort eine eigene, danach sortierte Gruppe (kleinere Zahl Legionsleitung = 1, Offiziere = 2); Mitglieder ohne so eine Rolle landen in der allgemeinen Gruppe am Ende. Hat jemand mehrere sortierte Rollen, zählt die mit der kleinsten Zahl. +Die Gruppen eines Mitglieds stehen als kleine Tags in der Mitgliederliste und auf seiner +Profilseite. Unter Berechtigungsgruppen → Gruppe bearbeiten lassen sich für jedes Tag optional +eine eigene Hintergrund- und Textfarbe wählen (mit Vorschau; Spalten `roles.tag_bg`, +`roles.tag_color`). Ohne Farbe bleibt das Standard-Tag. + 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_form.php b/admin/role_form.php index beb4d04..abbc5f3 100644 --- a/admin/role_form.php +++ b/admin/role_form.php @@ -8,11 +8,12 @@ $pdo = db(); $editId = isset($_GET['id']) ? (int) $_GET['id'] : null; $isEdit = $editId !== null; -$role = ['id' => null, 'name' => '', 'display_name' => '', 'description' => '', 'is_system' => 0, 'roster_order' => null, 'discord_role_id' => null]; +$role = ['id' => null, 'name' => '', 'display_name' => '', 'description' => '', 'is_system' => 0, 'roster_order' => null, 'discord_role_id' => null, + 'tag_bg' => null, 'tag_color' => null]; $selectedPermissionIds = []; if ($isEdit) { - $stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id FROM roles WHERE id = ?'); + $stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id, tag_bg, tag_color FROM roles WHERE id = ?'); $stmt->execute([$editId]); $found = $stmt->fetch(); if (!$found) { @@ -61,6 +62,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $submittedPermissionIds = array_map('intval', $_POST['permissions'] ?? []); $discordRoleRaw = trim((string) ($_POST['discord_role_id'] ?? '')); $discordRoleId = $discordRoleRaw !== '' ? $discordRoleRaw : null; + // Eigene Tag-Farben nur mit Haken - ohne gilt die Standardfarbe + $tagBg = !empty($_POST['tag_bg_on']) ? role_tag_color_input((string) ($_POST['tag_bg'] ?? '')) : null; + $tagColor = !empty($_POST['tag_color_on']) ? role_tag_color_input((string) ($_POST['tag_color'] ?? '')) : null; if ($name === '') { $error = 'Bitte einen Namen für die Gruppe angeben.'; @@ -75,12 +79,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo->beginTransaction(); if ($isEdit) { - $pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ? WHERE id = ?') - ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $editId]); + $pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ?, tag_bg = ?, tag_color = ? WHERE id = ?') + ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagColor, $editId]); $roleId = $editId; } else { - $pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id) VALUES (?, ?, ?, ?, ?)') - ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId]); + $pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id, tag_bg, tag_color) VALUES (?, ?, ?, ?, ?, ?, ?)') + ->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagColor]); $roleId = (int) $pdo->lastInsertId(); } @@ -115,6 +119,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { 'Discord-Rolle' => (string) ($role['discord_role_id'] ?? '') !== (string) $discordRoleId ? (($role['discord_role_id'] ?? null) !== null ? '<@&' . $role['discord_role_id'] . '>' : 'keine') . ' → ' . ($discordRoleId !== null ? '<@&' . $discordRoleId . '>' : 'keine') : '', + // "Hintergrund / Text", nur wenn sich etwas geaendert hat + 'Tag-Farben' => admin_log_change( + (($isEdit ? $role['tag_bg'] : null) ?: 'Standard') . ' / ' . (($isEdit ? $role['tag_color'] : null) ?: 'Standard'), + ($tagBg ?? 'Standard') . ' / ' . ($tagColor ?? 'Standard') + ), 'Berechtigungen hinzugefügt' => $permList(array_diff($submittedPermissionIds, $selectedPermissionIds)), 'Berechtigungen entfernt' => $permList(array_diff($selectedPermissionIds, $submittedPermissionIds)), ], $isEdit ? 'info' : 'success'); @@ -131,6 +140,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $role['description'] = $description; $role['roster_order'] = $rosterOrder; $role['discord_role_id'] = $discordRoleId; + $role['tag_bg'] = $tagBg; + $role['tag_color'] = $tagColor; $selectedPermissionIds = $submittedPermissionIds; } } @@ -187,6 +198,25 @@ include __DIR__ . '/../includes/header.php'; +
+ +
+ + + + Vorschau: + +
+
So erscheint die Gruppe als Tag in der Mitgliederliste und auf den Profilseiten. Ohne Haken gilt die Standardfarbe.
+
@@ -255,6 +285,33 @@ include __DIR__ . '/../includes/header.php';
+ +

Neue Berechtigung anlegen

Für zukünftige Funktionen kannst du hier weitere Berechtigungs-Schlüssel anlegen (z.B. "events.manage").

diff --git a/admin/roles.php b/admin/roles.php index 1cc5118..2a868ed 100644 --- a/admin/roles.php +++ b/admin/roles.php @@ -4,7 +4,7 @@ require_once __DIR__ . '/../includes/events_api.php'; require_permission('roles.manage'); $roles = db()->query( - 'SELECT r.id, r.name, r.display_name, r.description, r.is_system, r.roster_order, r.discord_role_id, + 'SELECT r.id, r.name, r.display_name, r.description, r.is_system, r.roster_order, r.discord_role_id, r.tag_bg, r.tag_color, COUNT(DISTINCT ur.user_id) AS user_count, COUNT(DISTINCT rp.permission_id) AS permission_count FROM roles r @@ -60,7 +60,7 @@ include __DIR__ . '/../includes/header.php'; System - —' ?> + diff --git a/assets/css/style.css b/assets/css/style.css index 40bacf3..2322710 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -4374,26 +4374,26 @@ body.home-page .navbar { margin-top: 0.55rem; } +/* Gruppen-Tag - eigene Farben je Gruppe (Berechtigungsgruppen) kommen als --tag-bg / --tag-color */ .member-role { display: inline-flex; align-items: center; - gap: 0.35rem; padding: 0.12rem 0.55rem; - border: 1px solid var(--border); + border: 1px solid var(--tag-bg, var(--border)); border-radius: 999px; - background: rgba(255, 255, 255, 0.04); + background: var(--tag-bg, rgba(255, 255, 255, 0.04)); font-size: 0.75rem; - color: var(--text); + color: var(--tag-color, var(--text)); white-space: nowrap; } -.member-role::before { - content: ''; - width: 7px; - height: 7px; - border-radius: 50%; - background: var(--gold); -} +/* Berechtigungsgruppe bearbeiten: Farbwahl fuer das Tag mit Vorschau */ +.role-tag-colors { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; margin-top: 0.3rem; } +.role-tag-color { display: inline-flex; align-items: center; gap: 0.45rem; margin: 0; font-weight: 400; cursor: pointer; } +.role-tag-color input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--gold); } +.role-tag-color input[type="color"] { width: 2.4rem; height: 1.8rem; padding: 0.1rem; border-radius: 6px; cursor: pointer; } +.role-tag-color:has(input[type="checkbox"]:not(:checked)) input[type="color"] { opacity: 0.45; } +.role-tag-preview { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.85rem; } /* Profil: Klassen laut Discord-Klassenrollen, Main-Klasse per Auswahl (profile.php) */ .profile-classes { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; } diff --git a/includes/permissions.php b/includes/permissions.php index 30526bc..437785b 100644 --- a/includes/permissions.php +++ b/includes/permissions.php @@ -142,6 +142,56 @@ function sync_role_assign_permissions(): void } } +// ---- Gruppen-Tags (Mitgliederliste, Profilseite) ---- + +/** Eine Farbe aus dem Formular: "#rrggbb" (klein geschrieben) oder null. */ +function role_tag_color_input(string $value): ?string +{ + $value = strtolower(trim($value)); + return preg_match('/^#[0-9a-f]{6}$/', $value) ? $value : null; +} + +/** Style-Angabe fuer ein Tag mit eigenen Farben ("--tag-bg:#…;--tag-color:#…"), leer = Standard. */ +function role_tag_css(?string $background, ?string $text): string +{ + $parts = []; + if ($background !== null && ($background = role_tag_color_input($background)) !== null) { + $parts[] = '--tag-bg:' . $background; + } + if ($text !== null && ($text = role_tag_color_input($text)) !== null) { + $parts[] = '--tag-color:' . $text; + } + return implode(';', $parts); +} + +/** Eigene Tag-Farben aller Gruppen: [Anzeigename => Style-Angabe]. */ +function role_tag_styles(): array +{ + static $styles = null; + if ($styles === null) { + $styles = []; + try { + $rows = db()->query("SELECT COALESCE(NULLIF(display_name, ''), name) AS label, tag_bg, tag_color FROM roles ORDER BY id")->fetchAll(); + } catch (PDOException $e) { + $rows = []; // Spalten kommen erst mit dem naechsten Schema-Abgleich + } + foreach ($rows as $row) { + $css = role_tag_css($row['tag_bg'], $row['tag_color']); + if ($css !== '' && !isset($styles[$row['label']])) { + $styles[$row['label']] = $css; + } + } + } + return $styles; +} + +/** Tag einer Gruppe, mit ihren eigenen Farben, falls sie welche hat ($style = null: nach Namen nachschlagen). */ +function role_tag_html(string $label, ?string $style = null): string +{ + $style ??= role_tag_styles()[$label] ?? ''; + return '' . e($label) . ''; +} + function require_permission(string $key): void { require_login(); diff --git a/includes/schema.php b/includes/schema.php index ee7e572..4d8c8e5 100644 --- a/includes/schema.php +++ b/includes/schema.php @@ -11,7 +11,7 @@ declare(strict_types=1); */ // Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu. -const SCHEMA_VERSION = 36; +const SCHEMA_VERSION = 37; /** * Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql). @@ -664,6 +664,9 @@ function schema_column_upgrades(): array ], 'roles' => [ 'discord_role_id' => "ALTER TABLE roles ADD COLUMN discord_role_id BIGINT UNSIGNED NULL AFTER roster_order", + // Eigene Farben des Gruppen-Tags (Mitgliederliste, Profilseite) als #rrggbb - leer = Standard + 'tag_bg' => "ALTER TABLE roles ADD COLUMN tag_bg VARCHAR(7) NULL AFTER discord_role_id", + 'tag_color' => "ALTER TABLE roles ADD COLUMN tag_color VARCHAR(7) NULL AFTER tag_bg", ], // Freigabe von Galeriebildern (Moderation) - vorhandene Bilder bleiben sichtbar 'member_gallery' => [ diff --git a/member.php b/member.php index d51f65b..6c0c8a3 100644 --- a/member.php +++ b/member.php @@ -75,7 +75,7 @@ include __DIR__ . '/includes/header.php';
- +
diff --git a/members.php b/members.php index 4e2341a..493b464 100644 --- a/members.php +++ b/members.php @@ -115,7 +115,7 @@ function member_card(array $member): string if (!empty($roles)) { $html .= '
'; foreach ($roles as $role) { - $html .= '' . e($role) . ''; + $html .= role_tag_html($role); } $html .= '
'; } diff --git a/sql/schema.sql b/sql/schema.sql index 2c5e0ab..17b4d0c 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -76,6 +76,9 @@ CREATE TABLE IF NOT EXISTS roles ( -- Verknuepfte Discord-Rolle: wer sie auf dem Server hat, ist automatisch in dieser -- Gruppe, wer sie verliert, fliegt raus. NULL = Gruppe wird von Hand vergeben. discord_role_id BIGINT UNSIGNED NULL, + -- Eigene Farben des Gruppen-Tags (Mitgliederliste, Profilseite) als #rrggbb - NULL = Standard + tag_bg VARCHAR(7) NULL, + tag_color VARCHAR(7) NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;