feat: Saisons-Verwaltung im Admin-Bereich implementieren und Menü anpassen

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 17:55:58 +02:00
parent 374b8fed6e
commit 55e03541ff
4 changed files with 245 additions and 1 deletions

View file

@ -105,6 +105,67 @@ if ($page === 'login') {
Auth::requireLogin();
Auth::requireAdmin();
require __DIR__ . '/../src/Views/admin.php';
} elseif ($page === 'admin_seasons') {
Auth::requireLogin();
Auth::requireAdmin();
$message = null;
$error = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
$seasonId = $_POST['id'] ?? null;
$redirect = '/index.php?page=admin_seasons';
try {
if ($action === 'create' || $action === 'update') {
$data = [
'name' => $_POST['name'],
'rounds' => $_POST['rounds'],
];
if (empty($data['name']) || !is_numeric($data['rounds'])) {
throw new \Exception('Name und Anzahl der Runden sind erforderlich.');
}
if ($action === 'create') {
Season::create($data);
$_SESSION['admin_message'] = "Saison erfolgreich erstellt.";
} elseif ($seasonId) {
Season::update($seasonId, $data);
$_SESSION['admin_message'] = "Saison erfolgreich aktualisiert.";
}
} elseif ($action === 'set_current' && $seasonId) {
Season::setCurrent($seasonId);
$_SESSION['admin_message'] = "Aktive Saison wurde geändert.";
}
} catch (\Throwable $e) {
$_SESSION['admin_error'] = "Fehler: " . $e->getMessage();
if ($action === 'update' && $seasonId) {
$redirect = '/index.php?page=admin_seasons&edit_id=' . $seasonId;
}
}
header('Location: ' . $redirect);
exit;
}
if (isset($_SESSION['admin_message'])) {
$message = $_SESSION['admin_message'];
unset($_SESSION['admin_message']);
}
if (isset($_SESSION['admin_error'])) {
$error = $_SESSION['admin_error'];
unset($_SESSION['admin_error']);
}
$seasons = Season::getAll();
$currentSeason = Season::getCurrent();
$editSeason = null;
if (isset($_GET['edit_id'])) {
$editSeason = Season::findById((int)$_GET['edit_id']);
}
require __DIR__ . '/../src/Views/admin/seasons.php';
} elseif ($page === 'admin_users') {
Auth::requireLogin();
Auth::requireAdmin();