<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
require_once "include/time_inc.php";
$person_id=$_SESSION['login_user_id'];
$today_date = date("Y-m-d");
$today_startTime="05:00:00"; //กำหนดเวลาเริ่มต้น (ใหลงเวลาปฏิบัติงานได้ตั้งแต่กี่โมง)
//ส่วนหัว
//ส่วนหัว
echo "<table width='100%' border='0' align='center' class='myTableOrange'>";
echo "<th align=center>บันทึกการปฏิบัติราชการในสำนังานเขตพื้นที่การศึกษา</th>";
echo "</table>";
//ส่วนแสดงหลัก
$sql_person = "select * from person_main where status='0'";
$dbquery_person=mysqli_query($connect,$sql_person);
$num_person=mysqli_num_rows($dbquery_person);
While ($result_person = mysqli_fetch_array($dbquery_person)){
$personWork = $result_person['person_id'];
$sql="select * from work_main where work_date='$today_date' and person_id='$personWork' ";
$db = mysqli_query($connect,$sql);
if($rs=mysqli_fetch_array($db)){
$work_ar[$personWork]=$rs['work'];
}
}
$sql_work = "select * from work_main where work_date='$today_date' and person_id='$person_id' ";
$dbquery_work = mysqli_query($connect,$sql_work);
$work_num=mysqli_num_rows($dbquery_work);
$result_work = mysqli_fetch_array($dbquery_work);
$work_index=$result_work['work'];
$Workstart_time=$result_work[start_time];
$Workend_time=$result_work[end_time];
//เช็คการไปราชการลา la_type 1="ลาป่วย" 2="ลากิจ" 3="ลาคลอด" 4="ลาพักผ่อน"
$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_date' 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)){
if(isset($result_la['lamid'])){
$la_type=$result_la['la_type'];
//เช็คประเภทการลา
$la_type = $result_la['la_type'];
if($la_type==1){
$check_index3="ลาป่วย";
$color="#FF3366";
}else if($la_type==2){
$check_index4="ลากิจ";
$color="#FFFF00";
}else if($la_type==3){
$check_index6="ลาคลอด";
$color="#FF00FF";
}else if($la_type==4){
$check_index5="ลาพักผ่อน";
$color="#0099FF";
}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_date' 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)){
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="";
}
}
}
}
}
//เช็คการไปราชการ
$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_date'
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="#00FFFF";
}
}
//เพิ่มเงื่อนไขกรณีมีผู้ขอราชการไปพร้อมด้วย
$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_date'
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";
}
}
//แสดงผล
$timeNow=strtotime(date("H:i:s"));
$beginMorning=strtotime(date("05:00:00"));
$endMorning=strtotime(date("11:59:00"));
$beginAfternoon=strtotime(date("12:00:00"));
$endAfternoon=strtotime(date("17:59:00"));
$beginEvening=strtotime(date("18:00:00"));
$endEvening=strtotime(date("20:59:00"));
$beginNight=strtotime(date("21:00:00"));
$endNight=strtotime(date("24:00:00"));
$beginNight2=strtotime(date("00:00:00"));
$endNight2=strtotime(date("04:59:00"));
switch ($timeNow){
case ($timeNow>=$beginMorning) and ($timeNow<=$endMorning) : $sawadee="อรุณสวัสดิ์"; $color="#0000ff"; break;
case ($timeNow>=$beginAfternoon) and ($timeNow<=$endAfternoon) : $sawadee="ทิวาสวัสดิ์"; $color="#ff5809"; break;
case ($timeNow>=$beginEvening) and ($timeNow<=$endEvening) : $sawadee="สายัณห์สวัสดิ์"; $color="#008000"; break;
case ($timeNow>=$beginNight) and ($timeNow<=$endNight) : $sawadee="ราตรีสวัสดิ์"; $color="#0080c0"; break;
case ($timeNow>=$beginNight2) and ($timeNow<=$endNight2) : $sawadee="ราตรีสวัสดิ์"; $color="#0080c0"; break;
}
echo "<form action='blocks/block-work-record.php' name='frm' method='post'>";
echo "<table border='0' align='center'>";
echo "<tr><td style='padding:2px; border:#fff 1px solid;' align=center>";
echo "ลงเวลาการปฏิบัติราชการแล้ว <b>".count($work_ar)." คน</b> จากทั้งสิ้น <b>".$num_person." คน</b>";
echo "</td></tr>";
echo "<tr><td style='padding:2px; border:#fff 1px solid;' align=center>";
echo "<font color=$color><b>".$sawadee."</b></font> สถานะการปฎิบัติราชการของคุณในวันนี้<br>";
echo "<font color=blue><b>".thai_date($today_date)."</b></font><br>";
echo "</td></tr>";
echo "<tr><td style='padding:2px;' align=center>";
echo "<input type='text' size='15' name='Clock' style='text-align:center; color:blue' readonly>";
echo "</td></tr>";
echo "<tr><td style='padding:10px;' align=center>";
$start_time=date("H:i:s");
if($start_time>=$today_startTime){
if($check_index2=='' AND $check_index3=='' AND $check_index4=='' AND $check_index5=='' AND $check_index6=='' AND $check_index7=='' AND $work_index==''){
echo "<input type='hidden' name='start_time' id='start_time' value='$start_time'>";
echo "<input type='hidden' name='work' value='1'><font color=$color><b>บันทึกเข้าปฏิบัติราชการประจำวัน</b></font><br>";
echo "<INPUT TYPE='submit' value='บันทึกลงเวลา' class=entrybutton>";
}else if($work_index=='') {
$count_check_index=$check_index2+$check_index3+$check_index4+$check_index5+$check_index6+$check_index7;
if($count_check_index=='0'){
if($check_index2!=''){ $check_index=2; }
if($check_index3!=''){ $check_index=3; }
if($check_index4!=''){ $check_index=4; }
if($check_index5!=''){ $check_index=5; }
if($check_index6!=''){ $check_index=6; }
if($check_index7!=''){ $check_index=7; }
$sql="INSERT INTO work_main (work_date, person_id, work, rec_date, officer)
VALUES ('$today_date', '$person_id', '$check_index', '$rec_date', '$person_id') ";
$dbQuery=mysqli_query($connect,$sql);
echo "<meta http-equiv=refresh content=0;url=index.php>";
}else{
echo "<font color=red><b>มีความซ้ำซ้อนในการปฏิบัติราชการของท่านเลือก 1 รายการ
<br>แล้วติดต่อเจ้าหน้าที่ที่เกี่ยวข้องต่อไป</b></font><br>";
if($check_index2!=''){ echo "<input type='radio' name='work' value='2'> $check_index2<br>";}
if($check_index3!=''){ echo "<input type='radio' name='work' value='3'> $check_index3<br>"; }
if($check_index4!=''){ echo "<input type='radio' name='work' value='4'> $check_index4<br>"; }
if($check_index5!=''){ echo "<input type='radio' name='work' value='5'> $check_index5<br>"; }
if($check_index6!=''){ echo "<input type='radio' name='work' value='6'> $check_index6<br>"; }
if($check_index7!=''){ echo "<input type='radio' name='work' value='7'> $check_index7<br>"; }
echo "<INPUT TYPE='submit' value='บันทึก' class=entrybutton>";
}
}
}else{
echo "ยังไม่ถึงเวลาปฏิบัติราชการ ".$today_startTime." น.";
}
switch ($work_index){
case 1:
echo "เวลามา <b>".$Workstart_time." น.</b>";
if( $Workend_time != '00:00:00' ){
echo " | เวลาเลิกงาน <b>".$Workend_time." น.</b>";
}else{
echo "<br>";
echo "<b>เวลาเลิกงาน </b>";
$Hourend_time=strtotime($Workstart_time) + 28800; //ตั้งเวลาทำงานไว้ 8 ชั่วโมง 1 ชั่วโมง=3600 (8*3600=28800)
if( $timeNow>=$Hourend_time ){
$end_time=date("H:i:s");
echo "<input type='hidden' name='end_time' id='end_time' value='$end_time'>";
echo "<INPUT TYPE='submit' value='บันทึกลงเวลาเลิกงาน' class=entrybutton>";
}else{
echo "ท่านต้องปฏิบัติราชการถึงเวลา <b>".date("H:i:s", $Hourend_time)." น.</b><br>จึงจะบันทึกลงเวลาเลิกงานได้";
}
}
break;
case 2: echo "<font color=blue><b>".$check_index2."</b></font>"; break;
case 3: echo "<font color=red><b>".$check_index3."</b></font>"; break;
case 4: echo "<font color=red><b>".$check_index4."</b></font>"; break;
case 5: echo "<font color=red><b>".$check_index5."</b></font>"; break;
case 6: echo "<font color=red><b>".$check_index6."</b></font>"; break;
case 7: echo "<font color=red><b>".$check_index7."</b></font>"; break;
}
echo "</td></tr>";
echo "<input type='hidden' name='person_id' id='person_id' value='$person_id'>";
echo "<input type='hidden' name='today_date' id='today_date' value='$today_date'>";
echo "</Table>";
echo "</form>";
?>
<script>
<!--
function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="น."
if (hours>=12)
dn="น."
if (hours>24)
hours=hours-24
if (hours==0)
hours=24
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
document.frm.Clock.value=hours+":"+minutes+":"
+seconds+" "+dn
setTimeout("show()",1000)
}
show()
//-->
</script>