<html>
<head>
<title>
<? 

echo"Viewing Reviews for this 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 = "#CCDDFF">
<?php
/***************************************************************************
 *			see_review.php                   	           *
 *                     	          				           *
 *   File Info:		  View customer reviews                            *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./config.php");
include("./tests.php");


$pid = getenv("QUERY_STRING");
$pos = strpos($pid,'=');
if ($pos > 0)
{
	$page = substr($pid,0,$pos);
	$pid = substr($pid,$pos+1);
	
}
echo "<br><center><img src=images/srchfol.gif border=0><font face=verdana size=3>   Viewing reviews for product</font></center><br>";
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $limit= addslashes($_POST["limit"]);
        $pid = addslashes($_POST["pid"]);
}
if ($limit == NULL)
	$limit = 5;

	echo "<img src=images/line.gif border=0 width=100% height=1><br><font face = Verdana size = 2>Please select number of reviews you wish to view:- ";
	$form = "<form action =see-review.php method = POST>";
	$form.="<input type = hidden name = pid value = $pid>";
	$form.= "<select name = limit><option value = 5>5 records</option><option value = 10>10 records</option><option value = 25>25 records</option><option value = 50>50 records</option></select>";
	$form.= "<input type=submit value = 'View Review'></form>";
	echo $form;

$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...Please press 'Create Database' to create new database.");

// limit value for records to be shown


$query_count = "SELECT * from $table where pid = '$pid'";
$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);

if (empty($page))
$page = 1;
$limitv = $page * $limit - ($limit);

$query = "SELECT * from $table where pid = '$pid' LIMIT $limitv,$limit";
$result = mysql_query($query,$conn)
	or die("SQL command fail ".mysql_error());
$count_result = mysql_num_rows($result);

$numpages = ceil($totalrows / $limit);

echo "<p><center><b>Found $totalrows</b> result(s) for product id = '$pid' - Listing $limit reviews per page.</center></p>";
$from = $limit*$page-$limit+1;
$to = $from+$count_result-1;
if ($style == 1) #style 1
{
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"#CCDDFF\" align=\"left\">";if($numpages>1){echo"Showing item(s): $from to $to</td><td width=\"50%\" bgcolor=\"$backcolor1\" align=\"right\"><b>Go to page:</b> ";} 
}
if ($style == 2) #style 2
{
echo "<table align=\"center\" width=\"60%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"#CCDDFF\" align=\"left\">";if($numpages>1){echo"Showing item(s): $from to $to</td></tr><hr><tr><td width=\"50%\" bgcolor=\"#CCDDFF\" align=\"right\"><b>Go to page:</b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev=$pid\"><img src = ./images/back.gif  width = 20 height = 16 border = 0></a>"); 

} 

// display page nos if not 1 
for($i = 1; $i <= $numpages; $i++){ 
if($numpages>1){
if($i == $page) 
echo("&nbsp;".$i."&nbsp;"); 
else
echo("&nbsp;<a href=\".\see-review.php?$i=$pid\">$i</a>&nbsp;"); 
}}

// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){ 
$pagenext = $page + 1; 
echo("<a href=\"$PHP_SELF?$pagenext=$pid\"><img src = ./images/next.gif width = 20 height = 16 border = 0></a>"); 

}
echo "</td><tr></table>";
echo("<br><center><hr width=360></center><center><a href = javascript:window.close('acePopup')>Close Window</a></center><br>");
$list = "<center><table border=1 width=450>";
while($row = mysql_fetch_array($result))
{
	$pid = $row["pid"];
	$pitem = $row["pitem"];
	$rating = $row["rating"];
	$title = $row["title"];
	$review = $row["review"];
	$dispname = $row["dispname"];
	$location = $row["location"];
	$date_added = $row["date_added"];
	$list.= "<tr>";
	$list.="<td><b>Product ID:</b>$pid<td><b>Product Item: </b> $pitem</td></tr>";
	$list.="<tr><td><b>Title: </b> $title</td></tr>";
	$list.="<tr><td><b>Rating: </b>";
	if ($rating == "0 star")
		$list.= "$rating";
	if ($rating == "1 star")
		$list.= "<img src = ./images/yelstar.gif>";
	if ($rating == "2 star")
		$list.= "<img src = ./images/yelstar.gif><img src = ./images/yelstar.gif>";
	if ($rating == "3 star")
		$list.= "<img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif>";
	if ($rating == "4 star")
		$list.= "<img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif>";
	if ($rating == "5 star")
		$list.= "<img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif><img src = ./images/yelstar.gif>";
	$llist.= "</td></tr>";
	$list.="<tr><td colspan=2><b>Review: </b> $review</td></tr>";
	$list.="<tr><td><b>Author: </b> $dispname</td><td><b>Location: </b> $location</td></tr>";
	$list.="<tr><td colspan=2><b>Date: </b> $date_added</td></tr>";
}
$list.= "</table></center>";
echo $list;
echo "<img src=images/line.gif border=0 width=100% height=1>";
include_once("./footer.inc");
?>
</body>
</html>