<style>
  .mytable{
    font-size:16px;
	width:700px;
	margin-top:10px;
	color:#FFFFFF;
  }
  
  .mytableth{
    background-color:#000000;
	color:#FFCC00;
	padding:5px 5px 5px 5px;
  }
  
    .mytabletd{
        background-color: #EEEEEE;
        text-align: center;
        color: #000000;
    }
    
    .mytabletd2{
        padding-left: 10px;
    }
    
  .mybtn{
    width:100px;
	font-size:14px;
	font-weight: bold;
	font-family: Arial;
    color: #0000FF;
  }
    
  .mytext{
    text-align: center;
    padding: 3px;
  }
</style>

<?
  if($_GET["dt"]!=""){
    $today_date=$_GET["dt"];
  }else{
    $today_date = date("Y-m-d");
  }
?>

<center>
<form action="main.php" method="get">
<input type="hidden" name="pg" value="rmk" />
<input type="hidden" name="ac" value="tsk" />
<table border="0" cellpadding="0" cellspacing="1" class="mytable">
  <tr>
      <th class="mytableth" style="text-align: right; padding-right: 10px; width: 40%">DATE : </th>
      <td class="mytableth">
        <input type="date" id="txtDate" name="dt" size="9" value="<?= $today_date ?>" onchange="this.form.submit()">
        <input type="submit" value="SUBMIT" />
  </td>
  </tr>
</table>
</form>
    
    

<?
  $qtea = "SELECT * FROM punchsys_staff WHERE id NOT IN ('admin','pejabat') AND  userID<>'1'";
  $rtea = mysqli_query($conn,$qtea);
  $ntea = mysqli_num_rows($rtea);
  while($myrow = mysqli_fetch_array($rtea)){
	$tid = $myrow["id"];
	$arrTea[$tid] = substr($myrow["eName"],0,24);
  }
?> 
<?
  $qevt = "SELECT * FROM punchsys_remarkevent";
  $revt = mysqli_query($conn,$qevt);
  $nevt = mysqli_num_rows($revt);
  while($myrow = mysqli_fetch_array($revt)){
    $tid = $myrow["id"];
	$arrEvent[$tid]=$myrow["event"];
  }
?>
    
<?
  $qrmk = "SELECT * FROM punchsys_remarkrecord WHERE remarkDate='$today_date' AND status='1'";
  $rrmk = mysqli_query($conn,$qrmk);
  $nrmk = mysqli_num_rows($rrmk);
  while($myrow = mysqli_fetch_array($rrmk)){
    $tstaffid = $myrow["staffId"];
	$teventid = $myrow["eventId"];
	$tnotice = $myrow["notice"];
	
	$arrRmkevt[$tstaffid]=$teventid;
	$arrRmkntc[$tstaffid]=$tnotice;
  }
?>
<?
  $qrecord = "SELECT * FROM punchsys_punchrecord WHERE punchDate='$today_date' ORDER BY punchIn";
  $rrecord = mysqli_query($conn,$qrecord);
  $nrecord = mysqli_num_rows($rrecord);
  if($nrecord>0){
  while($myrow = mysqli_fetch_array($rrecord)){
      $tid = $myrow["punch_Id"];
      $tstaffid = $myrow["staffId"];
      
      $arrRcdstaff[$tid] = $tstaffid;
      $arrRcdin[$tid] = $myrow["punchIn"];
      $arrRcdout[$tid] = $myrow["punchOut"];

  }
  $strStaffid0 = "'".implode("','",$arrRcdstaff)."'";
  }else{
      $strStaffid0 = "''";
  }
?>
    
<?
  $qtea2 = "SELECT * FROM punchsys_staff WHERE id NOT IN ('admin','pejabat') AND userID<>'1' AND id NOT IN ($strStaffid0) ORDER BY ename";
  $rtea2 = mysqli_query($conn,$qtea2);
  $ntea2 = mysqli_num_rows($rtea2);
  if($ntea2>0){
  while($myrow = mysqli_fetch_array($rtea2)){
      $arrTea2[$myrow["id"]] = $myrow["eName"];
  }
  }
?>
    
<?
//--- display pending request -----------
?>
<table border="0" cellpadding="0" cellspacing="1" class="mytable">
  <tr>
    <th class="mytableth" width="15px"></th>
    <th class="mytableth" width="200px">STAFF</th>
	<th class="mytableth" width="60px">PUNCH IN</th>
	<th class="mytableth" width="60px">PUNCH OUT</th>
	<th class="mytableth">REMARK</th>
	<th class="mytableth" width="35px"></th>
  </tr>
    
  <?php
  if( count($arrTea2)>0){
  ?>
  <form action="main.php" id="formAdd" method="get">
  <input type="hidden" name="pg" value="<?= $_GET["pg"] ?>">
  <input type="hidden" name="ac" value="tsk22">
  <input type="hidden" name="pdate" value="<?= $today_date ?>">
  <tr align="center">
    <th class="mytableth"></th>
    <td class="mytableth">
	<select name="teaid" style="font-family:Arial; font-size:11px">
	<?
	foreach($arrTea2 as $tid=>$tename){
	  echo "<option value='$tid'>$tename</option>";
	}
	?>
	</select>
	</td>
	<td class="mytableth">00:00:00</td>
	<td class="mytableth">00:00:00</td>
	<td class="mytableth">...add remark...</td>
	<td class="mytableth" align="center"><img width="20px" src="img/ico_add.png" style="cursor:pointer" onclick="addRemark()" /></td>
  </tr>
  </form>
    
<script>
    function addRemark(){
        document.getElementById("formAdd").submit();
    }
</script>
    
    <?
  }
 ?>
    
<?
  $i=1;
  if($nrecord>0){
  foreach($arrRcdstaff as $tid=>$tstaffid){
    //$tid = $myrow["punch_Id"];
	$teaid = $tstaffid;
	$punchin = $arrRcdin[$tid];
	$punchout = $arrRcdout[$tid];
	
    if($arrRmkevt[$teaid]!=""){
	  $remark = $arrEvent[$arrRmkevt[$teaid]] . " - " . $arrRmkntc[$teaid];
	}else{
	  $remark = "&nbsp;";
	}
?>
  <form id="formEdit" action="main.php" method="get">
    <input type="hidden" name="pg" value="<?= $_GET["pg"] ?>">
    <input type="hidden" name="ac" value="tsk2">
    <input type="hidden" id="editid" name="pid" value="">
  <tr style="color: #000000; font-size: 13px">
    <td class="mytabletd" style="background-color: #CCCCCC;"><?= $i ?></td>
    <td class="mytabletd2" style="background-color: #B9B9B9; text-align: left"><?= $arrTea[$teaid] ?></td>
	<td style="background-color: #CCCCCC; text-align: center"><?= $punchin ?></td>
	<td style="background-color: #B9B9B9; text-align: center"><?= $punchout ?></td>
	<td class="mytabletd2" style="background-color: #CCCCCC; text-align: left"><?= $remark ?>&nbsp;</td>
	<td bgcolor="#B9B9B9" align="center" style="padding: 3px"><img width="20px" src="img/ico_edit.png" style="cursor:pointer" onclick="editRemark('<?= $tid ?>')" /></td>
  </tr>
  </form>
<?
    $i++;
  }
?>
<script>
    function editRemark(pid){
        document.getElementById("editid").value = pid;
        document.getElementById("formEdit").submit();
    }
</script>
<?
  }//if($nrecord>0){
?>
  
</table>
</center>