Lagde løpersøk
This commit is contained in:
33
runner.php
33
runner.php
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
include("import_runners.php");
|
||||
$hash = file_get_contents("data/hash.txt");
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
print_r($_POST);
|
||||
if ($method == "POST") {
|
||||
$runner_id = $_POST['id'];
|
||||
$name = $_POST['name'];
|
||||
@@ -22,5 +22,34 @@ if ($method == "POST") {
|
||||
file_put_contents($file, $line, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
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){
|
||||
$r = $filtered[0];
|
||||
$response .= "
|
||||
<h2> $r->name</h2>
|
||||
<p> Klubb: $r->club</p>
|
||||
<p> Løype: $r->course</p>
|
||||
<p> Epost: <a href=\"mailto:$r->email\">$r->email</a></p>
|
||||
<p> Mobilnummer: <a href=\"tel:$r->phone\">$r->phone</a></p>
|
||||
<p> Mobilnummer: <a href=\"tel:$r->phone\">$r->phone</a></p>
|
||||
<p> Student? $r->is_student</p>
|
||||
";
|
||||
header("HX-Replace-Url: false");
|
||||
echo($response);
|
||||
}
|
||||
elseif (count($filtered) > 1){
|
||||
$response = "";
|
||||
|
||||
for ($i = 0; $i < count($filtered); $i++) {
|
||||
$runner = $filtered[$i];
|
||||
$response .= "<button class=\"default\" hx-get=\"/runner.php?search=$runner->id\" hx-target=\"#runner_info\" hx-swap=\"show:none\">$runner->id $runner->name</button>";
|
||||
header("HX-Replace-Url: false");
|
||||
echo($response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user