<?php
date_default_timezone_set('Asia/Kolkata'); 
$date = date("Y-m-d", time());
include ('../config.php');
@session_start();
@$user_id1=$_SESSION['user_id1'];
@$idvfied1=$_SESSION['idverified1'];
@$namevfied1=$_SESSION['namevfied1'];
if(!isset($_SESSION['user_id1'])){
	header("Location: index.php");
}

$timeout = 60 * 60 * 24 * 365;
$s_name = session_name();
if(isset( $_COOKIE[ $s_name ] )) {
  setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
}

$sel1=mysqli_query($conn,"select * from hr_dump where empid='".@$user_id1."'");
$fetch1=mysqli_fetch_array($sel1);

$queryFR=mysqli_query($conn,"select * from tracker where Functional_Reporting='$fetch1[Employee_Number]'");
$dataFR=mysqli_fetch_array($queryFR);

$queryFR=mysqli_query($conn,"select * from emp_leave where Functional_Reporting='$fetch1[Employee_Number]'");
$dataFR=mysqli_fetch_array($queryFR);
?>

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>Mark Your Attendance</title>
	
	<?php	include ('header.php');	?>
	<script src="../assets/js/webcam.min.js"></script>
	
	<div id="appCapsule">
        <div class="section wallet-card-section pt-1">
            <div class="wallet-card">
			
			<!--<div class="balance">
                    <div class="left">
                        <span class="title"></?php echo $fetch1['Employee_Full_Name']; ?></span>
                        <h4></?php echo $fetch1['Team_Name']; ?></h4>
                        <h6></?php echo $date = date("Y-m-d", time()); ?></h6>
                    </div>
                    <div class="right">
                        <a href="#"><img src="../assets/img/noimage.png" alt="logo" class="logo-profile"></a>
                    </div>
                </div>-->
				
				<?php	include ('include/wallet-balance.php');	?>
			
<!--<div class="wallet-footer">-->
<div class="">
<?php
//echo 'Server IP - '.$_SERVER['REMOTE_ADDR'];
function getUserIpAddr(){
  if(!empty($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
  }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  }else{
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  return $ip;
}
$getUserIpAddr = getUserIpAddr();

//echo '<br>User Device IP - '.getUserIpAddr();

$arr_browsers = ["Opera", "Edg", "Chrome", "Safari", "Firefox", "MSIE", "Trident"];
$agent = $_SERVER['HTTP_USER_AGENT'];
$user_browser = '';
foreach ($arr_browsers as $browser) {
  if (strpos($agent, $browser) !== false) {
    $user_browser = $browser;
    break;
  }  
}
switch ($user_browser) {
  case 'MSIE':
    $user_browser = 'Internet Explorer';
    break;
  case 'Trident':
    $user_browser = 'Internet Explorer';
    break;
  case 'Edg':
    $user_browser = 'Microsoft Edge';
    break;
}
//echo "<br>You are using ".$user_browser." browser";

?>
<?php
$isMob = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "mobile")); 
$isTab = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "tablet")); 
$isWin = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "windows")); 
$isAndroid = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "android")); 
$isIPhone = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "iphone")); 
$isIPad = is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "ipad")); 
$isIOS = $isIPhone || $isIPad; 

if($isIOS){
    $user_device = 'IOS';
}elseif($isAndroid){
    $user_device = 'ANDROID';
}elseif($isWin){
    $user_device = 'WINDOWS';
}

