include("../php_scripts/connect_database.php");
// include("php_scripts/session_start.php");
include("php_scripts/function_share.php");
include("php_scripts/load_per_control.php");
$db_dpis2 = new connect_dpis($dpisdb_host, $dpisdb_name, $dpisdb_user, $dpisdb_pwd);
if($OL_CODE=="01") $page_title = $MINISTRY_TITLE;
elseif($OL_CODE=="02") $page_title = $DEPARTMENT_TITLE;
elseif($OL_CODE=="03") $page_title = $ORG_TITLE;
elseif($OL_CODE=="04") $page_title = $ORG_TITLE1;
elseif($OL_CODE=="05") $page_title = $ORG_TITLE2;
if( !$current_page ) $current_page = 1;
if(!$data_per_page) $data_per_page = 30;
$start_record = ($current_page - 1) * $data_per_page;
if(trim($OL_CODE)) $arr_search_condition[] = "(trim(OL_CODE)='".trim($OL_CODE)."')";
if(($OL_CODE=="01" || $OL_CODE=="02" || $OL_CODE=="03") && trim($PV_CODE)){
$PV_CODE=trim($PV_CODE);
$cmd = " select a.ORG_ID as MINISTRY_ID, b.ORG_ID as DEPARTMENT_ID, c.ORG_ID
from PER_ORG a, PER_ORG b, PER_ORG c
where a.OL_CODE='01' and b.OL_CODE='02' and c.OL_CODE='03' and trim(c.PV_CODE)='$PV_CODE'
and a.ORG_ID=b.ORG_ID_REF and b.ORG_ID=c.ORG_ID_REF
order by a.ORG_ID, b.ORG_ID, c.ORG_ID ";
$db_dpis->send_cmd($cmd);
//$db_dpis->show_error();
//echo "
$cmd
";
while($data = $db_dpis->get_array()){
if($OL_CODE=="01") {
if(!in_array("$data[MINISTRY_ID]", $arr_org)) $arr_org[] = $data[MINISTRY_ID];
} elseif($OL_CODE=="02") {
if(!in_array("$data[DEPARTMENT_ID]", $arr_org)) $arr_org[] = $data[DEPARTMENT_ID];
} elseif($OL_CODE=="03") {
if(!in_array("$data[ORG_ID]", $arr_org)) $arr_org[] = $data[ORG_ID];
} // end if
} // end while
$arr_search_condition[] = "(ORG_ID in (". implode(",", $arr_org) ."))";
} // end if
if(trim($ORG_ID_REF)) $arr_search_condition[] = "(ORG_ID_REF=$ORG_ID_REF)";
if(trim($search_org_code)) $arr_search_condition[] = "(ORG_CODE like '$search_org_code%')";
if(trim($search_org_name)) $arr_search_condition[] = "(ORG_NAME like '%$search_org_name%')";
$search_condition = "";
if(count($arr_search_condition)) $search_condition = " and " . implode(" and ", $arr_search_condition);
$cmd = " select count(ORG_CODE) as count_data
from PER_ORG
where ORG_ACTIVE=1
$search_condition ";
$db_dpis->send_cmd($cmd);
// $db_dpis->show_error();
// echo "
$cmd
";
$data = $db_dpis->get_array();
$data = array_change_key_case($data, CASE_LOWER);
$count_data = $data[count_data];
?>