<?
  include "include/dbcon.php";
//  include "../admsys/include/CSETTING.php";
  include "include/CTEACHER.php";
//  include "include/CTIMETABLE.php";
  include "include/cfunction.php";
//  date_default_timezone_set('Asia/Kuala_Lumpur');
?>
<?
  //-- 08:15:24       2009-08-31
  //$mynowtime = date("H:i:s");
  $mynowdate = date("Y-m-d");
?>
<?
  $staffId = $_POST["teaid"];
  $myuser = new CTEACHER();
  $myuser->setTeacher("id",$staffId);
  
//  $nowT = date("H:i:s");
  $punchDate = $_POST["pdate"];
  $arrDate = explode("-",$punchDate);
  $pinhr = $_POST["inhr"];
  $pinmin = $_POST["inmin"];
  $pouthr = $_POST["outhr"];
  $poutmin = $_POST["outmin"];

  $intime = "$pinhr:$pinmin:00";
  $outtime = "$pouthr:$poutmin:00";
  $startT = $myuser->getStartT( date("w",mktime(0,0,0,$arrDate[1],$arrDate[2],$arrDate[1])) );
  $endT  = $myuser->getEndT( date("w",mktime(0,0,0,$arrDate[1],$arrDate[2],$arrDate[1])) );

  $punchIn = $intime;
  $punchOut = $outtime;
  $difSec1 = getDifSec2($startT,$punchDate,$punchIn,$punchDate);

  //--- come late -----------------
  if( $difSec1>0 ){
    $comLate = secConvTime($difSec1);
  //--- come early -----------------
  }else{
    $comLate = "00:00:00";
  }
  $difSec2 = getDifSec2($punchOut,$punchDate,$endT,$punchDate);

  //--- come late -----------------
  if( $difSec2>0 ){
    $levEarly = secConvTime($difSec2);
  //--- come early -----------------
  }else{
    $levEarly = "00:00:00";
  }

  $query = "INSERT INTO punchsys_punchrecord 
	            (staffId,punchDate,punchIn,comLate,punchOutDate,punchOut,levEarly)
				VALUES
				('$staffId','$punchDate','$punchIn','$comLate','$punchDate','$punchOut','$levEarly')";
 // echo $query . "<br>";
    mysqli_query($conn,$query);

/*
  if($_POST["eventid"]!=""){
    $peventid = $_POST["eventid"];
	$pnotice = $_POST["notice"];
	$pstatus = "1";
  
    $query = "INSERT INTO xoops_pc_remarkrecord VALUES
			   (NULL,'$staffId','$punchDate','$punchDate','$peventid','$pnotice','$pstatus','".$_SESSION["teacherSessionId"]."','$mynowdate')";
//    mysql_query($query);  
  }
*/

?>
<?
  header("Location: main.php?pg=pch&pdte=" . $_POST["pdate"]);
?>