<link rel="stylesheet" type="text/css" href="../css/main.css" />
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/Placeholders.js"  type="text/javascript"></script>

<script>
$("#choice").change(function () {
    if($(this).val() == "0") $(this).addClass("empty");
    else $(this).removeClass("empty")
});

$("#choice").change();
</script>

<style>
#choice option { color: black; }
.empty { color: red; }
</style>

<?php


$table_name = $_SESSION['db_prefix']."_list_late";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId1 = array ();
	$arrName1 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId1[$b] = mysql_result($position_result, $b, "item_name");
		$arrName1[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}
	
$table_name = $_SESSION['db_prefix']."_list_not_clocked";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId2 = array ();
	$arrName2 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId2[$b] = mysql_result($position_result, $b, "item_name");
		$arrName2[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}
	
$table_name = $_SESSION['db_prefix']."_list_early";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId3 = array ();
	$arrName3 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId3[$b] = mysql_result($position_result, $b, "item_name");
		$arrName3[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}
	
$table_name = $_SESSION['db_prefix']."_list_absent";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId4 = array ();
	$arrName4 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId4[$b] = mysql_result($position_result, $b, "item_name");
		$arrName4[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}

$table_name = $_SESSION['db_prefix']."_list_leave_reason";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId5 = array ();
	$arrName5 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId5[$b] = mysql_result($position_result, $b, "item_name");
		$arrName5[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}
	
$table_name = $_SESSION['db_prefix']."_list_sick_reason";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId6 = array ();
	$arrName6 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId6[$b] = mysql_result($position_result, $b, "item_name");
		$arrName6[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}

$table_name = $_SESSION['db_prefix']."_time_sheet_temp";
$display_query = "SELECT * FROM $table_name " ;
$display_result = mySQL_query($display_query);
$display_num = mysql_num_rows($display_result);
$attendance_date = mysql_result($display_result, 0, "attendance_date");

?>
<!--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/prompt_late_hr.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/prompt_early_hr.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/prompt_absent_hr.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4_2.js"  type="text/javascript" xml:space="preserve"></script>

<?php include('../include/wait.php') ?>
</head>


<body onLoad="MM_showHideLayers('wait','','hide'); " onFocus="MM_showHideLayers('wait','','hide');">

<div class="wizard_page_middle_frame">
<form id="feedbackform" method="post" action="final_recordTimes_save.php" >
<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": [[ 2, "asc" ]],
					"aoColumns": [
								{"iDataSort": 10},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								
								 ]
				} );
			} );
		</script>
