<?php
session_start();
include_once("../class/class.MySQL.php");
$db	=new MySQL();

if($_GET['action'] == 'loademp_branch' && $_GET['branch'] != ''){
	$branch_selected = $_GET['branch'];
	$empname_list = $db->fetchQuery("SELECT * FROM employee WHERE branchid = '".$branch_selected."' ORDER BY employee. e_fname ASC");
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}

if($_GET['action'] == 'load'){
	if($_SESSION['usertype']=='Superadmin')
	{
		$empname_list = $db->fetchQuery("select * from employee where user_type!='Superadmin' and emp_status NOT IN(2,3)  order by employee. e_fname ASC");
	}
	else
	{
		$branch_id=$_SESSION['branch_id'];
		$empname_list = $db->fetchQuery("select * from employee where user_type!='Superadmin' and branchid='$branch_id' and emp_status NOT IN(2,3) order by employee. e_fname ASC");
	}
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}

if($_GET['action']=='load_emp_status') {
	$empname_list = $db->fetchQuery("select * from emp_status");
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}

if($_GET['action'] == 'load_st'){
	$statuss = mysql_query("select * from emp_status where emply_stat='Resigned' or emply_stat='Terminated'");
	$ids=array();
	while($rows = mysql_fetch_array($statuss))
	{
	   $ids[]=$rows['id'];  
	} 
	$empst = join(',',$ids);
	$empname_list = $db->fetchQuery("select * from employee  where emp_status  in('$empst') order by employee. e_fname ASC");
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}

if($_GET['action'] == 'loademp_branch_modified'){
	$where_cond='where emp_status NOT IN(2,3)';
	if($_GET['branch'])
	{
		$where_cond.=' and branchid = '.$_GET['branch'].'';
	}
	if($_GET['dept_id'])
	{
		$where_cond.=' and departid = '.$_GET['dept_id'].'';
	}
	
	$empname_list = $db->fetchQuery("SELECT * FROM employee ".$where_cond." ORDER BY employee. e_fname ASC");
	
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}

if($_GET['action'] == 'loademp_dept_modified'){
	$where_cond='where emp_status NOT IN(2,3)';
	if($_GET['branch'])
	{
		$where_cond.=' and branchid = '.$_GET['branch'].'';
	}
	
	if($_GET['dept_id'])
	{
		$where_cond.=' and departid = '.$_GET['dept_id'].'';
	}
	
	$empname_list = $db->fetchQuery("SELECT * FROM employee ".$where_cond." ORDER BY employee. e_fname ASC");
	
	echo '{"empnamelist":'.json_encode($empname_list).'}';
}
?>