<!DOCTYPE html>
<html>
<head>
<title>QR Scanner</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/@zxing/library@latest"></script>
<script src="https://kit.fontawesome.com/de23248495.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.grid-container{
display: grid;
grid-template-columns: auto 30%;
padding: 10px;
grid-gap: 10px;
}
.container{
width: 350px;}
</style>
</head>
<body>
<h1 id="title" style="font-size: 3vw;color: steelblue;" align="center"><img src="windsorLogo.png"/> <br>Scanning</h1>
<h5 id="scanAnimation" style="font-size: 2vw;color: gray;" align="center"></h5>
<div class="container">
<form action="javascript:send()">
<div class="form-group grid-container">
<input class="form-control" id="cid" placeholder="Enter Password"><button type="submit" class="btn btn-default" id="submitButton">Login</button>
<div class="form-group">
<br>
<a href="qrscanner3PasswordRecovery.html" >Forgot Password?</a>
<br>
<br>
<div id="linkGeneratorOptions" style='display:none'>
<a href='javascript:goToLinkGenerator()'>Make Zoom Link</a> | <a href='javascript:goToClass()'>To to Class</a>
</div>
</div>
</div>
</form>
</div>
<h2 id="status" style="font-size: 2vw;color: steelblue;" align="center"></h2>
<h3 id="student" style="font-size: 2vw;color: steelblue;" align="center"></h3>
<script>
var video = document.createElement('video');
var parameters = new URLSearchParams(window.location.search);
var classInfo = parameters.get('class');
var gClassInfo = parameters.get('gClass');
var crdID = "";
var timer = 0;
var initialTime = 0;
var dataReceived = true;
var textRead = "";
const codeReader = new ZXing.BrowserQRCodeReader();
repeat();
function repeat() {
if (timer % 5 == 0) {
document.getElementById("scanAnimation").innerHTML = ".";
}
if (timer % 5 == 1) {
document.getElementById("scanAnimation").innerHTML = ". .";
}
if (timer % 5 == 2) {
document.getElementById("scanAnimation").innerHTML = ". . .";
}
if (timer % 5 == 3) {
document.getElementById("scanAnimation").innerHTML = ". . . .";
}
if (timer % 5 == 4) {
document.getElementById("scanAnimation").innerHTML = ". . . . .";
}
if (initialTime > 1) {
document.getElementById("status").innerHTML = "";
document.getElementById("student").innerHTML = "";
}
timer++;
initialTime++;
codeReader.decodeFromVideoDevice(null, video, (result, err) => {
if (result) {
document.getElementById("status").innerHTML = "";
document.getElementById("student").innerHTML = "";
textRead = result.text;
try {
crdID = textRead ;
if (crdID == null) {
document.getElementById("status").innerHTML = "Card Invalid";
document.getElementById("student").innerHTML = "";
initialTime = 0;
} else {
if (dataReceived) {
dataReceived = !dataReceived;
sendDataToRegister();
}
document.getElementById("status").innerHTML = "Processing ID";
initialTime = -5;
}
} catch (err) {
document.getElementById("status").innerHTML = "";
document.getElementById("student").innerHTML = "";
initialTime = 0;
document.getElementById("status").innerHTML = "Card Invalid";
}
}
});
setTimeout(repeat, 1000);
}
function sendDataToRegister() {
jQuery.post('https://script.google.com/macros/s/AKfycbztDJpQpBTdJY_Cl_rJDmnJEKHKZnJzErNCWmjrmJdl_p4dBLle/exec', {
cardID: crdID,
class: classInfo,
email: '',
instruction: 'login'
}
).done(function (data) {
var dataAsArray=data.split(",");
if (dataAsArray[0]=== "Approved") {
initialTime = 0;
document.getElementById("status").innerHTML = "Approved";
document.getElementById("student").innerHTML = dataAsArray[1]+ ", " + dataAsArray[2];
redirect();
} else {
document.getElementById("status").innerHTML = "";
document.getElementById("student").innerHTML = "";
initialTime = 0;
document.getElementById("status").innerHTML = "Card Invalid";
dataReceived = true
document.getElementById("submitButton").disabled = false;
}
})
}
function redirect() {
if(crdID.substring(6,8).indexOf('te')!=-1&&gClassInfo.indexOf('zoom')==-1){
document.getElementById("linkGeneratorOptions").style.display= "block";}else{
if(gClassInfo.indexOf('zoom')==-1){
window.location.assign("https://meet.google.com/" + gClassInfo);
}
else{
window.location.assign(gClassInfo);
}
}
}
function send() {
crdID = document.getElementById("cid").value
document.getElementById("submitButton").disabled = true;
document.getElementById("status").innerHTML = "Processing ID";
initialTime = -5;
sendDataToRegister();
}
function goToLinkGenerator(){
window.location.assign("https://advancedfunctions.co/qrscanner81.html?class=" + classInfo);
}
function goToClass(){
window.location.assign("https://meet.google.com/" + gClassInfo);
}
</script>
</body>
</html>