<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}

include_once("opendb.php");


$res=mysqli_query($db,"select  max(slno) from vehinout where brcode='$brcode'");
 $row=mysqli_fetch_row($res);
 if($row[0]<=0)
  $dbno=1;
 else
  $dbno=($row[0]+1);

$d=$_REQUEST['d'];
$m=$_REQUEST['m'];
$y=$_REQUEST['y'];
$dtin=$y.'-'.$m.'-'.$d;
$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
$dtout=$y1.'-'.$m1.'-'.$d1;
$i=0;
$inttype=$_REQUEST['inttype'];
$ottype=$_REQUEST['ottype'];
$h=$_REQUEST['h'];
$min=$_REQUEST['min'];

$intime1=$h.':'.$min;
$h1=$_REQUEST['h1'];
$min1=$_REQUEST['min1'];

$outtime1=$h1.':'.$min1;
$reg=$_REQUEST['reg'];
$cp=$_REQUEST['cp'];
$mob=$_REQUEST['mob'];
$desc=$_REQUEST['desc'];
$savec=0;
date_default_timezone_set("Asia/Kolkata");
$logdt=date("Y-m-d H:i:s");
//$logtime=date("H:i:s");
//print "select  regno from vehinout where brcode='$brcode' and outtime='0000-00-00' and regno='$reg'";
$res11=mysqli_query($db,"select  regno from vehinout where brcode='$brcode' and outdate='0000-00-00' and regno='$reg'");
 //$row11=mysqli_fetch_row($res11);
 //print $row11[0];
 if(mysqli_num_rows($res11)>0)
 {
     print"<script> alert('Already Inserted'); history.back(1);</script>";
     return;
 } 
if($savec==0)
{
 $sql="insert into vehinout values('$dbno','$dtin','$intime1','$inttype','$reg','$cp','$mob','$dtout','$outtime1','$ottype','$brcode','$logdt','$desc','$logdt')";
mysqli_query($db,$sql) or die(mysqli_error($db));
$savec=1;
}
print "<font color=green>Data has been Saved</font><br>";
include("vehinout.php");
?>
