<?
  include "include/dbcon.php";
  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 punchsys_staff";
  $rtea = mysqli_query($conn,$qtea);
  $ntea = mysqli_num_rows($rtea);
  $i=0;
  while($myrow = mysqli_fetch_array($rtea)){
  
    $tname = $myrow["eName"];
	$tid = $myrow["id"];
	$arrTea[$tid] = $tname;
  
    $i++;
  }
  $tname="";
  $tid = "";
?>
<?
  //pasive staff
  $qtea2 = "SELECT * FROM punchsys_staff WHERE userID='1'";
  $rtea2 = mysqli_query($conn,$qtea2);
  $ntea2 = mysqli_num_rows($rtea2);
  $i=0;
  while($myrow = mysqli_fetch_array($rtea2)){
	$tid = $myrow["id"];
	$arrTea2id[$i] = $tid;
  
    $i++;
  }
  if(count($arrTea2id)>0){
    $strTea2id=" AND staffid NOT IN ('".implode("','",$arrTea2id)."')";
  }else{
    $strTea2id="";
  }
?>
<?
  $qrmk = "SELECT * FROM punchsys_remarkevent";
  $rrmk = mysqli_query($conn,$qrmk);
  $nrmk = mysqli_num_rows($rrmk);
  $i=0;
  if($nrmk>0){
  while($myrow = mysqli_fetch_array($rrmk)){
  
    $tid = $myrow["id"];
    $tevent = $myrow["event"];
	$arrEvent[$tid] = $tevent;
  
    $i++;
  }
  }
?>
<?
  $qrmkrcd = "SELECT * FROM punchsys_remarkrecord WHERE remarkDate='$mynowdate'";
  $rrmkrcd = mysqli_query($conn,$qrmkrcd);
  $nrmkrcd = mysqli_num_rows($rrmkrcd);
  if($nrmkrcd>0){
  while($i<$nrmkrcd){
  
    $tstaffid = $myrow["staffId"];
	$teventid = $myrow["eventId"];
	$tnotice = $myrow["notice"];
	$arrEventr[$tstaffid] = $teventid;
	$arrNotice[$tstaffid] = $tnotice;
  
  }
  }
?>
<?
  $query = "SELECT * FROM punchsys_punchrecord WHERE punchDate='$mynowdate' $strTea2id ORDER BY punchOut, punchIn DESC ";
  $result = mysqli_query($conn,$query);
  $num = mysqli_num_rows($result);
?>
<html>
<head>

<style>
  .dis_tbl{
  font-family:Arial;
  font-size:14px;
  border-collapse:collapse;
  }
</style>

</head>
<body bgcolor="#000000">
<center>
<table class="dis_tbl" border="1">
	<tr bgcolor="#999999">
	  <th width="20px">&nbsp;</th>
	  <th width="450px">NAME</th>
	  <th width="100px">PUNCH IN</th>
	  <th width="100px">PUNCH OUT</th>
	</tr>
<?
  $i=0;
  if($num>0){
  while($myrow = mysqli_fetch_array($result)){
  
    $tid = $myrow["staffId"];
    $tpunchIn = $myrow["punchIn"];
    $tpunchOut = $myrow["punchOut"];
    $tmessage = $myrow["message"];
    $tcomLate = $myrow["comLate"];
    $tlevEarly = $myrow["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 bgcolor="#CCCCCC">
	  <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>
	</tr>
<?
  
    $i++;
  }
  }
?>
</table>
</center>
