initial commit with working version (for improvement)
This commit is contained in:
parent
438d738091
commit
4085cbb713
5 changed files with 181 additions and 0 deletions
76
src/index.html
Normal file
76
src/index.html
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="https://unpkg.com/html5-qrcode"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<H1>Osvobozená základní škola - Docházka</H1>
|
||||||
|
<H2>Ukaž svoji školní průkazku</H2>
|
||||||
|
<div id="qr-reader" style="width:800px; background-color: #cccccc;"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function get_at_school() {
|
||||||
|
fetch('veskole.php', {method: 'GET'})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => render_at_school(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function render_at_school(at_school_json) {
|
||||||
|
var at_school = JSON.parse(at_school_json);
|
||||||
|
console.log(at_school);
|
||||||
|
var result = "<ul>";
|
||||||
|
for (var i = 0; i < at_school.length; i++) {
|
||||||
|
result += "<li>"+ at_school[i] + "</li>";
|
||||||
|
}
|
||||||
|
result += "</ul>";
|
||||||
|
document.getElementById('at-school').innerHTML = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function onScanSuccess(decodedText, decodedResult) {
|
||||||
|
// const card = JSON.parse(decodedText);
|
||||||
|
// document.getElementById('qr-reader-results').textContent = card.salutation;
|
||||||
|
document.getElementById('qr-reader-results').textContent = decodedText;
|
||||||
|
html5QrcodeScanner.clear();
|
||||||
|
document.getElementById('wave').style.visibility = "visible";
|
||||||
|
var formData ={};
|
||||||
|
formData.id=33;
|
||||||
|
formData.name=decodedText;
|
||||||
|
formData.direction=document.querySelector('input[name="entrance"]:checked').id;
|
||||||
|
formData.main=true;
|
||||||
|
console.log(JSON.stringify(formData));
|
||||||
|
fetch('pruchod.php', { method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body:JSON.stringify(formData)
|
||||||
|
}).then(response => response.text())
|
||||||
|
.then(data => document.querySelector("p.result").innerHTML = data);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('qr-reader-results').textContent = "Načítám ...";
|
||||||
|
document.getElementById('wave').style.visibility = "hidden";
|
||||||
|
html5QrcodeScanner.render(onScanSuccess);
|
||||||
|
get_at_school();
|
||||||
|
}, 4000);
|
||||||
|
|
||||||
|
}
|
||||||
|
var html5QrcodeScanner = new Html5QrcodeScanner("qr-reader", { fps: 10, qrbox: 300, rememberLastUsedCamera: true });
|
||||||
|
html5QrcodeScanner.render(onScanSuccess);
|
||||||
|
get_at_school();
|
||||||
|
</script>
|
||||||
|
<label>
|
||||||
|
<input id="P" name="entrance" type="radio" checked="true">Příchod
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input id="O" name="entrance" type="radio">Odchod
|
||||||
|
</label>
|
||||||
|
<H3>Kdo jsi? </H3>
|
||||||
|
<p id="qr-reader-results">Načítám ...</p>
|
||||||
|
<p class="result"></p>
|
||||||
|
<H3>Kdo je ve škole</H3>
|
||||||
|
<p id="at-school">Načítám ...</p>
|
||||||
|
<img style = "visibility:hidden" id = "wave" src="giphy.webp"/>
|
||||||
|
</body>
|
||||||
|
</html>
|
6
src/osvobdoch_local_vars.php
Normal file
6
src/osvobdoch_local_vars.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
$apiuser = "";
|
||||||
|
$apiheslo = "";
|
||||||
|
$url = "https://skola.edookit.net";
|
||||||
|
?>
|
||||||
|
|
5
src/osvobdoch_vars.php
Normal file
5
src/osvobdoch_vars.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
$id = "OSVOBDOCH";
|
||||||
|
$key = "c64ad952351b5f9ae264e2320571adee0c4a2a5d";
|
||||||
|
?>
|
||||||
|
|
77
src/pruchod.php
Normal file
77
src/pruchod.php
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
include 'osvobdoch_vars.php';
|
||||||
|
include 'osvobdoch_local_vars.php';
|
||||||
|
|
||||||
|
$fileaccess = fileatime('at_school.txt');
|
||||||
|
//check if file is accessed today
|
||||||
|
if (date('Y-m-d', $fileaccess) != date('Y-m-d')) {
|
||||||
|
$at_school = array();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$at_school = include 'at_school.txt';
|
||||||
|
}
|
||||||
|
if (empty($at_school)) {
|
||||||
|
$at_school = array();
|
||||||
|
}
|
||||||
|
$metoda = "POST";
|
||||||
|
$cesta = "/api/dochazka/v2/pruchody";
|
||||||
|
# cas "2016-09-30 11:54:12.637";
|
||||||
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
$cas= date("Y-m-d H:i:s");
|
||||||
|
$data = $metoda ."+".$cesta . "+" . $cas . "+" . $apiheslo;
|
||||||
|
$hash = hash_hmac("sha1", $data, $key, $raw_output=false);
|
||||||
|
$auth = $apiuser . ":" . $hash;
|
||||||
|
//echo $url.$cesta."\n";
|
||||||
|
//echo $cas."\n";
|
||||||
|
|
||||||
|
$postdata = file_get_contents("php://input");
|
||||||
|
$pozadavek = json_decode($postdata);
|
||||||
|
//check if student is already at school
|
||||||
|
//if not, add him to the list
|
||||||
|
if ($pozadavek->direction == "P") {
|
||||||
|
if( !in_array($pozadavek->name, $at_school)) {
|
||||||
|
$at_school[] = $pozadavek->name;
|
||||||
|
} else {
|
||||||
|
echo $pozadavek->name." už je ve škole";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if student is already at school, remove him from the list
|
||||||
|
if( in_array($pozadavek->name, $at_school)) {
|
||||||
|
$key = array_search($pozadavek->name, $at_school);
|
||||||
|
unset($at_school[$key]);
|
||||||
|
} else {
|
||||||
|
echo $pozadavek->name." není ve škole";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$pruchod = array(
|
||||||
|
"PkUzivatel" => $pozadavek->id,
|
||||||
|
"TypUzivatele" => "P",
|
||||||
|
"Datum" => date("Y-m-d"),
|
||||||
|
"Cas" => date("H:i:s"),
|
||||||
|
"Smer" => $pozadavek->direction,
|
||||||
|
"Hlavni" => $pozadavek->main,
|
||||||
|
"BranaId" => "ENTRANCE",
|
||||||
|
"CteckaId" => "CAM1",
|
||||||
|
"Poznamka" => ""
|
||||||
|
);
|
||||||
|
$payload = json_encode($pruchod)."<br>";
|
||||||
|
echo $payload;
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url.$cesta);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
|
"com.edookit.Time: ".$cas,
|
||||||
|
"com.edookit.Auth: ".$auth,
|
||||||
|
"com.edookit.Client: ".$id,
|
||||||
|
"Content-Type: application/json"
|
||||||
|
));
|
||||||
|
/*curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
echo $result;*/
|
||||||
|
file_put_contents('at_school.txt', '<?php return ' . var_export($at_school, true) . ';');
|
||||||
|
?>
|
17
src/veskole.php
Normal file
17
src/veskole.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
include 'osvobdoch_vars.php';
|
||||||
|
include 'osvobdoch_local_vars.php';
|
||||||
|
|
||||||
|
$fileaccess = fileatime('at_school.txt');
|
||||||
|
//check if file is accessed today
|
||||||
|
if (date('Y-m-d', $fileaccess) != date('Y-m-d')) {
|
||||||
|
$at_school = array();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$at_school = include 'at_school.txt';
|
||||||
|
}
|
||||||
|
if (empty($at_school)) {
|
||||||
|
$at_school = array();
|
||||||
|
}
|
||||||
|
echo JSON_encode($at_school);
|
||||||
|
?>
|
Loading…
Reference in a new issue