La til endring av databasen og sjekk av ridstreng
This commit is contained in:
parent
f2ede38dca
commit
5b62326c42
@ -48,14 +48,14 @@ 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_info" hx-swap="show:none">
|
||||
<form action="/api/runner.php" method="GET" hx-boost="true" hx-target="#runner" hx-swap="show:none">
|
||||
<label>
|
||||
Navn, startnummer eller klubb
|
||||
<input type="text" name="search" id="search">
|
||||
</label>
|
||||
<button type="submit">Søk</button>
|
||||
</form>
|
||||
<div id="runner_info" class="profile-card"></div>
|
||||
<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>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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("<span class='bg-danger'>Startnummer er allerede i bruk!</span>");
|
||||
} 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("<span class='bg-danger'>Startnummer er allerede i bruk!</span>");
|
||||
} else {
|
||||
$all_lines[$csv_line] = $line;
|
||||
file_put_contents("$documentRoot/data/db.csv",implode("",$all_lines));
|
||||
echo("<span class='bg-success'>Endret: $line</span>");
|
||||
}
|
||||
}
|
||||
|
||||
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 .= "
|
||||
<h2>Endre $r->id $r->name</h2>
|
||||
<form hx-patch='/api/runner.php'>
|
||||
<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>
|
||||
<label>
|
||||
<fieldset>
|
||||
<input type='radio' name='course' value='Kadaverløpet' checked='checked'>
|
||||
Kadaverløpet
|
||||
</label>
|
||||
<label>
|
||||
<input type='radio' name='course' value=\"Minikadaver'n\">
|
||||
Minikadaver'n
|
||||
</label>
|
||||
</fieldset>
|
||||
<label>epost<input type='text' id='email' name='email' value='$r->email'></label>
|
||||
<label>telefon<input type='text' id='phone' name='phone' value='$r->phone'></label>
|
||||
<label><input type='hidden' id='student' name='student' required value='$r->is_student'></label>
|
||||
<label><input type='hidden' id='line_in_csv' name='line_in_csv' required value='$r->line_in_csv'></label>
|
||||
<button type='submit'>Endre løper</button>
|
||||
</form>
|
||||
";
|
||||
header("HX-Replace-Url: false");
|
||||
echo($response);
|
||||
} elseif (count($filtered) == 1){
|
||||
$r = $filtered[0];
|
||||
$response .= "
|
||||
<h2> $r->name</h2>
|
||||
@ -50,7 +110,12 @@ if ($method == "GET") {
|
||||
|
||||
for ($i = 0; $i < count($filtered); $i++) {
|
||||
$runner = $filtered[$i];
|
||||
$response .= "<button class=\"default\" hx-get=\"/api/runner.php?search=$runner->id\" hx-target=\"#runner_info\" hx-swap=\"show:none\">$runner->id $runner->name</button>";
|
||||
if ($query['edit'] == "true") {
|
||||
$url = "/api/runner.php?search=$runner->id&edit=true";
|
||||
} else {
|
||||
$url = "/api/runner.php?search=$runner->id";
|
||||
}
|
||||
$response .= "<button class=\"default\" hx-get=\"$url\" hx-target=\"#runner\" hx-swap=\"show:none\">$runner->id $runner->name</button>";
|
||||
header("HX-Replace-Url: false");
|
||||
}
|
||||
echo($response);
|
||||
|
||||
@ -63,5 +63,15 @@
|
||||
|
||||
</script>
|
||||
<script src="/lib/htmx.min.js"></script>
|
||||
<script>
|
||||
document.body.addEventListener('htmx:beforeSwap', function(evt) {
|
||||
// Allow 422 and 400 responses to swap
|
||||
// We treat these as form validation errors
|
||||
if (evt.detail.xhr.status === 422 || evt.detail.xhr.status === 400) {
|
||||
evt.detail.shouldSwap = true;
|
||||
evt.detail.isError = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -54,6 +54,18 @@
|
||||
|
||||
<button type="submit">Legg til løper</button>
|
||||
</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">
|
||||
<input type="hidden" id="edit" name="edit" value="true">
|
||||
<label>
|
||||
Søk etter navn, startnummer eller klubb
|
||||
<input type="text" name="search" id="search">
|
||||
</label>
|
||||
<button type="submit">Søk</button>
|
||||
</form>
|
||||
<div id="runner"></div>
|
||||
|
||||
|
||||
</div>
|
||||
<div id="updated"></div>
|
||||
@ -76,5 +88,15 @@
|
||||
|
||||
</script>
|
||||
<script src="/lib/htmx.min.js"></script>
|
||||
<script>
|
||||
document.body.addEventListener('htmx:beforeSwap', function(evt) {
|
||||
// Allow 422 and 400 responses to swap
|
||||
// We treat these as form validation errors
|
||||
if (evt.detail.xhr.status === 422 || evt.detail.xhr.status === 400) {
|
||||
evt.detail.shouldSwap = true;
|
||||
evt.detail.isError = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -11,7 +11,7 @@ class Runner
|
||||
public string $is_student;
|
||||
public array $splits;
|
||||
|
||||
function __construct($id, $name, $club, $course, $email, $phone, $is_student)
|
||||
function __construct($id, $name, $club, $course, $email, $phone, $is_student, $line_in_csv)
|
||||
{
|
||||
if ($id == null) {
|
||||
$id = 0;
|
||||
@ -24,6 +24,7 @@ class Runner
|
||||
$this->email = $email;
|
||||
$this->phone = $phone;
|
||||
$this->is_student = $is_student;
|
||||
$this->line_in_csv = $line_in_csv;
|
||||
$this->splits = [false, false, false];
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ function read_runners_from_csv(){
|
||||
$csv_runners = str_getcsv($csv_runners, "\n");
|
||||
for ($i = 1; $i < count($csv_runners); $i++) {
|
||||
$line = str_getcsv($csv_runners[$i], ";");
|
||||
array_push($runners, new Runner($line[0], $line[2], $line[5], $line[6], $line[3], $line[4], $line[7]));
|
||||
array_push($runners, new Runner($line[0], $line[2], $line[5], $line[6], $line[3], $line[4], $line[7], $i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user