<div class="wizard_frame">
<div style="float:left;">Recordings for <?php echo date("d-m-Y", strtotime($attendance_date)) ?> </div>
<table width="594" class="data_display" id="scroll_table" >
  <thead>
    <tr>
      <td width="50">Date</td>
      <td width="35">Emp no</td>
      <td width="119">Name</td>
      <td width="47">Status</td>
      <td width="35">Zone</td>
      <td width="46" align="center">Check in</td>
      <td width="47" align="center">Check out</td>
      <td width="39" align="center">Hours</td>
      <td width="109" align="left"><input type="checkbox" name="checkbox" id="checkbox" checked="checked">=with permission</td>
      <td width="23">&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");
		$leave_reason = mysql_result($display_result, $p, "leave_reason");
		$sick_reason = mysql_result($display_result, $p, "sick_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 = '<font color=red>'.date("H:i", strtotime($check_in)) . '</font>';
		}
		
		if ($attendance_status=='Not clocked') {
		       $check_in_display = '<font color=orange>'.date("H:i", strtotime($check_in)) . '</font>';
		  	}
		
		if ($attendance_status=='Absent') {
		       $check_in_display = '<font color=blue>'.date("H:i", strtotime($check_in)) . '</font>';
			   $check_out_display = '<font color=blue>'.date("H:i", strtotime($check_out)) . '</font>';
		}
		
		if ($attendance_status=='Annual leave') {
		       $check_in_display = '<font color=blue>'.date("H:i", strtotime($check_in)) . '</font>';
			   $check_out_display = '<font color=blue>'.date("H:i", strtotime($check_out)) . '</font>';
		}
		
		if ($attendance_status=='Sick') {
		    $check_in_display = '<font color=purple>'.date("H:i", strtotime($check_in)) . '</font>';
		    $check_out_display = '<font color=purple>'.date("H:i", strtotime($check_out)) . '</font>';
		}
		
				
		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 = '<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 = '<font color=red>'.date("H:i", strtotime($check_out)) . '</font></a>';
		}
		
		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="50"><?php echo date("d-m-Y", strtotime($attendance_date)) ?>
    <input name="attendance_date_text" id="attendance_date_text" type="hidden" value="<?php echo $attendance_date ?>"></td>
    <td width="35"><?php echo $emp_no ?>
      <input type="hidden" name="emp_no_text<?php echo $p ?>" id="emp_no_text<?php echo $p ?>" value="<?php echo $emp_no ?>">
      <input type="hidden" name="emp_id_text<?php echo $p ?>" id="emp_id_text<?php echo $p ?>" value="<?php echo $emp_id ?>"></td>
    <td width="119"><?php echo $employee_name ?></td>
    <td width="47"><?php echo $attendance_status ?><input name="attendance_status_text<?php echo $p ?>" id="attendance_status_text<?php echo $p ?>" type="hidden" value="<?php echo $attendance_status ?>"><input name="status_out_text<?php echo $p ?>" id="status_out_text<?php echo $p ?>" type="hidden" value="<?php echo $status_out ?>">
     </td>
    <td width="35" align="center"><?php echo $time_zone ?>/<?php echo $p ?></td>
    <td width="46" align="center"><?php echo $check_in_display ?></td>
    <td width="47" align="center"><?php echo $check_out_display;?></td>
    <td width="39" align="center"><?php echo $attendance_time_display ?></td>
    <td width="109" align="center">
    <div id="late_div<?php echo $p ?>" <?php if ($attendance_status!='Late') { ?> hidden="true" <?php } ?> style="height:20px; width:160px; float:left;">
    <div style="float:left;">
    <input name="late_permission_checkbox<?php echo $p ?>" id="late_permission_checkbox<?php echo $p ?>" type="checkbox" value="yes" <?php if ($late_permission=='yes') { ?> checked="checked" <?php } ?> >
             
      <select name="late_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:125px;" >
         <?php if ($late_reason=='') { ?>
              <option value="" selected="selected">Late?</option>
         <?php } else { ?>
			  <option value="<?php echo $late_reason ?>" selected="selected"><?php echo $late_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId1); $j++) {
    		echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
	}
?>
        </select>
    </div>
    </div>
    
    <div id="early_div<?php echo $p ?>" <?php if ($status_out!='Early') { ?> hidden="true" <?php } ?> style="height:20px; width:160px; float:left;">
    <div style="float:left;">
    <input name="early_permission_checkbox<?php echo $p ?>" id="early_permission_checkbox<?php echo $p ?>" type="checkbox" value="yes" <?php if ($early_permission=='yes') { ?> checked="checked" <?php } ?> >
             
      <select name="early_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:125px;" >
         <?php if ($early_reason=='') { ?>
              <option value="" selected="selected">Early?</option>
         <?php } else { ?>
			  <option value="<?php echo $early_reason ?>" selected="selected"><?php echo $early_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId3); $j++) {
    		echo "<option value=" . "\"" . $arrId3[$j] . "\"" . ">" . $arrName3[$j] . "</option>";
	}
