
<?php
require_once "../../config.php";
mysql_query("SET CHARACTER SET 'utf8'", $conn);
$q = strtolower($_GET["q"]);

/*------------------GET BY charset ISO ----------*/
//$k = JB_utf8_to_html($q);
/*------------------ GET BY UTF8 ----------------*/
$k = ($q);
if (!$k) return;
$sql = "SELECT emp.emp_id, emp.name, emp.name_eng, org.orgunitname, if(ptn.position_name IS NULL OR ptn.position_name ='', 'ວິຊາການ', ptn.position_name) as position, emp.tel 
	from emp_personal emp LEFT JOIN emp_employment epp ON (epp.emp_id = emp.emp_id)
	LEFT JOIN emp_position ptn ON (ptn.position_id = epp.position_id)
	LEFT JOIN orgunit org ON (org.orgunitid = epp.orgunitid)  WHERE emp.name LIKE '%$k%'  ORDER BY emp.name ASC ";  
$rsd = mysql_query($sql);
/* ----------------- the code autocompete // that perface, but the count list multi -----------*/
while($rs = mysql_fetch_array($rsd)) {

	$emp_id = $rs['emp_id'];
	$name = $rs['name'];
	$orgunit = $rs['orgunitname'];
	$position = $rs['position'];
	$tel = $rs['tel'];
	echo $name."|$emp_id|$orgunit|$position|$tel\n";
}
 /*---------------------- the new edited----------------
$rows = array();
while (list($eid, $ename, $email, $etel) = mysql_fetch_row($rsd)){
	$rows[] = array($eid, $ename, $email, $etel);
}
*/
//echo json_encode($rows);

/* function convert font */
function JB_utf8_to_html ($data) {
    return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '_utf8_to_html("\\1")', $data);
}

function _utf8_to_html ($data) {
    $ret = 0;
	
    foreach ((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v)
        $ret += (ord($v) % 128) * pow(64, $k);
	if ($ret<256) return chr($ret); // no need to convert to entities
    return "&#$ret;";
} 
?><!--<p><font color="#000000">recognize </font></p>-->
