<html>

	<script type="text/javascript">

	
	
var sec = 00; // set the seconds
var min = 180 ;// set the minutes
var hour = 0;
function countDown() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (min >=60) { hour = hour +1; min = min -60}
if (sec<=9) { sec = "0" + sec; }
time = hour + " hour " +(min<=9 ? "0" + min : min) + " min and " + sec + " sec ";

if (document.getElementById) { theTime.innerHTML = time; }
SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
countDown();
})
;
</script>
<?php 

$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
		date_default_timezone_set('Asia/Brunei');

$script_tz = date_default_timezone_get();
$time = date('H:i');

$result2 = mysql_query("select * from room ");
while($row2=mysql_fetch_array($result2)){
$time2 = $row2['time'];
$date = date('Y-m-d');

if(($time == $time2)){

$result3=mysql_query("select RoomNo from room where time='$time'");
$row3=mysql_fetch_array($result3);
$RoomNo = $row3['RoomNo'];



$query = mysql_query("Update room SET status='Available',time='',User='' where RoomNo='$RoomNo'");	
}
}
$result5=mysql_query("select * from roomtrans");
while($row5=mysql_fetch_array($result5)){
$t3 = $row5['booktime'];

if(($time == $t3)){

$result6=mysql_query("select * from roomtrans where booktime='$time' and date='$date'");
$row6=mysql_fetch_array($result6);
$RoomNo = $row6['RoomNo'];
$BookID = $row6['BroomID'];
$bt = $row6['booktime'];
$te =  $row6['endtime'];
$query = mysql_query("Update room SET status='Unavailable',time='$te',User='$BookID',stime='$bt' where RoomNo='$RoomNo'");	
}

}



?>
<body style="background-color: #ffffff;background-image:url(rail.jpg);background-repeat: repeat-y">
<center>
<?php include('link.php'); ?>
<h1 align=center>Admin Book Room</h1>
<a href='http://www.wauhaha.com/karaoke/room.php'>Back</a>
</center>
<?php

$roomtype = $_GET['roomtype'];
echo "<meta http-equiv='refresh' content='5';url=http://www.wauhaha.com/karaoke/viewroom1.php?roomtype=$roomtype >";
$result = mysql_query("select * from room  where roomtype='$roomtype' order by RoomNo");
echo "<form >
<table border=1 align=center>
<tr>
	<td width=100 bgcolor=lightblue align=center>Room Num</td>
	<td width=100 bgcolor=lightblue align=center>RoomType</td>
	<td width=100 bgcolor=lightblue align=center>Status</td>
	<td width=100 bgcolor=lightblue align=center>Book Time</td>
	
	<td width=100 bgcolor=lightblue align=center>End Time</td>
	<td width=100 bgcolor=lightblue align=center>Book ID</td>
	<td width=100 bgcolor=lightblue align=center>Book</td>
	<td width=100 bgcolor=lightblue align=center>Extend</td>
	<td width=100 bgcolor=lightblue align=center>Reservation</td>
</tr>
";
	while($row=mysql_fetch_array($result)){
	$RoomNo = $row['RoomNo'];
	$BookID = $row['User'];
	echo "<tr><td align=center>".$row['RoomNum']."</td>";
	echo "<td>".$roomtype."</td>";
	echo "<td align=center>".$row['status']."</td>";
	echo "<td align=center>".$row['stime']."</td>";
	echo "<td align=center>".$row['time']."</td>";
	echo "<td align=center><a href='viewuser.php?BookID=$BookID' target=_window>".$row['User']."</a></td>";
	echo "<td align=center><a href='http://www.wauhaha.com/karaoke/bookroom1.php?RoomNo=$RoomNo&BookID=$BookID'>Book</a></td>";
	echo "<td align=center><a href='http://www.wauhaha.com/karaoke/extend.php?RoomNo=$RoomNo'>Extend</a></td>";
	echo "<td align=center><a href='http://www.wauhaha.com/karaoke/viewres.php?RoomNo=$RoomNo' target=_window>Reservation</a></td></tr>";
	
	}


echo"
</table>";	
	
	
?>
</body>
</html>