<!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" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>   
<?php
include ("../navigation/header.php");
$page_name = "HR-leave";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/hr_sidebar.php");

$attendance_date =$_GET['attendance_date'];

$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_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']."_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']."_time_sheet";
$display_query = "SELECT * FROM $table_name WHERE attendance_date = '".$attendance_date."' ";
$display_result = mySQL_query($display_query);
$display_num = mysql_num_rows($display_result);

if ($display_num==0) { $no_records = 'yes'; } else { $no_records = 'no' ;}

?>
</head>

<body onLoad="<?php if ($no_records=='yes') {?> alertMessage(1, '', 'There are no time records for <br><br><?php echo date("l, d-m-Y", strtotime($attendance_date))?>.'); <?php } ?>">



<div class="main_frame"  style="height:auto; min-height:570px;">

<div class="page_head_frame">
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Edit time records</label></td>
          </tr>
        </table>
  </div>
       


<div class="page_middle_frame">
<form id="form1" method="POST" action="edit_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": [[ 1, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
							 ]
				} );
			} );
		</script>
<div class="wizard_frame">
Recordings for <?php echo date("l, d-m-Y", strtotime($attendance_date))?>
<table class="data_display" id="scroll_table" >
  <thead>
    <tr>
      <td width="40" height="33" align="center">No</td>
      <td width="200" align="center">Name</td>
      <td width="25" align="center">&nbsp;</td>
      <td width="110" align="center">Status</td>
      <td width="200" align="center">Check in</td>
      <td width="45" align="center">&nbsp;</td>
      <td width="180" align="center">Check out</td>
      </tr>
  </thead>
    <?php
	
	$p=0;
	while ($p<$display_num) {
		 
	//echo '<br>'.'--------------test';
	$enable_box = 'name';
	$name = 'enable'.$p;
	//echo '<br>'. $$enable_box;
	$$enable_box=0;	
	//echo '<br>'.$$enable_box;
	    
		
		$time_sheet_id = mysql_result($display_result, $p, "time_sheet_id");
		$emp_no = mysql_result($display_result, $p, "emp_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);
			$emp_id = mysql_result($employee_result, 0, "emp_id");	
			$employee_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 
			$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");
		
				
		$time_in = mysql_result($display_result, $p, "check_in");
		$intime_hour = date("H", strtotime($time_in));
		$intime_min = date("i", strtotime($time_in));
		if ($intime_hour==0) {$intime_hour='00'; $intime_min='00';}
		$time_in_min = mysql_result($display_result, $p, "check_in_min");
		
		
		$absent_permission = mysql_result($display_result, $p, "absent_permission");
		$absent_reason = mysql_result($display_result, $p, "absent_reason");
		if ($absent_reason=='') {
			$absent_permission = 'no';
			$absent_reason = 'no reason';
		}
		
		
		$late_permission = mysql_result($display_result, $p, "late_permission");
		$late_reason = mysql_result($display_result, $p, "late_reason");
		if ($late_reason=='') {
			$late_permission = 'no';
			$late_reason = 'no reason';
		}
		
		$leave_reason = mysql_result($display_result, $p, "leave_reason");
		
		$sick_reason = mysql_result($display_result, $p, "sick_reason");
		
								
		$time_out = mysql_result($display_result, $p, "check_out");
		$time_out_min = mysql_result($display_result, $p, "check_out_min");
		$outtime_hour = date("H", strtotime($time_out));
		$outtime_min = date("i", strtotime($time_out));
		if ($outtime_hour==0) {$outtime_hour='00'; $outtime_min='00';}
		
		
		//$early_permission = mysql_result($display_result, $p, "early_permission");
		//$early_reason = mysql_result($display_result, $p, "early_reason");
		
					    
	?> 
    
    <tr >
      <td align="center" valign="top"><?php echo $emp_no ?><input name="time_sheet_id<?php echo $p ?>" type="hidden" value="<?php echo $time_sheet_id ?>">
        <input type="hidden" name="attendance_date" id="attendance_date" value="<?php echo $attendance_date?>">        &nbsp;</td>
      <td align="left" valign="top"><a href="" onMouseover="ddrivetip('click here  ', 150)"; onMouseout="hideddrivetip()"><?php echo $employee_name ?>
        <input type="hidden" name="emp_id<?php echo $p ?>" id="emp_id<?php echo $p ?>" value="<?php echo $emp_id ?>" >
      </a></td>
      <td align="center" valign="top"><?php echo $time_zone ?><input name="time_zone<?php echo $p ?>" type="hidden" value="<?php echo $time_zone ?>"></td>
      
      <td align="center" valign="top"><select name="status_select<?php echo $p ?>" id="status_select<?php echo $p ?>" class="select100" 
       onChange="    
       document.getElementById('absent_div<?php echo $p ?>').hidden=true;
       document.getElementById('late_div<?php echo $p ?>').hidden=true;
       document.getElementById('leave_div<?php echo $p ?>').hidden=true;
       document.getElementById('sick_div<?php echo $p ?>').hidden=true;
       document.getElementById('not_clocked_div<?php echo $p ?>').hidden=true;
       
       if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==0) {
                      document.getElementById('intime_hour_select<?php echo $p ?>').selectedIndex=1;
                      document.getElementById('intime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('outtime_hour_select<?php echo $p ?>').selectedIndex=5;
                      document.getElementById('outtime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('absent_div<?php echo $p ?>').hidden=true;
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      }
                     if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==1) {
                      document.getElementById('late_div<?php echo $p ?>').hidden=false;
                      document.getElementById('late_permission_group_1<?php echo $p ?>').checked=true;
                      document.getElementById('absent_div<?php echo $p ?>').hidden=true;
                      }   
                     if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==2) {
                      document.getElementById('intime_hour_select<?php echo $p ?>').selectedIndex=7;
                      document.getElementById('intime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('outtime_hour_select<?php echo $p ?>').selectedIndex=6;
                      document.getElementById('outtime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('absent_div<?php echo $p ?>').hidden=false;
                      document.getElementById('absent_permission_group_1<?php echo $p ?>').checked=true;
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      } 
                      if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==3) {
                      document.getElementById('intime_hour_select<?php echo $p ?>').selectedIndex=1;
                      document.getElementById('intime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('outtime_hour_select<?php echo $p ?>').selectedIndex=5;
                      document.getElementById('outtime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('leave_div<?php echo $p ?>').hidden=false;
                      document.getElementById('absent_div<?php echo $p ?>').hidden=true;
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      } 
                      if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==4) {
                      document.getElementById('intime_hour_select<?php echo $p ?>').selectedIndex=1;
                      document.getElementById('intime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('outtime_hour_select<?php echo $p ?>').selectedIndex=5;
                      document.getElementById('outtime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('absent_div<?php echo $p ?>').hidden=true;
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      document.getElementById('leave_div<?php echo $p ?>').hidden=true;
                      document.getElementById('sick_div<?php echo $p ?>').hidden=false;
                      }
                      if (document.getElementById('status_select<?php echo $p ?>').selectedIndex==5) {
                      document.getElementById('intime_hour_select<?php echo $p ?>').selectedIndex=7;
                      document.getElementById('intime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('outtime_hour_select<?php echo $p ?>').selectedIndex=6;
                      document.getElementById('outtime_min_select<?php echo $p ?>').selectedIndex=0;
                      document.getElementById('not_clocked_div<?php echo $p ?>').hidden=false;
                      }  
                       "
               onFocus="
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      if (document.getElementById('status_select<?php echo $p ?>').value=='Late') {
                      document.getElementById('late_div<?php echo $p ?>').hidden=true;
                      }
               "
               >
        <option value="present">present</option>
        <option value="late">late</option>
        <option value="absent">absent</option>
        <!--<option value="Leave">Leave</option>
        <option value="Sick">Sick</option>
        <option value="Not clocked">Not clocked</option>-->
        <option value="<?php echo $attendance_status?>" selected="selected"><?php echo $attendance_status?></option>
      </select></td>
     
      <td align="center" valign="top"  >
        <div id="clockin_div" style="float:left; margin:0px; " ><select name="intime_hour_select<?php echo $p ?>" class="select_no_arrow" id="intime_hour_select<?php echo $p ?>" >
          <option value="6">06</option>
          <option value="7">07</option>
          <option value="8">08</option>
          <option value="9">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="00">00</option>
          <option value="<?php echo $intime_hour ?>" selected="selected"><?php echo $intime_hour ?></option>
          </select>
          :
          <select name="intime_min_select<?php echo $p ?>" class="select_no_arrow" id="intime_min_select<?php echo $p ?>"  style="width:45px;">
            <option value="00">00</option>
            <option value="1">01</option>
            <option value="2">02</option>
            <option value="3">03</option>
            <option value="4">04</option>
            <option value="5">05</option>
            <option value="6">06</option>
            <option value="7">07</option>
            <option value="8">08</option>
            <option value="9">09</option>
            
            <?php 
		  $i=10;
		  while ($i<60) {
			  ?> 
            <option value="<?php echo $i ?>"><?php echo $i ?></option>      
            <?php
		  $i++;
		  }
		  ?>
             
            <option value="<?php echo $intime_min ?>" selected="selected"><?php echo $intime_min ?></option>  
  </select> 
          </div>
            
        <div id="late_div<?php echo $p ?>"  <?php if ($attendance_status!='late') { ?> hidden="true" <?php } ?>  style="height:20px; width:170px; float:left; margin-left:0px;">
        <div style="float:left; margin:0px;">
        <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="late_reason_select<?php echo $p ?>" style="width:140px;" >
              <option value="<?php echo $late_reason ?>" selected="selected"><?php echo $late_reason?></option>
              <?php
        	for ($j = 0; $j < count($arrId1); $j++) {
    		echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
	}
?>
              </select>
            <br>
          </div>
         </div>
        <div id="absent_div<?php echo $p ?>" <?php if ($attendance_status!='absent') { ?> hidden="true" <?php } ?> style="height:20px; width:170px; 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<?php echo $p ?>" style="margin:0px; width:140px;" >
             <option value="<?php echo $absent_reason ?>" selected="selected"><?php echo $absent_reason?></option>
              <?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:170px; float:left;">   
        <div style="float:left; margin:0px;"> 
        <select name="leave_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:160px;" >
          <option value="<?php echo $leave_reason ?>" selected="selected"><?php echo $leave_reason ?></option>
          <?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:170px; float:left;">   
        <div style="float:left; margin:0px;"> 
        <select name="sick_reason_select<?php echo $p ?>" class="select90" id="choice" style="width:160px;" >
          <option value="<?php echo $sick_reason ?>" selected="selected"><?php echo $sick_reason ?></option>
          <?php
        	for ($j = 0; $j < count($arrId6); $j++) {
    		echo "<option value=" . "\"" . $arrId6[$j] . "\"" . ">" . $arrName6[$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:170px; float:left;"> 
        <div style="float:left; margin:0px;"> 
          <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 } ?> >
            
          </div>
        </div>
            
      </td>
      <td align="center" valign="top">&nbsp;</td>
      <td align="center" valign="top"><div id="clockout_div" style="float:left;" ><select name="outtime_hour_select<?php echo $p ?>" class="select_no_arrow" id="outtime_hour_select<?php echo $p ?>" >
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="00">00</option>
        <option value="<?php echo $outtime_hour ?>" selected="selected"><?php echo $outtime_hour ?></option>
        </select>
        :
        <select name="outtime_min_select<?php echo $p ?>" class="select_no_arrow" id="outtime_min_select<?php echo $p ?>"  style="width:45px;">
          <option value="0">00</option>
          <option value="1">01</option>
          <option value="2">02</option>
          <option value="3">03</option>
          <option value="4">04</option>
          <option value="5">05</option>
          <option value="6">06</option>
          <option value="7">07</option>
          <option value="8">08</option>
          <option value="9">09</option>
          <?php 
		  $i=10;
		  while ($i<60) {
			  ?>
          <option value="<?php echo $i ?>"><?php echo $i ?></option>    
          <?php
		  $i++;
		  }
		  ?>
          <option value="<?php echo $outtime_min ?>" selected="selected" ><?php  echo $outtime_min ?></option>
          
          </select> 
        </div>
        <br></td>
      </tr>
    <?php 
	$p++;
	}
	?>
    
</table>
</div>


<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20">&nbsp;</td>
      <td width="384" valign="top">&nbsp;</td>
      <td width="227" align="right"><span class="wizard_frame">
        <input type="hidden" name="attendance_date" id="attendance_date" value="<?php echo $attendance_date ?>">
        <input type="hidden" name="list_no_text" id="list_no_text" value="<?php echo $display_num ?>">
      </span>
        <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_button"  id="save_button" type="submit" class="imagebutton" value="Save" onclick="needToConfirm = false; confirmRefresh();" />-->
        <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>
</div> 
</div>
</div>
<?php include ('../navigation/side_bar.php'); ?>

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

</body>
</html>