diff --git a/public/index.php b/public/index.php index cceb579..147dce4 100644 --- a/public/index.php +++ b/public/index.php @@ -123,18 +123,21 @@ if ($page === 'login') { $data = [ 'name' => $_POST['name'], 'rounds' => $_POST['rounds'], - 'stake' => $_POST['stake'], ]; - if (empty($data['name']) || !is_numeric($data['rounds']) || !is_numeric($data['stake'])) { + $stake = $_POST['stake'] ?? '0'; + if (empty($data['name']) || !is_numeric($data['rounds']) || !is_numeric($stake)) { throw new \Exception('Name, Runden und Einsatz sind erforderlich.'); } + + $quotasToSave = [['name' => 'Einsatz', 'prc' => $stake]]; + if (isset($_POST['quotas']) && is_array($_POST['quotas'])) { + $quotasToSave = array_merge($quotasToSave, $_POST['quotas']); + } if ($action === 'create') { $newSeasonId = Season::create($data); if ($newSeasonId) { - if (isset($_POST['quotas'])) { - Quota::updateForSeason($newSeasonId, $_POST['quotas']); - } + Quota::updateForSeason($newSeasonId, $quotasToSave); Season::setCurrent($newSeasonId); $_SESSION['admin_message'] = "Saison erfolgreich erstellt und als aktiv gesetzt."; } else { @@ -142,11 +145,7 @@ if ($page === 'login') { } } elseif ($seasonId) { Season::update($seasonId, $data); - - if (isset($_POST['quotas'])) { - Quota::updateForSeason($seasonId, $_POST['quotas']); - } - + Quota::updateForSeason($seasonId, $quotasToSave); $_SESSION['admin_message'] = "Saison erfolgreich aktualisiert."; } } elseif ($action === 'set_current' && $seasonId) { @@ -176,11 +175,19 @@ if ($page === 'login') { $seasons = Season::getAll(); $currentSeason = Season::getCurrent(); $editSeason = null; - $quotasOfSeason = []; + $quotasForForm = []; + $stakeValue = '25.00'; // Default if (isset($_GET['edit_id'])) { $editSeason = Season::findById((int)$_GET['edit_id']); if ($editSeason) { - $quotasOfSeason = Quota::getBySeason($editSeason['id']); + $allQuotas = Quota::getBySeason($editSeason['id']); + foreach ($allQuotas as $quota) { + if ($quota['name'] === 'Einsatz') { + $stakeValue = $quota['prc']; + } else { + $quotasForForm[] = $quota; + } + } } } diff --git a/schema.sql b/schema.sql index 497b8df..8a0632a 100644 --- a/schema.sql +++ b/schema.sql @@ -63,7 +63,6 @@ CREATE TABLE `seasons` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, `rounds` int(11) NOT NULL DEFAULT '36', - `stake` decimal(8,2) NOT NULL DEFAULT '25.00', `active` tinyint(1) NOT NULL DEFAULT '1', `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, diff --git a/src/Models/Season.php b/src/Models/Season.php index c4d7f46..671621b 100644 --- a/src/Models/Season.php +++ b/src/Models/Season.php @@ -75,12 +75,11 @@ class Season { try { $stmt = $db->prepare( - "INSERT INTO seasons (name, rounds, stake, created_at, updated_at) VALUES (:name, :rounds, :stake, NOW(), NOW())" + "INSERT INTO seasons (name, rounds, created_at, updated_at) VALUES (:name, :rounds, NOW(), NOW())" ); $stmt->execute([ ':name' => $data['name'], ':rounds' => $data['rounds'], - ':stake' => $data['stake'], ]); $seasonId = $db->lastInsertId(); @@ -111,13 +110,12 @@ class Season { public static function update($id, $data) { $db = Database::getConnection(); $stmt = $db->prepare( - "UPDATE seasons SET name = :name, rounds = :rounds, stake = :stake, updated_at = NOW() WHERE id = :id" + "UPDATE seasons SET name = :name, rounds = :rounds, updated_at = NOW() WHERE id = :id" ); return $stmt->execute([ ':id' => $id, ':name' => $data['name'], ':rounds' => $data['rounds'], - ':stake' => $data['stake'], ]); } diff --git a/src/Views/admin/seasons.php b/src/Views/admin/seasons.php index 2ab26db..cad4c98 100644 --- a/src/Views/admin/seasons.php +++ b/src/Views/admin/seasons.php @@ -32,15 +32,15 @@ require __DIR__ . '/../partials/header.php';