Compare commits
No commits in common. "744f4db361e1ff48cfac352adbbb972d79b79bdc" and "9a0dd90bd622a9ce0665c180688969afc9c2c319" have entirely different histories.
744f4db361
...
9a0dd90bd6
@ -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 1.11.24</h2>
|
||||
<h2>Oppdatert 13.10.24</h2>
|
||||
<?php
|
||||
$query = ["type"=>"paameldte"];
|
||||
$query = ["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="update()" placeholder="Søk etter startnummer">
|
||||
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
|
||||
<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("Ingen post valgt");
|
||||
console.error(error);
|
||||
alert("Velg en post!");
|
||||
return 0;
|
||||
}
|
||||
@ -84,20 +84,48 @@ function register_runner(id) {
|
||||
.then(response => {
|
||||
if (response.status == 401) {
|
||||
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() {
|
||||
const table = document.getElementById("runners");
|
||||
control = get_control();
|
||||
filter = document.getElementById("search").value;
|
||||
let request = new Request(`table.php?type=registrering&control=`+control+`&filter=`+filter);
|
||||
let request = new Request(`table.php?registrering,`+control);
|
||||
fetch(request)
|
||||
.then((response) => response.text())
|
||||
.then((text) => {table.innerHTML = text;})
|
||||
filterTable()
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
99
table.php
99
table.php
@ -1,22 +1,9 @@
|
||||
<?php
|
||||
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;
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
//declare(strict_types=1);
|
||||
class Runner
|
||||
{
|
||||
public int $id;
|
||||
@ -48,13 +35,14 @@ class Runner
|
||||
}
|
||||
|
||||
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])) {
|
||||
return $i-1;
|
||||
}
|
||||
}
|
||||
return count($this->splits)-1;
|
||||
}
|
||||
return count($this->splits)-1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,18 +84,6 @@ 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");
|
||||
@ -141,23 +117,11 @@ for ($i = 0; $i < count($timings); $i++) {
|
||||
|
||||
|
||||
if (!isset($query)){
|
||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||
$query = explode(",",$_SERVER['QUERY_STRING']);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($query[0] == "registrering"){
|
||||
$matpost = $query[1];
|
||||
echo(" <thead><tr>
|
||||
<th>#</th>
|
||||
<th>Navn</th>
|
||||
@ -194,7 +158,7 @@ if ($query["type"] == "registrering"){
|
||||
}
|
||||
echo("</tbody>");
|
||||
}
|
||||
elseif ($query["type"] == "paameldte") {
|
||||
elseif ($query[0] == "paameldte") {
|
||||
usort($runners, "cmp_course");
|
||||
|
||||
$kadaverløpere = 0;
|
||||
@ -232,11 +196,10 @@ 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>
|
||||
@ -246,16 +209,10 @@ else {
|
||||
<th>Mål</th>
|
||||
</tr></thead>
|
||||
<tbody>";
|
||||
$kadaver_num = 0;
|
||||
$mini_num = 0;
|
||||
for ($i = 0; $i < count($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") {
|
||||
$kadaver_num++;
|
||||
|
||||
if ($runner->course == "Kadaverløpet") {
|
||||
$tid_1_mat = "";
|
||||
if ($runner->splits[0] != false) {
|
||||
// https://www.php.net/manual/en/class.dateinterval.php
|
||||
@ -264,31 +221,23 @@ 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>";
|
||||
}
|
||||
else {
|
||||
$mini_num++;
|
||||
}
|
||||
|
||||
}
|
||||
$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_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") {
|
||||
$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>";
|
||||
$minikadaver_table .= "</tbody></table>";
|
||||
echo($kadaver_table);
|
||||
|
||||
}
|
||||
echo("<h2>Minikadaver'n</h2>");
|
||||
echo($minikadaver_table);
|
||||
}
|
Loading…
Reference in New Issue
Block a user