Compare commits

..

No commits in common. "744f4db361e1ff48cfac352adbbb972d79b79bdc" and "9a0dd90bd622a9ce0665c180688969afc9c2c319" have entirely different histories.

4 changed files with 65 additions and 88 deletions

View File

@ -2,7 +2,7 @@
<html lang="no"> <html lang="no">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Påmeldte Kadaverløpet</title> <title>Påmeldte kadaverløpet</title>
<meta name="viewport" content="width=device-width,initial-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" /> <meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
<link rel="stylesheet" href="matcha.css"> <link rel="stylesheet" href="matcha.css">
@ -17,11 +17,11 @@
<body> <body>
<div class="flex align-center"> <div class="flex align-center">
<figure><img src="img/kadaver.png" alt="" width="100px" class="invert"></figure> <figure><img src="img/kadaver.png" alt="" width="100px" class="invert"></figure>
<h1>Påmeldte Kadaverløpet 2024</h1> <h1>Påmeldte kadaverløpet 2024</h1>
</div> </div>
<h2>Oppdatert 1.11.24</h2> <h2>Oppdatert 13.10.24</h2>
<?php <?php
$query = ["type"=>"paameldte"]; $query = ["paameldte"];
include("table.php"); include("table.php");
?> ?>
<footer> <footer>

View File

