<?php

include("../include/session.php");
if(!$session->isAdmin() && !$session->isRadstoneReceptionUser()){
		header("Location: ../Store/productionMenu.php");
}else{
    
//include("../include/db.php");
	include("../reportHeader.php");
$dStart = date("Y-m-d", mktime(0, 0, 0, date("m")-6, date("d"), date("Y")));
$dEnd = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")+1, date("Y")));


	$queryLate = "SELECT * FROM nam_timekeeping WHERE date > '".$dStart."' AND date < '".$dEnd."' ORDER BY date DESC";
	$resultLate = execsql($queryLate);
	$numLate = mysql_num_rows($resultLate);

	$q = "SELECT empId, empFName, empLName FROM nam_employees";
	$resultEmp = execsql($q);
	$numEmp = mysql_num_rows($resultEmp);
	$j = 0;
	$empArray = array();
	while($j < $numEmp){
		$empArray[mysql_result($resultEmp, $j, "empId")] = mysql_result($resultEmp, $j, "empFName") ." ". mysql_result($resultEmp, $j, "empLName");
		$j++;
	}
	

?>
<script type="text/javascript" src="../include/tablesort.js"></script>
<h3>Employees late in the last 6 months</h3>

<table id="test1" cellpadding="0" cellspacing="0" border="0" class="rowstyle-alt colstyle-alt no-arrow">
    <thead>
      <tr>
        <th class="sortable-text">Employee Name</th>
        <th class="sortable-text">Permission</th>
        <th class="sortable-text">Details</th>
        <th class="sortable-numeric">Hours</th>
        <th class="sortable-date-ymd">Date</th>
        <th>Delete?</th>
      </tr>
    </thead>
    <tbody>
<?php
    $i = 0;
    while($i < $numLate){

       $b1 = mysql_result($resultLate, $i, "empId");
       $b2 = mysql_result($resultLate, $i, "permission");
       if($b2 < 1){
           $permission = "No";
       }else {
           $permission = "Yes";
       }
       $b3 = mysql_result($resultLate, $i, "details");
       $b4 = mysql_result($resultLate, $i, "hours");
       $b5 = mysql_result($resultLate, $i, "date");
       $b6 = mysql_result($resultLate, $i, "timeId");
      // echo "<tr><td class="sortable-numeric">$b1</td><td>$b2</td><td>$permission</td><td>$b4</td><td>$b5</td><td>$b6</td></tr>";
      // $i++;
   // }
?>
		<tr class="alt">
        <td><a href="../HR/searchAndDisplayE.php?id=<?php echo $b1?>"><?php echo $empArray[$b1] ?></a></td>
        <td><?php echo $permission?></td>
        <td><?php echo $b3?></td>
        <td><?php echo $b4?></td>
        <td><?php echo $b5?></td>
        <td><a href="deleteLate.php?id=<?php echo $b6?>">Delete</a></td>
        </tr> 
<?php
    $i++;
    }
?>
</tbody>
</table>

<?php
    include "../footer.html";
}
?>
