La til epost knapp

This commit is contained in:
Trygve
2025-10-28 23:46:42 +01:00
parent 4cc7ff821c
commit fdddbbb0ef
8 changed files with 46 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ function write_ini_file($assoc_array, $path) {
}
$content .= "\n";
}
file_put_contents($path, $content);
file_put_contents($path, data: $content);
}
$config = parse_ini_file("$documentRoot/data/config.ini");
@@ -31,7 +31,8 @@ if ($method == "POST") {
$file = "$documentRoot/data/config.ini";
$config["start_date"] = $start_time . "+01";
write_ini_file($config, $file);
header("Location: $documentRoot/config_editor.html");
header("HX-Replace-Url: false");
echo("Starttida er oppdatert til: $start_time");
}
}
elseif ($method == "GET"){

25
api/email.php Normal file
View File

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

View File

@@ -23,6 +23,8 @@ if ($method == "POST") {
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 == "GET") {