<?php
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );

include ("functions.php");

//error_reporting('0');
//ini_set('display_errors', '0');

$dbhost = 'db.washingtonyachtclub.org';
$dbuser = 'wyc';
$dbpass = 'WYC#Sail!Pass';
$database = 'production';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($database) or die( "Unable to select database");


if(isset($_COOKIE['ID_wycnumber']))
{
	$wycnumber = $_COOKIE['ID_wycnumber'];
	$password = $_COOKIE['Key_site'];
	$query = "SELECT * FROM WYCDatabase WHERE wycnumber = '$wycnumber' and password = PASSWORD('$password')";
	$check = mysql_query($query)or die(mysql_error());

	$check2 = mysql_num_rows($check);
	if ($check2 == 0)
		header("Location: login.php");
	else
	{
		//see if this user is an admin
		$queryadmin = "SELECT wycnum FROM calendaradmin WHERE wycnum = '$wycnumber'";
		$checkadmin = mysql_query($queryadmin)or die(mysql_error());
		$isadmin = mysql_num_rows($checkadmin);

		if($isadmin==0)
			die("You are not an admin user");
		else
		{
		$reservationId = $_REQUEST['resid'];

		if (isset($_POST['confirmdelete']))
		{
			if($_POST['confirmdelete']=="No")
				header("Location: reservationinfo.php?resid=".$reservationId);
			else
			{
				$queryres = "select reservefrom from calendartable where id = '$reservationId'";
				$checkres = mysql_query($queryres)or die(mysql_error());
				$fromdt = datetime(mysql_result($checkres,0,"reservefrom"));

				$querydelete = "delete from calendartable where id = '$reservationId'";
				$checkdelete = mysql_query($querydelete)or die(mysql_error());

				$querydeletecomments = "delete from calendarcomment where id = '$reservationId'";
				$checkdeletecomments = mysql_query($querydeletecomments)or die(mysql_error());

				echo "Reservation has been deleted. <a href=\"cal.php?monthyear=$fromdt\">Return to calendar</a>";
			}
		}
		else
		{
		?>

			<html>
				<head>
					<title>Washington Yacht Club Calendar</title>
					<link rel="stylesheet" type="text/css" href="css/wyc.css">
				</head>
				<body>
					<table style="width:100%">
						<tr>
						<td style="vertical-align:top; text-align:left; width:150px">
							<a href="http://www.washingtonyachtclub.com"><img src="images/burgee_purple.gif" alt="burgee_purple" /></a>
						</td>
						<td style="vertical-align:top">
							<span style="font-size:30">Washington Yacht Club</span>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
							<span style="font-size:18">Keelboat availability</span>
							<br />
							<span style="font-size:9pt">
								Confirm reservation deletion
							</span>
						</td>
						<td style="vertical-align:top; text-align:right">
							<b>Remember to <a href="logout.php">Logout</a></b>
						</td>
						</tr>
					</table>
					<br/><br/>
					<form name="form1" action="<?php echo $_SERVER['PHP_SELF'] . "?resid=" . $reservationId?>" method="post">
						Are you sure you want to delete this reservation, invoice number <?php echo $reservationId ?>?
						<br/><br/>
						<span style="color:red">WARNING:</span> Pressing Yes will delete this reservation permanently.
						<br/><br/><br/>
						<center>
						<input type="submit" name="confirmdelete" value="Yes">
						<input type="submit" name="confirmdelete" value="No">
						</center>
					</form>
				</body>
			</html>
		<?php
		}
		}
	}
}
?>

