<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$parent_name='';
$ledger_name='';
$veh_num='';$to_date='';$from_date='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';

if(isset($_REQUEST['approve']) && $_REQUEST['approve']=='imd')
{
	$id = $_REQUEST['id'];
	$val = $_REQUEST['val'];
	$otrval = $_REQUEST['otrval'];
	if($otrval ==1 && $val ==1)
	{
	mysql_query("update cf_time_approval set imd_status='$val' , is_blocked=1 where id='".$id."'");
	
	$sel_approv=mysql_query("select * from cf_time_approval where id='".$id."'");
	while($sel_row=mysql_fetch_array($sel_approv))
	{
	$e_datetbl=$sel_row['e_date'];
	$e_idtbl=$sel_row['e_id'];
	$deviceidstbl=$sel_row['deviceids'];
	$e_intbl=$sel_row['e_in'];
	$e_outtbl=$sel_row['e_out'];
	$e_worktbl=$sel_row['e_work'];
	$time_intbl=$sel_row['time_in'];
	$time_inloctbl=$sel_row['time_inloc'];
	$time_outtbl=$sel_row['time_out'];
	$time_outloctbl=$sel_row['time_outloc'];
	$total_worked_hourstbl=$sel_row['total_worked_hours'];
	$is_late_statustbl=$sel_row['is_late_status'];
	}
	
	mysql_query("insert into cf_time (e_date,e_id,deviceids,e_in,e_out,e_work,time_in,time_inloc,time_out,time_outloc,total_worked_hours,is_late_status,approve_id)  values('$e_datetbl','$e_idtbl','$deviceidstbl','$e_intbl','$e_outtbl','$e_worktbl','$time_intbl','$time_inloctbl','$time_outtbl','$time_outloctbl','$total_worked_hourstbl','$is_late_statustbl','$id')");
	}
	else
	{
	mysql_query("update cf_time_approval set imd_status='$val' , is_blocked=0 where id='".$id."'");
	mysql_query("delete from cf_time where approve_id ='".$id."'");
	}
	header("location:timesheet-approval.php");
}
if(isset($_REQUEST['approve']) && $_REQUEST['approve']=='admin')
{
	$id = $_REQUEST['id'];
	$val = $_REQUEST['val'];
	$otrval = $_REQUEST['otrval'];
	if($otrval ==1 && $val ==1)
	{
	mysql_query("update cf_time_approval set HRstatus='$val' , is_blocked=1 where id='".$id."'");
	
	$sel_approv=mysql_query("select * from cf_time_approval where id='".$id."'");
	while($sel_row=mysql_fetch_array($sel_approv))
	{
	$e_datetbl=$sel_row['e_date'];
	$e_idtbl=$sel_row['e_id'];
	$deviceidstbl=$sel_row['deviceids'];
	$e_intbl=$sel_row['e_in'];
	$e_outtbl=$sel_row['e_out'];
	$e_worktbl=$sel_row['e_work'];
	$time_intbl=$sel_row['time_in'];
	$time_inloctbl=$sel_row['time_inloc'];
	$time_outtbl=$sel_row['time_out'];
	$time_outloctbl=$sel_row['time_outloc'];
	$total_worked_hourstbl=$sel_row['total_worked_hours'];
	$is_late_statustbl=$sel_row['is_late_status'];
	}
	mysql_query("insert into cf_time (e_date,e_id,deviceids,e_in,e_out,e_work,time_in,time_inloc,time_out,time_outloc,total_worked_hours,is_late_status,approve_id)  values('$e_datetbl','$e_idtbl','$deviceidstbl','$e_intbl','$e_outtbl','$e_worktbl','$time_intbl','$time_inloctbl','$time_outtbl','$time_outloctbl','$total_worked_hourstbl','$is_late_statustbl','$id')");
	}
	else
	{
	mysql_query("update cf_time_approval set HRstatus='$val', is_blocked=0 where id='".$id."'");
	mysql_query("delete from cf_time where approve_id ='".$id."'");
	}
	header("location:timesheet-approval.php");
}



?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />

<link href="css/menu.css" rel="stylesheet" type="text/css" />
<style>
.newcategoryProfile{ background:#FFFFFF; position:absolute; width:400px; height:250px; z-index:5;
					-webkit-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					-moz-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);}


</style>
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/trippopup.js" type="text/javascript"></script>
<!----------------------------css for auto complete-------------------------------->
<link rel="stylesheet" href="css/chosen.css">

<!--end-->

<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script language="javascript">

function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   


