Lagde config fil og side for å endre starttidspunkt

This commit is contained in:
Trygve 2025-10-27 15:18:24 +01:00
parent cfd95bea41
commit 88dda157b5
9 changed files with 111 additions and 12 deletions

View File

@ -13,6 +13,7 @@
<li class="selected"><a href="/admin.php">📊 Dashbord</a></li>
<li class="disabled"><a href="/registrering.php">⏱️ Registrer passering matpost/mål</a></li>
<li class="disabled"><a href="/db_editor.html">👥 Endre løperbase</a></li>
<li class="disabled"><a href="/config_editor.html">⚙️ Konfigurasjon</a></li>
</menu>
</nav>
<button class="danger" onclick="log_out()">Logg ut</button>

41
config.php Normal file
View File

@ -0,0 +1,41 @@
<?php
function write_ini_file($assoc_array, $path) {
$content = "";
foreach ($assoc_array as $section => $values) {
if (is_array($values)) {
$content .= "[$section]\n";
foreach ($values as $key => $val) {
$content .= "$key = \"$val\"\n";
}
} else {
$content .= "$section = \"$values\"\n";
}
$content .= "\n";
}
file_put_contents($path, $content);
}
$config = parse_ini_file("data/config.ini");
$hash = file_get_contents("data/hash.txt");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$start_time = $_POST['start_time'];
$password = $_POST['password'];
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
}
else {
$file = 'data/config.ini';
$config["start_date"] = $start_time . "+01";
write_ini_file($config, $file);
header('Location: config_editor.html');
}
}
elseif ($method == "GET"){
print($config["start_date"]);
}

55
config_editor.html Normal file
View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="UTF-8" />
<title>EKT</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
<link rel="stylesheet" href="matcha.css">
</head>
<body>
<nav>
<menu>
<li class="disabled"><a href="/admin.php">📊 Dashbord</a></li>
<li class="disabled"><a href="/registrering.php">⏱️ Registrer passering på matpost/mål</a></li>
<li class="disabled"><a href="/db_editor.html">👥 Endre løperbase</a></li>
<li class="selected"><a href="/config_editor.html">⚙️ Konfigurasjon</a></li>
</menu>
</nav>
<h2>Sett dato og tid startskuddet gikk:</h2>
<form action="/config.php" method="POST">
<input style="display: none;" type="text" id="password" name="password" required>
<label>
Dato og tid
<input type="datetime-local" id="start_time" name="start_time" step="1">
</label>
<button type="submit">Oppdater</button>
</form>
</div>
<script>
function log_out(){
localStorage.removeItem("navn");
localStorage.removeItem("passord");
window.location.href = "/login.html";
}
// Sjekk om brukeren er logga inn. hvis ikke hiv de ut til innloggingskjermen
let xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("POST", "/is_authorized.php", false);
xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
xmlHttpReq.send("username=" + localStorage.getItem("navn")+"&"+"password=" + localStorage.getItem("passord"));
if (xmlHttpReq.status != 200){
window.location.href = "/login.html";
}
document.getElementById('password').value = localStorage.getItem("passord");
xmlHttpReq.open("GET", "/config.php", false);
xmlHttpReq.send();
document.getElementById('start_time').value = xmlHttpReq.response.split('+')[0]
console.log(xmlHttpReq.response)
</script>
</body>
</html>

View File

@ -13,11 +13,11 @@
<li class="disabled"><a href="/admin.php">📊 Dashbord</a></li>
<li class="disabled"><a href="/registrering.php">⏱️ Registrer passering på matpost/mål</a></li>
<li class="selected"><a href="/db_editor.html">👥 Endre løperbase</a></li>
<li class="disabled"><a href="/config_editor.html">⚙️ Konfigurasjon</a></li>
</menu>
</nav>
<h2>Legg til løper</h2>
<form action="/runner.php" method="POST">
<input style="display: none;" type="text" id="password" name="password" required>
<label for="id">Startnummer:
@ -41,7 +41,7 @@
</label>
</fieldset>
<button type="submit">Submit</button>
<button type="submit">Legg til løper</button>
</form>
</div>

View File

@ -1,5 +1,5 @@
<?php
$hash = file_get_contents("hash.txt");
$hash = file_get_contents("data/hash.txt");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$password = $_POST['password'];

View File

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

View File

@ -43,6 +43,7 @@
<li class="disabled"><a href="/admin.php">📊 Dashbord</a></li>
<li class="selected"><a href="/registrering.php">⏱️ Registrer passering matpost/mål</a></li>
<li class="disabled"><a href="/db_editor.html">👥 Endre løperbase</a></li>
<li class="disabled"><a href="/config_editor.html">⚙️ Konfigurasjon</a></li>
</menu>
</nav>
<fieldset>

View File

@ -1,5 +1,5 @@
<?php
$hash = file_get_contents("hash.txt");
$hash = file_get_contents("data/hash.txt");
$method = $_SERVER['REQUEST_METHOD'];
print_r($_POST);
if ($method == "POST") {
@ -18,7 +18,7 @@ if ($method == "POST") {
http_response_code(response_code: 400);
}
else {
$file = 'db.csv';
$file = 'data/db.csv';
file_put_contents($file, $line, FILE_APPEND);
}
}

View File

@ -1,11 +1,12 @@
<?php
$config = parse_ini_file("data/config.ini");
date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2026-10-26T08:53:00+01");
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, $config["start_date"]);
$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("Last-Modified: " . date("F d Y H:i:s.", filemtime("data/passering.csv")));
$etag = '"' . md5_file("data/passering.csv"). '"';
header(header: 'ETag: ' . $etag );
if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
@ -108,7 +109,7 @@ function time_diff(DateTime $date_1, DateTime $date_2) {
}
$runners = [];
$csv_runners = file_get_contents("db.csv");
$csv_runners = file_get_contents("data/db.csv");
$csv_runners = str_getcsv($csv_runners, "\n");
for ($i = 1; $i < count($csv_runners); $i++) {
$line = str_getcsv($csv_runners[$i], ";");
@ -116,7 +117,7 @@ for ($i = 1; $i < count($csv_runners); $i++) {
}
$timings = file_get_contents("passering.csv");
$timings = file_get_contents("data/passering.csv");
$timings = str_getcsv($timings, "\n");
for ($i = 0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);