<?php 

	//$user_id_form = mysql_real_escape_string(stripslashes($_GET['id']));
	$w_id_from = (int)mysql_real_escape_string(stripslashes($_GET['w_id_from']));
	$username_form = mysql_real_escape_string(stripslashes($_GET['username_form']));
	$emp_code_form = mysql_real_escape_string(stripslashes($_GET['emp_code_form']));
	$first_name_form = mysql_real_escape_string(stripslashes($_GET['first_name_form']));
	//$last_name_form = mysql_real_escape_string(stripslashes($_GET['last_name_form']));
	//$role_id_form = mysql_real_escape_string(stripslashes($_GET['role_id_form']));
	
	// -------------------------------------------	
$whereclause = "";
if ($username_form != NULL) $whereclause .= "username LIKE '%$username_form%' AND ";
if ($first_name_form !=NULL) $whereclause .= "first_name LIKE '%$first_name_form%' AND ";
if ($w_id_from !=NULL) $whereclause .= "orgunitid= '$w_id_from' AND ";


if ($whereclause != "") $whereclause = "WHERE " . substr($whereclause, 0, strlen($whereclause)-5);

$params = "";

if ($username_form != NULL) $params .= "username=$username_form&";
if ($first_name_form != null) $params .= "first_name=$first_name_form&";
if ($w_id_from !=NULL) $params .= "orgunitid=$w_id_from&";
	
// ------------------------------------- PAGE ------------------------------ //
$pagesize = 30;
$start =  (int)$_GET['start'];
	
$limitclause = "LIMIT $start, $pagesize";

// --------------------------------------------------------- Build Paging
$eqcount = mysql_num_rows(mysql_query("SELECT * FROM v_user $whereclause"));
$pagecount = ceil($eqcount / $pagesize);
$pagenum = floor($start/$pagesize) +1;
$starttext = $start+1;
$endtext = min($start + $pagesize, $eqcount);
$pagedescription = "ຫນ້າທີ $pagenum, ສະແດງລາຍການທີ $starttext ຫາ $endtext, ຈາກທັງຫມົດ $eqcount ລາຍການ";

function selOrgunit(){
	return mysql_query("select * from orgunit WHERE parentunit = 0 AND isdeleted = 0 AND inactive=0 ORDER BY orgunitid, orgunitname ASC");
}	

function selOrgList(){
	return mysql_query("select * from orgunit WHERE (parentunit = 0 OR orgunitid IN(31,35)) AND isdeleted = 0 AND inactive=0 ORDER BY orgunitid, orgunitname ASC");
}	
function selPosition(){
	return mysql_query("select * from emp_position WHERE isdeleted = 0 AND inactive = 0 ORDER BY position_id, position_name ASC");
}	
function selUser_role(){
	return mysql_query("select * from  tbl_sysrole ORDER BY role_id ASC");
}	
		
function LoadAllUser($whereclause, $limitclause) {
	return mysql_query("select * from v_user $whereclause $limitclause ");
}
function user_type() {
	return $type = array(				
		'none' => array('name_la' => 'ຜູ້ໃຊ້ພະແນກ'),
		'counter' => array('name_la' => 'ຜູ້ໃຊ້ເຄົາເຕີ'),
		'secretary' => array('name_la' => 'ຜູ້ໃຊ້້ຫ້ອງເລຂາ'),
	);
	
}


function getUser($whereclause,$limitclause){	 
	return mysql_query("SELECT * FROM v_user $whereclause $limitclause");
		// AND d.doc_file !=''
}
?>