<?php
session_start();  
include_once("../class/class.MySQL.php");

$db	=new MySQL();
 $limit=$page_rows;
   $page = $_GET['page'];   
	
	
	if($page) 
		$start = ($page - 1) * $limit;  //first item to display on this page
	else
	
		$start = 0;	
		if(isset($_GET['emp_post']))
		{
		
		
		if($_GET['emp_post']=='manager')
		{
		$where=$where." and a.e_post='manager'";
		}elseif($_GET['emp_post']=='supervisor')
		{
		$where=$where." and a.e_post='supervisor'";
		}elseif($_GET['emp_post']=='employee')
		{
		$where=$where." and a.e_post='employee'";
		}
		elseif($_GET['branch_id']=='')
		{
		$branchid = $_GET['branch_id'];
		$where=$where." and a.branchid='$branchid'";
		}
	
		elseif($_GET['emp_post']=='1'||$_GET['emp_post']=='')
		{
		$where="1";
		}
		
		
		
		}else{ $where="1"; }
		
		if(!empty($_GET['branch_id']))
		{
			$branchid = $_GET['branch_id'];
			$where=$where." and a.branchid='$branchid'";
		}
		
		if(!empty($_GET['emp_id']))
		{
			$empid = $_GET['emp_id'];
			$where=$where." and a.e_id='$empid'";
		}
		
		if(!empty($_GET['emp']))
		{
		$emp = $_GET['emp'];
		$where=$where." and a.emp_status='$emp'";
		}	
		
		
		if($_SESSION['usertype'] == 'SubadminHR')
		{
			$branchidhr = $_SESSION['branch_id'];
			$where=$where." and a.branchid='$branchidhr'";
		}	
		
			
		        $date = date('Y-m-d');
				$where=$where." and c.e_date='$date'";

    $join='a.e_id=b.e_id and a.e_id=c.e_id';
    $group='c.e_id'; 
	$ordr='c.time_in '; 
	

if($_GET['act'])
{
//echo 'subha';
		$sel_emp = $db->fetchAlljoineachrows_g_k('`employee` as a,`file` as b,`time` as c,`designation` as d', $where,$ordr,'a.e_id',$limit,$cols='a.e_fname,a.e_mname,a.e_gender,a.e_lname,a.e_mail,a.e_mob,a.e_post,a.e_id,a.employee_id,a.clock_status,a.status,b.photo,c.e_in,c.e_out,c.time_in,c.time_inloc,c.time_out,c.time_outloc,d.desig_name' ,' asc',$join,$start);
		
		
		
}
else
{
//echo "SELECT * FROM employee e,time t,file f,designation d where e.e_id=t.e_id and t.e_date='$date' and e.e_post=d.desig_id and f.e_id=e.e_id";
$sel_emp = $db->fetchQuery("SELECT * FROM employee e,time t,file f,designation d where e.e_id=t.e_id and t.e_date='$date' and e.e_post=d.desig_id and f.e_id=e.e_id");
}


		//$menu_list=$db->fetchQuery("SELECT e_post,e_id,departid FROM employee where e_id='$userid'");
		
   $arr=array();
   $i=1;
   foreach($sel_emp as $name)
   {
   $em_id=$name['em_id'];
   $e_id=$name['e_id'];
   /*$join1="c.id='". $em_id."'";
   $join1.=' and a.e_id=b.e_id and a.e_id=c.e_id and a.e_post=d.desig_id' ;
   $ordr='c.time_in '; 
   $qry = $db->fetchAlljoineachrows('`employee` as a,`file` as b,`time` as c,`designation` as d', $where,'','a.e_id',$limit,$cols='a.e_fname,a.e_mname,a.e_gender,a.e_lname,a.e_mail,a.e_mob,a.e_post,a.e_id,a.employee_id,a.clock_status,a.status,b.photo,c.e_in,c.e_out,c.time_in,c.time_inloc,c.time_out,c.time_outloc,d.desig_name' ,' desc',$join1,$start );*/
   
   $e_fname=$name['e_fname'];
   $e_mname=$name['e_mname'];
   $e_gender=$name['e_gender'];
   $e_lname=$name['e_lname'];
   $e_mail=$name['e_mail'];
   $e_mob=$name['e_mob'];
   $e_post=$name['desig_name'];
   $e_id=$name['e_id'];
   $clock_status=$name['clock_status'];
   $status=$name['status'];
   $photo=$name['photo'];
   $e_in=$name['e_in'];
   $e_out=$name['e_out'];
   $time_in=$name['time_in'];
   $time_inloc=$name['time_inloc'];
   $time_out=$name['time_out'];
   $time_outloc=$name['time_outloc'];
   $e_employee_id=$name['employee_id'];
   $arr[$i]['e_fname']= $e_fname;
   $arr[$i]['e_mname']= $e_mname;
   $arr[$i]['e_gender']= $e_gender;
   $arr[$i]['e_lname']= $e_lname;
   $arr[$i]['e_mail']= $e_mail;
   $arr[$i]['e_mob']= $e_mob;
	$arr[$i]['e_post']= $e_post;
	$arr[$i]['e_id']= $e_id;
	$arr[$i]['clock_status']= $clock_status;
	$arr[$i]['status']= $status;
	$arr[$i]['photo']= $photo;   
	$arr[$i]['e_in']= $e_in;  
	$arr[$i]['e_out']= $e_out;
	$arr[$i]['time_in']= $time_in;
	$arr[$i]['time_inloc']= $time_inloc;
	$arr[$i]['time_out']= $time_out;
	$arr[$i]['time_outloc']= $time_outloc;
	$arr[$i]['employee_id']= $e_employee_id;     
	$i++;
   }
	
	echo '{"name":'.json_encode($arr).'}';

?>
