<?
  date_default_timezone_set('Asia/Kuala_Lumpur');
  $mynowdate = date("Y-m-d");
?>
<?
  include "include/CHOLIDAY.php";
  $myhol = getHoliday($mynowdate);
  if($myhol>0){
    $strHol = "[".implode(",",$myhol)."]";
  }
?>
<?
  $qtea = "SELECT * FROM xoops_adm_teacher";
  $rtea = mysql_query($qtea);
  $ntea = mysql_num_rows($rtea);
  $i=0;
  while($i<$ntea){
  
    $tname = mysql_result($rtea,$i,"ename");
	$tid = mysql_result($rtea,$i,"id");
	$arrTea[$tid] = $tname;
  
    $i++;
  }
  $tname="";
  $tid = "";
?>
<?
  $qtea2 = "SELECT * FROM xoops_adm_teacher WHERE `type`>0";
  
  $rtea2 = mysql_query($qtea2);
  $ntea2 = mysql_num_rows($rtea2);
  $i=0;
  while($i<$ntea2){
	$tid = mysql_result($rtea2,$i,"id");
	$arrTea2id[$i] = $tid;
  
    $i++;
  }
  if(count($arrTea2id)>0){
    $strTea2id=" AND staffid NOT IN ('".implode("','",$arrTea2id)."')";
  }else{
    $strTea2id="";
  }
?>
<?
  $qrmk = "SELECT * FROM xoops_pc_remarkevent";
  $rrmk = mysql_query($qrmk);
  $nrmk = mysql_num_rows($rrmk);
  $i=0;
  while($i<$nrmk){
  
    $tid = mysql_result($rrmk,$i,"id");
    $tevent = mysql_result($rrmk,$i,"event");
	$arrEvent[$tid] = $tevent;
  
    $i++;
  }
?>
<?
  $qrmkrcd = "SELECT * FROM xoops_pc_remarkrecord WHERE remarkDate='$mynowdate'";
  $rrmkrcd = mysql_query($qrmkrcd);
  $nrmkrcd = mysql_num_rows($rrmkrcd);
  $i=0;
  while($i<$nrmkrcd){
  
    $tstaffid = mysql_result($rrmkrcd,$i,"staffId");
	$teventid = mysql_result($rrmkrcd,$i,"eventId");
	$tnotice = mysql_result($rrmkrcd,$i,"notice");
	$arrEventr[$tstaffid] = $teventid;
	$arrNotice[$tstaffid] = $tnotice;
  
    $i++;
  }
?>
<?
  $query = "SELECT * FROM xoops_pc_punchrecord WHERE punchDate='$mynowdate' $strTea2id ORDER BY punchOut, punchIn DESC ";
  $result = mysql_query($query);
  $num = mysql_num_rows($result);
?>
<style>
  .dis_tbl{
  font-family:Arial;
  font-size:14px;
  width:650px;
    
  }
</style>
<center>
<table class="dis_tbl" border="1">
	<tr>
	  <th width="20px">&nbsp;</th>
	  <th width="200px"><?= $NAME ?></th>
	  <th width="95px"><?= $PUNCHIN ?></th>
	  <th width="95px"><?= $PUNCHOUT ?></th>
	  <th><?= $NOTE ?></th>
	</tr>
<?
  $i=0;
  while($i<$num){
  
    $tid = mysql_result($result,$i,"staffId");
    $tpunchIn = mysql_result($result,$i,"punchIn");
    $tpunchOut = mysql_result($result,$i,"punchOut");
    $tmessage = mysql_result($result,$i,"message");
    $tcomLate = mysql_result($result,$i,"comLate");
    $tlevEarly = mysql_result($result,$i,"levEarly");
	
	if($tcomLate==""){
	  $tcomLate = "00:00:00";
	}
	if($tlevEarly==""){
	  $tlevEarly = "00:00:00";
	}
  
	if( $tcomLate=="00:00:00" ){
	  $acolors1 = "";
	  $acolore1 = "";
	}else{
	  $acolors1 = "<font color='red'>";
	  $acolore1 = "</font>";
	}
	
	if( $tlevEarly=="00:00:00" ){
	  $acolors2 = "";
	  $acolore2 = "";
	}else{
	  $acolors2 = "<font color='red'>";
	  $acolore2 = "</font>";
	}
	
	if($arrEventr[$tid]!=""){
      $tevent = $arrEvent[ $arrEventr[$tid] ];
	  if( $arrNotice[$tid] != "" ){
        $tmsg = " - " . $arrNotice[$tid];
	  }else{
        $tmsg = "";
	  }

	}else{
	  $tevent = "";
	  $tmsg = "";
	}
	
	if($tevent==""){
	  $tmsg = $tmessage;
	}else{
	  if($tmessage!=""){
	    $tmsg = $tmsg . "; " . $tmessage;
	  }else{
	    $tmsg = $tmsg;
	  }
	}
?>
    <tr>
	  <td align="center"><?= ($num-$i) ?>.</td>
	  <td>&nbsp;<?= $arrTea[$tid] ?></td>
	  <td align="center"><?= $acolors1 . $tpunchIn . $acolore1 ?></td>
	  <td align="center"><?= $acolors2 . $tpunchOut . $acolore2 ?></td>
	  <td>&nbsp;<?= $strHol . $tevent . $tmsg ?></td>
	</tr>
<?
  
    $i++;
  }
?>
</table>
</center>