@ -47,7 +47,7 @@
</fieldset> </fieldset>
<button onmousedown="update()">Oppdater tabell</button> <button onmousedown="update()">Oppdater tabell</button>
<input id="search" type="number" class="form-control" onkeyup="update()" placeholder="Søk etter startnummer"> <input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
<br> <br>
</div> </div>
<table id="runners"></table> <table id="runners"></table>
@ -67,7 +67,7 @@ function get_control() {
function register_runner(id) { function register_runner(id) {
control = get_control(); control = get_control();
if (control == 0) { if (control == 0) {
console.error("Ingen post valgt"); console.error(error);
alert("Velg en post!"); alert("Velg en post!");
return 0; return 0;
} }
@ -84,20 +84,48 @@ function register_runner(id) {
.then(response => { .then(response => {
if (response.status == 401) { if (response.status == 401) {
alert("Feil passord!") alert("Feil passord!")
}}) }
.then((response) => update()); })
document.getElementById("search").focus();
update()
document.getElementById("search").focus()
}; };
function filterTable() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("search");
filter = input.value;
table = document.getElementById("runners").getElementsByTagName("tbody")[0];
if (!table) {
setTimeout(filterTable, 100);
}
tr = table.getElementsByTagName("tr");
if (filter == "") {
for (i = 0; i < tr.length; i++) {
tr[i].style.display = "";
}
}
else {
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
txtValue = td[0].textContent;
if (txtValue == filter) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
function update() { function update() {
const table = document.getElementById("runners"); const table = document.getElementById("runners");
control = get_control(); control = get_control();
filter = document.getElementById("search").value; let request = new Request(`table.php?registrering,`+control);
let request = new Request(`table.php?type=registrering&control=`+control+`&filter=`+filter);
fetch(request) fetch(request)
.then((response) => response.text()) .then((response) => response.text())
.then((text) => {table.innerHTML = text;}) .then((text) => {table.innerHTML = text;})
filterTable()
} }
</script> </script>
</body> </body>

View File

@ -1,22 +1,9 @@
<?php <?php
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-11-02T08:53:00+01"); $GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08:07:32+01");
$GLOBALS['number_of_controls'] = 3; $GLOBALS['number_of_controls'] = 3;
// Caching //declare(strict_types=1);
header("Last-Modified: " . date("F d Y H:i:s.", filemtime("passering.csv")));
$etag = '"' . md5_file("passering.csv"). '"';
header(header: 'ETag: ' . $etag );
if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
// If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
// So send a 304 Not Modified response header and exit
if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.1 304 Not Modified', true, 304);
exit();
}
}
class Runner class Runner
{ {
public int $id; public int $id;
@ -48,8 +35,9 @@ class Runner
} }
function get_control() function get_control()
{ for ($i = 0; $i < count($this->splits); $i++) { {
// Returns wich control the runner last passed
for ($i = 0; $i < count($this->splits); $i++) {
if (!is_object($this->splits[$i])) { if (!is_object($this->splits[$i])) {
return $i-1; return $i-1;
} }
@ -96,18 +84,6 @@ function cmp_course(Runner $a, Runner $b) {
return strcmp($a->course, $b->course); return strcmp($a->course, $b->course);
} }
function filter_runners(Runner $runner, $id) {
if ($runner->id == $id) {
return True;
}
else {
return False;
}
}
function time_diff(DateTime $date_1, DateTime $date_2) {
return $date_2->getTimestamp() - $date_1->getTimestamp();
}
$runners = []; $runners = [];
$csv_runners = file_get_contents("db.csv"); $csv_runners = file_get_contents("db.csv");
@ -141,23 +117,11 @@ for ($i = 0; $i < count($timings); $i++) {
if (!isset($query)){ if (!isset($query)){
parse_str($_SERVER['QUERY_STRING'], $query); $query = explode(",",$_SERVER['QUERY_STRING']);
} }
if ($query["type"] == "registrering"){ if ($query[0] == "registrering"){
$matpost = $query["control"]; $matpost = $query[1];
$runners_filtered = [];
if ($query["filter"]) {
for ($i = 0; $i < count($runners); $i++) {
if (filter_runners($runners[$i], $query["filter"])) {
array_push($runners_filtered, $runners[$i]);
}
}
$runners = $runners_filtered;
}
echo(" <thead><tr> echo(" <thead><tr>
<th>#</th> <th>#</th>
<th>Navn</th> <th>Navn</th>
@ -194,7 +158,7 @@ if ($query["type"] == "registrering"){
} }
echo("</tbody>"); echo("</tbody>");
} }
elseif ($query["type"] == "paameldte") { elseif ($query[0] == "paameldte") {
usort($runners, "cmp_course"); usort($runners, "cmp_course");
$kadaverløpere = 0; $kadaverløpere = 0;
@ -236,7 +200,6 @@ else {
<th>1. matpost</th> <th>1. matpost</th>
<th>2. matpost</th> <th>2. matpost</th>
<th>Mål</th> <th>Mål</th>
<th>Sprekkindeks</th>
</tr></thead> </tr></thead>
<tbody>"; <tbody>";
$minikadaver_table = "<table><thead> $minikadaver_table = "<table><thead>
@ -246,16 +209,10 @@ else {
<th>Mål</th> <th>Mål</th>
</tr></thead> </tr></thead>
<tbody>"; <tbody>";
$kadaver_num = 0;
$mini_num = 0;
for ($i = 0; $i < count($runners); $i++) { for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i]; $runner = $runners[$i];
$tid_maal = "";
if ($runner->splits[2] != false) {
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
}
if ($runner->course == "Kadaverløpet") { if ($runner->course == "Kadaverløpet") {
$kadaver_num++;
$tid_1_mat = ""; $tid_1_mat = "";
if ($runner->splits[0] != false) { if ($runner->splits[0] != false) {
// https://www.php.net/manual/en/class.dateinterval.php // https://www.php.net/manual/en/class.dateinterval.php
@ -264,31 +221,23 @@ else {
$tid_2_mat = ""; $tid_2_mat = "";
if ($runner->splits[1] != false) { if ($runner->splits[1] != false) {
$tid_2_mat = $GLOBALS['start_time']->diff($runner->splits[1])->format('%H:%I:%S'); $tid_2_mat = $GLOBALS['start_time']->diff($runner->splits[1])->format('%H:%I:%S');
try {
$sprekk = "<td>" . number_format(100*(time_diff($GLOBALS['start_time'],$runner->splits[2]) - time_diff($GLOBALS['start_time'],$runner->splits[1])) / time_diff($GLOBALS['start_time'],$runner->splits[2]), 0) . "%</td>";
}
catch (DivisionByZeroError $e){
$sprekk = "<td></td>";
}
catch (TypeError $e) {
$sprekk = "<td></td>";
}
} }
$matposter = "<td>$tid_1_mat</td><td>$tid_2_mat</td>"; $matposter = "<td>$tid_1_mat</td><td>$tid_2_mat</td>";
} }
else { $tid_maal = "";
$mini_num++; if ($runner->splits[2] != false) {
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
} }
if ($runner->course == "Kadaverløpet") { if ($runner->course == "Kadaverløpet") {
$kadaver_table .= "<tr><td>". $kadaver_num .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td>$sprekk</tr>\n"; $kadaver_table .= "<tr><td>". $i+1 .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td></tr>\n";
} }
elseif ($runner->course == "Minikadaver'n") { elseif ($runner->course == "Minikadaver'n") {
$minikadaver_table .= "<tr><td>". "" .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n"; $minikadaver_table .= "<tr><td>". $i+1 .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
} }
} }
$kadaver_table .= "</tbody></table>"; $kadaver_table .= "</tbody></table>";
$minikadaver_table .= "</tbody></table>"; $minikadaver_table .= "</tbody></table>";
echo($kadaver_table); echo($kadaver_table);
echo("<h2>Minikadaver'n</h2>");
echo($minikadaver_table);
} }