<?php 
include_once('DB.php');

if($_POST['action']=='search_user'){
	if(isset($_POST['search'])){
		$search = $_POST['search'];
		
		$sql="";
		$t=array();
		$bdd=new DB();
		$rows=$bdd->getAll("SELECT id,fullname as name FROM user WHERE FIND_IN_SET(id,(SELECT GROUP_CONCAT(DISTINCT(user_id)) FROM device)) AND fullname LIKE '%$search%'",$t);
		$bdd->disconnect();
		foreach ($rows as $row) {
			$response[] = array("label"=>$row['name'],"id"=>$row['id']);	
		}
		echo json_encode($response);
	}
}
exit;
?>