?>
        </select>
    </div>
    </div>
    
    
    <div id="not_clocked_div<?php echo $p ?>" <?php if ($attendance_status!='Not clocked') { ?> hidden="true" <?php } ?> style="height:20px; width:150px; float:left;">   
    <div style="float:left;"> 
         <input name="not_clocked_permission_checkbox<?php echo $p ?>" id="not_clocked_permission_checkbox<?php echo $p ?>" type="checkbox" value="yes" <?php if ($not_clocked_permission=='yes') { ?> checked="checked" <?php } ?> >
        <select name="not_clocked_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:125px;" >
          <?php if ($not_clocked_reason=='') { ?>
              <option value="" selected="selected">Not clocked?</option>
         <?php } else { ?>
			  <option value="<?php echo $not_clocked_reason ?>" selected="selected"><?php echo $not_clocked_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId2); $j++) {
    		echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
	}
?>
        </select>
        </div>
        </div>
        
        <div id="absent_div<?php echo $p ?>" <?php if ($attendance_status!='Absent') { ?> hidden="true" <?php } ?> style="height:20px; width:150px; float:left;">   
        <div style="float:left; margin:0px;"> 
        <input name="absent_permission_checkbox<?php echo $p ?>" id="absent_permission_checkbox<?php echo $p ?>" type="checkbox" value="yes" <?php if ($absent_permission=='yes') { ?> checked="checked" <?php } ?> >
        <select name="absent_reason_select<?php echo $p ?>" class="select90" id="absent_reason_select" style="width:125px;" >
          <?php if ($absent_reason=='') { ?>
              <option value="" selected="selected">Absent?</option>
         <?php } else { ?>
			  <option value="<?php echo $absent_reason ?>" selected="selected"><?php echo $absent_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId4); $j++) {
    		echo "<option value=" . "\"" . $arrId4[$j] . "\"" . ">" . $arrName4[$j] . "</option>";
	}
?>
        </select>
        </div>
        </div>
        
        <div id="leave_div<?php echo $p ?>" <?php if ($attendance_status!='Leave') { ?> hidden="true" <?php } ?> style="height:20px; width:150px; float:left;">   
        <div style="float:left; margin:0px;"> 
        <select name="leave_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:148px;" >
          <?php if ($leave_reason=='') { ?>
              <option value="" selected="selected">Leave?</option>
         <?php } else { ?>
			  <option value="<?php echo $leave_reason ?>" selected="selected"><?php echo $leave_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId5); $j++) {
    		echo "<option value=" . "\"" . $arrId5[$j] . "\"" . ">" . $arrName5[$j] . "</option>";
	}
?>
        </select>
        </div>
        </div>
        
        <div id="sick_div<?php echo $p ?>" <?php if ($attendance_status!='Sick') { ?> hidden="true" <?php } ?> style="height:20px; width:150px; float:left;">   
        <div style="float:left; margin:0px;"> 
        <select name="sick_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:148px;" >
          <?php if ($sick_reason=='') { ?>
              <option value="" selected="selected">Sick?</option>
         <?php } else { ?>
			  <option value="<?php echo $sick_reason ?>" selected="selected"><?php echo $sick_reason ?></option>
         <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId6); $j++) {
    		echo "<option value=" . "\"" . $arrId6[$j] . "\"" . ">" . $arrName6[$j] . "</option>";
	}
?>
        </select>
        </div>
        </div>
        
        </td>
    <td width="23"><?php echo $attendance_date ?></td>
  </tr>
  <?php	
	$p++;
	}
	?>
</table>
</div>
<div class="wizard_frame">       
              <table width="656" height="50" align="center" id="tableButtonBar">
                <tr>
                  <td colspan="5">To make changes in times, click 'Prev',<br>
To record the times in the time sheet, click 'Finish'. </td>
                </tr>
                <tr>
                  <td width="110"><input  name="prev_button" type="submit" class="imagebutton" id="prev_button" value="Prev" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
                  <td width="92">
                    <input name="s" type="hidden" id="s" value="5" />
                    <input name="p" type="hidden" id="p" value="5" />
                  </td>
                  <td width="70">&nbsp;</td>
                  <td width="280" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../hr_module/hr_main.php?date=0');" value="Cancel" /></td>
                  <td width="80" align="right"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  /></td>
                </tr>
              </table>
</div>  
</form>

</div>
</body>