diff --git a/config.php b/config.php index e6f428e..dec742e 100644 --- a/config.php +++ b/config.php @@ -5,4 +5,8 @@ $rennplanJson = file_get_contents('https://api.sat.regattatech.de/api/v1/rennpla $bootJson = file_get_contents('https://api.sat.regattatech.de/api/v1/boot/'); -$ergebnisseJson = file_get_contents('https://api.sat.regattatech.de/api/v1/results/current/'); \ No newline at end of file +$ergebnisseJson = file_get_contents('https://api.sat.regattatech.de/api/v1/results/current/'); + +$pagerApi = "https://sat.regattatech.de/api/v1/page/"; + +$pagerApiSecret = "foobar"; \ No newline at end of file diff --git a/mod.php b/mod.php index 7dd632a..2f0d29a 100644 --- a/mod.php +++ b/mod.php @@ -14,14 +14,81 @@ foreach ($rennplanRaw as $lauf) { // 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'] - : []; + ? json_decode($ergebnisseJson, true)['ergebnisse'] + : []; // Aktuelles Rennen per Index (über URL) $rennenIndex = isset($_GET['rennen']) ? intval($_GET['rennen']) : 0; @@ -43,13 +110,13 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null; - Moderation <?php echo $eventname; ?> + Moderation <?= htmlspecialchars($eventname) ?>
-

Moderation

+

Moderation

@@ -60,12 +127,12 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null; $bootName = $current["bahn$i"]; $boot = $bootMap[$bootName] ?? null; ?> -
- Bahn : - - +
+ Bahn : + +
-
+

Wer sind wir:

Woher kommen wir:

Trommlerin:

@@ -78,8 +145,9 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null;

Notizen:

- -
+
+ +
@@ -121,9 +189,26 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null; +
+ + + +
+

Letztes Rennen im Lauf

+
@@ -132,6 +217,19 @@ $lastResult = $rennenIndex > 0 ? ($ergebnisse[$rennenIndex - 1] ?? null) : null; Vorheriges Rennen Nächstes Rennen +
+
+ + +
+