<?php
include("../include/session.php");
if(!$session->isAdmin() && !$session->isRadstoneReceptionUser()){
	header("Location: ../HR/employeeMenu.php");
}
else {
	include("../header.php");
	//        include("../include/db.php");
	$start = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";

	$end = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
	$empId = mysql_real_escape_string($_POST['empId']);

	//		$start = mysql_real_escape_string($_POST['startDate']);
	//		$end = mysql_real_escape_string($_POST['endDate']);
	$q = "SELECT * FROM timekeeping WHERE date >= '$start' AND date <= '$end' ORDER BY date DESC";
	if($empId != ""){
		$q = "SELECT * FROM timekeeping WHERE date >= '$start' AND date <= '$end' AND empId = '$empId' ORDER BY date DESC";
	}
	$resultLate = execsql($q);
	$num = mysql_num_rows($resultLate);
	$i = 0;

	$qry = "SELECT empId, empFName, empLName FROM employees";
	$resultEmp = execsql($qry);
	$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++;
	}
	$s = date("d-m-Y", strtotime($start));
	$e = date("d-m-Y", strtotime($end));
	?>
<h3>Showing late/absent between <?php echo $s?> and <?php echo $e?></h3>
<input type="button" value="Print" onclick="JavaScript:printPreviewDiv('top-bar');">
<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">Late/Absent</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>
		</tr>
	</thead>
	<tbody>
	<?php
	$i = 0;
	while($i < $num){
		$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");
		$b7 = mysql_result($resultLate, $i, "absent");
		// 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 $b7?></td>
			<td><?php echo $permission?></td>
			<td><a href="editComment.php?id=<?php echo $b6?>&type=timekeeping"><?php echo $b3?></a></td>
			<td><?php echo $b4?></td>
			<td><?php echo date("d-m-Y", strtotime($b5))?></td>
		</tr>
		<?php
		$i++;
	}
	?>
	</tbody>
</table>

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