<?php
  include "include/dbcon.php";
?>
<?php
  global $conn; 
  $teaid = $_POST["teaid"];
  $datefrom = $_POST["txtDatefrom"];
  $datetil = $_POST["txtDatefrom"];
  $eventid = $_POST["eventid"];
  $notice = $_POST["notice"];
  $status = "1";
  $apvby = $_SESSION["teacherSessionId"];
  $apvdate = $_POST["apvdate"];
?>
<?php
  if($_POST["submit"]=="SUBMIT"){
  
    $qchk = "SELECT * FROM punchsys_remarkrecord 
             WHERE staffId='$teaid' AND remarkDate='$datefrom'";
    $rchk = mysqli_query($conn,$qchk);
    $nchk = mysqli_num_rows($rchk);
  
    if($myrow = mysqli_fetch_array($rchk)){
      $query = "UPDATE punchsys_remarkrecord 
	            SET eventId='$eventid', notice='$notice'
				WHERE staffId='$teaid' AND remarkDate='$datefrom'";
    }else{
      $query = "INSERT INTO punchsys_remarkrecord VALUES
	            (NULL,'$teaid','$datefrom','$datetil','$eventid','$notice','$status','$apvby','$apvdate')";
    }
    mysqli_query($conn,$query);
  }else{
  
      $query = "DELETE FROM punchsys_remarkrecord 
				WHERE staffId='$teaid' AND remarkDate='$datefrom'";
      mysqli_query($conn,$query);

      $query = "UPDATE punchsys_punchrecord 
	            SET message=''
				WHERE staffId='$teaid' AND punchDate='$datefrom'";
      mysqli_query($conn,$query);
	
	
  }
?>
<?php
  header("location: main.php?pg=rmk&ac=tsk&dt=$datefrom");
?>