<?php
  include "include/dbcon.php";
?>
<?php
   global $conn;

    $pid = $_POST["pid"];
    $phfrom = $_POST["hfrom"];
    $phtill = $_POST["htill"];
    $phname = $_POST["hname"];
    $valid = true;
?>
<?php
  if( $phfrom=="" ){
      $valid = false;
      $_SESSION["errmsg"] = "<span style='color: #FF0000'>#ERROR: the date is not set.</span>";
  }

  if( $phtill=="" ){
      $phtill = $phfrom;
  }else{
      if($phfrom<=$phtill){
          
      }else{
          $valid = false;
          $_SESSION["errmsg"] = "<span style='color: #FF0000'>#ERROR: invalid date.</span>";
      }
  }

  if($phname==""){
      $valid = false;
      $_SESSION["errmsg"] = "<span style='color: #FF0000'>#ERROR: the holiday name can not empty.</span>";
  }
?>
<?php
  if( $valid ){
      
      $query = "UPDATE punchsys_holiday SET holDateFm='$phfrom', holDateTo='$phtill', holDesc='$phname' WHERE id='$pid'";
      mysqli_query($conn,$query);
      
      header("location: main.php?pg=sys&ac=hol");
  }else{
      header("location: main.php?pg=sys&ac=hol&ac2=edt&pid=$pid");
  }
?>