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

// Validasi parameter GET dan POST
if (!isset($_GET['tempahanID']) || empty($_GET['tempahanID'])) {
    echo "<script>alert('Ralat: ID tempahan tidak sah.'); window.location.href = '../listSemakKelulusan.php';</script>";
    exit;
}

$tempahanID = $_GET['tempahanID'];
$catatan = isset($_POST['catatan']) ? strtoupper($_POST['catatan']) : '';

$query = "SELECT tempahanID FROM tempahan_kenderaan WHERE tempahanID='".$tempahanID."'";
$strQuery = mysqli_query($conn,$query);

	if($strQuery)
	{
			
		$query= "UPDATE `tempahan_kenderaan` SET status='BATAL', catatan='".$catatan."' WHERE tempahanID='".$tempahanID."'";
		$strQuery = mysqli_query($conn,$query);	
		
		if($strQuery) 
		{
			$sql = "SELECT * FROM tempahan_kenderaan WHERE tempahanID='$tempahanID'";
			$result = mysqli_query($conn,$sql);
			$row = mysqli_fetch_array($result);
			
			echo "<script>";
			echo "window.location.href = '../listSemakKelulusan.php';</script>";
			exit;
		}
		else
		{
			echo 'MySQL Error: ' . mysqli_error($conn);
			exit;
		}
		
	}
	else
	{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
	}
?>