<html>
<head>
<title>
<? 

echo"Write a Review About Product";?></title>
	  <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
	  <link rel='stylesheet' href='../style.css' type='text/css'>
</head>
<body bgcolor = "#FFFFFF">
<?
/***************************************************************************
 *			write-review.php                                   *
 *                     	          				           *
 *   File Info:		  Write Reviews                                    *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include("./config.php");
include("./tests.php");
include_once("./your-headers.inc");
$pid = getenv("QUERY_STRING");
$done = "NO";
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $act= addslashes($_POST["act"]);
        $pid = addslashes($_POST["pid"]);
        $pitem = addslashes($_POST["pitem"]);
        $rating = addslashes($_POST["rating"]);
        $title = addslashes($_POST["title"]);
        $review = addslashes($_POST["review"]);
        $location = addslashes($_POST["location"]);
        $date_added = addslashes($_POST["date_added"]);
        $dispname = addslashes($_POST["dispname"]);
}

# code and function for saving  #

if ($act == "save")
{
	if ($dispname == NULL and $title == NULL and $review == NULL and $location == NULL)
	{
		echo "<img src=images/line.gif border=0 width=100% height=1><br><br><center><img src=images/write-review.gif border=0></center><br>";
		echo "<br><center><img src=images/bullets.gif border=0><font face=verdana size=2> Opps...there are some data fields which are empty...Please try again!!!</font></center>";
		echo "<br><br><center><a href=javascript:history.back()><b>Click to go back</b></a></center><br><img src=images/line.gif border=0 width=100% height=1>";
		exit();
	}	
	if ($dispname != NULL && $title != NULL && $review != NULL && $location != NULL)
	{

	}
	else
	{
		echo "<img src=images/line.gif border=0 width=100% height=1><br><br><center><img src=images/write-review.gif border=0></center><br>";
echo "<br><center><img src=images/bullets.gif border=0><font face=verdana size=2> Opps...there are some data fields which are missing data...Please try again!!!</font></center>";
		echo "<br><br><center><a href=javascript:history.back()><b>Click to go back</b></a></center><br><img src=images/line.gif border=0 width=100% height=1>";
		exit();
	}
	
	# print the contents of review
	
	$date_added = date("H:i dS F");
	
	echo "<img src=images/line.gif border=0 width=100% height=1><br><br><center><img src=images/write-review.gif border=0></center><br>";
	echo "<center><b>Your review contents</b></center>";
	echo "<br>";
	echo "Author: $dispname";
	echo "<br>Title: $title";
	echo "<br>Location: $location";
	echo "<br>Product Item: $pitem     Rating: $rating";
	echo "<br>Review Contents:<br>$review";
	echo "<br>Date Added: $date_added<br><img src=images/line.gif border=0 width=100% height=1>";

	#save it and close window

	$table = "reviews";
	$conn = @mysql_connect($server,$user,$password)
		or die("Unable to connect to SQL database...");
	$rs = @mysql_select_db($database,$conn) 
		or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");
	$sql = "INSERT INTO $table (pid,pitem,rating,title,review,dispname,location,date_added) values('$pid','$pitem','$rating','$title','$review','$dispname','$location','$date_added')";
	$rst = @mysql_query($sql,$conn)
		or die("Unable to fetch data for product item...please try again !!!!");

	echo "<br><br><center><img src=images/bullets.gif border=0><font color = navy face=verdana>Your review has been save to the database !!!</center>";
	echo("<br><center><img src=images/exit.gif border=0><a href = javascript:window.close('acePopup')>  Close Window</a></center>");

		
}
if ($act == NULL)
{

$table = "products";
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");
$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");

$sql = " SELECT pid,pitem from $table where pid = '$pid'";
$rst = @mysql_query($sql,$conn)
	or die("Unable to fetch data for product item...please try again !!!!");
while ($row = mysql_fetch_array($rst))
{
	$pitem = $row["pitem"];
}
	
echo "<img src=images/line.gif border=0 width=100% height=1><br><br><center><img src=images/write-review.gif border=0></center><br>";
	$form.="<form action = write-review.php method = post>";
	$form.="<input type = hidden name = act value = 'save'>";
	$form.="<input type = hidden name = pid value = $pid>";
	$form.= "<table width=100% cellpadding=2 cellspacing=0 border=0 bgcolor=$backcolor align = center>";
	$form.="<tr><td><font face=verdana size=2>Your name:</font></td><td><input type = text name =dispname maxlength = 30></td></tr>";
	$form.="<tr><td><font face=verdana size=2>Review Title:</font></td><td><input type = text name =title size = 50 maxlength = 50></td></tr>";
	$form.="<tr><td><font face=verdana size=2>Product Item:</font></td><td><input type = text name = pitem value = '$pitem' size = 50 maxlength = 50 readonly></td></tr>";
	$form.="<tr><td><font face=verdana size=2>Location:</font></td><td><input type = text name = location size = 35 maxlength = 50></td></tr>";
	$form.="<tr><td><font face=verdana size=2>Review:</font></td></td><td><textarea name = review cols = 45 rows = 5></textarea></td></tr>";
	$form.="<tr><td><font face=verdana size=2>Rate product 1 - 5 stars</font></td><td><select name = rating><option value =\"0 star\">-- No star --</option><option value =\"1 star\">-- 1 star --</option><option value =\"2 star\">-- 2 star --</option><option value =\"3 star\">-- 3 star --</option><option value =\"4 star\">-- 4 star --</option><option value =\"5 star\">-- 5 star --</option>";
	$form.="</select></td></tr>";
	$form.="<tr><td><input type = submit value = 'Save Review'></td><td><input type = reset value = 'Clear contents'>";
	$form.="</table></form>";
	echo $form;
	echo "<p align = justify><b><font face=verdana size=2>Write your own Review</b><br><br>We are very please you'd like to review $pitem. Please write your comments on the item's contents/features/performance/faults if any. To save your review, please fill in all the data fields and press 'Save button' at bottom.</font></p>";
echo "<br><br><br>";

}

?>

</body>
</html>