<?php
if($system_status==1){
	$form_name="";
	$date_start=$date_start;
	$date_end=$date_end;
}
if($system_status==2){
	$form_name="(หลังกำหนด)";
	$date_start=$date_start2;
	$date_end=$date_end2;
}
	
	
?>	 
<script type="text/javascript">
function check(e){
if(e.checked == true) {
document.getElementById('btnSend').disabled=false;
} else {
document.getElementById('btnSend').disabled=true;
}
}
</script>
 <center><h2><strong>ลงทะเบียน <?=$form_name?> ภาคเรียนที่ <?=$semester?> ปีการศึกษา <?=$academicYear?> </strong> </h2>
  <p><?php  echo "กำหนดชำระเงินภายในวันที่ ".thai2($date_start). " - ".thai2($date_end);   ?></p></center>
<style>
	li{
		list-style-type:none;
	}
</style>
<?php
//global $connect;		
			//ดึงข้อมูลนักศึกษา 
				$result_std2018_student=select("std2018_student,prefix,studentstatuscode","where std2018_student.studentCode='$studentCode' AND std2018_student.prefixID=prefix.prefix_id AND std2018_student.studentStatusCode=studentstatuscode.studentStatusCode");
					$prefix_name=$result_std2018_student['prefix_name'];
					$firstname=$result_std2018_student['firstname'];
					$surname=$result_std2018_student['surname'];
					$studentCode=$result_std2018_student['studentCode'];
					$studentStatusCode=$result_std2018_student['studentStatusCode'];
					$gpax=$result_std2018_student["gpax"];
					$tel=$result_std2018_student["tel"];
					$StatusName=$result_std2018_student["StatusName"];
					$tel=$result_std2018_student["tel"];
					$groupName=$result_std2018_student["groupName"];
					$minorNameTH=$result_std2018_student["minorNameTh"];
					$gpax=$result_std2018_student["gpax"];
					$idcard_student=$result_std2018_student["idcard"];	
//ดึงข้อมูลกลุ่มเรียน	
				$result_std2018=select("std2018_studentgroup","where groupCode='$groupCode'");
					$grade=$result_std2018['grade'];
					$groupCode=$result_std2018['groupCode'];
					$groupName=$result_std2018['groupName'];
					$teacherFirstname=$result_std2018['teacherFirstname'];
					$teacherLastname=$result_std2018['teacherLastname'];	
//------- ดึงข้อมูลค่าหน่วยกิต และค่าธรรมเนียมการศึกษา ------
				$num_regis_group=num_record("regis_group","where groupCode='$groupCode'  AND academicYear='$academicYear' AND semester='$semester'  AND status='1'");
				//echo $result;
				$result_regis_group=select("regis_group","where groupCode='$groupCode'  AND academicYear='$academicYear' AND semester='$semester' ");
					$credit=$result_regis_group["credit"];
					$cost_credit=$result_regis_group["cost_credit"];
					$cost_value=$result_regis_group["cost_value"];
					$total_value=$cost_credit+$cost_value;
					include("pages/convert.php"); 
					$convert_number= convert($total_value); 

?>
		
	<div class="card bg-light text-dark">
    			<div class="card-body">
					<div class="row">
		  <div class="col-sm-3"><div align="center"><img src="<?=$picStudent?>/<?=$studentCode?>.jpg" width="100" class="rounded"></div></div>
		  <div class="col-sm-9">
				  <ui>
				    <li>รหัสประจำตัวนักศึกษา : <b><?php echo"$studentCode"; ?></b></li> 
			  		<li>ชื่อ นามสกุล : <b><?php echo"$prefix_name$firstname    $surname"; ?></b></li>
					<li>GPA : <b><?php echo"$gpax"; ?></b></li>  
				  <li>สาขางาน : <b><?php echo"$minorNameTH"; ?></b></li>
				   <li>กลุ่ม : <b><?php echo"$groupName"; ?></b></li>
					 <li>ครูที่ปรึกษา : <b><?php if($teacherFirstname!=""){ echo"ครู$teacherFirstname   $teacherLastname"; }?></b></li>  
				  <li>สถานะภาพ : <b><?php echo"$StatusName"; ?></b></li>
 
			  </ui><br>
	</div></div></div>
</div>
<br>
<div class="row">
  <div class="col-sm-12">
	

