<?
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']);
}

$empid='';
$attMonth='';
$attYear='';
$typeradio='';
$typerd='';
if(isset($_POST['btnsubmit']))	
{
	$empid = $_POST['empid'];
	$typeradio = $_POST['type_radio'];
	$attMonth = $_POST['gMonth'];
	$attYear = $_POST['gYear'];
		
}


?>

<!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" />
<script type="text/javascript" src="js/jqmin1.js"></script>
<script src="js/popup1.js" type="text/javascript"></script>
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>


<script language="javascript">
$(document).ready(function(){
$('#attendance_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 showClientcodedropdown(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  Searchdate(1,str);
  return;
  }
  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_code_dropdown.php?str="+str,true);
xmlhttp.send();
}
</script>
</head>

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



<!---------------popup area ends------------------>

<script language="javascript">

  $(document).ready(function(){

    var type_radio = '<?php echo $typeradio;?>';
    var selected = '<?php echo $empid; ?>';
    if(type_radio == 2){

      $('#empid').empty();
        $('#driver_hidden > option').each(function(index, element) 
        { 
            $('#empid').append(new Option($(this).text(),$(this).val()))
        });

        $("#empid").val(selected);

    }

    $(".type").click(function(){

      var type = $(this).val(); 
      if(type == 1){
        $('#empid').empty();
        $('#empid_hidden > option').each(function(index, element) 
        {
            $('#empid').append(new Option($(this).text(),$(this).val()))
        });
      }else{
        $('#empid').empty();
        $('#driver_hidden > option').each(function(index, element) 
        { 
            $('#empid').append(new Option($(this).text(),$(this).val()))
        });
      }

      
    });

	
  });

</script>


<div class="wrapper">
   <div>
<?php 
	include("header.php");

?>
</div>
 
 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>Employee TimeSheet List</h1>
   <form name="att_frm" id="att_frm" method="post"  >
   <div class="searchBox" style="width:70%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    
    <div class="searchField" style="padding-left:20px;">
    

    <select name="empid_hidden" id="empid_hidden" style="display:none;" >
     <?php 
      $sqlemp = $sqlObj->fetchQuery("select * from cf_employee where user_type != 'Superadmin' and status = '1' order by e_fname asc "); 
      foreach($sqlemp as $emp){
      ?>
      <option value="<?=$emp['e_id']?>" <?php if($empid == $emp['e_id']){?> selected <?php } ?>><?=$emp['e_fname']?></option>
      <?php } ?>
    </select>

    <select name="driver_hidden" id="driver_hidden" style="display:none;">
     <?php 
      $sqldrv = $sqlObj->fetchQuery("select * from cf_driver"); 
      foreach($sqldrv as $drv){
      ?>
      <option value="<?=$drv['driver_id']?>" <?php if($empid == $drv['driver_id']){?> selected <?php } ?>><?=$drv['drivername']?></option>
      <?php } ?>
    </select>

     <p class="input1">
      <span style="float:left;padding-right:5px;">Employees</span><input type="radio" name="type_radio" class="type emp_list" value="1" checked="checked">
      <span style="float:left;padding-right:5px;padding-left:5px;">Drivers</span><input type="radio" name="type_radio" class="type driver_list" value="2" <?php if($typeradio == 2){?> checked <?php } ?> ></p>
      <select name="empid" id="empid" class="input1 input3" style="width:20px;" >
     <?php 
    //$sqlemp = $sqlObj->fetchQuery("select * from cf_employee where user_type != 'Superadmin' and status = '1' order by e_fname asc "); 
	 foreach($sqlemp as $emp)
	 {
	 ?>
	<option value="<?=$emp['e_id']?>" <?php if($empid == $emp['e_id']){?> selected <?php } ?>><?=$emp['e_fname']?></option>
	 <?php } ?>
     </select>
   </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Month</p>
    <select name="gMonth" id="gMonth" class="input1 input3" style="width:20px;" >
        <option value="01" <?php if($attMonth == '01'){?> selected <?php } ?>>January</option>
        <option value="02" <?php if($attMonth == '02'){?> selected <?php } ?>>February</option>
        <option value="03" <?php if($attMonth == '03'){?> selected <?php } ?>>March</option>
        <option value="04" <?php if($attMonth == '04'){?> selected <?php } ?>>April</option>
        <option value="05" <?php if($attMonth == '05'){?> selected <?php } ?>>May</option>
        <option value="06" <?php if($attMonth == '06'){?> selected <?php } ?>>June</option>
        <option value="07" <?php if($attMonth == '07'){?> selected <?php } ?>>July</option>
        <option value="08" <?php if($attMonth == '08'){?> selected <?php } ?>>August</option>
        <option value="09" <?php if($attMonth == '09'){?> selected <?php } ?>>September</option>
        <option value="10" <?php if($attMonth == '10'){?> selected <?php } ?>>October</option>
        <option value="11" <?php if($attMonth == '11'){?> selected <?php } ?>>November</option>
        <option value="12" <?php if($attMonth == '12'){?> selected <?php } ?>>December</option>
	</select>
    </div>
	
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Year</p>
     <select id="gYear" name="gYear" class="input1 input3" > 
     	<option value="2015" <?php if($attYear == '2015'){?> selected <?php } ?>>2015</option> 
    	<option value="2016" <?php if($attYear == '2016'){?> selected <?php } ?>>2016</option> 
        <option value="2017" <?php if($attYear == '2017'){?> selected <?php } ?>>2017</option> 
        <option value="2018" <?php if($attYear == '2018'){?> selected <?php } ?>>2018</option> 
        <option value="2019" <?php if($attYear == '2019'){?> selected <?php } ?>>2019</option> 
        <option value="2020" <?php if($attYear == '2020'){?> selected <?php } ?>>2020</option>
        <option value="2021" <?php if($attYear == '2021'){?> selected <?php } ?>>2021</option> 
        <option value="2022" <?php if($attYear == '2022'){?> selected <?php } ?>>2022</option> 
        <option value="2023" <?php if($attYear == '2023'){?> selected <?php } ?>>2023</option> 
        <option value="2024" <?php if($attYear == '2024'){?> selected <?php } ?>>2024</option> 
        <option value="2025" <?php if($attYear == '2025'){?> selected <?php } ?>>2025</option> 
        <option value="2026" <?php if($attYear == '2026'){?> selected <?php } ?>>2026</option> 
        <option value="2027" <?php if($attYear == '2027'){?> selected <?php } ?>>2027</option> 
        <option value="2028" <?php if($attYear == '2028'){?> selected <?php } ?>>2028</option> 
        <option value="2029" <?php if($attYear == '2029'){?> selected <?php } ?>>2029</option> 
        <option value="2030" <?php if($attYear == '2030'){?> selected <?php } ?>>2030</option> 
        <option value="2031" <?php if($attYear == '2031'){?> selected <?php } ?>>2031</option> 
        <option value="2032" <?php if($attYear == '2032'){?> selected <?php } ?>>2032</option> 
        <option value="2033" <?php if($attYear == '2033'){?> selected <?php } ?>>2033</option> 
        <option value="2034" <?php if($attYear == '2034'){?> selected <?php } ?>>2034</option> 
        <option value="2035" <?php if($attYear == '2035'){?> selected <?php } ?>>2035</option> 
        <option value="2036" <?php if($attYear == '2036'){?> selected <?php } ?>>2036</option> 
        <option value="2037" <?php if($attYear == '2037'){?> selected <?php } ?>>2037</option> 
        <option value="2038" <?php if($attYear == '2038'){?> selected <?php } ?>>2038</option> 
        <option value="2039" <?php if($attYear == '2039'){?> selected <?php } ?>>2039</option> 
    </select>
    </div>
            
    &nbsp;&nbsp;        
    <div class="searchField" style="padding-left:20px;">
     <input name="btnsubmit" type="submit" class="input1" onClick="Searchdate(1);" value="Submit" />
    </div>
  
   </div>
   </div>
   </form>
   <div class="searchBox" style="width:70%; 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>Date</td> 
            <td>Days</td>    
            <td>TimeIn</td> 
            <td>TimeOut</td> 
            <td>Total Time</td>
		</tr>
<?php


if(!empty($attMonth) && !empty($attYear))
{
	$month=$attMonth;
	$year=$attYear;
}
else
{
	$datetoday= date('Y-m-d');
	$time=strtotime($datetoday);
    $month=date("n",$time);
    $year=date("Y",$time);
}

$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);

