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");
if( !$current_page ) $current_page = 1;
if(!$data_per_page) $data_per_page = 30;
$start_record = ($current_page - 1) * $data_per_page;
$MENU_ID_LV0 = $_POST['MENU_ID_LV0'];
if (!$MENU_ID_LV0) $MENU_ID_LV0 = $_GET['MENU_ID_LV0'];
$MENU_ID_LV1 = $_POST['MENU_ID_LV1'];
if (!$MENU_ID_LV1) $MENU_ID_LV1 = $_GET['MENU_ID_LV1'];
$MENU_ID_LV2 = $_POST['MENU_ID_LV2'];
if (!$MENU_ID_LV2) $MENU_ID_LV2 = $_GET['MENU_ID_LV2'];
$MENU_ID_LV3 = $_POST['MENU_ID_LV3'];
if (!$MENU_ID_LV3) $MENU_ID_LV3 = $_GET['MENU_ID_LV3'];
$SELECTED_LIST = $_POST['SELECTED_LIST'];
if (!$SELECTED_LIST) $SELECTED_LIST = $_GET['SELECTED_LIST'];
if(substr($SELECTED_LIST,0,4)=="<***"){
$c = strpos($SELECTED_LIST,"***>");
if ($c) $session_save_name = substr($SELECTED_LIST,4,$c-4);
else $session_save_name = substr($SELECTED_LIST,4);
// echo "session_save_name=".$session_save_name."
";
}
// echo "msg_id=$MSG_ID, selected=$SELECTED_LIST
";
// if(trim($SELECTED_LIST)) $arr_search_condition[] = "(id in ($SELECTED_LIST))";
$EXCEPT_PER_ID = $_POST['EXCEPT_PER_ID'];
if (!$EXCEPT_PER_ID) $EXCEPT_PER_ID = $_GET['EXCEPT_PER_ID'];
$EXCEPT_LIST = $_POST['EXCEPT_LIST'];
if (!$EXCEPT_LIST) $EXCEPT_LIST = $_GET['EXCEPT_LIST'];
$isLock = $_POST['isLock'];
if (!$isLock) $isLock = $_GET['isLock'];
$LOCK_MINISTRY_ID = $_POST['LOCK_MINISTRY_ID'];
if (!$LOCK_MINISTRY_ID) $LOCK_MINISTRY_ID = $_GET['LOCK_MINISTRY_ID'];
$LOCK_DEPARTMENT_ID = $_POST['LOCK_DEPARTMENT_ID'];
if (!$LOCK_DEPARTMENT_ID) $LOCK_DEPARTMENT_ID = $_GET['LOCK_DEPARTMENT_ID'];
// $isSubmit2Parent = $_POST['isSubmit2Parent'];
$isSubmit2Parent = "";
$search_condition = "";
$search_per_status = (isset($search_per_status))? $search_per_status : 5;
if(trim($search_group)) $arr_search_condition[] = "(name_th like '%$search_group%')";
if(trim($search_name)) $arr_search_condition[] = "(fullname like '%$search_name%')";
if(trim($search_address)) $arr_search_condition[] = "(address like '%$search_address%')";
if(trim($search_per_status) < 5) {
$temp_per_status = $search_per_status - 1;
$arr_search_condition[] = "(a.PER_STATUS = $temp_per_status and d.USER_LINK_ID = a.PER_ID)";
}
$search_condition = "";
if(count($arr_search_condition)) $search_condition = " where " . implode(" and ", $arr_search_condition);
//หาชื่อผู้ที่มีในระบบการ login
if ($first_loaded==1) {
/*เดิม 2018/09/03 */
/* $cmd1 ="select username, d.id, titlename, fullname, name_th, address
from user_detail d inner join user_group g on g.id = d.group_id
$search_condition
order by g.group_seq_no, g.name_th, d.fullname ";
*/
$search_condition = str_replace(" where ", " and ", $search_condition);
$cmd1 = "select DISTINCT username, d.id, titlename, fullname, name_th, address ,g.group_seq_no
from user_detail d,user_group g , PER_PERSONAL a
where g.id=d.group_id and (d.USER_LINK_ID = a.PER_ID or d.USER_LINK_ID is null or d.USER_LINK_ID=0) $search_condition
order by g.group_seq_no, g.name_th, d.fullname";
$count_data=$db->send_cmd($cmd1);
//$count_data=0;
// echo $cmd1."
";
//$db->show_error();
if (!$ALL_PER_LIST && $count_data) {
$ARR_ALL_PER = (array) null;
$ARR_ALL_GRP= (array) null;
$data_count=0;
while($datausr = $db->get_array()) {
$data_count++;
// if ($data_count > 5000) break;
$datausr = array_change_key_case($datausr, CASE_LOWER);
$ARR_ALL_PER[] = $datausr[id];
$ARR_ALL_GRP[] = $datausr[name_th];
} // end while
$ALL_PER_LIST = implode(",",$ARR_ALL_PER);
$ALL_GRP_LIST = implode(",",$ARR_ALL_GRP);
} // end if (!$ALL_PER_LIST && $count_data)
}
function check_full_group_php($per_id){
global $ALL_PER_LIST, $ALL_GRP_LIST, $SELECTED_LIST;
// echo "per_id=$per_id
";
$arr_per = explode(",", $ALL_PER_LIST);
$arr_grp = explode(",", $ALL_GRP_LIST);
$arr_selected = explode(",", $SELECTED_LIST);
// หา index เริ่มต้นของ กลุ่ม/PER_ID ที่ต้องการ
$target_per_idx = array_search($per_id, $arr_per);
$target_grp_idx = array_search($arr_grp[$target_per_idx], $arr_grp); // หา index ตัวแรกของกลุ่มนี้
$target_firstper_idx = array_search($arr_per[$target_grp_idx], $arr_per); // หา per_id แรก ตาม index แรกของกลุ่ม
$target_idx = $target_firstper_idx;
// $target_idx = $target_per_idx;
$chk_grp = $arr_grp[$target_idx];
$cnt_full=0;
$cnt_exist=0;
while ($chk_grp == $arr_grp[$target_idx]) {
// echo "per_id=$per_id, grp[$target_idx]=".$arr_grp[$target_idx]."
";
$c = array_search($arr_per[$target_idx], $arr_selected);
if ($c !== false) $cnt_exist++; // นับเฉพาะที่เลือกไว้
$cnt_full++; // นับทั้งหมด
$target_idx++;
}
return ($cnt_full==$cnt_exist);
} // end function count_grp
?>