<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["pdte"]!=""){
    $pdate = $_GET["pdte"];
  }else{
    $pdate = date("Y-m-d");
  }
?>
<center>
<form action="main.php" method="get">
<input type="hidden" name="pg" value="pch" />
<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" name="pdte" id="pdte" value="<?= $pdate ?>" 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='$pdate' 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;
  }
?>

<?
  $query = "SELECT * FROM punchsys_punchrecord WHERE punchDate='$pdate' ORDER BY punchIn";
  $result = mysqli_query($conn,$query);
  $num = mysqli_num_rows($result);
  if($num>0){
  while($myrow = mysqli_fetch_array($result)){
    $tid = $myrow["punch_Id"];
    $arrRcdstaff[$tid] = $myrow["staffId"];
    $arrRecord[$tid]["punchIn"] = $myrow["punchIn"];
	$arrRecord[$tid]["comLate"] = $myrow["comLate"];
    $arrRecord[$tid]["punchOut"] = $myrow["punchOut"];
	$arrRecord[$tid]["levEarly"] = $myrow["levEarly"];
  }
  $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"];
  }
  }
?>
    
<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="100px">PUNCH IN</th>
  <th class="mytableth" width="100px">PUNCH OUT</th>
  <th class="mytableth">REMARK</th>
  <th class="mytableth" width="35px"></th>
</tr>
    
    
  <?php
  if( count($arrTea2)>0){
  ?>
<form action="record_sav.php" id="formAdd" method="post">
<input type="hidden" name="pdate" value="<?= $pdate ?>" />
<tr align="center">
  <th class="mytableth"></th>
  <th class="mytableth">
	<select name="teaid" style="font-family:Arial; font-size:11px">
	<?
	foreach($arrTea2 as $tid=>$tename){
	  echo "<option value='$tid'>$tename</option>";
	}
	?>
	</select>
  </th>
  <td class="mytableth">
  <?
    for($i=0;$i<24;$i++){
	  if($i<10){
	    $thr="0".$i;
	  }else{
	    $thr=$i;
	  }
	  $arrHr[]=$thr;
	}
    for($i=0;$i<60;$i++){
	  if($i<10){
	    $tmin="0".$i;
	  }else{
	    $tmin=$i;
	  }
	  $arrMin[]=$tmin;
	}
  ?>
  <select name="inhr">
    <?
	foreach($arrHr as $thr){
	  ?>
	  <option value="<?= $thr ?>"><?= $thr ?></option>
	  <?
	}
	?>
  </select>:
  <select name="inmin">
    <?
	foreach($arrMin as $tmin){
	  ?>
	  <option value="<?= $tmin ?>"><?= $tmin ?></option>
	  <?
	}
	?>
  </select>
  </td>
  <td class="mytableth">
  <select name="outhr">
    <?
	foreach($arrHr as $thr){
	  ?>
	  <option value="<?= $thr ?>"><?= $thr ?></option>
	  <?
	}
	?>
  </select>:
  <select name="outmin">
    <?
	foreach($arrMin as $tmin){
	  ?>
	  <option value="<?= $tmin ?>"><?= $tmin ?></option>
	  <?
	}
	?>
  </select>
  </td>
  <td class="mytableth">...add punch record...</td>
  <td class="mytableth" align="center"><img width="20px" src="img/ico_add.png" style="cursor:pointer" onclick="addRecord()" /></td>
</tr>
</form>
    
<script>
    function addRecord(){
        document.getElementById("formAdd").submit();
    }
</script>

  <?php
  }
  ?>
    

<?
  if( count($arrRecord)>0 ){
  $i = 0;
  foreach($arrRecord as $tid=>$trecord){

    $ttea = $arrRcdstaff[$tid];
    $tpunchin = $trecord["punchIn"];
	$tcomlate = $trecord["comLate"];
    $tpunchout = $trecord["punchOut"];
	$tlevEarly = $trecord["levEarly"];
  ?>
    <form action="main.php" id="formEdit" method="get">
	<input type="hidden" name="pg" value="pch" />
	<input type="hidden" name="ac" value="edt" />
	<input type="hidden" name="hid" id="editid" value="<?= $tid ?>" />
    <tr style="color: #000000; font-size: 13px">
	  <td class="mytabletd" style="background-color: #CCCCCC;"><?= ($i+1) ?></td>
	  <td class="mytabletd2" style="background-color: #B9B9B9; text-align: left"><?= $arrTea[$ttea] ?></td>
	  <td style="background-color: #CCCCCC; text-align: center"><?= $tpunchin ?></td>
	  <td style="background-color: #B9B9B9; text-align: center"><?= $tpunchout ?></td>
	  <td class="mytabletd2" style="background-color: #CCCCCC; text-align: left">
        <?
        if($arrRmkevt[$ttea]!==""){
            echo $arrEvent[$arrRmkevt[$ttea]];
        }
        ?>
      </td>
	  <th bgcolor="#CCCCCC" align="center" style="padding: 3px"><img width="20px" src="img/ico_edit.png" style="cursor:pointer" onclick="editPunch('<?= $tid ?>')" /></th>
	</tr>
	</form>
  <?
    $i++;
  }
?>
</table>
<script>
    function editPunch(pid){
        document.getElementById("editid").value = pid;
        document.getElementById("formEdit").submit();
        
    }
</script>
    
<?
  }//if( count($arrRecord)>0 ){
?>
</center>