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

if(isset($btn))
{
$q1=mysql_query("select * from register where pinno='$pinno'");
$n1=mysql_num_rows($q1);
	if($n1==1)
	{
	$r1=mysql_fetch_array($q1);
	$_SESSION['un']=$r1['account'];
	$account=$r1['account'];
	$id=$r1['id'];
	$email=$r1['email'];
	$ff="Q".$id.".jpg";
						$st1=substr($account,0,4);
						$st2=rand(1000,9999);
						$data=$st1.$st2;
						mysql_query("update register set qrcode='".$data."',status=1 where account='".$account."'");
					//$qrUrl = "http://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=L|1&chl=$data";
					$qrUrl="http://api.qrserver.com/v1/create-qr-code/?data=$data&size=100x100";
					$qr     = file_get_contents($qrUrl,true);
					$img  = imagecreatefromstring($qr);
					
					$a=imagejpeg($img,"upload/$ff",100);

						require_once("email.php");	

						$objEmail	=	new CI_Email();
								$objEmail->from('account@gmail.com', "QR Information");
								$objEmail->to("$email");
							
								//$objEmail->cc($txt_cc);
								//$objEmail->bcc($txt_bcc);
								$objEmail->subject("QR Information");
								$objEmail->message("You have received QR Image, Account:$account");
								//send mail
									if(file_exists("upload/$ff"))
									{
										$objEmail->attach("upload/$ff");
									}
									if ($objEmail->send())
									{	
									//echo "sent";
									}
									else
									{	
									//echo "not";
									}
									
	header("location:user_verify.php");
	}
	else
	{
	$msg="Pin No. is wrong!!";
	}
}

$arr_num=array(1,2,3,4,5,6,7,8,9,0);
//$arr_num=array_rand($arr,10);
//print_r($arr_num);
?>
<!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>
  <table width="71%" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#9AA1B3">
    <tr>
      <th width="62%" rowspan="2" scope="col"><img src="images/ATM-Machine.jpg" width="373" height="483" /></th>
      <th width="38%" scope="col">Enter Your PIN </th>
    </tr>
    <tr>
      <th valign="top" scope="col"><table width="293" height="341" border="1">
        <tr>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[0]; ?>')"><?php echo $arr_num[0]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[1]; ?>')"><?php echo $arr_num[1]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[2]; ?>')"><?php echo $arr_num[2]; ?></a></td>
        </tr>
        <tr>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[3]; ?>')"><?php echo $arr_num[3]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[4]; ?>')"><?php echo $arr_num[4]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[5]; ?>')"><?php echo $arr_num[5]; ?></a></td>
        </tr>
        <tr>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[6]; ?>')"><?php echo $arr_num[6]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[7]; ?>')"><?php echo $arr_num[7]; ?></a></td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[8]; ?>')"><?php echo $arr_num[8]; ?></a></td>
        </tr>
        <tr>
          <td scope="col">&nbsp;</td>
          <td align="center" class="butt" scope="col"><a href="javascript:getPin('<?php echo $arr_num[9]; ?>')"><?php echo $arr_num[9]; ?></a></td>
          <td scope="col">&nbsp;</td>
        </tr>
      </table></th>
    </tr>
  </table>
  
  <p align="center">
    <input name="pinno" type="password" readonly="" />
    <input type="submit" name="btn" value="Click here >>" onclick="return validate()" />
  </p>
  <p align="center"><?php
 echo $msg;
  ?></p>
  <p>&nbsp;</p>
  <p align="center" class="sd"><?php include("title.php"); ?></p>
</form>
</body>
</html>
