requireAdmin(); I18n::init(); $db = Database::getInstance(); $appTitle = $db->getSetting('app_title', 'UniFi Voucher System'); $error = ''; $success = ''; // Profil hinzufügen if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_template'])) { if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { $error = __('error_csrf'); } else { try { $name = trim($_POST['name'] ?? ''); $maxUses = (int)($_POST['max_uses'] ?? 1); $expireMin = (int)($_POST['expire_minutes'] ?? 480); $description = trim($_POST['description'] ?? ''); $qosDown = max(0, (int)($_POST['qos_rate_max_down'] ?? 0)) ?: null; $qosUp = max(0, (int)($_POST['qos_rate_max_up'] ?? 0)) ?: null; $qosQuota = max(0, (int)($_POST['qos_usage_quota'] ?? 0)) ?: null; if (empty($name)) throw new Exception(__('error_name_req')); if ($maxUses < 1) $maxUses = 1; if ($expireMin < 1) $expireMin = 60; $db->execute( "INSERT INTO voucher_templates (name, max_uses, expire_minutes, description, qos_rate_max_down, qos_rate_max_up, qos_usage_quota, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [$name, $maxUses, $expireMin, $description, $qosDown, $qosUp, $qosQuota, $_SESSION['user_id']] ); flashSet(__('templates_added')); header('Location: templates.php'); exit; } catch (Exception $e) { $error = $e->getMessage(); } } } // Profil bearbeiten if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_template'])) { if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { $error = __('error_csrf'); } else { try { $id = (int)$_POST['template_id']; $name = trim($_POST['name'] ?? ''); $maxUses = (int)($_POST['max_uses'] ?? 1); $expireMin = (int)($_POST['expire_minutes'] ?? 480); $description = trim($_POST['description'] ?? ''); $isActive = isset($_POST['is_active']) ? 1 : 0; $qosDown = max(0, (int)($_POST['qos_rate_max_down'] ?? 0)) ?: null; $qosUp = max(0, (int)($_POST['qos_rate_max_up'] ?? 0)) ?: null; $qosQuota = max(0, (int)($_POST['qos_usage_quota'] ?? 0)) ?: null; if (empty($name)) throw new Exception(__('error_name_req')); $db->execute( "UPDATE voucher_templates SET name=?, max_uses=?, expire_minutes=?, description=?, qos_rate_max_down=?, qos_rate_max_up=?, qos_usage_quota=?, is_active=? WHERE id=?", [$name, $maxUses, $expireMin, $description, $qosDown, $qosUp, $qosQuota, $isActive, $id] ); flashSet(__('templates_updated')); header('Location: templates.php'); exit; } catch (Exception $e) { $error = $e->getMessage(); } } } // Profil löschen (POST + PRG) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_template'])) { if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { $db->execute("DELETE FROM voucher_templates WHERE id = ?", [(int)$_POST['delete_template']]); flashSet(__('templates_deleted')); header('Location: templates.php'); exit; } else { $error = __('error_csrf'); } } if (empty($success) && empty($error) && ($flash = flashGet())) { $success = $flash['message']; } $templates = $db->fetchAll("SELECT t.*, u.name as creator FROM voucher_templates t LEFT JOIN users u ON t.created_by = u.id ORDER BY t.is_active DESC, t.name"); $currentPage = 'templates'; $adminBase = ''; ?> <?= __('templates_title') ?> - <?= htmlspecialchars($appTitle) ?>

Profile

= 1440 && $m % 1440 === 0) { $durLabel = ($m / 1440) . ' Tag' . ($m / 1440 > 1 ? 'e' : ''); } elseif ($m >= 60 && $m % 60 === 0) { $durLabel = ($m / 60) . ' Std.'; } else { $durLabel = $m . ' Min.'; } ?>