Compare commits

...

3 Commits

Author SHA1 Message Date
Trygve 5fba83a829 Lagde en løperklasse 2024-02-17 19:23:27 +01:00
Trygve acd4823dac Begynte på tabellproduskjon 2024-02-16 21:26:46 +01:00
Trygve 8dec0e4aa8 commit 2024-02-16 12:14:45 +01:00
4 changed files with 159 additions and 62 deletions

77
get_table.php Normal file
View File

@ -0,0 +1,77 @@
<?php
date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01");
$GLOBALS['number_of_controls'] = 3;
//declare(strict_types=1);
class Runner {
public int $id;
public string $name;
public array $splits;
function __construct($id, $name) {
echo($id);
echo($name);
if ($id == null) {$id = 0; $name = "";}
$this->id = $id;
$this->name = $name;
for($i = 0; $i<$$GLOBALS['number_of_controls']; $i++) {
array_push($this->splits, 0);
}
}
function set_split($control, $timestamp) {
$this->splits[$control] = $timestamp;
}
}
//find runner by id in list of Runner objects
function get_runner($runnner_list, int $id) {
for ($i = 0; $i < count($runnner_list); $i++) {
if ($runnner_list[$i] == $id) {
return $runnner_list[$i];
}
}
return false;
}
$runners = [];
$csv_runners = file_get_contents("db.csv");
$csv_runners = str_getcsv($csv_runners, "\n");
print_r($csv_runners);
for ($i=0; $i < count($csv_runners); $i++) {
$line = str_getcsv($csv_runners[$i]);
array_push($runners, new Runner($line[0], $line[1]));
}
$timings = file_get_contents("passering.csv");
$timings = str_getcsv($timings, "\n");
for ($i=0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);
$time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]);
if (!$time) {
//error
continue;
}
$runner = get_runner($runners, (int)$line[1]);
if (!$runner) {
//error
continue;
}
$runner->set_split($line[0], $time);
}
print_r($runners);
for ($i=0; $i < count($runners); $i++) {
$runner = $runners[$i];
$times = "";
//for ($i= 0; $i < count($runner[2]); $i++) {
//echo("". $runner[2][$i][1] ."\n");
//}
echo("<tr><td>$runner->id</td><td>$runner->name</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>
<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().split('.')[0]+"Z"
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);