Compare commits
2 Commits
744f4db361
...
sql
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c037ee8c5 | ||
|
|
8d3b914433 |
4
import_csv.sql
Normal file
4
import_csv.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS løpere(id INTEGER PRIMARY KEY, navn TEXT);
|
||||||
|
.separator ,
|
||||||
|
.mode csv
|
||||||
|
.import db.csv QNH
|
||||||
18
index.php
18
index.php
@@ -27,7 +27,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
|
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
|
||||||
<?php
|
<?php
|
||||||
include("table.php")
|
include("table.php");
|
||||||
|
liveresult_table($runners);
|
||||||
?>
|
?>
|
||||||
<footer>
|
<footer>
|
||||||
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
|
<h3>Laget av Trygve. <a href="https://git.willy.club/Trygve/elektronisk-kadaver-tidtakingssystem">Kildekode</a></h3>
|
||||||
@@ -36,12 +37,15 @@ include("table.php")
|
|||||||
<script>
|
<script>
|
||||||
function update() {
|
function update() {
|
||||||
const table = document.querySelector("table");
|
const table = document.querySelector("table");
|
||||||
const myRequest = new Request(`table.php`);
|
const request = new XMLHttpRequest();
|
||||||
fetch(myRequest)
|
request.onreadystatechange = function() {
|
||||||
.then((response) => response.text())
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
.then((text) => {
|
table.innerHTML = this.responseText;
|
||||||
table.innerHTML = text;
|
localStorage.setItem("ETag", this.getResponseHeader("ETag"));
|
||||||
});
|
}};
|
||||||
|
request.open("GET", "table.php?type=liveresultater");
|
||||||
|
request.setRequestHeader("If-None-Match", localStorage.getItem("ETag"));
|
||||||
|
request.send();
|
||||||
}
|
}
|
||||||
setInterval(update, 5*1000)
|
setInterval(update, 5*1000)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
91
oppdater_db.php
Normal file
91
oppdater_db.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
function import_csv_to_sqlite(&$pdo, $csv_path, $options = array())
|
||||||
|
{
|
||||||
|
extract($options);
|
||||||
|
|
||||||
|
if (($csv_handle = fopen($csv_path, "r")) === FALSE)
|
||||||
|
throw new Exception('Cannot open CSV file');
|
||||||
|
|
||||||
|
if(!$delimiter)
|
||||||
|
$delimiter = ',';
|
||||||
|
|
||||||
|
if(!$table)
|
||||||
|
$table = preg_replace("/[^A-Z0-9]/i", '', basename($csv_path));
|
||||||
|
|
||||||
|
if(!$fields){
|
||||||
|
$fields = array_map(function ($field){
|
||||||
|
return strtolower(preg_replace("/[^A-Z0-9]/i", '', $field));
|
||||||
|
}, fgetcsv($csv_handle, 0, $delimiter));
|
||||||
|
}
|
||||||
|
|
||||||
|
$create_fields_str = join(', ', array_map(function ($field){
|
||||||
|
return "$field TEXT NULL";
|
||||||
|
}, $fields));
|
||||||
|
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
|
$create_table_sql = "CREATE TABLE IF NOT EXISTS $table ($create_fields_str)";
|
||||||
|
$pdo->exec($create_table_sql);
|
||||||
|
|
||||||
|
$insert_fields_str = join(', ', $fields);
|
||||||
|
$insert_values_str = join(', ', array_fill(0, count($fields), '?'));
|
||||||
|
$insert_sql = "INSERT INTO $table ($insert_fields_str) VALUES ($insert_values_str)";
|
||||||
|
$insert_sth = $pdo->prepare($insert_sql);
|
||||||
|
|
||||||
|
$inserted_rows = 0;
|
||||||
|
while (($data = fgetcsv($csv_handle, 0, $delimiter)) !== FALSE) {
|
||||||
|
$insert_sth->execute($data);
|
||||||
|
$inserted_rows++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdo->commit();
|
||||||
|
|
||||||
|
fclose($csv_handle);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'table' => $table,
|
||||||
|
'fields' => $fields,
|
||||||
|
'insert' => $insert_sth,
|
||||||
|
'inserted_rows' => $inserted_rows
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
import_csv_to_sqlite()
|
||||||
|
|
||||||
|
$password = $_POST['password'];
|
||||||
|
|
||||||
|
function send_response ($response, $code = 200) {
|
||||||
|
http_response_code($code);
|
||||||
|
die(json_encode($response));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($method === 'POST') {
|
||||||
|
if (!password_verify($password, $hash)) {
|
||||||
|
http_response_code(response_code: 401);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$file = 'passering.csv';
|
||||||
|
$current = file_get_contents($file);
|
||||||
|
$current .= $control . "," . $runner_id . "," . $time . "\n";
|
||||||
|
file_put_contents($file, $current);
|
||||||
|
}
|
||||||
|
if (empty($data['favorite'])) {
|
||||||
|
send_response([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Please provide a favorite movie.',
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
send_response([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Fila er lasta opp',
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
send_response([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Fila er lasta opp',
|
||||||
|
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
29
table.php
29
table.php
@@ -12,7 +12,7 @@ if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|||||||
// If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
|
// If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
|
||||||
// So send a 304 Not Modified response header and exit
|
// So send a 304 Not Modified response header and exit
|
||||||
if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
|
if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
|
||||||
header('HTTP/1.1 304 Not Modified', true, 304);
|
http_response_code(304);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,8 +27,6 @@ class Runner
|
|||||||
|
|
||||||
function __construct($id, $name, $club, $course)
|
function __construct($id, $name, $club, $course)
|
||||||
{
|
{
|
||||||
//echo($id);
|
|
||||||
//echo($name);
|
|
||||||
if ($id == null) {
|
if ($id == null) {
|
||||||
$id = 0;
|
$id = 0;
|
||||||
$name = "";
|
$name = "";
|
||||||
@@ -139,12 +137,7 @@ for ($i = 0; $i < count($timings); $i++) {
|
|||||||
$runner->set_split($line[0]-1, $time);
|
$runner->set_split($line[0]-1, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function registration_table($runners) {
|
||||||
if (!isset($query)){
|
|
||||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($query["type"] == "registrering"){
|
|
||||||
$matpost = $query["control"];
|
$matpost = $query["control"];
|
||||||
$runners_filtered = [];
|
$runners_filtered = [];
|
||||||
if ($query["filter"]) {
|
if ($query["filter"]) {
|
||||||
@@ -194,7 +187,8 @@ if ($query["type"] == "registrering"){
|
|||||||
}
|
}
|
||||||
echo("</tbody>");
|
echo("</tbody>");
|
||||||
}
|
}
|
||||||
elseif ($query["type"] == "paameldte") {
|
|
||||||
|
function participants_table($runners) {
|
||||||
usort($runners, "cmp_course");
|
usort($runners, "cmp_course");
|
||||||
|
|
||||||
$kadaverløpere = 0;
|
$kadaverløpere = 0;
|
||||||
@@ -226,7 +220,7 @@ elseif ($query["type"] == "paameldte") {
|
|||||||
}
|
}
|
||||||
echo("<table><tbody>");
|
echo("<table><tbody>");
|
||||||
}
|
}
|
||||||
else {
|
function liveresult_table($runners) {
|
||||||
usort($runners, "cmp");
|
usort($runners, "cmp");
|
||||||
usort($runners, "cmp_course");
|
usort($runners, "cmp_course");
|
||||||
$kadaver_table = "<table><thead>
|
$kadaver_table = "<table><thead>
|
||||||
@@ -292,3 +286,16 @@ else {
|
|||||||
echo($kadaver_table);
|
echo($kadaver_table);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($query)){
|
||||||
|
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||||
|
if ($query["type"] == "registrering"){
|
||||||
|
registration_table($runners);
|
||||||
|
}
|
||||||
|
elseif ($query["type"] == "paameldte") {
|
||||||
|
participants_table($runners);
|
||||||
|
}
|
||||||
|
elseif ($query["type"] == "liveresultater") {
|
||||||
|
liveresult_table($runners);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user