<?php require 'controller/session.php'; ?>

<!DOCTYPE html>
<html lang="en-us">
	<head>
		<meta charset="utf-8">
		<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->

		<title> SIS </title>
		<meta name="description" content="">
		<meta name="author" content="">

		<!-- Use the correct meta names below for your web application
			 Ref: http://davidbcalhoun.com/2010/viewport-metatag 
			 
		<meta name="HandheldFriendly" content="True">
		<meta name="MobileOptimized" content="320">-->
		
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<!-- Basic Styles -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">	
		<link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.min.css">

		<!-- SmartAdmin Styles : Please note (smartadmin-production.css) was created using LESS variables -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.min.css">	
		
		<!-- SmartAdmin RTL Support is under construction-->
			<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.min.css"> 
		
		<!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/demo.min.css">

		<!-- page related CSS -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/lockscreen.min.css">

		<!-- FAVICONS -->
		<link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
		<link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

		<!-- GOOGLE FONT -->
		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700">


	</head>
	<body>

		<div id="main" role="main">

			<!-- MAIN CONTENT -->

			<form class="lockscreen animated flipInY" action="index.html" onsubmit="return false;">
				<div class="logo">
					<h1 class="semi-bold"><img src="img/logo-o.png" alt="" id="dp" /> SIS</h1>
				</div>
				<div>
					<img src="img/default.png" id="capture" alt="" width="120" height="120" />
					<div>
						<h1><i class="fa fa-3x text-muted air air-top-right hidden-mobile"></i>Log Book <small><i class="fa fa-pencil text-muted"></i> &nbsp;Key In </small></h1>
						<p class="text-muted">
							<span class="msg hidden hidden-mobile" style="color: #356635">Signed Successfully</span>
							<span class="err hidden hidden-mobile" style="color: #B8121D">Error Signing (Check Staff ID)</span>
							<span class="err2 hidden hidden-mobile" style="color: #B8121D">Internal Error!</span>

						</p>

						<div class="input-group">
							<input class="form-control" id="token" type="password" placeholder="Password">
							<div class="input-group-btn">
								<button class="btn btn-primary" type="submit" id="login_btn">
									<i class="fa fa-key"></i>
								</button>
							</div>
						</div>
						<p class="no-margin margin-top-5">
							Key In with Staff ID
						</p>
					</div>

				</div>
				<video id="player" controls autoplay class="hidden-mobile hidden"></video>
				<canvas id="canvas" class="hidden-mobile hidden"></canvas>
				<p class="font-xs margin-top-5">
					Copyright 2018.

				</p>
			</form>

		</div>

		<!--================================================== -->	

		<!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)-->
		<script src="js/plugin/pace/pace.min.js"></script>

	    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->
	    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
	    <script src="js/jquery-3.2.1.min.js"></script>
		<script> if (!window.jQuery) { document.write('<script src="js/libs/jquery-2.0.2.min.js"><\/script>');} </script>

	    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
		<script> if (!window.jQuery.ui) { document.write('<script src="js/libs/jquery-ui-1.10.3.min.js"><\/script>');} </script>

		<!-- JS TOUCH : include this plugin for mobile drag / drop touch events 		
		<script src="js/plugin/jquery-touch/jquery.ui.touch-punch.min.js"></script> -->

		<!-- BOOTSTRAP JS -->		
		<script src="js/bootstrap/bootstrap.min.js"></script>

		<!-- CUSTOM NOTIFICATION -->
		<script src="js/notification/SmartNotification.min.js"></script>

		<!-- JARVIS WIDGETS -->
		<script src="js/smartwidgets/jarvis.widget.min.js"></script>
		
		<!-- EASY PIE CHARTS -->
		<script src="js/plugin/easy-pie-chart/jquery.easy-pie-chart.min.js"></script>
		
		<!-- SPARKLINES -->
		<script src="js/plugin/sparkline/jquery.sparkline.min.js"></script>
		
		<!-- JQUERY VALIDATE -->
		<script src="js/plugin/jquery-validate/jquery.validate.min.js"></script>
		
		<!-- JQUERY MASKED INPUT -->
		<script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>
		
		<!-- JQUERY SELECT2 INPUT -->
		<script src="js/plugin/select2/select2.min.js"></script>

		<!-- JQUERY UI + Bootstrap Slider -->
		<script src="js/plugin/bootstrap-slider/bootstrap-slider.min.js"></script>
		
		<!-- browser msie issue fix -->
		<script src="js/plugin/msie-fix/jquery.mb.browser.min.js"></script>
		
		<!-- FastClick: For mobile devices -->
		<script src="js/plugin/fastclick/fastclick.min.js"></script>
		
		<!--[if IE 7]>
			
			<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>
			
		<![endif]-->
		
		<!-- MAIN APP JS FILE -->
		<script src="js/app.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
							 const player = document.getElementById('player');
  const canvas = document.getElementById('canvas');
  const context = canvas.getContext('2d');
  const captureButton = document.getElementById('login_btn');

  const constraints = {
    video: true,
  };

  // captureButton.addEventListener('click', () => {
    

    // Stop all video streams.
    // player.srcObject.getVideoTracks().forEach(track => track.stop());
  // });

  navigator.mediaDevices.getUserMedia(constraints)
    .then((stream) => {
      // Attach the video stream to the video element and autoplay.
      player.srcObject = stream;
    });
				$('#login_btn').click(function(){

					var token = $('#token').val();
					if($('#token').val()!==''){
			context.drawImage(player, 0, 0, canvas.width, canvas.height);
			//var image = canvas.toDataURL("image/png").replace("image/png","image/octet-stream");
			var image = canvas.toDataURL();
			// window.location.href = image;
			$.ajax({
				type:"POST",
				url:"controller/logbookCode.php?capture_user=",
				data:{
					imgBase64:image,
					token:token
				},
				success:function(response){
					
					if (response!=2&&response!=3) {
						$('.msg').removeClass('hidden');
					$('.msg').removeClass('hidden-mobile');
					$('.msg').html("Signed Successfully "+response);
					$('.err').addClass('hidden');
					$('.err').addClass('hidden-mobile');
					$('.err2').addClass('hidden');
					$('.err2').addClass('hidden-mobile');
					$('#token').val('');
					}else if(response==2){
						$('.err').removeClass('hidden');
					$('.err').removeClass('hidden-mobile');
						$('.msg').addClass('hidden');
					$('.msg').addClass('hidden-mobile');
					$('.err2').addClass('hidden');
					$('.err2').addClass('hidden-mobile');
					$('#token').val('');
					}else if(response==3){
						$('.err2').removeClass('hidden');
					$('.err2').removeClass('hidden-mobile');
					$('.err').addClass('hidden');
					$('.err').addClass('hidden-mobile');
						$('.msg').addClass('hidden');
					$('.msg').addClass('hidden-mobile');
					$('#token').val('');
					}

				}
			});
					}else{
						alert('Enter Staff Id');
					}
				});
			
			});
		</script>
	</body>
</html>