<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="../jscript/calendar.js"></script>


<?php
include ("../navigation/header.php");
$page_name = "HR-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");
?>
<?php
require_once('../include/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	include ("../include/date_set.php");
	
	
	
$table_name2 = $_SESSION['db_prefix']."_time_record";
$late_query = "SELECT emp_id, clock_in, clock_out, status, reason, date, permission FROM $table_name2 WHERE date >= '".$start."' AND date <= '".$end."' AND status = 'L' ORDER BY date DESC ";
$late_result = mySQL_query($late_query);
$late_num = mysql_num_rows($late_result);

$table_name2 = $_SESSION['db_prefix']."_time_record";
$early_query = "SELECT emp_id, clock_in, clock_out, status, reason2, date, permission FROM $table_name2 WHERE date >= '".$start."' AND date <= '".$end."' AND status_2 = 'E' ORDER BY date DESC ";
$early_result = mySQL_query($early_query);
$early_num = mysql_num_rows($early_result);

$table_name2 = $_SESSION['db_prefix']."_time_record";
$absent_query = "SELECT emp_id, clock_in, clock_out, status, reason, date, permission  FROM $table_name2 WHERE date >= '".$start."' AND date <= '".$end."' AND (status = 'A' OR status = 'U' OR status = 'S') ORDER BY date DESC ";
$absent_result = mySQL_query($absent_query);
$absent_num = mysql_num_rows($absent_result);

?>

<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="javascript" src="../jscript/calendar.js"></script>


</head>

<body>

<div class="main_frame" style="height:auto; min-height:500px;">
<div class="page_head_frame">
        
    <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Late / absent</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
        <br />
<br />
<br />
<br />
<div class="page_middle_frame"> 
<div class="page_inside_frame" style="width:670px;"> 
  <form action="late_absent_list.php" method="get" name="dateform" class="today" id="dateform">
 <table width="650"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select time period to display</label></td>
        <td valign="middle">&nbsp;</td>
        <td valign="middle">&nbsp;</td>
        <td valign="middle">&nbsp;</td>
      </tr>
      <tr>
        <td width="15" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="40" valign="middle"><label class="label_std">  from:</label> </td>
        <td width="238" valign="middle"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
	 	$myCalendar->writeScript();?></td>
        <td width="24" valign="middle"><label class="label_std">to:</label></td>
        <td width="233" valign="middle"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		$myCalendar->writeScript();?></td>
        <td width="102" valign="middle">&nbsp;&nbsp;
          <label>
            <input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" />
            <input name="date" type="hidden" id="date" value="1" />
          </label></td>
      </tr>
    </table>
  </form>
</div>  

<div class="scroll_frame_medium" style="height:200px;  width:670px;"> Late this period:
  <table width="650" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "   >
    <tr>
      <th class="sortable-date-dmy">date</th>
      <th class="sortable-text">name</th>
      <th class="sortable-text">department</th>
      <th >clock-in</th>
      <th colspan="2" class="sortable-text">reason /permission</th>
      </tr>
    <?php 
$i=0;

while ($i<$late_num) {
	
	$a1 = mysql_result($late_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $a1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$a7 = mysql_result($employee_result, 0, "department");
		$a2 = mysql_result($late_result, $i, "clock_in");
		   $hours =  floor($a2/60); 
		   $mins =   $a2 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a2a = $hours . ":" . $mins ;
		$a8 = mysql_result($late_result, $i, "date");
		$a6 = mysql_result($late_result, $i, "reason");
		$a9 = mysql_result($late_result, $i, "permission");
  
	?>
    <tr>
      <td width="72" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo date("d-m-Y", strtotime($a8 ))  ?></a></td>
      <td width="187" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo $a1a ?></a></td>
      <td width="133" align="left"><?php echo $a7 ?></td>
      <td width="71" align="left"><?php  echo $a2a ?></td>
      <td width="153" align="left"><?php echo $a6 ?></td>
      <td width="40" align="left"><?php echo $a9  ?></td>
      </tr>
    <?php
  $i++;
}
?>
</table>
  <div align="left">
    <label class="label_end">end of list</label>
  </div>
</div> 
 
<div class="scroll_frame_medium" style="height:200px;  width:670px;">
Absent this period:
  <table width="650" id="table_list_2" class="sortable-onload-0 rowstyle-alt no-arrow "  >
  <tr>
    <th class="sortable-text">date</th>
    <th class="sortable-text">name</th>
    <th class="sortable-text">department</th>
    <th colspan="2" class="sortable-text">reason/permission</th>
    </tr>
<?php 
$i=0;

while ($i<$absent_num) {
	
	$b1 = mysql_result($absent_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $b1 ";
		$employee_result = mySQL_query($employee_query);
        $b1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$b7 = mysql_result($employee_result, 0, "department");
	$b6 = mysql_result($absent_result, $i, "reason");
	$b8 = mysql_result($absent_result, $i, "date");
	$b9 = mysql_result($absent_result, $i, "permission");
	?>
  
  <tr>
    <td width="66" align="left"><a href="employee-details.php?emp_id=<?php echo $b1?>"><?php echo date("d-m-Y", strtotime($b8 ))  ?></a></td>
    <td width="193" align="left"><a href="employee-details.php?emp_id=<?php echo $b1?>"><?php echo $b1a ?></a></td>
    <td width="95" align="left"><?php echo $b7 ?></td>
    <td width="266" align="left"><?php echo $b6 ?></td>
    <td width="36" align="left"><?php echo  $b9 ?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
<div align="left"><label class="label_end">end of list</label></div>
</div>
<div class="scroll_frame_medium" style="height:100px; width:670px;"> Early departure this period:
  <table width="650" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "   >
    <tr>
      <th class="sortable-date-dmy">date</th>
      <th class="sortable-text">name</th>
      <th class="sortable-text">department</th>
      <th >clock-out</th>
      <th colspan="2" class="sortable-text">reason/permission</th>
      </tr>
    <?php 
$i=0;

while ($i<$early_num) {
	
	$a1 = mysql_result($early_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $a1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$a7 = mysql_result($employee_result, 0, "department");
		$a2 = mysql_result($early_result, $i, "clock_out");
		   $hours =  floor($a2/60); 
		   $mins =   $a2 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a2a = $hours . ":" . $mins ;
		$a8 = mysql_result($early_result, $i, "date");
		$a6 = mysql_result($early_result, $i, "reason2");
		$a9 = mysql_result($early_result, $i, "permission");
  
	?>
    <tr>
      <td width="68" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo date("d-m-Y", strtotime($a8 ))  ?></a></td>
      <td width="190" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>"><?php echo $a1a ?></a></td>
      <td width="106" align="left"><?php echo $a7 ?></td>
      <td width="68" align="left"><?php  echo $a2a ?></td>
      <td width="184" align="left"><?php echo $a6 ?></td>
      <td width="36" align="left"><?php echo $a9 ?></td>
      </tr>
    <?php
  $i++;
}
?>
</table>
  <div align="left">
    <label class="label_end">end of list</label>
  </div>
</div> 
</div>
  
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "hr_module/hr_main.php?date=";	
include ("../navigation/hr_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</html>