$tab = "";
$TMP_ORG_ID = $ORG_ID;
$arr_org = (array) null;
$firstloop=1;
while ($TMP_ORG_ID >= 1) {
$cmd = " select ORG_NAME, ORG_ID_REF from $ORGTAB where ORG_ID=$TMP_ORG_ID ";
$cnt = $db_dpis->send_cmd($cmd);
if ($cnt > 0) {
if ($data = $db_dpis->get_array()) {
$arr_org[id][] = $TMP_ORG_ID;
$arr_org[name][] = $data[ORG_NAME];
$arr_org[id_ref][] = $data[ORG_ID_REF];
if ($TMP_ORG_ID==$data[ORG_ID_REF]) {
$TMP_ORG_ID = 0;
} else {
$TMP_ORG_ID = $data[ORG_ID_REF];
}
// เพิ่มส่วนนี้เพื่อ เก็บ parant ไว้สำหรับการเลื่อนระดับขึ้น
if ($firstloop == 1 && $TMP_ORG_ID>1) {
$firstloop=0;
$PARENT_ORG_ID=$data[ORG_ID_REF];
} // end if ($firstloop == 1)
//echo "$firstloop - $PARENT_ORG_ID ===> $cmd ";
// เพิ่มส่วนนี้เพื่อ เก็บ parant ไว้สำหรับการเลื่อนระดับขึ้น
} // end if ($data = $db_dpis->get_array())
} else {
$TMP_ORG_ID = 0;
} // end if ($cnt > 0)
} // end loop while
array_multisort($arr_org[id], SORT_ASC, $arr_org[name], SORT_ASC, $arr_org[id_ref], SORT_ASC);
?>
|
$cmd = " select ORG_ID , ORG_NAME, ORG_ID_REF from $ORGTAB where ORG_ID_REF = $ORG_ID
order by ORG_ACTIVE DESC, ORG_SEQ_NO, ORG_CODE ";
$count_data = $db_dpis->send_cmd($cmd);
// $db_dpis->show_error();
// echo "part1-$cmd-($count_data) ";
if (strlen($current_page_lvl) > 0) { // ตรวจสอบ current page จาก หน้าก่อนส่งเข้ามา
$arr_current_page = explode(",", $current_page_lvl);
}
$arr_current_page_new = (array) null;
for($i=0; $i < count($arr_org[id]); $i++) {
$class = "table_body_over";
$i_edit="";
// echo "arr_org [id] [$i] (".$arr_org[id][$i].")==ORG_ID ($ORG_ID) ";
if ($arr_current_page[$i])
$arr_current_page_new[] = $arr_current_page[$i];
else
$arr_current_page_new[] = "1";
if($arr_org[id][$i]==$ORG_ID && $count_data==0) {
$sel_org = "select_head_org(". $arr_org[id][$i] .");";
$class = "table_body";
$i_edit = " ";
} elseif($arr_org[id][$i]==$ORG_ID) {
$sel_org = "";
if ($arr_org[id][$i]==1)
$i_edit = "
if ($MFA_FLAG==1 || $BKK_FLAG==1 || $RTF_FLAG==1) { ?>
} ?>
";
else
$i_edit = "
if ($MFA_FLAG==1 || $BKK_FLAG==1 || $RTF_FLAG==1) { ?>
} ?>
";
} else {
$sel_org = "select_head_org(". $arr_org[id][$i] .");";
}
?>
=$tab?>=$arr_org[name][$i]?>=$i_edit?> |
$tab .= " ";
} // end for $i
$current_page_lvl = implode(",", $arr_current_page_new); // ทำ current_page_lvl ให้เป็น list ของ current_page ที่ level ล่าสุด
$current_page_idx = count($arr_org[id])-1;
$current_page = $arr_current_page_new[$current_page_idx];
// echo "current_page=$current_page, current_page_idx=$current_page_idx, current_page_lvl=$current_page_lvl ";
?>
if ($count_data) {
$total_page = ceil( $count_data / $data_per_page );
$page_link = create_link_page($total_page, $current_page);
$limit_data = "";
if($DPISDB=="odbc"){
$select_top = ($current_page==$total_page)?($count_data - ($data_per_page * ($current_page - 1))):$data_per_page;
/****$cmd = " select *
from (
select top $select_top *
from (
select top ". ($data_per_page * $current_page) ."
ORG_ID , ORG_NAME, ORG_ID_REF, ORG_ACTIVE
from $ORGTAB where ORG_ID_REF = $ORG_ID
order by ORG_ACTIVE DESC, ORG_SEQ_NO, ORG_CODE
)
order by PER_NAME desc, PER_SURNAME desc
)
order by PER_NAME, PER_SURNAME
"; ****/
$cmd = " select top ". ($data_per_page * $current_page) ."
ORG_ID , ORG_NAME, ORG_ID_REF, ORG_ACTIVE
from $ORGTAB where ORG_ID_REF = $ORG_ID
order by ORG_ACTIVE DESC, ORG_SEQ_NO, ORG_CODE
";
}elseif($DPISDB=="oci8"){
$search_condition = str_replace(" where ", " and ", $search_condition);
$rec_start = (($current_page-1) * $data_per_page) + 1;
$rec_end = ($current_page > 1)? ($current_page * $data_per_page) : $data_per_page;
$cmd = "select * from (
select rownum rnum, q1.* from (
select ORG_ID , ORG_NAME, ORG_ID_REF, ORG_ACTIVE
from $ORGTAB where ORG_ID_REF = $ORG_ID
order by ORG_ACTIVE DESC, ORG_SEQ_NO, ORG_CODE
) q1
) where rnum between $rec_start and $rec_end ";
}elseif($DPISDB=="mysql"){
$limit_data = " limit " . (($current_page - 1) * $data_per_page) . ", " . $data_per_page;
$cmd = " select ORG_ID , ORG_NAME, ORG_ID_REF, ORG_ACTIVE from $ORGTAB
where ORG_ID_REF = $ORG_ID
order by ORG_ACTIVE DESC, ORG_SEQ_NO, ORG_CODE
$limit_data
";
} // end if
$count_page_data = $db_dpis->send_cmd($cmd);
// $db_dpis->show_error();
// echo "part2-$cmd-($count_page_data) ";
// exit("me terminate");
if($count_page_data){
$tab .= " ";
echo "";
if($total_page > 1) :
echo "";
endif;
$current_list = "";
$data_count = 0;
while($data = $db_dpis->get_array()) {
if (($data[ORG_ID]!=$START_ORG_ID && $data[ORG_ID]!=0 && $data[ORG_ID]!=1) || $START_ORG_ID==$SESS_ORG_ID) { //---ไม่เอา parent
$data_count++;
if($data_count > $data_per_page) break;
$cmd = " select ORG_ID from $ORGTAB where ORG_ID_REF=". $data[ORG_ID];
// echo "$cmd ";
$count_sub_tree = $db_dpis2->send_cmd($cmd);
$class = "table_body";
if ($data[ORG_ID] == $sel_org_id) $class = "table_body_over";
$current_list .= ((trim($current_list))?",":"") . $data[ORG_ID];
$tclass = "table_body";
if(!$count_sub_tree) {
$icon_name = "";
$onClick = "";
} else {
$icon_name = "icon_plus.gif";
$onClick = "select_org(". $data[ORG_ID] .");";
if ($SEL_ORG_ID==$data[ORG_ID]) {
$icon_name = "icon_minus.gif";
$tclass = "table_body_over2";
} // end if
}
if ($data[ORG_ACTIVE]==0) {
$font_red1 = ""; $font_red2 = "";
} else {
$font_red1 = ""; $font_red2 = "";
}
echo "";
echo " $tab ";
echo " ".$font_red1. $data[ORG_NAME] .$font_red2." ";
echo " ";
echo " ";
if ($MFA_FLAG==1 || $BKK_FLAG==1 || $RTF_FLAG==1) {
echo " ";
}
echo " ";
echo " | ";
} // end if ($data[ORG_ID]!=$START_ORG_ID)
} // end while
echo " ";
if($total_page > 1) :
echo "";
endif; echo " ";
} // end if($count_page_data)
} else {
echo "ไม่พบข้อมูลโครงสร้างที่ต้องการ | ";
} // end if ($count_data)
?>
|
|