Compare commits
18 Commits
dbcbaff3e1
...
sql
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c037ee8c5 | ||
|
|
8d3b914433 | ||
|
|
744f4db361 | ||
|
|
27a924584e | ||
|
|
2284704031 | ||
|
|
956da69043 | ||
|
|
a18c29cbe6 | ||
|
|
9a0dd90bd6 | ||
|
|
be878ac77e | ||
|
|
004474c2e1 | ||
|
|
3ec19dd4cb | ||
|
|
35df188cf6 | ||
|
|
78c6f0e2dd | ||
|
|
b2afadedf1 | ||
|
|
91ada2809d | ||
|
|
40f8468cd4 | ||
|
|
a51be0c2bf | ||
|
|
fb0d6cd678 |
BIN
QTOldGoudy.woff2
Normal file
BIN
QTOldGoudy.woff2
Normal file
Binary file not shown.
BIN
fonts/QTOldGoudy-Bold.otf
Normal file
BIN
fonts/QTOldGoudy-Bold.otf
Normal file
Binary file not shown.
BIN
fonts/QTOldGoudy.otf
Normal file
BIN
fonts/QTOldGoudy.otf
Normal file
Binary file not shown.
135
get_table.php
135
get_table.php
@@ -1,135 +0,0 @@
|
||||
<?php
|
||||
date_default_timezone_set('UTC');
|
||||
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08: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++) {
|
||||
$this->splits[$i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function set_split($control, $timestamp)
|
||||
{
|
||||
$this->splits[$control] = $timestamp;
|
||||
}
|
||||
|
||||
function get_control()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
//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 == $id) {
|
||||
return $runnner_list[$i];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function cmp(Runner $a, Runner $b) {
|
||||
$a_control = $a->get_control();
|
||||
$b_control = $b->get_control();
|
||||
if ($a_control > $b_control){
|
||||
return -1;
|
||||
}
|
||||
if ($a_control < $b_control){
|
||||
return 1;
|
||||
}
|
||||
if ($a_control == -1) {
|
||||
return 1;
|
||||
}
|
||||
if ($b_control == -1) {
|
||||
return -1;
|
||||
}
|
||||
if ($a->splits[$a_control]->getTimestamp() < $b->splits[$b_control]->getTimestamp()){
|
||||
return -1;
|
||||
}
|
||||
if ($a->splits[$a_control]->getTimestamp() > $b->splits[$b_control]->getTimestamp()){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
$runners = [];
|
||||
$csv_runners = file_get_contents("db.csv");
|
||||
$csv_runners = str_getcsv($csv_runners, "\n");
|
||||
//print_r($csv_runners);
|
||||
for ($i = 1; $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]-1, $time);
|
||||
}
|
||||
|
||||
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 = "";
|
||||
if ($runner->splits[2] != false) {
|
||||
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
|
||||
}
|
||||
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");
|
||||
}
|
||||
BIN
img/NMBUI.png
Normal file
BIN
img/NMBUI.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
BIN
img/NMBUI.webp
Normal file
BIN
img/NMBUI.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
BIN
img/kadaver.png
Normal file
BIN
img/kadaver.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 488 KiB |
4
import_csv.sql
Normal file
4
import_csv.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
CREATE TABLE IF NOT EXISTS løpere(id INTEGER PRIMARY KEY, navn TEXT);
|
||||
.separator ,
|
||||
.mode csv
|
||||
.import db.csv QNH
|
||||
48
index.php
48
index.php
@@ -5,29 +5,49 @@
|
||||
<title>EKT</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
|
||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
|
||||
<link rel="stylesheet" href="matcha.css">
|
||||
<style>
|
||||
@media only screen and (max-width: 650px) {
|
||||
body {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.invert {
|
||||
filter: invert(1);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Løpende resultater kadaverløpet 2024</h1>
|
||||
<div class="flex align-center">
|
||||
<figure><img src="img/kadaver.png" alt="" width="100px" class="invert"></figure>
|
||||
<h1>TESTING Løpende resultater Kadaverløpet 2024</h1>
|
||||
</div>
|
||||
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
|
||||
<table>
|
||||
<tbody>
|
||||
<?php
|
||||
include("get_table.php")
|
||||
include("table.php");
|
||||
liveresult_table($runners);
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
<footer>
|
||||
<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>
|
||||
</footer>
|
||||
<script>
|
||||
function update() {
|
||||
const table = document.querySelector("table");
|
||||
const myRequest = new Request(`get_table.php`);
|
||||
fetch(myRequest)
|
||||
.then((response) => response.text())
|
||||
.then((text) => {
|
||||
table.innerHTML = text;
|
||||
});
|
||||
const request = new XMLHttpRequest();
|
||||
request.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
table.innerHTML = this.responseText;
|
||||
localStorage.setItem("ETag", this.getResponseHeader("ETag"));
|
||||
}};
|
||||
request.open("GET", "table.php?type=liveresultater");
|
||||
request.setRequestHeader("If-None-Match", localStorage.getItem("ETag"));
|
||||
request.send();
|
||||
}
|
||||
setInterval(update, 5*1000)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
15
matcha.css
Normal file
15
matcha.css
Normal file
File diff suppressed because one or more lines are too long
91
oppdater_db.php
Normal file
91
oppdater_db.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
function import_csv_to_sqlite(&$pdo, $csv_path, $options = array())
|
||||
{
|
||||
extract($options);
|
||||
|
||||
if (($csv_handle = fopen($csv_path, "r")) === FALSE)
|
||||
throw new Exception('Cannot open CSV file');
|
||||
|
||||
if(!$delimiter)
|
||||
$delimiter = ',';
|
||||
|
||||
if(!$table)
|
||||
$table = preg_replace("/[^A-Z0-9]/i", '', basename($csv_path));
|
||||
|
||||
if(!$fields){
|
||||
$fields = array_map(function ($field){
|
||||
return strtolower(preg_replace("/[^A-Z0-9]/i", '', $field));
|
||||
}, fgetcsv($csv_handle, 0, $delimiter));
|
||||
}
|
||||
|
||||
$create_fields_str = join(', ', array_map(function ($field){
|
||||
return "$field TEXT NULL";
|
||||
}, $fields));
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$create_table_sql = "CREATE TABLE IF NOT EXISTS $table ($create_fields_str)";
|
||||
$pdo->exec($create_table_sql);
|
||||
|
||||
$insert_fields_str = join(', ', $fields);
|
||||
$insert_values_str = join(', ', array_fill(0, count($fields), '?'));
|
||||
$insert_sql = "INSERT INTO $table ($insert_fields_str) VALUES ($insert_values_str)";
|
||||
$insert_sth = $pdo->prepare($insert_sql);
|
||||
|
||||
$inserted_rows = 0;
|
||||
while (($data = fgetcsv($csv_handle, 0, $delimiter)) !== FALSE) {
|
||||
$insert_sth->execute($data);
|
||||
$inserted_rows++;
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
fclose($csv_handle);
|
||||
|
||||
return array(
|
||||
'table' => $table,
|
||||
'fields' => $fields,
|
||||
'insert' => $insert_sth,
|
||||
'inserted_rows' => $inserted_rows
|
||||
);
|
||||
|
||||
}
|
||||
import_csv_to_sqlite()
|
||||
|
||||
$password = $_POST['password'];
|
||||
|
||||
function send_response ($response, $code = 200) {
|
||||
http_response_code($code);
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
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);
|
||||
}
|
||||
if (empty($data['favorite'])) {
|
||||
send_response([
|
||||
'status' => 'failed',
|
||||
'message' => 'Please provide a favorite movie.',
|
||||
], 400);
|
||||
}
|
||||
|
||||
send_response([
|
||||
'status' => 'success',
|
||||
'message' => 'Fila er lasta opp',
|
||||
]);
|
||||
|
||||
}
|
||||
else {
|
||||
send_response([
|
||||
'status' => 'success',
|
||||
'message' => 'Fila er lasta opp',
|
||||
|
||||
], 400);
|
||||
}
|
||||
32
paameldte.php
Normal file
32
paameldte.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="no">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<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">
|
||||
<style>
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.invert {
|
||||
filter: invert(1);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<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>
|
||||
</div>
|
||||
<h2>Oppdatert 1.11.24</h2>
|
||||
<?php
|
||||
$query = ["type"=>"paameldte"];
|
||||
include("table.php");
|
||||
?>
|
||||
<footer>
|
||||
<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>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
17
passing.php
Normal file
17
passing.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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);
|
||||
}
|
||||
150
registrering.php
150
registrering.php
@@ -5,124 +5,100 @@
|
||||
<title>EKT</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
|
||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
|
||||
<link rel="stylesheet" href="matcha.css">
|
||||
<style>
|
||||
.passed {
|
||||
background-color: #8ff0a4;
|
||||
}
|
||||
fieldset {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
body {
|
||||
padding: 0;
|
||||
}
|
||||
.settings {
|
||||
padding: 0 1.5rem;
|
||||
}
|
||||
fieldset {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
.bg-success {
|
||||
background: var(--bg-success) !important;
|
||||
}
|
||||
.bg-active {
|
||||
background: var(--bg-active) !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="settings">
|
||||
<legend>Passord</legend>
|
||||
<input type="password" name="passord" id="password">
|
||||
<fieldset>
|
||||
<legend>Velg post</legend>
|
||||
<label>
|
||||
<input type="radio" name="post" value="1">
|
||||
<input type="radio" name="post" value="1" onclick="update()">
|
||||
1. Matpost
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="post" value="2">
|
||||
<input type="radio" name="post" value="2" onclick="update()">
|
||||
2. Matpost
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="post" value="3">
|
||||
<input type="radio" name="post" value="3" onclick="update()">
|
||||
Mål
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
|
||||
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
|
||||
<button onmousedown="update()">Oppdater tabell</button>
|
||||
<input id="search" type="number" class="form-control" onkeyup="update()" placeholder="Søk etter startnummer">
|
||||
<br>
|
||||
|
||||
<table>
|
||||
<tbody id="runners">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
<?php
|
||||
$action = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
|
||||
print_r($action)
|
||||
?>
|
||||
</div>
|
||||
<table id="runners"></table>
|
||||
<script>
|
||||
// Hvilken matpost vi er på:
|
||||
var control = location.search[1];
|
||||
|
||||
function get_control() {
|
||||
try {
|
||||
return document.querySelector('input[name="post"]:checked').value;
|
||||
}
|
||||
catch (error) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function register_runner(id) {
|
||||
control = document.querySelector('input[name="post"]:checked').value;
|
||||
control = get_control();
|
||||
if (control == 0) {
|
||||
console.error("Ingen post valgt");
|
||||
alert("Velg en post!");
|
||||
return 0;
|
||||
}
|
||||
let formData = new FormData();
|
||||
formData.append(name= 'password', value=document.getElementById('password').value)
|
||||
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", {
|
||||
response = fetch("passing.php", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
})
|
||||
.then(response => {
|
||||
if (response.status == 401) {
|
||||
alert("Feil passord!")
|
||||
}})
|
||||
.then((response) => update());
|
||||
document.getElementById("search").focus();
|
||||
|
||||
};
|
||||
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>`
|
||||
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);
|
||||
fetch(request)
|
||||
.then((response) => response.text())
|
||||
.then((text) => {table.innerHTML = text;})
|
||||
}
|
||||
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 = "<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() {
|
||||
var input, filter, table, tr, td, i, txtValue;
|
||||
input = document.getElementById("search");
|
||||
filter = input.value.toUpperCase();
|
||||
table = document.getElementById("runners");
|
||||
tr = table.getElementsByTagName("tr");
|
||||
|
||||
for (i = 0; i < tr.length; i++) {
|
||||
td = tr[i].getElementsByTagName("td");
|
||||
for (var j = 0; j < td.length; j++) {
|
||||
txtValue = td[j].textContent || td[j].innerText;
|
||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
||||
tr[i].style.display = "";
|
||||
break;
|
||||
} else {
|
||||
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("passed");
|
||||
}
|
||||
table = document.getElementById("runners")
|
||||
table.innerHTML = create_rows(read_db())
|
||||
</script>
|
||||
<html>
|
||||
</body>
|
||||
</html>
|
||||
301
table.php
Normal file
301
table.php
Normal file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
date_default_timezone_set('UTC');
|
||||
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-11-02T08:53:00+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) {
|
||||
http_response_code(304);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
class Runner
|
||||
{
|
||||
public int $id;
|
||||
public string $name;
|
||||
public string $club;
|
||||
public string $course;
|
||||
public array $splits;
|
||||
|
||||
function __construct($id, $name, $club, $course)
|
||||
{
|
||||
if ($id == null) {
|
||||
$id = 0;
|
||||
$name = "";
|
||||
}
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->club = $club;
|
||||
$this->course = $course;
|
||||
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
|
||||
$this->splits[$i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function set_split($control, $timestamp)
|
||||
{
|
||||
$this->splits[$control] = $timestamp;
|
||||
}
|
||||
|
||||
function get_control()
|
||||
{ for ($i = 0; $i < count($this->splits); $i++) {
|
||||
|
||||
if (!is_object($this->splits[$i])) {
|
||||
return $i-1;
|
||||
}
|
||||
}
|
||||
return count($this->splits)-1;
|
||||
}
|
||||
}
|
||||
|
||||
//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 == $id) {
|
||||
return $runnner_list[$i];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function cmp(Runner $a, Runner $b) {
|
||||
$a_control = $a->get_control();
|
||||
$b_control = $b->get_control();
|
||||
if ($a_control > $b_control){
|
||||
return -1;
|
||||
}
|
||||
if ($a_control < $b_control){
|
||||
return 1;
|
||||
}
|
||||
if ($a_control == -1) {
|
||||
return 1;
|
||||
}
|
||||
if ($b_control == -1) {
|
||||
return -1;
|
||||
}
|
||||
if ($a->splits[$a_control]->getTimestamp() < $b->splits[$b_control]->getTimestamp()){
|
||||
return -1;
|
||||
}
|
||||
if ($a->splits[$a_control]->getTimestamp() > $b->splits[$b_control]->getTimestamp()){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
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");
|
||||
$csv_runners = str_getcsv($csv_runners, "\n");
|
||||
//print_r($csv_runners);
|
||||
for ($i = 1; $i < count($csv_runners); $i++) {
|
||||
$line = str_getcsv($csv_runners[$i]);
|
||||
array_push($runners, new Runner($line[0], $line[1], $line[2], $line[3]));
|
||||
}
|
||||
|
||||
|
||||
$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]-1, $time);
|
||||
}
|
||||
|
||||
function registration_table($runners) {
|
||||
$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>
|
||||
<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>");
|
||||
}
|
||||
|
||||
function participants_table($runners) {
|
||||
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>");
|
||||
}
|
||||
function liveresult_table($runners) {
|
||||
usort($runners, "cmp");
|
||||
usort($runners, "cmp_course");
|
||||
$kadaver_table = "<table><thead>
|
||||
<tr>
|
||||
<th>#</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>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Navn</th>
|
||||
<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++;
|
||||
$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');
|
||||
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++;
|
||||
}
|
||||
|
||||
if ($runner->course == "Kadaverløpet") {
|
||||
$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>". "" .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
|
||||
}
|
||||
}
|
||||
$kadaver_table .= "</tbody></table>";
|
||||
$minikadaver_table .= "</tbody></table>";
|
||||
echo($kadaver_table);
|
||||
|
||||
}
|
||||
|
||||
if (!isset($query)){
|
||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||
if ($query["type"] == "registrering"){
|
||||
registration_table($runners);
|
||||
}
|
||||
elseif ($query["type"] == "paameldte") {
|
||||
participants_table($runners);
|
||||
}
|
||||
elseif ($query["type"] == "liveresultater") {
|
||||
liveresult_table($runners);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?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);
|
||||
Reference in New Issue
Block a user