288 lines
11 KiB
PHP
288 lines
11 KiB
PHP
<?php
|
|
// Rennplan abrufen
|
|
include 'config.php';
|
|
$rennplanRaw = json_decode($rennplanJson, true)['rennplan'];
|
|
|
|
// Alle Läufe in ein flaches Array überführen
|
|
$rennplan = [];
|
|
foreach ($rennplanRaw as $lauf) {
|
|
foreach ($lauf as $rennen) {
|
|
$rennplan[] = $rennen;
|
|
}
|
|
}
|
|
|
|
// Bootdaten abrufen
|
|
$boote = json_decode($bootJson, true);
|
|
$bootMap = [];
|
|
$bootIdMap = [];
|
|
foreach ($boote as $boot) {
|
|
$bootMap[$boot['name']] = $boot;
|
|
$bootIdMap[$boot['name']] = $boot['id'];
|
|
}
|
|
// Pager
|
|
function pageTeam($message, $pagerApi, $pagerApiSecret)
|
|
{
|
|
$ch = curl_init($pagerApi);
|
|
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POSTFIELDS => $message,
|
|
CURLOPT_HTTPHEADER => [
|
|
'Content-Type: text/plain',
|
|
'Authorization: Bearer ' . $pagerApiSecret
|
|
]
|
|
]);
|
|
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
return $response;
|
|
}
|
|
|
|
// Paging
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|
|
|
switch ($_POST['action']) {
|
|
|
|
case 'page_team':
|
|
if (!empty($_POST['bootid'])) {
|
|
pageTeam($_POST['bootid'], $pagerApi, $pagerApiSecret);
|
|
}
|
|
break;
|
|
|
|
case 'page_next':
|
|
if (isset($_POST['rennen']) && isset($rennplan[(int)$_POST['rennen'] + 1])) {
|
|
|
|
$nextRace = $rennplan[(int)$_POST['rennen'] + 1];
|
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
|
if (empty($nextRace["bahn$i"])) {
|
|
continue;
|
|
}
|
|
|
|
$bootName = $nextRace["bahn$i"];
|
|
|
|
if (isset($bootIdMap[$bootName])) {
|
|
pageTeam(
|
|
$bootIdMap[$bootName],
|
|
$pagerApi,
|
|
$pagerApiSecret
|
|
);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'page_all':
|
|
pageTeam(
|
|
'ALL',
|
|
$pagerApi,
|
|
$pagerApiSecret
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Ergebnisse abrufen
|
|
$ergebnisse = isset(json_decode($ergebnisseJson, true)['ergebnisse'])
|
|
? json_decode($ergebnisseJson, true)['ergebnisse']
|
|
: [];
|
|
|
|
// Aktuelles Rennen per Index (über URL)
|
|
$rennenIndex = isset($_GET['rennen']) ? intval($_GET['rennen']) : 0;
|
|
$totalRennen = count($rennplan);
|
|
|
|
// Index validieren
|
|
$rennenIndex = max(0, min($rennenIndex, $totalRennen - 1));
|
|
|
|
// Aktuelles, vorheriges, nächstes Rennen
|
|
$current = $rennplan[$rennenIndex];
|
|
$prev = $rennplan[$rennenIndex - 1] ?? null;
|
|
$next = $rennplan[$rennenIndex + 1] ?? null;
|
|
|
|
// Ergebnis für vorheriges Rennen
|
|
$lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Moderation <?= htmlspecialchars($eventname) ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<div class="container py-4">
|
|
<h1 class="mb-4">Moderation <?= htmlspecialchars($eventname) ?></h1>
|
|
|
|
<!-- Aktuelles Rennen -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-primary text-white">Aktuelles Rennen: <?= htmlspecialchars($current['name']) ?> (<?= $current['zeit'] ?>)</div>
|
|
<div class="card-body">
|
|
<?php for ($i = 1; $i <= 3; $i++): ?>
|
|
<?php if (!empty($current["bahn$i"])):
|
|
$bootName = $current["bahn$i"];
|
|
$boot = $bootMap[$bootName] ?? null;
|
|
?>
|
|
<div class="mb-2">
|
|
<strong>Bahn <?= $i ?>:</strong> <?= htmlspecialchars($bootName) ?>
|
|
<?php if ($boot): ?>
|
|
<button class="btn btn-sm btn-outline-secondary ms-2" data-bs-toggle="collapse" data-bs-target="#bootDetails<?= $i ?>">Details</button>
|
|
<div class="collapse mt-2" id="bootDetails<?= $i ?>">
|
|
<div class="card card-body">
|
|
<p><strong>Wer sind wir:</strong> <?= nl2br(htmlspecialchars($boot['wernsindwir'] ?? '')) ?></p>
|
|
<p><strong>Woher kommen wir:</strong> <?= htmlspecialchars($boot['woherkommenwir'] ?? '') ?></p>
|
|
<p><strong>Trommlerin:</strong> <?= htmlspecialchars($boot['trommlerin'] ?? '-') ?></p>
|
|
<p><strong>Aufschlag:</strong> <?= htmlspecialchars($boot['aufschlag'] ?? '-') ?></p>
|
|
<p><strong>Ziele:</strong> <?= htmlspecialchars($boot['ziele'] ?? '') ?></p>
|
|
<p><strong>Was uns auszeichnet:</strong> <?= htmlspecialchars($boot['was_uns_auszeichnet'] ?? '') ?></p>
|
|
<p><strong>Schlachtruf:</strong> <?= htmlspecialchars($boot['schlachtruf'] ?? '') ?></p>
|
|
<p><strong>Teilnahmen:</strong> <?= intval($boot['anzahl_teilnahmen']) ?></p>
|
|
<p><strong>Platzierungen:</strong> <?= implode(', ', $boot['platzierungen'] ?? []) ?></p>
|
|
<p><strong>Notizen:</strong> <?= htmlspecialchars($boot['notizen'] ?? '') ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endfor; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Ergebnisse -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-success text-white">Ergebnisse aus dem letzten Rennen</div>
|
|
<div class="card-body">
|
|
<?php if ($lastResult): ?>
|
|
<ul class="list-group">
|
|
<?php foreach (['bahn1', 'bahn2', 'bahn3'] as $bahn): ?>
|
|
<?php if (isset($lastResult[$bahn])): ?>
|
|
<li class="list-group-item">
|
|
<strong><?= htmlspecialchars($lastResult[$bahn]['boot']) ?>:</strong> <?= htmlspecialchars($lastResult[$bahn]['zeit']) ?>
|
|
<?php if (($lastResult['winner'] ?? '') === $bahn): ?>
|
|
<span class="badge bg-warning text-dark">Sieger</span>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else: ?>
|
|
<p>Noch kein Ergebnis.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Nächstes Rennen -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-info text-white">Nächstes Rennen</div>
|
|
<div class="card-body">
|
|
<?php if ($next): ?>
|
|
<p><strong><?= htmlspecialchars($next['name']) ?></strong> um <?= htmlspecialchars($next['zeit']) ?></p>
|
|
<ul class="list-group">
|
|
<?php for ($i = 1; $i <= 3; $i++): ?>
|
|
<?php if (!empty($next["bahn$i"])): ?>
|
|
<?php
|
|
$bootName = $next["bahn$i"];
|
|
$bootId = $bootIdMap[$bootName] ?? null;
|
|
?>
|
|
<li class="list-group-item">
|
|
Bahn <?= $i ?>:
|
|
<?= htmlspecialchars($bootName) ?>
|
|
<?php if ($bootId): ?>
|
|
<form method="post" class="d-inline float-end">
|
|
<input type="hidden" name="action" value="page_team">
|
|
<input type="hidden" name="bootid" value="<?= $bootId ?>">
|
|
<button type="submit" class="btn btn-sm btn-warning">
|
|
Page
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endif; ?>
|
|
<?php endfor; ?>
|
|
</ul>
|
|
<form method="post" class="mt-3">
|
|
<input
|
|
type="hidden"
|
|
name="action"
|
|
value="page_next">
|
|
<input
|
|
type="hidden"
|
|
name="rennen"
|
|
value="<?= $rennenIndex ?>">
|
|
<button
|
|
type="submit"
|
|
class="btn btn-warning">
|
|
Alle Boote des nächsten Rennens pagen
|
|
</button>
|
|
</form>
|
|
|
|
<?php else: ?>
|
|
<p><strong>Letztes Rennen im Lauf</strong></p>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Navigation -->
|
|
<div class="d-flex justify-content-between">
|
|
<a href="?rennen=<?= max(0, $rennenIndex - 1) ?>" class="btn btn-outline-secondary">Vorheriges Rennen</a>
|
|
<a href="?rennen=<?= min($totalRennen - 1, $rennenIndex + 1) ?>" class="btn btn-primary">Nächstes Rennen</a>
|
|
</div>
|
|
<hr>
|
|
<form method="post" id="pageAllForm">
|
|
<input
|
|
type="hidden"
|
|
name="action"
|
|
value="page_all">
|
|
<button
|
|
type="button"
|
|
class="btn btn-danger"
|
|
data-bs-toggle="modal"
|
|
data-bs-target="#confirmPageAllModal">
|
|
Alle Teams pagen
|
|
</button>
|
|
</form>
|
|
|
|
</div>
|
|
<div class="modal fade" id="confirmPageAllModal" tabindex="-1" aria-labelledby="confirmPageAllModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="confirmPageAllModalLabel">
|
|
ACHTUNG!
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Schließen"></button>
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
Möchtest du wirklich alle Boote pagen?
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
|
Abbrechen
|
|
</button>
|
|
|
|
<button type="button" class="btn btn-danger" id="confirmPageAllButton">
|
|
Ja, alle pagen
|
|
</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('confirmPageAllButton').addEventListener('click', function () {
|
|
document.getElementById('pageAllForm').submit();
|
|
});
|
|
</script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|