LuminaWebsite/admin/role_delete.php
Maaxxs 3fa3a7310d 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 <noreply@anthropic.com>
2026-09-25 12:35:02 +02:00

40 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/role_icons.php';
require_permission('roles.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/roles.php');
}
verify_csrf();
$id = (int) ($_POST['id'] ?? 0);
$pdo = db();
$stmt = $pdo->prepare('SELECT is_system, tag_icon FROM roles WHERE id = ?');
$stmt->execute([$id]);
$role = $stmt->fetch();
if (!$role) {
set_flash('error', 'Berechtigungsgruppe wurde nicht gefunden.');
} elseif ((int) $role['is_system'] === 1) {
set_flash('error', 'Diese System-Gruppe kann nicht gelöscht werden.');
} else {
$countStmt = $pdo->prepare('SELECT COUNT(*) FROM user_roles WHERE role_id = ?');
$countStmt->execute([$id]);
if ((int) $countStmt->fetchColumn() > 0) {
set_flash('error', 'Diese Gruppe ist noch Benutzern zugewiesen. Bitte zuerst die Zuweisung entfernen.');
} else {
$nameStmt = $pdo->prepare("SELECT COALESCE(NULLIF(display_name, ''), name) FROM roles WHERE id = ?");
$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.');
}
}
redirect('/admin/roles.php');