<?php session_start();?>
<?php
include('libs/phpqrcode/qrlib.php'); 

function getUsernameFromEmail($email) {
	$find = '@';
	$pos = strpos($email, $find);
	$username = substr($email, 0, $pos);
	return $username;
}

if(isset($_POST['submit']) ) {
	$tempDir = 'temp/'; 

	$filename = $_POST['msg'];
	$body =  $_POST['msg'];
	$neym =  $_POST['nem'];
	// $codeContents = 'mailto:'.$email.'?subject='.urlencode($subject).'&body='.urlencode($body); 
	$codeContents = $body . ':' . $neym;
	QRcode::png($codeContents, $tempDir.''.$filename.'.png', QR_ECLEVEL_L, 5);
}
?>


<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">
		<style>
		#divvideo{
			 box-shadow: 0px 0px 1px 1px rgba(0, 0, 0, 0.1);
		}
		</style>
    </head>
    <body style="background:#F5F5DC">
        <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>
			<ul class="nav navbar-nav">
			  <li class="active"><a href="main.php"><span class="glyphicon glyphicon-time"></span> Home</a></li>
			  <li><a href="attendance.php"><span class="glyphicon glyphicon-cog"></span> Attendance </a></li>
              <li><a href="qr.php"><span class="glyphicon glyphicon-qrcode"></span> Generate QR </a></li>
			  <li><a href="exportui.php"><span class="glyphicon glyphicon-export"></span> Export </a></li>
			  <!--<li><a href="export.php"><span class="glyphicon glyphicon-align-justify"></span> Reports</a></li>-->
			</ul>
		  </div>
		</nav>
       <div class="container">
            <div class="row">
                <div class="col-md-12">
					<?php
					if(isset($_SESSION['error'])){
					  echo "
						<div class='alert alert-danger alert-dismissible' style='background:red;color:#fff'>
						  <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
						  <h4><i class='icon fa fa-warning'></i> Error!</h4>
						  ".$_SESSION['error']."
						</div>
					  ";
					  unset($_SESSION['error']);
					}
					if(isset($_SESSION['success'])){
					  echo "
						<div class='alert alert-success alert-dismissible' style='background:green;color:#fff'>
						  <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
						  <h4><i class='icon fa fa-check'></i> Success!</h4>
						  ".$_SESSION['success']."
						</div>
					  ";
					  unset($_SESSION['success']);
					}
				  ?>

                </div>
				
                <div class="col-md-12">
				    <div style="border-radius: 5px;padding:10px;background:#fff;" id="divvideo">
                    <h4>LICA (QR) Code Generator</h4>
			        <div class="input-field">
				            <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" >
					            <div class="form-group">
						            <label>Employee Number</label>
						            <input type="text" class="form-control" name="msg" style="width:20em;" value="" required pattern="[a-zA-Z0-9 .]+" placeholder="Enter your employee number"></textarea>
									<label>Employee Name</label>
									<input type="text" class="form-control" name="nem" style="width:20em;" value="" required pattern="[a-zA-Z0-9 .]+" placeholder="Enter your employee name"></textarea>
					            </div>
					                <div class="form-group">
						            <input type="submit" name="submit" class="btn btn-primary submitBtn" style="width:20em; margin:0;" />
					            </div>
                                </div>
					                <div class="form-group">
						            <label>QR Code Result</label>
                                    <div class="qrframe" style="border:2px solid black; width:210px; height:210px;">
							            <?php echo '<img src="temp/'. @$filename.'.png" style="width:200px; height:200px;"><br>'; ?>
					                </div>
                                    <a class="btn btn-primary submitBtn" style="width:210px; margin:5px 0;" href="download.php?file=<?php echo $filename; ?>.png ">Download QR Code</a>
					            </div>

				            </form>
			        </div>	
                   
                    </div>
                </div>
						
        </div>



		<script>
			function Export()
			{
				var conf = confirm("Please confirm if you wish to proceed in exporting the attendance in to Excel File");
				if(conf == true)
				{
					window.open("export.php",'_blank');
				}
			}
		</script>				
    
		<script src="plugins/jquery/jquery.min.js"></script>
		<script src="plugins/bootstrap/js/bootstrap.min.js"></script>
		<script src="plugins/datatables/jquery.dataTables.min.js"></script>
		<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
		<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
		<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>

		<script>
		  $(function () {
			$("#example1").DataTable({
			  "responsive": true,
			  "autoWidth": false,
			});
			$('#example2').DataTable({
			  "paging": true,
			  "lengthChange": false,
			  "searching": false,
			  "ordering": true,
			  "info": true,
			  "autoWidth": false,
			  "responsive": true,
			});
		  });
		</script>
		
    </body>
</html>