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

  $phname = $_POST["hname"];
  $phfrom = $_POST["hfrom"];
  $phtill = $_POST["htill"];
  $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 = "INSERT INTO punchsys_holiday VALUES (null, '$phfrom','$phtill','$phname')";
      mysqli_query($conn,$query);
      
      header("location: main.php?pg=sys&ac=hol");
  }else{
      header("location: main.php?pg=sys&ac=hol");
  }
?>