<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include('../include/session.php');
$date = $_GET['date'];
if ($date==3) { 
       $start = $_GET['day_date'];
	   $day_date = $_GET['day_date'];
}

include('../include/period_select_date.php');

$emp_id = $_GET['emp_id'];


$table_name = $_SESSION['db_prefix']."_time_sheet";
if ($emp_id == '') {
$display_query = "SELECT * FROM $table_name WHERE attendance_date >= '".$start."' AND attendance_date <= '".$end."'";
}
else {
$display_query = "SELECT * FROM $table_name WHERE emp_id = '".$emp_id."' AND attendance_date >= '".$start."' AND attendance_date <= '".$end."'";
}

if ($date == 3) {
$display_query = "SELECT * FROM $table_name WHERE attendance_date = '".$start."' ";
}

$display_result = mySQL_query($display_query);
$display_num = mysql_num_rows($display_result);

	
?>
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<!--jscript-->
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

</head>


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

if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");
?>


<div class="main_frame">
   <div class="page_head_frame">
      <table width="650" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Attendance per period</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
   </div>
      
  <div class="page_middle_frame">
<?php 
$page='attendance_list.php';
$reference_name='emp_id';
$reference=$emp_id;
include('../include/period_select_block.php');
?>
  

<div class="page_inside_frame">
<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": [[ 10, "desc" ], [ 2, "asc" ]],
					"aoColumns": [
								{"iDataSort": 10},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<table width="650" class="data_display" id="scroll_table" >
  <thead>
    <tr>
      <td>Date</td>
      <td>Emp no</td>
      <td>Name</td>
      <td>Status</td>
      <td>Zone</td>
      <td align="center">Check in</td>
      <td align="center">Check out</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </thead>
    <?php 
	
	$p=0;
	while ($p<$display_num) {
		$emp_no = mysql_result($display_result, $p, "personnel_no");
			$table_name2 = $_SESSION['db_prefix']."_employee";
			$employee_query = "SELECT emp_id, emp_first_name, emp_last_name, time_zone FROM $table_name2 WHERE emp_no ='".$emp_no."' ";
			
			$employee_result = mySQL_query($employee_query);
			$employee_num = mysql_num_rows($employee_result);	
			$employee_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
			$emp_id = mysql_result($employee_result, 0, "emp_id");
			$time_zone = mysql_result($employee_result, 0, "time_zone");
			
		$attendance_date = mysql_result($display_result, $p, "attendance_date");
		$attendance_status = mysql_result($display_result, $p, "attendance_status");
		$status_out = mysql_result($display_result, $p, "status_out");
		$time_zone = mysql_result($display_result, $p, "time_zone");
		$check_in = mysql_result($display_result, $p, "check_in");
		$check_in_min = mysql_result($display_result, $p, "check_in_min");
		$check_lunch_out = mysql_result($display_result, $p, "check_lunch_out");
		$check_lunch_out_min = mysql_result($display_result, $p, "check_lunch_out_min");
		$check_lunch_in = mysql_result($display_result, $p, "check_lunch_in");
		$check_lunch_in_min = mysql_result($display_result, $p, "check_lunch_in_min");
		$check_out = mysql_result($display_result, $p, "check_out");
		$check_out_min = mysql_result($display_result, $p, "check_out_min");
		
		$late_permission = mysql_result($display_result, $p, "late_permission");
		$late_reason = mysql_result($display_result, $p, "late_reason");
		$early_permission = mysql_result($display_result, $p, "early_permission");
		$early_reason = mysql_result($display_result, $p, "early_reason");
		$absent_permission = mysql_result($display_result, $p, "absent_permission");
		$absent_reason = mysql_result($display_result, $p, "absent_reason");
		
		$not_clocked_permission = mysql_result($display_result, $p, "not_clocked_permission");
		$not_clocked_reason = mysql_result($display_result, $p, "not_clocked_reason");
		$not_clocked_out_permission = mysql_result($display_result, $p, "not_clocked_out_permission");
		$not_clocked_out_reason = mysql_result($display_result, $p, "not_clocked_out_reason");
		
			
		$intime = mysql_result($display_result, $p, "time_zone_in");
		$outtime = mysql_result($display_result, $p, "time_zone_out");
		
		
		if (($check_out_min>0) AND ($check_in_min>0)) {
		$attendance_time = $check_out_min - $check_in_min - 60;
		$attendance_hours =  floor($attendance_time/60); 
		$attendance_mins =   $attendance_time % 60; 
		if ($attendance_hours<10) { $attendance_hours = 0 . $attendance_hours; }
		if ($attendance_mins<10) { $attendance_mins = 0 . $attendance_mins; }
		$attendance_time_display = $attendance_hours.':'.$attendance_mins;
		}
		else {
			$attendance_time_display = '--';
		}
		
		$table_name = $_SESSION['db_prefix']."_time_sheet_report";
		$report_query = "SELECT report_line FROM $table_name WHERE emp_no = '".$emp_no."' ";
		$report_result = mySQL_query($report_query);
		$report_num = mysql_num_rows($report_result);
		if ($report_num>0) {
			  $report = 'yes';
			  $line='Report:';
			  $i=0;
			  while ($i<$report_num) {
				       $line = $line.'<br>'.mysql_result($report_result, $i, "report_line");
				       $i++;
			  }
		}
		else {
			$report = 'no';
			$line='';
			}
			
		$report_TT = $line;
		$employee_TT = $employee_name.'<br>Click for details';
		$late_TT="'Permission: ".$late_permission.".<br>Reason: ".$late_reason.".'";
		$early_TT="'Permission: ".$early_permission.".<br>Reason: ".$early_reason.".'";
		$absent_TT="'Permission: ".$absent_permission.".<br>Reason: ".$absent_reason.".'";
		$not_clocked_TT="'Permission: ".$not_clocked_permission.".<br>Reason: ".$not_clocked_reason.".'";
		$not_clocked_out_TT="'Permission: ".$not_clocked_out_permission.".<br>Reason: ".$not_clocked_out_reason.".'";
		$annual_leave_TT="'Permission: Yes<br>Reason: Annual leave'";
		$sick_TT="'Permission: Yes<br>Reason: Sick'";
		
		$check_in_display = '<font color=black>'.date("H:i", strtotime($check_in)) . '</font>';
		$check_out_display = '<font color=black>'.date("H:i", strtotime($check_out)) . '</font>';
		
		if ($attendance_status=='late') {
		       $check_in_display = '<a href=# onMouseover="ddrivetip('.$late_TT.', 175)"; onMouseout="hideddrivetip()"><font color=red>'.date("H:i", strtotime($check_in)) . '</font></a>';
		}
		
		//if ($attendance_status=='Not clocked') {
//		       $check_in_display = '<a href=# onMouseover="ddrivetip('.$not_clocked_TT.', 175)"; onMouseout="hideddrivetip()"><font color=orange>'.date("H:i", strtotime($check_in)) . '</font></a>';
//		  	}
		
		if ($attendance_status=='absent') {
		      $check_in_display = '---';
			  $check_out_display = '---';
		}
		
		if ($attendance_status=='annual leave') {
		      $check_in_display = '---';
			  $check_out_display = '---';
		}
		
		if ($attendance_status=='unpaid leave') {
		      $check_in_display = '---';
			  $check_out_display = '---';
		}
		
		if ($attendance_status=='paid sick') {
		      $check_in_display = '---';
			  $check_out_display = '---';
		}
		
		if ($attendance_status=='unpaid sick') {
		      $check_in_display = '---';
			  $check_out_display = '---';
		}
		
		if ($attendance_status=='public') {
			   $attendance_status = '<font color=blue>public holiday</font>';
			   $check_in_display = '---';
			   $check_out_display = '---';
		}
		
				
		//if($check_lunch_in_min!=0) {
//		if (($check_lunch_in_min-$check_lunch_out_min)>60) {
//			$check_lunch_in = '<font color=orange>'.date("H:i", strtotime($check_lunch_in)) . '</font>';
//		}
//		else {
//			$check_lunch_in = '<font color=black>'.date("H:i", strtotime($check_lunch_in)) . '</font>';
//		}
//		}
//		else {
//			$check_lunch_in = '';
//		}
			   
			
		//if($check_out_min!=0) {
//		if ($check_out_min<$outtime) {$early=1;} else {$early=0;}
//		if ($early==1) {
//			$check_out = '<a href=# onMouseover="ddrivetip('.$early_TT.', 175)"; onMouseout="hideddrivetip()"><font color=red>'.date("H:i", strtotime($check_out)) . '</font></a>';
//			} 
//			else { 
//			$check_out = '<font color=black>'.date("H:i", strtotime($check_out)) . '</font>';
//			}
//		}
//		else { 
//		$check_out = '';
//		}
		
	   //if ($status_out=='Not clocked') {
//		       $check_out_display = '<a href=# onMouseover="ddrivetip('.$not_clocked_out_TT.', 175)"; onMouseout="hideddrivetip()"><font color=orange>'.date("H:i", strtotime($check_out)) . '</font></a>';
//		}
		
		if ($status_out=='early') {
		       $check_out_display = '<a href=# onMouseover="ddrivetip('.$early_TT.', 175)"; onMouseout="hideddrivetip()"><font color=red>'.date("H:i", strtotime($check_out)) . '</font></a>';
			   $status_out = '(early out)';
		}
		
		//if ($status_out=='Leave') {
//		       $check_out_display = '<a href=# onMouseover="ddrivetip('.$leave_TT.', 175)"; onMouseout="hideddrivetip()"><font color=blue>'.date("H:i", strtotime($check_out)) . '</font></a>';
//		}
//		
//		if ($status_out=='Sick') {
//		       $check_out_display = '<a href=# onMouseover="ddrivetip('.$sick_TT.', 175)"; onMouseout="hideddrivetip()"><font color=purple>'.date("H:i", strtotime($check_out)) . '</font></a>';
//		}

	?>	
		
	<tr>
      <td width="53"><?php echo date("d-m-Y", strtotime($attendance_date)) ?></td>
      <td width="40"><?php echo $emp_no ?></td>
      <td width="144"><a href="employee_details.php?emp_id=<?php echo $emp_id?> " onMouseover="ddrivetip('<?php echo $employee_TT?>', 150)"; onMouseout="hideddrivetip()"><?php echo $employee_name ?></a></td>
      <td width="83"><?php echo $attendance_status ?>&nbsp;&nbsp;<?php echo $status_out ?> </td>
      <td width="35" align="center"><?php echo $time_zone ?></td>
      <td width="46" align="center"><?php echo $check_in_display ?></td>
      <td width="46" align="center"><?php echo $check_out_display;?></td>
      <td width="58" align="center"><?php echo $attendance_time_display ?></td>
      
      <td width="31"><?php echo $attendance_date ?></td>
    </tr>	
		
		
	<?php	
	$p++;
	}
	?>
  </table>
</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>