<?php require_once("initialize.php") ?>
<?php include("top.php") ?>
<?php
if($_REQUEST["name"]) {
	$ok = $_REQUEST[ 'ok' ];
	if( $ok == "12345" || $ok == "\\'12345\\'" ) {
		$query = "insert into guestBook(name,location,connection,comment,date) values(";
		$query .= "'$_REQUEST[name]',";
		$query .= "'$_REQUEST[location]',";
		$query .= "'$_REQUEST[connection]',";
		$query .= "'$_REQUEST[comment]',";
		$query .= "'" . date("F j, Y, g:i a") . "')";
		$databaseConnection->executeCommand($query);
	}
}

?>
<td>
<center>
<!--
<h1>Adding new messages is temporarily shut off, please come back later</h1>
-->
<form action="guestBook.php" method=POST>
<table>
	<tr>
		<td>Your Name:</td>
		<td><input type=text name=name id=name size=50 /></td>
	</tr>
	<tr>
		<td>Where are you from?</td>
		<td><input type=text name=location id=location size=50 /></td>
	</tr>
	<tr>
		<td>Your Connection to us:<br />(optional)</td>
		<td><textarea name=connection id=connection rows=3 cols=80></textarea></td>
	</tr>
	<tr>
		<td>Your Comment:</td>
		<td><textarea name=comment id=commnet rows=5 cols=80></textarea></td>
	</tr>
	<tr>
		<td>Please type the string '12345' here:</td>
		<td><input type=text name=ok id=ok size=50 /></td>
	</tr>
</table>
<input type=submit value="Post your message" />

</form>
</center>
<hr />
<center>
<h2>Messages friends have left us</h2>
<?php
$result = $databaseConnection->executeQuery("select * from guestBook order by id desc");
if(!$result) {
	echo "<i>No Messages Yet, be the first to leave one!</i>";
} else {
	$odd = 1;
	foreach($result as $entry) {
		if($odd) {
			$cell_color = "#FF9999";
			$border_color="#FCC169";
			$odd = 0;
		} else {
			$cell_color = "#FCC169";
			$border_color="#E08183";
			$border_color="#FF9999";
			$odd = 1;
		}
?>
<table border=1 width=90% bgcolor="<? echo $border_color ?>">
	<tr bgcolor="<? echo $cell_color ?>">
		<td width=50%>Name: <? echo $entry[name] ? $entry[name] : "Anonymous" ?></td>
		<td>Connection: <? echo $entry[connection] ? $entry[connection] : "Unknown" ?></td>
	</tr>
	<tr bgcolor="<? echo $cell_color ?>">
		<td>From: <? echo $entry[location] ? $entry[location] : "Unknown"?></td>
		<td>Date: <? echo $entry[date] ? $entry[date] : "Unknown" ?></td>
	<tr bgcolor="<? echo $cell_color ?>">
		<td colspan=2><? echo $entry[comment] ?></td>
	</tr>
</table>
<br />
<?php
	}
}
?>
</center>
</td>
<?php include("bottom.php");
