<?php session_start(); ?>


<script type="text/javascript">
const x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;
}
</script>


<html>
                
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Licaland QR Code</title>
        <!-- Tell the browser to be responsive to screen width -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script type="text/javascript" src="js/instascan.min.js"></script>
		<!-- DataTables -->
		<link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
		<link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
		<link rel="stylesheet" href="css/bootstrap.min.css">
    </head>
    
    <body style="background:#F5F5DC" onload="getLocation()">

        <nav class="navbar" style="background:#fff">
		  <div class="container-fluid">
			<div class="navbar-header">
			  <img src="database/logo.ico" class="navbar-brand" href="#"></img>
			  <a class="navbar-brand" href="#">LICALAND QR ATTENDANCE</a>
			</div>
		  </div>
		</nav>


        <p id="demo"></p>
        <div class="container">
            <i class="glyphicon glyphicon-user"></i> 
            <label>QR CODE LOGIN</label>
        </div>
        <div class="container">
            <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" class="form-horizontal" border-radius: 5px;padding:10px;background:#fff;" id="met">
                    <div class="form-group">
                    <br>
                    <input  name="usr_name" id="usr_id" placeholder="Enter Employee No" class="form-control" style="width:20em;">
                    </div>    
                <div class="form-group">
                    <input type="password" name="pcode_name" id="pcode_id" placeholder="Enter Password" class="form-control" style="width:20em;">
                </div>
                <div class="form-group">
                    <br>
                    <input type="submit" name="auth" value="Login" class="btn btn-primary submitBtn" style="width:20em; margin:0;" />
                </div>
            
            </form>
        </div>

        <?php
                        $server = "localhost";
                        $username="root";
                        $password="";
                        $dbname="qrcodedb";

    $conn = new mysqli($server,$username,$password,$dbname);

    if($conn->connect_error){
        die("Connection failed" .$conn->connect_error);
    }

    if(isset($_POST['pcode_name'])){
            
        $iusr =$_POST['usr_name'];
        $ipass =$_POST['pcode_name'];
        
        $sql ="SELECT * FROM qrlogin where empid='$iusr' and passcode='$ipass' and flag=1";
		$query=$conn->query($sql);

        if($query->num_rows==0){
            echo '<script>alert("Authentication problem: Either wrong credential or account is disabled");</script>';
        }else{
            while ($row = $query->fetch_assoc())
            { 
                $_SESSION['employeeid'] = $row['empid'];
                $_SESSION['mekus'] = 1;
                //echo '<script>window.location.replace("https://dtr.licagroup.net/main.php")</script>';
                echo '<script>window.location.replace("main.php")</script>';
			}
        }



    }



?>


    </body>
</html>