//$yrs = 
$total_hr=0;$total_min=0;$total_sec=0;
for($i=1;$i<=$days;$i++)
{

 ?> 
  <tr>
    <td><?php echo $i;?></td>
<?php  
/*if($month <=9)
{
	$monthval = '0'.$month;
}
else
{
	$monthval = $month;
}*/
if($i<10)
{
$i='0'.$i;
}
$createdt = $year.'-'.$month.'-'.$i;


$timestamp = strtotime($createdt);
$day = date('D', $timestamp);

?>
<td><?php echo $day;?></td>
<?php 
$sq_arr="select * from cf_time where e_date='$createdt' ";


//echo $typeradio;
if($empid!=''){
$sq_arr.=" and e_id ='".$empid."' ";
}

if($typeradio!=''){
if($typeradio == '1')
{
$typerd = 0;
}
else
{
$typerd = 1;
}

$sq_arr.=" and e_type ='".$typerd."' ";
}



$sq_arr.=" order by e_date asc ";
$query=$sq_arr;
//echo $query;

$workhrtot='';

$array=mysql_query($sq_arr);


$res=mysql_fetch_array($array);
if($res['total_worked_hours']!='')
{
	$workhrtot = date("H:i",strtotime($res['total_worked_hours']));  
}

$leaveres = mysql_query("select * from cf_payroll_user_leave_requests where employee_id = '".$empid."'  and day_from = '".$createdt."' and type_emp = '".$typerd."' ");

$rw = mysql_fetch_array($leaveres);
$calendares = mysql_query("select * from payroll_holiday_calendar where date = '".$createdt."'  ");
if(mysql_num_rows($calendares) >0)
{?>
	<td style="color:#990000"><?php echo "Holiday";?></td>   
	<td style="color:#990000"><?php echo "Holiday";?></td>
	<td></td>
<?php

}

else if($res['time_in'] == '' && $createdt != $rw['day_from'])
{?>
	<td style="color:#003333"><?php echo "--";?></td>   
	<td style="color:#003333"><?php echo "--";?></td>
	<td></td>
<?php }
else if($createdt != $rw['day_from'])
{?>
<td><?php echo $res['time_in'];?></td>   
<td><?php echo $res['time_out'];?></td>
<td><?php echo $workhrtot;?></td>
<?php 
}
else
{?>
	<td style="color:#0099FF"><?php echo "Leave";?></td>   
	<td style="color:#0099FF"><?php echo "Leave";?></td>
	<td></td>
<?php }





if($workhrtot!='')
{
$explode_time=explode(":",$workhrtot);
$time_hr=$explode_time[0];
$total_hr=$total_hr+$time_hr;
$time_min=$explode_time[1];
$total_min=$total_min+$time_min;
}
}

$total_hr=$total_hr + intval($total_min/60);
$total_min=$total_min%60;
$total_time_hour=$total_hr.':'.$total_min;



?></tr>

<tr>
<?php 

$calendares = mysql_query("select * from payroll_holiday_calendar where month(date) = '12' ");
while($rwcal = mysql_fetch_array($calendares))
{
	if($rwcal['date'] == $createdt)
	{?>
		<td><?php echo "Holiday";?></td>   
		<td><?php echo "Holiday";?></td>
		<td></td>
	<?php }
} ?>
</tr>
  
<tr class="heading">
<td></td> 
<td></td>    
<td></td> 
<td>Total</td> 
<td><?=$total_time_hour?></td>
</tr>

</table>
  </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>
