Compare commits
5 Commits
9a0dd90bd6
...
744f4db361
Author | SHA1 | Date | |
---|---|---|---|
|
744f4db361 | ||
|
27a924584e | ||
|
2284704031 | ||
|
956da69043 | ||
|
a18c29cbe6 |
@ -2,7 +2,7 @@
|
||||
<html lang="no">
|
||||
<head>
|
||||
<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="description" content="Elektronisk Kadaver Tidtakningssystem" />
|
||||
<link rel="stylesheet" href="matcha.css">
|
||||
@ -17,11 +17,11 @@
|
||||
<body>
|
||||
<div class="flex align-center">
|
||||
<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>
|
||||
<h2>Oppdatert 13.10.24</h2>
|
||||
<h2>Oppdatert 1.11.24</h2>
|
||||
<?php
|
||||
$query = ["paameldte"];
|
||||
$query = ["type"=>"paameldte"];
|
||||
include("table.php");
|
||||
?>
|
||||
<footer>
|
||||
|
@ -14,4 +14,4 @@ else {
|
||||
$current = file_get_contents($file);
|
||||
$current .= $control . "," . $runner_id . "," . $time . "\n";
|
||||
file_put_contents($file, $current);
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@
|
||||
</fieldset>
|
||||
|
||||
<button onmousedown="update()">Oppdater tabell</button>
|
||||
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
|
||||
<input id="search" type="number" class="form-control" onkeyup="update()" placeholder="Søk etter startnummer">
|
||||
<br>
|
||||
</div>
|
||||
<table id="runners"></table>
|
||||
@ -67,7 +67,7 @@ function get_control() {
|
||||
function register_runner(id) {
|
||||
control = get_control();
|
||||
if (control == 0) {
|
||||
console.error(error);
|
||||
console.error("Ingen post valgt");
|
||||
alert("Velg en post!");
|
||||
return 0;
|
||||
}
|
||||
@ -84,48 +84,20 @@ function register_runner(id) {
|
||||
.then(response => {
|
||||
if (response.status == 401) {
|
||||
alert("Feil passord!")
|
||||
}
|
||||
})
|
||||
|
||||
update()
|
||||
document.getElementById("search").focus()
|
||||
}})
|
||||
.then((response) => 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() {
|
||||
const table = document.getElementById("runners");
|
||||
control = get_control();
|
||||
let request = new Request(`table.php?registrering,`+control);
|
||||
filter = document.getElementById("search").value;
|
||||
let request = new Request(`table.php?type=registrering&control=`+control+`&filter=`+filter);
|
||||
fetch(request)
|
||||
.then((response) => response.text())
|
||||
.then((text) => {table.innerHTML = text;})
|
||||
filterTable()
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
99
table.php
99
table.php
@ -1,9 +1,22 @@
|
||||
<?php
|
||||
date_default_timezone_set('UTC');
|
||||
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08:07:32+01");
|
||||
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-11-02T08:53:00+01");
|
||||
$GLOBALS['number_of_controls'] = 3;
|
||||
|
||||
//declare(strict_types=1);
|
||||
// Caching
|
||||
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
|
||||
{
|
||||
public int $id;
|
||||
@ -35,14 +48,13 @@ class Runner
|
||||
}
|
||||
|
||||
function get_control()
|
||||
{
|
||||
// Returns wich control the runner last passed
|
||||
for ($i = 0; $i < count($this->splits); $i++) {
|
||||
{ for ($i = 0; $i < count($this->splits); $i++) {
|
||||
|
||||
if (!is_object($this->splits[$i])) {
|
||||
return $i-1;
|
||||
}
|
||||
}
|
||||
return count($this->splits)-1;
|
||||
}
|
||||
return count($this->splits)-1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,6 +96,18 @@ function cmp_course(Runner $a, Runner $b) {
|
||||
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 = [];
|
||||
$csv_runners = file_get_contents("db.csv");
|
||||
@ -117,11 +141,23 @@ for ($i = 0; $i < count($timings); $i++) {
|
||||
|
||||
|
||||
if (!isset($query)){
|
||||
$query = explode(",",$_SERVER['QUERY_STRING']);
|
||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||
}
|
||||
|
||||
if ($query[0] == "registrering"){
|
||||
$matpost = $query[1];
|
||||
if ($query["type"] == "registrering"){
|
||||
$matpost = $query["control"];
|
||||
$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>
|
||||
<th>#</th>
|
||||
<th>Navn</th>
|
||||
@ -158,7 +194,7 @@ if ($query[0] == "registrering"){
|
||||
}
|
||||
echo("</tbody>");
|
||||
}
|
||||
elseif ($query[0] == "paameldte") {
|
||||
elseif ($query["type"] == "paameldte") {
|
||||
usort($runners, "cmp_course");
|
||||
|
||||
$kadaverløpere = 0;
|
||||
@ -196,10 +232,11 @@ else {
|
||||
$kadaver_table = "<table><thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Navn</th>
|
||||
<th>Navn</th>
|
||||
<th>1. matpost</th>
|
||||
<th>2. matpost</th>
|
||||
<th>Mål</th>
|
||||
<th>Sprekkindeks</th>
|
||||
</tr></thead>
|
||||
<tbody>";
|
||||
$minikadaver_table = "<table><thead>
|
||||
@ -209,10 +246,16 @@ else {
|
||||
<th>Mål</th>
|
||||
</tr></thead>
|
||||
<tbody>";
|
||||
$kadaver_num = 0;
|
||||
$mini_num = 0;
|
||||
for ($i = 0; $i < count($runners); $i++) {
|
||||
$runner = $runners[$i];
|
||||
|
||||
if ($runner->course == "Kadaverløpet") {
|
||||
$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") {
|
||||
$kadaver_num++;
|
||||
$tid_1_mat = "";
|
||||
if ($runner->splits[0] != false) {
|
||||
// https://www.php.net/manual/en/class.dateinterval.php
|
||||
@ -221,23 +264,31 @@ else {
|
||||
$tid_2_mat = "";
|
||||
if ($runner->splits[1] != false) {
|
||||
$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>";
|
||||
}
|
||||
$tid_maal = "";
|
||||
if ($runner->splits[2] != false) {
|
||||
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$mini_num++;
|
||||
}
|
||||
|
||||
if ($runner->course == "Kadaverløpet") {
|
||||
$kadaver_table .= "<tr><td>". $i+1 .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td></tr>\n";
|
||||
$kadaver_table .= "<tr><td>". $kadaver_num .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td>$sprekk</tr>\n";
|
||||
}
|
||||
elseif ($runner->course == "Minikadaver'n") {
|
||||
$minikadaver_table .= "<tr><td>". $i+1 .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
|
||||
$minikadaver_table .= "<tr><td>". "" .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
|
||||
}
|
||||
}
|
||||
$kadaver_table .= "</tbody></table>";
|
||||
$minikadaver_table .= "</tbody></table>";
|
||||
echo($kadaver_table);
|
||||
echo("<h2>Minikadaver'n</h2>");
|
||||
echo($minikadaver_table);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user