Commit
This commit is contained in:
		
							parent
							
								
									800551f0a9
								
							
						
					
					
						commit
						1b83f16213
					
				| @ -23,7 +23,6 @@ class AccessControl | |||||||
|             // routes that need power level 1 and up
 |             // routes that need power level 1 and up
 | ||||||
|             [ |             [ | ||||||
|                 "routes" => [ |                 "routes" => [ | ||||||
|                     "race/simulator.php", |  | ||||||
|                     "race/configure/*" |                     "race/configure/*" | ||||||
|                 ], |                 ], | ||||||
|                 "catcher" => [ |                 "catcher" => [ | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ namespace App\Core; | |||||||
|  */ |  */ | ||||||
| class ErrorHandler  | class ErrorHandler  | ||||||
| { | { | ||||||
|     public array $error_messages; |     public array $error_messages = []; | ||||||
| 
 | 
 | ||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
| @ -17,7 +17,7 @@ class ErrorHandler | |||||||
| 
 | 
 | ||||||
|         set_error_handler([$this, 'error']); |         set_error_handler([$this, 'error']); | ||||||
|         set_exception_handler([$this, 'exception']); |         set_exception_handler([$this, 'exception']); | ||||||
|         $this->error_messages = []; |         register_shutdown_function([$this, 'shutdown']); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function error($errno, $errstr, $errfile, $errline): void |     public function error($errno, $errstr, $errfile, $errline): void | ||||||
| @ -31,7 +31,7 @@ class ErrorHandler | |||||||
|         $this->error_messages[] = "<b>Uncaught Exception:</b> " . $exception; |         $this->error_messages[] = "<b>Uncaught Exception:</b> " . $exception; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function __destruct() |     private function shutdown(): void | ||||||
|     { |     { | ||||||
|         if (!$this->error_messages) { |         if (!$this->error_messages) { | ||||||
|            return;  |            return;  | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| <h1>Endre lagtabell</h1> | <h1>Konfigurer</h1> | ||||||
| <span class="float-right">[ <a class="success" href="update.php">Opprett lag</a> ]</span> | <span class="float-right">[ <a class="success" href="update.php">Opprett lag</a> ]</span> | ||||||
| <span class="float-right">[ <a class="danger" href="../reset.php">Nullstill runder</a> ] </span> | <span class="float-right">[ <a class="danger" href="reset.php">Nullstill runder</a> ] </span> | ||||||
| <br> | <br> | ||||||
| <table> | <table> | ||||||
|     <tr> |     <tr> | ||||||
| @ -1,7 +1,7 @@ | |||||||
| <h1>Simulator</h1> | <h1>Simulator</h1> | ||||||
| <p>Skriv inn et kortnummer:</p> | <p>Skriv inn et kortnummer:</p> | ||||||
| <form method="post" autocomplete="off"> | <form method="post" autocomplete="off"> | ||||||
|     <input type="text" name="cardnumber" maxlength="32"> |     <input type="text" name="cardnumber" maxlength="32" autofocus> | ||||||
|     <br> |     <br> | ||||||
|     <br> |     <br> | ||||||
|     <input type="submit" value="Send"> |     <input type="submit" value="Send"> | ||||||
| @ -1,14 +0,0 @@ | |||||||
| <div id="alert" class="alert danger hidden" role="alert"></div> |  | ||||||
| 
 |  | ||||||
| <h1>Resultat service</h1> |  | ||||||
| <br> |  | ||||||
| 
 |  | ||||||
| <noscript> |  | ||||||
| Denne siden krever JavaScript |  | ||||||
| </noscript> |  | ||||||
| 
 |  | ||||||
| <div id="ranking-table"> |  | ||||||
| Laster inn... |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <script src="../static/js/resultservice.js"></script> |  | ||||||
							
								
								
									
										19
									
								
								app/view/pages/race/resultservice.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/view/pages/race/resultservice.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | <div id="alertBox" class="alert danger hidden" role="alert"></div> | ||||||
|  | 
 | ||||||
|  | <h1>Resultatservice</h1> | ||||||
|  | <br> | ||||||
|  | 
 | ||||||
|  | <noscript> | ||||||
|  | Denne siden krever JavaScript | ||||||
|  | </noscript> | ||||||
|  | 
 | ||||||
|  | <div id="rankingTable"> | ||||||
|  | Laster inn... | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | <script src="../static/js/ResultService.js"></script> | ||||||
|  | <script> | ||||||
|  | document.addEventListener('DOMContentLoaded', () => { | ||||||
|  |     new ResultService(alertBox, rankingTable, '../api/v1/race/sync.php?h='); | ||||||
|  | }); | ||||||
|  | </script> | ||||||
| @ -38,15 +38,15 @@ | |||||||
|             <h4>Felles</h4> |             <h4>Felles</h4> | ||||||
|             <ul> |             <ul> | ||||||
|                 <li><a href="<?=$this->config['root_url']?>index.php">Forside</a></li> |                 <li><a href="<?=$this->config['root_url']?>index.php">Forside</a></li> | ||||||
|                 <li><a href="<?=$this->config['root_url']?>race/live.php">Resultater</a></li> |                 <li><a href="<?=$this->config['root_url']?>race/resultservice.php">Resultater</a></li> | ||||||
|             </ul> |             </ul> | ||||||
| 
 | 
 | ||||||
|             <?php if ($this->user->logged_in): ?>
 |             <?php if ($this->user->logged_in): ?>
 | ||||||
|                 <?php if ($this->user->power_level > 0): ?>
 |                 <?php if ($this->user->power_level > 0): ?>
 | ||||||
|                     <h4>Tillatelser</h4> |                     <h4>Admin</h4> | ||||||
|                     <ul> |                     <ul> | ||||||
|                         <li><a href="<?=$this->config['root_url']?>race/simulator.php">Simulator</a></li> |  | ||||||
|                         <li><a href="<?=$this->config['root_url']?>race/configure/index.php">Konfigurer</a></li> |                         <li><a href="<?=$this->config['root_url']?>race/configure/index.php">Konfigurer</a></li> | ||||||
|  |                         <li><a href="<?=$this->config['root_url']?>race/configure/simulator.php">Simulator</a></li> | ||||||
|                     </ul> |                     </ul> | ||||||
|                 <?php endif; ?>
 |                 <?php endif; ?>
 | ||||||
|             <?php endif; ?>
 |             <?php endif; ?>
 | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ foreach ($time_mapper->getAll() as $time) | |||||||
| 
 | 
 | ||||||
|     if (!isset($name_map[$team->id])) |     if (!isset($name_map[$team->id])) | ||||||
|     { |     { | ||||||
|         $name_map[$team->id] = $team->name; |         $name_map[$team->id] = htmlspecialchars($team->name); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if ($time_ref === NULL) |     if ($time_ref === NULL) | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| <?php $app = require '../../../../app/inc.php'; | <?php $app = require '../../../app/inc.php'; | ||||||
| /** | /** | ||||||
|  * Deletes both team and related times |  * Deletes both team and related times | ||||||
|  */ |  */ | ||||||
| @ -32,7 +32,7 @@ if (!$team) | |||||||
| if (!$confirm) | if (!$confirm) | ||||||
| { | { | ||||||
|     $app->view('template/header', ['title' => 'Bekreft sletting']); |     $app->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'); |     $app->view('template/footer'); | ||||||
|     die(); |     die(); | ||||||
| } | } | ||||||
| @ -1,4 +1,11 @@ | |||||||
| <?php $app = require '../../../app/inc.php'; | <?php $app = require '../../../app/inc.php'; | ||||||
| 
 | 
 | ||||||
| // redirect
 | use App\Teamtable\TeamMapper; | ||||||
| $app->redirect('teams/'); | 
 | ||||||
|  | $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'); | ||||||
| @ -1,4 +1,4 @@ | |||||||
| <?php $app = require '../../app/inc.php'; | <?php $app = require '../../../app/inc.php'; | ||||||
| 
 | 
 | ||||||
| // uh oh.. stinky
 | // uh oh.. stinky
 | ||||||
| 
 | 
 | ||||||
| @ -11,7 +11,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') | |||||||
|         $cardnumber = (string)$_POST['cardnumber']; |         $cardnumber = (string)$_POST['cardnumber']; | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             $code = $baton_reader->receive($cardnumber, 0); |             $code = $baton_reader->receive($cardnumber, -1); | ||||||
|             switch ($code) { |             switch ($code) { | ||||||
|                 case 0: |                 case 0: | ||||||
|                     $app->session->flash('Opprettet nytt lag', 'success'); |                     $app->session->flash('Opprettet nytt lag', 'success'); | ||||||
| @ -46,5 +46,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| $app->view('template/header', ['title' => 'Simulator']); | $app->view('template/header', ['title' => 'Simulator']); | ||||||
| $app->view('pages/race/simulator'); | $app->view('pages/race/configure/simulator'); | ||||||
| $app->view('template/footer'); | $app->view('template/footer'); | ||||||
| @ -1,11 +0,0 @@ | |||||||
| <?php $app = require '../../../../app/inc.php'; |  | ||||||
| 
 |  | ||||||
| use App\Teamtable\TeamMapper; |  | ||||||
| 
 |  | ||||||
| $team_mapper = new TeamMapper($app->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'); |  | ||||||
| @ -1,4 +1,4 @@ | |||||||
| <?php $app = require '../../../../app/inc.php'; | <?php $app = require '../../../app/inc.php'; | ||||||
| /** | /** | ||||||
|  * Creates and updates team in teamtable |  * Creates and updates team in teamtable | ||||||
|  */ |  */ | ||||||
| @ -68,7 +68,7 @@ if ($item !== NULL) | |||||||
|     $app->view('template/header', [ |     $app->view('template/header', [ | ||||||
|         'title' => $title |         'title' => $title | ||||||
|     ]); |     ]); | ||||||
|     $app->view('pages/race/configure/teams/update', [ |     $app->view('pages/race/configure/update', [ | ||||||
|         "team" => $team, |         "team" => $team, | ||||||
|         "title" => $title |         "title" => $title | ||||||
|     ]); |     ]); | ||||||
| @ -81,7 +81,7 @@ $title = "Legg til lag"; | |||||||
| $app->view('template/header', [ | $app->view('template/header', [ | ||||||
|     'title' => $title |     'title' => $title | ||||||
| ]); | ]); | ||||||
| $app->view('pages/race/configure/teams/update', [ | $app->view('pages/race/configure/update', [ | ||||||
|     "team" => new Team, |     "team" => new Team, | ||||||
|     "title" => $title |     "title" => $title | ||||||
| ]); | ]); | ||||||
| @ -1,5 +0,0 @@ | |||||||
| <?php $app = require '../../app/inc.php'; |  | ||||||
| 
 |  | ||||||
| $app->view('template/header', ["title" => "Live resultater"]); |  | ||||||
| $app->view('pages/race/live'); |  | ||||||
| $app->view('template/footer'); |  | ||||||
							
								
								
									
										5
									
								
								public/race/resultservice.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								public/race/resultservice.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | <?php $app = require '../../app/inc.php'; | ||||||
|  | 
 | ||||||
|  | $app->view('template/header', ["title" => "Resultatservice"]); | ||||||
|  | $app->view('pages/race/resultservice'); | ||||||
|  | $app->view('template/footer'); | ||||||
| @ -1,16 +1,11 @@ | |||||||
| document.addEventListener('DOMContentLoaded', () => { |  | ||||||
|     new ResultService(); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| class ResultService  | class ResultService  | ||||||
| { | { | ||||||
|     hash     = 0; |     constructor(alertBox, rankingTable, endpoint) | ||||||
|     alertbox = document.getElementById("alert"); |  | ||||||
|     table    = document.getElementById("ranking-table"); |  | ||||||
|     endpoint = "../api/v1/race/sync.php?h="; |  | ||||||
| 
 |  | ||||||
|     constructor() |  | ||||||
|     { |     { | ||||||
|  |         this.alertBox = alertBox; | ||||||
|  |         this.rankingTable = rankingTable; | ||||||
|  |         this.endpoint = endpoint; | ||||||
|  |         this.hash = 0; | ||||||
|         this.loop(); |         this.loop(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -18,11 +13,11 @@ class ResultService | |||||||
|     { |     { | ||||||
|         try { |         try { | ||||||
|             await this.updateTable(); |             await this.updateTable(); | ||||||
|             this.alertbox.classList.add("hidden"); |             this.alertBox.classList.add("hidden"); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|             console.log(error); |             console.log(error); | ||||||
|             this.alertbox.innerHTML = "<b>Noe gikk galt: </b>" + error; |             this.alertBox.innerHTML = "<b>Noe gikk galt: </b>" + error; | ||||||
|             this.alertbox.classList.remove("hidden"); |             this.alertBox.classList.remove("hidden"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
| @ -48,12 +43,16 @@ class ResultService | |||||||
|         let tableHTML = ""; |         let tableHTML = ""; | ||||||
|         tableHTML += "<table>"; |         tableHTML += "<table>"; | ||||||
|         tableHTML += "<tr>"; |         tableHTML += "<tr>"; | ||||||
|  |         tableHTML += "<th>#</th>"; | ||||||
|         tableHTML += "<th>Lag</th>"; |         tableHTML += "<th>Lag</th>"; | ||||||
|         tableHTML += "<th>Tid</th>"; |         tableHTML += "<th>Tid</th>"; | ||||||
|         tableHTML += "</tr>"; |         tableHTML += "</tr>"; | ||||||
| 
 | 
 | ||||||
|  |         let iterator = 0; | ||||||
|         data.times.reverse().forEach(element => { |         data.times.reverse().forEach(element => { | ||||||
|  |             iterator++; | ||||||
|             tableHTML += "<tr>"; |             tableHTML += "<tr>"; | ||||||
|  |             tableHTML += "<td>" + iterator + "</td>"; | ||||||
|             tableHTML += "<td>" + data.map.team.name[element.id] + "</td>"; |             tableHTML += "<td>" + data.map.team.name[element.id] + "</td>"; | ||||||
|             tableHTML += "<td>" + element.time + "</td>"; |             tableHTML += "<td>" + element.time + "</td>"; | ||||||
|             tableHTML += "</tr>"; |             tableHTML += "</tr>"; | ||||||
| @ -61,6 +60,6 @@ class ResultService | |||||||
| 
 | 
 | ||||||
|         tableHTML += "<table>"; |         tableHTML += "<table>"; | ||||||
| 
 | 
 | ||||||
|         this.table.innerHTML = tableHTML; |         this.rankingTable.innerHTML = tableHTML; | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user