<?php
if($num_regis_group==0){
	echo " <div class=\"alert alert-danger\"><center>  <strong> กลุ่มเรียนนี้ ไม่มีข้อมูลการลงทะเบียน</strong> ติดต่องานทะเบียนฯ $tel_regis </center></div>";
	exit();
}	  
if($studentStatusCode!=="03"){
	echo " <div class=\"alert alert-danger\"><center> นักศึกษา <strong>พ้นสภาพ</strong> ไม่สามารถลงทะเบียนได้ ติดต่องานทะเบียนฯ $tel_regis  <br>(กรณีที่ GPA กว่า $lowGPA  นักศึกษาจะไม่สามารถลงทะเบียนได้) </center></div>";
	
}
else
{		
		//echo "333";
		
?>
<div class="card bg-light text-dark">
    			<div class="card-body">
<?php
	//ตรวจสอบว่ามีการ ยีนยันรายการเรียบร้อยแล้วหรือยัง
	$result=num_record("regis_student_log","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode' AND confirm='1' ");
	//echo $result;
	if($result!=0){
		//index.php?op=system
		//header( "location:index.php?op=home" );

		echo "<meta http-equiv=\"refresh\" content=\"0;url=?op=home\">";
		exit(0);
	}

	//ส่งค่า ยืนยันการลงทะเบียน
	$action=$_POST['action'];
	//echo $action;
	if($action=="confirm"){
		//อัพเดจ confirm
		$result_regis_group=select("regis_group","where academicYear='$academicYear' AND semester='$semester' AND groupCode='$groupCode'");
		$cost_credit=$result_regis_group["cost_credit"];
					$cost_value=$result_regis_group["cost_value"];
					$total_value=$cost_credit+$cost_value;
		
		update("regis_student_log","confirm='1',cost_total='$total_value' ","where academicYear='$academicYear' AND semester='$semester' AND studentCode='$studentCode'");
		//เพิ่มรายการค่าธรรมเนียมที่เลืือก
		$cost_item_id_array=$_POST['cost_item_id_array'];
		for ($i=0;$i<count($cost_item_id_array);$i++) {
			$cost_item_id = $cost_item_id_array[$i];
			//เพิ่มค่านธรรมเนียมที่เลือก
			insert("NULL,'$academicYear','$semester','$studentCode','$cost_item_id' ","student_select_option");
		}
		echo "<meta http-equiv=\"refresh\" content=\"0;url=?op=home\">";
		exit(0);	
	}

?>

<form action="" method="post" enctype="multipart/form-data" class="login-form">			
<?php
// -- ค่าธรรมเนียมการศึกษาที่เลือก
$sql2="Select * From cost_groups_item_list,cost_item_list,cost_item where cost_groups_item_list.academicYear='$academicYear' AND cost_groups_item_list.semester='$semester' AND cost_groups_item_list.GroupCode='$groupCode' AND cost_groups_item_list.cost_item_id=cost_item_list.cost_item_id
AND cost_item_list.option=1 AND cost_item_list.cost_item_id=cost_item.cost_item_id";
$db_query2=mysqli_query($connect,$sql2);
$num_rows2=mysqli_num_rows($db_query2);
$a2=0;
$cost_total2=0;	
//echo $num_rows2;
if($num_rows2==0){
	echo"ไม่มีค่าธรรมเนียมการศึกษาเพิ่มเติม";
	$cost_info="ข้าพเจ้ายืนยันในการลงทะเบียนในภาคเรียนนี้";
}else{
	echo "<p>เนื่องจากสถานะการณ์โรคระบบโควิด 19 วิทยาลัยฯ มีนโยบายลดค่าใช้จ่ายของผู้ปกครอง จึงให้ผู้ปกครองเลือกจะจ่ายค่าธรรมเนียมการศึกษาหรือไม่จ่ายค่าธรรมเนียนการศึกษาดังต่อไปนี้ (ถ้าไม่ประสงค์จะจ่ายให้คลิกเครื่องหมายถูกออกจากรายการ)</p>";
	//echo "เลือกค่าธรรมเนียมการศึกษาเพิ่มเติม";
	$cost_info="ข้าพเจ้าขอยืนยันในการชำระค่าธรรมเนียมการศึกษา ตามเลือกทุกประการ และไม่ขอยกเลิกค่าธรรมเนียนการศึกษาที่เลือกภายหลัง";
	while($a2 < $num_rows2)
	{
		$result2 = mysqli_fetch_array($db_query2);
		$cost_item_id=$result2['cost_item_id'];
		$cost_subject=$result2['cost_subject'];
		$cost_var=$result2['cost_var'];
?>
<div class="form-check">
<label class="form-check-label">
    <input type="checkbox" class="form-check-input" name="cost_item_id_array[]" value="<?=$cost_item_id?>" checked><?php echo"$cost_subject     (+$cost_var บาท)"; ?>
  </label>
</div>
<?php
		$a2++;

	}
}	
?>
<center>
<hr>	
<div>
<input type="checkbox" name="chkCon" value="1" id="chkCon" onClick="check(this)" /> <?php echo"$cost_info"; ?>
</div><br>	
<input name="btnSend" id="btnSend" type="submit" class="btn btn-success" disabled value="ยืนยันการลงทะเบียน (ภาคเรียนที่ <?=$semester?> ปีการศึกษา <?=$academicYear;?>)">
<input name="action" type="hidden" id="action" value="confirm">
</center>
</form>
</div>



</div>
<?php } ?>
</div>					
		
</div>
</div>	
