<?php
session_start();
include("dbconnect.php");
extract($_REQUEST);
$msg="";

$account=$_SESSION['un'];

	if(isset($btn))
	{
	echo "select * from register where account='".$account."' && qrcode='".$qrcode."'";
		$qry=mysql_query("select * from register where account='".$account."' && qrcode='".$qrcode."'");
		$num=mysql_num_rows($qry);
			if($num==1)
			{
			$_SESSION['uname']=$account;
			header("location:userhome.php");
			}
			else
			{
			$msg="Wrong!";
			}
		
	}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php include("title.php"); ?></title>

<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function validate()
{
	if(document.form1.pinno.value=="")
	{
	alert("Enter your Pin No.");
	return false;
	}
	return true;
}
function getPin(id)
{
var a=id;
	if(document.form1.pinno.value.length>3)
	{
	alert("Your PIN was entered!!");
	}
	else
	{
	document.form1.pinno.value+=a;
	}
	
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  
  <div class="sd"><!--<a href="index.php">Home</a>-->
    <div align="center"><a href="index.php">Home</a><a href="login.php">Admin</a></div>
  </div>
  <p align="center" class="txt">Welcome to ATM </p>
  <h2 align="center">QR Image Verification</h2>
  <table width="397" border="0" align="center" cellpadding="5" cellspacing="0">
    <tr>
      <th colspan="2" align="center" scope="col"> <video autoplay></video>
          <button id="reset">Reset</button>
        <button id="stop" >Stop</button>
        <script src="QRCodePHP/build/qcode-decoder.min.js"></script>
          <script type="text/javascript">

  (function () {
    'use strict';

    var qr = new QCodeDecoder();

    if (!(qr.isCanvasSupported() && qr.hasGetUserMedia())) {
      alert('Your browser doesn\'t match the required specs.');
      throw new Error('Canvas and getUserMedia are required');
    }

    var video = document.querySelector('video');
    var reset = document.querySelector('#reset');
    var stop = document.querySelector('#stop');


    function resultHandler (err, result) {
      if (err)
        return console.log(err.message);
		 document.form1.qrcode.value=result;
      //alert(result);
	 
    }

    // prepare a canvas element that will receive
    // the image to decode, sets the callback for
    // the result and then prepares the
    // videoElement to send its source to the
    // decoder.

    qr.decodeFromCamera(video, resultHandler);


    // attach some event handlers to reset and
    // stop whenever we want.

    reset.onclick = function () {
      qr.decodeFromCamera(video, resultHandler);
    };

    stop.onclick = function () {
      qr.stop();
    };

  })();
                              </script></th>
    </tr>
    <tr>
      <th align="left" scope="col">&nbsp;</th>
      <th align="left" scope="col"><input type="text" name="qrcode" /></th>
    </tr>
    <tr>
      <td align="left">&nbsp;</td>
      <td align="left"><input type="submit" name="btn" value="Submit" /></td>
    </tr>
    <tr>
      <td align="left">&nbsp;</td>
      <td align="left">&nbsp;</td>
    </tr>
  </table>
  <p align="center" class="msg"><?php echo $msg; ?></p>
  <p align="center" class="sd"><?php include("title.php"); ?></p>
</form>
</body>
</html>
