<?
  include "include/dbcon.php";
  include "include/CSYSTEM.php";
  include "include/CPCSETTING.php";
  include "include/cfunction.php";
//  include "../admsys/include/CSYSTEM.php";
  include "include/CHOLIDAY.php";

?>
<?
  $teaid = $_POST["tea1"];
  $datefrom = $_POST["txtDatefrom"];
  $datetil = $_POST["txtDatetil"];
  $ord = $_POST["ord"];
  $pbrk = $_POST["pbrk"];
  $clp = $_POST["clp"];
  $shw = $_POST["shw"];
  $teaids = str_replace("\'","'",$_POST["teaids"]);
  $arrTeaid = explode(",",$teaids);
  //$strTeaid = "'".implode("','",$arrTeaid)."'";
  $strTeaid = $teaids;
  $style = $_POST["style"];
  $highlight = $_POST["highlight"];
  $pchkSec = $_POST["chkSec"];
  $strSecid = "'".implode("','",$pchkSec)."'";
  
  if( $pchkSec[0] !=""){
	  if($teaid!="_s"){
		$exquery = " AND staffId='$teaid' ";
		$exquery2 = " AND id='$teaid' ";
	  }else{
	    $exquery = "";
		$exquery2 = "";
	  }
  }else{
	  if($teaid!="_s"){
		$exquery = " AND staffId='$teaid' ";
		$exquery2 = " AND id='$teaid' ";
	  }else{
	    $exquery = "";
		$exquery2 = " AND section IN ($strSecid)";
	  }
  }

  
  $mysys = new CSYSTEM();
  $mypcsetting = new CPCSETTING();
?>
<?
  function add_date($pdate,$pday){ 
    $tdate = strtotime($pdate); 
    $retDAY = date('Y-m-d', mktime(0,0,0,date('m',$tdate) , (date('d',$tdate)+$pday) , date('Y',$tdate))); 
    return $retDAY; 
  }
?>
<?
  function convertDateFor($pdate){
      $arrDate = explode("-",$pdate);
      return $arrDate[2] . "-" . $arrDate[1] . "-" . $arrDate[0];
  }
?>
<?
  if($shw=='0'){
    unset($arrTeaid);
    $qtea0 = "SELECT DISTINCT staffId FROM punchsys_punchrecord WHERE punchDate BETWEEN '$datefrom' AND '$datetil'";
    $rtea0 = mysqli_query($conn,$qtea0);
    $ntea0 = mysqli_num_rows($rtea0);
	$i=0;
	while($myrow = mysqli_fetch_array($rtea0)){
	
	  $arrTeaid[] = $myrow["staffId"];
	
	  $i++;
	}
	$strTeaid = "'".implode("','",$arrTeaid)."'";
	
    $exquery = "";
	$exquery2 = "";
	
  }
?>
<?
  $qtea = "SELECT * FROM punchsys_staff WHERE id IN ($strTeaid) $exquery2 AND userID<>'1' ORDER BY repPrint, CAST(id as SIGNED)";
  $rtea = mysqli_query($conn,$qtea);
  $ntea = mysqli_num_rows($rtea);
  $i=0;
  while($myrow = mysqli_fetch_array($rtea)){
  
    $tid = $myrow["id"];
	$tname = $myrow["eName"];
  
    $arrTea[$tid] = $tname;
  
    $i++;
  }
?>
<?
  $qrmk = "SELECT * FROM punchsys_remarkevent";
  $rrmk = mysqli_query($conn,$qrmk);
  $nrmk = mysqli_num_rows($rrmk);
  $i=0;
  while($myrow = mysqli_fetch_array($rrmk)){
  
    $tid = $myrow["id"];
    $tevent = $myrow["event"];
	$arrEvent[$tid] = $tevent;
  
    $i++;
  }
?>
<?
  $qrcd = "SELECT * FROM punchsys_punchrecord WHERE punchDate BETWEEN '$datefrom' AND '$datetil' AND staffid IN ($strTeaid) $exquery";
  $rrcd = mysqli_query($conn,$qrcd);
  $nrcd = mysqli_num_rows($rrcd);
  $i = 0;
  while($myrow = mysqli_fetch_array($rrcd)){
  
    $tteaid = $myrow["staffId"];
	$tpdate = $myrow["punchDate"];
	$tpunchIn = $myrow["punchIn"];
	$tpunchOut = $myrow["punchOut"];
	$tmessage = $myrow["message"];
	$tcomLate = $myrow["comLate"];
	$tlevEarly = $myrow["levEarly"];
	
	$arrPunchintime[$tpdate][$tteaid] = $tpunchIn;
	$arrPunchouttime[$tpdate][$tteaid] = $tpunchOut;
	$arrComlate[$tpdate][$tteaid] = $tcomLate;
	$arrLevearly[$tpdate][$tteaid] = $tlevEarly;
	$arrMessage[$tpdate][$tteaid] = $tmessage;
  
    $i++;
  }
?>
<?
  $qrmk = "SELECT * FROM punchsys_remarkrecord WHERE remarkDate BETWEEN '$datefrom' AND '$datetil' AND status='1' AND staffid IN ($strTeaid) $exquery";
  $rrmk = mysqli_query($conn,$qrmk);
  $nrmk = mysqli_num_rows($rrmk);
  $i = 0;
  while($myrow = mysqli_fetch_array($rrmk)){
  
    $tteaid = $myrow["staffId"];
    $tpdate = $myrow["remarkDate"];
	$teventid = $myrow["eventId"];
	$tnotice = $myrow["notice"];

	$arrRemark[$tpdate][$tteaid] = $tnotice;
	$arrRemarkEvent[$tpdate][$tteaid] = $teventid;
  
    $i++;
  }
?>
<?
  if($ord=="date"){
    if($style=="1"){
      include "rptltely1_prvd.php";
	}else{
      include "rptltely1_prvd2.php";
	}
  }else{
    include "rptltely1_prvt.php";
  }
?>