Files
Backend/WEBROOT/index.php
T

129 lines
3.6 KiB
PHP

<?php
ob_start();
// Vor allen includes, vor jeglicher Ausgabe
session_set_cookie_params([
'lifetime' => 0, // bis Browser geschlossen
'path' => '/', // Gültig für ganze Domain
'domain' => '', // aktuelle Domain
'secure' => false, // true nur für HTTPS
'httponly' => true,
'samesite' => 'Lax'
]);
session_start();
if (empty($_SESSION['user_logged_in'])) {
header('Location: login.php');
exit;
}
include 'config.php';
include 'controller/CookieController.php';
include 'controller/DatabaseConnect.php';
include 'controller/DatabaseController.php';
include 'controller/DataController.php';
include 'controller/LogController.php';
include 'controller/UserController.php';
// include 'controller/RoutesController.php';
$selectedService = null;
// 1. Service aus URL, wenn erlaubt & aktiv
if (
isset($_GET['service']) &&
isset($services[$_GET['service']]) &&
$services[$_GET['service']]['active']
) {
$selectedService = $_GET['service'];
}
// 2. Default-Service
if (!$selectedService &&
isset($defaultService) &&
isset($services[$defaultService]) &&
$services[$defaultService]['active']
) {
$selectedService = $defaultService;
}
// 3. Fallback: erster aktiver Service
if (!$selectedService) {
foreach ($services as $key => $service) {
if ($service['active']) {
$selectedService = $key;
break;
}
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backend</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
Backend
<button id="darkModeToggle">🌙 Dark Mode</button>
<script src="main.js"></script>
</header>
<div class="main">
<div class="sidebar">
<?php foreach ($serviceGroups as $groupKey => $group): ?>
<?php
$isOpen = false;
if (!empty($group['defaultOpen'])) {
$isOpen = true;
}
if (in_array($selectedService, $group['services'], true)) {
$isOpen = true;
}
?>
<div class="service-group <?= $isOpen ? 'open' : '' ?>" data-group="<?= $groupKey ?>">
<div class="group-title">
<?= htmlspecialchars($group['label']) ?>
<span class="arrow">▸</span>
</div>
<div class="group-services">
<?php foreach ($group['services'] as $serviceKey): ?>
<?php
if (!isset($services[$serviceKey])) continue;
if (!$services[$serviceKey]['active']) continue;
if (!empty($services[$serviceKey]['adminOnly']) && !$isAdmin) {
continue;
}
?>
<a href="?service=<?= $serviceKey ?>">
<button class="<?= $selectedService === $serviceKey ? 'active' : '' ?>">
<?= htmlspecialchars($services[$serviceKey]['name']) ?>
</button>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="content">
<?php
if ($selectedService) {
include "services/$selectedService.php";
} else {
echo "<p>Kein aktiver Service verfügbar.</p>";
}
?>
</div>
</div>
</body>
</html>