Initial Upload
This commit is contained in:
commit
dbdc237fa1
22 changed files with 7995 additions and 0 deletions
1027
admin/index.php
Normal file
1027
admin/index.php
Normal file
File diff suppressed because it is too large
Load diff
799
admin/settings.php
Normal file
799
admin/settings.php
Normal file
|
|
@ -0,0 +1,799 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
require_once __DIR__ . '/../config.php';
|
||||
require_once __DIR__ . '/../includes/Database.php';
|
||||
require_once __DIR__ . '/../includes/Auth.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$auth->requireAdmin();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
// Einstellungen speichern
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_settings'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$settings = [];
|
||||
$formType = $_POST['form_type'] ?? '';
|
||||
|
||||
// Allgemeine Einstellungen
|
||||
if ($formType === 'general') {
|
||||
$settings['app_title'] = trim($_POST['app_title'] ?? '');
|
||||
$settings['logo_url'] = trim($_POST['logo_url'] ?? '');
|
||||
$settings['favicon_url'] = trim($_POST['favicon_url'] ?? '');
|
||||
$settings['instruction_header'] = trim($_POST['instruction_header'] ?? '');
|
||||
$settings['instruction_text'] = $_POST['instruction_text'] ?? '';
|
||||
$settings['public_access'] = isset($_POST['public_access']) ? '1' : '0';
|
||||
}
|
||||
|
||||
// M365 Einstellungen
|
||||
if ($formType === 'm365') {
|
||||
$settings['m365_client_id'] = trim($_POST['m365_client_id'] ?? '');
|
||||
$settings['m365_client_secret'] = trim($_POST['m365_client_secret'] ?? '');
|
||||
$settings['m365_tenant_id'] = trim($_POST['m365_tenant_id'] ?? '');
|
||||
}
|
||||
|
||||
// SMTP Einstellungen
|
||||
if ($formType === 'smtp') {
|
||||
$settings['smtp_enabled'] = isset($_POST['smtp_enabled']) ? '1' : '0';
|
||||
$settings['smtp_host'] = trim($_POST['smtp_host'] ?? '');
|
||||
$settings['smtp_port'] = trim($_POST['smtp_port'] ?? '587');
|
||||
$settings['smtp_username'] = trim($_POST['smtp_username'] ?? '');
|
||||
if (!empty($_POST['smtp_password'])) {
|
||||
$settings['smtp_password'] = trim($_POST['smtp_password']);
|
||||
}
|
||||
$settings['smtp_encryption'] = trim($_POST['smtp_encryption'] ?? 'tls');
|
||||
$settings['smtp_from_email'] = trim($_POST['smtp_from_email'] ?? '');
|
||||
$settings['smtp_from_name'] = trim($_POST['smtp_from_name'] ?? '');
|
||||
}
|
||||
|
||||
// E-Mail Templates
|
||||
if ($formType === 'templates') {
|
||||
$settings['email_voucher_subject'] = trim($_POST['email_voucher_subject'] ?? '');
|
||||
$settings['email_voucher_body'] = $_POST['email_voucher_body'] ?? '';
|
||||
$settings['email_user_notification_subject'] = trim($_POST['email_user_notification_subject'] ?? '');
|
||||
$settings['email_user_notification_body'] = $_POST['email_user_notification_body'] ?? '';
|
||||
$settings['system_url'] = trim($_POST['system_url'] ?? '');
|
||||
}
|
||||
|
||||
// System Einstellungen
|
||||
if ($formType === 'system') {
|
||||
$settings['tinymce_api_key'] = trim($_POST['tinymce_api_key'] ?? '');
|
||||
$settings['print_template'] = $_POST['print_template'] ?? '';
|
||||
}
|
||||
|
||||
foreach ($settings as $key => $value) {
|
||||
$db->setSetting($key, $value);
|
||||
}
|
||||
|
||||
$success = 'Einstellungen erfolgreich gespeichert!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = 'Fehler: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cron-Token generieren
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['generate_cron_token'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
// Sicheren Token generieren
|
||||
$newToken = bin2hex(random_bytes(32));
|
||||
$db->setSetting('cron_token', $newToken);
|
||||
$success = 'Neuer Cron-Token wurde generiert!';
|
||||
} catch (Exception $e) {
|
||||
$error = 'Fehler: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cron-Token löschen
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_cron_token'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$db->setSetting('cron_token', '');
|
||||
$success = 'Cron-Token wurde gelöscht!';
|
||||
} catch (Exception $e) {
|
||||
$error = 'Fehler: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Passwort ändern
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$currentPassword = $_POST['current_password'];
|
||||
$newPassword = $_POST['new_password'];
|
||||
$confirmPassword = $_POST['confirm_password'];
|
||||
|
||||
$user = $auth->getCurrentUser();
|
||||
|
||||
if (!password_verify($currentPassword, $user['password_hash'])) {
|
||||
throw new Exception('Aktuelles Passwort ist falsch');
|
||||
}
|
||||
|
||||
if (strlen($newPassword) < 8) {
|
||||
throw new Exception('Neues Passwort muss mindestens 8 Zeichen lang sein');
|
||||
}
|
||||
|
||||
if ($newPassword !== $confirmPassword) {
|
||||
throw new Exception('Passwörter stimmen nicht überein');
|
||||
}
|
||||
|
||||
$newHash = password_hash($newPassword, PASSWORD_DEFAULT);
|
||||
$db->query("UPDATE users SET password_hash = ? WHERE id = ?", [$newHash, $user['id']]);
|
||||
|
||||
$success = 'Passwort erfolgreich geändert!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Aktuelle Einstellungen laden
|
||||
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$scriptPath = dirname($_SERVER['SCRIPT_NAME'], 2);
|
||||
$scriptPath = $scriptPath === '/' ? '' : $scriptPath;
|
||||
$autoDetectedUrl = $protocol . '://' . $host . $scriptPath;
|
||||
|
||||
$currentSettings = [
|
||||
'app_title' => $db->getSetting('app_title', 'UniFi Voucher System'),
|
||||
'logo_url' => $db->getSetting('logo_url', ''),
|
||||
'favicon_url' => $db->getSetting('favicon_url', ''),
|
||||
'instruction_header' => $db->getSetting('instruction_header', 'So verwenden Sie Ihren Code'),
|
||||
'instruction_text' => $db->getSetting('instruction_text', 'Verbinden Sie sich mit dem WLAN und geben Sie den Code ein.'),
|
||||
'public_access' => $db->getSetting('public_access', '0'),
|
||||
'm365_client_id' => $db->getSetting('m365_client_id', ''),
|
||||
'm365_client_secret' => $db->getSetting('m365_client_secret', ''),
|
||||
'm365_tenant_id' => $db->getSetting('m365_tenant_id', ''),
|
||||
'smtp_enabled' => $db->getSetting('smtp_enabled', '0'),
|
||||
'smtp_host' => $db->getSetting('smtp_host', ''),
|
||||
'smtp_port' => $db->getSetting('smtp_port', '587'),
|
||||
'smtp_username' => $db->getSetting('smtp_username', ''),
|
||||
'smtp_password' => $db->getSetting('smtp_password', ''),
|
||||
'smtp_encryption' => $db->getSetting('smtp_encryption', 'tls'),
|
||||
'smtp_from_email' => $db->getSetting('smtp_from_email', ''),
|
||||
'smtp_from_name' => $db->getSetting('smtp_from_name', ''),
|
||||
'system_url' => $db->getSetting('system_url', $autoDetectedUrl),
|
||||
'email_voucher_subject' => $db->getSetting('email_voucher_subject', '{APP_TITLE} - Ihr WLAN-Zugang'),
|
||||
'email_voucher_body' => $db->getSetting('email_voucher_body', "Hallo,\n\nIhr Code: {VOUCHER_CODE}\n\nGültigkeit: 8h\nGeräte: {MAX_USES}\nSite: {SITE_NAME}"),
|
||||
'email_user_notification_subject' => $db->getSetting('email_user_notification_subject', '{APP_TITLE} - Berechtigungen geändert'),
|
||||
'email_user_notification_body' => $db->getSetting('email_user_notification_body', "Hallo {USER_NAME},\n\n{CHANGES}"),
|
||||
'tinymce_api_key' => $db->getSetting('tinymce_api_key', ''),
|
||||
'print_template' => $db->getSetting('print_template', '<div style="text-align:center;padding:40px"><h1>{APP_TITLE}</h1><h2>WLAN Code</h2><div style="font-size:48px;font-weight:bold;margin:30px 0;font-family:monospace">{VOUCHER_CODE}</div><p><strong>Gültig bis:</strong> {EXPIRY_DATE} {EXPIRY_TIME}</p><p><strong>Site:</strong> {SITE_NAME}</p><p><strong>Geräte:</strong> {MAX_USES}</p><hr style="margin:30px 0"><div>{INSTRUCTIONS}</div></div>'),
|
||||
'cron_token' => $db->getSetting('cron_token', ''),
|
||||
'last_cron_sync' => $db->getSetting('last_cron_sync', '')
|
||||
];
|
||||
|
||||
$currentUser = $auth->getCurrentUser();
|
||||
$faviconUrl = $db->getSetting('favicon_url', '');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Einstellungen - <?= htmlspecialchars($appTitle) ?></title>
|
||||
<?php if ($faviconUrl): ?>
|
||||
<link rel="icon" type="image/x-icon" href="<?= htmlspecialchars($faviconUrl) ?>">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
|
||||
<!-- TinyMCE -->
|
||||
<?php if (!empty($currentSettings['tinymce_api_key'])): ?>
|
||||
<script src="https://cdn.tiny.cloud/1/<?= htmlspecialchars($currentSettings['tinymce_api_key']) ?>/tinymce/6/tinymce.min.js"></script>
|
||||
<?php else: ?>
|
||||
<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/6/tinymce.min.js"></script>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f7fa; }
|
||||
.header { background: white; border-bottom: 1px solid #e0e0e0; padding: 0 30px; height: 70px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
|
||||
.header-title { font-size: 20px; font-weight: 600; color: #333; }
|
||||
.sidebar { position: fixed; left: 0; top: 70px; bottom: 0; width: 260px; background: white; border-right: 1px solid #e0e0e0; padding: 30px 0; }
|
||||
.sidebar-nav { list-style: none; }
|
||||
.sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 12px 30px; color: #666; text-decoration: none; transition: all 0.2s; font-size: 15px; }
|
||||
.sidebar-nav a:hover, .sidebar-nav a.active { background: #f8f9fa; color: #667eea; }
|
||||
.sidebar-nav i { width: 20px; text-align: center; }
|
||||
.main-content { margin-left: 260px; padding: 30px; min-height: calc(100vh - 70px); }
|
||||
.page-header { margin-bottom: 30px; }
|
||||
.page-title { font-size: 28px; font-weight: 600; color: #333; margin-bottom: 10px; }
|
||||
.btn { padding: 10px 20px; border-radius: 8px; border: none; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s; font-size: 14px; }
|
||||
.btn-primary { background: #667eea; color: white; }
|
||||
.btn-primary:hover { background: #5568d3; }
|
||||
.btn-secondary { background: #f8f9fa; color: #666; border: 1px solid #e0e0e0; }
|
||||
.alert { padding: 14px 20px; border-radius: 10px; margin-bottom: 25px; font-size: 14px; display: flex; align-items: center; gap: 10px; }
|
||||
.alert-error { background: #fee; border: 1px solid #fcc; color: #c33; }
|
||||
.alert-success { background: #efe; border: 1px solid #cfc; color: #3c3; }
|
||||
|
||||
.tab-container { background: white; border-radius: 15px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); border: 1px solid #e0e0e0; overflow: hidden; }
|
||||
.tab-navigation { display: flex; background: #f8f9fa; border-bottom: 2px solid #e0e0e0; overflow-x: auto; position: sticky; top: 70px; z-index: 50; }
|
||||
.tab-button { padding: 18px 25px; background: transparent; border: none; border-bottom: 3px solid transparent; cursor: pointer; font-size: 14px; font-weight: 500; color: #666; transition: all 0.3s; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
|
||||
.tab-button:hover { background: rgba(102, 126, 234, 0.1); color: #667eea; }
|
||||
.tab-button.active { color: #667eea; border-bottom-color: #667eea; background: white; }
|
||||
.tab-content { display: none; padding: 30px; animation: fadeIn 0.3s; }
|
||||
.tab-content.active { display: block; }
|
||||
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
||||
|
||||
.form-group { margin-bottom: 20px; }
|
||||
label { display: block; margin-bottom: 8px; color: #555; font-weight: 500; font-size: 14px; }
|
||||
input[type="text"], input[type="url"], input[type="password"], input[type="number"], select, textarea { width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 8px; font-size: 14px; transition: border-color 0.3s; font-family: inherit; }
|
||||
input:focus, textarea:focus, select:focus { outline: none; border-color: #667eea; }
|
||||
textarea { resize: vertical; min-height: 100px; }
|
||||
.checkbox-group { display: flex; align-items: center; gap: 10px; }
|
||||
.checkbox-group input { width: auto; accent-color: #667eea; }
|
||||
.help-text { font-size: 12px; color: #999; margin-top: 4px; }
|
||||
.info-box { background: #e7f3ff; border: 1px solid #b3d9ff; border-radius: 8px; padding: 15px; margin-bottom: 20px; }
|
||||
.info-box h4 { color: #0066cc; margin-bottom: 8px; font-size: 14px; }
|
||||
.info-box p { color: #004d99; font-size: 13px; line-height: 1.5; }
|
||||
.section-divider { border-top: 2px solid #f0f0f0; margin: 30px 0; }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
|
||||
.placeholder-info { background: #fff9e6; border: 1px solid #ffe066; border-radius: 8px; padding: 15px; margin: 15px 0; }
|
||||
.placeholder-info h4 { color: #996600; margin-bottom: 8px; font-size: 14px; }
|
||||
.placeholder-info code { background: #fff; padding: 2px 6px; border-radius: 3px; font-size: 12px; color: #d63384; }
|
||||
.placeholder-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<div class="header-title"><i class="fas fa-shield-alt"></i> Administration</div>
|
||||
<a href="../index.php" class="btn btn-secondary"><i class="fas fa-arrow-left"></i> Zurück</a>
|
||||
</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<nav class="sidebar-nav">
|
||||
<ul>
|
||||
<li><a href="index.php"><i class="fas fa-home"></i> Dashboard</a></li>
|
||||
<li><a href="sites.php"><i class="fas fa-map-marker-alt"></i> Sites verwalten</a></li>
|
||||
<li><a href="users.php"><i class="fas fa-users"></i> Benutzer verwalten</a></li>
|
||||
<li><a href="vouchers.php"><i class="fas fa-ticket-alt"></i> Voucher-Historie</a></li>
|
||||
<li><a href="settings.php" class="active"><i class="fas fa-cog"></i> Einstellungen</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Einstellungen</h1>
|
||||
<p style="color: #666; font-size: 14px;">System-Konfiguration und Personalisierung</p>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error"><i class="fas fa-exclamation-circle"></i><span><?= htmlspecialchars($error) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><i class="fas fa-check-circle"></i><span><?= htmlspecialchars($success) ?></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="tab-container">
|
||||
<div class="tab-navigation">
|
||||
<button class="tab-button active" onclick="switchTab('general')"><i class="fas fa-sliders-h"></i> Allgemein</button>
|
||||
<button class="tab-button" onclick="switchTab('cron')"><i class="fas fa-clock"></i> Cron-Sync</button>
|
||||
<button class="tab-button" onclick="switchTab('m365')"><i class="fab fa-microsoft"></i> Microsoft 365</button>
|
||||
<button class="tab-button" onclick="switchTab('smtp')"><i class="fas fa-envelope"></i> SMTP</button>
|
||||
<button class="tab-button" onclick="switchTab('templates')"><i class="fas fa-file-alt"></i> Templates</button>
|
||||
<button class="tab-button" onclick="switchTab('system')"><i class="fas fa-cogs"></i> System</button>
|
||||
<button class="tab-button" onclick="switchTab('password')"><i class="fas fa-key"></i> Passwort</button>
|
||||
</div>
|
||||
|
||||
<!-- TAB: Allgemein -->
|
||||
<div id="tab-general" class="tab-content active">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-sliders-h"></i> Allgemeine Einstellungen</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="form_type" value="general">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="app_title">Anwendungs-Titel *</label>
|
||||
<input type="text" id="app_title" name="app_title" value="<?= htmlspecialchars($currentSettings['app_title']) ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="logo_url">Logo-URL</label>
|
||||
<input type="url" id="logo_url" name="logo_url" value="<?= htmlspecialchars($currentSettings['logo_url']) ?>" placeholder="https://example.com/logo.png">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="favicon_url">Favicon-URL</label>
|
||||
<input type="url" id="favicon_url" name="favicon_url" value="<?= htmlspecialchars($currentSettings['favicon_url']) ?>" placeholder="https://example.com/favicon.ico">
|
||||
<div class="help-text">Icon im Browser-Tab (.ico, .png, .svg)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="instruction_header">Anleitung - Überschrift</label>
|
||||
<input type="text" id="instruction_header" name="instruction_header" value="<?= htmlspecialchars($currentSettings['instruction_header']) ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="instruction_text">Anleitung - Text</label>
|
||||
<textarea id="instruction_text" name="instruction_text" class="tinymce-editor"><?= htmlspecialchars($currentSettings['instruction_text']) ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="public_access" name="public_access" <?= $currentSettings['public_access'] == '1' ? 'checked' : '' ?>>
|
||||
<label for="public_access" style="margin:0;">Öffentlicher Zugriff</label>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px;">
|
||||
<button type="submit" name="save_settings" class="btn btn-primary"><i class="fas fa-save"></i> Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- TAB: Cron-Sync -->
|
||||
<div id="tab-cron" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-clock"></i> Automatische Voucher-Synchronisation</h2>
|
||||
|
||||
<div class="info-box">
|
||||
<h4><i class="fas fa-info-circle"></i> Was macht der Cron-Job?</h4>
|
||||
<p>Der Cron-Job synchronisiert automatisch alle Voucher von Ihren UniFi Controllern in die lokale Datenbank.
|
||||
Dadurch werden Dashboard und Voucher-Übersicht sofort beim Öffnen angezeigt, ohne auf die API warten zu müssen.</p>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Cron-Token</h3>
|
||||
|
||||
<?php if (empty($currentSettings['cron_token'])): ?>
|
||||
<div style="background: #fff3cd; border: 1px solid #ffc107; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
|
||||
<p style="color: #856404; margin-bottom: 15px;"><i class="fas fa-exclamation-triangle"></i> <strong>Kein Token konfiguriert.</strong> Generieren Sie einen Token, um den Cron-Job zu aktivieren.</p>
|
||||
<form method="post" style="display: inline;">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<button type="submit" name="generate_cron_token" class="btn btn-primary">
|
||||
<i class="fas fa-key"></i> Token generieren
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div style="background: #d4edda; border: 1px solid #28a745; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
|
||||
<p style="color: #155724; margin-bottom: 10px;"><i class="fas fa-check-circle"></i> <strong>Token ist aktiv</strong></p>
|
||||
<div style="background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 15px; font-family: monospace; word-break: break-all;">
|
||||
<?= htmlspecialchars($currentSettings['cron_token']) ?>
|
||||
</div>
|
||||
<div style="display: flex; gap: 10px; flex-wrap: wrap;">
|
||||
<button onclick="copyToClipboard('<?= htmlspecialchars($currentSettings['cron_token']) ?>')" class="btn btn-secondary">
|
||||
<i class="fas fa-copy"></i> Token kopieren
|
||||
</button>
|
||||
<form method="post" style="display: inline;">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<button type="submit" name="generate_cron_token" class="btn btn-secondary">
|
||||
<i class="fas fa-sync"></i> Neu generieren
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" style="display: inline;" onsubmit="return confirm('Token wirklich löschen? Der Cron-Job wird deaktiviert.');">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<button type="submit" name="delete_cron_token" class="btn btn-secondary" style="color: #dc3545;">
|
||||
<i class="fas fa-trash"></i> Löschen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Cron-Job einrichten</h3>
|
||||
|
||||
<?php
|
||||
// Basis-Pfad aus dem bereits berechneten $scriptPath verwenden (vermeidet doppelten Slash)
|
||||
$cronUrl = $protocol . '://' . $_SERVER['HTTP_HOST'] . $scriptPath . '/cron_sync.php?token=' . ($currentSettings['cron_token'] ?: 'DEIN_TOKEN');
|
||||
?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Cron-URL (für Webhooks oder externe Aufrufe)</label>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<input type="text" id="cronUrl" value="<?= htmlspecialchars($cronUrl) ?>" readonly style="flex: 1; background: #f8f9fa;">
|
||||
<button onclick="copyToClipboard(document.getElementById('cronUrl').value)" class="btn btn-secondary">
|
||||
<i class="fas fa-copy"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="placeholder-info" style="background: #f8f9fa; border-color: #ccc;">
|
||||
<h4 style="color: #333;">Crontab-Eintrag (Linux/Mac)</h4>
|
||||
<p style="color: #666; margin-bottom: 10px;">Fügen Sie diese Zeile in Ihre Crontab ein (<code>crontab -e</code>):</p>
|
||||
<div style="background: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 6px; font-family: monospace; font-size: 13px; overflow-x: auto;">
|
||||
*/30 * * * * curl -s "<?= htmlspecialchars($cronUrl) ?>" > /dev/null 2>&1
|
||||
</div>
|
||||
<p style="color: #999; font-size: 12px; margin-top: 10px;">Dies führt die Synchronisation alle 30 Minuten aus.</p>
|
||||
</div>
|
||||
|
||||
<div class="placeholder-info" style="background: #f8f9fa; border-color: #ccc; margin-top: 15px;">
|
||||
<h4 style="color: #333;">Windows Task Scheduler</h4>
|
||||
<p style="color: #666; margin-bottom: 10px;">Erstellen Sie eine geplante Aufgabe mit diesem Befehl:</p>
|
||||
<div style="background: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 6px; font-family: monospace; font-size: 13px; overflow-x: auto;">
|
||||
powershell -Command "Invoke-WebRequest -Uri '<?= htmlspecialchars($cronUrl) ?>' -UseBasicParsing"
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Status</h3>
|
||||
|
||||
<table style="width: 100%; max-width: 500px;">
|
||||
<tr>
|
||||
<td style="padding: 10px 0; color: #666;">Letzte Synchronisation:</td>
|
||||
<td>
|
||||
<?php if ($currentSettings['last_cron_sync']): ?>
|
||||
<strong><?= date('d.m.Y H:i:s', strtotime($currentSettings['last_cron_sync'])) ?></strong>
|
||||
<?php else: ?>
|
||||
<em style="color: #999;">Noch nie ausgeführt</em>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 10px 0; color: #666;">Token-Status:</td>
|
||||
<td>
|
||||
<?php if ($currentSettings['cron_token']): ?>
|
||||
<span style="color: #28a745;"><i class="fas fa-check-circle"></i> Aktiv</span>
|
||||
<?php else: ?>
|
||||
<span style="color: #dc3545;"><i class="fas fa-times-circle"></i> Nicht konfiguriert</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php if ($currentSettings['cron_token']): ?>
|
||||
<div style="margin-top: 20px;">
|
||||
<button onclick="testCronJob()" class="btn btn-primary" id="testCronBtn">
|
||||
<i class="fas fa-play"></i> Jetzt manuell ausführen
|
||||
</button>
|
||||
<span id="testCronResult" style="margin-left: 15px;"></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- TAB: M365 -->
|
||||
<div id="tab-m365" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fab fa-microsoft"></i> Microsoft 365</h2>
|
||||
<div class="info-box">
|
||||
<h4><i class="fas fa-info-circle"></i> Azure AD App</h4>
|
||||
<p>Redirect URI: <strong><?= $protocol . '://' . $host . $scriptPath ?>/m365_callback.php</strong></p>
|
||||
</div>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="form_type" value="m365">
|
||||
<div class="form-group">
|
||||
<label for="m365_client_id">Client ID</label>
|
||||
<input type="text" id="m365_client_id" name="m365_client_id" value="<?= htmlspecialchars($currentSettings['m365_client_id']) ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="m365_client_secret">Client Secret</label>
|
||||
<input type="password" id="m365_client_secret" name="m365_client_secret" value="<?= htmlspecialchars($currentSettings['m365_client_secret']) ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="m365_tenant_id">Tenant ID</label>
|
||||
<input type="text" id="m365_tenant_id" name="m365_tenant_id" value="<?= htmlspecialchars($currentSettings['m365_tenant_id']) ?>">
|
||||
</div>
|
||||
<button type="submit" name="save_settings" class="btn btn-primary"><i class="fas fa-save"></i> Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- TAB: SMTP -->
|
||||
<div id="tab-smtp" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-envelope"></i> SMTP</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="form_type" value="smtp">
|
||||
<div class="checkbox-group" style="margin-bottom: 20px;">
|
||||
<input type="checkbox" id="smtp_enabled" name="smtp_enabled" <?= $currentSettings['smtp_enabled'] == '1' ? 'checked' : '' ?>>
|
||||
<label for="smtp_enabled" style="margin:0;">SMTP aktivieren</label>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="smtp_host">Host</label>
|
||||
<input type="text" id="smtp_host" name="smtp_host" value="<?= htmlspecialchars($currentSettings['smtp_host']) ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="smtp_port">Port</label>
|
||||
<input type="number" id="smtp_port" name="smtp_port" value="<?= htmlspecialchars($currentSettings['smtp_port']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="smtp_encryption">Verschlüsselung</label>
|
||||
<select id="smtp_encryption" name="smtp_encryption">
|
||||
<option value="tls" <?= $currentSettings['smtp_encryption'] === 'tls' ? 'selected' : '' ?>>TLS</option>
|
||||
<option value="ssl" <?= $currentSettings['smtp_encryption'] === 'ssl' ? 'selected' : '' ?>>SSL</option>
|
||||
<option value="none" <?= $currentSettings['smtp_encryption'] === 'none' ? 'selected' : '' ?>>Keine</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="smtp_username">Benutzername</label>
|
||||
<input type="text" id="smtp_username" name="smtp_username" value="<?= htmlspecialchars($currentSettings['smtp_username']) ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="smtp_password">Passwort</label>
|
||||
<input type="password" id="smtp_password" name="smtp_password" value="<?= htmlspecialchars($currentSettings['smtp_password']) ?>" placeholder="Leer = nicht ändern">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="smtp_from_email">Absender E-Mail</label>
|
||||
<input type="email" id="smtp_from_email" name="smtp_from_email" value="<?= htmlspecialchars($currentSettings['smtp_from_email']) ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="smtp_from_name">Absender Name</label>
|
||||
<input type="text" id="smtp_from_name" name="smtp_from_name" value="<?= htmlspecialchars($currentSettings['smtp_from_name']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" name="save_settings" class="btn btn-primary"><i class="fas fa-save"></i> Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- TEIL 1 ENDET HIER - Fortsetzung in TEIL 2 -->
|
||||
|
||||
|
||||
<!-- TEIL 2 BEGINNT HIER - Füge dies NACH Teil 1 ein -->
|
||||
|
||||
<!-- TAB: Templates -->
|
||||
<div id="tab-templates" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-file-alt"></i> E-Mail Templates</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="form_type" value="templates">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="system_url">System-URL</label>
|
||||
<input type="url" id="system_url" name="system_url" value="<?= htmlspecialchars($currentSettings['system_url']) ?>" required>
|
||||
<div class="help-text">Wird in E-Mails als Login-Link verwendet. Auto: <code><?= $autoDetectedUrl ?></code></div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Voucher E-Mail</h3>
|
||||
<div class="placeholder-info">
|
||||
<h4>Platzhalter:</h4>
|
||||
<div class="placeholder-list">
|
||||
<div><code>{VOUCHER_CODE}</code></div>
|
||||
<div><code>{SITE_NAME}</code></div>
|
||||
<div><code>{MAX_USES}</code></div>
|
||||
<div><code>{APP_TITLE}</code></div>
|
||||
<div><code>{INSTRUCTIONS}</code></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email_voucher_subject">Betreff</label>
|
||||
<input type="text" id="email_voucher_subject" name="email_voucher_subject" value="<?= htmlspecialchars($currentSettings['email_voucher_subject']) ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email_voucher_body">E-Mail Text</label>
|
||||
<textarea id="email_voucher_body" name="email_voucher_body" class="tinymce-editor"><?= htmlspecialchars($currentSettings['email_voucher_body']) ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Benutzer-Benachrichtigung</h3>
|
||||
<div class="placeholder-info">
|
||||
<h4>Platzhalter:</h4>
|
||||
<div class="placeholder-list">
|
||||
<div><code>{USER_NAME}</code></div>
|
||||
<div><code>{CHANGES}</code></div>
|
||||
<div><code>{APP_TITLE}</code></div>
|
||||
<div><code>{SYSTEM_URL}</code></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email_user_notification_subject">Betreff</label>
|
||||
<input type="text" id="email_user_notification_subject" name="email_user_notification_subject" value="<?= htmlspecialchars($currentSettings['email_user_notification_subject']) ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email_user_notification_body">E-Mail Text</label>
|
||||
<textarea id="email_user_notification_body" name="email_user_notification_body" class="tinymce-editor"><?= htmlspecialchars($currentSettings['email_user_notification_body']) ?></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="save_settings" class="btn btn-primary"><i class="fas fa-save"></i> Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- TAB: System -->
|
||||
<div id="tab-system" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-cogs"></i> System & Erweitert</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="form_type" value="system">
|
||||
|
||||
<div class="info-box">
|
||||
<h4><i class="fas fa-info-circle"></i> TinyMCE API Key</h4>
|
||||
<p>Kostenlosen API Key erhalten: <a href="https://www.tiny.cloud/auth/signup/" target="_blank" style="color: #0066cc;">tiny.cloud/signup</a><br>
|
||||
Ohne Key wird eine eingeschränkte Version geladen.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="tinymce_api_key">TinyMCE API Key (optional)</label>
|
||||
<input type="text" id="tinymce_api_key" name="tinymce_api_key" value="<?= htmlspecialchars($currentSettings['tinymce_api_key']) ?>" placeholder="your-api-key-here">
|
||||
<div class="help-text">Für WYSIWYG-Editor in Anleitungen und E-Mail-Templates</div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">Druck-Template</h3>
|
||||
<div class="placeholder-info">
|
||||
<h4>Platzhalter:</h4>
|
||||
<div class="placeholder-list">
|
||||
<div><code>{VOUCHER_CODE}</code></div>
|
||||
<div><code>{EXPIRY_DATE}</code></div>
|
||||
<div><code>{EXPIRY_TIME}</code></div>
|
||||
<div><code>{SITE_NAME}</code></div>
|
||||
<div><code>{MAX_USES}</code></div>
|
||||
<div><code>{APP_TITLE}</code></div>
|
||||
<div><code>{INSTRUCTIONS}</code></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="print_template">HTML Template für Voucher-Druck</label>
|
||||
<textarea id="print_template" name="print_template" class="tinymce-editor" style="min-height: 300px;"><?= htmlspecialchars($currentSettings['print_template']) ?></textarea>
|
||||
<div class="help-text">HTML/CSS-Code für den Ausdruck von Vouchers</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="save_settings" class="btn btn-primary"><i class="fas fa-save"></i> Speichern</button>
|
||||
</form>
|
||||
|
||||
<div class="section-divider"></div>
|
||||
|
||||
<h3 style="margin-bottom: 15px;">System-Information</h3>
|
||||
<table style="width: 100%;">
|
||||
<tr><td style="padding: 10px 0; color: #666;">PHP Version:</td><td><strong><?= phpversion() ?></strong></td></tr>
|
||||
<tr><td style="padding: 10px 0; color: #666;">Datenbank:</td><td><strong><?= DB_NAME ?></strong></td></tr>
|
||||
<tr><td style="padding: 10px 0; color: #666;">Installiert:</td><td><strong><?= date('d.m.Y H:i', filectime(__DIR__ . '/../config.php')) ?></strong></td></tr>
|
||||
<tr><td style="padding: 10px 0; color: #666;">Version:</td><td><strong>2.0.0</strong></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- TAB: Passwort -->
|
||||
<div id="tab-password" class="tab-content">
|
||||
<h2 style="margin-bottom: 20px;"><i class="fas fa-key"></i> Passwort ändern</h2>
|
||||
<form method="post" style="max-width: 500px;">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="current_password">Aktuelles Passwort</label>
|
||||
<input type="password" id="current_password" name="current_password" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new_password">Neues Passwort</label>
|
||||
<input type="password" id="new_password" name="new_password" required minlength="8">
|
||||
<div class="help-text">Mindestens 8 Zeichen</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirm_password">Passwort bestätigen</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="change_password" class="btn btn-primary"><i class="fas fa-lock"></i> Passwort ändern</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Tab-Switching
|
||||
function switchTab(tabName) {
|
||||
// Alle Tabs ausblenden
|
||||
document.querySelectorAll('.tab-content').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
|
||||
// Alle Tab-Buttons deaktivieren
|
||||
document.querySelectorAll('.tab-button').forEach(btn => {
|
||||
btn.classList.remove('active');
|
||||
});
|
||||
|
||||
// Gewählten Tab aktivieren
|
||||
document.getElementById('tab-' + tabName).classList.add('active');
|
||||
event.target.classList.add('active');
|
||||
|
||||
// URL Hash aktualisieren (optional)
|
||||
window.location.hash = tabName;
|
||||
}
|
||||
|
||||
// Tab aus URL Hash laden (beim Seitenladen)
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
const hash = window.location.hash.substring(1);
|
||||
if (hash && document.getElementById('tab-' + hash)) {
|
||||
const tabButton = Array.from(document.querySelectorAll('.tab-button')).find(btn =>
|
||||
btn.textContent.toLowerCase().includes(hash)
|
||||
);
|
||||
if (tabButton) {
|
||||
tabButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
// TinyMCE initialisieren
|
||||
initTinyMCE();
|
||||
});
|
||||
|
||||
// In Zwischenablage kopieren
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert('In die Zwischenablage kopiert!');
|
||||
}).catch(err => {
|
||||
// Fallback für ältere Browser
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(textarea);
|
||||
alert('In die Zwischenablage kopiert!');
|
||||
});
|
||||
}
|
||||
|
||||
// Cron-Job testen
|
||||
async function testCronJob() {
|
||||
const btn = document.getElementById('testCronBtn');
|
||||
const result = document.getElementById('testCronResult');
|
||||
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Läuft...';
|
||||
result.innerHTML = '';
|
||||
|
||||
try {
|
||||
const response = await fetch('../cron_sync.php?token=<?= htmlspecialchars($currentSettings['cron_token']) ?>');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
result.innerHTML = '<span style="color: #28a745;"><i class="fas fa-check-circle"></i> ' + data.message + '</span>';
|
||||
// Seite nach 2 Sekunden neu laden, um Status zu aktualisieren
|
||||
setTimeout(() => window.location.reload(), 2000);
|
||||
} else {
|
||||
result.innerHTML = '<span style="color: #dc3545;"><i class="fas fa-times-circle"></i> ' + data.message + '</span>';
|
||||
}
|
||||
} catch (error) {
|
||||
result.innerHTML = '<span style="color: #dc3545;"><i class="fas fa-times-circle"></i> Fehler: ' + error.message + '</span>';
|
||||
}
|
||||
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-play"></i> Jetzt manuell ausführen';
|
||||
}
|
||||
|
||||
// TinyMCE WYSIWYG Editor initialisieren
|
||||
function initTinyMCE() {
|
||||
tinymce.init({
|
||||
selector: '.tinymce-editor',
|
||||
height: 400,
|
||||
menubar: false,
|
||||
plugins: [
|
||||
'advlist', 'autolink', 'lists', 'link', 'charmap',
|
||||
'searchreplace', 'visualblocks', 'code', 'fullscreen',
|
||||
'insertdatetime', 'table', 'help', 'wordcount'
|
||||
],
|
||||
toolbar: 'undo redo | blocks | bold italic forecolor | alignleft aligncenter alignright | bullist numlist | removeformat | help',
|
||||
content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.6; }',
|
||||
branding: false,
|
||||
promotion: false
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
671
admin/sites.php
Normal file
671
admin/sites.php
Normal file
|
|
@ -0,0 +1,671 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
require_once __DIR__ . '/../config.php';
|
||||
require_once __DIR__ . '/../includes/Database.php';
|
||||
require_once __DIR__ . '/../includes/Auth.php';
|
||||
require_once __DIR__ . '/../includes/UniFiController.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$auth->requireAdmin();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
// Site bearbeiten
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_site'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$siteId = (int)$_POST['site_id'];
|
||||
$name = trim($_POST['name']);
|
||||
$siteIdStr = trim($_POST['site_id_str']);
|
||||
$controllerUrl = trim($_POST['controller_url']);
|
||||
$username = trim($_POST['username']);
|
||||
$password = $_POST['password'];
|
||||
$publicAccess = isset($_POST['public_access']) ? 1 : 0;
|
||||
|
||||
if (empty($name) || empty($siteIdStr) || empty($controllerUrl) || empty($username)) {
|
||||
throw new Exception('Bitte füllen Sie alle Pflichtfelder aus');
|
||||
}
|
||||
|
||||
// Wenn neues Passwort, Verbindung testen
|
||||
if (!empty($password)) {
|
||||
$testResult = UniFiController::testConnection($controllerUrl, $username, $password, $siteIdStr);
|
||||
if ($testResult !== true) {
|
||||
throw new Exception('Verbindung fehlgeschlagen: ' . $testResult);
|
||||
}
|
||||
|
||||
// Mit neuem Passwort aktualisieren
|
||||
$db->execute(
|
||||
"UPDATE sites SET name = ?, site_id = ?, unifi_controller_url = ?, unifi_username = ?, unifi_password = ?, public_access = ? WHERE id = ?",
|
||||
[$name, $siteIdStr, $controllerUrl, $username, $password, $publicAccess, $siteId]
|
||||
);
|
||||
} else {
|
||||
// Ohne Passwort-Änderung
|
||||
$db->execute(
|
||||
"UPDATE sites SET name = ?, site_id = ?, unifi_controller_url = ?, unifi_username = ?, public_access = ? WHERE id = ?",
|
||||
[$name, $siteIdStr, $controllerUrl, $username, $publicAccess, $siteId]
|
||||
);
|
||||
}
|
||||
|
||||
$success = 'Site erfolgreich aktualisiert!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Site hinzufügen
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_site'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$name = trim($_POST['name']);
|
||||
$siteId = trim($_POST['site_id']);
|
||||
$controllerUrl = trim($_POST['controller_url']);
|
||||
$username = trim($_POST['username']);
|
||||
$password = $_POST['password'];
|
||||
$publicAccess = isset($_POST['public_access']) ? 1 : 0;
|
||||
|
||||
if (empty($name) || empty($siteId) || empty($controllerUrl) || empty($username)) {
|
||||
throw new Exception('Bitte füllen Sie alle Pflichtfelder aus');
|
||||
}
|
||||
|
||||
// Verbindung testen
|
||||
$testResult = UniFiController::testConnection($controllerUrl, $username, $password, $siteId);
|
||||
if ($testResult !== true) {
|
||||
throw new Exception('Verbindung fehlgeschlagen: ' . $testResult);
|
||||
}
|
||||
|
||||
$db->execute(
|
||||
"INSERT INTO sites (name, site_id, unifi_controller_url, unifi_username, unifi_password, public_access)
|
||||
VALUES (?, ?, ?, ?, ?, ?)",
|
||||
[$name, $siteId, $controllerUrl, $username, $password, $publicAccess]
|
||||
);
|
||||
|
||||
$success = 'Site erfolgreich hinzugefügt!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Site löschen
|
||||
if (isset($_GET['delete']) && isset($_GET['token'])) {
|
||||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||||
$db->query("DELETE FROM sites WHERE id = ?", [(int)$_GET['delete']]);
|
||||
$success = 'Site erfolgreich gelöscht!';
|
||||
} else {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
}
|
||||
}
|
||||
|
||||
// Site aktivieren/deaktivieren
|
||||
if (isset($_GET['toggle']) && isset($_GET['token'])) {
|
||||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||||
$site = $db->fetchOne("SELECT is_active FROM sites WHERE id = ?", [(int)$_GET['toggle']]);
|
||||
if ($site) {
|
||||
$newStatus = $site['is_active'] ? 0 : 1;
|
||||
$db->query("UPDATE sites SET is_active = ? WHERE id = ?", [$newStatus, (int)$_GET['toggle']]);
|
||||
$success = 'Site-Status aktualisiert!';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alle Sites abrufen
|
||||
$sites = $db->fetchAll("SELECT * FROM sites ORDER BY name");
|
||||
$currentUser = $auth->getCurrentUser();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sites verwalten - <?= htmlspecialchars($appTitle) ?></title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
.header {
|
||||
background: white;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
padding: 0 30px;
|
||||
height: 70px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
|
||||
}
|
||||
.header-title { font-size: 20px; font-weight: 600; color: #333; }
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 70px;
|
||||
bottom: 0;
|
||||
width: 260px;
|
||||
background: white;
|
||||
border-right: 1px solid #e0e0e0;
|
||||
padding: 30px 0;
|
||||
}
|
||||
.sidebar-nav { list-style: none; }
|
||||
.sidebar-nav a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 30px;
|
||||
color: #666;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s;
|
||||
font-size: 15px;
|
||||
}
|
||||
.sidebar-nav a:hover,
|
||||
.sidebar-nav a.active {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
}
|
||||
.sidebar-nav i { width: 20px; text-align: center; }
|
||||
.main-content {
|
||||
margin-left: 260px;
|
||||
padding: 30px;
|
||||
min-height: calc(100vh - 70px);
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.page-title { font-size: 28px; font-weight: 600; color: #333; }
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.2s;
|
||||
font-size: 14px;
|
||||
}
|
||||
.btn-primary {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
.btn-primary:hover { background: #5568d3; }
|
||||
.btn-secondary {
|
||||
background: #f8f9fa;
|
||||
color: #666;
|
||||
border: 1px solid #e0e0e0;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
.btn-success {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
}
|
||||
.btn-small {
|
||||
padding: 6px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
|
||||
border: 1px solid #e0e0e0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.card-header {
|
||||
padding: 20px 25px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
.card-title { font-size: 18px; font-weight: 600; color: #333; }
|
||||
.card-body { padding: 25px; }
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-group { margin-bottom: 20px; }
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
}
|
||||
input[type="text"],
|
||||
input[type="password"],
|
||||
input[type="url"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
.checkbox-group input {
|
||||
width: auto;
|
||||
}
|
||||
.alert {
|
||||
padding: 14px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 25px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.alert-error {
|
||||
background: #fee;
|
||||
border: 1px solid #fcc;
|
||||
color: #c33;
|
||||
}
|
||||
.alert-success {
|
||||
background: #efe;
|
||||
border: 1px solid #cfc;
|
||||
color: #3c3;
|
||||
}
|
||||
.sites-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
.site-card {
|
||||
background: white;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
.site-card:hover {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
|
||||
}
|
||||
.site-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: start;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.site-name {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.site-id {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
font-family: monospace;
|
||||
}
|
||||
.site-info {
|
||||
margin: 15px 0;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
.site-info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.site-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 15px;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.badge-success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
.badge-warning {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
.badge-info {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
}
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.modal.active { display: flex; }
|
||||
.modal-content {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
max-width: 600px;
|
||||
width: 90%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.modal-header {
|
||||
padding: 25px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.modal-title { font-size: 20px; font-weight: 600; }
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
}
|
||||
.modal-body { padding: 25px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<div class="header-title">
|
||||
<i class="fas fa-shield-alt"></i> Administration
|
||||
</div>
|
||||
<a href="../index.php" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Zurück
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<nav class="sidebar-nav">
|
||||
<ul>
|
||||
<li><a href="index.php"><i class="fas fa-home"></i> Dashboard</a></li>
|
||||
<li><a href="sites.php" class="active"><i class="fas fa-map-marker-alt"></i> Sites verwalten</a></li>
|
||||
<li><a href="users.php"><i class="fas fa-users"></i> Benutzer verwalten</a></li>
|
||||
<li><a href="vouchers.php"><i class="fas fa-ticket-alt"></i> Voucher-Historie</a></li>
|
||||
<li><a href="settings.php"><i class="fas fa-cog"></i> Einstellungen</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Sites verwalten</h1>
|
||||
<button onclick="openModal()" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Neue Site hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error"><i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= htmlspecialchars($success) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($sites)): ?>
|
||||
<div class="card">
|
||||
<div class="card-body" style="text-align: center; padding: 60px 20px; color: #999;">
|
||||
<i class="fas fa-map-marker-alt" style="font-size: 48px; margin-bottom: 20px; opacity: 0.3;"></i>
|
||||
<p>Noch keine Sites konfiguriert.<br>Fügen Sie Ihre erste Site hinzu!</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="sites-grid">
|
||||
<?php foreach ($sites as $site): ?>
|
||||
<div class="site-card">
|
||||
<div class="site-card-header">
|
||||
<div>
|
||||
<div class="site-name"><?= htmlspecialchars($site['name']) ?></div>
|
||||
<div class="site-id">ID: <?= htmlspecialchars($site['site_id']) ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<?php if ($site['is_active']): ?>
|
||||
<span class="badge badge-success"><i class="fas fa-check"></i> Aktiv</span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge-warning"><i class="fas fa-pause"></i> Inaktiv</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($site['public_access']): ?>
|
||||
<span class="badge badge-info"><i class="fas fa-globe"></i> Öffentlich</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="site-info">
|
||||
<div class="site-info-item">
|
||||
<i class="fas fa-server" style="color: #667eea;"></i>
|
||||
<span><?= htmlspecialchars($site['unifi_controller_url']) ?></span>
|
||||
</div>
|
||||
<div class="site-info-item">
|
||||
<i class="fas fa-user" style="color: #667eea;"></i>
|
||||
<span><?= htmlspecialchars($site['unifi_username']) ?></span>
|
||||
</div>
|
||||
<div class="site-info-item">
|
||||
<i class="fas fa-clock" style="color: #999;"></i>
|
||||
<span>Erstellt: <?= date('d.m.Y', strtotime($site['created_at'])) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="site-actions">
|
||||
<button onclick="openEditModal(<?= $site['id'] ?>, '<?= htmlspecialchars($site['name'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['site_id'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['unifi_controller_url'], ENT_QUOTES) ?>', '<?= htmlspecialchars($site['unifi_username'], ENT_QUOTES) ?>', <?= $site['public_access'] ?>)"
|
||||
class="btn btn-secondary btn-small">
|
||||
<i class="fas fa-edit"></i> Bearbeiten
|
||||
</button>
|
||||
<a href="?toggle=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||||
class="btn btn-secondary btn-small">
|
||||
<i class="fas fa-<?= $site['is_active'] ? 'pause' : 'play' ?>"></i>
|
||||
<?= $site['is_active'] ? 'Deaktivieren' : 'Aktivieren' ?>
|
||||
</a>
|
||||
<a href="?delete=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||||
class="btn btn-danger btn-small"
|
||||
onclick="return confirm('Möchten Sie diese Site wirklich löschen?')">
|
||||
<i class="fas fa-trash"></i> Löschen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Modal für neue Site -->
|
||||
<div id="addSiteModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">Neue Site hinzufügen</h2>
|
||||
<button class="modal-close" onclick="closeModal('addSiteModal')">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" id="addSiteForm">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Site-Name *</label>
|
||||
<input type="text" id="name" name="name" required
|
||||
placeholder="z.B. Hauptgebäude">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="site_id">UniFi Site ID *</label>
|
||||
<input type="text" id="site_id" name="site_id" required
|
||||
placeholder="z.B. default">
|
||||
<small style="color: #999; font-size: 12px;">
|
||||
Zu finden in der UniFi Controller URL oder in den Site-Einstellungen
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="controller_url">Controller URL *</label>
|
||||
<input type="url" id="controller_url" name="controller_url" required
|
||||
placeholder="https://unifi.example.com:8443">
|
||||
<small style="color: #999; font-size: 12px;">
|
||||
Vollständige URL inklusive Port (meist 8443)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="username">Benutzername *</label>
|
||||
<input type="text" id="username" name="username" required
|
||||
placeholder="admin">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Passwort *</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group checkbox-group">
|
||||
<input type="checkbox" id="public_access" name="public_access">
|
||||
<label for="public_access" style="margin: 0;">
|
||||
Öffentlicher Zugriff (ohne Login nutzbar)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 10px; margin-top: 25px;">
|
||||
<button type="submit" name="add_site" class="btn btn-primary" style="flex: 1;">
|
||||
<i class="fas fa-save"></i> Site hinzufügen
|
||||
</button>
|
||||
<button type="button" onclick="closeModal('addSiteModal')" class="btn btn-secondary">
|
||||
Abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal für Site bearbeiten -->
|
||||
<div id="editSiteModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">Site bearbeiten</h2>
|
||||
<button class="modal-close" onclick="closeModal('editSiteModal')">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" id="editSiteForm">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="site_id" id="edit_site_id">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit_name">Site-Name *</label>
|
||||
<input type="text" id="edit_name" name="name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit_site_id_str">UniFi Site ID *</label>
|
||||
<input type="text" id="edit_site_id_str" name="site_id_str" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit_controller_url">Controller URL *</label>
|
||||
<input type="url" id="edit_controller_url" name="controller_url" required>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label for="edit_username">Benutzername *</label>
|
||||
<input type="text" id="edit_username" name="username" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="edit_password">Neues Passwort</label>
|
||||
<input type="password" id="edit_password" name="password" placeholder="Leer lassen = nicht ändern">
|
||||
<small style="color: #999; font-size: 12px;">
|
||||
Nur ausfüllen wenn Sie das Passwort ändern möchten
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group checkbox-group">
|
||||
<input type="checkbox" id="edit_public_access" name="public_access">
|
||||
<label for="edit_public_access" style="margin: 0;">
|
||||
Öffentlicher Zugriff (ohne Login nutzbar)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 10px; margin-top: 25px;">
|
||||
<button type="submit" name="edit_site" class="btn btn-primary" style="flex: 1;">
|
||||
<i class="fas fa-save"></i> Änderungen speichern
|
||||
</button>
|
||||
<button type="button" onclick="closeModal('editSiteModal')" class="btn btn-secondary">
|
||||
Abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function openModal() {
|
||||
document.getElementById('addSiteModal').classList.add('active');
|
||||
}
|
||||
|
||||
function closeModal(modalId) {
|
||||
document.getElementById(modalId).classList.remove('active');
|
||||
}
|
||||
|
||||
function openEditModal(id, name, siteIdStr, controllerUrl, username, publicAccess) {
|
||||
document.getElementById('edit_site_id').value = id;
|
||||
document.getElementById('edit_name').value = name;
|
||||
document.getElementById('edit_site_id_str').value = siteIdStr;
|
||||
document.getElementById('edit_controller_url').value = controllerUrl;
|
||||
document.getElementById('edit_username').value = username;
|
||||
document.getElementById('edit_password').value = '';
|
||||
document.getElementById('edit_public_access').checked = publicAccess == 1;
|
||||
|
||||
document.getElementById('editSiteModal').classList.add('active');
|
||||
}
|
||||
|
||||
// Modal schließen bei Klick außerhalb
|
||||
document.getElementById('addSiteModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal('addSiteModal');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('editSiteModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal('editSiteModal');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
767
admin/users.php
Normal file
767
admin/users.php
Normal file
|
|
@ -0,0 +1,767 @@
|
|||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
require_once __DIR__ . '/../config.php';
|
||||
require_once __DIR__ . '/../includes/Database.php';
|
||||
require_once __DIR__ . '/../includes/Auth.php';
|
||||
require_once __DIR__ . '/../includes/Mailer.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$auth->requireAdmin();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$mailer = new Mailer();
|
||||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
// Benutzer bearbeiten
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_user'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$userId = (int)$_POST['user_id'];
|
||||
$isAdmin = isset($_POST['is_admin']) ? 1 : 0;
|
||||
$siteIds = $_POST['site_ids'] ?? [];
|
||||
|
||||
// Alten Status abrufen
|
||||
$oldUser = $db->fetchOne("SELECT * FROM users WHERE id = ?", [$userId]);
|
||||
$oldIsAdmin = $oldUser['is_admin'];
|
||||
$oldSites = $db->fetchAll("SELECT s.name FROM sites s INNER JOIN user_site_access usa ON s.id = usa.site_id WHERE usa.user_id = ?", [$userId]);
|
||||
|
||||
// Admin-Status aktualisieren
|
||||
$db->query("UPDATE users SET is_admin = ? WHERE id = ?", [$isAdmin, $userId]);
|
||||
|
||||
// Alte Site-Zugriffe löschen (nur wenn nicht Admin)
|
||||
$db->query("DELETE FROM user_site_access WHERE user_id = ?", [$userId]);
|
||||
|
||||
// Neue Site-Zugriffe zuweisen (nur wenn nicht Admin)
|
||||
$newSites = [];
|
||||
if (!$isAdmin && !empty($siteIds)) {
|
||||
foreach ($siteIds as $siteId) {
|
||||
$db->execute(
|
||||
"INSERT INTO user_site_access (user_id, site_id) VALUES (?, ?)",
|
||||
[$userId, $siteId]
|
||||
);
|
||||
$site = $db->fetchOne("SELECT name FROM sites WHERE id = ?", [$siteId]);
|
||||
if ($site) {
|
||||
$newSites[] = $site['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// E-Mail-Benachrichtigung vorbereiten
|
||||
$changes = [];
|
||||
|
||||
if ($oldIsAdmin != $isAdmin) {
|
||||
if ($isAdmin) {
|
||||
$changes[] = "Sie wurden zum Administrator ernannt";
|
||||
} else {
|
||||
$changes[] = "Ihre Administrator-Rechte wurden entfernt";
|
||||
}
|
||||
}
|
||||
|
||||
// Site-Änderungen erkennen
|
||||
$oldSiteNames = array_column($oldSites, 'name');
|
||||
$addedSites = array_diff($newSites, $oldSiteNames);
|
||||
$removedSites = array_diff($oldSiteNames, $newSites);
|
||||
|
||||
if (!empty($addedSites)) {
|
||||
$changes[] = "Zugriff gewährt auf: " . implode(', ', $addedSites);
|
||||
}
|
||||
|
||||
if (!empty($removedSites)) {
|
||||
$changes[] = "Zugriff entfernt von: " . implode(', ', $removedSites);
|
||||
}
|
||||
|
||||
if ($isAdmin && !$oldIsAdmin) {
|
||||
$changes[] = "Sie haben nun Zugriff auf alle Sites";
|
||||
}
|
||||
|
||||
// E-Mail senden wenn Änderungen vorliegen
|
||||
if (!empty($changes)) {
|
||||
$mailer->sendUserNotification($oldUser['email'], $oldUser['name'], $changes);
|
||||
}
|
||||
|
||||
$success = 'Benutzer erfolgreich aktualisiert!' . (!empty($changes) ? ' Benachrichtigung wurde versendet.' : '');
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Benutzer hinzufügen
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_user'])) {
|
||||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
} else {
|
||||
try {
|
||||
$email = trim($_POST['email']);
|
||||
$name = trim($_POST['name']);
|
||||
$password = $_POST['password'];
|
||||
$isAdmin = isset($_POST['is_admin']) ? 1 : 0;
|
||||
$siteIds = $_POST['site_ids'] ?? [];
|
||||
|
||||
if (empty($email) || empty($name) || empty($password)) {
|
||||
throw new Exception('Bitte füllen Sie alle Pflichtfelder aus');
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new Exception('Ungültige E-Mail-Adresse');
|
||||
}
|
||||
|
||||
if (strlen($password) < 8) {
|
||||
throw new Exception('Passwort muss mindestens 8 Zeichen lang sein');
|
||||
}
|
||||
|
||||
// Prüfen ob E-Mail bereits existiert
|
||||
$existing = $db->fetchOne("SELECT id FROM users WHERE email = ?", [$email]);
|
||||
if ($existing) {
|
||||
throw new Exception('Ein Benutzer mit dieser E-Mail existiert bereits');
|
||||
}
|
||||
|
||||
// Benutzer anlegen
|
||||
$userId = $auth->registerUser($email, $name, $password, $isAdmin);
|
||||
|
||||
if (!$userId) {
|
||||
throw new Exception('Benutzer konnte nicht erstellt werden');
|
||||
}
|
||||
|
||||
// Site-Zugriffe zuweisen (nur wenn nicht Admin)
|
||||
if (!$isAdmin && !empty($siteIds)) {
|
||||
foreach ($siteIds as $siteId) {
|
||||
$db->execute(
|
||||
"INSERT INTO user_site_access (user_id, site_id) VALUES (?, ?)",
|
||||
[$userId, $siteId]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$success = 'Benutzer erfolgreich erstellt!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Benutzer löschen
|
||||
if (isset($_GET['delete']) && isset($_GET['token'])) {
|
||||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||||
$deleteId = (int)$_GET['delete'];
|
||||
$currentUserId = $_SESSION['user_id'];
|
||||
|
||||
if ($deleteId === $currentUserId) {
|
||||
$error = 'Sie können sich nicht selbst löschen';
|
||||
} else {
|
||||
$db->query("DELETE FROM users WHERE id = ?", [$deleteId]);
|
||||
$success = 'Benutzer erfolgreich gelöscht!';
|
||||
}
|
||||
} else {
|
||||
$error = 'Ungültiges Sicherheits-Token';
|
||||
}
|
||||
}
|
||||
|
||||
// Benutzer aktivieren/deaktivieren
|
||||
if (isset($_GET['toggle']) && isset($_GET['token'])) {
|
||||
if ($auth->validateCsrfToken($_GET['token'])) {
|
||||
$toggleId = (int)$_GET['toggle'];
|
||||
$currentUserId = $_SESSION['user_id'];
|
||||
|
||||
if ($toggleId === $currentUserId) {
|
||||
$error = 'Sie können sich nicht selbst deaktivieren';
|
||||
} else {
|
||||
$user = $db->fetchOne("SELECT is_active FROM users WHERE id = ?", [$toggleId]);
|
||||
if ($user) {
|
||||
$newStatus = $user['is_active'] ? 0 : 1;
|
||||
$db->query("UPDATE users SET is_active = ? WHERE id = ?", [$newStatus, $toggleId]);
|
||||
$success = 'Benutzer-Status aktualisiert!';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alle Benutzer und Sites abrufen
|
||||
$users = $db->fetchAll("SELECT * FROM users ORDER BY name");
|
||||
$sites = $db->fetchAll("SELECT * FROM sites WHERE is_active = 1 ORDER BY name");
|
||||
|
||||
// Site-Zugriffe für jeden Benutzer abrufen
|
||||
$userSiteAccess = [];
|
||||
foreach ($users as $user) {
|
||||
$userSiteAccess[$user['id']] = $db->fetchAll(
|
||||
"SELECT s.name FROM sites s
|
||||
INNER JOIN user_site_access usa ON s.id = usa.site_id
|
||||
WHERE usa.user_id = ?",
|
||||
[$user['id']]
|
||||
);
|
||||
}
|
||||
|
||||
$currentUser = $auth->getCurrentUser();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Benutzer verwalten - <?= htmlspecialchars($appTitle) ?></title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
.header {
|
||||
background: white;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
padding: 0 30px;
|
||||
height: 70px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
|
||||
}
|
||||
.header-title { font-size: 20px; font-weight: 600; color: #333; }
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 70px;
|
||||
bottom: 0;
|
||||
width: 260px;
|
||||
background: white;
|
||||
border-right: 1px solid #e0e0e0;
|
||||
padding: 30px 0;
|
||||
}
|
||||
.sidebar-nav { list-style: none; }
|
||||
.sidebar-nav a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 30px;
|
||||
color: #666;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s;
|
||||
font-size: 15px;
|
||||
}
|
||||
.sidebar-nav a:hover,
|
||||
.sidebar-nav a.active {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
}
|
||||
.sidebar-nav i { width: 20px; text-align: center; }
|
||||
.main-content {
|
||||
margin-left: 260px;
|
||||
padding: 30px;
|
||||
min-height: calc(100vh - 70px);
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.page-title { font-size: 28px; font-weight: 600; color: #333; }
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.2s;
|
||||
font-size: 14px;
|
||||
}
|
||||
.btn-primary {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
.btn-primary:hover { background: #5568d3; }
|
||||
.btn-secondary {
|
||||
background: #f8f9fa;
|
||||
color: #666;
|
||||
border: 1px solid #e0e0e0;
|
||||
}
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
}
|
||||
.btn-small {
|
||||
padding: 6px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
|
||||
border: 1px solid #e0e0e0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.card-header {
|
||||
padding: 20px 25px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
.card-title { font-size: 18px; font-weight: 600; color: #333; }
|
||||
.card-body { padding: 0; }
|
||||
.alert {
|
||||
padding: 14px 25px;
|
||||
margin: 0 25px 20px 25px;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.alert-error {
|
||||
background: #fee;
|
||||
border: 1px solid #fcc;
|
||||
color: #c33;
|
||||
}
|
||||
.alert-success {
|
||||
background: #efe;
|
||||
border: 1px solid #cfc;
|
||||
color: #3c3;
|
||||
}
|
||||
.table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.table th {
|
||||
text-align: left;
|
||||
padding: 15px;
|
||||
background: #f8f9fa;
|
||||
color: #666;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.table td {
|
||||
padding: 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
color: #333;
|
||||
}
|
||||
.table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.badge-success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
.badge-warning {
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
.badge-danger {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
.badge-info {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
}
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.modal.active { display: flex; }
|
||||
.modal-content {
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
max-width: 600px;
|
||||
width: 90%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.modal-header {
|
||||
padding: 25px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.modal-title { font-size: 20px; font-weight: 600; }
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #999;
|
||||
}
|
||||
.modal-body { padding: 25px; }
|
||||
.form-group { margin-bottom: 20px; }
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #555;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
}
|
||||
input[type="text"],
|
||||
input[type="email"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.checkbox-group input {
|
||||
width: auto;
|
||||
}
|
||||
.site-selection {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #999;
|
||||
}
|
||||
.empty-state i {
|
||||
font-size: 48px;
|
||||
margin-bottom: 20px;
|
||||
opacity: 0.3;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<div class="header-title">
|
||||
<i class="fas fa-shield-alt"></i> Administration
|
||||
</div>
|
||||
<a href="../index.php" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Zurück
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="sidebar">
|
||||
<nav class="sidebar-nav">
|
||||
<ul>
|
||||
<li><a href="index.php"><i class="fas fa-home"></i> Dashboard</a></li>
|
||||
<li><a href="sites.php"><i class="fas fa-map-marker-alt"></i> Sites verwalten</a></li>
|
||||
<li><a href="users.php" class="active"><i class="fas fa-users"></i> Benutzer verwalten</a></li>
|
||||
<li><a href="vouchers.php"><i class="fas fa-ticket-alt"></i> Voucher-Historie</a></li>
|
||||
<li><a href="settings.php"><i class="fas fa-cog"></i> Einstellungen</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Benutzer verwalten</h1>
|
||||
<button onclick="openModal()" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Neuer Benutzer
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-error"><i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><i class="fas fa-check-circle"></i> <?= htmlspecialchars($success) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Alle Benutzer</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($users)): ?>
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-users"></i>
|
||||
<p>Noch keine Benutzer vorhanden</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Rolle</th>
|
||||
<th>Status</th>
|
||||
<th>Site-Zugriffe</th>
|
||||
<th>Letzter Login</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $user): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<strong><?= htmlspecialchars($user['name']) ?></strong>
|
||||
<?php if ($user['id'] == $_SESSION['user_id']): ?>
|
||||
<span class="badge badge-info">Sie</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?= htmlspecialchars($user['email']) ?></td>
|
||||
<td>
|
||||
<?php if ($user['is_admin']): ?>
|
||||
<span class="badge badge-danger"><i class="fas fa-crown"></i> Admin</span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge-info">Benutzer</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($user['is_active']): ?>
|
||||
<span class="badge badge-success"><i class="fas fa-check"></i> Aktiv</span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge-warning"><i class="fas fa-pause"></i> Inaktiv</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($user['is_admin']): ?>
|
||||
<em style="color: #999;">Alle Sites</em>
|
||||
<?php elseif (!empty($userSiteAccess[$user['id']])): ?>
|
||||
<?php foreach ($userSiteAccess[$user['id']] as $site): ?>
|
||||
<span class="badge badge-info"><?= htmlspecialchars($site['name']) ?></span>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<em style="color: #999;">Keine</em>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($user['last_login']): ?>
|
||||
<?= date('d.m.Y H:i', strtotime($user['last_login'])) ?>
|
||||
<?php else: ?>
|
||||
<em style="color: #999;">Noch nie</em>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($user['id'] != $_SESSION['user_id']): ?>
|
||||
<button onclick="openEditModal(<?= $user['id'] ?>, '<?= htmlspecialchars($user['name'], ENT_QUOTES) ?>', <?= $user['is_admin'] ?>, [<?= implode(',', array_map(function($s) { return $s['site_id'] ?? 0; }, $db->fetchAll("SELECT site_id FROM user_site_access WHERE user_id = ?", [$user['id']]))) ?>])"
|
||||
class="btn btn-secondary btn-small">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<a href="?toggle=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||||
class="btn btn-secondary btn-small">
|
||||
<i class="fas fa-<?= $user['is_active'] ? 'pause' : 'play' ?>"></i>
|
||||
</a>
|
||||
<a href="?delete=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
|
||||
class="btn btn-danger btn-small"
|
||||
onclick="return confirm('Benutzer wirklich löschen?')">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<button onclick="openEditModal(<?= $user['id'] ?>, '<?= htmlspecialchars($user['name'], ENT_QUOTES) ?>', <?= $user['is_admin'] ?>, [<?= implode(',', array_map(function($s) { return $s['site_id'] ?? 0; }, $db->fetchAll("SELECT site_id FROM user_site_access WHERE user_id = ?", [$user['id']]))) ?>])"
|
||||
class="btn btn-secondary btn-small">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal für neuen Benutzer -->
|
||||
<div id="addUserModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">Neuen Benutzer anlegen</h2>
|
||||
<button class="modal-close" onclick="closeModal('addUserModal')">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" id="addUserForm">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">Name *</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">E-Mail *</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Passwort *</label>
|
||||
<input type="password" id="password" name="password" required minlength="8">
|
||||
<small style="color: #999; font-size: 12px;">Mindestens 8 Zeichen</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="is_admin" name="is_admin" onchange="toggleSiteSelection('add')">
|
||||
<label for="is_admin" style="margin: 0;">Administrator-Rechte</label>
|
||||
</div>
|
||||
<small style="color: #999; font-size: 12px;">Admins haben Zugriff auf alle Sites und Einstellungen</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="siteSelectionGroup">
|
||||
<label>Site-Zugriffe</label>
|
||||
<div class="site-selection">
|
||||
<?php if (empty($sites)): ?>
|
||||
<em style="color: #999;">Keine Sites verfügbar. Bitte zuerst Sites anlegen.</em>
|
||||
<?php else: ?>
|
||||
<?php foreach ($sites as $site): ?>
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" name="site_ids[]" value="<?= $site['id'] ?>" id="site_<?= $site['id'] ?>">
|
||||
<label for="site_<?= $site['id'] ?>" style="margin: 0;"><?= htmlspecialchars($site['name']) ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<small style="color: #999; font-size: 12px;">Wählen Sie die Sites, auf die dieser Benutzer Zugriff haben soll</small>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 10px; margin-top: 25px;">
|
||||
<button type="submit" name="add_user" class="btn btn-primary" style="flex: 1;">
|
||||
<i class="fas fa-save"></i> Benutzer anlegen
|
||||
</button>
|
||||
<button type="button" onclick="closeModal('addUserModal')" class="btn btn-secondary">
|
||||
Abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal für Benutzer bearbeiten -->
|
||||
<div id="editUserModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">Benutzer bearbeiten</h2>
|
||||
<button class="modal-close" onclick="closeModal('editUserModal')">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="post" id="editUserForm">
|
||||
<input type="hidden" name="csrf_token" value="<?= $auth->getCsrfToken() ?>">
|
||||
<input type="hidden" name="user_id" id="edit_user_id">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" id="edit_name" readonly style="background: #f5f5f5;">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="edit_is_admin" name="is_admin" onchange="toggleSiteSelection('edit')">
|
||||
<label for="edit_is_admin" style="margin: 0;">Administrator-Rechte</label>
|
||||
</div>
|
||||
<small style="color: #999; font-size: 12px;">Admins haben Zugriff auf alle Sites und Einstellungen</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="editSiteSelectionGroup">
|
||||
<label>Site-Zugriffe</label>
|
||||
<div class="site-selection" id="editSitesList">
|
||||
<?php if (!empty($sites)): ?>
|
||||
<?php foreach ($sites as $site): ?>
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" name="site_ids[]" value="<?= $site['id'] ?>" id="edit_site_<?= $site['id'] ?>">
|
||||
<label for="edit_site_<?= $site['id'] ?>" style="margin: 0;"><?= htmlspecialchars($site['name']) ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 10px; margin-top: 25px;">
|
||||
<button type="submit" name="edit_user" class="btn btn-primary" style="flex: 1;">
|
||||
<i class="fas fa-save"></i> Änderungen speichern
|
||||
</button>
|
||||
<button type="button" onclick="closeModal('editUserModal')" class="btn btn-secondary">
|
||||
Abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function openModal() {
|
||||
document.getElementById('addUserModal').classList.add('active');
|
||||
}
|
||||
|
||||
function closeModal(modalId) {
|
||||
document.getElementById(modalId).classList.remove('active');
|
||||
}
|
||||
|
||||
function openEditModal(userId, userName, isAdmin, siteIds) {
|
||||
document.getElementById('edit_user_id').value = userId;
|
||||
document.getElementById('edit_name').value = userName;
|
||||
document.getElementById('edit_is_admin').checked = isAdmin == 1;
|
||||
|
||||
// Alle Checkboxen erst deaktivieren
|
||||
document.querySelectorAll('#editSitesList input[type="checkbox"]').forEach(cb => {
|
||||
cb.checked = false;
|
||||
});
|
||||
|
||||
// Ausgewählte Sites aktivieren
|
||||
siteIds.forEach(siteId => {
|
||||
const checkbox = document.getElementById('edit_site_' + siteId);
|
||||
if (checkbox) checkbox.checked = true;
|
||||
});
|
||||
|
||||
toggleSiteSelection('edit');
|
||||
document.getElementById('editUserModal').classList.add('active');
|
||||
}
|
||||
|
||||
function toggleSiteSelection(mode) {
|
||||
const isAdmin = document.getElementById(mode + '_is_admin').checked;
|
||||
const siteSelection = document.getElementById(mode === 'add' ? 'siteSelectionGroup' : 'editSiteSelectionGroup');
|
||||
siteSelection.style.display = isAdmin ? 'none' : 'block';
|
||||
}
|
||||
|
||||
// Initial state
|
||||
toggleSiteSelection('add');
|
||||
|
||||
// Modal schließen bei Klick außerhalb
|
||||
document.getElementById('addUserModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal('addUserModal');
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('editUserModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal('editUserModal');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
1004
admin/vouchers.php
Normal file
1004
admin/vouchers.php
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue