<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

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

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "AD-tracking";
include ("../navigation/access.php");
include('../include/period_select_date.php');

	
$table_name2 = $_SESSION['db_prefix']."_tracking_hr";
$tracking_query = "SELECT * FROM $table_name2 WHERE entry_date >= '".$start."' AND entry_date <= '".$end."' ";
$tracking_result = mySQL_query($tracking_query);
$tracking_num = mysql_num_rows($tracking_result);
?>

</head>

<body>
<?php 

if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
     <label class="label_page_head">HR tracking</label></td>
  </div>
        <br />
<br />
<br />
<br />
<div class="page_middle_frame">
<?php
$page='tracking_HR.php';
$reference_name='';
$reference='';
include('../include/period_select_block.php');
?>
<div class="page_inside_frame">
<!--jscript-->
<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, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
<table width="659" id="scroll_table" class="data_display"  >
  <thead>
  <tr>
    <th>date</th>
    <th>time</th>
    <th>user</th>
    <th>action</th>
    <th>details</th>
    <th>&nbsp;</th>
  </tr>
  </thead>
<?php 

$i=0;

while ($i<$tracking_num) {
    $b0  =  mysql_result($tracking_result, $i, "action_id");
	$b1 =  mysql_result($tracking_result, $i, "entry_date");
	$b2 =  mysql_result($tracking_result, $i, "user_name");
	$b3 =  mysql_result($tracking_result, $i, "action");
	$d1 =  mysql_result($tracking_result, $i, "details_1");
	$d2 =  mysql_result($tracking_result, $i, "details_2");
	$d3 =  mysql_result($tracking_result, $i, "details_3");
	$d4 =  mysql_result($tracking_result, $i, "details_4");
	
	$action='';
	$details='';
	switch ($b3) {
    case 20:
	    $action = 'New employee';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
        $details='New employee: <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 250)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> ';
        break;
		
	case 21:
	    $action = 'Edit employee';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
        $details= $d4.' for: <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 250)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> edited from: '.$d2.' to: '.$d3;
        break;
		
	case 23:
	    $action = 'Warning given';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
		$TT2 = "'Click here for details on this warning'";
        $details= '<b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 250)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> was given a warning for <b><a href="../hr_module/warning_details.php?warning_id='.$d4.'" onMouseover="ddrivetip('.$TT2.', 250)"; onMouseout="hideddrivetip()">'.$d3.'</a></b> by: '.$d2;
        break;
		
	
		
		case 29:
	    $action = 'Clock in time';
		$TT = "'Click here for time sheet'";
        $details= 'Clock in times for <a href="../hr_module/attendance_list.php?date=3&emp_id=&recording_date='.$d1.' " onMouseover="ddrivetip('.$TT.', 150)"; onMouseout="hideddrivetip()"><b>'.date("d-m-Y", strtotime($d1)).'</b></a> recorded.';
        break;	
		
		case 30:
	    $action = 'Clock out time';
        $TT = "'Click here for time sheet'";
        $details= 'Clock out times for <a href="../hr_module/attendance_list.php?date=3&emp_id=&recording_date='.$d1.' " onMouseover="ddrivetip('.$TT.', 150)"; onMouseout="hideddrivetip()"><b>'.date("d-m-Y", strtotime($d1)).'</b></a> recorded.';
        break;	
		
		case 31:
	    $action = 'Leave days';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
		$TT2 = "'Click here for leave details'";
		if ($d2!='') {$qty=$d2; $a = 'added';}
		if ($d3!='') {$qty=$d3; $a = 'subtracted';}
        $details= $qty.' leave days for <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> were '.$a.', new balance is:<b> '.$d4.'</b>';
        break;
		
			
		case 32:
	    $action = 'Sick days';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
		$TT2 = "'Click here for leave details'";
		if ($d2!='') {$qty=$d2; $a = 'added';}
		if ($d3!='') {$qty=$d3; $a = 'subtracted';}
        $details= $qty.' sick days for <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> were '.$a.', new balance is:<b> '.$d4.'</b>';
        break;
		
		case 33:
	    $action = 'Overtime';
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
		$TT2 = "'Click here for overtime details'";
		if ($d3!=0) {
		$details= '<b>'.$d3.'</b> hour(s) overtime 150% recorded for <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> on <b>'.date("d-m-Y", strtotime($d2)).'</b>.';
		}
		if ($d4!=0) {
		$details= '<b>'.$d4.'</b> hour(s) overtime 200% recorded for <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> on <b>'.date("d-m-Y", strtotime($d2)).'</b>.';
		}
        break;
		
				
		case 35:
	    $action = 'Time records';
        $details= 'Time record file for '.date("d-m-Y", strtotime($d1)).' was edited.';
        break;
		
		case 36:
	    $action = 'Edit warning';
		$table_name = $_SESSION['db_prefix']."_warnings";
		$warning_query = "SELECT warning, offence, emp_id FROM $table_name WHERE warning_id = '".$d1."' ";
		$warning_result = mySQL_query($warning_query);
		$warning = mysql_result($warning_result, 0, "warning");
		$offence = mysql_result($warning_result, 0, "offence");
		$emp_id = mysql_result($warning_result, 0, "emp_id");
		
		
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$emp_id."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
		$TT2 = "'Click here to view warning.'";
		
        $details= '<b>'.$d4.'</b> on <b>'.$warning.'</b> for <b>'.$offence.'</b> to <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> was changed from <b>'.$d3.'</b> to <b>'.$d2.'</b>';
        break;
		
		case 37:
	    $action = 'Add  note';
				
        $table_name = $_SESSION['db_prefix']."_employee";
		$name_query = "SELECT emp_first_name, emp_last_name FROM $table_name WHERE emp_id = '".$d1."' ";
		$name_result = mySQL_query($name_query);
		$emp_name = mysql_result($name_result, 0, "emp_first_name").' '.mysql_result($name_result, 0, "emp_last_name");
		$TT = "'Click here for details on ".$emp_name."'";
				
        $details= '<b>Personal note entered</b> for <b><a href="../hr_module/employee_details.php?emp_id='.$d1.'" onMouseover="ddrivetip('.$TT.', 290)"; onMouseout="hideddrivetip()">'.$emp_name.'</a></b> on employee details.';
        break;
			
}
?>

  <tr>
    <td width="66" align="left"><?php echo date("d-m-Y", strtotime($b1 )) ?></td>
    <td width="46" align="left"><?php echo date("H:i", strtotime($b1 ))  ?></td>
    <td width="49" align="left"><?php echo $b2 ?></td>
    <td width="71" align="left"><?php echo $action ?></td>
    <td width="376" align="left"><?php echo $details ?></td>
    <td width="23" align="left"><?php echo $b1 ?></td>
    </tr>
  <?php
  $i++;
}
?>

</table>
</div>
</div>
</div>

<?php } else {
$_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
</body>
</html>