include("../php_scripts/connect_database.php");
include("php_scripts/data_absent.php");
$url=$_SERVER["REQUEST_URI"];
$query_str = parse_url($url, PHP_URL_QUERY);
if(empty($current_url)){
$current_url=$query_str;
}
if($PAGE_AUTH["add"]=="Y" && ($SESS_PER_ID == $PER_ID)){
$check_it = 0;
}else{
$check_it = 1;
}
//echo $check_it."/".$SESS_PER_ID." == ".$PER_ID;
if(!$PER_TYPE){
$PER_TYPE=1;
}
$ABS_STARTPERIOD = (trim($ABS_STARTPERIOD))? $ABS_STARTPERIOD : 3;
$ABS_ENDPERIOD = (trim($ABS_ENDPERIOD))? $ABS_ENDPERIOD : 3;
$ABS_LETTER = (trim($ABS_LETTER))? $ABS_LETTER : 1;
if($select_org_structure==""){$select_org_structure=1;}
$search_ab_code = trim($search_ab_code);
$search_abs_startdate = trim($search_abs_startdate);
$search_abs_enddate = trim($search_abs_enddate);
$per_id_search = "";
$per_id_join = "";
if($holiday_extra=="") $holiday_extra = 0;
/*if($SEARCHABS_PER_ID){// $SEARCHABS_PER_ID (ผู้ลาที่ค้นหา) + $PER_ID (ล็อกอิน)
$arr_search_condition[] = "(a.PER_ID = $SEARCHABS_PER_ID and (a.PER_ID = $PER_ID or a.REVIEW1_PER_ID = $PER_ID or a.REVIEW2_PER_ID = $PER_ID or a.AUDIT_PER_ID = $PER_ID or a.APPROVE_PER_ID = $PER_ID))";
}else{*/
if ($SESS_PER_ID){
if($search_onlyme_flag==1){
$arr_search_condition[] = "(a.PER_ID = $SESS_PER_ID)";
//$arr_condition[] = "(a.PER_ID = $SESS_PER_ID)";
}else{
if($SESS_PER_AUDIT_FLAG == 1){
$arr_search_condition[] = "(a.PER_ID = $SESS_PER_ID or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID OR a.update_user = $SESS_PER_ID OR 1=1)";
//$arr_condition[] = "(a.PER_ID = $SESS_PER_ID or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID OR a.update_user = $SESS_PER_ID)";
}else{
$arr_search_condition[] = "(a.PER_ID = $SESS_PER_ID or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID)";
//$arr_condition[] = "(a.PER_ID = $SESS_PER_ID or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID)";
}
}
}
//}
if ($search_ab_code) $arr_search_condition[] = "(a.AB_CODE = '$search_ab_code')";
if ($search_per_type){
$arr_search_condition[] = "(trim(b.PER_TYPE) = $search_per_type)";
}else if ($search_per_type==0) { //ทั้งหมด
$arr_search_condition[] = "(trim(b.PER_TYPE) in('1','2','3','4')) ";
}
if ($search_abs_startdate || $search_abs_enddate) {
$temp_date = explode("/", $search_abs_startdate);
$temp_start = ($temp_date[2] - 543) ."-". $temp_date[1] ."-". $temp_date[0];
$temp_date = explode("/", $search_abs_enddate);
$temp_end = ($temp_date[2] - 543) ."-". $temp_date[1] ."-". $temp_date[0];
//$arr_search_condition[] = "(a.ABS_STARTDATE >= '$temp_start' and a.ABS_ENDDATE <= '$temp_end')"; /*ก่อนปรับ*/
$arr_search_condition[] = "( a.ABS_STARTDATE between '$temp_start' and '$temp_end'
OR a.ABS_ENDDATE between '$temp_start' and '$temp_end'
OR '$temp_start' between a.ABS_STARTDATE and a.ABS_ENDDATE
or '$temp_end' between a.ABS_STARTDATE and a.ABS_ENDDATE )";
}
if(empty($Submit3) && empty($image22) ){
if($SESS_PER_AUDIT_FLAG == 1){
if($SESS_AuditArray[0][0] <>0){
$cmd_ass = " select ORG_ID,ORG_NAME from PER_ORG_ASS where ORG_ID = ".$SESS_AuditArray[0][0];
$db_dpis2->send_cmd($cmd_ass);
$data_ass = $db_dpis2->get_array();
$def_search_org_name = $data_ass[ORG_NAME];
$def_search_org_id = $data_ass[ORG_ID];
}
/*ปิดไว้เพราะไม่ต้องการ def หากต้องการให้ def ให้เปิด จะแสดงที่ ช่องสำนัก/กอง*/
//if(!$search_org_name)$search_org_name=$def_search_org_name;
//if(!$search_org_id)$search_org_id=$def_search_org_id;
}
}
if(!$search_abs_approve) $search_abs_approve=3;
if($search_abs_approve==4){
$arr_search_condition[] = "(a.APPROVE_FLAG in(0,1,2) or a.APPROVE_FLAG is null)";
}else{
if($search_abs_approve==3){
$arr_search_condition[] = "( (a.APPROVE_FLAG = 0 or a.APPROVE_FLAG is null) and ( a.CANCEL_FLAG = 0 or a.CANCEL_FLAG = 8 or a.CANCEL_FLAG = 9 ))";
} else{
if($search_abs_approve==1) $search_abs_approve_tmp = 1;
if($search_abs_approve==2) $search_abs_approve_tmp = 2;
$arr_search_condition[] = "(a.APPROVE_FLAG in($search_abs_approve_tmp))";
}
}
//echo $SESS_PER_AUDIT_FLAG."|
";
if($search_cancel_flag==1) $arr_search_condition[] = "(a.CANCEL_FLAG = 1)";
$tCon='';
if($SESS_PER_AUDIT_FLAG == 1){
$cnt_AuditArray=count($SESS_AuditArray);
if($cnt_AuditArray>0){
$tCon="(";
for ($i=0; $i < $cnt_AuditArray; $i++) {
if ($i>0)
$tCon .= " or ";
$tCon .= "( b.ORG_ID=" .$SESS_AuditArray[$i][0];
if ($SESS_AuditArray[$i][1] != 0)
$tCon .= ' and b.ORG_ID_1='. $SESS_AuditArray[$i][1];
$tCon .= ")";
}
$conORGASS=' OR a.PER_ID='.$SESS_PER_ID;
$tCon=$tCon.$conORGASS;
//die($tCon.$conORGASS);
$conditionto_audit ='';
if(empty($search_org_id)){
$conditionto_audit =" or a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID ";
}
$tCon .= " $conditionto_audit )";
$arr_search_condition[] = $tCon;
}else{
$arr_search_condition[] =" ( a.REVIEW1_PER_ID = $SESS_PER_ID or a.REVIEW2_PER_ID = $SESS_PER_ID or a.AUDIT_PER_ID = $SESS_PER_ID or a.APPROVE_PER_ID = $SESS_PER_ID) ";
}
if($search_org_id && $select_org_structure==0){
$arr_search_condition[] = "(d.ORG_ID=$search_org_id or e.ORG_ID=$search_org_id or f.ORG_ID=$search_org_id or g.ORG_ID=$search_org_id)";
//$arr_search_condition[] = "";
}elseif($search_org_id && $select_org_structure==1){
$arr_search_condition[] = "(b.ORG_ID=$search_org_id ) ";
}
}elseif($search_org_id){
if($select_org_structure=='0' || empty($select_org_structure) ) $arr_search_condition[] = "(d.ORG_ID=$search_org_id or e.ORG_ID=$search_org_id or f.ORG_ID=$search_org_id or g.ORG_ID=$search_org_id)";
if($select_org_structure=='1' )$arr_search_condition[] = "(b.ORG_ID=$search_org_id)";
}elseif($search_department_id){
$arr_search_condition[] = "(b.DEPARTMENT_ID = $search_department_id)";
}elseif($search_ministry_id){
$cmd = " select ORG_ID from PER_ORG where ORG_ID_REF=$search_ministry_id ";
$db_dpis->send_cmd($cmd);
while($data = $db_dpis->get_array()) $arr_org[] = $data[ORG_ID];
$arr_search_condition[] = "(b.DEPARTMENT_ID in (". implode(",", $arr_org) ."))";
} // end if
if(trim($search_per_name)) $arr_search_condition[] = "(b.PER_NAME like '$search_per_name%')";
if(trim($search_per_surname)) $arr_search_condition[] = "(b.PER_SURNAME like '$search_per_surname%')";
// SORT -----------------------
if(!$sort_by) $sort_by=3;
$sort_type = (isset($sort_type))? $sort_type : "3:desc";
$arrSort=explode(":",$sort_type);
$SortType[$arrSort[0]] =$arrSort[1];
if(!$order_by) $order_by=3;
if($order_by==1){ //ชื่อ-สกุล
$order_str = "b.PER_NAME ".$SortType[$order_by].",b.PER_SURNAME ".$SortType[$order_by];
}elseif($order_by==2){ //ประเภท
$order_str = "AB_NAME ".$SortType[$order_by];
} elseif($order_by==3) { //ตั้งแต่วันที่
$order_str = "ABS_STARTDATE ".$SortType[$order_by].",CREATE_DATE ".$SortType[$order_by];
//if($temp_todate){
//$having_str = "HAVING ABS_STARTDATE<= ('$temp_todate') ";
//}
} elseif($order_by==4) { //ถึงวันที่
$order_str = "ABS_ENDDATE ".$SortType[$order_by];
}elseif($order_by==5) { //จำนวนวัน
$order_str = "ABS_DAY ".$SortType[$order_by];
}elseif($order_by==6) { //การส่งใบลา
$order_str = "ABS_LETTER ".$SortType[$order_by];
}elseif($order_by==7) { //อนุมัติ
$order_str = "a.APPROVE_FLAG ".$SortType[$order_by];
}elseif($order_by==8) { //ประเภทบุคลากร
$order_str = "b.PER_TYPE ".$SortType[$order_by];
}elseif($order_by==9) { //วันที่ส่งใบลา
$order_str = "a.CREATE_DATE ".$SortType[$order_by];
}
//--------------------------------
$search_condition = "";
if ($arr_search_condition) $search_condition = " and " . implode(" and ", $arr_search_condition);
//if ($arr_condition) $condition = " and " . implode(" and ", $arr_condition);
//echo $search_condition;
$cmd =" select a.PER_ID
from PER_ABSENT a, PER_PERSONAL b, PER_POSITION d, PER_POS_EMP e, PER_POS_EMPSER f, PER_POS_TEMP g
where a.PER_ID=b.PER_ID and b.POS_ID=d.POS_ID(+) and b.POEM_ID=e.POEM_ID(+) and b.POEMS_ID=f.POEMS_ID(+) and b.POT_ID=g.POT_ID(+)
$search_condition
order by $order_str";
//echo '
'.$cmd; $count_data = $db_dpis->send_cmd($cmd); //$db_dpis->show_error(); $total_page = ceil( $count_data / $data_per_page ); $page_link = create_link_page($total_page, $current_page); $limit_data = ""; $EditTextDisable = ""; if($ABS_APPROVE_FLAG==1 && $UPD==1){ $EditTextDisable = "disabled"; } //หาว่าอยู่กลุ่ม กจ. กรม หรือไม่-------------------------------- $cmd4 = " select b.CODE from user_detail a, user_group b where a.group_id=b.id AND a.ID=".$SESS_USERID; $db_dpis2->send_cmd($cmd4); $data4 = $db_dpis2->get_array(); if ($data4[CODE]) { $NAME_GROUP_HRD = $data4[CODE]; }else{ $NAME_GROUP_HRD = ""; } //echo ">>>".$NAME_GROUP_HRD; $DAY = date("d"); $MOUNT = date("m"); $YEAR = date("Y")+543; $GETDATENOW = $DAY.'/'.$MOUNT.'/'.$YEAR; ?>=$webpage_title?> - =$MENU_TITLE_LV0?> - =$MENU_TITLE_LV1?>}?> //เช็คปุ่มที่ได้ค่าออกมา ว่าเป็นปุ่มเพิ่มหรือแก้ไข if($PAGE_AUTH["edit"]=="Y" && $UPD) $Submit = "Submit_edit"; else if(!$VIEW && $PAGE_AUTH["add"]=="Y") $Submit = "Submit_add"; ?>
if ($UPD) $OPTIONAL_TITLE=" > แก้ไขข้อมูล"; elseif ($VIEW) $OPTIONAL_TITLE=" > ดูข้อมูล"; include("current_location.html"); ?> |