<?
  include "../../mainfile.php";
  include "include/lang.php";
  include "include/CPCSETTING.php";
  include "../admsys/include/CTEACHER.php";
  include "include/CFUNCTION2.php";
  date_default_timezone_set('Asia/Kuala_Lumpur');
?>
<?
  $mynowtime = date("H:i:s");
  $mynowdate = date("Y-m-d");
  $mysys = new CPCSETTING();
?>
<?
  $pfr = $_REQUEST["fr"];

  if($mysys->passverify==1){
    $pid = $_POST["txtId"];
	if($pid==""){
	  $pid = $_GET["txtId"];
	}
  }else{
    $pid = $_SESSION["userid"];
  }
?>
<?
  //********* check wherether holiday **********************

  //--- is day of holiday
  if(checkHoliday($mynowdate)){
  ?>
  <script language='javascript'>
  function cfmhol(){
    var response = confirm("Today is holday, do you want to continue?");
      if(response==true){
      }else{
        window.location = 'index.php';
      }
  }
  cfmhol();
  </script>
  <?
  }
?>
<?
  //********* check max punch time of the day **********************
  //--- max punch limit is over
//  echo "$pfr - $pid<br>";
  if(checkMaxpunch($pid,$mynowdate,$mysys->maxpunchtime)){
  	$_SESSION["msg"] = $LIMITOVER;
	
    //$myuser = new CTEACHER($pid);
	
	if($pfr=="v"){
	//echo "1";
	  $locaitonURL = "vb_index_report.php?msg=".$_SESSION["msg"]."&v2=1";
	  //header("Location: vb_index_php?msg=asdfasf");
	
	}else{
	//echo "2";
	  $locaitonURL = "index.php";
	  //header("Location: index.php");
	}
	//vb_index_report.php?msg=$msg
	//echo $locaitonURL;
  ?>
  <script language="javascript">
    //alert("Sorry, you punch limit is over");
	window.location = '<?= $locaitonURL ?>';
  </script>
  <?
  }
?>
<?
/*
	  }else{
		$_SESSION["msg"] = "[$name], $EVENTALERT";
	  //--- record already exist, but record in remark
      ?>
      <script language='javascript'>
	    //str = 'Are you [<?= $name ?>] ? \nYou can not punch in today, \nbecause your attendance already in remark.';
        //alert(str);
		//alert('Are you [asdf]? You can not punch in today, because your attendance already in remark.');
        window.location = 'index.php';
      </script>
      <?

	  }
*/
?>
<?
  //********* check whether password is needed **********************
  if($mysys->passverify==1){
    $ppass = $_POST["txtPass"];
	$mycheckpass = checkTeaID(2,$pid,$ppass);
  }else{
    $mycheckpass = checkTeaID(1,$pid,"");
  }
?>
<?
  //--- correct password
  if($mycheckpass){
    $mytempuser = new CTEACHER($pid);
	$name = $mytempuser->eName;

    //********* check wherether punch in or punch out **********************
	$mychkpunch = checkPunchOUT($pid,$mynowdate);
	if($mychkpunch[0]){
      $punchIn = $mychkpunch[1];

      //--- message for punch out
        ?>
        <script language='javascript'>
          window.location = 'punchup.php?fr=<?= $fr ?>&pid=<?= $pid ?>&ty=2&tme=<?= $mynowtime ?>&dte=<?= $mynowdate ?>';
        </script>
      <?
    //--- message for punch in
    }else{
      ?>
        <script language='javascript'>
          window.location = 'punchup.php?fr=<?= $fr ?>&pid=<?= $pid ?>&ty=1&tme=<?= $mynowtime ?>&dte=<?= $mynowdate ?>';
        </script>
      <?  
    }
      unset($_SESSION["userid"]);

    
  }else{
    //--- invalid password
    header("Location: index.php?pass=1&err=2");
  }
?>