Compare commits

..

No commits in common. "9a0dd90bd622a9ce0665c180688969afc9c2c319" and "91ada2809d33e1aa361b47fa3ccecec26a3d9cfe" have entirely different histories.

10 changed files with 148 additions and 203 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -80,10 +80,6 @@ function cmp(Runner $a, Runner $b) {
} }
return 0; return 0;
} }
function cmp_course(Runner $a, Runner $b) {
return strcmp($a->course, $b->course);
}
$runners = []; $runners = [];
$csv_runners = file_get_contents("db.csv"); $csv_runners = file_get_contents("db.csv");
@ -122,97 +118,16 @@ if (!isset($query)){
if ($query[0] == "registrering"){ if ($query[0] == "registrering"){
$matpost = $query[1]; $matpost = $query[1];
echo(" <thead><tr> echo(" <tr>
<th>#</th>
<th>Navn</th>
<th>Tid</th>
<th></th>
</tr></thead>
<tbody>");
for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i];
// Klokkeslett for denne posten
if ($runner->splits[$matpost-1] != false) {
$tid_passering = $GLOBALS['start_time']->diff($runner->splits[$matpost-1])->format('%H:%I:%S');
}
else {
$tid_passering = "";
}
if ($runner->get_control() == $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "class=\"bg-success\"";
}
elseif ($runner->get_control() > $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "class=\"bg-active\"";
}
else {
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "";
}
echo ("<tr $cssclass><td>$runner->id</td><td>$runner->name</td><td>$tid_passering</td><td>$button</td></tr>\n");
}
echo("</tbody>");
}
elseif ($query[0] == "paameldte") {
usort($runners, "cmp_course");
$kadaverløpere = 0;
$minikadaverløpere = 0;
for ($i = 0; $i < count($runners); $i++) {
if ($runners[$i]->course == "Kadaverløpet") {
$kadaverløpere++;
}
elseif ($runners[$i]->course == "Minikadaver'n") {
$minikadaverløpere++;
}
}
echo("<div class=\"flex space-evenly\">
<div class=\"flash accent\">$kadaverløpere påmeldt Kadaverløpet</div><div class=\"flash accent\">$minikadaverløpere påmeldte i Minikadaver'n</div>
</div>");
echo("<table><thead>
<tr>
<th>S.nr</th>
<th>Navn</th>
<th>Klubb/Forening</th>
<th>Variant</th>
</tr></thead>
<tbody>");
for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i];
echo ("<tr><td>$runner->id</td><td>$runner->name</td><td>$runner->club</td><td>$runner->course</td></tr>\n");
}
echo("<table><tbody>");
}
else {
usort($runners, "cmp");
usort($runners, "cmp_course");
$kadaver_table = "<table><thead>
<tr>
<th>#</th> <th>#</th>
<th>Startnummer</th>
<th>Navn</th> <th>Navn</th>
<th>1. matpost</th> <th>1. matpost</th>
<th>2. matpost</th> <th>2. matpost</th>
<th>Mål</th> <th>Mål</th>
</tr></thead> </tr>");
<tbody>";
$minikadaver_table = "<table><thead>
<tr>
<th>#</th>
<th>Navn</th>
<th>Mål</th>
</tr></thead>
<tbody>";
for ($i = 0; $i < count($runners); $i++) { for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i]; $runner = $runners[$i];
if ($runner->course == "Kadaverløpet") {
$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
@ -222,22 +137,63 @@ else {
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');
} }
$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');
}
if ($runner->get_control() == $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "class=\"bg-success\"\"";
}
elseif ($runner->get_control() > $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "class=\"bg-active\"\"";
}
else {
$button = "<button onclick=\"register_runner($runner->id)\">✓</button>";
$cssclass = "";
}
echo ("<tr $cssclass><td>". $i+1 .".</td><td>$runner->id</td><td>$runner->name</td><td>$tid_1_mat</td><td>$tid_2_mat</td><td>$tid_maal</td><td>$button</td></tr>\n");
}
}
elseif ($query[0] == "paameldte") {
echo(" <tr>
<th>Navn</th>
<th>Klubb/Forening</th>
<th>Variant</th>
</tr>");
for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i];
echo ("<td>$runner->name</td><td>$runner->club</td><td>$runner->course</td></tr>\n");
}
}
else {
usort($runners, "cmp");
echo(" <tr>
<th>#</th>
<th>Startnummer</th>
<th>Navn</th>
<th>1. matpost</th>
<th>2. matpost</th>
<th>Mål</th>
</tr>");
for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i];
$tid_1_mat = "";
if ($runner->splits[0] != false) {
// https://www.php.net/manual/en/class.dateinterval.php
$tid_1_mat = $GLOBALS['start_time']->diff($runner->splits[0])->format('%H:%I:%S');
}
$tid_2_mat = "";
if ($runner->splits[1] != false) {
$tid_2_mat = $GLOBALS['start_time']->diff($runner->splits[1])->format('%H:%I:%S');
} }
$tid_maal = ""; $tid_maal = "";
if ($runner->splits[2] != false) { if ($runner->splits[2] != false) {
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S'); $tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
} }
if ($runner->course == "Kadaverløpet") { echo ("<tr><td>". $i+1 .".</td><td>$runner->id</td><td>$runner->name</td><td>$tid_1_mat</td><td>$tid_2_mat</td><td>$tid_maal</td></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>". $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);
} }

