Compare commits

..

3 Commits

Author SHA1 Message Date
Trygve
6825e90568 Småfikser 2025-10-31 14:48:53 +01:00
Trygve
5f377cf811 Fiksa header pssord og la til minkadavertid 2025-10-31 11:59:38 +01:00
Trygve
2aff55b50d aaaaaaaa 2025-10-31 01:45:41 +01:00
13 changed files with 180 additions and 186 deletions

View File

@ -33,10 +33,10 @@
<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>
<li class="selected">⏳️ Nedtelling matpost
<li class="disabled">⏳️ Nedtelling matpost
<menu>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=1">2. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=1">2. mat</a></li>
</menu>
</li>
</menu>
@ -48,7 +48,7 @@ include("api/statistics.php");
?>
</div>
<h1>Søk opp løper</h1>
<form action="/api/runner.php" method="GET" hx-boost="true" hx-target="#runner" hx-swap="show:none">
<form action="/api/runner.php" method="GET" hx-boost="true" hx-target="#runner" hx-swap="show:none" hx-headers='js:{"Password": localStorage.getItem("passord")}'>
<label>
Navn, startnummer eller klubb
<input type="text" name="search" id="search">
@ -57,9 +57,9 @@ include("api/statistics.php");
</form>
<div id="runner" class="profile-card"></div>
<button hx-get="/api/email.php" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>hent alle eposter</button>
<button hx-get="/api/email.php?course=Kadaverløpet" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>Hent bare eposter for fullkadavern</button>
<button hx-get="/api/email.php?course=Minikadaver'n" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>Hent bare eposter for minikadaver'n</button>
<button hx-get="/api/email.php" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>hent alle eposter</button>
<button hx-get="/api/email.php?course=Kadaverløpet" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>Hent bare eposter for fullkadavern</button>
<button hx-get="/api/email.php?course=Minikadaver'n" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>Hent bare eposter for minikadaver'n</button>
<div class="flash default">
<output id="emails"></output>
</div>

View File

@ -18,12 +18,15 @@ function write_ini_file($assoc_array, $path) {
$config = parse_ini_file("$documentRoot/data/config.ini");
$hash = file_get_contents("$documentRoot/data/hash.txt");
include("$documentRoot/data/hash.php");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$start_time = $_POST['start_time'];
$start_time_mini = $_POST['mini_time'];
$password = $_POST['Password'];
$password = getallheaders()['Password'];
$password = $_POST['password'];
$new_time = DateTime::createFromFormat(DateTime::ISO8601, $start_time. "+01");
if (!password_verify($password, $hash)) {
@ -35,13 +38,30 @@ if ($method == "POST") {
$file = "$documentRoot/data/config.ini";
$config["start_date"] = $start_time . "+01";
$config["start_date_mini"] = $start_time_mini . "+01";
write_ini_file($config, $file);
header("HX-Replace-Url: false");
echo("Starttida er oppdatert til: $start_time");
echo("Starttida er oppdatert til: $start_time for Kadaver'n <br> $start_time_mini for Minikadaer'n");
}
}
elseif ($method == "GET"){
print($config["start_date"]);
$start_kadaver = explode("+", $config["start_date"])[0];
$start_mini = explode("+", $config["start_date_mini"])[0];
$response = "
<form action='/api/config.php' method='POST' hx-boost='true' hx-target='#updated' hx-swap='show:none' hx-headers='js:{\"Password\": localStorage.getItem(\"passord\")}'>
<label>
Starttid Kadaverløpet
<input type='datetime-local' id='start_time' name='start_time' step='1' value='$start_kadaver'>
</label>
<label>
Starttid Minikadaver'n
<input type='datetime-local' id='mini_time' name='mini_time' step='1' value='$start_mini'>
</label>
<button type='submit'>Oppdater</button>
</form>
<div id='updated'></div>
";
echo($response);
}

View File

@ -1,15 +1,15 @@
<?php
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
include("$documentRoot/import_runners.php");
$hash = file_get_contents("$documentRoot/data/hash.txt");
include("$documentRoot/data/hash.php");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "GET") {
parse_str($_SERVER['QUERY_STRING'], $query);
$course = $query['course'];
$password = getallheaders()['password'];
$password = getallheaders()['Password'];
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
}
} else {
$runners = read_runners_from_csv();
$emails = "";
for ($i = 0; $i < count($runners); $i++) {
@ -23,3 +23,4 @@ if ($method == "GET") {
}
echo($emails);
}
}

View File

@ -1,18 +1,17 @@
<?php
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
print_r($documentRoot);
$hash = file_get_contents("$documentRoot/data/hash.txt");
include("$documentRoot/data/hash.php");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$password = $_POST['password'];
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
}
else {
http_response_code(response_code: 200);
}
}
else {
}else {
http_response_code(response_code: 405);
}

