<?php
session_start();
$session=session_id();
require("../inc/config.inc.php");
require("../inc/common.php");


if($_SESSION['login']!="admin"){	
	echo"Error";
	exit();
}
$groupCode=$_GET['groupCode'];		


if($_GET['ex']=='xls'){
$strExcelFileName="รายชื่อนักศึกษาที่ไม่ลงทะเบียน ปีการศึกษา $academicYear ภาคเรียน $semester (ทุกกลุ่มเรียน).xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
}

?>
<?php //echo FCPATH."images/logo_e2e.png"; ?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="utf-8">

	
</head>
<body>
<!-- <div id="SiXhEaD_Excel" align=center x:publishsource="Excel"> -->
<div id="SiXhEaD_Excel"  x:publishsource="Excel">	
<!-------- เริ่มข้อมูล ------------------------>

<h4>สรุปข้อมูลนักศึกษาที่ไม่ลงทะเบียน ภาคเรียนที่ <?=$semester?> ปีการศึกษา <?=$academicYear?></h4>


<?php
//กลุ่มเรียนทั้งหมด	
$sql_regis_group="Select * From regis_group where academicYear='$academicYear' AND semester='$semester' AND status='1' order by level_no,groupCode ASC"; 
$db_query_regis_group=mysqli_query($connect,$sql_regis_group);
$num_rows_regis_group=mysqli_num_rows($db_query_regis_group); /* นับ Reccord ที่พบ */	
$a_regis_group=0;
while($a_regis_group < $num_rows_regis_group)
{
	$result_regis_group = mysqli_fetch_array($db_query_regis_group);
	$groupCode=$result_regis_group['groupCode'];
	$cost_credit=$result_regis_group['cost_credit'];
	$cost_value=$result_regis_group['cost_value'];
	//ยอดเงินที่ต้องลงทะเบียน
	$total_cost=$cost_credit+$cost_value;

	
//ดึงข้อมูลกลุ่มเรียน	
$result_std2018=select("std2018_studentgroup","where groupCode='$groupCode'");
	$grade=$result_std2018['grade'];
	$groupCode=$result_std2018['groupCode'];
	$groupName=$result_std2018['groupName'];
	$groupAbbr=$result_std2018['groupAbbr'];
	$teacherFirstname=$result_std2018['teacherFirstname'];
	$teacherLastname=$result_std2018['teacherLastname'];	
	  
	 $num_student=num_record("std2018_student","where groupCode='$groupCode' AND studentStatusCode='03'"); 
	 $num_student_all=num_record("std2018_student","where groupCode='$groupCode' "); 
	 $num_out=$num_student_all-$num_student;	
	
	 $num_payment=num_record("regis_payment_log","where academicYear='$academicYear' AND semester='$semester' AND groupCode='$groupCode'  ");
	
	
	//ตรวจสอบว่าลงทะเบียนครบไม่ไม่ ถ้าครบไม่ต้องแสดงผล
	if($num_student>$num_payment){

?>
ระดับ   <b><?=$grade?></b>    รหัสกลุ่ม <b><?=$groupCode?></b>  <b><?=$groupName?></b><br>
ครูที่ปรึกษา <b><?php if($teacherFirstname!=""){ echo "ครู$teacherFirstname    $teacherLastname"; }?></b><br>
จำนวนนักศึกษาทั้งหมด  <b><?=$num_student?></b> คน  ลงทะเบียน <b><?=$num_payment?></b> คน  ยังไม่ได้ลงทะเบียน <b><?php $num_student_lost=$num_student-$num_payment;  echo $num_student_lost;?></b> คน  <br>
ร้อยละของนักศึกษาที่ลงทะเบียน	<b><?php  $percent=$num_payment/$num_student*100; $percent=number_format($percent,2); echo $percent; ?></b><br>
ยอดเงินค่าลงทะเบียน <b><?php echo number_format($total_cost);?></b> บาท <br>	
(รายชื่อนักศึกษาที่ไม่ลงทะเบียนเท่านั้น)	
<?php	
//ดึงค่านักศึกษาในกลุ่ม
	$sql="Select * From std2018_student,prefix where std2018_student.groupCode='$groupCode' AND std2018_student.studentStatusCode='03' AND std2018_student.prefixID=prefix.prefix_id  order by std2018_student.studentCode ASC"; 

$db_query=mysqli_query($connect,$sql);
$num_rows=mysqli_num_rows($db_query); /* นับ Reccord ที่พบ */
//echo "มีจำนวน <b>$num_rows</b> คน";		
if($num_rows==0)
{
	echo " ไม่พบข้อมูลนักศึกษา";
}else{
?>
         
<table width="779" border="1">
    <thead>
      <tr>
        <th width="52" bgcolor="#E7E7E7"><center>
          ลำดับ
        </center></th>
        <th width="162" bgcolor="#E7E7E7"><center>รหัสประจำตัวนักศึกษา</center></th>
        <th width="181" bgcolor="#E7E7E7">ชื่อ</th>
		<th width="137" bgcolor="#E7E7E7">นามสกุล</th> 
		  <th width="99" bgcolor="#E7E7E7"><center>เบอร์โทรศัพท์</center></th>  
        <th width="108" bgcolor="#E7E7E7"><center>สถานะ </center></th>  
	  </tr>
    </thead>
    <tbody>
<?php
$a=0;
$no=1;	
while($a < $num_rows)
{
	$result = mysqli_fetch_array($db_query);
	$prefix_name=$result['prefix_name'];
	$firstname=$result['firstname'];
	$surname=$result['surname'];
	$studentCode=$result['studentCode'];
	$studentStatusCode=$result['studentStatusCode'];
	$gpax=$result["gpax"];
	$tel=$result["tel"];
	$tel="&nbsp;$tel";
	 if($studentStatusCode=='03'){ $studentStatus="<font color=\"#0A7E02\">กำลังศึกษา</<font>"; }else{ $studentStatus="<font color=\"#FB4447\">พ้นสภาพ</<font>"; }
	
	//ตรวจสอบว่ามีการชำระเงินหรือไม่
	$num_payment=num_record("regis_payment_log","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode'  ");
	if($num_payment!=0){
		//ดึงยอดการชำระเงิน
		$result_regis_payment_log=select("regis_payment_log","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode'  ");
		$cost_totalx=$result_regis_payment_log["cost_total"];
		$cost_totalx=number_format($cost_totalx);
		$comment_pay="/";
		
	}else{
		$comment_pay="x";
		$cost_totalx="-";
	}
	
	
	//แสดงเฉพาะนักศึกษาที่ไม่ลงทะเบียน
	if($num_payment==0){
?>	
      <tr>
        <td><center>
          <?php echo $no;?>
        </center></td>
        <td><center><?=$studentCode?></center></td>
        <td><?php echo "$prefix_name$firstname";?></td>
        <td><?=$surname?></td>
		 <td style="text-align: center"><?=$tel?> </td> 
        <td style="text-align: center"><?=$comment_pay?></td>
      </tr>
<?php
		$no++;
	}
	$a++;
}
?>	
    </tbody>
  </table>	
<h4></h4>	
<!------ สิ้นสุดข้อมูล ------------------------>		
<?php
}
	}
	$a_regis_group++;
}
$login_name=$_SESSION['login_name'];	
$Publisher_day=thai3($today);
echo"ผู้พิมพ์   $login_name     วันที่พิมพ์รายงาน  $Publisher_day  ";
echo"<br>$dev";
	?>	

</div>	
</body>
</html>
	