Path : /var/www/html/smart_kpp2_bk17 มีค 69/blocks/
File Upload :
Current File : /var/www/html/smart_kpp2_bk17 มีค 69/blocks/block-work.php

<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );

$today=date("Y-m-d");

//ส่วนหัว
echo "<table width='100%' border='0' align='center'>";
	echo "<tr align='center'>"
		."<td align=center><font color='#990000' size='3'><strong>ข้อมูลบุคลากรไปราชการ/ลา - วันนี้</strong>"
		."</td></tr>";
echo "</table>";

$sql = "select * from  person_position order by position_code";
$dbquery = mysqli_query($connect,$sql);
While ($result = mysqli_fetch_array($dbquery)){
$position_ar[$result['position_code']]=$result['position_name'];
}

//ส่วนแสดงหลัก
$sql_person = "select * from person_main where status='0'"; 
$dbquery_person=mysqli_query($connect,$sql_person);
While ($result_person = mysqli_fetch_array($dbquery_person)){
$person_id = $result_person['person_id'];
		$sql_work = "select * from  work_main  where work_date='$today' and person_id='$person_id' ";
		$dbquery_work = mysqli_query($connect,$sql_work);
		$result_work = mysqli_fetch_array($dbquery_work);
$work_ar[$person_id]=$result_work['work'];		
}
$N=1;
$sql = "select * from person_main where status='0' order by department,position_code,person_order";
$dbquery = mysqli_query($connect,$sql);
echo  "<table width='100%' border='0' align='center' class='table table-hover table-sm'>";
echo "<Tr align='center'>";
echo "<Td><b><font size='2'>ที่</font></Td><Td><b><font size='2'>ชื่อ</Td><Td><b><font size='2'>ตำแหน่ง</Td><Td><b><font size='2'>ไปราชการ</Td><Td><b><font size='2'>ลาป่วย</Td>"
	."<Td><b><font size='2'>ลากิจ</Td><Td><b><font size='2'>ลาพักผ่อน</Td><Td><b><font size='2'>ลาคลอด</Td><Td><b><font size='2'>ลาอื่นๆ</font></Td></Tr>";
