- Kontrast: gedämpfter Text war mit 3,1:1 unter WCAG AA, jetzt 4,9:1 (hell) bzw. 6,4:1 (dunkel) - Sprungmarke „Zum Inhalt springen" in Admin-Shell und Voucher-Seite - aria-label für alle reinen Icon-Schaltflächen (Theme, Menü, Abmelden, Zeilenaktionen), aria-current auf dem aktiven Navigationspunkt, role="group" für den Sprachumschalter - 194 dekorative Icons mit aria-hidden versehen, damit Screenreader sie nicht vorlesen - Toast-Container als aria-live-Bereich ausgezeichnet - prefers-reduced-motion schaltet Animationen und Übergänge ab Tabellen (Benutzer, Vouchers, Profile, Audit-Log, Dashboard, API-Keys) werden unter 720 px zu Karten: die Spaltenüberschrift steht per data-label vor dem Wert, statt horizontal zu scrollen. Datums- und Zeitformat in der Voucher-Liste folgen jetzt der gewählten Sprache statt fest de-DE. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
295 lines
16 KiB
PHP
295 lines
16 KiB
PHP
<?php
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 0);
|
|
ini_set('log_errors', 1);
|
|
|
|
require_once __DIR__ . '/../config.php';
|
|
require_once __DIR__ . '/../includes/Database.php';
|
|
require_once __DIR__ . '/../includes/Auth.php';
|
|
require_once __DIR__ . '/../includes/I18n.php';
|
|
|
|
$auth = new Auth();
|
|
$auth->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']]
|
|
);
|
|
$success = __('templates_added');
|
|
} 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]
|
|
);
|
|
$success = __('templates_updated');
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Profil löschen
|
|
if (isset($_GET['delete']) && isset($_GET['token'])) {
|
|
if ($auth->validateCsrfToken($_GET['token'])) {
|
|
$db->execute("DELETE FROM voucher_templates WHERE id = ?", [(int)$_GET['delete']]);
|
|
$success = __('templates_deleted');
|
|
} else {
|
|
$error = __('error_csrf');
|
|
}
|
|
}
|
|
|
|
$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 = '';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="<?= I18n::getLanguage() ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= __('templates_title') ?> - <?= htmlspecialchars($appTitle) ?></title>
|
|
<?php include __DIR__ . '/../includes/admin_nav.php'; ?>
|
|
|
|
<div class="page-header">
|
|
<div>
|
|
<h1 class="page-title"><?= __('templates_title') ?></h1>
|
|
<p class="page-subtitle"><?= __('templates_subtitle') ?></p>
|
|
</div>
|
|
<button onclick="openAddModal()" class="btn btn-primary">
|
|
<i class="fas fa-plus" aria-hidden="true"></i> <?= __('templates_add') ?>
|
|
</button>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-error"><i class="fas fa-exclamation-circle" aria-hidden="true"></i> <?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success"><i class="fas fa-check-circle" aria-hidden="true"></i> <?= htmlspecialchars($success) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2 class="card-title"><?= __('templates_title') ?></h2>
|
|
<span style="font-size: 13px; color: var(--text-muted);"><?= count($templates) ?> Profile</span>
|
|
</div>
|
|
<?php if (empty($templates)): ?>
|
|
<div class="empty-state">
|
|
<i class="fas fa-layer-group" aria-hidden="true"></i>
|
|
<p style="font-size: 15px; margin-bottom: 8px;"><?= __('templates_none') ?></p>
|
|
<p style="font-size: 13px;"><?= __('templates_add_hint') ?></p>
|
|
<button onclick="openAddModal()" class="btn btn-primary" style="margin-top: 20px;"><i class="fas fa-plus" aria-hidden="true"></i> <?= __('templates_add') ?></button>
|
|
</div>
|
|
<?php else: ?>
|
|
<div style="overflow-x: auto;">
|
|
<div class="table-container">
|
|
<table class="table table-stack">
|
|
<thead>
|
|
<tr>
|
|
<th><?= __('templates_name') ?></th>
|
|
<th><?= __('templates_devices') ?></th>
|
|
<th><?= __('templates_duration') ?></th>
|
|
<th><?= __('templates_desc') ?></th>
|
|
<th><?= __('label_status') ?></th>
|
|
<th><?= __('label_actions') ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($templates as $t): ?>
|
|
<tr>
|
|
<td data-label="<?= __('templates_name') ?>"><strong><?= htmlspecialchars($t['name']) ?></strong></td>
|
|
<td data-label="<?= __('templates_devices') ?>">
|
|
<span class="duration-badge"><i class="fas fa-mobile-alt" aria-hidden="true"></i> <?= (int)$t['max_uses'] ?></span>
|
|
</td>
|
|
<td data-label="<?= __('templates_duration') ?>">
|
|
<?php
|
|
$m = (int)$t['expire_minutes'];
|
|
if ($m >= 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.';
|
|
}
|
|
?>
|
|
<span class="duration-badge"><i class="fas fa-clock" aria-hidden="true"></i> <?= $durLabel ?></span>
|
|
</td>
|
|
<td data-label="<?= __('templates_desc') ?>" style="color: var(--text-secondary);"><?= htmlspecialchars($t['description'] ?? '-') ?></td>
|
|
<td data-label="<?= __('label_status') ?>">
|
|
<?php if ($t['is_active']): ?>
|
|
<span class="badge badge-success"><?= __('status_active') ?></span>
|
|
<?php else: ?>
|
|
<span class="badge badge-secondary"><?= __('status_inactive') ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td data-label="<?= __('label_actions') ?>">
|
|
<button onclick="openEditModal(<?= $t['id'] ?>, '<?= htmlspecialchars($t['name'], ENT_QUOTES) ?>', <?= (int)$t['max_uses'] ?>, <?= (int)$t['expire_minutes'] ?>, '<?= htmlspecialchars($t['description'] ?? '', ENT_QUOTES) ?>', <?= (int)$t['is_active'] ?>, <?= (int)($t['qos_rate_max_down'] ?? 0) ?>, <?= (int)($t['qos_rate_max_up'] ?? 0) ?>, <?= (int)($t['qos_usage_quota'] ?? 0) ?>)"
|
|
class="btn btn-secondary btn-small"><i class="fas fa-edit" aria-hidden="true"></i></button>
|
|
<a href="?delete=<?= $t['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
|
onclick="return confirm('<?= __('js_confirm_delete_template') ?>')"
|
|
class="btn btn-danger-soft btn-small"><i class="fas fa-trash" aria-hidden="true"></i></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<!-- Modal: Hinzufügen -->
|
|
<div id="addModal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h2 class="modal-title"><i class="fas fa-plus-circle" style="color: var(--accent);" aria-hidden="true"></i> <?= __('templates_add') ?></h2>
|
|
<button class="modal-close" onclick="closeModal('addModal')">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="post">
|
|
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
|
<div class="form-group"><label><?= __('templates_name') ?> *</label><input type="text" name="name" required placeholder="z.B. Tagespass, Event 4h"></div>
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
|
|
<div class="form-group">
|
|
<label><?= __('templates_devices') ?></label>
|
|
<input type="number" name="max_uses" value="1" min="1" max="100">
|
|
<div class="help-text">Max. gleichzeitige Geräte</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label><?= __('templates_duration') ?> *</label>
|
|
<input type="number" name="expire_minutes" value="480" min="1" max="525600">
|
|
<div class="help-text"><?= __('templates_minutes_hint') ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group"><label><?= __('templates_desc') ?></label><textarea name="description" rows="2" placeholder="<?= __('templates_desc_placeholder') ?>"></textarea></div>
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px;">
|
|
<div class="form-group"><label>Download (kbit/s)</label><input type="number" name="qos_rate_max_down" min="0" placeholder="0 = unbegrenzt"></div>
|
|
<div class="form-group"><label>Upload (kbit/s)</label><input type="number" name="qos_rate_max_up" min="0" placeholder="0 = unbegrenzt"></div>
|
|
<div class="form-group"><label>Datenlimit (MB)</label><input type="number" name="qos_usage_quota" min="0" placeholder="0 = unbegrenzt"></div>
|
|
</div>
|
|
<div style="display:flex;gap:10px;margin-top:20px;">
|
|
<button type="submit" name="add_template" class="btn btn-primary" style="flex:1;"><i class="fas fa-save" aria-hidden="true"></i> <?= __('btn_save') ?></button>
|
|
<button type="button" onclick="closeModal('addModal')" class="btn btn-secondary"><?= __('btn_cancel') ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal: Bearbeiten -->
|
|
<div id="editModal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h2 class="modal-title"><i class="fas fa-edit" style="color: var(--accent);" aria-hidden="true"></i> <?= __('templates_edit') ?></h2>
|
|
<button class="modal-close" onclick="closeModal('editModal')">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="post">
|
|
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
|
<input type="hidden" name="template_id" id="editId">
|
|
<div class="form-group"><label><?= __('templates_name') ?> *</label><input type="text" name="name" id="editName" required></div>
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
|
|
<div class="form-group">
|
|
<label><?= __('templates_devices') ?></label>
|
|
<input type="number" name="max_uses" id="editMaxUses" min="1" max="100">
|
|
</div>
|
|
<div class="form-group">
|
|
<label><?= __('templates_duration') ?></label>
|
|
<input type="number" name="expire_minutes" id="editExpireMin" min="1">
|
|
</div>
|
|
</div>
|
|
<div class="form-group"><label><?= __('templates_desc') ?></label><textarea name="description" id="editDesc" rows="2"></textarea></div>
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px;">
|
|
<div class="form-group"><label>Download (kbit/s)</label><input type="number" name="qos_rate_max_down" id="editQosDown" min="0" placeholder="0 = unbegrenzt"></div>
|
|
<div class="form-group"><label>Upload (kbit/s)</label><input type="number" name="qos_rate_max_up" id="editQosUp" min="0" placeholder="0 = unbegrenzt"></div>
|
|
<div class="form-group"><label>Datenlimit (MB)</label><input type="number" name="qos_usage_quota" id="editQosQuota" min="0" placeholder="0 = unbegrenzt"></div>
|
|
</div>
|
|
<div class="checkbox-group" style="margin-bottom:20px;">
|
|
<input type="checkbox" name="is_active" id="editActive">
|
|
<label for="editActive" style="margin:0;"><?= __('status_active') ?></label>
|
|
</div>
|
|
<div style="display:flex;gap:10px;">
|
|
<button type="submit" name="edit_template" class="btn btn-primary" style="flex:1;"><i class="fas fa-save" aria-hidden="true"></i> <?= __('btn_save') ?></button>
|
|
<button type="button" onclick="closeModal('editModal')" class="btn btn-secondary"><?= __('btn_cancel') ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="../assets/global.js"></script>
|
|
<script>
|
|
function openAddModal() { document.getElementById('addModal').classList.add('active'); }
|
|
function closeModal(id) { document.getElementById(id).classList.remove('active'); }
|
|
function openEditModal(id, name, maxUses, expMin, desc, isActive, qosDown, qosUp, qosQuota) {
|
|
document.getElementById('editId').value = id;
|
|
document.getElementById('editName').value = name;
|
|
document.getElementById('editMaxUses').value = maxUses;
|
|
document.getElementById('editExpireMin').value = expMin;
|
|
document.getElementById('editDesc').value = desc;
|
|
document.getElementById('editActive').checked = isActive == 1;
|
|
document.getElementById('editQosDown').value = qosDown || '';
|
|
document.getElementById('editQosUp').value = qosUp || '';
|
|
document.getElementById('editQosQuota').value = qosQuota || '';
|
|
document.getElementById('editModal').classList.add('active');
|
|
}
|
|
['addModal','editModal'].forEach(id => {
|
|
document.getElementById(id).addEventListener('click', function(e) {
|
|
if (e.target === this) closeModal(id);
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|