//echo "<br>You are using : ".$user_device." device";
?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if (isset($_POST['submit']))
{
	$camera_status = $_POST['camera_status'];		
	$querylog=mysqli_query($conn,"insert into tracker_log (user_IP, user_browser, user_device, empid, Employee_Full_Name, cityID, location, lat, longt)
	values ('".$_POST['user_IP']."', '".$_POST['user_browser']."', '".$_POST['user_device']."', '".$_POST['empid']."', '".$_POST['Employee_Full_Name']."', '".$_POST['cityID']."', '".$_POST['location']."', '".$_POST['lat']."', '".$_POST['longt']."') ");
	
	$lat1= $_POST['latitude'];
	$lon1= $_POST['longitude'];
	$lat2= $_POST['lat'];
	$lon2= $_POST['longt'];

	$distance = "Selfie";
	
	$OfficeDate = date("Y-m-d", time());
	$OfficeIn = date("H:i:s", time());
		$img = $_POST['image'];
		$folderPath = "../ams_selfie/";
		$image_parts = explode(";base64,", $img);
		$image_type_aux = explode("image/", $image_parts[0]);
		$image_type = $image_type_aux[1];
		$image_base64 = base64_decode($image_parts[1]);
		//$loc_review_in_selfie = 'astralis-'.$fetch1['empid'].'-'.uniqid().'.png';
		$loc_review_in_selfie = $fetch1['empid'].'-'.uniqid().'.png';
		$file = $folderPath . $loc_review_in_selfie;
		file_put_contents($file, $image_base64);
	
	if ($OfficeIn <= '10:16:00')
	{
		$status = "MIS";
		$query=mysqli_query($conn,"insert into tracker (user_IP, user_browser, user_device, empid, Employee_Full_Name, Team_Name, Role, entry, Location_of_Work, Functional_Reporting, Reporting_Head_Code, Team_Head_Code, loc_review, loc_review_in_selfie, bh_empid, loc_id, latitude, longitude, lat, longt, cityID, location, distance, camera_status, status, OfficeDate, OfficeIn)
		values ('".$_POST['user_IP']."', '".$_POST['user_browser']."', '".$_POST['user_device']."', '".$_POST['empid']."', '".$_POST['Employee_Full_Name']."', '".$_POST['Team_Name']."', '".$_POST['Role']."', '".$_POST['entry']."', '".$_POST['Location_of_Work']."', '".$_POST['Functional_Reporting']."', '".$_POST['Reporting_Head_Code']."', '".$_POST['Team_Head_Code']."', '".$_POST['loc_review']."', '$loc_review_in_selfie', '".$_POST['bh_empid']."', '".$_POST['loc_id']."', '".$_POST['latitude']."', '".$_POST['longitude']."', '".$_POST['lat']."', '".$_POST['longt']."', '".$_POST['cityID']."', '".$_POST['location']."', '$distance', '$camera_status', '$status', '$OfficeDate', '$OfficeIn') ");
	
		//echo "<pre>"; print_r($_POST); exit;
		if($query==true)
		{
		echo "<script>window.location.href='view.php';</script>";			exit; 
		echo "<div class='col-md-12 text-center btn btn-success'>Attendance Marked Successfully! </div>";
		}
		else
			{	
			echo mysqli_error($conn);
			echo "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong Insert!</div>";	}
	}
	elseif ($OfficeIn >= '10:16:00')
	{
		$timeIN = '10:00:00';
		$timelength = strtotime( $OfficeIn ) - strtotime( $timeIN );
		$hours = intval( $timelength / 3600 );
		$minutes = intval( ( $timelength % 3600 ) / 60 );
		$seconds = $timelength % 60;
		$OfficeLate =gmdate("H:i:s", $timelength);
		$status = "MIS";
	
		$query=mysqli_query($conn,"insert into tracker (user_IP, user_browser, user_device, empid, Employee_Full_Name, Team_Name, Role, entry, Location_of_Work, Functional_Reporting, Reporting_Head_Code, Team_Head_Code, loc_review, loc_review_in_selfie, bh_empid, loc_id, latitude, longitude, lat, longt, cityID, location, distance, camera_status, status, OfficeDate, OfficeIn, OfficeLate)
		values ('".$_POST['user_IP']."', '".$_POST['user_browser']."', '".$_POST['user_device']."', '".$_POST['empid']."', '".$_POST['Employee_Full_Name']."', '".$_POST['Team_Name']."', '".$_POST['Role']."', '".$_POST['entry']."', '".$_POST['Location_of_Work']."', '".$_POST['Functional_Reporting']."', '".$_POST['Reporting_Head_Code']."', '".$_POST['Team_Head_Code']."', '".$_POST['loc_review']."', '$loc_review_in_selfie', '".$_POST['bh_empid']."', '".$_POST['loc_id']."', '".$_POST['latitude']."', '".$_POST['longitude']."', '".$_POST['lat']."', '".$_POST['longt']."', '".$_POST['cityID']."', '".$_POST['location']."', '$distance', '$camera_status', '$status', '$OfficeDate', '$OfficeIn', '$OfficeLate') ");

		if($query==true)
		{	echo "<script>window.location.href='view.php';</script>";	exit; 
			echo "<div class='col-md-12 text-center btn btn-success'>Attendance Marked Successfully! </div>";
		}
		else
		{	echo mysqli_error($conn);
			echo "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong Insert!</div>";
		}
	}
}
}
?>

<?php
$qu=mysqli_query($conn,"select * from tracker where empid='".@$user_id1."' AND created_at LIKE '%$date%' ORDER BY id DESC");
$punchtype=mysqli_fetch_array($qu);
{
if ($punchtype['entry'] == 'Punch In')
{
	

if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if (isset($_POST['outsubmit']))
{
	$camera_status = $_POST['camera_status'];	
	
		$img = $_POST['image'];
		$folderPath = "../ams_selfie/";
		$image_parts = explode(";base64,", $img);
		$image_type_aux = explode("image/", $image_parts[0]);
		$image_type = $image_type_aux[1];
		$image_base64 = base64_decode($image_parts[1]);
		//$loc_review_out_selfie = 'astralis-'.$fetch1['empid'].'-'.uniqid().'.png';
		$loc_review_out_selfie = $fetch1['empid'].'-'.uniqid().'.png';
		$file = $folderPath . $loc_review_out_selfie;
		file_put_contents($file, $image_base64);
		
		$querylog=mysqli_query($conn,"insert into tracker_log (user_IP, user_browser, user_device, empid, Employee_Full_Name, cityID, location, lat, longt)
		values ('".$_POST['user_IP']."', '".$_POST['user_browser']."', '".$_POST['user_device']."', '".$_POST['empid']."', '".$_POST['Employee_Full_Name']."', '".$_POST['cityID']."', '".$_POST['location']."', '".$_POST['lat']."', '".$_POST['longt']."') ");
		
		$lat1= $_POST['latitude'];
		$lon1= $_POST['longitude'];
		$lat2= $_POST['lat'];
		$lon2= $_POST['longt'];
		$distance = "Selfie";
		
		$timeIN = date("H:i:s", time());
		if ($timeIN <= '18:30:00')
		{
			$timeout = '18:30:00';
			$timelength = strtotime( $timeout ) - strtotime( $timeIN );
			$hours = intval( $timelength / 3600 );
			$minutes = intval( ( $timelength % 3600 ) / 60 );
			$seconds = $timelength % 60;
			$OfficeEarly =gmdate("H:i:s", $timelength);
			
			if ($punchtype['OfficeIn'] <= '10:16:00' && $timeIN >= '18:15:00')
				{	$status = "EARLY";}
			
			if ($punchtype['OfficeIn'] <= '10:16:00' && $timeIN >= '16:30:00' && $timeIN <= '18:15:00')
				{	$status = "SRT";}
			
			if ($punchtype['OfficeIn'] <= '10:16:00' && $timeIN <= '16:30:00')
				{	$status = "HALF";}
			
			if ($punchtype['OfficeIn'] >= '10:16:00' && $timeIN >= '16:30:00')
				{	$status = "HALF";}
			
			$workinghr = gmdate("H:i:s", $whr = strtotime( $timeIN ) - strtotime($punchtype['OfficeIn']));
			
			if ($workinghr <= '04:00:00')
				{	$status = "ABSENT"; }
			if ($workinghr >= '04:00:00' && $workinghr <= '06:15:00')
				{	$status = "HALF"; }
			if ($workinghr >= '06:15:00' && $workinghr <= '08:15:00')
				{	$status = "SRT"; }
			
			$query = mysqli_query($conn,"update tracker set out_user_IP='".$_POST['user_IP']."', out_browser='".$_POST['user_browser']."', out_device='".$_POST['user_device']."', loc_id='".$_POST['loc_id']."', latitude='".$_POST['latitude']."', longitude='".$_POST['longitude']."', out_lat='".$_POST['lat']."', out_longt='".$_POST['longt']."', cityID='".$_POST['cityID']."', out_location='".$_POST['location']."', loc_review='".$_POST['loc_review']."', loc_review_out_selfie='$loc_review_out_selfie', camera_status_out='$camera_status', status='$status', OfficeEarly='$OfficeEarly', OfficeOut='". date('H:i:s')."', workinghr='$workinghr' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
			
				if($query==true)	{
				echo "<script>window.location.href='view.php';</script>";	exit; 
				echo "<div class='col-md-12 text-center btn btn-success'>Attendance Marked Successfully! </div>";
					}
				else {
					echo "Error: " . $query . "<br>" . mysqli_error($conn);
					echo "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong!</div>";
				}
		}
		
		elseif ($timeIN >= '18:30:00')
		{
			$OfficeEarly =' ';
			
			if ($punchtype['OfficeIn'] >= '15:30:00' )
				{	$status = "ABSENT"; }
			if ($punchtype['OfficeIn'] <= '15:30:00' )
				{	$status = "HALF"; }
			if ($punchtype['OfficeIn'] >= '12:00:00' )
				{	$status = "HALF"; }
			if ($punchtype['OfficeIn'] >= '10:30:00' && $punchtype['OfficeIn'] <= '12:00:00' )
				{	$status = "SRT";}
			if ($punchtype['OfficeIn'] >= '10:16:00' && $punchtype['OfficeIn'] <= '10:30:00' )
				{	$status = "LATE";}
			if ($punchtype['OfficeIn'] <= '10:16:00' )
				{	$status = "PRESENT";}
			
			$workinghr = gmdate("H:i:s", $whr = strtotime( $timeIN ) - strtotime($punchtype['OfficeIn']));
			
			if ($workinghr <= '04:00:00')
				{	$status = "ABSENT"; }
			if ($workinghr >= '04:00:00' && $workinghr <= '06:15:00')
				{	$status = "HALF"; }

			$query = mysqli_query($conn,"update tracker set out_user_IP='".$_POST['user_IP']."', out_browser='".$_POST['user_browser']."', out_device='".$_POST['user_device']."', loc_id='".$_POST['loc_id']."', latitude='".$_POST['latitude']."', longitude='".$_POST['longitude']."', out_lat='".$_POST['lat']."', out_longt='".$_POST['longt']."', cityID='".$_POST['cityID']."', out_location='".$_POST['location']."', loc_review='".$_POST['loc_review']."', loc_review_out_selfie='$loc_review_out_selfie', camera_status_out='$camera_status', status='$status', OfficeEarly='$OfficeEarly', OfficeOut='". date('H:i:s')."', workinghr='$workinghr' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
			
				if($query==true)	{
				echo "<script>window.location.href='view.php';</script>";	exit; 
				echo "<div class='col-md-12 text-center btn btn-success'>Attendance Marked Successfully! </div>";
					}
				else {
					echo "Error: " . $query . "<br>" . mysqli_error($conn);
					echo "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong!</div>";
				}
		}
	}
}
}
?>

<div class="d-none d-lg-block">
	<div class="col-md-12 col-sm-12 alert alert-danger"><h5>Punch <b>In / Out</b> have been enabled Only on Mobile Device</h5></div>
</div>

<div class="d-lg-none">
<form class="form-horizontal" name="ams_mark" action="" method="post" enctype="multipart/form-data" autocomplete="off">
	<div class="row">
	<div class="col-md-6 col-sm-6 text-center">
		<input class="form-control" type="hidden" name="user_IP" value="<?php echo $getUserIpAddr ?>" >
		<input class="form-control" type="hidden" name="user_browser" value="<?php echo $user_browser ?>" >
		<input class="form-control" type="hidden" name="user_device" value="<?php echo $user_device ?>" >
		<input class="form-control" type="hidden" name="empid" value="<?php echo $fetch1['empid']; ?>" >
		<input class="form-control" type="hidden" name="Employee_Full_Name" value="<?php echo $fetch1['Employee_Full_Name']; ?>" >
		<input class="form-control" type="hidden" name="Team_Name" value="<?php echo $fetch1['Team_Name']; ?>" >
		<input class="form-control" type="hidden" name="Role" value="<?php echo $fetch1['Role']; ?>" >
		<input class="form-control" type="hidden" name="Location_of_Work" value="<?php echo $fetch1['Location_of_Work']; ?>" >
		<input class="form-control" type="hidden" name="Functional_Reporting" value="<?php echo $fetch1['Functional_Reporting']; ?>" >
		<input class="form-control" type="hidden" name="Reporting_Head_Code" value="<?php echo $fetch1['Reporting_Head_Code']; ?>" >
		<input class="form-control" type="hidden" name="Team_Head_Code" value="<?php echo $fetch1['Team_Head_Code']; ?>" >
		<input class="form-control" type="hidden" name="loc_review" value="Selfie" >
		<input class="form-control" type="hidden" name="entry" value="Punch In" required>
		<input class="form-control" type="hidden" name="loc_id" id="id" value="Selfie" required>
		<input class="form-control" type="hidden" name="latitude" id="latitude" value="Selfie" required>
		<input class="form-control" type="hidden" name="longitude" id="longitude" value="Selfie" onkeydown="return false;" required>
		<input class="form-control" type="hidden" name="bh_empid" id="bh_empid" onkeydown="return false;" required>
		<input class="form-control" type="hidden" name="lat" id="lat" onkeydown="return false;" style="pointer-events: none;" placeholder="No Manual Entry" required>
		<input class="form-control" type="hidden" name="longt" id="longt" onkeydown="return false;" style="pointer-events: none;" placeholder="No Manual Entry" required>
		<input type="hidden" id="hiddenCameraStatus" name="camera_status">
	<!-- *************************************************************************************************** -->
	<?php
	/* $allowedIPs = [
	'122.186.71.114' => 'Astralis Office',
    '125.22.201.102' => 'Boulevard Walk',
    '182.75.151.138' => 'Irish Tech Park 4th-8th Floor',
    '122.161.41.148' => 'Airtel Anup',
    '122.161.41.148' => 'Anup',
	]; */
	?>
<p id="cameraStatus">Camera Checking...</p>

<script>
navigator.mediaDevices.getUserMedia({ video: true })
    .then(function(stream) {
        document.getElementById("cameraStatus").innerText = "Camera access allowed";
        document.getElementById("hiddenCameraStatus").value = "allowed";
    })
    .catch(function(err) {
        document.getElementById("cameraStatus").innerText = "Camera access blocked";
        document.getElementById("hiddenCameraStatus").value = "blocked";
    });
</script>
	<?php
	include ('include/ip_location.php');
		//$userIP = $_SERVER['REMOTE_ADDR'];
		$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
		if (array_key_exists($userIP, $allowedIPs))
			{
			$getlocation = $allowedIPs[$userIP];
			echo "<h6 class='text-center'>Location: $getlocation</h6>";
			echo '<div id="my_camera" style="margin:auto"></div>
					<input type="hidden" name="image" class="image-tag">';
				/* if ($punchtype['entry'] == 'Punch Out')
					{
				echo "<button type='submit' name='outsubmit' id='submit' class='btn btn-success' onClick='take_snapshot()'>Submit 3</button>";			
				} */

				if ($punchtype['entry'] == 'Punch In')
					{
				echo "<button type='submit' name='outsubmit' id='submit' class='btn btn-success' onClick='take_snapshot()'>Submit</button>";
				}
				if ($punchtype['entry'] == '')
					{
				echo "<button type='submit' name='submit' id='submit' class='btn btn-success' onClick='take_snapshot()'>Submit</button>";
				}
			}
		else{
			echo "<div class='alert alert-danger'><strong>Use Office Wifi and Chrome Browser</strong> You must be within your assigned location!</div>";
			}
	?>
	</div>
	<b class="text-danger">No IMAGE => Absent<br>Camera must be enabled for Selfie</b>
	</div>

	<div class="row py-4">
		<div class="col-md-12 col-sm-12 text-center">
			<input class="form-control" type="hidden" name="location" value="<?php echo $getlocation ?>">
			<?php	}	?>
		</div>
	</div>
	
		<script>
		function showPosition(position) {
		  document.getElementById("demo").innerHTML =
		  "Latitude: " + position.coords.latitude + "<br>" +
		  "Longitude: " + position.coords.longitude;
		}
		if(navigator.geolocation){
			navigator.geolocation.getCurrentPosition(showPosition);
		}
		navigator.geolocation.getCurrentPosition(function(position)
		{
			var coordinates = position.coords;
			document.getElementById('lat').value = coordinates.latitude;
			document.getElementById('longt').value = coordinates.longitude;
		});
	</script>
	
	<!-- *************************************************************************************************** -->
	
</form>
</div>

<div class="table">
	<table class="table table-bordered datatable responsive">
		<thead>
			<tr>
				<th>Today In</th> 
				<th>Late</th> 
				<th>Today Out</th>
				<th>Early</th>
			</tr>
		</thead>
		<tbody> 
		<?php
		$query="select * from tracker where empid='".@$user_id1."' AND created_at LIKE '%$date%' ORDER BY id ASC";
		$result=mysqli_query($conn,$query);
		while($data=mysqli_fetch_assoc($result))
		{
		@$sn++;
		?>
		<tr>
			<?php
			if(strlen($data['lat']) >= 12 && ($data['user_device']) == 'ANDROID')
				{
					echo "<td><div class='bg-danger text-white'>".$data ['OfficeIn']."</div></td>";
					echo "<td><div class='bg-danger text-white'>Fake GPS</div></td>";
				}
				else
				{
				echo "<td>".$data ['OfficeIn']."</td>";
				echo "<td><div class='bg-danger text-white'>".$data['OfficeLate']."</div></td>";
			}?>
			<?php
			if(strlen($data['out_lat']) >= 12 && ($data['out_device']) == 'ANDROID')
				{
					echo "<td><div class='bg-danger text-white'>".$data ['OfficeOut']."</div></td>";
					echo "<td><div class='bg-danger text-white'>Fake GPS</div></td>";
				}
				else
				{
				echo "<td>".$data ['OfficeOut']."</td>";
				echo "<td><div class='bg-danger text-white'>".$data['OfficeEarly']."</div></td>";
			}?>
		</tr>
		<?php    }    ?>
		</tbody>
	</table>
</div>

<script type="text/javascript">
  var ab;
  function showPosition(position){
   ab = position.coords.latitude+","+position.coords.longitude;     
  }
  function showError(error) {
  switch(error.code) {
    case error.PERMISSION_DENIED:
      x.innerHTML = "User denied the request for Geolocation."
      break;
    case error.POSITION_UNAVAILABLE:
      x.innerHTML = "Location information is unavailable."
      break;
    case error.TIMEOUT:
      x.innerHTML = "The request to get user location timed out."
      break;
    case error.UNKNOWN_ERROR:
      x.innerHTML = "An unknown error occurred."
      break;
		}
	}
</script>
<script>  
 function geocodeLatLng(geocoder, map, infowindow) {
	 var input = ab;
	 var latlngStr = input.split(',', 2);
	 var latlng = {lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1])};
	geocoder.geocode({'location': latlng}, function(results, status) {
	 if (status === 'OK') {
		if (results[0]) {
	document.getElementById('addr_location').value = results[0].formatted_address;
	document.getElementById('latlong').value = input;
		} else {			 window.alert('No address location found !');			}
	 } else {			window.alert('Geocoder failed due to: ' + status);		 }
	});
 }
 function initMap() {
	var geocoder = new google.maps.Geocoder;
	var infowindow = new google.maps.InfoWindow;
	document.getElementById('submit').addEventListener('click', function() { geocodeLatLng(geocoder, map, infowindow); });
 }
</script>
<script type="text/javascript">
$(document).ready(function() {
  $("select.location_name").change(function() {
    var selectedp = $(this).children("option:selected").val();
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        var myObj = JSON.parse(this.responseText);
				document.getElementById("id").value = myObj[0];
        document.getElementById("latitude").value = myObj[1];
        document.getElementById("longitude").value = myObj[2];
        document.getElementById("bh_empid").value = myObj[3];
     }
    };
    xmlhttp.open("GET", "ams_location.php?location_name=" + selectedp, true);
    xmlhttp.send();
  });
});
</script>
<script language="JavaScript">
    Webcam.set({
        width: 280,
        height: 300,
        image_format: 'jpeg',
        //jpeg_quality: 50
    });
  
    Webcam.attach( '#my_camera' );
  
    function take_snapshot() {
        Webcam.snap( function(data_uri) {
            $(".image-tag").val(data_uri);
            document.getElementById('results').innerHTML = '<img src="'+data_uri+'"/>';
        } );
    }
</script>
</div>		
			<!--</?php	include ('include/wallet-footer.php');	?>-->
            </div>
        </div>
 
		<?php	include ('include/copyright.php');	?>
	</div>
	
	<?php	include ('footer.php');	?>