<?
  include "include/dbcon.php";
//  include "include/cfunction.php";
  include "include/CSYSTEM.php";
?>
<?
  $teaid = $_POST["tea1"];
  $datefrom = $_POST["txtDatefrom"];
  $datetil = $_POST["txtDatetil"];
  $ord = $_POST["ord"];
  $pbrk = $_POST["pbrk"];
  $teaids = str_replace("\\","",$_POST["teaids"]);
  $arrTeaid = explode(",",$teaids);
//  $strTeaid = "'".implode("','",$arrTeaid)."'";
  $rmk = $_POST["rmk"];
  
  $mysys = new CSYSTEM();
?>
<?
  function convertDateFor($pdate){
      $arrDate = explode("-",$pdate);
      return $arrDate[2] . "-" . $arrDate[1] . "-" . $arrDate[0];
  }
?>
<?
  $qtea = "SELECT * FROM punchsys_staff WHERE id NOT IN ('admin','pejabat') ORDER BY repPrint, id";
  $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 xoops_pc_punchrecord WHERE punchDate BETWEEN '$datefrom' AND '$datetil' AND staffid IN ($strTeaid) $exquery";
  $rrcd = mysql_query($qrcd);
  $nrcd = mysql_num_rows($rrcd);
  $i = 0;
  while($i<$nrcd){
  
    $tteaid = mysql_result($rrcd,$i,"staffid");
	$tpdate = mysql_result($rrcd,$i,"punchDate");
	$tpunchIn = mysql_result($rrcd,$i,"punchIn");
	$tpunchOut = mysql_result($rrcd,$i,"punchOut");
	
	$tcomLate = mysql_result($rrcd,$i,"comLate");
	$tlevEarly = mysql_result($rrcd,$i,"levEarly");
	
	$arrPunchintime[$tpdate][$tteaid] = $tpunchIn;
	$arrPunchouttime[$tpdate][$tteaid] = $tpunchOut;
	$arrComlate[$tpdate][$tteaid] = $tcomLate;
	$arrLevearly[$tpdate][$tteaid] = $tlevEarly;
  
    $i++;
  }
*/
  if($rmk!=="a"){
    $exquery = " AND eventId='$rmk'";
  }else{
    $exquery = "";
  }

  if($teaid!=="a"){
    $exquery .= " AND staffId='$teaid'";
  }else{
      $exquery .= "";
  }

  $qrcd = "SELECT * FROM punchsys_remarkrecord WHERE remarkDate BETWEEN '$datefrom' AND '$datetil' $exquery ORDER BY remarkDate";
  $rrcd = mysqli_query($conn,$qrcd);
  $nrcd = mysqli_num_rows($rrcd);
  $i=0;
  while($myrow = mysqli_fetch_array($rrcd)){
  
    $tteaid = $myrow["staffId"];
    $tdate = $myrow["remarkDate"];
    $tnotice = $myrow["notice"];
	$tevent = $myrow["eventId"];

    $arrRcd[$tteaid][$tdate]["notice"] = $tnotice;
    $arrRcd[$tteaid][$tdate]["event"] = $tevent;

    $i++;
  }
?>
<?
/*
  $qrmk = "SELECT * FROM xoops_pc_remarkrecord WHERE remarkDate BETWEEN '$datefrom' AND '$datetil' AND status='1' AND staffid IN ($teaids) $exquery";
echo $qrmk;
  $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"){
    include "rptltely2_prvd.php";
//  }else{
//    include "rptltely2_prvt.php";
//  }
?>