diff --git a/app/lib/App/Core/AccessControl.php b/app/lib/App/Core/AccessControl.php index cb46d87..7717981 100644 --- a/app/lib/App/Core/AccessControl.php +++ b/app/lib/App/Core/AccessControl.php @@ -23,7 +23,6 @@ class AccessControl // routes that need power level 1 and up [ "routes" => [ - "race/simulator.php", "race/configure/*" ], "catcher" => [ diff --git a/app/lib/App/Core/ErrorHandler.php b/app/lib/App/Core/ErrorHandler.php index af73c6a..5000451 100644 --- a/app/lib/App/Core/ErrorHandler.php +++ b/app/lib/App/Core/ErrorHandler.php @@ -8,7 +8,7 @@ namespace App\Core; */ class ErrorHandler { - public array $error_messages; + public array $error_messages = []; public function __construct() { @@ -17,7 +17,7 @@ class ErrorHandler set_error_handler([$this, 'error']); set_exception_handler([$this, 'exception']); - $this->error_messages = []; + register_shutdown_function([$this, 'shutdown']); } public function error($errno, $errstr, $errfile, $errline): void @@ -31,7 +31,7 @@ class ErrorHandler $this->error_messages[] = "Uncaught Exception: " . $exception; } - public function __destruct() + private function shutdown(): void { if (!$this->error_messages) { return; diff --git a/app/view/pages/race/configure/teams/delete.php b/app/view/pages/race/configure/delete.php similarity index 100% rename from app/view/pages/race/configure/teams/delete.php rename to app/view/pages/race/configure/delete.php diff --git a/app/view/pages/race/configure/teams/index.php b/app/view/pages/race/configure/index.php similarity index 90% rename from app/view/pages/race/configure/teams/index.php rename to app/view/pages/race/configure/index.php index 9dd5c18..5d8ee0d 100644 --- a/app/view/pages/race/configure/teams/index.php +++ b/app/view/pages/race/configure/index.php @@ -1,6 +1,6 @@ -

Endre lagtabell

+

Konfigurer

Opprett lag ] -Nullstill runder ]  +Nullstill runder ] 
diff --git a/app/view/pages/race/simulator.php b/app/view/pages/race/configure/simulator.php similarity index 66% rename from app/view/pages/race/simulator.php rename to app/view/pages/race/configure/simulator.php index a61f735..01c7453 100644 --- a/app/view/pages/race/simulator.php +++ b/app/view/pages/race/configure/simulator.php @@ -1,7 +1,7 @@

Simulator

Skriv inn et kortnummer:

- +

diff --git a/app/view/pages/race/configure/teams/update.php b/app/view/pages/race/configure/update.php similarity index 100% rename from app/view/pages/race/configure/teams/update.php rename to app/view/pages/race/configure/update.php diff --git a/app/view/pages/race/live.php b/app/view/pages/race/live.php deleted file mode 100644 index 6982ec4..0000000 --- a/app/view/pages/race/live.php +++ /dev/null @@ -1,14 +0,0 @@ - - -

Resultat service

-
- - - -
-Laster inn... -
- - \ No newline at end of file diff --git a/app/view/pages/race/resultservice.php b/app/view/pages/race/resultservice.php new file mode 100644 index 0000000..cae6f0c --- /dev/null +++ b/app/view/pages/race/resultservice.php @@ -0,0 +1,19 @@ + + +

Resultatservice

+
+ + + +
+Laster inn... +
+ + + \ No newline at end of file diff --git a/app/view/template/header.php b/app/view/template/header.php index f1b61e4..dbef58a 100644 --- a/app/view/template/header.php +++ b/app/view/template/header.php @@ -38,15 +38,15 @@

Felles

user->logged_in): ?> user->power_level > 0): ?> -

Tillatelser

+

Admin

