
<?php
include '../../connect.php';
session_start();

$ic = $_SESSION["kadPengenalan"];
$bilikID = $_GET['bilikID'];

$kelulusan= $_POST['kelulusan'];
$catatan =$_POST['catatan'];

date_default_timezone_set("Asia/Kuala_Lumpur");			
$date=date('Y-m-d');
$time=date('H:i:sa');

	if($kelulusan =="")
	{
		mysqli_commit($conn);
		echo "<script>alert('Sila lengkapkan maklumat. ');";
		echo "window.location.href = '../semakKelulusan.php';</script>";
		exit;
		
	}
	else
	{
		if ($catatan=="")
		{
			$query="UPDATE tempahan_bilik SET status='$kelulusan' WHERE bilikID='$bilikID' ";
			$strQuery = mysqli_query($conn,$query);
			
			if($strQuery) 
				{
					$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
							VALUES ('$ic','$date','$time','Kelulusan','Permohonan bilik.$kelulusan')";
					$strQuery1 = mysqli_query($conn,$q4);
					
					if($strQuery1)
					{								
						echo "<script>window.location.href = '../listSemakKelulusan.php';</script>";
						exit;
					}
					else{
						
					}
					
				}
				else
				{
					mysqli_commit($conn);
					echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
					echo "window.location.href = '../semakKelulusan.php';</script>";
					exit;
					
				}
		}
		else
		{
			$query="UPDATE tempahan_bilik SET status='$kelulusan',catatan='$catatan' WHERE bilikID='$bilikID' ";
			$strQuery = mysqli_query($conn,$query);
			
			if($strQuery) 
				{
					$q4="INSERT INTO audit_trail(kad_pengenalan,tarikh,masa,operasi,catatan)
							VALUES ('$ic','$date','$time','Kelulusan','Permohonan bilik.$kelulusan')";
					$strQuery1 = mysqli_query($conn,$q4);
					
					if($strQuery1)
					{								
						echo "<script>window.location.href = '../listSemakKelulusan.php';</script>";
						exit;
					}
					else{
						
					}
					
				}
				else
				{
					mysqli_commit($conn);
					echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
					echo "window.location.href = '../semakKelulusan.php';</script>";
					exit;
					
				}
		}
		
	}
?>

