<!--Notice: (c)2013 This page is part of the management program for Tlhomeso Timbers, Gaborone, 
and developed by Customized Software (Pty) Ltd, Gaborone, Botswana. 
Customized Software holds the copyright on the source code on this and all other pages in the 
management program. For more info contact Customized Software on email: info@bwcustomized.com-->


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "HR-edit";
include ("../navigation/access.php");

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

require_once('../include/tc_calendar.php');
    
	
	$edit_date = $_GET['edit_date'];
	$edit = $_GET['edit'];
	$day = $edit_date;
			
	$d = date("d", strtotime($day) );
	$m = date("m", strtotime($day) );
	$y = date("Y", strtotime($day) );
	
	if ($edit==1) {
	   $time_id = $_GET['time_id'];
	   $clock_in_hrs = $_GET['clock_in_hrs_select'];
	   $clock_in_min = $_GET['clock_in_min_select'];
	   $clock_out_hrs = $_GET['clock_out_hrs_select'];
	   $clock_out_min = $_GET['clock_out_min_select'];
	   $permission = $_GET['permission_group'];
	   echo $permission;
  
	   $clock_in = ($clock_in_hrs*60)+$clock_in_min;
	   $clock_out = ($clock_out_hrs*60)+$clock_out_min;
	   $w_min = $clock_out - $clock_in - 60;
	   	     
	   if (($clock_in==0) && ($clock_out==0)) {
		   $w_min=0;
		   
	   }
	   
	   if ($clock_in==420) {
		   $status = "P";
		   
		   
	   }
	   else {
		   $status = "L";
		   
		   }
		   
	   if ($clock_in_hrs==0) {
		   $status = "A";
		   $clock_in = 0;
		   $clock_out = 0;
		   $w_min = 0;
		   
	   }
	   
		   
		   
	   $table_name = $_SESSION['db_prefix']."_time_record";
	   $editQuery = "UPDATE $table_name SET clock_in = '".$clock_in."', clock_out = '".$clock_out."', w_min = '".$w_min."', status = '".$status."', permission = '".$permission."'  WHERE time_id = '$time_id' ";
       $editResult = mySQL_query($editQuery);
	}
	
	if ($edit==2) {
	   $time_id = $_GET['time_id'];
	   $status = "A";
       $clock_in = 0;
	   $clock_out = 0;
	   $w_min = 0;$permission="";
	   
	   $table_name = $_SESSION['db_prefix']."_time_record";
	   $editQuery = "UPDATE $table_name SET clock_in = '".$clock_in."', clock_out = '".$clock_out."', w_min = '".$w_min."', status = '".$status."', permission = '".$permission."'  WHERE time_id = '$time_id' ";
       $editResult = mySQL_query($editQuery);
	   
	}
	
	
	if ($edit==3) {
	   $time_id = $_GET['time_id'];
	   $reason = $_GET['reason_select'];
	   $reason2 = $_GET['reason2_select'];
	   
	   $table_name = $_SESSION['db_prefix']."_time_record";
	   $editQuery = "UPDATE $table_name SET reason = '".$reason."', reason2 = '".$reason2."' WHERE time_id = '$time_id' ";
       $editResult = mySQL_query($editQuery);
	}
	   
	
$table_name2 = $_SESSION['db_prefix']."_time_record";
$presence_query = "SELECT time_id, emp_id, clock_in, clock_out, w_min, status, permission, reason, reason2  FROM $table_name2 WHERE date = '".$day."'  ";
$presence_result = mySQL_query($presence_query);
$presence_num = mysql_num_rows($presence_result);


?>
<link rel="stylesheet" href="../css/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="../css/dhtmlwindow.js"></script>
<link rel="stylesheet" href="../css/modal.css" type="text/css" />
<script type="text/javascript" src="../css/modal.js"></script>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
</head>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>


<div class="main_frame">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="125" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Edit timekeeping</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
        <br />
