<?php 

$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
mysql_selectDB("wauhaha_karaoke",$login);
$Username = $_GET['Username'];
$BookID = $_GET['BookID'];

$date = date('Y-m-d');
		date_default_timezone_set('Asia/Brunei');

$script_tz = date_default_timezone_get();
$time = date('H:i');
$result2 = mysql_query("SELECT * FROM roomtrans where BroomID='$BookID' ");
$row2 = mysql_fetch_array($result2);
$date1 = $row2['date'];
$time1 = $row2['booktime'];
$credit = $row2['Credit'];
$result3 = mysql_query("Select * from regmember where Username='$Username' ");
$row3 = mysql_fetch_array($result3);
$MemID = $row3['MemID'];
$Name= $row3['Name'];
$credit1 = $row3['Credit'];

$credit2 = $credit + $credit1;

if(($time > $time1)||($date > $date1)){
		echo "<script>alert('Cannot Cancel Reserve')</script>";
		echo "<script language='javascript'>window.location='viewbooktrans1.php?Username=$Username&BookID=$BookID'</script>";die;

}else{

$query =mysql_query("delete from roomtrans where BroomID='$BookID'");
$query4 =mysql_query("Insert into credittran(MemID,Username,Name,AddCredit,AddCreditD,BalCredit)VALUES('$MemID','$Username','$Name','$credit','$date1','$credit2')");
$query2 =mysql_query("update regmember set Credit='$credit2' where Username='$Username' ");
$query3 = mysql_query("update room set time='',status='Available',User='',stime='' where User='$BookID'");
if(($query)&&($query2)&&($query3)){
		echo "<script>alert('Cancel Reserve Successful')</script>";
		echo "<script language='javascript'>window.location='viewbooktrans.php?Username=$Username'</script>";die;

}else
	echo "<script>alert('Cancel Reserve Fail')</script>";
		echo "<script language='javascript'>window.location='viewbooktrans.php?Username=$Username'</script>";die;

}
?>