View File

@ -7,12 +7,6 @@
<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">
<style> <style>
@media only screen and (max-width: 650px) {
body {
padding-left: 0;
padding-right: 0;
}
}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
.invert { .invert {
filter: invert(1); filter: invert(1);
@ -23,20 +17,25 @@
<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>TESTING Løpende resultater Kadaverløpet 2024</h1> <h1>TESTING Løpende resultater kadaverløpet 2024</h1>
</div> </div>
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2> <h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
<table>
<tbody>
<?php <?php
include("table.php") include("get_table.php")
?> ?>
</tbody>
<footer> <footer>
</table>
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3> <h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
<figure><img src="img/NMBUI.webp" alt="" width="200px"></figure> <figure><img src="img/NMBUI.webp" alt="" width="200px"></figure>
</footer> </footer>
</body>
<script> <script>
function update() { function update() {
const table = document.querySelector("table"); const table = document.querySelector("table");
const myRequest = new Request(`table.php`); const myRequest = new Request(`get_table.php`);
fetch(myRequest) fetch(myRequest)
.then((response) => response.text()) .then((response) => response.text())
.then((text) => { .then((text) => {
@ -45,5 +44,4 @@ include("table.php")
} }
setInterval(update, 5*1000) setInterval(update, 5*1000)
</script> </script>
</body>
</html> </html>

File diff suppressed because one or more lines are too long

View File

@ -19,12 +19,16 @@
<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 13.10.24</h2> <h2>Oppdatert 11.10.24</h2>
<table>
<tbody>
<?php <?php
$query = ["paameldte"]; $query = ["paameldte"];
include("table.php"); include("get_table.php");
?> ?>
</tbody>
<footer> <footer>
</table>
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3> <h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
<figure><img src="img/NMBUI.webp" alt="" width="200px"></figure> <figure><img src="img/NMBUI.webp" alt="" width="200px"></figure>
</footer> </footer>

View File

@ -1,17 +0,0 @@
<?php
$control = $_POST['control'];
$runner_id = $_POST['id'];
$time = $_POST['time'];
$password = $_POST['password'];
$hash = file_get_contents("hash.txt");
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
}
else {
$file = 'passering.csv';
$current = file_get_contents($file);
$current .= $control . "," . $runner_id . "," . $time . "\n";
file_put_contents($file, $current);
}

View File

@ -7,11 +7,8 @@
<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">
<style> <style>
body { .passed {
padding: 0; background-color: #8ff0a4;
}
.settings {
padding: 0 1.5rem;
} }
fieldset { fieldset {
display: flex; display: flex;
@ -27,9 +24,6 @@
</style> </style>
</head> </head>
<body> <body>
<div class="settings">
<legend>Passord</legend>
<input type="password" name="passord" id="password">
<fieldset> <fieldset>
<legend>Velg post</legend> <legend>Velg post</legend>
<label> <label>
@ -46,11 +40,20 @@
</label> </label>
</fieldset> </fieldset>
<button onmousedown="update()">Oppdater tabell</button> <button onmousedown="update()">Oppdater</button>
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk"> <input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
<br> <br>
</div>
<table id="runners"></table> <table>
<tbody id="runners">
</tbody>
</table>
</body>
<?php
$action = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
print_r($action)
?>
<script> <script>
// Hvilken matpost vi er på: // Hvilken matpost vi er på:
var control = location.search[1]; var control = location.search[1];
@ -72,61 +75,63 @@ function register_runner(id) {
return 0; return 0;
} }
let formData = new FormData(); let formData = new FormData();
formData.append(name= 'password', value=document.getElementById('password').value)
formData.append(name= 'control', value=control); formData.append(name= 'control', value=control);
formData.append(name= 'id', value=id); formData.append(name= 'id', value=id);
time = new Date(Date.now()).toISOString().split('.')[0]+"Z" time = new Date(Date.now()).toISOString().split('.')[0]+"Z"
formData.append('time', time); formData.append('time', time);
response = fetch("passing.php", { fetch("upload.php", {
method: "POST", method: "POST",
body: formData, body: formData,
}) });
.then(response => {
if (response.status == 401) {
alert("Feil passord!")
}
})
update() update()
document.getElementById("search").focus() //document.getElementById("search").focus()
}; };
function create_rows(csv) {
csv = csv.split('\n')
rows = "<tr><th>#</th><th>Navn</th><th></th>";
for (i in csv) {
data = csv[i].split(",")
rows += create_row(data[0], data[1], false)
}
return rows
}
function filterTable() { function filterTable() {
var input, filter, table, tr, td, i, txtValue; var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("search"); input = document.getElementById("search");
filter = input.value; filter = input.value.toUpperCase();
table = document.getElementById("runners").getElementsByTagName("tbody")[0]; table = document.getElementById("runners");
if (!table) {
setTimeout(filterTable, 100);
}
tr = table.getElementsByTagName("tr"); 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++) { for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td"); td = tr[i].getElementsByTagName("td");
txtValue = td[0].textContent; for (var j = 0; j < td.length; j++) {
if (txtValue == filter) { txtValue = td[j].textContent || td[j].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = ""; tr[i].style.display = "";
break;
} else { } else {
tr[i].style.display = "none"; tr[i].style.display = "none";
} }
} }
}
} }
function update_row(id, name, passed) {
row = document.getElementById(id)
row.innerHTML = create_row(id, name, passed)
row.classList.add("bg-success");
} }
function update() { function update() {
const table = document.getElementById("runners"); const table = document.getElementById("runners");
control = get_control(); control = get_control();
let request = new Request(`table.php?registrering,`+control); const myRequest = new Request(`get_table.php?registrering,`+control);
fetch(request) fetch(myRequest)
.then((response) => response.text()) .then((response) => response.text())
.then((text) => {table.innerHTML = text;}) .then((text) => {
filterTable() table.innerHTML = text;
});
} }
update()
</script> </script>
</body> <html>
</html>

8
upload.php Normal file
View File

@ -0,0 +1,8 @@
<?php
$control = $_POST['control'];
$runner_id = $_POST['id'];
$time = $_POST['time'];
$file = 'passering.csv';
$current = file_get_contents($file);
$current .= $control . "," . $runner_id . "," . $time . "\n";
file_put_contents($file, $current);