<?php
include ("./tests.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Shopping Menu</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>

<?php
/***************************************************************************
 *			shop_viewpage.php                                  *
 *                     	          				           *
 *   File Info:		  View products paging                             *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/
include ("./config.php");

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

## extract page number from string ##

if ($pos >= 0)
{
	$pages = substr($strvar,$pos+1);
	$page = $pages;
	
}

if ($pos >= 0 && $_SESSION["empty"] != NULL)
{
	include_once("./your-header.inc");
	echo "<br>";####### code to prevent display of emtpy product list! #######

	if (strlen($strvar) == 32)
	{
		echo "<br><br><center><img src=images/line.gif border=0 width=400><br><font face=verdana size=2>Please click the 'Store Home' icon to return to main page</font><br><img src=images/line.gif border=0 width=400></center><br><br><br><br>";
		include_once("./footer.inc");
		exit();
	}
}
if ($pos >= 0 && $_SESSION["empty"] == NULL) 
{
	$empty = "true";
	session_register('empty');
	$_SESSION['empty'] = $empty;
	include_once("./your-header.inc");


echo "<br><center><table width=550 border=1 cellspacing=0 cellpadding=0 height=150>
<tr><td width=550 bgcolor=#CCCCCC height=10>$header</td></tr>
<tr><td width=550 bgcolor=#FFFFFF height=140><br>";

################ display welcome info ##################

$filename = "./info/";
$filename.= "welcome.txt";

if (fopen($filename,"r") != NULL)
{
	$filename = "./info/welcome.txt";
	$file =fopen($filename,"r");
	$filesize = filesize($filename);
	$text = fread($file,$filesize);
	fclose($file);
	echo "<font color = #000000>$text</font>";
}
$sessid = session_id();
echo "</td></tr></table></center>";
include_once("./your-footer.inc");
@header("Refresh:shop_viewpages.php?PHPSESSID=$sessid");
exit();
} 
# code to get no. of products from database.


$table= "products";
$sel_item_totalprice = $sel_item_qty * $sel_item_price;
$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.");
$itemcount = "SELECT pid FROM $table";
$res = mysql_query($itemcount,$conn);
############## remove ################

echo "<center><table width=530 border=1 cellspacing=0 cellpadding=0 height=150>
<tr><td width=530 bgcolor=#CCCCCC height=10>$header</td></tr>
<tr><td width=530 bgcolor=#FFFFFF height=140>";
if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $page= addslashes($_POST["page"]);
	$limit = addslashes($_POST["limit"]);
	$pages = addslashes($_POST["pages"]);
	$page = $pages;
}	
echo "<br><center><img src=images/barcodes.gif border=0><font face=verdana size=3 color=navy>  Shopping Menu - View All Products By Pages</font>";	
	
?>
       
   
<br><br><center><a href=javascript:history.back()><img src=images/previous-page.gif border =0 height=18></a>
<?php
include("./config.php");
$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.");

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

// limit value for records to be shown
if ($limit == NULL)
	$limit = 10;

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

$query = "SELECT * from $table order by 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("<strong><font face=verdana size=2>Found $totalrows product(s)</b> </font></strong></center><br>");
echo "<br><center><font face = Verdana size = 2>Select number of records you wish to view per page:<br>Currently viewing  $limit records per page.";
$form = "<form action =shop_viewpages.php method = POST>";
$form.= "<select name = limit><option value = 10>10 records</option><option value = 20>20 records</option><option value = 25>25 records</option><option value = 50>50 records</option></select> ";
$form.= "<input type=hidden name=scats value='$scat'>";
$form.= "<input type=hidden name=pages value='$page'>";
$form.= "<input type=submit value = 'View Records'></form><br></center><center><font face=verdana size=1 color=#CCCCCC>.....................................................................................</font></center>";
echo $form;

$from = $limit*$page - $limit+1;
$to =$from+$count_result-1;
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"100%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"Showing item(s): $from to $to</tr><table> ";} 
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if ($numpages > 1)
echo "<tr><td width=\"100%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
if($page != 1){ 
$pageprev = $page - 1; 

if ($totalrows >= $limit && $numpages == 1)
echo "<tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
echo("<a href=\"$PHP_SELF?page=$pageprev\"><img src = ./images/back.gif  width = 20 height = 16 border = 0></a>&nbsp;"); 
} 

// 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=\".\shop_viewpages.php?page=$i\">$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?page=$pagenext\"><img src = ./images/next.gif width = 20 height = 16 border = 0></a>"); 
}
echo "</td><tr></table><br>";

# normal table style
if ($style == 1)
{
	$list = "<table border =\"1\" cellpadding =\"2\" align=center>";
	$list.="<tr ><th><font face=verdana size=2>Product ID</font></th>";
	$list.="<th><font face=verdana size=2>Product Item</font></th>";
	$list.="<th><font face=verdana size=2>Product Description</font></th>";
	$list.="<th><font face=verdana size=2>Price $currency</font></th>";
	$list.="<th><font face=verdana size=2>Shopping Link</font></th>";
	$list.="</tr>";
}
# secondary style
if ($style == 2)
{
	$list = "<TABLE id=\"AutoNumber1\" style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#cccccc\" 
height=\"85\" cellSpacing=\"0\" borderColorDark=\"#cccccc\" cellPadding=\"0\" width=\"500\" 
borderColorLight=\"#cccccc\" border=\"1\">
  <TBODY>
  <TR><TD width=\"14%\" bgColor=\"#cccccc\" height=\"19\"><FONT style=\"FONT-SIZE: 9pt\" 
      face=\"Arial\">&nbsp; <font face=verdana size=2>Image</font></FONT></TD>
    <TD width=\"40%\" bgColor=\"#cccccc\" height=\"19\"><FONT style=\"FONT-SIZE: 9pt\" 
      face=\"Arial\"><font face=verdana size=2>Product ID, Title, Description</font></FONT></TD>
    <TD width=\"16%\" bgColor=\"#cccccc\" height=\"19\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
face=\"Arial\"><font face=verdana size=2>Order</font></FONT></P></TD>
    <TD width=\"16%\" bgColor=\"#cccccc\" height=\"19\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
      face=\"Arial\"><font face=verdana size=2>Information</font></FONT></P></TD>
    <TD width=\"40%\" bgColor=\"#cccccc\" height=\"19\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
    face=\"Arial\"><font face=verdana size=2>Currency</font></FONT></P></TD></TR>
  <TR>";
}
while($row = mysql_fetch_array($result))
{
	$pid = $row["pid"];
	$pitem = $row["pitem"];
	$pdes = $row["pdes"];
	$prices = $row["price"]; 
	$price = number_format($prices,2); 

	
	################ code to display picture thumbnail ################

	$tables = "stocks";
	$sqlone = "SELECT * from $tables where pid = $pid";
	$resultx = @mysql_query($sqlone,$conn)
	or die("SQL command fail - ".mysql_error());
	$getrows = mysql_fetch_array($resultx);
	$picture = $getrows["spic"];

	if (@fopen($picture,"r") == NULL)
		$picture = "./images/nopic.jpg";	// set to no picture thumbnail

	#############################################################
	
	#style 1
	if ($style == 1)
	{
	$list.= "<tr>";
	$list.="<td>".$row["pid"]."</td>";
	$list.="<td>".$row["pitem"]."</td>";
	$list.="<td>".$row["pdes"]."</td>";
	$list.="<td>".$row["price"]."</td>";
	$list.="<td><li><a href=\"shop_showitem.php?pid=$pid\"><img src =./images/order.gif  width = 40 height = 24 border=0 alt=Order></a><em><font color = $highlight>($currency$price)</font></em></td>";
	$list.="</tr>";
	}
	#style 2
	if ($style == 2)
	{
		$list.="<tr><TD width=\"14%\" height=\"110\">
<IMG height=\"72\" src=\"$picture\" width=\"72\" border=\"0\">
      <P>&nbsp;</P></TD>";
		
		$list.="<TD bgcolor = #BBEEED vAlign=\"top\" width=\"40%\" height=\"136\"><FONT style=\"FONT-SIZE: 9pt\" 
      face=\"Arial\"><SPAN class=\"boldtext\">Product ID: $pid</SPAN><SPAN class=\"smalltext\">&nbsp;<FONT 
      color=\"#804040\"><B>Item:</B></FONT> $pitem&nbsp;</SPAN></FONT>
      <P><FONT style=\"FONT-SIZE: 9pt\" face=\"Arial\"><SPAN class=\"normaltext\"><SPAN 
      class=\"redtext\"><B>Description:</b> $pdes</SPAN></FONT></P></TD>";

              	$list.="<TD width=16% bgColor=#ffffff height=136><a href=./shop_showitem.php?pid=$pid><center><img src =./images/order.gif  width = 40 height = 24 border = 0 alt=Order></center></a></TD><TD width=11% bgColor=#e1eaf0 height=136>";

	if ($empty != NULL)
		$list.="<a href= javascript:newWindow('./image.php?$pid','acePopup',650,500,'scrollbars=yes')><center><img src =./images/moreinfo.gif width=40 height=24 border = 0 alt=Info></center></a></TD>";
		else
		$list.="<a href= ./images.php?$pid><center><img src =./images/moreinfo.gif width=40 height=24 border =0></center></a></TD>";	
            
                             if ($wcurrency == "NO")
		   $list.="<TD width=40% height=136><p align = center>Our Price $currency$price</p></TD></TR>";

                            if ($wcurrency == "ARS")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/argntina.gif> $price</p></TD></TR>";
  if ($wcurrency == "SGD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/singapor.gif> $price</p></TD></TR>";
		if ($wcurrency == "BRL")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/brazil.gif> $price</p></TD></TR>";
		
		if ($wcurrency == "BND")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/brunei.gif> $price</p></TD></TR>";

		if ($wcurrency == "CNY")
		$list.="<TD width=20% height=136><p align = center>Our Price <img src = ./images/china.gif> $price</p></TD></TR>";

		if ($wcurrency == "EGY")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/egypt.gif> $price</p></TD></TR>";

		if ($wcurrency == "HKD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/hngkng97.gif> $price</p></TD></TR>";

		if ($wcurrency == "INR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/india.gif> $price</p></TD></TR>";

		if ($wcurrency == "IDR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/indonsia.gif> $price</p></TD></TR>";

		if ($wcurrency == "KWD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/kuwait.gif> $price</p></TD></TR>";

		if ($wcurrency == "MYR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/malaysia.gif> $price</p></TD></TR>";

		if ($wcurrency == "NZD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/newzeal.gif> $price</p></TD></TR>";

		if ($wcurrency == "NOR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/norway.gif> $price</p></TD></TR>";

		if ($wcurrency == "PKR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/pakistan.gif> $price</p></TD></TR>";

		if ($wcurrency == "PHP")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/phillipn.gif> $price</p></TD></TR>";

		if ($wcurrency == "PLN")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/poland.gif> $price</p></TD></TR>";

		if ($wcurrency == "ROL")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/romania.gif> $price</p></TD></TR>";

		if ($wcurrency == "RUR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/russia.gif> $price</p></TD></TR>";

		if ($wcurrency == "SAR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/saudiar.gif> $price</p></TD></TR>";

		if ($wcurrency == "ZAR")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/safrica.gif> $price</p></TD></TR>";

		if ($wcurrency == "KRW")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/skorea.gif> $price</p></TD></TR>";

		if ($wcurrency == "SEK")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/sweden.gif> $price</p></TD></TR>";

		if ($wcurrency == "CHF")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/switzrld.gif> $price</p></TD></TR>";

		if ($wcurrency == "TWD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/taiwan.gif> $price</p></TD></TR>";

		if ($wcurrency == "THB")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/thailand.gif> $price</p></TD></TR>";
		if ($wcurrency == "VND")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/vietnam.gif> $price</p></TD></TR>";
		if ($wcurrency == "USD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/usa.gif> $price</p></TD></TR>";
	}
}
if ($style == 1)
{
$list.= "</table></table><br></table>";
echo "<table border=0 width=100% align = middle><tr align=center class=subtitle><td><a href=./shop_showall.php><img src =./images/our-prods.gif border=0 height=60></a></td><td><a href = ./shop_viewcart.php><img src =./images/carts.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>VIEW CART     </b></font></a></td><td><a href = ./shop_delcart.php><img src =./images/trashcan.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>EMPTY CART</b></font></a></td><td><a href = ./shop_updcart.php><img src = ./images/upd-cart.gif border=0 width=27 height=27><font face=arial size=1 color=#0F0F0F><b>UPDATE CART</b></font></a></td></tr></table>";
}
if ($style == 2)
{
$list.="<TR>
    <TD width=14% height=1></TD>
    <TD width=40% height=1></TD>
    <TD width=13% height=1></TD>
    <TD width=11% height=1></TD>
    <TD width=40% height=1></TD></TR></TBODY></table></table>";
$list.= "<br><center><p align = right><A href=.\shop_viewcart.php>View Shopping Basket</a><A href=.\shop_checkout.php><IMG src=./images/cart.gif width=42 height=50 border=0 alt=Cart></A></p></center>";
echo "<table border=0 width=100% align = middle><tr align=center class=subtitle><td><a href=./shop_showall.php><img src =./images/our-prods.gif border=0 height=60></a></td><td><a href = ./shop_viewcart.php><img src =./images/carts.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>VIEW CART     </b></font></a></td><td><a href = ./shop_delcart.php><img src =./images/trashcan.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>EMPTY CART</b></font></a></td><td><a href = ./shop_updcart.php><img src = ./images/upd-cart.gif border=0 width=27 height=27><font face=arial size=1 color=#0F0F0F><b>UPDATE CART</b></font></a></td></tr></table>";
$list.="</table>";
}
echo($list);
echo "<br>";
if ($style ==1)
$lists.= "<br><center><p align = right><A href=.\shop_viewcart.php>View Shopping Basket</a><A href=.\shop_checkout.php><IMG src=./images/cart.gif width=42 height=50 border=0 alt=Cart></A></p></center>";
echo $lists;
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if ($numpages > 1)
echo "<tr><td width=\"100%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
if($page != 1){ 
$pageprev = $page - 1; 

if ($totalrows >= $limit && $numpages == 1)
echo "<tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
echo("<a href=\"$PHP_SELF?page=$pageprev\"><img src = ./images/back.gif  width = 20 height = 16 border = 0></a>&nbsp;"); 
} 

// 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=\".\shop_viewpages.php?page=$i\">$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?page=$pagenext\"><img src = ./images/next.gif width = 20 height = 16 border = 0></a>"); 
}
echo "</td><tr></table><br>";
if ($totalrows > 0)
{
	
	$linenum = 11;
	$linenum = $linenum - $totalrows;
	for ($i = 0; $i < $linenum; $i++)
	{
		$spaces.= "<br>";
	}
	echo($spaces);

}
if ($pos > 0 && $empty != NULL)
{
	echo "<br><br>";
	if ($totalrows == 0)
	include_once("./your-footer.inc");
}
?>

</BODY>
</HTML>