<?php 
session_start();
include 'dbc.php';

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$userid=$_SESSION["userid"];
$status=$_POST["status"];
$lttime=$_POST["lttime"];
$ttime=$_POST["ttime"];
$rfid=$_POST["rfid"];
$rfid=round($rfid);
$date=$_POST["date"];
$month_name=$_POST["month_name"];
$sess1=$_POST["sess1"];
  if ($ttime > $lttime)
{
$istatus= "Late";
}
else
{
$istatus= "In Time";
}


  $a=0;
$sql1 = "SELECT * FROM attendence_tech_out where rfid='$rfid' and date='$today' and user_id='$userid'";
$result=$conn->query($sql1);
while($row = $result->fetch_assoc())
	 
{

$a=$a + 1;
}

if ($a >=1)
{
header("location:Genrate_Attendance_RF.php");
	
	}
	
else if ($rfid =="")
{
header("location:Genrate_Attendance_RF.php");
	
	}
	else
{




  $sqlchallan = "SELECT * FROM teacher where teacher_id='$rfid' and user_id='$userid'";
$resultchallan=$conn->query($sqlchallan);
while($rowchallan = $resultchallan->fetch_assoc())
 
  {
 
$id=$rowchallan['id'];

$std_name=$rowchallan['tech_name'];
$fname=$rowchallan['father_name'];
$cell_1=$rowchallan['cell_no'];
$class_name=$rowchallan['class_name'];


$sql = "Insert into attendence_tech_out (id,date,rollno,stdname,fname,class_name,cls_sec,status,month_name,cell,user_id,sess1,rfid,portal_id,ttime) values (null,'$today','$id','$std_name','$fname','$class_name','$cls_sec','$status','$month_name','$cell_1','$userid','$sess1','$rfid','$istatus','$ttime')";
$conn->query($sql);

 }
header("location:Genrate_Attendance_RF_Out.php");
}
?>
