<?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>Conveyance Attendance</title>
	
	<?php	include ('header.php');	?>
	
	<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
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();
?>

<?php
if(isset($_POST['submit1']))
{
	$status = "MIS1";
	$OfficeDate = date("Y-m-d", time());
	$loc1_IP= $getUserIpAddr;
	$loc1_Time = date("H:i:s", time());
	$loc1_name= $_POST['loc_name'];
	$loc1_lat= $_POST['lat'];
	$loc1_longt= $_POST['longt'];

	$query=mysqli_query($conn,"insert into tracker_rider (empid, Employee_Full_Name, entry, Functional_Reporting, status, OfficeDate, loc1_IP, loc1_Time, loc1_name, loc1_lat, loc1_longt)
	values ('".$_POST['empid']."', '".$_POST['Employee_Full_Name']."', '".$_POST['entry']."', '".$_POST['Functional_Reporting']."', '$status', '$OfficeDate', '$loc1_IP', '$loc1_Time', '$loc1_name', '$loc1_lat', '$loc1_longt') ");
	//echo "<pre>"; print_r($_POST); exit;
	if($query==true)
		{
		echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	exit; 
		//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 Insert!</div>";
		}
}
?>

<?php
$qu=mysqli_query($conn,"select * from tracker_rider where empid='".@$user_id1."' AND created_at LIKE '%$date%' ORDER BY id DESC");
$punchtype=mysqli_fetch_array($qu);
{
	if(isset($_POST['submit2']))
	{
		$status = "MIS2";
		$loc2_IP= $getUserIpAddr;
		$loc2_Time = date("H:i:s", time());
		$loc2_name= $_POST['loc_name'];
		$loc2_lat= $_POST['lat'];
		$loc2_longt= $_POST['longt'];
	/* --------------------------------------------------------------------------------- */
		echo $origin = $punchtype['loc1_lat'].','.$punchtype['loc1_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
	/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc1_kms='$distance', loc2_IP='$loc2_IP', loc2_Time='". date('H:i:s')."', loc2_name='$loc2_name', loc2_lat='$loc2_lat', loc2_longt='$loc2_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	exit; 
			//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 "<div class='col-md-12 text-center btn btn-danger'><strong>Error!</strong>Sorry something went wrong!</div>";
		}
	}
	
	if(isset($_POST['submit3']))
	{
		$status = "MIS3";		$loc3_IP= $getUserIpAddr;
		$loc3_Time = date("H:i:s", time());
		$loc3_name= $_POST['loc_name'];
		$loc3_lat= $_POST['lat'];		$loc3_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		echo $origin = $punchtype['loc2_lat'].','.$punchtype['loc2_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc2_kms='$distance', loc3_IP='$loc3_IP', loc3_Time='". date('H:i:s')."', loc3_name='$loc3_name', loc3_lat='$loc3_lat', loc3_longt='$loc3_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit4']))
	{
		$status = "MIS4";		$loc4_IP= $getUserIpAddr;
		$loc4_Time = date("H:i:s", time());
		$loc4_name= $_POST['loc_name'];
		$loc4_lat= $_POST['lat'];		$loc4_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		echo $origin = $punchtype['loc3_lat'].','.$punchtype['loc3_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc3_kms='$distance', loc4_IP='$loc4_IP', loc4_Time='". date('H:i:s')."', loc4_name='$loc4_name', loc4_lat='$loc4_lat', loc4_longt='$loc4_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit5']))
	{
		$status = "MIS5";		$loc5_IP= $getUserIpAddr;
		$loc5_Time = date("H:i:s", time());
		$loc5_name= $_POST['loc_name'];
		$loc5_lat= $_POST['lat'];		$loc5_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		echo $origin = $punchtype['loc4_lat'].','.$punchtype['loc4_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		
		//echo "<pre>"; print_r($_POST); exit;
		
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc4_kms='$distance', loc5_IP='$loc5_IP', loc5_Time='". date('H:i:s')."', loc5_name='$loc5_name', loc5_lat='$loc5_lat', loc5_longt='$loc5_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit6']))
	{
		$status = "MIS6";		$loc6_IP= $getUserIpAddr;
		$loc6_Time = date("H:i:s", time());
		$loc6_name= $_POST['loc_name'];
		$loc6_lat= $_POST['lat'];		$loc6_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		echo $origin = $punchtype['loc5_lat'].','.$punchtype['loc5_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc5_kms='$distance', loc6_IP='$loc6_IP', loc6_Time='". date('H:i:s')."', loc6_name='$loc6_name', loc6_lat='$loc6_lat', loc6_longt='$loc6_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit7']))
	{
		$status = "MIS7";		$loc7_IP= $getUserIpAddr;
		$loc7_Time = date("H:i:s", time());
		$loc7_name= $_POST['loc_name'];
		$loc7_lat= $_POST['lat'];		$loc7_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		$origin = $punchtype['loc6_lat'].','.$punchtype['loc6_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc6_kms='$distance', loc7_IP='$loc7_IP', loc7_Time='". date('H:i:s')."', loc7_name='$loc7_name', loc7_lat='$loc7_lat', loc7_longt='$loc7_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit8']))
	{
		$status = "MIS8";		$loc8_IP= $getUserIpAddr;
		$loc8_Time = date("H:i:s", time());
		$loc8_name= $_POST['loc_name'];
		$loc8_lat= $_POST['lat'];		$loc8_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		$origin = $punchtype['loc7_lat'].','.$punchtype['loc7_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc7_kms='$distance', loc8_IP='$loc8_IP', loc8_Time='". date('H:i:s')."', loc8_name='$loc8_name', loc8_lat='$loc8_lat', loc8_longt='$loc8_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit9']))
	{
		$status = "MIS9";		$loc9_IP= $getUserIpAddr;
		$loc9_Time = date("H:i:s", time());
		$loc9_name= $_POST['loc_name'];
		$loc9_lat= $_POST['lat'];		$loc9_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		$origin = $punchtype['loc8_lat'].','.$punchtype['loc8_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc8_kms='$distance', loc9_IP='$loc9_IP', loc9_Time='". date('H:i:s')."', loc9_name='$loc9_name', loc9_lat='$loc9_lat', loc9_longt='$loc9_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit10']))
	{
		$status = "MIS10";		$loc10_IP= $getUserIpAddr;
		$loc10_Time = date("H:i:s", time());
		$loc10_name= $_POST['loc_name'];
		$loc10_lat= $_POST['lat'];		$loc10_longt= $_POST['longt'];
		/* --------------------------------------------------------------------------------- */
		$origin = $punchtype['loc9_lat'].','.$punchtype['loc9_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		/* if ($distance_arr->status=='OK') {			$destination_addresses = $distance_arr->destination_addresses[0];
			$origin_addresses = $distance_arr->origin_addresses[0];		}
			else {		  echo "<p>The request was Invalid</p>";		  exit();		} */
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;
		/* --------------------------------------------------------------------------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc9_kms='$distance', loc10_IP='$loc10_IP', loc10_Time='". date('H:i:s')."', loc10_name='$loc10_name', loc10_lat='$loc10_lat', loc10_longt='$loc10_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit11']))
	{
		$status = "MIS11";		$loc11_IP= $getUserIpAddr;
		$loc11_Time = date("H:i:s", time());
		$loc11_name= $_POST['loc_name'];
		$loc11_lat= $_POST['lat'];		$loc11_longt= $_POST['longt'];
		/* ------------- */	$origin = $punchtype['loc10_lat'].','.$punchtype['loc10_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;	/* ------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc10_kms='$distance', loc11_IP='$loc11_IP', loc11_Time='". date('H:i:s')."', loc11_name='$loc11_name', loc11_lat='$loc11_lat', loc11_longt='$loc11_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit12']))
	{
		$status = "MIS12";		$loc12_IP= $getUserIpAddr;
		$loc12_Time = date("H:i:s", time());
		$loc12_name= $_POST['loc_name'];
		$loc12_lat= $_POST['lat'];		$loc12_longt= $_POST['longt'];
		/* ------------- */	$origin = $punchtype['loc11_lat'].','.$punchtype['loc11_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;	/* ------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc11_kms='$distance', loc12_IP='$loc12_IP', loc12_Time='". date('H:i:s')."', loc12_name='$loc12_name', loc12_lat='$loc12_lat', loc12_longt='$loc12_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit13']))
	{
		$status = "MIS13";		$loc13_IP= $getUserIpAddr;
		$loc13_Time = date("H:i:s", time());
		$loc13_name= $_POST['loc_name'];
		$loc13_lat= $_POST['lat'];		$loc13_longt= $_POST['longt'];
		/* ------------- */	$origin = $punchtype['loc12_lat'].','.$punchtype['loc12_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;	/* ------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc12_kms='$distance', loc13_IP='$loc13_IP', loc13_Time='". date('H:i:s')."', loc13_name='$loc13_name', loc13_lat='$loc13_lat', loc13_longt='$loc13_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit14']))
	{
		$status = "MIS14";		$loc14_IP= $getUserIpAddr;
		$loc14_Time = date("H:i:s", time());
		$loc14_name= $_POST['loc_name'];
		$loc14_lat= $_POST['lat'];		$loc14_longt= $_POST['longt'];
		/* ------------- */	$origin = $punchtype['loc13_lat'].','.$punchtype['loc13_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;	/* ------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc13_kms='$distance', loc14_IP='$loc14_IP', loc14_Time='". date('H:i:s')."', loc14_name='$loc14_name', loc14_lat='$loc14_lat', loc14_longt='$loc14_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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>";
		}
	}
	
	if(isset($_POST['submit15']))
	{
		$status = "MIS15";		$loc15_IP= $getUserIpAddr;
		$loc15_Time = date("H:i:s", time());
		$loc15_name= $_POST['loc_name'];
		$loc15_lat= $_POST['lat'];		$loc15_longt= $_POST['longt'];
		/* ------------- */	$origin = $punchtype['loc14_lat'].','.$punchtype['loc14_longt'] ;
		$destination = $_POST['lat'].','.$_POST['longt'] ;
		$distance_data = file_get_contents('https://maps.googleapis.com/maps/api/distancematrix/json?&origins='.urlencode($origin).'&destinations='.urlencode($destination).'&key=AIzaSyB-FZbEtDvYXFk3M7ALNt11S4kfMO1XVPo');
		$distance_arr = json_decode($distance_data);
		$elements = $distance_arr->rows[0]->elements;
		$distance = $elements[0]->distance->text;	/* ------------- */
		$query = mysqli_query($conn,"update tracker_rider set status='$status', loc14_kms='$distance', loc15_IP='$loc15_IP', loc15_Time='". date('H:i:s')."', loc15_name='$loc15_name', loc15_lat='$loc15_lat', loc15_longt='$loc15_longt' where created_at='$punchtype[created_at]' AND empid='$fetch1[empid]'" );
		
		if($query==true){
			echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';	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">
<h4 class="text-center">Conveyance Attendance</h4>
<div class="">
<form class="form-horizontal" name="ams_rider" action="" method="post" enctype="multipart/form-data" autocomplete="off">
	<div class="row">
		<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="Functional_Reporting" value="<?php echo $fetch1['Functional_Reporting']; ?>" >
		<?php
			if ($punchtype['status'] == 'MIS15')	{	echo '<div class="alert alert-warning text-center"><strong>Today Trip Ended!</strong></div>';	}
			else{
				echo '<div class="col-md-3 col-sm-3"><input class="form-control" type="text" name="loc_name" placeholder="Location Name" required></div>
				<div class="col-md-3 col-sm-3">
					<label><h4><input type="radio" name="entry" onClick="getMyLocation();" id="submit" value="Punch In" required> Mark Punch</h4></label>
					<input class="form-control" type="hidden" name="lat" id="lat" required>
					<input class="form-control" type="text" name="longt" id="longt" onkeydown="return false;" style="pointer-events: none;" placeholder="No Manual Entry" required>
				</div>';
			}
		?>
	</div>

	<script>
		function getMyLocation(){
			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>
	<div class="row">
		<div class="col-md-4 col-sm-4"></div>
		<div class="col-md-4 col-sm-4 p2 text-center">
			<?php
			if ($punchtype['status'] == 'MIS14'){	echo "<button type='submit' name='submit15' id='submit' class='btn btn-success'>Location 15</button>";	}
			if ($punchtype['status'] == 'MIS13'){	echo "<button type='submit' name='submit14' id='submit' class='btn btn-success'>Location 14</button>";	}
			if ($punchtype['status'] == 'MIS12'){	echo "<button type='submit' name='submit13' id='submit' class='btn btn-success'>Location 13</button>";	}
			if ($punchtype['status'] == 'MIS11'){	echo "<button type='submit' name='submit12' id='submit' class='btn btn-success'>Location 12</button>";	}
			if ($punchtype['status'] == 'MIS10'){	echo "<button type='submit' name='submit11' id='submit' class='btn btn-success'>Location 11</button>";	}
			
			if ($punchtype['status'] == 'MIS9')	{	echo "<button type='submit' name='submit10' id='submit' class='btn btn-success'>Location 10</button>";	}
			if ($punchtype['status'] == 'MIS8')	{	echo "<button type='submit' name='submit9' id='submit' class='btn btn-success'>Location 9</button>";	}
			if ($punchtype['status'] == 'MIS7')	{	echo "<button type='submit' name='submit8' id='submit' class='btn btn-success'>Location 8</button>";	}
			if ($punchtype['status'] == 'MIS6')	{	echo "<button type='submit' name='submit7' id='submit' class='btn btn-success'>Location 7</button>";	}
			
			if ($punchtype['status'] == 'MIS5')	{	echo "<button type='submit' name='submit6' id='submit' class='btn btn-success'>Location 6</button>";	}
			if ($punchtype['status'] == 'MIS4')	{	echo "<button type='submit' name='submit5' id='submit' class='btn btn-success'>Location 5</button>";	}
			if ($punchtype['status'] == 'MIS3')	{	echo "<button type='submit' name='submit4' id='submit' class='btn btn-success'>Location 4</button>";	}
			if ($punchtype['status'] == 'MIS2')	{	echo "<button type='submit' name='submit3' id='submit' class='btn btn-success'>Location 3</button>";	}
			if ($punchtype['status'] == 'MIS1')	{	echo "<button type='submit' name='submit2' id='submit' class='btn btn-success'>Location 2</button>";	}
			if ($punchtype['status'] == '')		{	echo "<button type='submit' name='submit1' id='submit' class='btn btn-success'>Location 1</button>";	}
			
			}
			?>
		</div>
	</div>
</form>
</div>
</div>

	<div class="table">
		<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
			<tbody> 
			<?php
			$query="select * from tracker_rider where empid='".@$user_id1."' AND created_at LIKE '%$date%'";
			
			$result=mysqli_query($conn,$query);
			while($data=mysqli_fetch_assoc($result))
			{
			@$sn++;
			?>
			<tr><th><?php echo date('d-M', strtotime($data ['created_at'])); ?></th>	<th>Time</th>	<th>Loc Name</th></tr>
			<tr><td>Loc-01</td>	<td><?php echo $data['loc1_Time'] ?></td>  <td><?php echo $data['loc1_name'] ?></td>  </tr>
			<tr><td>Loc-02</td>	<td><?php echo $data['loc2_Time'] ?></td>  <td><?php echo $data['loc2_name'] ?></td>  </tr>
			<tr><td>Loc-03</td>	<td><?php echo $data['loc3_Time'] ?></td>  <td><?php echo $data['loc3_name'] ?></td>  </tr>
			<tr><td>Loc-04</td>	<td><?php echo $data['loc4_Time'] ?></td>  <td><?php echo $data['loc4_name'] ?></td>  </tr>
			<tr><td>Loc-05</td>	<td><?php echo $data['loc5_Time'] ?></td>  <td><?php echo $data['loc5_name'] ?></td>  </tr>
			<tr><td>Loc-06</td>	<td><?php echo $data['loc6_Time'] ?></td>  <td><?php echo $data['loc6_name'] ?></td>  </tr>
			<tr><td>Loc-07</td>	<td><?php echo $data['loc7_Time'] ?></td>  <td><?php echo $data['loc7_name'] ?></td>  </tr>
			<tr><td>Loc-08</td>	<td><?php echo $data['loc8_Time'] ?></td>  <td><?php echo $data['loc8_name'] ?></td>  </tr>
			<tr><td>Loc-09</td>	<td><?php echo $data['loc9_Time'] ?></td>  <td><?php echo $data['loc9_name'] ?></td>  </tr>
			<tr><td>Loc-10</td>	<td><?php echo $data['loc10_Time'] ?></td> <td><?php echo $data['loc10_name'] ?></td> </tr>
			<tr><td>Loc-11</td>	<td><?php echo $data['loc11_Time'] ?></td> <td><?php echo $data['loc11_name'] ?></td> </tr>
			<tr><td>Loc-12</td>	<td><?php echo $data['loc12_Time'] ?></td> <td><?php echo $data['loc12_name'] ?></td> </tr>
			<tr><td>Loc-13</td>	<td><?php echo $data['loc13_Time'] ?></td> <td><?php echo $data['loc13_name'] ?></td> </tr>
			<tr><td>Loc-14</td>	<td><?php echo $data['loc14_Time'] ?></td> <td><?php echo $data['loc14_name'] ?></td> </tr>
			<tr><td>Loc-15</td>	<td><?php echo $data['loc15_Time'] ?></td> <td><?php echo $data['loc15_name'] ?></td> </tr>
			<?php    }    ?>
			</tbody>
		</table>
	</div>
		
	<div class="table">
		<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
			<thead>
			<tr>
				<th>All Dates</th>
				<th>Loc1 Time</th><th>Loc1 Name</th><th>Loc1 KMS</th>
				<th>Loc2 Time</th><th>Loc2 Name</th><th>Loc2 KMS</th>
				<th>Loc3 Time</th><th>Loc3 Name</th><th>Loc3 KMS</th>
				<th>Loc4 Time</th><th>Loc4 Name</th><th>Loc4 KMS</th>
				<th>Loc5 Time</th><th>Loc5 Name</th><th>Loc5 KMS</th>
				
				<th>Loc6 Time</th><th>Loc6 Name</th><th>Loc6 KMS</th>
				<th>Loc7 Time</th><th>Loc7 Name</th><th>Loc7 KMS</th>
				<th>Loc8 Time</th><th>Loc8 Name</th><th>Loc8 KMS</th>
				<th>Loc9 Time</th><th>Loc9 Name</th><th>Loc9 KMS</th>
				<th>Loc10 Time</th><th>Loc10 Name</th><th>Loc10 KMS</th>
				
				<th>Loc11 Time</th><th>Loc11 Name</th><th>Loc11 KMS</th>
				<th>Loc12 Time</th><th>Loc12 Name</th><th>Loc12 KMS</th>
				<th>Loc13 Time</th><th>Loc13 Name</th><th>Loc13 KMS</th>
				<th>Loc14 Time</th><th>Loc14 Name</th><th>Loc14 KMS</th>
				<th>Loc15 Time</th><th>Loc15 Name</th><th>Loc15 KMS</th>
			</tr>
			</thead>
			<tbody> 
			<?php
			$query="select * from tracker_rider where empid='".@$user_id1."' AND created_at >= DATE_ADD( CURDATE(), INTERVAL -6 DAY ) ORDER BY id Desc ";
			
			$result=mysqli_query($conn,$query);
			while($data=mysqli_fetch_assoc($result))
			{
			@$sn++;
			?>
			<tr>
				<td><?php echo $data['OfficeDate'] ?></td>
				
				<td><?php echo $data['loc1_Time'] ?></td><td><?php echo $data['loc1_name'] ?></td><td><?php echo $data['loc1_kms'] ?></td>
				<td><?php echo $data['loc2_Time'] ?></td><td><?php echo $data['loc2_name'] ?></td><td><?php echo $data['loc2_kms'] ?></td>
				<td><?php echo $data['loc3_Time'] ?></td><td><?php echo $data['loc3_name'] ?></td><td><?php echo $data['loc3_kms'] ?></td>
				<td><?php echo $data['loc4_Time'] ?></td><td><?php echo $data['loc4_name'] ?></td><td><?php echo $data['loc4_kms'] ?></td>
				<td><?php echo $data['loc5_Time'] ?></td><td><?php echo $data['loc5_name'] ?></td><td><?php echo $data['loc5_kms'] ?></td>
				<td><?php echo $data['loc6_Time'] ?></td><td><?php echo $data['loc6_name'] ?></td><td><?php echo $data['loc6_kms'] ?></td>
				<td><?php echo $data['loc7_Time'] ?></td><td><?php echo $data['loc7_name'] ?></td><td><?php echo $data['loc7_kms'] ?></td>
				<td><?php echo $data['loc8_Time'] ?></td><td><?php echo $data['loc8_name'] ?></td><td><?php echo $data['loc8_kms'] ?></td>
				<td><?php echo $data['loc9_Time'] ?></td><td><?php echo $data['loc9_name'] ?></td><td><?php echo $data['loc9_kms'] ?></td>
				
				<td><?php echo $data['loc10_Time'] ?></td><td><?php echo $data['loc10_name'] ?></td><td><?php echo $data['loc10_kms'] ?></td>
				<td><?php echo $data['loc11_Time'] ?></td><td><?php echo $data['loc11_name'] ?></td><td><?php echo $data['loc11_kms'] ?></td>
				<td><?php echo $data['loc12_Time'] ?></td><td><?php echo $data['loc12_name'] ?></td><td><?php echo $data['loc12_kms'] ?></td>
				<td><?php echo $data['loc13_Time'] ?></td><td><?php echo $data['loc13_name'] ?></td><td><?php echo $data['loc13_kms'] ?></td>
				<td><?php echo $data['loc14_Time'] ?></td><td><?php echo $data['loc14_name'] ?></td><td><?php echo $data['loc14_kms'] ?></td>
				<td><?php echo $data['loc15_Time'] ?></td><td><?php echo $data['loc15_name'] ?></td><td><?php echo $data['loc15_kms'] ?></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>


</div>		
			<!--</?php	include ('include/wallet-footer.php');	?>-->
            </div>
        </div>
 
		<?php	include ('include/copyright.php');	?>
	</div>
	
	<?php	include ('footer.php');	?>