<?php
session_start();
$session=session_id();
require("../inc/config.inc.php");
require("../inc/common.php");
require('../pdf-thai/fpdf.php');
  include "qr/qrlib.php";  

//echo $_SESSION['login'];
if(empty($_SESSION['login'])){	
	echo"Error";
	exit();
}
$groupCode=$_GET['groupCode'];		
//ดึงข้อมูลกลุ่มเรียน	
$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;	
	
	$result_regis_group=select("regis_group","where groupCode='$groupCode' AND academicYear='$academicYear' AND semester='$semester' ");
	$cost_credit=$result_regis_group['cost_credit'];
	$cost_value=$result_regis_group['cost_value'];
	//ยอดเงินที่ต้องลงทะเบียน
	$total_cost=$cost_credit+$cost_value;
	$total_cost2=$cost_credit+$cost_value;
/*
if($_GET['ex']=='xls'){
$strExcelFileName="รายชื่อนักศึกษา ปีการศึกษา $academicYear ภาคเรียน $semester ระดับ $grade  $groupName กลุ่ม $groupAbbr.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">	
<!-------- เริ่มข้อมูล ------------------------>

<h3>ข้อมูล QR Code นักศึกษา ภาคเรียนที่ <?=$semester?> ปีการศึกษา <?=$academicYear?> </h3>


<?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> คน";	
?>
ระดับ   <b><?=$grade?></b>    รหัสกลุ่ม <b><?=$groupCode?></b>  <b><?=$groupName?></b><br>
ครูที่ปรึกษา <b><?php if($teacherFirstname!=""){ echo "ครู$teacherFirstname    $teacherLastname"; }?></b> 
จำนวนนักศึกษาทั้งหมด  <b><?=$num_student?></b> คน  <br>

	
<?php	
if($num_rows==0)
{
	echo " ไม่พบข้อมูลนักศึกษา";
}else{
?>
         
<table width="747" border="1" cellpadding="0" cellspacing="0">
    <thead>
      <tr>
        <th width="48" bgcolor="#E7E7E7"><center>
          ลำดับ
        </center></th>
        <th width="140" bgcolor="#E7E7E7"><center>รหัสประจำตัว<br>นักศึกษา</center></th>
        <th width="152" bgcolor="#E7E7E7">ชื่อ</th>
		<th width="127" bgcolor="#E7E7E7">นามสกุล</th>
		 <th width="120" bgcolor="#E7E7E7">เบอร์โทร</th> 
		 <th width="120" bgcolor="#E7E7E7">QR Code</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'];
	$tel=$result['tel'];
	$tel="&nbsp;$tel";
	$studentCode=$result['studentCode'];
	$studentStatusCode=$result['studentStatusCode'];
	$gpax=$result["gpax"];

//------- ดึงข้อมูลค่าหน่วยกิต และค่าธรรมเนียมการศึกษา ------

?>	
      <tr>
	  <td bgcolor="<?=$high_ling_bg?>"><center>
          <?php echo $no;?>
        </center></td>
        <td bgcolor="<?=$high_ling_bg?>"><center><?=$studentCode?></center></td>
        <td bgcolor="<?=$high_ling_bg?>"><?php echo "$prefix_name$firstname";?></td>
        <td bgcolor="<?=$high_ling_bg?>"><?=$surname?></td>
		
		<td bgcolor="<?=$high_ling_bg?>"><center>
		  <?=$tel?>
		</center></td>
		 <td style="text-align: center; font-size: x-small;" bgcolor="<?=$high_ling_bg?>">
<?php             
   if($studentCode!='')
	{
    //set it to writable location, a place for temp generated PNG files
    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
    //html PNG location prefix
    $PNG_WEB_DIR = 'temp/';
    if (!file_exists($PNG_TEMP_DIR))
        mkdir($PNG_TEMP_DIR);
    $filename = $PNG_TEMP_DIR.'test.png';
	$data=$studentCode;
		$filename2 = 'test'.md5($data.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
		$filename = $PNG_TEMP_DIR.'test'.md5($data.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
        QRcode::png($data, $filename, $errorCorrectionLevel, 6, 2);    
    	//echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" />';  
		$qr1="temp/$filename2"; 
		//if($status_qr=="on"){
       //echo "$qr1";

        echo "<img src=\"$qr1\" width=\"80\" >";     
             

		//}
		
		//ฺbarcode
		//$pdf->Image('http://regis-std.cmtc.ac.th/barcode.php?text='.$ref1.'&print=true',45,265,70,10,'PNG');	
		//$pdf->Image('http://regis-std.cmtc.ac.th/barcode.php?text='.$bar_code.'&print=true',50,270,120,12,'PNG');	
	}
//--------------------------             
             
             
             
?>
            <?=$studentCode?>
            <br /><br></td>
	  </tr>
<?php
	$a++;
	$no++;
}
?>	
    </tbody>
  </table>		
<?php
	}
$login_name=$_SESSION['login_name'];	
$Publisher_day=thai3($today);
echo"ผู้พิมพ์   $login_name  $Publisher_day  ";
//echo"<br>$dev";
	?>	
		
	
	
<!------ สิ้นสุดข้อมูล ------------------------>	
</div>	
</body>
</html>
<?php
	/*
if($ex2!='xls'){
$html = ob_get_contents();
ob_end_clean();
$pdf = new mPDF('th', 'A4', '0', 'THSaraban');
$pdf->SetAutoFont();
$pdf->SetDisplayMode('fullpage');
$pdf->WriteHTML($html, 2);
$pdf->Output();

}*/
?>   	