This commit is contained in:
Trygve 2024-02-16 12:14:45 +01:00
parent 7f182932a7
commit 8dec0e4aa8
4 changed files with 114 additions and 62 deletions

32
get_table.php Normal file
View File

@ -0,0 +1,32 @@
<?php
//TODO: les fra config istedet:
$start_time = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01");
echo(date_timestamp_get($start_time));
$db = file_get_contents("db.csv");
$db = str_getcsv($db, "\n");
$timings = file_get_contents("passering.csv");
$timings = str_getcsv($timings, "\n");
//add the time diff to each runner
for ($i = 0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);
$control = $line[0];
$id = $line[1];
$time = DateTime::createFromFormat(DateTime::ISO8601, $line[2]);
if (!in_array($id, $db)) {
continue;
//TODO: Burde logge dette ellerno
}
arra
array_search($id, $db);
}
for ($i=0; $i < count($db); $i++) {
$runner = str_getcsv($db[$i]);
echo("<tr><td>$runner[0]</td><td>$runner[1]</td></tr>");
}

View File

@ -1,67 +1,12 @@
<!DOCTYPE html>
<html lang="no">
<head>
<style>
.passed {
background-color: #8ff0a4;
}
</style>
</head>
<body>
<table>
<tbody id="runners">
<tbody>
<?php
include("get_table.php")
?>
</tbody>
</table>
</body>
<script>
function register_runner(id, name) {
update_row(id, name, true)
let formData = new FormData();
formData.append(name= 'id', value=id);
time = new Date(Date.now()).toISOString()
formData.append('time', time);
fetch("upload.php", {
method: "POST",
body: formData,
});
};
function read_db() {
let xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "db.csv", false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
function create_row(id, name, passed) {
if (!passed) {
button = `<button onclick="register_runner(${id}, '${name}')">✓</button>`
return `<tr id="${id}"><td>${id}</td><td>${name}</td><td>${button}</td></tr>`
}
else {
button = `<button onclick="register_runner(${id}, '${name}')">Angre</button>`
return `<tr id="${id}" class="passed"><td>${id}</td><td>${name}</td><td>${button}</td></tr>`
}
}
function create_rows(csv) {
csv = csv.split('\n')
rows = ""
for (i in csv) {
data = csv[i].split(",")
rows += create_row(data[0], data[1], false)
}
return rows
}
function update_row(id, name, passed) {
row = document.getElementById(id)
row.innerHTML = create_row(id, name, passed)
row.classList.add("passed");
}
table = document.getElementById("runners")
table.innerHTML = create_rows(read_db())
</script>
<html>
</html>

74
registrering.php Normal file
View File

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="no">
<head>
<style>
.passed {
background-color: #8ff0a4;
}
</style>
</head>
<body>
<table>
<tbody id="runners">
</tbody>
</table>
</body>
<script>
// Hvilken matpost vi er på:
var control = 1;
function register_runner(id) {
let formData = new FormData();
formData.append(name= 'control', value=control);
formData.append(name= 'id', value=id);
time = new Date(Date.now()).toISOString()
formData.append('time', time);
fetch("upload.php", {
method: "POST",
body: formData,
});
};
function update_runner_status(id, name) {
update_row(id, name, true);
register_runner(id);
}
function read_db() {
let xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "db.csv", false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
function create_row(id, name, passed) {
if (!passed) {
button = `<button onclick="update_runner_status(${id}, '${name}')">✓</button>`
return `<tr id="${id}"><td>${id}</td><td>${name}</td><td>${button}</td></tr>`
}
else {
button = `<button onclick="update_runner_status(${id}, '${name}')">Angre</button>`
return `<tr id="${id}" class="passed"><td>${id}</td><td>${name}</td><td>${button}</td></tr>`
}
}
function create_rows(csv) {
csv = csv.split('\n')
rows = ""
for (i in csv) {
data = csv[i].split(",")
rows += create_row(data[0], data[1], false)
}
return rows
}
function update_row(id, name, passed) {
row = document.getElementById(id)
row.innerHTML = create_row(id, name, passed)
row.classList.add("passed");
}
table = document.getElementById("runners")
table.innerHTML = create_rows(read_db())
</script>
<html>

View File

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