<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_' ) or die( 'Direct Access to this location is not allowed.' );
?>
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","modules/person/livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
<?php
include("include/time_inc.php");
$officer=$_SESSION['login_user_id'];
if(!(isset($_REQUEST['school_code']))){
$_REQUEST['school_code']="";
}
if(!(isset($_REQUEST['page_var1']))){
$_REQUEST['page_var1']="";
}
if(!(isset($_REQUEST['name_search']))){
$_REQUEST['name_search']="";
}
$other_index="";
$sql="select * from person_sch_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="select * from system_school";
$dbquery=mysqli_query($connect,$sql);
While ($result=mysqli_fetch_array($dbquery)){
$school_ar[$result['school_code']]=$result['school_name'];
}
echo "<br />";
if(!(($index==1) or ($index==2) or ($index==2.1) or ($index==5))){
echo "<table width='50%' border='0' align='center'>";
echo "<tr align='center'><td><font color='#006666' size='3'><strong>ข้อมูลครูและบุคลากรในสถานศึกษา</strong></font> เรียงลำดับรหัสโรงเรียน/ตำแหน่ง</td></tr>";
echo "</table>";
}
//ส่วนการแสดงผล
if(!(($index==1) or ($index==2) or ($index==2.1) or ($index==5))){
//เกี่ยวการส่งค่ารหัสโรงเรียนตอนเลือกหน้า
if(($_REQUEST['school_code']=="") and ($_REQUEST['page_var1']!="")){
$_REQUEST['school_code']=$_REQUEST['page_var1'];
}
//ส่วนของการแยกหน้า
if($index==8 and ($_REQUEST['name_search']!="")){
$sql_page="select * from person_sch_main left join system_school on person_sch_main.school_code=system_school.school_code left join person_sch_position on person_sch_main.position_code=person_sch_position.position_code where person_sch_main.prename like '%$_REQUEST[name_search]%' or person_sch_main.name like '%$_REQUEST[name_search]%' or person_sch_main.surname like '%$_REQUEST[name_search]%' or person_sch_main.position_code like '%$_REQUEST[name_search]%' or system_school.school_name like '%$_REQUEST[name_search]%' and person_sch_main.status='0' order by person_sch_main.school_code, person_sch_main.position_code ";
$_REQUEST['school_code']="";
}else if($_REQUEST['school_code']==""){
$sql_page="select id from person_sch_main where status='0' order by school_code, position_code";
}else{
$sql_page="select id from person_sch_main where status='0' and school_code='$_REQUEST[school_code]' ";
}
$dbquery_page=mysqli_query($connect,$sql_page);
$num_rows=mysqli_num_rows($dbquery_page);
//$pagelen=20; // กำหนดแถวต่อหน้า
$url_link="option=person&task=person_sch_report1&page_var1=$_REQUEST[school_code]&index=$index&name_search=$_REQUEST[name_search]";
$totalpages=ceil($num_rows/$pagelen);
if(!(isset($_REQUEST['page']))){
$_REQUEST['page']="";
}
if($_REQUEST['page']==""){
$page=$totalpages;
if($page<2){
$page=1;
}
}else{
if($totalpages<$_REQUEST['page']){
$page=$totalpages;
if($page<1){
$page=1;
}
}else{
$page=$_REQUEST['page'];
}
}
$start=($page-1)*$pagelen;
if(($totalpages>1) and ($totalpages<7)){
//echo "<div align=center>";
//echo "หน้า ";
echo "<nav><ul class='pagination'>";
echo "<li><a>หน้า $page จาก $totalpages</a></li>";
for($i=1; $i<=$totalpages; $i++) {
if($i==$page){
//echo "[<b><font size=+1 color=#990000>$i</font></b>]";
echo " <li><a href=''><font color=#990000>$i</font></a></li> ";
}
else {
//echo "<a href=$PHP_SELF?$url_link&page=$i>[$i]</a>";
echo "<li><a href=$PHP_SELF?$url_link&page=$i> $i </a></li>";
}
}
//echo "</div>";
echo "</nav>";
}
if($totalpages>6){
if($page <=3){
$e_page=6;
$s_page=1;
}
if($page>3){
if($totalpages-$page>=3){
$e_page=$page+3;
$s_page=$page-3;
}else{
$e_page=$totalpages;
$s_page=$totalpages-6;
}
}
//echo "<div align=center>";
echo "<nav><ul class='pagination'>";
echo "<li><a>หน้า $page จาก $totalpages</a></li>";
if($page!=1){
$f_page1=$page-1;
//echo "<<a href=$PHP_SELF?$url_link&page=1>หน้าแรก </a>";
//echo "<<<a href=$PHP_SELF?$url_link&page=$f_page1>หน้าก่อน </a>";
echo "<li><a href=$PHP_SELF?$url_link&page=1 aria-label='หน้าแรก'>
<span aria-hidden='true'>หน้าแรก</span></a></li>";
echo "<li><a href=$PHP_SELF?$url_link&page=$f_page1 aria-label='หน้าก่อน'>
<span aria-hidden='true'>หน้าก่อน</span></a></li>";
}else {
//echo "หน้า ";
}
for($i=$s_page; $i<=$e_page; $i++){
if($i==$page){
//echo "[<b><font size=+1 color=#990000>$i</font></b>]";
echo " <li><a href=''><font color=#990000><strong>$i</strong></font></a></li> ";
}
else {
//echo "<a href=$PHP_SELF?$url_link&page=$i>[$i]</a>";
echo "<li><a href=$PHP_SELF?$url_link&page=$i>$i</a></li>";
}
}
if($page<$totalpages) {
$f_page2=$page+1;
echo "<li><a href=$PHP_SELF?$url_link&page=$f_page2 aria-label='หน้าถัดไป'>
<span aria-hidden='true'>หน้าถัดไป</span></a></li>";
echo "<li><a href=$PHP_SELF?$url_link&page=$totalpages aria-label='หน้าสุดท้าย'>
<span aria-hidden='true'>หน้าสุดท้าย>$totalpages</span></a></li>";
//echo "<a href=$PHP_SELF?$url_link&page=$f_page2> หน้าถัดไป</a>>>";
//echo "<a href=$PHP_SELF?$url_link&page=$totalpages> หน้าสุดท้าย</a>>";
}
echo " <select onchange=\"location.href=this.options[this.selectedIndex].value;\" size=\"1\" name=\"select\">";
echo "<option value=\"\">หน้า</option>";
for($p=1;$p<=$totalpages;$p++){
echo "<option value=\"?$url_link&page=$p\">$p</option>";
}
echo "</select>";
//echo "</div>";
echo "</nav>";
}
//จบแยกหน้า
echo "<form id='frm1' name='frm1'>";
echo "<table width='90%' align='center'>";
echo "<tr><td colspan='2' align='right'>";
?>
ค้นหาโรงเรียน <input type="text" size="15" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
<?php
echo "</td></tr>";
echo "<tr><td align='left'>";
//ค้นหาบุคคล
echo "ค้นหาด้วย คำนำหน้า/ชื่อ/นามสกุล/ตำแหน่ง/โรงเรียน ";
if($index==8){
echo "<Input Type='Text' Name='name_search' value='$_REQUEST[name_search]'>";
}else{
echo "<Input Type='Text' Name='name_search'>";
}
echo " <INPUT TYPE='button' name='smb' value='ค้น' onclick='goto_display(2)'>";
echo "   </td>";
echo "<td align='right'>";
echo "เลือกสถานศึกษา ";
echo "<select name='school_code' id='school_code' onChange=location.href='index.php?option=person&task=person_sch_report1&school_code='+this.options[this.selectedIndex].value;>";
echo "<option value=\"\">ทั้งหมด</option>";
$sql="select * from system_school order by school_code";
$dbquery=mysqli_query($connect,$sql);
While ($result=mysqli_fetch_array($dbquery)){
if($_REQUEST['school_code']==""){
echo "<option value=$result[school_code]>$result[school_code] $result[school_name]</option>";
}else{
if($_REQUEST['school_code']==$result['school_code']){
echo "<option value=$result[school_code] selected>$result[school_code] $result[school_name]</option>";
}else{
echo "<option value=$result[school_code]>$result[school_code] $result[school_name]</option>";
}
}
}
echo "</select>";
//echo " <INPUT TYPE='button' name='smb' value='เลือก' onclick='goto_display(1)' class='entrybutton'>";
echo "</td></tr></table>";
if($index==8 and ($_REQUEST['name_search']!="")){
$sql="select * from person_sch_main left join system_school on person_sch_main.school_code=system_school.school_code left join person_sch_position on person_sch_main.position_code=person_sch_position.position_code where person_sch_main.prename like '%$_REQUEST[name_search]%' or person_sch_main.name like '%$_REQUEST[name_search]%' or person_sch_main.surname like '%$_REQUEST[name_search]%' or person_sch_position.position_name like '%$_REQUEST[name_search]%' or system_school.school_name like '%$_REQUEST[name_search]%' and person_sch_main.status='0' order by person_sch_main.school_code, person_sch_main.position_code limit $start,$pagelen";
$_REQUEST['school_code']="";
}else if($_REQUEST['school_code']==""){
$sql="select * from person_sch_main where status='0' order by school_code,position_code,person_order,id limit $start,$pagelen";
}else{
$sql="select * from person_sch_main where status='0' and school_code='$_REQUEST[school_code]' order by school_code, position_code,person_order,id limit $start,$pagelen";
$other_index=1;
}
$dbquery=mysqli_query($connect,$sql);
echo "<table width='90%' align='center' class='myTableBlue'>";
echo "<th width='70'>ที่</th><th>ชื่อ</th><th width='300'>ตำแหน่ง</th><th width='300'>สถานศึกษา</th><th width='120'>รายละเอียดบุคคล</th>";
$N=(($page-1)*$pagelen)+1; //*เกี่ยวข้องกับการแยกหน้า
$M=1;
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'];
$school_code= $result['school_code'];
$person_order= $result['person_order'];
echo "<Tr><Td align=center>$N</Td><Td align='left'>$prename $name $surname</Td><Td align='center'>";
if(isset($position_ar[$position_code])){
echo $position_ar[$position_code];
}
echo "</Td>";
echo "<Td align='center'>";
if(isset($school_ar[$school_code])){
echo $school_ar[$school_code];
}
// ส่วนบุคลากรขยาย ปฎิบัติงานในโรงเรียนรอง
$sql_other="select system_school.school_name from person_sch_other left join system_school on person_sch_other.school_code=system_school.school_code where person_id='$result[person_id]' ";
$dbquery_other=mysqli_query($connect,$sql_other);
$num_other=mysqli_num_rows($dbquery_other);
if($num_other!=0){
echo " <font color=#008000>และ</font><div align=left><font color=red><ol>";
while($result_other=mysqli_fetch_array($dbquery_other)){
echo "<li>".$result_other[school_name]."</li>";
}
echo "</font></ol></div>";
}
echo "</Td>";
//ค้นหาว่ามีการสร้างข้อมูลหรือยัง
$sql_detail="select * from person_detail where person_id='$person_id' ";
$dbquery_detail=mysqli_query($connect,$sql_detail);
$num=mysqli_num_rows($dbquery_detail);
if($num==0){
//ส่วนของรายละเอียด
echo "<Td align='center'> </Td>";
}else{
//ส่วนของรายละเอียด
echo "<Td align='center'><a href='modules/person/person_detail_sch.php?person_id=$person_id' class='dialogify'><img src=images/my-icons/list.png width=28 border='0' title='รายละเอียด ข้อมูลบุคคล'></a></Td>";
}
echo "</Tr>";
$M++;
$N++;
}
//ส่วนบุคลากรขยาย มาจากโรงเรียนหลัก ปฎิบัติหน้าที่โรงเรียนรอง
$sql="select person_sch_main.id, person_sch_main.person_id, person_sch_main.prename, person_sch_main.name, person_sch_main.surname, person_sch_main.position_code, person_sch_main.school_code from person_sch_other left join person_sch_main on person_sch_other.person_id=person_sch_main.person_id where person_sch_main.status='0' and person_sch_other.status='0' and person_sch_other.school_code='$_REQUEST[school_code]' order by position_code,name";
$dbquery=mysqli_query($connect,$sql);
$num=mysqli_num_rows($dbquery);
if($num!=0){
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'];
$school_code= $result['school_code'];
echo "<Tr><Td align=center><font color=red>**</font></Td><Td align='left'>$prename $name $surname</Td><Td align='center'>$position_ar[$position_code]</Td>";
echo "<Td align='center'>โรงเรียนหลัก <font color=red>$school_ar[$school_code]</font></Td>";
//ค้นหาว่ามีการสร้างข้อมูลหรือยัง
$sql_detail="select * from person_detail where person_id='$person_id' ";
$dbquery_detail=mysqli_query($connect,$sql_detail);
$num=mysqli_num_rows($dbquery_detail);
if($num==0){
//ส่วนของรายละเอียด
echo "<Td align='center'> </Td>";
}else{
//ส่วนของรายละเอียด
echo "<Td align='center'><a href='modules/person/person_detail_sch.php?person_id=$person_id' class='dialogify'><img src=images/my-icons/list.png width=28 border='0' title='รายละเอียด ข้อมูลบุคคล'></a></Td>";
}
echo "</Tr>";
}
echo "<tr><td colspan=5>หมายเหตุ <font color=red>**</font> ไม่นับสรุปจำนวนครูและบุคลากรทางการศึกษาอยู่ในโรงเรียนนี้</td></tr>";
}
echo "</Table>";
echo "</form>";
if(($page==$totalpages) or ($_REQUEST['school_code']!="")){
//ส่วนรายงานสรุป
echo "<table width='100%' border='0' align='center'>";
echo "<tr align='center'><td><font color='#006666' size='3'><strong>สรุปสารสนเทศจำนนวนบุคลากร - จำแหนกประเภท</strong></font></td></tr>";
echo "</table>";
echo "<br />";
echo "<table width='99%' border='0' align='center'>";
echo "<tr><td width=33% valign=top>";
//ประเภทตำแหน่ง
echo "<table width='100%' align='center' class='myTableOrange'>";
echo "<th>ตำแหน่ง</th><th width='80'>จำนวน</th>";
$person_num=0;
//$sql="select * from person_sch_position order by position_code";
$sql="select position_code from person_sch_main group by position_code order by position_code";
$dbquery=mysqli_query($connect,$sql);
while ($result=mysqli_fetch_array($dbquery)){
$id=$result['id'];
$position_code= $result['position_code'];
$sql_name="select * from person_sch_position where position_code='$result[position_code]' ";
$dbquery_name=mysqli_query($connect,$sql_name);
$result_name=mysqli_fetch_array($dbquery_name);
if($result_name[position_name]==''){
$position_name="<font color=red>ตำแหน่งนี้ไม่มีในระบบ (ค้นหา/แก้ไข)</font>";
}else{
$position_name= $result_name['position_name'];
}
//หาจำนวนคนในตำแหน่ง
if($_REQUEST['school_code']!=''){
$sql_sum="select count(name) as member_num from person_sch_main where status='0' and position_code='$position_code' and school_code='$_REQUEST[school_code]' ";
}else{
$sql_sum="select count(name) as member_num from person_sch_main where status='0' and position_code='$position_code'";
}
$dbquery_sum=mysqli_query($connect,$sql_sum);
$result_sum=mysqli_fetch_array($dbquery_sum);
$person_num=$person_num+$result_sum['member_num'];
$position_person_num=number_format($result_sum['member_num']);
if($result_sum['member_num']>0){
echo "<Tr><Td align=left>$position_name</Td><Td align=right>$position_person_num</Td></Tr>";
}
}
$person_num=number_format($person_num);
echo "<Tr><Td align=center>รวม</Td><Td align=right>$person_num</Td></Tr>";
echo "</Table>";
echo "</td><td width=33% valign=top>";
//ประเภทเพศและการศึกษา
//ประเภทเพศ
echo "<table align='center' class='myTableGreen' width=100%>";
echo "<th>เพศ</th><th width='80'>จำนวน</th>";
if($_REQUEST['school_code']!=''){
$sql="select count(*) as man from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.sex='1' AND person_sch_main.school_code='$_REQUEST[school_code]'";
}else{
$sql="select count(*) as man from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.sex='1' ";
}
$dbquery=mysqli_query($connect,$sql);
$result_man=mysqli_fetch_array($dbquery);
echo "<tr><td>ชาย</td><td align=center>".$result_man['man']."</td></tr>";
if($_REQUEST['school_code']!=''){
$sql="select count(*) as women from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.sex='2' AND person_sch_main.school_code='$_REQUEST[school_code]'";
}else{
$sql="select count(*) as women from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.sex='2' ";
}
$dbquery=mysqli_query($connect,$sql);
$result_women=mysqli_fetch_array($dbquery);
echo "<tr><td>หญิง</td><td align=center>".$result_women['women']."</td></tr>";
$total_sex=$result_man['man']+$result_women['women'];
echo "<tr><td align=center><strong>รวม</strong></td><td align=center><strong>".$total_sex."</strong></td></tr>";
//ประเภทการศึกษา
echo "<th>ระดับการศึกษา</th><th width='80'>จำนวน</th>";
$sql="select * from person_education_class";
$dbquery=mysqli_query($connect,$sql);
$education_class_num='0';
while($result_education=mysqli_fetch_array($dbquery)){
$education_class=$result_education['code'];
if($_REQUEST['school_code']!=''){
$sql_count_education="select count(*) as education_class from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.education_class='$education_class' AND person_sch_main.school_code='$_REQUEST[school_code]'";
}else{
$sql_count_education="select count(*) as education_class from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.education_class='$education_class' ";
}
$dbquery_count_education=mysqli_query($connect,$sql_count_education);
$result_count_education=mysqli_fetch_array($dbquery_count_education);
echo "<tr><td>".$result_education['name']."</td><td align=center>".$result_count_education['education_class']."</td></tr>";
$education_class_num=$education_class_num+$result_count_education['education_class'];
}
echo "<tr><td align=center><strong>รวม</strong></td><td align=center><strong>".$education_class_num."</strong></td></tr>";
echo "</table>";
echo "</td><td width=33% valign=top>";
//ประเภทวิทยฐานะ
echo "<table align='center' class='myTableBlue' width=100%>";
echo "<th>วิทยะฐานะ</th><th width='80'>จำนวน</th>";
$sql="select * from person_position_class";
$dbquery=mysqli_query($connect,$sql);
$position_class_num='0';
while($result_position=mysqli_fetch_array($dbquery)){
$position_class=$result_position['code'];
if($_REQUEST['school_code']!=''){
$sql_count_position="select count(*) as position_class from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.position_class='$position_class' AND person_sch_main.school_code='$_REQUEST[school_code]'";
}else{
$sql_count_position="select count(*) as position_class from person_sch_main, person_detail where person_sch_main.person_id=person_detail.person_id AND person_sch_main.status='0' AND person_detail.position_class='$position_class' ";
}
$dbquery_count_position=mysqli_query($connect,$sql_count_position);
$result_count_position=mysqli_fetch_array($dbquery_count_position);
echo "<tr><td>".$result_position['name']."</td><td align=center>".$result_count_position['position_class']."</td></tr>";
$position_class_num=$position_class_num+$result_count_position['position_class'];
}
echo "<tr><td align=center><strong>รวม</strong></td><td align=center><strong>".$position_class_num."</strong></td></tr>";
echo "</table>";
echo "</td></tr>";
echo "</table>";
echo "<br><br><br>";
}
}
?>
<script>
function goto_display(val){
if(val==1){
callfrm("?option=person&task=person_sch_report1");
}
else if(val==2){
callfrm("?option=person&task=person_sch_report1&index=8");
}
}
</script>
<script type="text/javascript" src="css/scrolltop/scrolltopcontrol.js"></script>
<link rel="stylesheet" href="./jquery/themes/ui-lightness/jquery.ui.all.css">
<script src="./jquery/jquery-1.5.1.js"></script>
<script src="./jquery/external/jquery.bgiframe-2.1.2.js"></script>
<script src="./jquery/ui/jquery.ui.core.js"></script>
<script src="./jquery/ui/jquery.ui.widget.js"></script>
<script src="./jquery/ui/jquery.ui.mouse.js"></script>
<script src="./jquery/ui/jquery.ui.draggable.js"></script>
<script src="./jquery/ui/jquery.ui.position.js"></script>
<script src="./jquery/ui/jquery.ui.resizable.js"></script>
<script src="./jquery/ui/jquery.ui.dialog.js"></script>
<script type="text/javascript">
/*
* jQuery UI Dialog: Load Content via AJAX
* http://salman-w.blogspot.com/2013/05/jquery-ui-dialog-examples.html
*/
jQuery.noConflict();
jQuery(function() {
jQuery("#dialog").dialog({
height: 580,
width: 650,
minHeight: 580,
minWidth: 650,
autoOpen: false,
show: "blind",
hide: "explode",
modal: true,
resizable: false,
});
jQuery(".dialogify").click(function(e) {
e.preventDefault();
jQuery("#dialog").html("");
jQuery("#dialog").dialog("option", "title", "Loading...").dialog("open");
jQuery("#dialog").load(this.href, function() {
jQuery(this).dialog("option", "title", "ข้อมูลบุคลากร");
//jQuery(this).dialog("option", "title", jQuery(this).find("h1").text());
//jQuery(this).find("h1").remove();
});
});
});
</script>
<div id="dialog"></div>