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';