<?php
session_start();
	
include_once("class/class.MySQL.php");

$db=new MySQL();
 $dates = date('Y-m-d');
 $time_in = date('h:i');
  $emp_in = date('h:i:s');
  
  $emp_an = date('A');
  
 $userid=$_SESSION['admin_id'];

if($_POST['rel_ID']==1)
{
	 $timerin = $time_in;
	 mysql_query("DELETE FROM time where e_id = '$eid' and e_date ='$dts'");
	 mysql_query("INSERT INTO time (e_date,e_id,deviceids,e_in,time_in,time_inloc) VALUES ('$dates','$userid','44','$emp_in','$time_in','$emp_an')");
	 
	 $db->fetchQuery("UPDATE employee SET clock_status='1' WHERE e_id='$userid'");
	 
?>

<div class="clockedin-admin-click">
<div style="text-align:center;">You have Signed In @ <?php echo date("h:i a"); ?></div>
<div class="timein-time" ></div>
<input type="button"  onClick="clock('<?php echo $userid;?>',2);" value="Sign Out" class="clockin-button">
<?php	 
	 
	 
}
else
{
//echo "SELECT *  FROM time where e_id='$userid' and e_date='$dates' order by id desc";
	$resultemp = mysql_query("SELECT *  FROM time where e_id='$userid' and e_date='$dates' order by id desc");
	$resultemp =mysql_fetch_array($resultemp);
	
	
	 $time1 = strtotime($resultemp['e_in']);
	$time2 = strtotime($emp_in);
	
	$diff = $time2 - $time1;
	$totalWorkTime = date('H:i:s',strtotime("-6 hours 30 minutes",$diff));
	$dateq = date('Y-m-d');

	mysql_query("UPDATE time SET e_out = '$emp_in', e_work = '$totalWorkTime',time_out = '$time_in', time_outloc = '$emp_an',total_worked_hours='$totalWorkTime' WHERE e_id = '$userid' and e_date='$dateq' AND id=$resultemp[id]");

		$clockins = mysql_query("SELECT * FROM time t,employee e where t.e_id='$userid' and t.e_date='$dateq' and e.e_id=t.e_id  order by id desc");
        $clockins = mysql_fetch_array($clockins);
	$db->fetchQuery("UPDATE employee SET clock_status='0' WHERE e_id='$userid'");
?>

<div class="clockedin-admin-click">
<div style="text-align:center;">You have Signed Out @ <?php echo date("h:i a"); ?></div>
<div class="timein-time" ></div>
<input type="button"  onClick="clock('<?php echo $userid;?>',1);" value="Sign In" class="clockin-button">

<?php

}

	
	
?>