include("../php_scripts/connect_database.php");
$url=$_SERVER["REQUEST_URI"];
$query_str = parse_url($url, PHP_URL_QUERY);
if(empty($current_url)){
$current_url=$query_str;
}
if(!$CARD_NO_FILL && (!$BKK_FLAG && !$ISCS_FLAG)){// fixed $CARD_NO_FILL สำหรับ หน่วยงานอื่นที่ไม่ใช่ $BKK_FLAG || $ISCS_FLAG เพราะไม่มี checkbox ในหน้า C06 กำหนดค่าโปรแกรม
$CARD_NO_FILL = "Y";
}
if(!isset($show_topic)) $show_topic = 1; //echo $show_topic;
if($show_topic==1){
include("php_scripts/personal_master.php");
}elseif($show_topic==2){
//echo "1..POS_NO=$POS_NO , POS_NO_NAME=$POS_NO_NAME ";
include("php_scripts/personal_master_form.php");
if ($form1command=="personal"){
$POS_ID = $sendPOS;
include("php_scripts/find_personal_position.php");
}
}
//echo "$BKK_FLAG || $ISCS_FLAG || $CARD_NO_FILL --------- COMMAND : $command // TOPIC : $show_topic // $POS_ID = $sendPOS -----------";
$db_dpis1 = new connect_dpis($dpisdb_host, $dpisdb_name, $dpisdb_user, $dpisdb_pwd, $dpisdb_port);
$db_dpis2 = new connect_dpis($dpisdb_host, $dpisdb_name, $dpisdb_user, $dpisdb_pwd, $dpisdb_port);
$db_dpis3 = new connect_dpis($dpisdb_host, $dpisdb_name, $dpisdb_user, $dpisdb_pwd, $dpisdb_port);
// รวมไว้ที่เดียวเลย
switch($CTRL_TYPE){
case 2 :
$search_pv_code = $PROVINCE_CODE;
$search_pv_name = $PROVINCE_NAME;
$PROVINCE_CODE = $PROVINCE_CODE;
$PROVINCE_NAME = $PROVINCE_NAME;
break;
case 3 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
break;
case 4 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$search_department_id = $DEPARTMENT_ID;
$search_department_name = $DEPARTMENT_NAME;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
$MAIN_DEPARTMENT_ID = $DEPARTMENT_ID;
$MAIN_DEPARTMENT_NAME = $DEPARTMENT_NAME;
break;
} // end switch case
switch($SESS_USERGROUP_LEVEL){
case 2 :
$search_pv_code = $PROVINCE_CODE;
$search_pv_name = $PROVINCE_NAME;
$PROVINCE_CODE = $PROVINCE_CODE;
$PROVINCE_NAME = $PROVINCE_NAME;
break;
case 3 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
break;
case 4 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$search_department_id = $DEPARTMENT_ID;
$search_department_name = $DEPARTMENT_NAME;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
$MAIN_DEPARTMENT_ID = $DEPARTMENT_ID;
$MAIN_DEPARTMENT_NAME = $DEPARTMENT_NAME;
break;
case 5 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$search_department_id = $DEPARTMENT_ID;
$search_department_name = $DEPARTMENT_NAME;
$search_org_id = $ORG_ID;
$search_org_name = $ORG_NAME;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
$MAIN_DEPARTMENT_ID = $DEPARTMENT_ID;
$MAIN_DEPARTMENT_NAME = $DEPARTMENT_NAME;
$MAIN_ORG_ID = $ORG_ID;
$MAIN_ORG_NAME = $ORG_NAME;
break;
case 6 :
$search_ministry_id = $MINISTRY_ID;
$search_ministry_name = $MINISTRY_NAME;
$search_department_id = $DEPARTMENT_ID;
$search_department_name = $DEPARTMENT_NAME;
$search_org_id = $ORG_ID;
$search_org_name = $ORG_NAME;
$search_org_id_1 = $ORG_ID_1;
$search_org_name_1 = $ORG_NAME_1;
$MAIN_MINISTRY_ID = $MINISTRY_ID;
$MAIN_MINISTRY_NAME = $MINISTRY_NAME;
$MAIN_DEPARTMENT_ID = $DEPARTMENT_ID;
$MAIN_DEPARTMENT_NAME = $DEPARTMENT_NAME;
$MAIN_ORG_ID = $ORG_ID;
$MAIN_ORG_NAME = $ORG_NAME;
break;
} // end switch case
//---เพิ่มมาจาก personal_master_form
if($SESS_PER_TYPE && $SESS_PER_TYPE!=0) $PER_TYPE=$SESS_PER_TYPE;
if(!$PER_TYPE){ $PER_TYPE=1; }
if(!$PER_STATUS){
$PER_STATUS=0;
if ($PER_TYPE==1) $PER_MEMBER=1;
} //default เพิ่มใหม่ รอบรรจุ
if(!$PER_DISABILITY){ $PER_DISABILITY=1; }
$search_per_status = (isset($search_per_status))? $search_per_status : 2;
if ($search_data==20) { $search_per_status = 5; $order_by = 1; }
if($DPISDB=="odbc") {
$POS_NO_NUM = "CLng(POS_NO)";
$POEM_NO_NUM = "CLng(POEM_NO)";
$POEMS_NO_NUM = "CLng(POEMS_NO)";
$POT_NO_NUM = "CLng(POT_NO)";
} elseif($DPISDB=="oci8") {
$POS_NO_NUM = "to_number(replace(POS_NO,'-',''))";
$POEM_NO_NUM = "to_number(replace(POEM_NO,'-',''))";
$POEMS_NO_NUM = "to_number(replace(POEMS_NO,'-',''))";
$POT_NO_NUM = "to_number(replace(POT_NO,'-',''))";
} elseif($DPISDB=="mysql") {
$POS_NO_NUM = "POS_NO+0";
$POEM_NO_NUM = "POEM_NO+0";
$POEMS_NO_NUM = "POEMS_NO+0";
$POT_NO_NUM = "POT_NO+0";
} // end if
// ส่วนของการค้นหา จากเงื่อนไขที่เลือกมา //
if (!$search_cardno || $SESS_USERGROUP!=1) {
if($search_org_id_1 && !$search_org_id_2 && !$search_org_id_3 && !$search_org_id_4 && !$search_org_id_5){ /* Release 5.1.0.4 */
if($select_org_structure==0){ //โครงสร้างตามกฎหมาย
$arr_search_condition[] = "(c.ORG_ID_1=$search_org_id_1 or d.ORG_ID_1=$search_org_id_1 or e.ORG_ID_1=$search_org_id_1 or g.ORG_ID_1=$search_org_id_1)";
}else if($select_org_structure==1){ //โครงสร้างตามมอบหมายงาน
$arr_search_condition[] = "(a.ORG_ID_1=$search_org_id_1)";
}
}elseif($search_org_id_1 && $search_org_id_2 && !$search_org_id_3 && !$search_org_id_4 && !$search_org_id_5){ /* Release 5.1.0.4 */
if($select_org_structure==0){ //โครงสร้างตามกฎหมาย
$arr_search_condition[] = "(c.ORG_ID_2=$search_org_id_2 or d.ORG_ID_2=$search_org_id_2 or e.ORG_ID_2=$search_org_id_2 or g.ORG_ID_2=$search_org_id_2)";
}else if($select_org_structure==1){ //โครงสร้างตามมอบหมายงาน
$arr_search_condition[] = "(a.ORG_ID_2=$search_org_id_2)";
}
}elseif($search_org_id_1 && $search_org_id_2 && $search_org_id_3 && !$search_org_id_4 && !$search_org_id_5){ /* Release 5.1.0.4 */
if($select_org_structure==0){ //โครงสร้างตามกฎหมาย
$arr_search_condition[] = "(c.ORG_ID_3=$search_org_id_3 or d.ORG_ID_3=$search_org_id_3 or e.ORG_ID_3=$search_org_id_3 or g.ORG_ID_3=$search_org_id_3)";
}else if($select_org_structure==1){ //โครงสร้างตามมอบหมายงาน
$arr_search_condition[] = "(a.ORG_ID_3=$search_org_id_3)";
}
}elseif($search_org_id_1 && $search_org_id_2 && $search_org_id_3 && $search_org_id_4 && !$search_org_id_5){ /* Release 5.1.0.4 */
if($select_org_structure==0){ //โครงสร้างตามกฎหมาย
$arr_search_condition[] = "(c.ORG_ID_4=$search_org_id_4 or d.ORG_ID_4=$search_org_id_4 or e.ORG_ID_4=$search_org_id_4 or g.ORG_ID_4=$search_org_id_4)";
}else if($select_org_structure==1){ //โครงสร้างตามมอบหมายงาน
$arr_search_condition[] = "(a.ORG_ID_4=$search_org_id_4)";
}
}elseif($search_org_id_1 && $search_org_id_2 && $search_org_id_3 && $search_org_id_4 && $search_org_id_5){ /* Release 5.1.0.4 */
if($select_org_structure==0){ //โครงสร้างตามกฎหมาย
$arr_search_condition[] = "(c.ORG_ID_5=$search_org_id_5 or d.ORG_ID_5=$search_org_id_5 or e.ORG_ID_5=$search_org_id_5 or g.ORG_ID_5=$search_org_id_5)";
}else if($select_org_structure==1){ //โครงสร้างตามมอบหมายงาน
$arr_search_condition[] = "(a.ORG_ID_5=$search_org_id_5)";
}
}elseif($search_org_id){
if($select_org_structure==0){
$arr_search_condition[] = "(c.ORG_ID=$search_org_id or d.ORG_ID=$search_org_id or e.ORG_ID=$search_org_id or g.ORG_ID=$search_org_id)";
}else if($select_org_structure==1){
$arr_search_condition[] = "(a.ORG_ID=$search_org_id )";
// $arr_search_condition[] = "(a.ORG_ID=$search_org_id or c.ORG_ID=$search_org_id)";
}
}elseif($search_department_id){
$arr_search_condition[] = "(a.DEPARTMENT_ID = $search_department_id)";
}elseif($search_ministry_id){
unset($arr_department);
$cmd = " select ORG_ID from PER_ORG where ORG_ID_REF=$search_ministry_id and OL_CODE='02' ";
if($SESS_ORG_STRUCTURE==1){ $cmd = str_replace("PER_ORG","PER_ORG_ASS",$cmd); }
$db_dpis->send_cmd($cmd);
while($data = $db_dpis->get_array()) $arr_department[] = $data[ORG_ID];
$arr_search_condition[] = "(a.DEPARTMENT_ID in (". implode(",", $arr_department) ."))";
}elseif($PROVINCE_CODE){
$cmd = " select distinct ORG_ID_REF from PER_ORG where PV_CODE='$PROVINCE_CODE' and OL_CODE='03' ";
if($SESS_ORG_STRUCTURE==1){ $cmd = str_replace("PER_ORG","PER_ORG_ASS",$cmd); }
$db_dpis->send_cmd($cmd);
while($data = $db_dpis->get_array()) $arr_department[] = $data[ORG_ID_REF];
$arr_search_condition[] = "(a.DEPARTMENT_ID in (". implode(",", $arr_department) ."))";
} // end if
}
if(!$sort_by) $sort_by=2;
$sort_type = (isset($sort_type))? $sort_type : "1:asc";
$arrSort=explode(":",$sort_type);
$SortType[$arrSort[0]] =$arrSort[1];
if(!$order_by) $order_by=2;
/*Release 5.2.1.7 .... 25/04/2017 */
if($search_per_type == "1"){ if(trim($search_pl_code)) $arr_search_condition[] = "(trim(c.PL_CODE) = '". trim($search_pl_code) ."')"; }
else if($search_per_type == "2"){ if(trim($search_pl_code)) $arr_search_condition[] = "(trim(d.PN_CODE) = '". trim($search_pl_code) ."')"; }
else if($search_per_type == "3"){ if(trim($search_pl_code)) $arr_search_condition[] = "(trim(e.EP_CODE) = '". trim($search_pl_code) ."')"; }
else if($search_per_type == "4"){ if(trim($search_pl_code)) $arr_search_condition[] = "(trim(g.TP_CODE) = '". trim($search_pl_code) ."')"; }
else if($search_per_type == "0"){ if(trim($search_pl_code)) $arr_search_condition[] = "(trim(c.PL_CODE) = '". trim($search_pl_code) ."')"; }
/*END Release 5.2.1.7 .... 25/04/2017*/
if(trim($search_pm_code)) $arr_search_condition[] = "(trim(PM_CODE) = '". trim($search_pm_code) ."')";
if(trim($search_name))
if($command == "SEARCH") $arr_search_condition[] = "(PER_NAME like '$search_name%' or UPPER(PER_ENG_NAME) like UPPER('$search_name%'))";
elseif($command == "SEARCHNAMEHIS") $arr_search_condition[] = "(PER_NAME like '$search_name%' or UPPER(PER_ENG_NAME) like UPPER('$search_name%') or NH_NAME like '$search_name%')";
if(trim($search_surname))
if($command == "SEARCH") $arr_search_condition[] = "(PER_SURNAME like '$search_surname%' or UPPER(PER_ENG_SURNAME) like UPPER('$search_surname%'))";
elseif($command == "SEARCHNAMEHIS") $arr_search_condition[] = "(PER_SURNAME like '$search_surname%' or UPPER(PER_ENG_SURNAME) like UPPER('$search_surname%') or NH_SURNAME like '$search_surname%')";;
if(trim($search_cardno)) $arr_search_condition[] = "(a.PER_CARDNO = '$search_cardno')";
if(trim($search_offno)) $arr_search_condition[] = "(PER_OFFNO = '$search_offno')";
if(trim($search_pos_no)) {
if ($search_per_type == 1 || $search_per_type==5)
$arr_search_condition[] = "(trim(POS_NO) = '$search_pos_no')";
elseif ($search_per_type == 2)
$arr_search_condition[] = "(trim(POEM_NO) = '$search_pos_no')";
elseif ($search_per_type == 3)
$arr_search_condition[] = "(trim(POEMS_NO) = '$search_pos_no')";
elseif ($search_per_type == 4)
$arr_search_condition[] = "(trim(POT_NO) = '$search_pos_no')";
else if ($search_per_type==0) //ทั้งหมด
$arr_search_condition[] = "((trim(POS_NO) = '$search_pos_no') or (trim(POEM_NO) = '$search_pos_no') or (trim(POEMS_NO) = '$search_pos_no') or (trim(POT_NO) = '$search_pos_no')) ";
}
if(trim($search_pos_no_name)){
if ($search_per_type == 1 || $search_per_type==5)
$arr_search_condition[] = "(trim(POS_NO_NAME) like '$search_pos_no_name%')";
elseif ($search_per_type == 2)
$arr_search_condition[] = "(trim(POEM_NO_NAME) like '$search_pos_no_name%')";
elseif ($search_per_type == 3)
$arr_search_condition[] = "(trim(POEMS_NO_NAME) like '$search_pos_no_name%')";
elseif ($search_per_type == 4)
$arr_search_condition[] = "(trim(POT_NO_NAME) like '$search_pos_no_name%')";
else if ($search_per_type==0) //ทั้งหมด
$arr_search_condition[] = "((trim(POS_NO_NAME) like '$search_pos_no_name%') or (trim(POEM_NO_NAME) like '$search_pos_no_name%') or
(trim(POEMS_NO_NAME) like '$search_pos_no_name%') or (trim(POT_NO_NAME) like '$search_pos_no_name%')) ";
}
if(trim($search_pay_no)) $arr_search_condition[] = "(trim(POS_NO) = '$search_pay_no' and a.PER_TYPE = 1)";
if(trim($search_level_no)) $arr_search_condition[] = "(trim(a.LEVEL_NO) = '". trim($search_level_no) ."')";
if(trim($search_per_type)) $arr_search_condition[] = "(a.PER_TYPE = $search_per_type)";
if(trim($search_per_status) < 5) {
$temp_per_status = $search_per_status - 1;
$arr_search_condition[] = "(PER_STATUS = $temp_per_status)";
}
$check_condition = "";
if ($search_data==1)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%1%')) ";
elseif ($search_data==2)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%2%')) ";
elseif ($search_data==3)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_POSITIONHIS b where a.PER_ID = b.PER_ID)) ";
elseif ($search_data==4)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_SALARYHIS b where a.PER_ID = b.PER_ID)) ";
elseif ($search_data==5)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_DECORATEHIS b where a.PER_ID = b.PER_ID)) ";
elseif ($search_data==6)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%1%' group by b.PER_ID having count(*) > 1)) ";
elseif ($search_data==7)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%2%' group by b.PER_ID having count(*) > 1)) ";
elseif ($search_data==8)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and INS_CODE is NULL and EDU_INSTITUTE is NULL)) ";
elseif ($search_data==9)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%4%')) ";
elseif ($search_data==10)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_EDUCATE b where a.PER_ID = b.PER_ID and EDU_TYPE like '%4%' group by b.PER_ID having count(*) > 1)) ";
elseif ($search_data==11) {
// PIC_SIGN ไม่เท่ากับ 1 หรือ = NULL แปลว่า เป็นรูปที่ใช้แสดง และไม่ใช้ลายเซ็น
// $check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_PERSONALPIC b where a.PER_ID = b.PER_ID and PIC_SHOW = 1 and (PIC_SIGN <> 1 or PIC_SIGN is NULL))) ";
$check_condition = "";
} elseif ($search_data==12)
$check_condition = " and (a.ORG_ID is NULL) ";
elseif ($search_data==13) {
// PIC_SIGN = 1 แปลว่า เป็นรูป "ลายเซ็น" ที่ใช้แสดง
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_PERSONALPIC b where a.PER_ID = b.PER_ID and PIC_SHOW = 1 and PIC_SIGN = 1)) ";
$check_condition = "";
} elseif ($search_data==14)
$check_condition = " and (c.PL_CODE in (select d.PL_CODE from PER_LINE d where c.PL_CODE = d.PL_CODE and a.LEVEL_NO not between LEVEL_NO_MIN and LEVEL_NO_MAX)) ";
elseif ($search_data==15)
$check_condition = " and (a.POS_ID in (select POS_ID from PER_PERSONAL where PER_TYPE = 1 and PER_STATUS = 1 group by POS_ID having count(*) > 1)) ";
elseif ($search_data==16)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_POSITIONHIS b where a.PER_ID = b.PER_ID and b.POH_EFFECTIVEDATE < '$PT_DATE' and (b.LEVEL_NO in ('O1', 'O2', 'O3', 'O4', 'K1', 'K2', 'K3', 'K4', 'K5', 'D1', 'D2', 'M1', 'M2') or b.POH_LEVEL_NO in ('O1', 'O2', 'O3', 'O4', 'K1', 'K2', 'K3', 'K4', 'K5', 'D1', 'D2', 'M1', 'M2')))) ";
elseif ($search_data==17)
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SALARYHIS b where a.PER_ID = b.PER_ID and b.SAH_EFFECTIVEDATE < '$PT_DATE' and b.LEVEL_NO in ('O1', 'O2', 'O3', 'O4', 'K1', 'K2', 'K3', 'K4', 'K5', 'D1', 'D2', 'M1', 'M2'))) ";
elseif ($search_data==18)
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_ABSENTHIS b where a.PER_ID = b.PER_ID)) ";
elseif ($search_data==19) {
$cmd = " select PER_ID from PER_PERSONAL where POS_ID in (select POS_ID from PER_POS_MGTSALARY a, PER_EXTRATYPE b
where a.EX_CODE=b.EX_CODE and POS_STATUS = 1 and MGT_FLAG = 1) and PER_TYPE = 1 and PER_STATUS = 1
minus
select PER_ID from PER_POS_MGTSALARYHIS a, PER_EXTRATYPE b
where a.EX_CODE=b.EX_CODE and MGT_FLAG = 1 and PMH_ACTIVE = 1 and
(PMH_ENDDATE is NULL or PMH_ENDDATE >= '$UPDATE_DATE') ";
$db_dpis2->send_cmd($cmd);
// echo "$cmd ";
while ($data2 = $db_dpis2->get_array()) {
$arr_per_id[] = $data2[PER_ID];
}
$check_condition = " and (a.PER_ID in (".implode(",",$arr_per_id).")) ";
} elseif ($search_data==20) {
$cmd = " select PER_ID, PER_NAME, PER_SURNAME from PER_PERSONAL order by PER_NAME, PER_SURNAME ";
$db_dpis2->send_cmd($cmd);
// echo "$cmd ";
while ($data2 = $db_dpis2->get_array()) {
if ($CHK_PER_NAME == trim($data2[PER_NAME]) && $CHK_PER_SURNAME == trim($data2[PER_SURNAME])) {
$count = $count + 2;
if ($count < 1000) {
$arr_per_id[] = $data2[PER_ID];
$arr_per_id[] = $CHK_PER_ID;
} elseif ($count < 2000) {
$arr_per_id2[] = $data2[PER_ID];
$arr_per_id2[] = $CHK_PER_ID;
} elseif ($count < 3000) {
$arr_per_id3[] = $data2[PER_ID];
$arr_per_id3[] = $CHK_PER_ID;
} elseif ($count < 4000) {
$arr_per_id4[] = $data2[PER_ID];
$arr_per_id4[] = $CHK_PER_ID;
} elseif ($count < 5000) {
$arr_per_id5[] = $data2[PER_ID];
$arr_per_id5[] = $CHK_PER_ID;
} elseif ($count < 6000) {
$arr_per_id6[] = $data2[PER_ID];
$arr_per_id6[] = $CHK_PER_ID;
} elseif ($count < 7000) {
$arr_per_id7[] = $data2[PER_ID];
$arr_per_id7[] = $CHK_PER_ID;
} elseif ($count < 8000) {
$arr_per_id8[] = $data2[PER_ID];
$arr_per_id8[] = $CHK_PER_ID;
} elseif ($count < 9000) {
$arr_per_id9[] = $data2[PER_ID];
$arr_per_id9[] = $CHK_PER_ID;
} elseif ($count < 10000) {
$arr_per_id10[] = $data2[PER_ID];
$arr_per_id10[] = $CHK_PER_ID;
} elseif ($count < 11000) {
$arr_per_id11[] = $data2[PER_ID];
$arr_per_id11[] = $CHK_PER_ID;
} else {
$arr_per_id12[] = $data2[PER_ID];
$arr_per_id12[] = $CHK_PER_ID;
}
}
$CHK_PER_ID = $data2[PER_ID];
$CHK_PER_NAME = trim($data2[PER_NAME]);
$CHK_PER_SURNAME = trim($data2[PER_SURNAME]);
}
if (count($arr_per_id) > 0) {
if (count($arr_per_id11)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")) or (a.PER_ID in (". implode(",", $arr_per_id8) .")) or
(a.PER_ID in (". implode(",", $arr_per_id9) .")) or (a.PER_ID in (". implode(",", $arr_per_id10) .")) or
(a.PER_ID in (". implode(",", $arr_per_id11) .")) or (a.PER_ID in (". implode(",", $arr_per_id12) .")))";
elseif (count($arr_per_id11)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")) or (a.PER_ID in (". implode(",", $arr_per_id8) .")) or
(a.PER_ID in (". implode(",", $arr_per_id9) .")) or (a.PER_ID in (". implode(",", $arr_per_id10) .")) or
(a.PER_ID in (". implode(",", $arr_per_id11) .")))";
elseif (count($arr_per_id10)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")) or (a.PER_ID in (". implode(",", $arr_per_id8) .")) or
(a.PER_ID in (". implode(",", $arr_per_id9) .")) or (a.PER_ID in (". implode(",", $arr_per_id10) .")))";
elseif (count($arr_per_id9)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")) or (a.PER_ID in (". implode(",", $arr_per_id8) .")) or
(a.PER_ID in (". implode(",", $arr_per_id9) .")))";
elseif (count($arr_per_id8)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")) or (a.PER_ID in (". implode(",", $arr_per_id8) .")))";
elseif (count($arr_per_id7)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")) or
(a.PER_ID in (". implode(",", $arr_per_id7) .")))";
elseif (count($arr_per_id6)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")) or (a.PER_ID in (". implode(",", $arr_per_id6) .")))";
elseif (count($arr_per_id5)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")) or
(a.PER_ID in (". implode(",", $arr_per_id5) .")))";
elseif (count($arr_per_id4)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")) or (a.PER_ID in (". implode(",", $arr_per_id4) .")))";
elseif (count($arr_per_id3)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")) or
(a.PER_ID in (". implode(",", $arr_per_id3) .")))";
elseif (count($arr_per_id2)) $check_condition = " and ((a.PER_ID in (". implode(",", $arr_per_id) .")) or (a.PER_ID in (". implode(",", $arr_per_id2) .")))";
else $check_condition = " and (a.PER_ID in (".implode(",",$arr_per_id).")) ";
}
}
else if($search_data==21){/* เพิ่มการเช็ค มีข้อมูลความเชี่ยวชาญพิเศษ 3/11/2559*/
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID and b.ss_code != '-1')) ";
}else if($search_data==22){/* เพิ่มการเช็คที่มีการตรวจสอบเเล้ว มีข้อมูลความเชี่ยวชาญพิเศษ 3/11/2559*/
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID and b.ss_code != '-1' and b.AUDIT_FLAG = '2')) ";
}else if($search_data==23){
$cmd = " select AUDIT_FLAG from PER_SPECIAL_SKILL ";
$db_dpis->send_cmd($cmd);
while($data = $db_dpis->get_array()){
$data[AUDIT_FLAG];
}
if($data[AUDIT_FLAG] != "1" || $data[AUDIT_FLAG] != "2" || $data[AUDIT_FLAG] != "3"){/* เพิ่มการเช็คที่ยังไม่ได้ตรวจสอบ มีข้อมูลความเชี่ยวชาญพิเศษ 3/11/2559*/
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID AND b.AUDIT_FLAG is null OR AUDIT_FLAG='N' and b.ss_code != '-1')) ";
}
}// credit by kong
else if($search_data==24){
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_PERSONAL b where a.PER_ID = b.PER_ID and b.LEVEL_NO IS NULL)) ";
}else if($search_data==25){
$check_condition = " and (a.PER_ID not in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID)) ";
}else if($search_data==26){
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID and b.ss_code = '-1')) ";
}else if($search_data==27){
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID and b.ss_code != '-1' and b.AUDIT_FLAG = '1')) ";
}
/* Release 5.2.1.7 ปรับเปลี่ยน flag เหลือ 3
else if($search_data==28){
$check_condition = " and (a.PER_ID in (select b.PER_ID from PER_SPECIAL_SKILL b where a.PER_ID = b.PER_ID and b.ss_code != '-1' and b.AUDIT_FLAG = '3')) ";
}
*/
$search_condition = "";
if(count($arr_search_condition)) $search_condition = " where " . implode(" and ", $arr_search_condition);
if($order_by==1) { //ชื่อ
if($DPISDB=="oci8"){
$order_str = "NLSSORT(PER_NAME,'NLS_SORT=THAI_DICTIONARY') $SortType[$order_by], NLSSORT(PER_SURNAME,'NLS_SORT=THAI_DICTIONARY') $SortType[$order_by] ";
}else{
$order_str = "PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by] ";
}
} elseif($order_by==2){ //(ค่าเริ่มต้น) เลขที่ตำแหน่ง
$org_cond = "";
if ($POSITION_NO_CHAR=="Y") $org_cond = ", i.ORG_SEQ_NO $SortType[$order_by], i.ORG_CODE $SortType[$order_by]";
if($DPISDB=="odbc") {
if ($search_per_type==0 || $search_per_type==1 || $search_per_type==5)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POS_NO_NAME $SortType[$order_by], iif(isnull(POS_NO),0,$POS_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==2)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POEM_NO_NAME $SortType[$order_by], iif(isnull(POEM_NO),0,$POEM_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==3)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POEMS_NO_NAME $SortType[$order_by], iif(isnull(POEMS_NO),0,$POEMS_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==4)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POT_NO_NAME $SortType[$order_by], iif(isnull(POT_NO),0,$POT_NO_NUM) $SortType[$order_by]";
}elseif($DPISDB=="oci8" || $DPISDB=="mysql"){
if ($search_per_type==0 || $search_per_type==1 || $search_per_type==5)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POS_NO_NAME $SortType[$order_by], $POS_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==2)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POEM_NO_NAME $SortType[$order_by], $POEM_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==3)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POEMS_NO_NAME $SortType[$order_by], $POEMS_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==4)
$order_str = "a.DEPARTMENT_ID $SortType[$order_by]".$org_cond.", POT_NO_NAME $SortType[$order_by], $POT_NO_NUM $SortType[$order_by]";
}
} elseif($order_by==3) {//ระดับตำแหน่ง
if($DPISDB=="odbc") {
if ($search_per_type==0 || $search_per_type==1 || $search_per_type==5) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], iif(isnull(POS_NO),0,$POS_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==2) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], iif(isnull(POEM_NO),0,$POEM_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==3) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], iif(isnull(POEMS_NO),0,$POEMS_NO_NUM) $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==4) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], iif(isnull(POT_NO),0,$POT_NO_NUM) $SortType[$order_by]";
}elseif($DPISDB=="oci8" || $DPISDB=="mysql"){
if ($search_per_type==0 || $search_per_type==1 || $search_per_type==5) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], $POS_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==2) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], $POEM_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==3) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], $POEMS_NO_NUM $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==4) $order_str = "f.LEVEL_SEQ_NO $SortType[$order_by], $POT_NO_NUM $SortType[$order_by]";
}
} elseif($order_by==4) {
$order_str = "a.DEPARTMENT_ID $SortType[$order_by], PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by]";
} elseif($order_by==5) {
if ($search_per_type==0 || $search_per_type==1 || $search_per_type==5) $order_str = "c.ORG_ID $SortType[$order_by], PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==2) $order_str = "d.ORG_ID $SortType[$order_by], PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==3) $order_str = "e.ORG_ID $SortType[$order_by], PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by]";
elseif ($search_per_type==0 || $search_per_type==4) $order_str = "f.ORG_ID $SortType[$order_by], PER_NAME $SortType[$order_by], PER_SURNAME $SortType[$order_by]";
} elseif($order_by==6) {
if ($SESS_DEPARTMENT_NAME=="กรมวิชาการเกษตร")
$order_str = "PER_SEQ_NO $SortType[$order_by]";
else
$order_str = "PER_FILE_NO $SortType[$order_by]";
}
if($command == "SEARCH" || $command == "SEARCHNAMEHIS" || $command == "SEARCHPAY"){
if($command == "SEARCH" || $command == "SEARCHNAMEHIS") $search_con = "a.POS_ID=c.POS_ID";
elseif($command == "SEARCHPAY") $search_con = "a.PAY_ID=c.POS_ID";
if($search_pos_no || $search_pos_no_name) $search_con = "a.POS_ID=c.POS_ID";
elseif($search_pay_no) $search_con = "a.PAY_ID=c.POS_ID";
/* by jerd **********************************
//สำหรับเงื่อนไข check คนที่ไม่มีรูปประจำตัว
if ($search_data==11){
if($DPISDB=="odbc"){
$cmd = " select a.PER_CARDNO, a.PER_ID, a.PN_CODE, PER_NAME, PER_SURNAME, NH_NAME, NH_SURNAME
from (
(
(
(
(
(
PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_LEVEL f on (a.LEVEL_NO=f.LEVEL_NO)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
) left join PER_NAMEHIS h on (a.PER_ID=h.PER_ID)
) left join PER_ORG i on (c.ORG_ID=i.ORG_ID)
$search_condition $check_condition
order by $order_str ";
}elseif($DPISDB=="oci8"){
$search_condition = str_replace(" where ", " and ", $search_condition);
$cmd = "select a.PER_CARDNO, a.PER_ID, a.PN_CODE, PER_NAME, PER_SURNAME, NH_NAME, NH_SURNAME
from PER_PERSONAL a, PER_POSITION c, PER_POS_EMP d, PER_POS_EMPSER e, PER_LEVEL f, PER_POS_TEMP g, PER_NAMEHIS h, PER_ORG i
where $search_con(+) and a.POEM_ID=d.POEM_ID(+) and a.POEMS_ID=e.POEMS_ID(+) and a.LEVEL_NO=f.LEVEL_NO(+) and
a.POT_ID=g.POT_ID(+) and a.PER_ID=h.PER_ID(+) and c.ORG_ID=i.ORG_ID(+)
$search_condition $check_condition
order by $order_str ";
}elseif($DPISDB=="mysql"){
$cmd = " select a.PER_CARDNO, a.PER_ID, a.PN_CODE, PER_NAME, PER_SURNAME, NH_NAME, NH_SURNAME
from (
(
(
(
(
(
PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_LEVEL f on (a.LEVEL_NO=f.LEVEL_NO)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
) left join PER_NAMEHIS h on (a.PER_ID=h.PER_ID)
) left join PER_ORG i on (c.ORG_ID=i.ORG_ID)
$search_condition $check_condition
order by $order_str ";
}
// echo "
$cmd ";
$db_dpis->send_cmd($cmd);
// $db_dpis->show_error();
$countNOPIC=0;
while ($data = $db_dpis->get_array()) {
$PER_ID= trim($data[PER_ID]);
$PER_NAME_SHOW = $data[PER_NAME];
$PER_SURNAME_SHOW = $data[PER_SURNAME];
$FULLNAME = "$PER_NAME_SHOW $PER_SURNAME_SHOW";
$FULLNAMEO = "$NH_NAME $NH_SURNAME";
$PER_CARDNO=trim($data[PER_CARDNO]);
if(!file_exists("../attachment/pic_personal/".$PER_CARDNO."-001.jpg")){
//echo "[ไม่มี] $PER_CARDNO = $PER_ID :: $FULLNAME ";
$arrNOPIC[]="'".$PER_ID."'";
}else{ //มี
//echo "[มี] $PER_CARDNO = $PER_ID :: $FULLNAME ";
$arrHAVEPIC[]="'".$PER_ID."'";
}
} //end while
//ใน query IN ต้องมีจำนวน list ไม่มากกว่า 1000 ถ้ามากกว่า มันจะ error
if(is_array($arrNOPIC)){
$countNOPIC=count($arrNOPIC);
for($i=0; $i < $countNOPIC; $i++){
if($i%1000==0){
$aa[]=$i;
}
}
//วน loop เพื่อสร้าง string
for($i=0; $i";
for($j=($aa[$i]); $j<($aa[$i+1]); $j++){ $strfirst.=$arrNOPIC[$j].","; }
}else{
if($i==count($aa)-1){ //ตำแหน่งสุดท้าย
//__echo ($aa[$i])." < ".$countNOPIC." ";
for($j=($aa[$i]); $j<($countNOPIC); $j++){ $strlast.=$arrNOPIC[$j].","; }
}else{ //ตำแหน่งอื่นๆ ซึ่งมีมากกว่า 1 อัน
//__echo ($aa[$i])." < ".$aa[$i+1]." ";
$count++;
for($j=($aa[$i]); $j<($aa[$i+1]); $j++){ $strmid[$count] .=$arrNOPIC[$j].","; }
}
}
} // end for
//##สร้างเงื่อนไขให้ query (==First==)##
$strfirst=substr($strfirst,0,-1);
$check_condition = " and (a.PER_ID in (".$strfirst.") ";
for($i=1; $i <= count($strmid); $i++){ $arr_strmid[$i]=" or a.PER_ID in ( ".substr($strmid[$i],0,-1).") "; } //end for
//==Middle==//
for($i=1; $i <= count($arr_strmid); $i++){ $check_condition .= $arr_strmid[$i]; } //end for
//==Last==//
$strlast=substr($strlast,0,-1);
$check_condition .= " or a.PER_ID in (".$strlast.")) ";
} //end if(is_array($arrNOPIC))
if(is_array($arrHAVEPIC)){
$countHAVEPIC=count($arrHAVEPIC); //$check_condition = " and (a.PER_ID not in (". implode(",", $arrHAVEPIC) .")) "; //ตัดคนที่มีออก เอาคนที่ไม่มีมา
}
//___echo $check_condition." ";
} //end if check คนที่ไม่มีรูปประจำตัว
by jerd ***************************************/
if($command == "SEARCH") {
if($DPISDB=="odbc"){
$cmd = " select count(a.PER_ID) as count_data
from ((( PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
$search_condition $check_condition ";
}elseif($DPISDB=="oci8"){
$search_condition = str_replace(" where ", " and ", $search_condition);
$cmd = " select count(a.PER_ID) as count_data
from PER_PERSONAL a, PER_POSITION c, PER_POS_EMP d, PER_POS_EMPSER e, PER_POS_TEMP g
where $search_con(+) and a.POEM_ID=d.POEM_ID(+) and a.POEMS_ID=e.POEMS_ID(+) and a.POT_ID=g.POT_ID(+)
$search_condition $check_condition ";
}elseif($DPISDB=="mysql"){
$cmd = " select count(a.PER_ID) as count_data
from ((( PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
$search_condition $check_condition ";
} // end if
} elseif($command == "SEARCHNAMEHIS") {
if($DPISDB=="odbc"){
$cmd = " select count(a.PER_ID) as count_data
from (((( PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
) left join PER_NAMEHIS h on (a.PER_ID=h.PER_ID)
$search_condition $check_condition ";
}elseif($DPISDB=="oci8"){
$search_condition = str_replace(" where ", " and ", $search_condition);
$cmd = " select count(a.PER_ID) as count_data
from PER_PERSONAL a, PER_POSITION c, PER_POS_EMP d, PER_POS_EMPSER e, PER_POS_TEMP g, PER_NAMEHIS h
where $search_con(+) and a.POEM_ID=d.POEM_ID(+) and a.POEMS_ID=e.POEMS_ID(+) and a.POT_ID=g.POT_ID(+) and a.PER_ID=h.PER_ID(+)
$search_condition $check_condition ";
}elseif($DPISDB=="mysql"){
$cmd = " select count(a.PER_ID) as count_data
from (((( PER_PERSONAL a
left join PER_POSITION c on ($search_con)
) left join PER_POS_EMP d on (a.POEM_ID=d.POEM_ID)
) left join PER_POS_EMPSER e on (a.POEMS_ID=e.POEMS_ID)
) left join PER_POS_TEMP g on (a.POT_ID=g.POT_ID)
) left join PER_NAMEHIS h on (a.PER_ID=h.PER_ID)
$search_condition $check_condition ";
} // end if
} // end if
$db_dpis->send_cmd($cmd);
// $db_dpis->show_error();
$data = $db_dpis->get_array();
$data = array_change_key_case($data, CASE_LOWER);
$count_data = $data[count_data];
// if(isset($countNOPIC)){ $count_data = $countNOPIC; }
// echo "$cmd ($count_data) ";
// เกี่ยวกับรูปภาพ
if ($count_data > 0) {
if ($search_data==11 || $search_data==13) { // กรณีค้นหา ไม่มีรูปภาพ หรือ ไม่มีลายเซ็น
$cmd1 = str_replace("count(a.PER_ID) as count_data","a.PER_ID",$cmd);
// echo "$cmd1 ";
$db_dpis1->send_cmd($cmd1);
$arr_per_id = $arr_per_id2 = $arr_per_id3 = $arr_per_id4 = $arr_per_id5 = $arr_per_id6 = (array) null; // select per_id not in $arr_per_id
$cnt_deduct = $count = 0;
while ($data1 = $db_dpis1->get_array()) {
$TMP_PER_ID = $data1[PER_ID];
// echo "TMP_PER_ID=$TMP_PER_ID ";
if ($TMP_PER_ID) {
if ($search_data==11) { // รูปภาพ
$cmd2 = " select * from PER_PERSONALPIC where PER_ID=$TMP_PER_ID and PIC_SHOW=1 and (PIC_SIGN <> 1 or PIC_SIGN is NULL) order by PER_ID, PER_PICSEQ ";
} else { // รูปลายเซ็น $search_data==13
$cmd2 = " select * from PER_PERSONALPIC where PER_ID=$TMP_PER_ID and PIC_SHOW=1 and PIC_SIGN = 1 order by PER_ID, PER_PICSEQ ";
}
$db_dpis2->send_cmd($cmd2);
// echo "cmd2=$cmd2 ";
$founded = false;
while ($data2 = $db_dpis2->get_array()) {
$TMP_PIC_SEQ = $data2[PER_PICSEQ];
// echo "CARD=".$data2[PER_CARDNO]."-".$TMP_PIC_SEQ." ";
$current_list .= ((trim($current_list))?",":"") . $TMP_PIC_SEQ;
$T_PIC_SEQ = substr("000",0,3-strlen("$TMP_PIC_SEQ"))."$TMP_PIC_SEQ";
$TMP_SERVER = $data2[PIC_SERVER_ID];
$TMP_PIC_SIGN= $data2[PIC_SIGN];
if ($TMP_SERVER) {
$cmd3 = " SELECT * FROM OTH_SERVER WHERE SERVER_ID=$TMP_SERVER ";
$db_dpis3->send_cmd($cmd3);
$data3 = $db_dpis3->get_array();
$tmp_SERVER_NAME = trim($data3[SERVER_NAME]);
$tmp_ftp_server = trim($data3[FTP_SERVER]);
$tmp_ftp_username = trim($data3[FTP_USERNAME]);
$tmp_ftp_password = trim($data3[FTP_PASSWORD]);
$tmp_main_path = trim($data3[MAIN_PATH]);
$tmp_http_server = trim($data3[HTTP_SERVER]);
} else {
$TMP_SERVER = 0;
$tmp_SERVER_NAME = "";
$tmp_ftp_server = "";
$tmp_ftp_username = "";
$tmp_ftp_password = "";
$tmp_main_path = "";
$tmp_http_server = "";
}
$SIGN_NAME = "";
if($TMP_PIC_SIGN==1){ $SIGN_NAME = "SIGN"; }
if (trim($data2[PER_CARDNO]) && trim($data2[PER_CARDNO]) != "NULL") {
$TMP_PIC_NAME = $data2[PER_PICPATH].$data2[PER_CARDNO]."-".$SIGN_NAME.$T_PIC_SEQ.".jpg".($tmp_SERVER_NAME ? " [".$tmp_SERVER_NAME."]" : "");
$TMP_SHOW_PIC = ($tmp_http_server ? $tmp_http_server."/" : "").$data2[PER_PICPATH].$data2[PER_CARDNO]."-".$SIGN_NAME.$T_PIC_SEQ.".jpg";
} else {
$TMP_PIC_NAME = $data2[PER_PICPATH].$data2[PER_GENNAME]."-".$SIGN_NAME.$T_PIC_SEQ.".jpg".($tmp_SERVER_NAME ? " [".$tmp_SERVER_NAME."]" : "");
$TMP_SHOW_PIC = ($tmp_http_server ? $tmp_http_server."/" : "").$data2[PER_PICPATH].$data2[PER_CARDNO]."-".$SIGN_NAME.$T_PIC_SEQ.".jpg";
}
if (file_exists($TMP_SHOW_PIC)) {
// echo "$TMP_SHOW_PIC exist ";
// $arr_per_id[] = $TMP_PER_ID;
$founded = true;
break;
// } else {
// echo "$TMP_SHOW_PIC not exist ";
// $cnt_deduct++;
}
} // end while ($data2 = $db_dpis2->get_array())
if ($founded) {
// echo "$TMP_PER_ID-$TMP_SHOW_PIC exist ";
$count++;
if ($count < 1000) $arr_per_id[] = $TMP_PER_ID;
elseif ($count < 2000) $arr_per_id2[] = $TMP_PER_ID;
elseif ($count < 3000) $arr_per_id3[] = $TMP_PER_ID;
elseif ($count < 4000) $arr_per_id4[] = $TMP_PER_ID;
elseif ($count < 5000) $arr_per_id5[] = $TMP_PER_ID;
else $arr_per_id6[] = $TMP_PER_ID;
} else {
// echo "$TMP_PER_ID-$TMP_SHOW_PIC not exist ";
// $cnt_deduct++;
}
}
} // end while
if (count($arr_per_id) > 0) {
if (count($arr_per_id6)) $check_condition = " and (a.PER_ID not in (". implode(",", $arr_per_id) .")) and (a.PER_ID not in (". implode(",", $arr_per_id2) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id3) .")) and (a.PER_ID not in (". implode(",", $arr_per_id4) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id5) .")) and (a.PER_ID not in (". implode(",", $arr_per_id6) ."))";
elseif (count($arr_per_id5)) $check_condition = " and (a.PER_ID not in (". implode(",", $arr_per_id) .")) and (a.PER_ID not in (". implode(",", $arr_per_id2) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id3) .")) and (a.PER_ID not in (". implode(",", $arr_per_id4) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id5) ."))";
elseif (count($arr_per_id4)) $check_condition = " and (a.PER_ID not in (". implode(",", $arr_per_id) .")) and (a.PER_ID not in (". implode(",", $arr_per_id2) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id3) .")) and (a.PER_ID not in (". implode(",", $arr_per_id4) ."))";
elseif (count($arr_per_id3)) $check_condition = " and (a.PER_ID not in (". implode(",", $arr_per_id) .")) and (a.PER_ID not in (". implode(",", $arr_per_id2) .")) and
(a.PER_ID not in (". implode(",", $arr_per_id3) ."))";
elseif (count($arr_per_id2)) $check_condition = " and (a.PER_ID not in (". implode(",", $arr_per_id) .")) and (a.PER_ID not in (". implode(",", $arr_per_id2) ."))";
else $check_condition = " and (a.PER_ID not in (".implode(",",$arr_per_id).")) ";
$count_data -= count($arr_per_id)+count($arr_per_id2)+count($arr_per_id3)+count($arr_per_id4)+count($arr_per_id5)+count($arr_per_id6);
}
// $count_data -= $cnt_deduct;
} // end if ($search_data==11 || $search_data==13)
} // end if ($count_data > 0)
// จบ เกี่ยวกับรูปภาพ
$total_page = ceil( $count_data / $data_per_page );
$page_link = create_link_page($total_page, $current_page);
$limit_data = "";
} // end if $command == "SEARCH" || $command == "SEARCHNAMEHIS" || $command == "SEARCHPAY"
// echo "6.command=$command LEVEL_NO=$LEVEL_NO ";
$PAGE_AUTH["del"] = "N"; /*pitak*/
?>
=$webpage_title?> - =$MENU_TITLE_LV0?> - =$MENU_TITLE_LV1?>}?> - =$MENU_TITLE_LV2?>}?> - =$MENU_TITLE_LV3?>}?>
//เช็คปุ่มที่ได้ค่าออกมา ว่าเป็นปุ่มเพิ่มหรือแก้ไข
if($PAGE_AUTH["edit"]=="Y" && $UPD)
$Submit = "Submit_edit";
else if(!$VIEW && $PAGE_AUTH["add"]=="Y")
$Submit = "Submit_add";
?>
if (!$HEAD_HIDE) { ?>
//$OPTIONAL_TITLE="".(($HIDE_HEADER)?"ข้อมูลความสามารถพิเศษ":"") ;
if ($UPD) $OPTIONAL_TITLE.=" > แก้ไขข้อมูล"; elseif ($VIEW) $OPTIONAL_TITLE.=" > ดูข้อมูล";
include("current_location.html");
?>
} ?>
;">
//==Check เลขบัตร ปชช ซ้ำ
if($command=="CHKADD" && trim($PER_CARDNO)){
$cmd2="select PER_CARDNO from PER_PERSONAL where PER_CARDNO=$PER_CARDNO";
$db_dpis->send_cmd($cmd2);
$data2 = $db_dpis->get_array();
$card_no=$data2[PER_CARDNO];
$c_duplicate=0;
if($card_no){
$c_duplicate=1;
$err_text = "เลขประจำตัวประชาชนซ้ำ $PER_CARDNO";
}
} //end if
?>
if($MAIN_VIEW){ ?>
$OPTIONAL_TITLE="".(($HIDE_HEADER)?"ข้อมูลทั่วไป":"") ;
if ($UPD) $OPTIONAL_TITLE.=" > แก้ไขข้อมูล"; elseif ($VIEW) $OPTIONAL_TITLE.=" > ดูข้อมูล";
include("current_location.html");
?>
} // end if ?>
include("jqModalDialog.html");
?>