<?php 
$user_role = $_SESSION['role_id'];
/*=================================*/
	$orgunitname = mysql_real_escape_string(stripslashes($_GET['orgunitname']));
	
	// -------------------------------------------	
$whereclause = "";
if ($orgunitname != NULL) $whereclause .= " AND orgunitname LIKE '%$orgunitname%' ";

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


$params = "";
if ($orgunitname != NULL) $params .= "orgunitname=$orgunitname&";
	
// ------------------------------------- PAGE ------------------------------ //
$pagesize = 20;
$start =  (int)$_GET['start'];
	
$limitclause = "LIMIT $start, $pagesize";

// --------------------------------------------------------- Build Paging
$eqcount = nr_execute("SELECT COUNT(*) FROM orgunit WHERE isdeleted = 0 AND inactive = 0 $whereclause");
$pagecount = ceil($eqcount / $pagesize);
$pagenum = floor($start/$pagesize) +1;
$starttext = $start+1;
$endtext = min($start + $pagesize, $eqcount);
$pagedescription = "ຫນ້າທີ $pagenum, ສະແດງລາຍການທີ $starttext ຫາ $endtext, ຈາກທັງຫມົດ $eqcount ລາຍການ";		
		
function LoadEq($whereclause, $limitclause) {
	return mysql_query("select * from orgunit WHERE isdeleted = 0 AND inactive = 0 $whereclause  ORDER BY parentunit,orgunitname ASC $limitclause  ");
}
function fparent(){
	return mysql_query("select * from orgunit WHERE inactive  <> 1 AND isdeleted <> 1 ORDER BY parentunit ASC");
}
function unittype(){
	return mysql_query("select * from orgunittype WHERE inactive  <> 1 AND isdeleted <> 1 ORDER BY unittypeid ASC ");
}