$(document).ready(function(){
$('#pay_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#add_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#cheque_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#from_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#to_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

function Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var ledger_name='';
	 var fromdate='';
	 var todate='';
	 
	 
	 if(document.voucher_frm.from_date){
	 fromdate= document.voucher_frm.from_date.value;
	 }
	 
	 if(document.voucher_frm.to_date){
	 todate= document.voucher_frm.to_date.value;
	 }
	 

	 
	var strURL="ajax/timesheet_approval_data.php?&page="+page;
	
	
	
	if(fromdate!=''){
	strURL+="&fromdate="+fromdate;
	}
	
	if(todate!=''){
	strURL+="&todate="+todate;
	}
	
	//alert(strURL);
	
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
 
   
}

</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="viewEmployeePopup login-popup"  id="login-box" style="height: 220px;width:500px;
overflow-x: scroll;">
    <a href="#" class="close">
    <img src="" class="btn_close" title="Close Window" alt="Close" />
    </a>
    <div id="view_emp"></div>
</div>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Timesheet Approval</h1>
   <form name="voucher_frm" id="voucher_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div align="left">
   <div style="padding:20px;">
    
    
    
    <div class="searchField">
     <p class="input1">From Date</p>
    		<input type="text" name="from_date" id="from_date"  class="slabinput input1" style="width:70px;" value="<?=$from_date?>" required="required"/></td>

    </div>
   
    <div class="searchField">
     <p class="input1">To Date</p>
    		<input type="text" name="to_date" id="to_date"  class="slabinput input1" style="width:70px;" value="<?=$to_date?>" required="required"/></td>

    </div>

    <div class="searchField">
    <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
  </div>
   </div>
   </div>
   </form>
   <div id="popup" align="center"  style="margin-left: 400px;"></div>
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>    
    <td>Employee Name</td>    
	<td>Employee Type</td>    
    <td>Date</td>
	<td>Time In</td>
	<td>Time Out</td>
	<td>Imm Supervisor</td>
    <td>Admin</td>
	<td>Edit</td>
  </tr>
  
  <?php


/*
if(isset($_REQUEST['typename'])){
$typenames=$_REQUEST['typename'];
}*/

$i=1;

$emp_ses_id=$_SESSION['emp_id'];
$typename=$_SESSION['typename'];

if($typename=='SuperAdmin')
{
	  $sq_arr="SELECT * FROM cf_time_approval where 1";
}
else
{
$sq_arr="SELECT a.*,b.e_fname as emp_name
    FROM cf_time_approval a
        LEFT JOIN cf_employee b
            ON b.e_id = a.e_id where b.imm_supr=$emp_ses_id";

}




$query=$sq_arr;


if(isset($_REQUEST['from_date']) && $_REQUEST['from_date']!=''){
$from_date=date('Y-m-d',strtotime($_REQUEST['from_date']));
$sq_arr.=" and   a.pay_date >= '$from_date'";
}
if(isset($_REQUEST['to_date']) && $_REQUEST['to_date']!=''){
$to_date=date('Y-m-d',strtotime($_REQUEST['to_date']));
$sq_arr.=" and   a.pay_date <= '$to_date'";
}
$sq_arr.=" order by e_date desc ";

$function="Searchdate";
include("pagingserch.php");
 $sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=20;
}


$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{

$pagecnt++;

$empids = $res['e_id'];
if($res['emp_type'] == '0')
{
	$type_emp = 'Employee';
	$sql_emp = mysql_query("select * from cf_employee where e_id = '$empids'");
	$row1 = mysql_fetch_array($sql_emp);
	$emp_name = $row1['e_fname'];
}
else
{
	$type_emp = 'Driver';
	$sql_driver = mysql_query("select * from cf_driver where driver_id = '$empids'");
	$row2 = mysql_fetch_array($sql_driver);
	$emp_name = $row2['drivername'];
	
}	

  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo $emp_name;?></td>
	<td><?php echo $type_emp;?></td>
    <td><?php echo date('d-m-Y',strtotime($res['e_date']));?></td>
	 <td><?php echo date("H:i",strtotime($res['e_in']));?></td>
     <td><?php echo date("H:i",strtotime($res['e_out']));?></td>
	 <?php
	
	if($res['imd_status']!=0)
	{
		if($typename=='SubAdmin')
		{
	?>
    <td align="center" class="tr_td_r" ><a href="timesheet-approval.php?approve=imd&id=<?php echo $res['id']; ?>&val=0&otrval=<?php echo $res['HRstatus']; ?>" ><img src="images/ok-green.png" width="20" height="20" title="delete"></a></td>
	<?php
		}
		else
		{
		?>
    <td align="center" class="tr_td_r" ><a href="#" ><img src="images/ok-green.png" width="20" height="20" title="delete"></a></td>
	<?php
		
		}
	}
	else
	{
		if($typename=='SubAdmin')
		{
	?>
	<td align="center" class="tr_td_r" ><a href="timesheet-approval.php?approve=imd&id=<?php echo $res['id']; ?>&val=1&otrval=<?php echo $res['HRstatus']; ?>" ><img src="images/cross-red.png" width="20" height="20"  title="delete"></a></td>
	<?php
		}
		else
		{
		?>
	<td align="center" class="tr_td_r" ><a href="#" ><img src="images/cross-red.png" width="20" height="20"  title="delete"></a></td>
	<?php
		
		}
	}
	?>
	<?php
	
	if($res['HRstatus']!=0)
	{
		if($typename=='SuperAdmin')
		{
	?>
    <td align="center" class="tr_td_r" ><a href="timesheet-approval.php?approve=admin&id=<?php echo $res['id']; ?>&val=0&otrval=<?php echo $res['imd_status']; ?>" ><img src="images/ok-green.png" width="20" height="20"  title="delete"></a></td>
	
	
	<?php
		}
		else
		{
	?>
    <td align="center" class="tr_td_r" ><a href="#" ><img src="images/ok-green.png" width="20" height="20"  title="delete"></a></td>
	<?php
		}
	}
	else{
			if($typename=='SuperAdmin')
			{
	?><td align="center" class="tr_td_r" ><a href="timesheet-approval.php?approve=admin&id=<?php echo $res['id']; ?>&val=1&otrval=<?php echo $res['imd_status']; ?>" ><img src="images/cross-red.png" width="20" height="20"  title="delete"></a></td>
	<?php
		}
		else
		{
	?>
<td align="center" class="tr_td_r" ><a href="#" ><img src="images/cross-red.png" width="20" height="20"  title="delete"></a></td>



	<?php
	}
	}
	?>
   
    <td align="center" class="tr_td_r" ><a href="add-timesheet.php?timeid=<?php echo $res['id']; ?>"><img src="images/edit.png" title="edit"></a></td>
   
  </tr>
  <?php 
    }}
  ?>
 


   
</table>

  <div align="right" style="padding-top:10px;"><?=$pagination?></div> 
  </div>
  </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->

</html>