diff --git a/public/api/v1/race/sync.php b/public/api/v1/race/sync.php index a8c3a37..7a6b954 100644 --- a/public/api/v1/race/sync.php +++ b/public/api/v1/race/sync.php @@ -32,7 +32,7 @@ foreach ($time_mapper->getAll() as $time) if (!isset($name_map[$team->id])) { - $name_map[$team->id] = $team->name; + $name_map[$team->id] = htmlspecialchars($team->name); } if ($time_ref === NULL) diff --git a/public/race/configure/teams/delete.php b/public/race/configure/delete.php similarity index 88% rename from public/race/configure/teams/delete.php rename to public/race/configure/delete.php index 03c0e56..8b88e76 100644 --- a/public/race/configure/teams/delete.php +++ b/public/race/configure/delete.php @@ -1,4 +1,4 @@ -view('template/header', ['title' => 'Bekreft sletting']); - $app->view('pages/race/configure/teams/delete', ['team' => $team]); + $app->view('pages/race/configure/delete', ['team' => $team]); $app->view('template/footer'); die(); } diff --git a/public/race/configure/index.php b/public/race/configure/index.php index d85750b..2dd6e10 100644 --- a/public/race/configure/index.php +++ b/public/race/configure/index.php @@ -1,4 +1,11 @@ redirect('teams/'); \ No newline at end of file +use App\Teamtable\TeamMapper; + +$team_mapper = new TeamMapper($app->database->conn); + +$teams = $team_mapper->getAll(); + +$app->view('template/header', ['title' => 'Konfigurer']); +$app->view('pages/race/configure/index', ["teams" => $teams]); +$app->view('template/footer'); \ No newline at end of file diff --git a/public/race/simulator.php b/public/race/configure/simulator.php similarity index 88% rename from public/race/simulator.php rename to public/race/configure/simulator.php index 56acb1b..ae743c6 100644 --- a/public/race/simulator.php +++ b/public/race/configure/simulator.php @@ -1,4 +1,4 @@ -receive($cardnumber, 0); + $code = $baton_reader->receive($cardnumber, -1); switch ($code) { case 0: $app->session->flash('Opprettet nytt lag', 'success'); @@ -46,5 +46,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') } $app->view('template/header', ['title' => 'Simulator']); -$app->view('pages/race/simulator'); +$app->view('pages/race/configure/simulator'); $app->view('template/footer'); \ No newline at end of file diff --git a/public/race/configure/teams/index.php b/public/race/configure/teams/index.php deleted file mode 100644 index 1232274..0000000 --- a/public/race/configure/teams/index.php +++ /dev/null @@ -1,11 +0,0 @@ -database->conn); - -$teams = $team_mapper->getAll(); - -$app->view('template/header', ['title' => 'Endre lagtabell']); -$app->view('pages/race/configure/teams/index', ["teams" => $teams]); -$app->view('template/footer'); \ No newline at end of file diff --git a/public/race/configure/teams/update.php b/public/race/configure/update.php similarity index 92% rename from public/race/configure/teams/update.php rename to public/race/configure/update.php index 7fbfb04..09fffa9 100644 --- a/public/race/configure/teams/update.php +++ b/public/race/configure/update.php @@ -1,4 +1,4 @@ -view('template/header', [ 'title' => $title ]); - $app->view('pages/race/configure/teams/update', [ + $app->view('pages/race/configure/update', [ "team" => $team, "title" => $title ]); @@ -81,7 +81,7 @@ $title = "Legg til lag"; $app->view('template/header', [ 'title' => $title ]); -$app->view('pages/race/configure/teams/update', [ +$app->view('pages/race/configure/update', [ "team" => new Team, "title" => $title ]); diff --git a/public/race/live.php b/public/race/live.php deleted file mode 100644 index 597f80c..0000000 --- a/public/race/live.php +++ /dev/null @@ -1,5 +0,0 @@ -view('template/header', ["title" => "Live resultater"]); -$app->view('pages/race/live'); -$app->view('template/footer'); \ No newline at end of file diff --git a/public/race/resultservice.php b/public/race/resultservice.php new file mode 100644 index 0000000..36bb55d --- /dev/null +++ b/public/race/resultservice.php @@ -0,0 +1,5 @@ +view('template/header', ["title" => "Resultatservice"]); +$app->view('pages/race/resultservice'); +$app->view('template/footer'); \ No newline at end of file diff --git a/public/static/js/resultservice.js b/public/static/js/ResultService.js similarity index 66% rename from public/static/js/resultservice.js rename to public/static/js/ResultService.js index e42cacb..9ebe9a1 100644 --- a/public/static/js/resultservice.js +++ b/public/static/js/ResultService.js @@ -1,16 +1,11 @@ -document.addEventListener('DOMContentLoaded', () => { - new ResultService(); -}); - class ResultService { - hash = 0; - alertbox = document.getElementById("alert"); - table = document.getElementById("ranking-table"); - endpoint = "../api/v1/race/sync.php?h="; - - constructor() + constructor(alertBox, rankingTable, endpoint) { + this.alertBox = alertBox; + this.rankingTable = rankingTable; + this.endpoint = endpoint; + this.hash = 0; this.loop(); } @@ -18,11 +13,11 @@ class ResultService { try { await this.updateTable(); - this.alertbox.classList.add("hidden"); + this.alertBox.classList.add("hidden"); } catch (error) { console.log(error); - this.alertbox.innerHTML = "Noe gikk galt: " + error; - this.alertbox.classList.remove("hidden"); + this.alertBox.innerHTML = "Noe gikk galt: " + error; + this.alertBox.classList.remove("hidden"); } setTimeout(() => { @@ -48,12 +43,16 @@ class ResultService let tableHTML = ""; tableHTML += "
"; tableHTML += ""; + tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; + let iterator = 0; data.times.reverse().forEach(element => { + iterator++; tableHTML += ""; + tableHTML += ""; tableHTML += ""; tableHTML += ""; tableHTML += ""; @@ -61,6 +60,6 @@ class ResultService tableHTML += "
#LagTid
" + iterator + "" + data.map.team.name[element.id] + "" + element.time + "
"; - this.table.innerHTML = tableHTML; + this.rankingTable.innerHTML = tableHTML; } }