<?php
include("../../../include/startup.php"); 
if(isset($_REQUEST['action']) && $_REQUEST['action']=='get_admin_by_job'){
	$job_id = $_REQUEST['job_id'];
	$admin_id = $_REQUEST['admin_id'];
	$admin_ids = "";
	$sql_for_admin = "SELECT * FROM job_admin_mapping WHERE job_id = '$job_id' ";
	$rs_for_admin = mysqli_query($conn,$sql_for_admin);
	if(mysqli_num_rows($rs_for_admin) > 0){
		while($row_for_admin = mysqli_fetch_assoc($rs_for_admin)){
			$admin_ids .= $row_for_admin["admin_id"].",";
		}
		$admin_ids = substr($admin_ids,0,-1);
	}
	if(isset($admin_ids) && $admin_ids !=""){
		print Admin::getAdminList("admin_id",$admin_id,"100%",false,"form-control","required",$admin_ids); 
	}else{
		echo "<span style='color:red;' id='span'>No consultant assign to this job. First assign consultant.</span>";
		//print Admin::getAdminList("admin_id",$admin_id,"100%",false,"form-control","required",999999); 
	}
	die;
}else if(isset($_REQUEST['action']) && $_REQUEST['action']=='search_job'){	
	$json = array();
	$q	=	$_REQUEST['q'];
	if(strlen($q) >2){
		if($q){
			$where = " company_name LIKE '$q%' ";
		}else{
			$where = " 1=0";
		} 
		
		$sql = "SELECT id,first_name,last_name,company_name FROM job WHERE $where ORDER BY company_name ";
		$result = $db->query($sql);
		$test = array();
		if ($db->num_rows($result) > 0){
			while($row = $db->next_record($result)){	
				$row["text"] = ucfirst($row['company_name'])." / ".ucfirst($row['first_name'])." ".ucfirst($row['last_name']);
				$json[] = $row;
			}			
		}	
	}
	ob_clean();
	echo json_encode($json);
	die;
}
?>