query('SELECT department_id FROM help_topics')->fetchAll(PDO::FETCH_COLUMN))); $priorities = $pdo->query('SELECT * FROM priorities ORDER BY sort_order')->fetchAll(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { verify_csrf(); $action = $_POST['action'] ?? ''; if ($action === 'create' || $action === 'update') { $id = $action === 'update' ? (int) ($_POST['id'] ?? 0) : 0; try { help_topic_save($pdo, $id, [ 'name' => $_POST['name'] ?? '', 'department_id' => $_POST['department_id'] ?? 0, 'priority_id' => $_POST['priority_id'] ?? 0, 'is_active' => ($_POST['status'] ?? 'active') === 'active', 'is_public' => ($_POST['type'] ?? 'public') === 'public', 'parent_id' => $_POST['parent_id'] ?? null, 'sla_plan_id' => $_POST['sla_plan_id'] ?? null, 'notes' => $_POST['notes'] ?? '', 'sort_order' => $_POST['sort_order'] ?? 0, ]); audit_log($admin['id'], ($action === 'create' ? 'Hilfethema erstellt: ' : 'Hilfethema aktualisiert: ') . trim($_POST['name'] ?? '')); flash('success', $action === 'create' ? 'Hilfethema erstellt.' : 'Änderungen gespeichert.'); redirect('/staff/help_topics.php'); } catch (AdminModelException $e) { $errors[] = $e->getMessage(); } } if ($action === 'delete') { $deleted = help_topic_delete($pdo, (int) $_POST['id']); audit_log($admin['id'], "Hilfethema gelöscht: {$deleted}"); flash('success', 'Hilfethema gelöscht.'); redirect('/staff/help_topics.php'); } } $isNew = isset($_GET['new']); $editId = (int) ($_GET['edit'] ?? 0); $showForm = $isNew || $editId || ($errors && in_array($_POST['action'] ?? '', ['create', 'update'], true)); $editTopic = null; if ($editId) { $stmt = $pdo->prepare('SELECT * FROM help_topics WHERE id = ?'); $stmt->execute([$editId]); $editTopic = $stmt->fetch() ?: null; } $topicFields = $globalFields = []; $fieldTypeLabels = ['text' => 'Einzeiliger Text', 'textarea' => 'Mehrzeiliger Text', 'select' => 'Dropdown-Auswahl', 'checkbox' => 'Checkbox (Ja/Nein)', 'number' => 'Zahl', 'date' => 'Datum']; if ($editTopic) { $cfStmt = $pdo->prepare('SELECT * FROM custom_fields WHERE help_topic_id = ? ORDER BY sort_order, label'); $cfStmt->execute([$editTopic['id']]); $topicFields = $cfStmt->fetchAll(); $globalFields = $pdo->query('SELECT * FROM custom_fields WHERE help_topic_id IS NULL AND department_id IS NULL AND is_active = 1 ORDER BY sort_order, label')->fetchAll(); } $sortMode = ($_GET['sort'] ?? 'alpha') === 'manual' ? 'manual' : 'alpha'; $topics = $pdo->query( 'SELECT h.*, d.name AS department_name, p.name AS priority_name FROM help_topics h JOIN departments d ON d.id = h.department_id JOIN priorities p ON p.id = h.priority_id ORDER BY ' . ($sortMode === 'manual' ? 'h.sort_order, h.name' : 'h.name') )->fetchAll(); // Anzeigename mit Elternpfad $names = array_column($topics, 'name', 'id'); $parents = array_column($topics, 'parent_id', 'id'); $pathOf = function (int $id) use ($names, $parents): string { $parts = []; $seen = []; while ($id && isset($names[$id]) && !isset($seen[$id])) { $seen[$id] = true; array_unshift($parts, $names[$id]); $id = (int) ($parents[$id] ?? 0); } return implode(' / ', $parts); }; $fmt = fn(?string $dt) => $dt ? date('d.m.Y H:i', strtotime($dt)) : '–'; $pageTitle = 'Hilfethemen'; $activePage = 'help_topics'; require __DIR__ . '/_header.php'; ?>
Hilfethemen erscheinen im Kundenportal als Auswahl bei der Ticket-Erstellung und setzen automatisch Abteilung und Priorität.
| Hilfethema | Status | Typ | Priorität | Abteilung | Zuletzt aktualisiert | Erstellt | |
|---|---|---|---|---|---|---|---|
| = e($pathOf((int) $t['id'])) ?> | = $t['is_active'] ? 'Aktiv' : 'Deaktiviert' ?> | = ($t['is_public'] ?? 1) ? 'Öffentlich' : 'Intern' ?> | = e($t['priority_name']) ?> | = e($t['department_name']) ?> | = e($fmt($t['updated_at'] ?? null)) ?> | = e($fmt($t['created_at'] ?? null)) ?> | Bearbeiten · |
| Noch keine Hilfethemen angelegt. | |||||||