Files
deskhub/DeskHub-Webseite/staff/ticket_templates.php
T
2026-11-05 21:21:52 +00:00

85 lines
6.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../includes/bootstrap.php';
$admin = require_admin_or_permission('manage_ticket_templates');
$pdo = get_db();
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
$action = $_POST['action'] ?? '';
if ($action === 'save') {
$id = (int) ($_POST['id'] ?? 0) ?: null;
$r = ticket_template_save($pdo, $id, $_POST);
if (!$r['ok']) {
$errors[] = $r['error'];
} else {
audit_log($admin['id'], 'Ticket-Vorlage gespeichert: ' . trim((string) ($_POST['name'] ?? '')));
flash('success', 'Vorlage gespeichert.');
redirect('/staff/ticket_templates.php');
}
} elseif ($action === 'delete') {
ticket_template_delete($pdo, (int) ($_POST['id'] ?? 0));
audit_log($admin['id'], 'Ticket-Vorlage gelöscht');
flash('success', 'Vorlage gelöscht.');
redirect('/staff/ticket_templates.php');
}
}
$departments = $pdo->query('SELECT id, name FROM departments ORDER BY name')->fetchAll();
$priorities = $pdo->query('SELECT id, name FROM priorities ORDER BY id')->fetchAll();
$helpTopics = help_topic_options($pdo);
$templates = ticket_templates_list($pdo, false, true);
$editing = null;
if (!empty($_GET['edit'])) {
foreach ($templates as $t) if ((int) $t['id'] === (int) $_GET['edit']) $editing = $t;
}
// Bei einem Fehler die eingegebenen Werte behalten
$v = $errors ? $_POST : ($editing ?: ['is_public' => 1, 'is_active' => 1, 'sort_order' => count($templates) * 10 + 10]);
$pageTitle = 'Ticket-Vorlagen';
$activePage = 'ticket_templates';
require __DIR__ . '/_header.php';
?>
<h1>Ticket-Vorlagen</h1>
<?php foreach ($errors as $err): ?><div class="flash error"><?= e($err) ?></div><?php endforeach; ?>
<p class="muted" style="max-width:820px">Vorbelegte Formulare für häufige Anliegen, zum Beispiel „Neuer Mitarbeiter“ oder „Passwort zurücksetzen“. Kunden wählen sie auf der Seite „Neues Ticket“ (wenn sie für Kunden sichtbar sind), Mitarbeiter beim Anlegen eines Tickets im Web, im Windows-Programm und in der App.</p>
<form method="post" class="card" style="max-width:820px;margin-bottom:16px"><?= csrf_field() ?>
<input type="hidden" name="action" value="save"><input type="hidden" name="id" value="<?= (int) ($editing['id'] ?? $_POST['id'] ?? 0) ?>">
<h3><?= $editing || !empty($_POST['id']) ? 'Vorlage bearbeiten' : 'Neue Vorlage' ?></h3>
<div class="field-row">
<div><label for="name">Name der Vorlage</label><input type="text" id="name" name="name" maxlength="120" required value="<?= e((string) ($v['name'] ?? '')) ?>" placeholder="z. B. Neuer Mitarbeiter"></div>
<div><label for="description">Kurzbeschreibung (optional)</label><input type="text" id="description" name="description" maxlength="255" value="<?= e((string) ($v['description'] ?? '')) ?>"></div>
</div>
<label for="subject" style="margin-top:8px">Betreff</label>
<input type="text" id="subject" name="subject" maxlength="200" value="<?= e((string) ($v['subject'] ?? '')) ?>" placeholder="Vorgabe für den Betreff">
<label for="body" style="margin-top:8px">Text</label>
<textarea id="body" name="body" rows="7" maxlength="10000" placeholder="Zum Beispiel eine Liste mit den Angaben, die Sie brauchen: Name, Startdatum, benötigte Geräte …"><?= e((string) ($v['body'] ?? '')) ?></textarea>
<div class="field-row" style="margin-top:8px">
<div><label for="department_id">Abteilung</label><select id="department_id" name="department_id"><option value="">– nicht vorgeben –</option><?php foreach ($departments as $d): ?><option value="<?= (int) $d['id'] ?>" <?= (int) ($v['department_id'] ?? 0) === (int) $d['id'] ? 'selected' : '' ?>><?= e($d['name']) ?></option><?php endforeach; ?></select></div>
<div><label for="help_topic_id">Hilfethema</label><select id="help_topic_id" name="help_topic_id"><option value="">– nicht vorgeben –</option><?php foreach ($helpTopics as $h): ?><option value="<?= (int) $h['id'] ?>" <?= (int) ($v['help_topic_id'] ?? 0) === (int) $h['id'] ? 'selected' : '' ?>><?= e($h['path']) ?></option><?php endforeach; ?></select></div>
<div><label for="priority_id">Priorität</label><select id="priority_id" name="priority_id"><option value="">– nicht vorgeben –</option><?php foreach ($priorities as $p): ?><option value="<?= (int) $p['id'] ?>" <?= (int) ($v['priority_id'] ?? 0) === (int) $p['id'] ? 'selected' : '' ?>><?= e($p['name']) ?></option><?php endforeach; ?></select></div>
</div>
<div style="display:flex;gap:18px;flex-wrap:wrap;margin-top:10px;align-items:center">
<label style="font-weight:400"><input type="checkbox" name="is_public" value="1" style="width:auto" <?= !empty($v['is_public']) ? 'checked' : '' ?>> Für Kunden sichtbar (auf „Neues Ticket“)</label>
<label style="font-weight:400"><input type="checkbox" name="is_active" value="1" style="width:auto" <?= !isset($v['is_active']) || !empty($v['is_active']) ? 'checked' : '' ?>> Aktiv</label>
<label style="font-weight:400">Reihenfolge <input type="number" name="sort_order" value="<?= (int) ($v['sort_order'] ?? 0) ?>" style="width:80px"></label>
</div>
<div class="btn-row"><button type="submit" class="btn">Speichern</button><?php if ($editing): ?> <a class="btn secondary" href="/staff/ticket_templates.php">Abbrechen</a><?php endif; ?></div>
</form>
<div class="card" style="max-width:820px">
<h3>Vorhandene Vorlagen</h3>
<?php if (!$templates): ?><p class="muted">Noch keine Vorlagen.</p><?php endif; ?>
<?php foreach ($templates as $t): ?>
<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;padding:10px 0;border-top:1px solid var(--border,#e3e9ee)">
<div style="flex:1;min-width:200px"><strong><?= e($t['name']) ?></strong>
<?= $t['is_public'] ? '<span class="muted" style="font-size:.76rem"> · für Kunden</span>' : '<span class="muted" style="font-size:.76rem"> · nur Mitarbeiter</span>' ?>
<?= $t['is_active'] ? '' : '<span style="color:#b45309;font-size:.76rem"> · inaktiv</span>' ?>
<?php if ($t['description']): ?><div class="muted" style="font-size:.82rem"><?= e($t['description']) ?></div><?php endif; ?></div>
<a class="btn secondary" href="/staff/ticket_templates.php?edit=<?= (int) $t['id'] ?>" style="padding:3px 12px;font-size:.8rem">Bearbeiten</a>
<form method="post" onsubmit="return confirm('Vorlage löschen?')"><?= csrf_field() ?><input type="hidden" name="action" value="delete"><input type="hidden" name="id" value="<?= (int) $t['id'] ?>"><button class="btn secondary" type="submit" style="padding:3px 12px;font-size:.8rem">Löschen</button></form>
</div>
<?php endforeach; ?>
</div>
<?php require __DIR__ . '/_footer.php'; ?>