set json data to qr code , at_school is using id as key
This commit is contained in:
parent
ca11bae56c
commit
5505e23754
2 changed files with 49 additions and 19 deletions
|
@ -3,10 +3,40 @@
|
|||
<head>
|
||||
<script src="https://unpkg.com/html5-qrcode"></script>
|
||||
</head>
|
||||
<style>
|
||||
#reader {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#qr-reader {
|
||||
position: absolute;
|
||||
width:800px;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
#wave {
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
visibility: hidden;
|
||||
width:800px;
|
||||
height: 640px;
|
||||
background-color: #cccccc;
|
||||
background-image: url('wave.gif');
|
||||
background-repeat: no-repeat;
|
||||
background-size: auto;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
</style>
|
||||
<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>
|
||||
<div id="reader">
|
||||
<div id="qr-reader" ></div>
|
||||
<div id="wave"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
@ -21,7 +51,7 @@
|
|||
var at_school = JSON.parse(at_school_json);
|
||||
console.log(at_school);
|
||||
var result = "<ul>";
|
||||
for (var i = 0; i < at_school.length; i++) {
|
||||
for(var i in at_school){
|
||||
result += "<li>"+ at_school[i] + "</li>";
|
||||
}
|
||||
result += "</ul>";
|
||||
|
@ -29,14 +59,16 @@
|
|||
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();
|
||||
const card = JSON.parse(decodedText);
|
||||
var fullname = card.name+" "+card.surname;
|
||||
document.getElementById('qr-reader-results').textContent = fullname;
|
||||
//document.getElementById('qr-reader-results').textContent = decodedText;
|
||||
html5QrcodeScanner.pause();
|
||||
document.getElementById('wave').style.visibility = "visible";
|
||||
|
||||
var formData ={};
|
||||
formData.id=33;
|
||||
formData.name=decodedText;
|
||||
formData.id=card.id;
|
||||
formData.name=fullname;
|
||||
formData.direction=document.querySelector('input[name="entrance"]:checked').id;
|
||||
formData.main=true;
|
||||
console.log(JSON.stringify(formData));
|
||||
|
@ -46,12 +78,13 @@
|
|||
},
|
||||
body:JSON.stringify(formData)
|
||||
}).then(response => response.text())
|
||||
.then(data => document.querySelector("p.result").innerHTML = data);
|
||||
.then(data => document.getElementById('qr-reader-results').textContent = data);
|
||||
//.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);
|
||||
html5QrcodeScanner.resume();
|
||||
get_at_school();
|
||||
}, 4000);
|
||||
|
||||
|
@ -68,9 +101,7 @@
|
|||
</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>
|
||||
|
|
|
@ -29,17 +29,16 @@ $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;
|
||||
if( !isset($at_school[$pozadavek->id])) {
|
||||
$at_school[$pozadavek->id] = $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]);
|
||||
if( isset($at_school[$pozadavek->id])) {
|
||||
unset($at_school[$pozadavek->id]);
|
||||
} else {
|
||||
echo $pozadavek->name." není ve škole";
|
||||
return;
|
||||
|
@ -58,8 +57,8 @@ $pruchod = array(
|
|||
"CteckaId" => "CAM1",
|
||||
"Poznamka" => ""
|
||||
);
|
||||
$payload = json_encode($pruchod)."<br>";
|
||||
echo $payload;
|
||||
$payload = json_encode($pruchod);
|
||||
echo $pozadavek->name;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url.$cesta);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
|
Loading…
Reference in a new issue