
<!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" />

<?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']);
	
	
	if ($date==1) {
	$day = mysql_real_escape_string($_GET['date1']);
	}
	else {
	$day = date("Y-m-d");
	}
		
	$d = date("d", strtotime($day) );
	$m = date("m", strtotime($day) );
	$y = date("Y", strtotime($day) );
	
	
$table_name2 = $_SESSION['db_prefix']."_time_record";
$presence_query = "SELECT emp_id, clock_in, clock_out, status, w_min, permission, reason, reason2  FROM $table_name2 WHERE date = '".$day."'  ";
$presence_result = mySQL_query($presence_query);
$presence_num = mysql_num_rows($presence_result);


?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="javascript" src="../jscript/calendar.js"></script>
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								
								 ]
				} );
			} );
		</script>
</head>

<body>
<?php include ('../include/tooltip.php'); ?>


<div class="main_frame">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="125" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Present by day</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">
  <form action="presence_list.php" method="get" name="dateform" class="today" id="dateform">
  
    <table width="690"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select a day to display</label></td>
        <td width="37" valign="middle">&nbsp;</td>
        <td width="254" valign="middle">&nbsp;</td>
        <td valign="middle">&nbsp;</td>
      </tr>
      <tr>
        <td width="34" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="48" valign="middle"><label class="label_std">  from:</label> </td>
        <td colspan="3" valign="middle"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
	 	$myCalendar->writeScript();?>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" />
          <input name="date" type="hidden" id="date" value="1" /></td>
        <td width="194" valign="middle">&nbsp;&nbsp;</td>
      </tr>
    </table>
  </form>
  </div>
</td> <!--center of tableMain-->
</tr>
<tr>
<td> <!--center of tableMain-->
<div class="page_middle_frame">
<table width="669" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>No</th>
    <th>Name</th>
    <th>Department</th>
    <th>Start</th>
    <th>End</th>
    <th>Recorded</th>
    <th>Status</th>
    <th>Permission</th>
    <th>Reason</th>
    </tr>
    </thead>
<?php 
$i=0;
$a4tot=0;
$a4totaal='';
while ($i<$presence_num) {
	
	$a1 = mysql_result($presence_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_no, emp_first_name, emp_last_name, department, time_keeping  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");
		$a10 = mysql_result($employee_result, 0, "time_keeping");
		$a1b = mysql_result($employee_result, 0, "emp_no");
		
	$a2 = mysql_result($presence_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 ;
		   if ($a2a=='00:00') { $a2a=''; }
	$a3 = mysql_result($presence_result, $i, "clock_out");
		   $hours =  floor($a3/60); 
		   $mins =   $a3 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a3a = $hours . ":" . $mins ;
			if ($a3a=='00:00') { $a3a=''; }
	
		
	$a4 = mysql_result($presence_result, $i, "w_min");
		   $hours =  floor($a4/60); 
		   $mins =   $a4 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a4a = $hours . ":" . $mins ;
		   if ($a4a=='00:00') { $a4a=''; }
	
	$a4tot= $a4tot+$a4;
	       $hours =  floor($a4tot/60); 
		   $mins =   $a4tot % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a4totaal = $hours . ":" . $mins ;
	
	$a5 = mysql_result($presence_result, $i, "status");
	if ($a5=="P") {$a5="";}
	if ($a5=="L") {$a5="late";}
	if ($a5=="U") {$a5="unknown";}	
	if ($a5=="A") {$a5="absent";}
	if ($a5=="E") {$a5="early dismiss";}
	if ($a5=="S") {$a5="sick";}
	
	$a11 = mysql_result($presence_result, $i, "permission");
	$a6 = mysql_result($presence_result, $i, "reason");
	$a9 = mysql_result($presence_result, $i, "reason2");
	if ($a6!="") { $a9 = " / ".$a9 ;}	   
		
	//$a5 = $a2 + $a3 + $a4;	
//	       $hours =  floor($a5/60); 
//		   $mins =   $a5 % 60; 
//		   $a5a = $hours . " Hrs " . $mins . " Min ";
		   
     
	
	?>
  
  <tr>
    <td width="64" align="left"><?php echo $a1b ?></td>
    <td width="118" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>" onMouseover="ddrivetip(' Click for employee details.', 150)"; onMouseout="hideddrivetip()"><?php echo $a1a ?></a></td>
    <td width="93" align="left"><?php echo $a7 ?></td>
    <td width="45" align="left"><?php  echo $a2a ?></td>
    <td width="41" align="left"><?php  echo $a3a ?></td>
    <td width="67" align="right"><?php echo $a4a ?></td>
    <td width="50" align="left"><?php echo $a5 ?></td>
    <td width="73" align="left"><?php echo $a11 ?></td>
    <td width="78" align="left"><?php echo $a6 ?><?php echo $a9 ?></td>
    </tr>
  
  <?php
  $i++;
}
?>
<tfoot>
    <tr>
      <td align="left">&nbsp;</td>
      <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td colspan="2" align="right">Total hours:</td>
    <td align="right"><?php echo $a4totaal ?></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
  </tfoot>
</table>
<div align="left"><label class="label_end">end of list</label></div>
</div></td>
</tr>
</table>  <!--end of tableMain-->
  
</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>