Compare commits

..

2 commits

Author SHA1 Message Date
Karel Košnar
a2c86b587b tools for generating cards 2024-12-02 18:05:26 +01:00
Karel Košnar
5505e23754 set json data to qr code , at_school is using id as key 2024-12-02 18:03:04 +01:00
4 changed files with 81 additions and 19 deletions

View file

@ -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>

View file

@ -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);

23
tools/get_employees.php Normal file
View file

@ -0,0 +1,23 @@
<?php
include '../src/osvobdoch_vars.php';
include '../src/osvobdoch_local_vars.php';
$metoda = "GET";
$cesta = "/api/dochazka/v2/pracovnici";
# 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;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$cesta);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $metoda);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"com.edookit.Time: ".$cas,
"com.edookit.Auth: ".$auth,
"com.edookit.Client: ".$id
));
$result = curl_exec($ch);
echo $result;
?>

9
tools/process.bash Executable file
View file

@ -0,0 +1,9 @@
!#/bin/bash
cat students.json | jq -c '.Zaci[]|{id: .PkZak, name: .Jmeno, surname: .Prijmeni }' | while read line; do
id=$(echo $line | jq -r '.id')
name=$(echo $line | jq -r '.name')
surname=$(echo $line | jq -r '.surname')
echo "Processing $name $surname "
qrencode -o "qrcodes/$id.png" $line
convert -size 1000x640 xc:white templates/background.png -geometry 500x460+0+200 -composite templates/logo.png -geometry 420x100+40+40 -composite -background transparent -fill black -size 420x240 -font templates/Quicksand-VariableFont_wght.ttf caption:"$name\n$surname" -geometry +40+220 -composite qrcodes/$id.png -geometry 420x420+540+140 -composite "cards/$name-$surname.png"
done