<?
  include "include/dbcon.php";
  include "include/CTEACHER.php";
  include "include/cfunction.php";
?>
<?
  function getNextDay($pday,$pcount){
    return date("Y-m-d",strtotime(date("Y-m-d", strtotime($pday)) . " +" . $pcount . " day"));
  }
  
  function getMKTIME($pdate){
    $mydate = explode("-",$pdate);
    return mktime(0,0,0,$mydate[1],$mydate[2],$mydate[0]);
  }
?>
<?
  $teaid = $_POST["teaid"];
  $datefrom = $_POST["txtDatefrom"];
  $datetil = $_POST["txtDatetil"];
  $eventid = $_POST["eventid"];
  $notice = $_POST["notice"];
  $status = "1";
  $apvby = $_SESSION["teacherSessionId"];
  $apvdate = $_POST["apvdate"];
  
  $mytea = new CTEACHER();
  $mytea->setTeacher("id",$teaid);
  $punchin = $mytea->getStartT(getWeek2($datefrom));
  $punchout = $mytea->getEndT(getWeek2($datefrom));

  while($datefrom<=$datetil){

//    if(date("w",getMKTIME($datefrom))<6 && date("w",getMKTIME($datefrom))>0){

    $query = "INSERT INTO punchsys_punchrecord VALUES
              (NULL,'$teaid','$datefrom','00:00:00','$datefrom','00:00:00','','00:00:00','00:00:00')";
    mysqli_query($conn,$query);

    $query = "INSERT INTO punchsys_remarkrecord VALUES
			   (NULL,'$teaid','$datefrom','$datefrom','$eventid','$notice','$status','$apvby','$apvdate')";	
    mysqli_query($conn,$query);

//  }	
    $datefrom = getNextDay($datefrom,1);
  }
?>
<?php
  header("location: main.php?pg=rmk&ac=tsk&dt=" . $_POST["txtDatefrom"]);
?>