While ($result = mysqli_fetch_array($dbquery)){
	$id = $result['id'];
	$person_id = $result['person_id'];
	$prename=$result['prename'];
	$name= $result['name'];
	$surname = $result['surname'];
	$position_code= $result['position_code'];
	$department= $result['department'];
			
	//check การลา
	$sql_la="select * from la_main where (la_start<='$today' and '$today'<=la_finish) and person_id='$person_id' ";
	$dbquery_la = mysqli_query($connect,$sql_la);
		if($dbquery_la){
		$la_num=mysqli_num_rows($dbquery_la);	
				if($la_num>=1){
						$result_la = mysqli_fetch_array($dbquery_la);
						if($result_la['la_type']==1){
						$color="#ffdfe8";
						} 
						else if($result_la['la_type']==2){
						$color="#ffffdf";
						}
						else if($result_la['la_type']==3){
						$color="#ffdfff";
						}
						else if($result_la['la_type']==4){
						$color="#dff2ff";
						}
				$sql_cancel="select * from la_cancel where (cancel_la_start<='$today' and '$today'<=cancel_la_finish) and person_id='$person_id' ";
				$dbquery_cancel = mysqli_query($connect,$sql_cancel);
						if($dbquery_cancel){
						$la_num_cancel=mysqli_num_rows($dbquery_cancel);	
								if($la_num_cancel>=1){
								$color=$color2;
								}
						}
						
				}
		}

//check การไปราชการ
/*	$sql_date="select * from permission_date where person_id='$person_id' and date='$today' ";
	$dbquery_date = mysqli_query($connect,$sql_date);
		if($dbquery_date){
		$date_num=mysqli_num_rows($dbquery_date);	
				if($date_num>=1){
				$color="#dfffff";
				}
		}
*/

$check_index2="";	
$check_index3="";	
$check_index4="";	
$check_index5="";	
$check_index6="";	
$check_index7="";	

if(!isset($_GET['index'])){
$_GET['index']="";
}

//if($_GET['index']==2){
//$check_index1="checked";
//}

if($work_ar[$person_id]==2){
$check_index2="ไปราชการ 1";
$color="#dfffff";
}
else if($work_ar[$person_id]==3){
$check_index3="ลาป่วย";
$color="#ffdfe8";
}
else if($work_ar[$person_id]==4){
$check_index4="ลากิจ";
$color="#FFFF00";
}
else if($work_ar[$person_id]==5){
$check_index5="ลาพักผ่อน";
$color="#0099FF";
}
else if($work_ar[$person_id]==6){
$check_index6="ลาคลอด";
$color="#FF00FF";
}
else if($work_ar[$person_id]==7){
$check_index7="ลาอื่นๆ";
}

//เช็คการไปราชการลา  la_type 1="ลาป่วย" 2="ลากิจ" 3="ลาคลอด" 4="ลาพักผ่อน"
if($check_index3!="ลาป่วย" && $check_index4!="ลากิจ" && $check_index5!="ลาพักผ่อน" && $check_index6!="ลาคลอด" && $check_index7!="ลาอื่นๆ"){ 
//echo "ที่หนึ่งด้านบน เช็คว่าไม่ว่าง";    
$sql_la="SELECT
            la_main.id AS lamid ,
            la_main.la_type AS la_type
            FROM
            la_main 
            WHERE
            la_main.person_id = $person_id 
            and '$today' BETWEEN la_main.la_start AND la_main.la_finish AND
            la_main.commander_grant = 1 ";    
$dbquery_la = mysqli_query($connect,$sql_la);
While ($result_la = mysqli_fetch_array($dbquery_la))
	{
//echo "ที่สอง เช็คการลา";    
        if(isset($result_la['lamid'])){
                $la_type=$result_la['la_type'];
                        //เช็คประเภทการลา
                            $la_type = $result_la['la_type'];
                            if($la_type==1){
                            $check_index3="ลาป่วย";
                            $color="#ffdfe8";
                            }
                            else if($la_type==2){
                            $check_index4="ลากิจ";
                            $color="#ffffdf";    
                            }
                            else if($la_type==3){
                            $check_index6="ลาคลอด";
                            $color="#ffdfff";    
                            }
                            else if($la_type==4){
                            $check_index5="ลาพักผ่อน";
                            $color="#dff2ff";
                            }else{
                            $check_index7="ลาอื่นๆ";
                            }
           
                $sql_lac="SELECT
                        la_cancel.id AS lacid ,
                        la_cancel.la_type AS la_ctype
                        FROM
                        la_cancel
                        WHERE
                        la_cancel.person_id = $person_id 
                        and '$today' BETWEEN la_cancel.cancel_la_start AND la_cancel.cancel_la_finish AND
                        la_cancel.commander_grant = '1' and la_cancel.la_type='$la_type' ";    
                $dbquery_lac = mysqli_query($connect,$sql_lac);
                While ($result_lac = mysqli_fetch_array($dbquery_lac))
                   {
//echo "ที่สาม เช็คยกเลิกการลา";    
                    
                        if(isset($result_lac['lacid'])){
                            $la_ctype = $result_lac['la_ctype'];
                            if($la_ctype==1){
                            $check_index3="";
                            }
                            else if($la_ctype==2){
                            $check_index4="";
                            }
                            else if($la_ctype==3){
                            $check_index6="";
                            }
                            else if($la_ctype==4){
                            $check_index5="";
                            }else{
                            $check_index7="";
                            }
                        }
                    }
        }
}
}
//echo   "ประเภทลา:".$la_type;
//echo   "ประเภทยกเลิกลา:".$la_ctype;

//เช็คการไปราชการ       
if($check_index2!="ไปราชการ"){     
$sql_permis="SELECT permission_main.id,permission_main.ref_id
            FROM
            permission_main
            INNER JOIN permission_date ON permission_main.ref_id = permission_date.ref_id
            WHERE
            permission_date.date = '$today' 
            and permission_date.person_id='$person_id'
            and permission_main.grant_x='1' ";
$dbquery_permis = mysqli_query($connect,$sql_permis);
While ($result_permis = mysqli_fetch_array($dbquery_permis))
	{
        if(isset($result_permis['id'])){
            $check_index2="ไปราชการ";
            $color="#dfffff";
        }
}

//เพิ่มเงื่อนไขกรณีมีผู้ขอราชการไปพร้อมด้วย
            $sql_follow="SELECT permission_main.id,permission_main.person_id
                        FROM
                        permission_main
                        INNER JOIN permission_follower ON permission_follower.ref_id = permission_main.ref_id
                        INNER JOIN permission_date ON permission_date.ref_id = permission_main.ref_id 
                        WHERE
                        permission_date.date = '$today' 
                        and permission_follower.person_id='$person_id'
                        and permission_main.grant_x='1' ";
 
                $dbquery_follow = mysqli_query($connect,$sql_follow);
                While ($result_follow = mysqli_fetch_array($dbquery_follow))
                    {
                        if(isset($result_follow['id'])){
							$sql_follow_main = "select * from person_main where person_id=$result_follow[person_id] ";
							$dbquery_follow_main = mysqli_query($connect,$sql_follow_main);
							$result_follow_main = mysqli_fetch_array($dbquery_follow_main) ;
							$check_index2="ไปราชการกับ/$result_follow_main[name]";
                        $color="#dfffff";
                        }
                }  

}

//แสดงผล
if($check_index2!='' or $check_index3!='' or $check_index4!='' or $check_index5!='' or $check_index6!='' or $check_index7!=''){
	echo "<Tr  bgcolor=$color align=center class=style1 onmouseover=\"javascript:this.bgColor='#80ff80'\" onmouseout=\"javascript:this.bgColor='$color'\">";
		echo "<td align='center'>$N</td>";
		echo "<Td align='left'>$prename&nbsp;$name&nbsp;&nbsp;$surname</Td>";
		echo "<Td align='left'>";
		if(isset($position_ar[$position_code])){
			echo $position_ar[$position_code];
		}
		echo "</Td>";

		echo "<Td>$check_index2</Td>";
		echo "<Td>$check_index3</Td>";
		echo "<Td>$check_index4</Td>";
		echo "<Td>$check_index5</Td>";
		echo "<Td>$check_index6</Td>";
		echo "<Td>$check_index7</Td>";
	echo "</tr>";
}
$N++;
	}
echo "</Table>";

$sql = "SELECT * FROM line_notify WHERE date_line='$today' AND module_line='work' ";
$query = mysqli_query($connect,$sql);
$num_rows = mysqli_num_rows($query);
if ($num_rows == '0'){ 
	require_once("modules/line_notify/work.php");
}
?>