From 5b62326c42306d6be9dcca838cd5a3fea996bb3f Mon Sep 17 00:00:00 2001 From: Trygve Date: Thu, 30 Oct 2025 23:21:49 +0100 Subject: [PATCH] La til endring av databasen og sjekk av ridstreng --- admin.php | 4 +-- api/config.php | 9 ++++-- api/runner.php | 77 ++++++++++++++++++++++++++++++++++++++++++---- config_editor.html | 10 ++++++ db_editor.html | 22 +++++++++++++ import_runners.php | 5 +-- 6 files changed, 115 insertions(+), 12 deletions(-) diff --git a/admin.php b/admin.php index a9267af..7fcca5e 100644 --- a/admin.php +++ b/admin.php @@ -48,14 +48,14 @@ include("api/statistics.php"); ?>

Søk opp løper

-
+
-
+
diff --git a/api/config.php b/api/config.php index 059db30..6f8663e 100644 --- a/api/config.php +++ b/api/config.php @@ -24,10 +24,15 @@ if ($method == "POST") { $start_time = $_POST['start_time']; $password = $_POST['password']; + + $new_time = DateTime::createFromFormat(DateTime::ISO8601, $start_time. "+01"); if (!password_verify($password, $hash)) { http_response_code(response_code: 401); - } - else { + } elseif (!$new_time) { + http_response_code(response_code: 400); + echo("Feil datoformat din noldus!!!!!!!11!!! Skriv inn sekund"); + } else { + $file = "$documentRoot/data/config.ini"; $config["start_date"] = $start_time . "+01"; write_ini_file($config, $file); diff --git a/api/runner.php b/api/runner.php index a9819b5..0beaec1 100644 --- a/api/runner.php +++ b/api/runner.php @@ -21,18 +21,78 @@ if ($method == "POST") { http_response_code(response_code: 400); } else { - $file = "$documentRoot/data/db.csv"; - file_put_contents($file, $line, FILE_APPEND); - header("HX-Replace-Url: false"); - echo("Løper lagt til: $line"); + $runners = read_runners_from_csv(); + $filtered = search_for_runner($runners, $runner_id); + if ($filtered != []) { + http_response_code(response_code: 400); + echo("Startnummer er allerede i bruk!"); + } else { + $file = "$documentRoot/data/db.csv"; + file_put_contents($file, $line, FILE_APPEND); + header("HX-Replace-Url: false"); + echo("Løper lagt til: $line"); + } + + } } +if ($method == "PATCH") { + parse_str(file_get_contents('php://input'), $_PATCH); + $line = $_PATCH["id"] . ";;" . $_PATCH["name"] . ";" . $_PATCH["email"] . ";" . $_PATCH["phone"] . ";" . $_PATCH["club"] . ";" . $_PATCH["course"] . ";;;\n"; + + $all_lines = file("$documentRoot/data/db.csv"); + $csv_line = (int)$_PATCH["line_in_csv"]; + + $old_id = str_getcsv($all_lines[$csv_line], ";")[0]; + + $runners = read_runners_from_csv(); + $filtered = search_for_runner($runners, $_PATCH["id"]); + + if (!is_int($csv_line)){ + http_response_code(response_code: 400); + } elseif ($filtered != [] && $_PATCH["id"] != $old_id) { + http_response_code(response_code: 400); + echo("Startnummer er allerede i bruk!"); + } else { + $all_lines[$csv_line] = $line; + file_put_contents("$documentRoot/data/db.csv",implode("",$all_lines)); + echo("Endret: $line"); + } +} + if ($method == "GET") { parse_str($_SERVER['QUERY_STRING'], $query); $runners = read_runners_from_csv(); $filtered = search_for_runner($runners, $query['search']); - if (count($filtered) == 1){ + if (count($filtered) == 1 && $query['edit'] == "true") { + $r = $filtered[0]; + $response .= " +

Endre $r->id $r->name

+
+ + + +