fix: Verwalte Spieleinsatz über Quoten-Tabelle

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-04 18:19:51 +02:00
parent 362966e0cd
commit d130676940
4 changed files with 25 additions and 21 deletions

View file

@ -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;
}
}
}
}

View file

@ -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,

View file

@ -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'],
]);
}

View file

@ -32,15 +32,15 @@ require __DIR__ . '/../partials/header.php';
</div>
<div class="form-group">
<label for="stake">Einsatz (€):</label>
<input type="number" step="0.01" id="stake" name="stake" value="<?php echo htmlspecialchars($editSeason['stake'] ?? '25.00'); ?>" required>
<input type="number" step="0.01" id="stake" name="stake" value="<?php echo htmlspecialchars($stakeValue ?? '25.00'); ?>" required>
</div>
<hr style="margin: 2rem 0;">
<h2>Quoten</h2>
<div id="quotas-container">
<?php
$quotas = $quotasOfSeason ?? [];
if ($editSeason === null && empty($quotasOfSeason)) {
$quotas = $quotasForForm ?? [];
if ($editSeason === null && empty($quotasForForm)) {
$quotas = [
['name' => '1. Platz', 'prc' => '50'],
['name' => '2. Platz', 'prc' => '30'],
@ -71,7 +71,7 @@ require __DIR__ . '/../partials/header.php';
<script>
document.addEventListener('DOMContentLoaded', function() {
let quotaIndex = <?php echo count($quotas ?? []); ?>;
let quotaIndex = <?php echo count($quotasForForm ?? []); ?>;
document.getElementById('add-quota').addEventListener('click', function() {
const container = document.getElementById('quotas-container');