<?php
if($_SESSION['user_os']=='mobile'){
include("modules/work/report_1_mobile.php");
}
else{
echo "<br />";
?>
<?php
//บุคลากรเขต
$user=$_SESSION['login_user_id'];
//เขต
$sql_person = "select * from person_main where person_id='$user'";
$dbquery_person = mysqli_query($connect,$sql_person);
$result_person = mysqli_fetch_array($dbquery_person);
$total_pid = mysqli_num_rows($dbquery_person);
$position_code = $result_person['position_code'];
$department = $result_person['department'];
$pic = $result_person['pic'];
$fullname=$result_person['prename'].$result_person['name']." ".$result_person['surname'];
$responsible=$result_person['responsible'];
//หาตำแหน่ง
$sql_position = "select * from person_position where position_code='$position_code' ";
$dbquery_position = mysqli_query($connect,$sql_position);
$result_position = mysqli_fetch_array($dbquery_position);
$position_name = $result_position['position_name'];
//หาหน่วยงาน
$sql_workgroup = "select * from system_workgroup where workgroup='$department' ";
$dbquery_workgroup = mysqli_query($connect,$sql_workgroup);
$result_workgroup = mysqli_fetch_array($dbquery_workgroup);
$school_name = $result_workgroup['workgroup_desc'];
?>
<?php if($total_pid > 0){ //เฉพาะบุคลากรเขต ?>
<?php
echo "<center>";
//$date =date("Y-m-d H:i:s");
//กำหนดวันเดือนปีไทย
$thai_w=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_n=array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
$w=$thai_w[date("w")];
$d=date("d");
$n=$thai_n[date("n") -1];
$y=date("Y") +543;
$t=date("เวลา H นาฬิกา i นาที s วินาที");
$t2=date("เวลา H. i น.");
$date_thai = "$d $n $y";
echo "<h3>ลงเวลาปฏิบัติราชการ วันที่ $date_thai</h3>";
?>
<form name="checkForm">
<h1><input type="text" class="btn btn-warning" name="txtTime" id="txtTime" width="100" maxlength="100" value="" /></h1>
<?php
echo "<h4>";
echo "$fullname $position_name$school_name";
//echo "<br>$school_name";
echo "</h4>";
?>
<script>
function show(){
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="AM"
if (hours>=24)
dn="PM"
txt="ขณะนี้เวลา :: "
n="น."
if (hours>24)
hours=hours-24
if (hours==0)
hours=24
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
document.checkForm.txtTime.value=txt+""+hours+":"+minutes+":"
+seconds+" "+n
setTimeout("show()",1000)
}
show()
</script>
</form>
<?php
$p = (get_magic_quotes_gpc()) ? $_GET["p"] : addslashes($_GET["p"]);
$user=$_SESSION['login_user_id'];
$date_today = date("Y-m-d"); //เวลาปัจจุบัน
$sql = "SELECT
work_main.id,
work_main.work_date,
work_main.start_time,
work_main.end_time,
work_main.person_id,
work_main.`work`,
work_main.`comment`,
work_main.rec_date,
work_main.officer
FROM
work_main
WHERE
work_main.work_date = '$date_today' AND
work_main.person_id = '$user'";
$dbquery = mysqli_query($connect,$sql);
$result = mysqli_fetch_array($dbquery);
$total = mysqli_num_rows($dbquery);
$work_date = $result['work_date'];
$rec_date = $result['rec_date'];
$start_time = $result['start_time'];
$comment = $result['comment'];
if($p == "save"){ //บันทึกลงเวลา
//id work_date start_time end_time person_id work comment rec_date officer
//$person_id = $_POST['person_id'];
$comment = $_POST['comment'];
$date_today = date("Y-m-d"); //วันปัจจุบัน
$time_tody = date("H:i:s"); //เวลาปัจจุบัน
$datetime_today = date("Y-m-d H:i:s"); //วันเวลาปัจจุบัน
//ตรวจสอบค่าว่าง
if ($user =="") {
echo "<center><h2>ไม่กรอกข้อมูล ผู้ลงเวลา</h2> <br><input type=\"button\" value=\"กลับไปแก้ไข\" class=\"btn btn-primary\" onClick=\"javascript:history.go(-1)\" ></center>" ;
exit () ;
}
if ($comment =="") {
echo "<center><h2>ยังไม่เลือกสถานที่ลงเวลา</h2> <br><input type=\"button\" value=\"กลับไปแก้ไข\" class=\"btn btn-primary\" onClick=\"javascript:history.go(-1)\" ></center>" ;
exit () ;
}
if ($user > "" and $total ==0 and $comment > "") {
$sql2 = "insert into work_main (work_date,start_time,end_time,person_id,work,comment,rec_date,officer) values ('$date_today','$time_tody','$end_time','$user','1','$comment','$datetime_today','$user')";
$dbquery2 = mysqli_query($connect,$sql2);
echo" <center><h3>บันทึกข้อมูลเวลาเรียบร้อย</h3> <br> <input type=\"button\" value=\"กลับหน้าหลัก\" class=\"btn btn-primary\" onClick=\"window.location='?option=work'\"></center> ";
}else{
echo" <center><h3>บันทึกข้อมูลเวลาไม่สำเร็จ</h3> <br> <input type=\"button\" value=\"กลับหน้าหลัก\" class=\"btn btn-primary\" onClick=\"window.location='?option=work'\"></center> ";
}
} //end บันทึก
?>
<?php if($total==1 and $p !="save"){ // ลงเวลาแล้ว ?>
<?php
if($comment == 1){
$comment_txt ="ที่บ้าน";
}
if($comment == 2){
$comment_txt ="ที่สำนักงาน";
}
?>
<button type="button" class="btn btn-success">วันนี้ท่านลงเวลาแล้ว :: <?php echo $comment_txt;?> :: <?php echo $start_time?> น.</button><br>
<?php } //ลงเวลาแล้ว ?>
<?php if($total==0 and $p !="save"){ // ถ้ายังไม่ลงเวลา ?>
<form id="form1" name="form1" method="post" action="?option=work&p=save">
<div class="form-check-inline"><h4>
<input type="radio" class="form-check-input" name="comment" value="1" id="comment_0" checked/><font color="blue"> ลงเวลาที่บ้าน</font>
<input type="radio" class="form-check-input" name="comment" value="2" id="comment_1" /><font color="green"> ลงเวลาที่สำนักงาน</font></h4>
</div>
<h2><button type="submit" id="button" class="btn btn-primary btn-lg">คลิกลงเวลาปฏิบัติราชการ</button></h2>
</form>
<?php } //จบยังไม่ลงเวลา ?>
<?php } //จบเช็ค จนท.เขต ?>
<?php
echo "</center><br>";
//echo "<div align='center'><img src='modules/work/images/work.jpg' border='0'></div>";
}
?>