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


if($_GET['action'] == 'load'){
	
	if($_SESSION['usertype'] == 'Subadmin')
{
$userid = $_SESSION['admin_id'];
    if($_GET['branch_cal']!='')
	{
$branch = $db->fetchQuery('select * from branches inner join employee on employee.branchid=branches.branch_id where imd_supervisor_id="'.$userid.'" and branches.branch_id="'.$_GET['branch_cal'].'"  group by branches.branch_id');	
	}
	else
	{
 $branch = $db->fetchQuery('select * from branches inner join employee on employee.branchid=branches.branch_id where imd_supervisor_id="'.$userid.'" group by branches.branch_id');
   }
}
else
{	
     if($_GET['branch_cal']!='')
	{
$branch = $db->fetchQuery('select * from branches inner join employee on employee.branchid=branches.branch_id where imd_supervisor_id="'.$userid.'" and branches.branch_id="'.$_GET['branch_cal'].'"  group by branches.branch_id');	
	}
	else
	{
$branch = $db->fetchAll('branches');
}
}
	
	echo '{"branch":'.json_encode($branch).'}';
}


if($_GET['action'] == 'loadstst'){
	
	if($_SESSION['usertype'] == 'Subadmin')
{
$userid = $_SESSION['admin_id'];

$branch = $db->fetchQuery('select * from emp_status ');
}
else
{	
$branch = $db->fetchAll('emp_status');
}
	
	echo '{"branch":'.json_encode($branch).'}';
}

if($_GET['action'] == 'loadstate'){
	


$state = $db->fetchQuery('select * from state where country_id=356 ');

	
	echo '{"state":'.json_encode($state).'}';
}



/* language*/
if($_GET['action'] == 'lang'){
	$lang = array();
	if($_SESSION['usertype'] == 'Subadmin')
	{
		$userid = $_SESSION['admin_id'];
		$e_id	= $_GET['employ_id'] ;
		
		$lang = $db->fetchQuery('select * from emp_language  where e_id="'.$e_id.'" ORDER BY id ASC');
	}
	else
	{	
		$e_id	= $_GET['employ_id'] ;
		$lang = $db->fetchQuery('select * from emp_language  where e_id="'.$e_id.'" ORDER BY id ASC');
	}
	
	echo '{"lang":'.json_encode($lang).'}';
}

/* work experience*/
if($_GET['action'] == 'exp'){
	$lang = array();
	if($_SESSION['usertype'] == 'Subadmin')
	{
		$userid = $_SESSION['admin_id'];
		$e_id	= $_GET['employ_id'] ;
		
		$lang = $db->fetchQuery('select * from employee_expirence  where e_id="'.$e_id.'"');
	}
	else
	{	
		$e_id	= $_GET['employ_id'] ;
		$lang = $db->fetchQuery('select * from employee_expirence  where e_id="'.$e_id.'"');
	}
	
	echo '{"wk_exp":'.json_encode($lang).'}';
}


/* Education*/
if($_GET['action'] == 'edu'){
	$lang = array();
	if($_SESSION['usertype'] == 'Subadmin')
	{
		$userid = $_SESSION['admin_id'];
		$e_id	= $_GET['employ_id'] ;
		
		$edn = $db->fetchQuery('select * from employee_education  where e_id="'.$e_id.'"');
	}
	else
	{	
		$e_id	= $_GET['employ_id'] ;
		$edn = $db->fetchQuery('select * from employee_education  where e_id="'.$e_id.'"');
	}
	
	echo '{"educ":'.json_encode($edn).'}';
}





//settings

if($_GET['action'] == 'userstt'){
	
	if($_SESSION['usertype'] == 'Subadmin')
{
$userid = $_SESSION['admin_id'];

$users = $db->fetchQuery('select * from employee ');
}
else
{	
$users = $db->fetchAll('employee');
}
	
	echo '{"users":'.json_encode($users).'}';
}


if($_GET['act'] == 'list'){
	
	if($_SESSION['usertype'] == 'Subadmin')
{
$userid = $_SESSION['admin_id'];

$desig = $db->fetchQuery('SELECT * FROM designation join department on designation.departs_id =department.depart_id order by department.depart_name , depart_rank ASC');
}
else
{	
$desig = $db->fetchQuery('SELECT * FROM designation join department on designation.departs_id =department.depart_id order by department.depart_name , depart_rank ASC');
}
	
	echo '{"desig":'.json_encode($desig).'}';
}

if($_GET['action'] == 'atch'){

$leavetype = $_GET['leavetype'];	
$leavesnums = $db->fetchQuery("SELECT * from payroll_leave where lid=$leavetype group by lid");

	
	echo '{"leavatch":'.json_encode($leavesnums).'}';
}

if($_GET['act'] == 'emp'){

$eid=$_GET['empid'];	
$users = $db->fetchQuery("SELECT * from employee e,department d,designation g,emp_status s where e.e_id=$eid and e.e_post=g.desig_id and e.departid=d.depart_id and e.emp_status=s.id");

	
	echo '{"users":'.json_encode($users).'}';
}

if($_GET['action']=='documents')
			{	

			$idn=$_GET['employ_id'];
			$docquery=$db->fetchQuery("SELECT * from emp_documents where emp_id=$idn ORDER BY emp_doc_id ASC");
				
			echo '{"documents":'.json_encode($docquery).'}';
			

}
?>