tippspiel2027/src/Views/admin/rounds.php
2026-10-04 23:15:54 +02:00

136 lines
6.5 KiB
PHP

<?php
use App\Models\Round;
$pageTitle = 'Spiele & Ergebnisse eintragen';
require __DIR__ . '/../partials/header.php';
$failedRoundId = $failedForm ? (int)($failedForm['round_id'] ?? 0) : null;
?>
<h1>Spiele &amp; Ergebnisse eintragen</h1>
<?php if (!empty($message)): ?>
<p style="color: green;"><?php echo htmlspecialchars($message); ?></p>
<?php endif; ?>
<?php if (!empty($error)): ?>
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>
<?php endif; ?>
<form method="get" action="/index.php" class="round-filter">
<input type="hidden" name="page" value="admin_rounds">
<label for="season_id">Saison:</label>
<select id="season_id" name="season_id" onchange="this.form.submit()">
<?php foreach ($seasons as $s): ?>
<option value="<?php echo (int)$s['id']; ?>" <?php if ((int)$s['id'] === $seasonId) echo 'selected'; ?>>
<?php echo htmlspecialchars($s['name']); ?><?php if ($currentSeason && (int)$currentSeason['id'] === (int)$s['id']) echo ' (aktiv)'; ?>
</option>
<?php endforeach; ?>
</select>
<noscript><button type="submit">Anzeigen</button></noscript>
</form>
<?php if (!$season): ?>
<p>Keine Saison vorhanden. Bitte zuerst unter <a href="/index.php?page=admin_seasons">Saisons verwalten</a> eine Saison anlegen.</p>
<?php elseif (empty($rounds)): ?>
<p>Diese Saison hat keine Runden.</p>
<?php else: ?>
<p class="round-index">
<?php foreach ($rounds as $round): ?>
<a href="#round-<?php echo (int)$round['id']; ?>" class="<?php echo $round['completed'] ? 'done' : 'open'; ?>"
title="<?php echo $round['completed'] ? 'Abgeschlossen' : 'Offen'; ?>"><?php echo htmlspecialchars($round['name']); ?></a>
<?php endforeach; ?>
</p>
<?php foreach ($rounds as $round):
$roundId = (int)$round['id'];
$form = ($failedRoundId === $roundId) ? $failedForm : null;
$isOpen = $failedRoundId === $roundId || ($failedRoundId === null && $roundId === $firstIncompleteRoundId);
?>
<details id="round-<?php echo $roundId; ?>" class="round-admin" <?php if ($isOpen) echo 'open'; ?>>
<summary>
<strong><?php echo htmlspecialchars($round['name']); ?></strong>
<span class="round-status <?php echo $round['completed'] ? 'done' : 'open'; ?>">
<?php echo $round['completed'] ? 'abgeschlossen' : 'offen'; ?>
</span>
<?php if ($round['lock_time']): ?>
<small>sperrt: <?php echo $round['lock_time']->format('d.m.Y H:i'); ?></small>
<?php endif; ?>
</summary>
<form method="post" action="/index.php?page=admin_rounds&amp;season_id=<?php echo $seasonId; ?>">
<input type="hidden" name="round_id" value="<?php echo $roundId; ?>">
<div class="form-group">
<label for="name-<?php echo $roundId; ?>">Rundenname:</label>
<input type="text" id="name-<?php echo $roundId; ?>" name="name" maxlength="64" required
value="<?php echo htmlspecialchars($form['name'] ?? $round['name']); ?>">
</div>
<table>
<thead>
<tr>
<th>Heim</th>
<th>Gast</th>
<th>Anstoß</th>
<th>Ergebnis</th>
</tr>
</thead>
<tbody>
<?php foreach ($round['games'] as $game):
$gameId = (int)$game['id'];
$in = $form['games'][$gameId] ?? null;
$field = "games[$gameId]";
?>
<tr>
<td><input type="text" name="<?php echo $field; ?>[team1]" maxlength="100" required
value="<?php echo htmlspecialchars($in['team1'] ?? $game['team1']); ?>"></td>
<td><input type="text" name="<?php echo $field; ?>[team2]" maxlength="100" required
value="<?php echo htmlspecialchars($in['team2'] ?? $game['team2']); ?>"></td>
<td><input type="datetime-local" name="<?php echo $field; ?>[kickoff]" required
value="<?php echo htmlspecialchars($in['kickoff'] ?? date('Y-m-d\TH:i', strtotime($game['kickoff']))); ?>"></td>
<td class="score">
<input type="number" min="0" name="<?php echo $field; ?>[score1]"
value="<?php echo htmlspecialchars($in['score1'] ?? ((int)$game['score1'] < 0 ? '' : $game['score1'])); ?>">
:
<input type="number" min="0" name="<?php echo $field; ?>[score2]"
value="<?php echo htmlspecialchars($in['score2'] ?? ((int)$game['score2'] < 0 ? '' : $game['score2'])); ?>">
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p class="hint">Ergebnis leer lassen, solange das Spiel noch nicht beendet ist.</p>
<div class="form-group">
<label for="report-<?php echo $roundId; ?>">Berichterstattung:</label><br>
<textarea id="report-<?php echo $roundId; ?>" name="report" rows="4"><?php
echo htmlspecialchars($form['report'] ?? Round::reportToText($round['report']));
?></textarea>
</div>
<button type="submit">Speichern</button>
</form>
</details>
<?php endforeach; ?>
<?php endif; ?>
<style>
.round-index a { margin-right: 0.6em; white-space: nowrap; text-decoration: none; }
.round-index a.done { color: #888; }
.round-index a.open { color: #007bff; font-weight: bold; }
.round-admin { border: 1px solid #ccc; padding: 0.5em 1em; margin-bottom: 1em; max-width: 1000px; }
.round-admin summary { cursor: pointer; }
.round-admin summary small { color: #666; margin-left: 1em; }
.round-status { margin-left: 0.5em; font-size: 0.8em; padding: 0 0.4em; border-radius: 3px; }
.round-status.done { background: #d4edda; color: #155724; }
.round-status.open { background: #fff3cd; color: #856404; }
.round-admin td input[type="text"] { width: 10em; }
.round-admin td.score { white-space: nowrap; }
.round-admin td.score input { width: 3.5em; }
.round-admin textarea { width: 100%; max-width: 800px; }
.round-admin .form-group { margin: 0.8em 0; }
.round-admin .hint { color: #666; font-size: 0.8em; }
</style>
<?php require __DIR__ . '/../partials/footer.php'; ?>