<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--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> 
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>    

<style>
#overlay {
     visibility: hidden;
     position: absolute;
     left: 0px;
     top: 0px;
     width:100%;
     height:100%;
     text-align:center;
     z-index: 1000;
}

#overlay div {
     width:300px;
     margin: 200px auto;
     background-color:#CCC;
     border:1px solid #000;
     padding:15px;
     text-align:center;
}
</style>

<script>
function overlay() {
	
	//alert(window.line_no);
	
	//var pop_up_name = document.getElementById('emp_name_text'+doc_line_num).value;
	//alert(name);
	
	//document.getElementById('pop_up_no').value = doc_line_num;
	//document.getElementById('pop_up_name').value = document.getElementById('emp_name_text'+line_num).value;
	
	el = document.getElementById("overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	
	show_popup ();
}

</script>

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

$page_name = "HR-time recording";
include ("../navigation/access.php");
$today = date("Y-m-d");
$recording_date = $_GET['recording_date'];

$table_name = $_SESSION['db_prefix']."_time_sheet";
$time_sheet_query = "SELECT emp_id, attendance_status, check_in, check_in_min, late_permission, late_reason, absent_permission, absent_reason FROM $table_name WHERE attendance_date = '".$recording_date."' ";
$time_sheet_result = $con->query($time_sheet_query);
$time_sheet_num = mysqli_num_rows($time_sheet_result);


$table_name = $_SESSION['db_prefix']."_list_early";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId1 = array ();
	$arrName1 = array ();
	$position_result = $con->query($position_query);
	if ($position_result!="") {
	$b = 0;
	while($row = $position_result->fetch_assoc()) {
		$arrId1[$b] = $row["item_name"];
		$arrName1[$b] = $row["item_name"];
		$b++;
	}
	}

$table_name = $_SESSION['db_prefix']."_list_absent";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId2 = array ();
	$arrName2 = array ();
	$position_result = $con->query($position_query);
	if ($position_result!="") {
	$b = 0;
	while($row = $position_result->fetch_assoc()) {
		$arrId2[$b] = $row["item_name"];
		$arrName2[$b] = $row["item_name"];
		$b++;
	}
	}	
?>
</head>

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

<div class="main_frame">
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Time out recording for <?php echo date("l, d-m-Y", strtotime($recording_date)) ?></label></td>
          </tr>
        </table>
      </div>
<div class="page_middle_frame">
<form action="time_out_recording_save.php" method="post" name="form1">
<div class="page_inside_frame">
<table width="693" id="table_details_display">
  <tr>
    <td width="33">Emp no</td>
    <td width="172">Name</td>
    <td width="48">Status</td>
    <td width="54" align="center">Clock in<br>
      time</td>
    <td width="74">&nbsp;O&nbsp;&nbsp;&nbsp;&nbsp;E&nbsp;&nbsp; &nbsp;A</td>
    <td><img src="../images/info_blue.png" width="16" height="16"><label class="label_std" style="font-size:10px;">O=on time&nbsp;&nbsp;E=early out&nbsp;&nbsp;A=absent</label></td>
    </tr>
<?php 
$i=0;
	while($row = $time_sheet_result->fetch_assoc()) {
	$emp_id = $row["emp_id"];
	$status = $row["attendance_status"];
	$check_in = $row["check_in"];
		$intime_hour = date("H", strtotime($check_in));
		$intime_min = date("i", strtotime($check_in));
		if ($intime_hour==0) {$intime_hour='00'; $intime_min='00';}
	$check_in_min = $row["check_in_min"];
	$late_permission = $row["late_permission"];
	$late_reason = $row["late_reason"];
	$absent_permission = $row["absent_permission"];
	$absent_reason = $row["absent_reason"];
	
	

	$table_name = $_SESSION['db_prefix']."_employee";
	$employee_query = "SELECT emp_id, emp_no, emp_first_name, emp_last_name, time_zone FROM $table_name WHERE emp_id = '".$emp_id."' AND time_keeping = 'yes' ORDER BY emp_no ASC "; 
	$employee_result = $con->query($employee_query);
	$row = mysqli_fetch_assoc($employee_result);
	$emp_id = $row["emp_id"];
	$emp_no = $row["emp_no"];
	$emp_first_name = $row["emp_first_name"];
	$emp_last_name = $row["emp_last_name"];
	$time_zone = $row["time_zone"];

?>
  <tr>
    <td><?php echo $emp_no ?>
      <input type="hidden" name="emp_no_text<?php echo $i ?>" id="emp_no_text<?php echo $i ?>" value="<?php echo $emp_no ?>">
      <input type="hidden" name="emp_id_text<?php echo $i ?>" id="emp_id_text<?php echo $i ?>" value="<?php echo $emp_id ?>"></td>
    <td><?php echo $emp_first_name.' '.$emp_last_name ?><input name="emp_name_text<?php echo $i ?>" id="emp_name_text<?php echo $i ?>" type="hidden" value="<?php echo $emp_first_name.' '.$emp_last_name ?>"> <input type="hidden" name="time_zone_text<?php echo $i ?>" id="time_zone_text<?php echo $i ?>" value="<?php echo $time_zone ?>"></td>
    <td><input name="status_text<?php echo $i ?>" id="status_text<?php echo $i ?>" style="border:hidden; width:50px;" readonly type="text" value="<?php echo $status ?>"></td>
    <td><input type="text" name="intime_hour_text<?php echo $i ?>" id="intime_hour_text<?php echo $i ?>" style="border:hidden; width:15px;" readonly value="<?php echo $intime_hour ?>">:<input type="text" name="intime_min_text<?php echo $i ?>" id="intime_min_text<?php echo $i ?>" style="border:hidden; width:15px;" readonly value="<?php echo $intime_min ?>"> </td>
    <td><input type="checkbox" name="out_time_checkbox<?php echo $i ?>" id="out_time_checkbox<?php echo $i ?>"  
    onClick="
    document.getElementById('out_time_checkbox<?php echo $i ?>').checked=true;
    document.getElementById('early_div<?php echo $i ?>').hidden=true; 
    document.getElementById('early_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('l-permission_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('early_select<?php echo $i ?>').selectedIndex=-1;
    document.getElementById('early_checkbox<?php echo $i ?>').disabled=false;
    document.getElementById('absent_div<?php echo $i ?>').hidden=true; 
    document.getElementById('absent_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('a-permission_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('absent_select<?php echo $i ?>').selectedIndex=-1;
    document.getElementById('absent_checkbox<?php echo $i ?>').disabled=false;
    document.getElementById('status_check<?php echo $i ?>').value = 'checked';
    "
    <?php if ($status=='absent') { ?> disabled <?php } ?>
    >
      
      <input type="checkbox" name="early_checkbox<?php echo $i ?>" id="early_checkbox<?php echo $i ?>" 
    onClick="
    document.getElementById('early_div<?php echo $i ?>').hidden=false; 
    document.getElementById('out_time_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('early_checkbox<?php echo $i ?>').disabled=false;
    document.getElementById('early_checkbox<?php echo $i ?>').checked=true;
    document.getElementById('absent_div<?php echo $i ?>').hidden=true; 
    document.getElementById('absent_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('a-permission_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('absent_select<?php echo $i ?>').selectedIndex=-1;
    document.getElementById('absent_checkbox<?php echo $i ?>').disabled=false; 
    document.getElementById('status_check<?php echo $i ?>').value = 'checked';  
    "
    <?php if ($status=='absent') { ?> disabled <?php } ?>
    >
    
    
      <input type="checkbox" name="absent_checkbox<?php echo $i ?>" id="absent_checkbox<?php echo $i ?>" 
    onClick="
    document.getElementById('absent_div<?php echo $i ?>').hidden=false; 
    document.getElementById('out_time_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('absent_checkbox<?php echo $i ?>').disabled=false;
    document.getElementById('absent_checkbox<?php echo $i ?>').checked=true;
    document.getElementById('early_div<?php echo $i ?>').hidden=true; 
    document.getElementById('early_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('l-permission_checkbox<?php echo $i ?>').checked=false; 
    document.getElementById('early_select<?php echo $i ?>').selectedIndex=-1;
    document.getElementById('out_time_checkbox<?php echo $i ?>').disabled=true;
    document.getElementById('early_checkbox<?php echo $i ?>').disabled=true;
    document.getElementById('status_text<?php echo $i ?>').value = 'absent';
    document.getElementById('intime_hour_text<?php echo $i ?>').value = '00';
    document.getElementById('intime_min_text<?php echo $i ?>').value = '00';
    document.getElementById('status_check<?php echo $i ?>').value = 'checked';
    ">
    
    <input type="hidden" name="status_check<?php echo $i ?>" id="status_check<?php echo $i ?>" value='';>
     
    
    </td>
    <td width="284">
      <div id='early_div<?php echo $i ?>' hidden="true;">
      
        <select name="early_hour_select<?php echo $i ?>" id="early_hour_select<?php echo $i ?>">
          <option value="17">17</option>
          <option value="16">16</option>
          <option value="15">15</option>
          <option value="14">14</option>
          <option value="131">13</option>
          <option value="12">12</option>
        </select>
        <select name="early_min_select<?php echo $i ?>" id="early_min_select<?php echo $i ?>">
        <?php 
		$m=0;
		while ($m<10) {
		?>
		<option value="<?php echo '0'.$m ?>"><?php echo '0'.$m ?></option>	
        <?php
		$m++;
		}
		
		
		while ($m<60) {
		?>
		<option value="<?php echo $m ?>"><?php echo $m ?></option>	
        <?php
		$m++;
		}
		?>
        </select>
        <select name="early_select<?php echo $i ?>" id="early_select<?php echo $i ?>" class="select120" >
          <option value=" " selected> </option>
          <?php
        	for ($j = 0; $j < count($arrId1); $j++) {
    		echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
	}
?>
          </select>
        perm: 
        <input type="checkbox" name="l-permission_checkbox<?php echo $i ?>" id="l-permission_checkbox<?php echo $i ?>">
        </div>
      
      <div id='absent_div<?php echo $i ?>' hidden="true;">
     <?php if ($status=='absent') { ?>
	 <script>
	 document.getElementById('absent_checkbox<?php echo $i ?>').checked=true; 
     document.getElementById('absent_div<?php echo $i ?>').hidden=false;
	 document.getElementById('status_check<?php echo $i ?>').value = 'checked';
	 </script>
     <?php } ?>
	 <select name="absent_select<?php echo $i ?>" id="absent_select<?php echo $i ?>" class="select120" onClick="document.getElementById('absent_div<?php echo $i ?>').hidden=false; document.getElementById('out_time_checkbox<?php echo $i ?>').checked=false; document.getElementById('early_checkbox<?php echo $i ?>').checked=false; "  >
	   <?php if ($status=='absent') { ?>
       <option value="<?php echo $absent_reason ?>" selected="selected"><?php echo $absent_reason ?></option>
       <?php } else { ?>
       <option value="" selected="selected"></option>
       <?php } ?>
          <?php
        	for ($j = 0; $j < count($arrId2); $j++) {
    		echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
	}
?>
          </select>
        perm: 
        <input type="checkbox" name="a-permission_checkbox<?php echo $i ?>" id="a-permission_checkbox<?php echo $i ?>" value="yes" <?php
	 if ($absent_permission=='yes') { ?> checked <?php } ?> >
&nbsp;&nbsp;
  <a href="#" onMouseover="ddrivetip('To undo the absent status and re-enter clock in time, click here.', 170); window.line_no=<?php echo $i ?>"; onMouseout="hideddrivetip()" onclick="overlay(<?php echo $i ?>)"><img src="../images/line_edit.png" width="16" height="16"></a>
      </div>
      
<div>
<?php if ($status=='late') { ?> 
late reason: <input name="late_reason_text<?php echo $i ?>" type="text" value="<?php echo $late_reason ?>" style="border:hidden; width:100px;" readonly>&nbsp;&nbsp;
perm: <input name="late_permission_text<?php echo $i ?>" type="text" value="<?php echo $late_permission ?>" style="border:hidden; width:20px;;" readonly>
<?php } ?>      
</div>     
    </td>
    </tr>
<?php
$i++;
}
?>
</table>
<input name="line_num" type="hidden" value="<?php echo $i ?>">
<input name="recording_date" type="hidden" value="<?php echo $recording_date ?>">

</div>
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../hr_module/hr_main.php?date=0');" value="Close"/>
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</form>
<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 50; i++) {
	
	frmvalidator.addValidation("status_check"+i,"req","- status "+document.getElementById('emp_name_text'+i).value+".");
	
}	
  </script>
</div>
</div>

<?php include ('../navigation/side_bar.php'); ?>

<div id="overlay">
     <div>
       <table width="290" border="0">
         <tr>
           	<td colspan="2" align="center"><label class="label_std">Change absent status for:</label> <br>
                                                
                <script>
				function show_popup () {
				k = line_no;	
				document.getElementById('pop_up_name').value = document.getElementById('emp_name_text'+k).value;
				}
				</script>
				
				<input name="pop_up_name" id="pop_up_name"  type="text"  class="text200" style="border:hidden; background-color:#CCC;" readonly>
                
                
               
				<br>
			</td>
         </tr>
         <tr>
           <td width="103"><select name="late_hour_select" id="late_hour_select">
             <option value="07">07</option>
             <option value="08">08</option>
             <option value="09">09</option>
             <option value="10">10</option>
             <option value="11">11</option>
             <option value="12">12</option>
           </select>
           
           
           <select name="late_min_select" id="late_min_select">
           <?php 
		$m=0;
		while ($m<10) {
		?>
        <option value="<?php echo '0'.$m ?>"><?php echo '0'.$m ?></option>
        <?php
		$m++;
		}
		while ($m<60) {
		?>
        <option value="<?php echo $m ?>"><?php echo $m ?></option>
        <?php
		$m++;
		}
		?>
        </select>
        </td>
           <td width="177" align="left"><label class="label_std" onClick="
           document.getElementById('out_time_checkbox'+k).disabled=false;
           document.getElementById('early_checkbox'+k).disabled=false;
           document.getElementById('out_time_checkbox'+k).checked=true;
           document.getElementById('absent_checkbox'+k).checked=false;
           document.getElementById('absent_select'+k).selectedIndex=-1;
           document.getElementById('a-permission_checkbox'+k).checked=false;
           document.getElementById('absent_div'+k).hidden=true;
           document.getElementById('intime_hour_text'+k).value = document.getElementById('late_hour_select').value;
           document.getElementById('intime_min_text'+k).value = document.getElementById('late_min_select').value;
           document.getElementById('status_text'+k).value = 'late';
           overlay(1);
           ">Set to late</label></td>
         </tr>
         <tr>
           <td>&nbsp;</td>
           <td align="left"><a href='#' onclick="
       document.getElementById('out_time_checkbox'+k).disabled=false;
       document.getElementById('early_checkbox'+k).disabled=false;
       document.getElementById('out_time_checkbox'+k).checked=true;
       document.getElementById('absent_checkbox'+k).checked=false;
       document.getElementById('absent_select'+k).selectedIndex=-1;
       document.getElementById('a-permission_checkbox'+k).checked=false;
       document.getElementById('absent_div'+k).hidden=true;
       document.getElementById('intime_hour_text'+k).value = '07';
       document.getElementById('intime_min_text'+k).value = '00';
       document.getElementById('status_text'+k).value = 'present';
       overlay(1)"><label class="label_std">Set to present</label></a></td>
         </tr>
         <tr>
           <td>&nbsp;</td>
           <td align="left"><a href='#' onclick='overlay(1)'><label class="label_std">Cancel</label></a></td>
         </tr>
       </table>
       <br>
<br>

  </div>
</div>



</body>

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