View File

@ -6,7 +6,7 @@ $runner_id = $_POST['id'];
$time = $_POST['time'];
$password = $_POST['password'];
$hash = file_get_contents("$documentRoot/data/hash.txt");
include("$documentRoot/data/hash.php");
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);

View File

@ -3,7 +3,7 @@ $documentRoot = $_SERVER['DOCUMENT_ROOT'];
include("$documentRoot/import_runners.php");
$hash = file_get_contents("$documentRoot/data/hash.txt");
include("$documentRoot/data/hash.php");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$runner_id = $_POST['id'];
@ -37,6 +37,10 @@ if ($method == "POST") {
}
}
if ($method == "PATCH") {
$password = getallheaders()['Password'];
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
} else {
parse_str(file_get_contents('php://input'), $_PATCH);
$line = $_PATCH["id"] . ";;" . $_PATCH["name"] . ";" . $_PATCH["email"] . ";" . $_PATCH["phone"] . ";" . $_PATCH["club"] . ";" . $_PATCH["course"] . ";;;\n";
@ -59,17 +63,25 @@ if ($method == "PATCH") {
echo("<span class='bg-success'>Endret: $line</span>");
}
}
}
if ($method == "GET") {
$password = getallheaders()['Password'];
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
} else {
parse_str($_SERVER['QUERY_STRING'], $query);
$runners = read_runners_from_csv();
$filtered = search_for_runner($runners, $query['search']);
if (isset($query['get'])) {
$filtered = [get_runner($runners,$query['get'])];
}
if (count($filtered) == 1 && $query['edit'] == "true") {
$r = $filtered[0];
$response .= "
<h2>Endre $r->id $r->name</h2>
<form hx-patch='/api/runner.php'>
<form hx-patch='/api/runner.php' hx-headers='js:{\"Password\": localStorage.getItem(\"passord\")}'>
<label>Startnummer<input type='number' id='id' name='id' required value='$r->id'></label>
<label>Navn<input type='text' id='name' name='name' required value='$r->name'></label>
<label>Forening<input type='text' id='club' name='club' required value='$r->club'></label>
@ -111,11 +123,11 @@ if ($method == "GET") {
for ($i = 0; $i < count($filtered); $i++) {
$runner = $filtered[$i];
if ($query['edit'] == "true") {
$url = "/api/runner.php?search=$runner->id&edit=true";
$url = "/api/runner.php?get=$runner->id&edit=true";
} else {
$url = "/api/runner.php?search=$runner->id";
$url = "/api/runner.php?get=$runner->id";
}
$response .= "<button class=\"default\" hx-get=\"$url\" hx-target=\"#runner\" hx-swap=\"show:none\">$runner->id $runner->name</button>";
$response .= "<button class=\"default\" hx-get=\"$url\" hx-target=\"#runner\" hx-swap=\"show:none\" hx-headers='js:{\"Password\": localStorage.getItem(\"passord\")}'>$runner->id $runner->name</button>";
header("HX-Replace-Url: false");
}
echo($response);
@ -123,5 +135,5 @@ if ($method == "GET") {
else{
echo("Ingen resultater...");
}
}
}

View File

@ -4,6 +4,7 @@ $documentRoot = $_SERVER['DOCUMENT_ROOT'];
$config = parse_ini_file("$documentRoot/data/config.ini");
date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, $config["start_date"]);
$GLOBALS['start_time_mini'] = DateTime::createFromFormat(DateTime::ISO8601, $config["start_date_mini"]);
$GLOBALS['number_of_controls'] = 3;
/*
// Caching
@ -165,7 +166,9 @@ function liveresult_table($runners) {
$matposter = "<td>$tid_1_mat</td><td>$tid_2_mat</td>";
}
if ($runner->course == "Kadaverløpet") {
$kadaver_table .= "<tr><td>". $kadaver_num .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td><td>$tid_etter</td>$sprekk</tr>\n";
$runner_number = $kadaver_num .".";
if ($runner->get_control() == -1){$runner_number = "";};
$kadaver_table .= "<tr><td>". $runner_number ."</td><td>$runner->name</td>$matposter<td>$tid_maal</td><td>$tid_etter</td>$sprekk</tr>\n";
}
}
$kadaver_table .= "</tbody></table>\n";
@ -174,8 +177,8 @@ function liveresult_table($runners) {
}
function minikadadvern_table($runners) {
usort($runners, "cmp");
usort($runners, "cmp_course");
//usort($runners, "cmp");
//usort($runners, "cmp_course");
$minikadaver_table = "<table><thead>
<tr>
<th>#</th>
@ -183,53 +186,18 @@ function minikadadvern_table($runners) {
<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 = "";
$sprekk = "<td></td>";
if ($runner->splits[2] != false) {
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
$tid_maal = $GLOBALS['start_time_mini']->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 = "";
//tid etter vinner
$tid_etter = "";
if ($runner->splits[2] != false && $kadaver_num > 0) {
$tid_etter = $runners[0]->splits[2]->diff($runner->splits[2])->format('%I:%S');
}
//sprekkindekss
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 {
if ($runner->course == "Minikadaver'n") {
$mini_num++;
}
if ($runner->course == "Kadaverløpet") {
$kadaver_table .= "<tr><td>". $kadaver_num .".</td><td>$runner->name</td>$matposter<td>$tid_maal</td><td>$tid_etter</td>$sprekk</tr>\n";
}
elseif ($runner->course == "Minikadaver'n") {
$minikadaver_table .= "<tr><td>". "" .".</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
$runner_number = $mini_num . ".";
if ($runner->get_control() != 2){$runner_number = "";};
$minikadaver_table .= "<tr><td>". "$runner_number" ."</td><td>$runner->name</td><td>$tid_maal</td></tr>\n";
}
}
$minikadaver_table .= "</tbody></table>";

View File

@ -19,26 +19,17 @@
<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>
<li class="selected">⏳️ Nedtelling matpost
<li class="disabled">⏳️ Nedtelling matpost
<menu>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=1">2. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=1">2. mat</a></li>
</menu>
</li>
</menu>
</nav>
<h2>Sett dato og tid startskuddet gikk:</h2>
<form action="/api/config.php" method="POST" hx-boost="true" hx-target="#updated" hx-swap="show:none">
<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 id="updated"></div>
</div>
<div hx-get="/api/config.php" hx-swap="outerHTML" hx-trigger="load"></div>
<script>
function log_out(){
localStorage.removeItem("navn");

View File

@ -19,16 +19,16 @@
<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>
<li class="selected">⏳️ Nedtelling matpost
<li class="disabled">⏳️ Nedtelling matpost
<menu>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=1">2. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=1">2. mat</a></li>
</menu>
</li>
</menu>
</nav>
<h2>Legg til løper</h2>
<form action="/api/runner.php" method="POST" hx-boost="true" hx-target="#updated" hx-swap="show:none">
<form action="/api/runner.php" method="POST" hx-boost="true" hx-target="#updated" hx-swap="show:none" hx-headers='js:{"Password": localStorage.getItem("passord")}'>
<input style="display: none;" type="text" id="password" name="password" required>
<label for="id">Startnummer:
@ -56,7 +56,7 @@
</form>
<div id="updated"></div>
<h2>Endre løper</h2>
<form action="/api/runner.php" method="GET" hx-boost="true" hx-target="#runner" hx-swap="show:none">
<form action="/api/runner.php" method="GET" hx-boost="true" hx-target="#runner" hx-swap="show:none" hx-headers='js:{"Password": localStorage.getItem("passord")}'>
<input type="hidden" id="edit" name="edit" value="true">
<label>
Søk etter navn, startnummer eller klubb

View File

@ -34,13 +34,17 @@ class Runner
}
function get_control(){
$control = -1;
for ($i = 0; $i < count($this->splits); $i++) {
if ($this->splits[$i] != false) {
$control++;
if ($this->splits[2] != false) {
return 2;
} elseif ($this->splits[1] != false) {
return 1;
}
elseif ($this->splits[0] != false) {
return 0;
}
else {
return -1;
}
return $control;
}
}

View File

@ -50,8 +50,8 @@
<li class="disabled"><a href="/config_editor.html">⚙️ Konfigurasjon</a></li>
<li class="selected">⏳️ Nedtelling matpost
<menu>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=1">2. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=1">2. mat</a></li>
</menu>
</li>
</menu>

View File

@ -20,7 +20,6 @@
<h1>Påmeldte Kadaverløpet 2025</h1>
</div>
<h2>Oppdatert 28.10.25</h2>
<div class="flash attention">Startnummer blir tildelt nærmere arrangementet. Prøver å oppdatere lista jevnlig. TBN</div>
<?php
$query = ["type"=>"paameldte"];
include("api/table.php");

View File

@ -53,10 +53,10 @@
<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>
<li class="selected">⏳️ Nedtelling matpost
<li class="disabled">⏳️ Nedtelling matpost
<menu>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="http://localhost:8000/matpost_nedtelling.php?matpost=1">2. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=0">1. mat</a></li>
<li><a href="/matpost_nedtelling.php?matpost=1">2. mat</a></li>
</menu>
</li>
</menu>