<?
  include "../../mainfile.php";
  include "include/cfunction.php";
?>
<?
  $tea1 = $_POST["tea1"];
  $tea2 = $_POST["tea2"];
  $datefrom = $_POST["txtDatefrom"];
  $datetil = $_POST["txtDatetil"];
  $section = $_POST["section"];
  $orderby = $_POST["radOrder"];
  $pgbreak = $_POST["pgbreak"];
?>
<?
//  echo "<br>$tea1 | $tea2 | $datefrom | $datetil | $section | $orderby | $pgbreak";
?>
<?
  if($tea1!="all" && $tea2!="all"){
    $exquery = " AND id BETWEEN '$tea1' AND '$tea2'";
  }else{
    $exquery = "";
  }
  //----- teacher -----------------
  $qteat = "SELECT * FROM xoops_adm_teacher WHERE id<>'admin' $exquery";
  $rteat = mysql_query($qteat);
  $nteat = mysql_num_rows($rteat);
  $i=0;
  while($i<$nteat){
  
    $teaidt = mysql_result($rteat,$i,"id");
	$arrTeaidt[$i] = $teaidt;
    $i++;
  }
  $strTeaId = "'" . implode("','",$arrTeaidt) . "'";
  $qtea = "SELECT * FROM xoops_adm_teacher WHERE id IN ($strTeaId) ORDER BY repPrint, id";
  $rtea = mysql_query($qtea);
  $ntea = mysql_num_rows($rtea);
  $i=0;
  while($i<$ntea){
  
    $teaId = mysql_result($rtea,$i,"id");
    $teaename = mysql_result($rtea,$i,"ename");
    $teacname = mysql_result($rtea,$i,"cname");
	$teaposition = mysql_result($rtea,$i,"position");
	$arrTea[$teaId] = $teacname . " " . $teaename;
  
    $i++;
  }
?>
<?
  $qeventrcd = "SELECT * FROM xoops_pc_remarkevent";
  $reventrcd = mysql_query($qeventrcd);
  $neventrcd = mysql_num_rows($reventrcd);
  $i=0;
  while($i<$neventrcd){
  
    $eventid = mysql_result($reventrcd,$i,"id");
    $event = mysql_result($reventrcd,$i,"event");
	$arrEvent[$eventid] = $event;
  
    $i++;
  }
?>
<?
  $qremark = "SELECT * FROM xoops_pc_remarkrecord 
                WHERE staffId IN ($strTeaId)
				AND status=1
				AND remarkDate BETWEEN '$datefrom' AND '$datetil'";
  $rremark = mysql_query($qremark);
  $nremark = mysql_num_rows($rremark);
  $i=0;
  while($i<$nremark){
  
    $rdate = mysql_result($rremark,$i,"remarkDate");
	$staffId = mysql_result($rremark,$i,"staffId");
	$eventid = mysql_result($rremark,$i,"eventId");
	$notice = mysql_result($rremark,$i,"notice");
	$message = $arrEvent[$eventid] . " - " . $notice;
	
	$arrRemark[$staffId][$rdate] = $message;
  
    $i++;
  }
?>
<?
  $qpunchtime = "SELECT * FROM xoops_pc_punchrecord 
                   WHERE staffId IN ($strTeaId)
				   AND punchDate BETWEEN '$datefrom' AND '$datetil'
				   ORDER BY punchDate";
  $rpunchtime = mysql_query($qpunchtime);
  $npunchtime = mysql_num_rows($rpunchtime);
  $i=0;
  while($i<$npunchtime){
  
    $staffId = mysql_result($rpunchtime,$i,"staffId");
	$punchDate = mysql_result($rpunchtime,$i,"punchDate");
	$punchIn = mysql_result($rpunchtime,$i,"punchIn");
	$punchOut = mysql_result($rpunchtime,$i,"punchOut");
	$comeLate = mysql_result($rpunchtime,$i,"comLate");
	$levEarly = mysql_result($rpunchtime,$i,"levEarly");
	$message = mysql_result($rpunchtime,$i,"message");
	
	//--- punch in -----
	if($arrPunchIn[$staffId][$punchDate]==""){
	  $arrPunchIn[$staffId][$punchDate]=$punchIn;
	  $arrPunchOut[$staffId][$punchDate]=$punchOut;
	}
	//--- punch out ---
	if($arrPunchOut[$staffId][$punchDate]!=""){
	  $arrPunchOut[$staffId][$punchDate]=$punchOut;
	}
	//--- comeLate ---
	$arrComeLate[$staffId][$punchDate]=$comeLate;
	//--- levEarly ---
	$arrLevEarly[$staffId][$punchDate]=$levEarly;
	//--- note ----
	$arrNote[$staffId][$punchDate]=$message;
  
    $i++;
  }
?>
<?
  if($_POST["radOrder"]=="id"){
    include "rptltelyprv1.php";
  }else if($_POST["radOrder"]=="date"){
    include "rptltelyprv2.php";
  }
?>