Lagde løpersøk
This commit is contained in:
parent
544517b3d8
commit
e6d76cd69c
20
admin.php
20
admin.php
@ -6,6 +6,15 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
|
||||
<link rel="stylesheet" href="matcha.css">
|
||||
<style>
|
||||
.profile-card{
|
||||
background-color: var(--bg-active);
|
||||
font-size: 1.4em;
|
||||
padding: 1rem;
|
||||
border-radius: var(--bd-radius);
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
@ -17,7 +26,15 @@
|
||||
</menu>
|
||||
</nav>
|
||||
<button class="danger" onclick="log_out()">Logg ut</button>
|
||||
|
||||
<h1>Søk opp løper</h1>
|
||||
<form action="/runner.php" method="GET" hx-boost="true" hx-target="#runner_info" hx-swap="show:none">
|
||||
<label>
|
||||
Navn eller startnummer
|
||||
<input type="text" name="search" id="search">
|
||||
</label>
|
||||
<button type="submit">Søk</button>
|
||||
</form>
|
||||
<div id="runner_info" class="profile-card"></div>
|
||||
<h1>Løpende resultater</h1>
|
||||
<?php
|
||||
include("table.php");
|
||||
@ -55,5 +72,6 @@ liveresult_table($runners);
|
||||
}
|
||||
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js" integrity="sha384-/TgkGk7p307TH7EXJDuUlgG3Ce1UVolAOFopFekQkkXihi5u/6OCvVKyz1W+idaz" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -7,9 +7,10 @@ class Runner
|
||||
public string $course;
|
||||
public string $email;
|
||||
public string $phone;
|
||||
public string $is_student;
|
||||
public array $splits;
|
||||
|
||||
function __construct($id, $name, $club, $course, $email, $phone)
|
||||
function __construct($id, $name, $club, $course, $email, $phone, $is_student)
|
||||
{
|
||||
if ($id == null) {
|
||||
$id = 0;
|
||||
@ -21,6 +22,7 @@ class Runner
|
||||
$this->course = $course;
|
||||
$this->email = $email;
|
||||
$this->phone = $phone;
|
||||
$this->is_student = $is_student;
|
||||
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
|
||||
$this->splits[$i] = false;
|
||||
}
|
||||
@ -53,6 +55,22 @@ function get_runner($runnner_list, int $id)
|
||||
return false;
|
||||
}
|
||||
|
||||
function search_for_runner($runner_list, $search_term) {
|
||||
$filtered_runners = [];
|
||||
for ($i = 0; $i < count($runner_list); $i++) {
|
||||
$runner = $runner_list[$i];
|
||||
if (str_contains(strtolower($runner->name), strtolower($search_term))){
|
||||
array_push($filtered_runners, $runner);
|
||||
}
|
||||
elseif (str_contains($runner->id, $search_term)){
|
||||
array_push($filtered_runners, $runner);
|
||||
}
|
||||
|
||||
}
|
||||
return $filtered_runners;
|
||||
}
|
||||
|
||||
|
||||
function cmp(Runner $a, Runner $b) {
|
||||
$a_control = $a->get_control();
|
||||
$b_control = $b->get_control();
|
||||
@ -99,7 +117,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]));
|
||||
array_push($runners, new Runner($line[0], $line[2], $line[5], $line[6], $line[3], $line[4], $line[7]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user