<?
/***************************************************************************
 *			shop_shopitems.php                      	   *
 *                     	          				           *
 *   File Info:		  View product information                         *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include("./config.php");
include("./tests.php");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Product Item Details</TITLE>
<script language="JavaScript">
function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}
</script>
</HEAD>
<BODY  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<?

######################### if first time...url will contain PHPSESSID=xxxx         #############################
######################### code below will refresh page to remove PHPSESSID #############################
$strvar = getenv("QUERY_STRING");
$pos = strpos($strvar,'&');
$strs = substr($strvar,0,$pos);
session_start();


if ($pos > 0 && $_SESSION['empty'] == NULL)
{
if ($noshow == "YES")
{
echo "<br><br><table width=450 border=1 cellspacing=0 cellpadding=0 height=150>
<tr><td width=450 bgcolor=#CCCCCC height=10>EZ Shopper Information</td></tr>
<tr><td width=450 bgcolor=#FFFFFF height=140>";
	echo "<b><br><center>Please be patient as we now re-directing you to main store page...<br>You will only see this message once i.e every time you start a new browser window.</center></b><br></td></tr></table>";
}
	include_once("./redirect-me.php");
}else{

if ($phpcart == "NO") {
if ($usecat == "YES")
	include_once("./sidebars.php");
else
	include_once("./sidebar.php"); }
$pidnew = getenv("QUERY_STRING"); 

$color = "#00CC00";
$pic=".\images\pocky.jpg";
$pidnews = getenv("QUERY_STRING"); 
$pos = strpos($pidnews,"&");
if ($pos > 0)
{
	$pidnew = substr($pidnews,0,$pos);
}
else
{
	$pidnew = getenv("QUERY_STRING"); 
}
$table = "stocks";
$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.");

echo("<br>");
$sql = " SELECT pid,sitem,scat,spic,stock,color,size from $table where $pidnew";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

$row=mysql_fetch_array($rs);
$pics = $row["spic"];
$scat=$row["scat"];
$stocknum = $row["stock"];
if (strlen($pics) < 1)
{
	$pics="./images/nopic.jpg";
}
if (fopen($pics,"r") == NULL)
	$pics = "./images/nopic.jpg";
if (strlen($scat) < 1)
{
	$scat = "N/A";
}

# check if there are stocks for a product 
$showform = "YES";
if ($stockopt == "YES")
{
if ($stocknum <= 0)
{
	$showform = "NO"; // disable display of add button
}
}
echo"<table width=90% border=0 align=center cellspacing=0 cellpadding=0>
  <tr bgcolor=#B8C9D8>
    <td width=8 height=27><img src=images/tl.gif width=8 height=27></td>
    <td height=27 background=images/tbg.gif align=center><font face=verdana size=2><b>Category:</b></font> <font face=verdana size = 2>$scat</font></td>
    <td width=8 height=27><img src=images/tr.gif width=8 height=27></td>
  </tr></table>";

?>

<?


$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.");

# updating rating table

$table = "rating";
$ratesql = "SELECT * from $table where $pidnew";
$rate = @mysql_query($ratesql,$conn)
	or die("Unable to find product id from rating table...");
$rrow = mysql_num_rows($rate);
$ratenum = 0;
if ($rrow == 0)
{
	$getpid = $pidnew;
	$postion = strpos($getpid,'=');
	if ($postion > 0)
	$pid = substr($getpid,$postion+1);
	$table = "products";
	$nsql = "SELECT pid,pitem,pdes,price from $table where $pidnew";
	$rst = @mysql_query($nsql,$conn);
	$pow = mysql_fetch_array($rst);
	$pitem = $pow["pitem"];
	$table ="rating";
	$ratesqls = "INSERT INTO $table (pid,item,rating) values('$pid','$pitem',1)";
	$rates = @mysql_query($ratesqls,$conn)
		or die("Unable to insert rating for product item");
}
else
{
	$table = "rating";
	$getrate = "SELECT * from $table where $pidnew";
	$rates1 = @mysql_query($getrate,$conn)
		or die("Unable to find product id from rating table...");
	while ($rinf = mysql_fetch_array($rates1))
	{
		$ratenum = $rinf["rating"];
	}
	$ratenum += 1;
	$updrate = "UPDATE $table set rating = '$ratenum'  where $pidnew";
	$rates2 = @mysql_query($updrate,$conn);
}

$table = "products";
echo("<br>");
$sql = " SELECT pid,pitem,pdes,price from $table where $pidnew";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

$row=mysql_fetch_array($rs);
$pid=$row["pid"];
$pitem=$row["pitem"];
$pdes=$row["pdes"];
$price=$row["price"];
$price = number_format($price,2);

$table = "stocks";
$sqls = "SELECT pid,scat,stock,color,size from $table where $pidnew";
$rss = @mysql_query($sqls,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query will cause a fault...:");
$rows = mysql_fetch_array($rss);

$category = $rows["scat"];
$stocknum = $rows["stock"];
$color = $rows["color"];
$size = $rows["size"];

$list="<table width=100% cellpadding=2 cellspacing=0 border=0 bgcolor=$backcolor align = center>";
$list.="<tr>";
$list.="<td width=200><strong>Product Image</strong></td>";
$list.="<td width=200><img src=$pics></td>";
$list.="<tr>";
$list.="<td><strong>Product ID:</strong></td>";
$list.="<td>$pid</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td align=justify><strong>Product Item:</strong></td>";
$list.="<td>$pitem</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td align=justify><strong>Product Description</strong></td>";
$list.="<td>$pdes</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td><strong>Category</strong></td>";
$list.="<td>$category</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td><strong>Stock</strong></td>";
$list.="<td>$stocknum</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td><strong>Color</strong></td>";
$list.="<td>$color</td>";
$list.="</tr>";

$list.="<tr>";
$list.="<td><strong>Size</strong></td>";
$list.="<td>$size</td>";
$list.="</tr>";
if ($wcurrency == "NO")
{
	$list.="<tr>";
	$list.="<td><strong>Price: $currency</strong></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "ARS")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/argntina.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "BRL")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/brazil.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "BND")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/brunei.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "CNY")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/china.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "EGY")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/egypt.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "HKD")
{
	$list.="<tr>";	
	$list.="<td><img src = ./images/hngkng97.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "INR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/india.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "IDR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/indonsia.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "KWD")
{
	$list.="<tr>";	
	$list.="<td><img src = ./images/kuwait.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "MYR")
{
	$list.="<tr>";	
	$list.="<td><img src = ./images/malaysia.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	

}
if ($wcurrency == "NZD")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/newzeal.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "NOR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/norway.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "PKR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/pakistan.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "PHP")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/phillipn.gif><td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}
if ($wcurrency == "PLN")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/poland.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}		
if ($wcurrency == "ROL")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/romania.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";	
}		
if ($wcurrency == "RUR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/russia.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}		
if ($wcurrency == "SAR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/saudiar.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "SGD")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/singapor.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "ZAR")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/safrica.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}		
if ($wcurrency == "KRW")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/skorea.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "SEK")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/sweden.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}		
if ($wcurrency == "CHF")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/switzrld.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}		
if ($wcurrency == "TWD")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/taiwan.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "THB")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/thailand.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}
if ($wcurrency == "VND")
{
	$list.="<tr>";
	$list.="<td><img src = ./images/vietnam.gif></td>";
	$list.="<td>$price</td>";
	$list.="</tr>";
}		
if ($ratenum > 0)
{
	
	$table = "rating";
	$nsql = "SELECT * from $table order by rating desc LIMIT 10";
	$rst = @mysql_query($nsql,$conn);
	while ($row = mysql_fetch_array($rst))
	{
		$pidget = $row["pid"];
		if ($pid == $pidget)
			$list.="<tr><td><b>Rated product:</b></td><td><img src = ./images/cokecan.gif></td>";
	}
}
if ($showform == "YES")
{
if ($wcurrency == "NO")
{
 $list.="<tr> <td><b><form method=POST action=shop_addtocart.php?pid=$pid>
	<input type=hidden name=sel_item value='$pitem'>
	<input type=hidden name=sel_item_title value='$pdes'>
	<input type=hidden name=sel_item_price value=$price>
	<em><font color=#0000BB>Quantity:</td><td><input type=text name=sel_item_qty  value=1 size=3></td></tr><tr><td><center><input type=submit name=submit value='Add to Shopping Cart'></center>
	</form></td><td><font color=#FF0000><strong>Our Price $currency$price!</strong></font></td></tr>";
}
else
{
$list.="<tr> <td><b><form method=POST action=shop_addtocart.php?pid=$pid>
	<input type=hidden name=sel_item value='$pitem'>
	<input type=hidden name=sel_item_title value='$pdes'>
	<input type=hidden name=sel_item_price value=$price>
	<em><font color=#0000BB>Quantity:</td><td><input type=text name=sel_item_qty  value=1 size=3></td></tr><tr><td><center><input type=submit name=submit value='Add to Shopping Cart'></center>
	</form></td><td><font color=#FF0000><strong>Our Price ($wcurrency) $price!</strong></font></td></tr>";
}
$list.= "<tr><td><img src = ./images/email-me.gif></td><td><img src = ./images/mailto.gif><a href = javascript:newWindow('./email-me.php?$pid','acePopup',450,600,'scrollbars=yes')>Email a friend </a></td></tr><tr><td><img src = ./images/email-me.gif></td><td><img src = ./images/edit.gif><a href = javascript:newWindow('./write-review.php?$pid','acePopup',600,550,'scrollbars=yes')>Write a Review</a></td></tr>";

}
else
{
	$list.="<tr><td></td><td><strong><font color =0000BB>OUT OF STOCK!!!</font></strong></td></tr>";
}

########################### check for any reviews for this product ####################################

$table = "reviews";
$chkrev = "SELECT * from $table where pid = '$pid'";
$getrest = @mysql_query($chkrev,$conn)
	or die("SQL Command failed - unabled to extract reviews for this product!!!");

$number = mysql_num_rows($getrest);

# continue extract count of reviews for product

if ($number > 0)
{
	$list.="<tr><td><b>$number Reviews for this product</b></td><td><img src = ./images/search.gif><a href = javascript:newWindow('./see-review.php?$pid','acePopup',600,600,'scrollbars=yes')>View Reviews</a></td></tr>";
}
##### display shipping option #####

$table = "shipopts";
$sql = "SELECT * from $table where shipitem = '$category'";
$rs = @mysql_query($sql,$conn)
	or die("Could not execute SQL query!!! Possibly SQL query already been executed.");

$row=mysql_fetch_array($rs);
$shipitem=$row["shipitem"];
$shiprice = $row["shipitemprice"];
$shiprice = number_format($shiprice,2);

if ($shiprice > 0) # display shipping price if price > 0
{
	if ($wcurrency == "NO")
	$list.="<tr><td><br></td><td><br></td></tr><tr><td><font color=green>Shipping Price: $currency$shiprice</font></td><td><font color=green>Flat Shipping Rate:$currency$shiprates</font></td></tr><br>";
	else
	$list.="<tr><td><br></td><td><br></td></tr><tr><td><font color=green>Shipping Price: ($wcurrency)$shiprice</font></td><td><font color=darkgreen>Flat Shipping Rate:($wcurrency)$shiprates</font></td></tr><br>";
}
$list.="</table>";
echo($list);
?>

<?php

?>
</table></td>
<?php
echo"<br>";
?>
<?
if ($shipopt == "YES")
{
	echo "<p align=justify><font color = red face=verdana size=2>NOTE:</font><font color = navy face=verdana size=2> Shipping price is the price for you pay for shipping a single item. If you order multiples of a single item then you pay multiple of the shipping price. Flat shipping rate is amount you pay per delivery. Orders within the United Kingdom will be handled by Royal Mail through First Class Recorded Delivery. Larger bulky items will be sent as standard parcel. If you hosting your online store outside the United Kingdom then shipping be handled by your country's mailing company.</p>";
}
include ("./your-footer.inc");}
?>

</BODY>
</HTML>
