<?php
$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	
$RoomNo = $_GET['RoomNo'];	
$BroomID = $_POST['BroomID'];
$rt = $_POST['rt'];
$n = $_POST['n'];
$ic = $_POST['ic'];
$c = $_POST['c'];
$d = $_POST['d'];
$t = $_POST['t'];
$h = $_POST['h'];
$t1 = $t +3;
$q1 = $_POST['q1'];
$p1 = $_POST['p1'];
$tp1 = $_POST['tp1'];
$q2 = $_POST['q2'];
$p2 = $_POST['p2'];
$tp2 = $_POST['tp2'];
$tp3 = $_POST['tp3'];

$From = $t;
$Minutes = 60 * $h;

$To = date("H:i", strtotime($From)+($Minutes*60));
$res1 = mysql_query("select * from roomtrans where RoomNo='$RoomNo' ");

$aa = mysql_fetch_array($res1);

$enti = $aa['time'];
$stti = $aa['booktime'];

if(($t >=0)&&($t <6)){
	echo "<script>alert('Closed')</script>";
		echo "<script language='javascript'>window.location='viewroom2.php?roomtype=$rt'</script>";die;
}	
if(($To <3))	{
		echo "<script>alert('Closed')</script>";
		echo "<script language='javascript'>window.location='viewroom2.php?roomtype=$rt'</script>";die;
		}
		if(($To <= $enti)&&($To >= $stti)){
		echo "<script>alert('Room With Customer')</script>";
		echo "<script language='javascript'>window.location='viewroom2.php?roomtype=$rt'</script>";die;
	
	}
$query = mysql_query("Insert into roomtrans(BroomID,Name,IC,Contact,date,time,booktime,hours,Total,package1,people1,price1,package2,people2,price2,total1,total2,roomtype)Value
					('$BroomID','$n','$ic','$c','$d','$t','$t','$h','$tp3','Normal','$q1','$p1','Student','$q2','$p2','$tp1','$tp2','$rt')");

$query2 = mysql_query("Update room SET status='Unavailable',time ='$To',User='$BroomID' where RoomNo='$RoomNo'");	

if(($query)&&($query2)){
			echo "<script>alert('Book Successful')</script>";
		echo "<script language='javascript'>window.location='viewroom2.php?roomtype=$rt'</script>";die;


}else
	echo "<script>alert('Book Fail ')</script>";
		echo "<script language='javascript'>window.location='viewroom2.php?roomtype=$rt'</script>";die;

	
	
	?>