<br />
<br />
<br />
  <form action="edit_timekeeping.php" method="get" name="dateform" class="today" id="dateform">
    <table width="700"  id='table_calendar'>
      <tr>
        <td height="20" colspan="3" align="left" valign="middle"><label class="label_std">Select a day to edit times</label></td>
        <td width="37" valign="middle">&nbsp;</td>
        <td width="254" valign="middle">&nbsp;</td>
        <td valign="middle">&nbsp;</td>
      </tr>
      <tr>
        <td width="34" height="25" valign="middle">&nbsp;&nbsp; </td>
        <td width="48" valign="middle"><label class="label_std">  from:</label> </td>
        <td colspan="3" valign="middle"><?php
		$myCalendar = new tc_calendar("edit_date", true);
		$myCalendar->setIcon("iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
	 	$myCalendar->writeScript();?>
          &nbsp;&nbsp;&nbsp;&nbsp;
<input name="button5" type="submit" class="linkbutton"  id="button5" value="Go" />
          <input name="date" type="hidden" id="date" value="1" />
           <input name="edit" type="hidden" id="edit" value="" /></td>
        <td width="194" valign="middle">&nbsp;&nbsp;</td>
      </tr>
    </table>
  </form>
</td> <!--center of tableMain-->
</tr>
<tr>
<td> <!--center of tableMain-->
<div class="scroll_frame_long"><div align="left">
  <label class="label_end">click on start time to edit.</label></div>
<table width="690" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
  <tr>
    <th class="sortable-text">name</th>
    <th class="sortable-text">department</th>
    <th class="sortable-numeric">start</th>
    <th class="sortable-numeric">end</th>
    <th class="sortable-numeric">recorded</th>
    <th class="sortable-text">status</th>
    <th class="sortable-text">permission</th>
    <th class="sortable-text">reason</th>
    <th class="sortable-text">&nbsp;</th>
    </tr>
<?php 
$i=0;

while ($i<$presence_num) {
	$a0 = mysql_result($presence_result, $i, "time_id");
	$a1 = mysql_result($presence_result, $i, "emp_id");
	   	$table_name = $_SESSION['db_prefix']."_employee";
    	$employee_query = "SELECT emp_first_name, emp_last_name, department, time_keeping  FROM $table_name WHERE emp_id = $a1 ";
		$employee_result = mySQL_query($employee_query);
        $a1a = mysql_result($employee_result, 0, "emp_first_name")." ".mysql_result($employee_result, 0, "emp_last_name");
		$a7 = mysql_result($employee_result, 0, "department");
		$a10 = mysql_result($employee_result, 0, "time_keeping");
	$a2 = mysql_result($presence_result, $i, "clock_in");
		   $hours =  floor($a2/60); 
		   $mins =   $a2 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a2a = $hours . ":" . $mins ;
	$a3 = mysql_result($presence_result, $i, "clock_out");
		   $hours =  floor($a3/60); 
		   $mins =   $a3 % 60; 
		   if ($hours<10) { $hours = 0 . $hours; }
		   if ($mins<10) { $mins = 0 . $mins; }
		   $a3a = $hours . ":" . $mins ;

	
		
	$a4 = mysql_result($presence_result, $i, "w_min");
	      $hours =  floor($a4/60); 
		  $mins =   $a4 % 60; 
		  $a4a = $hours . ":" . $mins ;
	
	$a5a="";
	$a5 = mysql_result($presence_result, $i, "status");
	if ($a5=="P") {$a5a="";}
	if ($a5=="L") {$a5a="late";}
	if ($a5=="I") {$a5a="sick";}
	if ($a5=="F") {$a5a="leave";}
	if ($a5=="E") {$a5a="early dismiss";}
	if ($a5=="S") {$a5a="not recorded";}
	if ($a5=="A") {$a5a="absent";}
	
	$a11 = mysql_result($presence_result, $i, "permission");
	$a6 = mysql_result($presence_result, $i, "reason");
	$a9 = mysql_result($presence_result, $i, "reason2");
	if ($a6!="") { $a9 = " / ".$a9 ;}	   
		
	//$a5 = $a2 + $a3 + $a4;	
//	       $hours =  floor($a5/60); 
//		   $mins =   $a5 % 60; 
//		   $a5a = $hours . " Hrs " . $mins . " Min ";
		   
     
	
	?>
  
  <tr > 
    <td width="99" align="left"><a href="employee-details.php?emp_id=<?php echo $a1?>" onMouseover="ddrivetip(' Click for employee details.', 150)"; onMouseout="hideddrivetip()"></a><a href="employee-details.php?emp_id=<?php echo $a1?>" onmouseover="ddrivetip(' Click for employee details.', 150)"; onmouseout="hideddrivetip()"></a><a href="employee-details.php?emp_id=<?php echo $a1?>" onmouseover="ddrivetip(' Click for employee details.', 150)"; onmouseout="hideddrivetip()"><?php echo $a1a ?></a></td>
    <td width="87" align="left"><?php echo $a7 ?></td>
    <td width="57" align="left"><a href="" onclick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/timekeeping_edit_clock_in.php?time_id=<?php echo $a0?>', 'Edit time keeping', 'width=550px,height=300px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php  echo $a2a ?></a></td>
    <td width="49" align="left"><?php  echo $a3a ?></td>
    <td width="72" align="left"><?php echo $a4a ?></td>
    <td width="53" align="left"><?php echo $a5a ?></td>
    <td width="84" align="left"><?php echo $a11 ?></td>
    <td width="94" align="left"><a href="" onclick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/timekeeping_edit_reason.php?time_id=<?php echo $a0?>', 'Edit time keeping', 'width=550px,height=200px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $a6 ?></a><?php echo $a9 ?></td>
    <td width="55" align="left"><?php echo $a10 ?></td>
    </tr>
  <?php
  $i++;
}
?>
<tfoot>
  </tfoot>
</table>
<div align="left"><label class="label_end">end of list</label></div>
</div></td>
</tr>
</table>  <!--end of tableMain-->
  
</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>