<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$client_namek ='';
if(isset($_REQUEST['client_name'])){
$client_namek=mysql_escape_string($_REQUEST['client_name']);
}
if(isset($_REQUEST['client_main'])){
$client_main=mysql_escape_string($_REQUEST['client_main']);
}
if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("delete from cf_payroll_user_leave_requests where id='".$id."'");
	header("location:approve-leaves.php?msg=You Have Successfully Deleted");
}
if(isset($_REQUEST['approve']) && $_REQUEST['approve']=='imd')
{
	$id = $_REQUEST['id'];$val = $_REQUEST['val'];
	mysql_query("update cf_payroll_user_leave_requests set imd_status='$val' where id='".$id."'");
	header("location:approve-leaves.php");
}
if(isset($_REQUEST['approve']) && $_REQUEST['approve']=='admin')
{
	$id = $_REQUEST['id'];$val = $_REQUEST['val'];
	mysql_query("update cf_payroll_user_leave_requests set HRstatus='$val' where id='".$id."'");
	header("location:approve-leaves.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" />
<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 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 src="js/popup_sales.js" type="text/javascript"></script>
<script>

$(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'
});
});

</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;
	}   


function Searchdate(page,val)
{ 
 	
	 var page=page;	
	 var saletype='';
	 var fromdate='';
	 var todate='';
	 var clientboxid='';
	 
	
	 if(document.sales_frm.from_date){
	 fromdate= document.sales_frm.from_date.value;
	 }
	 
	 if(document.sales_frm.to_date){
	 todate= document.sales_frm.to_date.value;
	 } 
	 
	 
	var strURL="ajax/approve_leave_data.php?&page="+page;
		
		
		if(fromdate!=''){
		strURL+="&fromdate="+fromdate;
		}
			
		if(todate!=''){
		strURL+="&todate="+todate;
		}
		
	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)--------------->

<div class="viewEmployeePopup login-popup"  id="login-box" style="width:800px;height:400px;">
<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
   <div id="popupid_sales"></div>
   
     
    </div>

<!---------------popup area ends------------------>
<div class="wrapper" >
   <div>
<?php 
	include("header.php");
?>
</div>
 
 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>Approval Lists</h1>
   
   <form name="sales_frm" id="sales_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    
    <div class="searchField" style="padding-left:20px;">
     
    </div>
     
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="from_date" id="from_date" style="width:75px;" maxlength="100" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="to_date" id="to_date" style="width:75px;" maxlength="100" class="input1" />
    </div>
       
    <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
  
   </div>
   </div>
   </form>
   
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px;">
  
   
   <div id="list">
     <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px; ">
  <tr class="heading">
    <td>No</td>    
    <td>Employee</td>   
	<td>Employee Type</td>   
    <td>Leave Date</td>   
    <td>Leave Type</td>
    <td>Reason</td>
    <td>Day</td>
	<td align="center">Imm.Supervisor</td>
	<td align="center">Admin</td>
    <td align="center">Delete</td>
  </tr>
  
<?php
$i=1;
$emp_ses_id=$_SESSION['emp_id'];
$typename=$_SESSION['typename'];
if($typename=='SubAdmin')
{
/*$sq_arr="select emp.e_fname as e_fname,emp.e_lname as e_lname,desg.desig_name as desig_name, leavetype.title as title ,leaves.* from cf_payroll_user_leave_requests as leaves join cf_employee as emp on leaves.employee_id = emp.e_id left join cf_designation as desg on emp.desigid = desg.desig_id left join cf_payroll_leave as leavetype on leaves.leave_id = leavetype.lid where  emp.imm_supr='$emp_ses_id'";*/

$sq_arr="select * from cf_payroll_user_leave_requests as leaves join  cf_payroll_leave as leavetype on leaves.leave_id = leavetype.lid ";

/*$sq_arr="select leavetype.title as title ,leaves.* from cf_payroll_user_leave_requests as leaves join cf_employee as emp on leaves.employee_id = emp.e_id left join cf_designation as desg on emp.desigid = desg.desig_id left join cf_payroll_leave as leavetype on leaves.leave_id = leavetype.lid where  emp.imm_supr='$emp_ses_id'";*/
}
else
{
$sq_arr="select * from cf_payroll_user_leave_requests as leaves join  cf_payroll_leave as leavetype on leaves.leave_id = leavetype.lid ";
}		
$sq_arr.=" order by leaves.id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

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

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

$pagecnt++;

$empids = $res['employee_id'];
if($res['type_emp'] == '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['day_from']));?></td>
    <td><?php echo $res['title'];?></td>  
    <td><?php echo $res['reason'];?></td>
    <td><?php if($res['half_full_day'] == '1')
	{
		echo "Half Day";
	}
	else
	{
		echo "Full Day";
	}
	?></td>  
	<?php
	
	if($res['imd_status']!=0)
	{
		if($typename=='SubAdmin')
		{
	?>
    <td align="center" class="tr_td_r" ><a href="approve-leaves.php?approve=imd&id=<?php echo $res['id']; ?>&val=0" ><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="approve-leaves.php?approve=imd&id=<?php echo $res['id']; ?>&val=1" ><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="approve-leaves.php?approve=admin&id=<?php echo $res['id']; ?>&val=0" ><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="approve-leaves.php?approve=admin&id=<?php echo $res['id']; ?>&val=1" ><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="approve-leaves.php?del=delete&id=<?php echo $res['id']; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></a></td>
  </tr>
  <?php 
    }
	}else{?>
	 <tr>
    <td class="errorMessage"  style="border-right:0px;border-bottom:0px; "><font color="#FF0000">No Records Found</font></td></tr>
	<? }
  ?>
</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>
</html>
