<?php
session_start();
include "../conn.php";
include "../functions.php";

$userID = checkAdmin(session_id());

$fid = $_POST["fid"];

$res = mysql_query("select count(*) from room");
$total = mysql_result($res, 0);

if ($total > 1)
{
	if ($_POST["confirm"] == 1)
	{
		mysql_query("delete from room where roomid=$fid");
		mysql_query("delete from roombook where roomid=$fid");
		header ("location: f.php");
		exit;
	}

	$res = mysql_query("select roomname, descr from room where roomid=$fid");
	if ($row = mysql_fetch_array($res))
	{
		$roomname = $row[0];
	}
	include "fheader.php";
	echo "<table width=80% align=center cellspacing=1 cellpadding=3><tr><td align=center>Are you sure you want to delete the room: <b>$roomname</b></td></tr>";
	?>
	<form action=delf.php method=post><tr><td align=center><input type=hidden name=confirm value=1><input type=hidden name=fid value="<?php echo $fid; ?>"><input type=submit value="Yes"></td></tr></form>
	<tr><td align=center><input type=button value="&nbsp;No&nbsp;" onclick="window.location='f.php'"></td></tr>
	</table>
	<?php
	include "adminFooter.php";
}
else
{
	include "fheader.php";
	echo "<table width=80% align=center cellspacing=1 cellpadding=3>";
	?>
	<tr><td align=center><font color=red>This is your last room, you cannot delete it</font></td></tr>
	<tr><td align=center><input type=button value="Go Back" onclick="window.location='f.php'"></td></tr>
	</table>
	<?php
	include "adminFooter.php";
}
?>