'Einzeiliger Text', 'textarea' => 'Mehrzeiliger Text', 'select' => 'Dropdown-Auswahl', 'radio' => 'Radio-Auswahl (Punkte)', 'checkbox' => 'Checkbox (Ja/Nein)', 'number' => 'Zahl', 'date' => 'Datum', ]; if ($_SERVER['REQUEST_METHOD'] === 'POST') { verify_csrf(); $action = $_POST['action'] ?? ''; if ($action === 'create' || $action === 'update') { $label = trim($_POST['label'] ?? ''); $type = array_key_exists($_POST['field_type'] ?? '', $fieldTypes) ? $_POST['field_type'] : 'text'; $optionsRaw = trim($_POST['options'] ?? ''); $helpTopicId = ($_POST['help_topic_id'] ?? '') !== '' ? (int) $_POST['help_topic_id'] : null; $isRequired = !empty($_POST['is_required']) ? 1 : 0; $isActive = !empty($_POST['is_active']) ? 1 : 0; $sort = (int) ($_POST['sort_order'] ?? 0); $radioInline = !empty($_POST['radio_inline']) ? 1 : 0; $helpText = form_help_compose((string) ($_POST['help_text'] ?? ''), (string) ($_POST['link_url'] ?? ''), (string) ($_POST['link_word'] ?? ''), $label); if ($label === '') $errors[] = 'Bitte eine Bezeichnung angeben.'; if (in_array($type, ['select', 'radio'], true) && $optionsRaw === '') $errors[] = 'Bitte mindestens eine Option angeben (eine pro Zeile).'; if (!$errors) { if ($action === 'create') { $pdo->prepare('INSERT INTO custom_fields (label, field_type, options, help_topic_id, is_required, is_active, sort_order, radio_inline, help_text, created_at) VALUES (?,?,?,?,?,?,?,?,?,?)') ->execute([$label, $type, $optionsRaw ?: null, $helpTopicId, $isRequired, $isActive, $sort, $radioInline, $helpText ?: null, db_now()]); audit_log($admin['id'], "Ticket-Feld erstellt: {$label}"); flash('success', 'Feld erstellt.'); } else { $id = (int) $_POST['id']; $pdo->prepare('UPDATE custom_fields SET label=?, field_type=?, options=?, help_topic_id=?, is_required=?, is_active=?, sort_order=?, radio_inline=?, help_text=? WHERE id=?') ->execute([$label, $type, $optionsRaw ?: null, $helpTopicId, $isRequired, $isActive, $sort, $radioInline, $helpText ?: null, $id]); audit_log($admin['id'], "Ticket-Feld aktualisiert: {$label}"); flash('success', 'Feld aktualisiert.'); } redirect('/staff/custom_fields.php'); } } if ($action === 'delete') { $id = (int) $_POST['id']; $labelStmt = $pdo->prepare('SELECT label FROM custom_fields WHERE id = ?'); $labelStmt->execute([$id]); $delLabel = $labelStmt->fetchColumn(); $pdo->prepare('DELETE FROM custom_fields WHERE id = ?')->execute([$id]); audit_log($admin['id'], "Ticket-Feld gelöscht: {$delLabel}"); flash('success', 'Feld gelöscht (bereits erfasste Werte bleiben in bestehenden Tickets sichtbar).'); redirect('/staff/custom_fields.php'); } } $fields = $pdo->query( 'SELECT cf.*, ht.name AS help_topic_name FROM custom_fields cf LEFT JOIN help_topics ht ON ht.id = cf.help_topic_id WHERE cf.department_id IS NULL ORDER BY cf.sort_order, cf.label' )->fetchAll(); $helpTopics = $pdo->query('SELECT * FROM help_topics ORDER BY name')->fetchAll(); $editId = $_GET['edit'] ?? null; $editField = null; if ($editId) { $stmt = $pdo->prepare('SELECT * FROM custom_fields WHERE id = ?'); $stmt->execute([$editId]); $editField = $stmt->fetch(); } $pageTitle = 'Ticket-Felder'; $activePage = 'custom_fields'; require __DIR__ . '/_header.php'; ?>
Diese Felder erscheinen zusätzlich zu Name, E-Mail, Betreff und Beschreibung auf dem Formular „Neues Ticket erstellen“. Die eingegebenen Werte werden im Ticket angezeigt.
| Bezeichnung | Typ | Hilfe-Thema | Pflichtfeld | Aktiv | |
|---|---|---|---|---|---|
| = e($f['label']) ?> | = e($fieldTypes[$f['field_type']] ?? $f['field_type']) ?> | = $f['help_topic_name'] ? e($f['help_topic_name']) : 'Alle Themen' ?> | = $f['is_required'] ? '✓' : '–' ?> | = $f['is_active'] ? '✓' : '–' ?> | Bearbeiten · |
| Noch keine individuellen Felder angelegt. | |||||