<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
global $defaultHomeLink;
render('_header');
 ?>
<div data-role="page">
<a href="https://wtrbill.com/exhibit/logout.php">LOGOUT</a>
<h1><?php echo $_SESSION['email'];?></h1>
</div>
<div id="qr-reader" style="width:300px"></div>
<div id="qr-reader-results"></div>
<div id="scanner1"></div>
<script src="https://unpkg.com/html5-qrcode"></script>    
<script>
var resultContainer = document.getElementById('qr-reader-results');
var lastResult, countResults = 0;
function onScanSuccess(decodedText, decodedResult) {
    if (decodedText !== lastResult) {
        ++countResults;
        lastResult = decodedText;
        // Handle on success condition with the decoded message.
        console.log(`Scan result ${decodedText}`, decodedResult);
        rdecodedText = decodedText.substring(0,4);
        let http = new XMLHttpRequest();
         http.open('GET', 'https://wtrbill.com/exhibit/includes/getter.php?dtm=' + rdecodedText);
         http.send()
         http.onload = function(){
             console.log('done');
         }
        window.location.reload(); 
    }
}

var html5QrcodeScanner = new Html5QrcodeScanner(
    "qr-reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess);
</script>
<div>
<a href="https://wtrbill.com/exhibit/includes/downld.php">Please click here to download your saved contacts!</a>
</div>
<?php
render('_footer');
?>


