<?php

/***************************************************************************
 *                              shop_showcat.php		           *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *	
 *   File Info:		  Show products by categories                      *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
 ***************************************************************************/

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


$str = getenv("QUERY_STRING");
if (strlen($str) > 0)
{
	$pos = strpos($str,'=');
	$poss = strpos($str,'&');
	$pos1 = strpos($str,'+');
	$page = substr($str,0,$pos);
	if ($pos1 >= 1)
	$scat = substr($str,$pos+1,$pos1-2);
	else
	$scat = substr($str,$pos+1);
	$scat = str_replace("%20"," ",$scat);
	if ($pos1 >=1)
	{
		$limit = substr($str,$pos1+$poss+2,strlen($str));
		
	}
}
$scat = str_replace("%20"," ",$scat);
 if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $scat = addslashes($_POST["scat"]);
        $scat = str_replace("%20"," ",$scat);
        $oldscat = $scat;
	$scats = addslashes($_POST["scats"]);
        $scats = str_replace("%20"," ",$scats);
    	$scat = $scats;
	$limit = addslashes($_POST["limit"]);
	$pages = addslashes($_POST["pages"]);
	$page = $pages;
	
}

include ("./config.php");
include ("./tests.php");

session_start();
if ($pos == 0 && $poss > 0 && $_SESSION["empty"]== NULL)
{
	include_once("./your-header.inc");
	if ($noshow == "YES")
	{
	echo "<br><table width=450 border=1 cellspacing=0 cellpadding=0 height=150>
<tr><td width=450 bgcolor=#CCCCCC height=10>$header</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 ($usecat == "YES")
		$scat = str_replace('%20',' ',$scat);

$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");
$table = "stocks";
$sql_count1 = "SELECT * FROM $table 
	WHERE scat = '$scat'";
$sql_result1 = mysql_query($sql_count1,$conn) 
	or die ("SQL command failed - Couldn't find records count!");
$totalrows = mysql_num_rows($sql_result1);

if ($limit == NULL)
	$limit = 5;


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

$sql_count1 = "SELECT * FROM $table where scat = '$scat' LIMIT $limitv,$limit";
$sql_result = mysql_query($sql_count1,$conn) 
	or die ("Couldn't get records!");
$count_result = mysql_num_rows($sql_result);

$numpages = ceil($totalrows / $limit);
echo "<br><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 ($style == 1)
echo("<center><strong><br><img src = images/view-by-cat.gif border=0 height=32><br><font face =verdana color = #666666 size=2><b>Found $totalrows product(s)   </b> </font></strong></center>");
if ($style == 2)
echo("<center><strong><br><img src=images/view-by-cat.gif border=0 height=32><br><font face =verdana color = #666666 size=2><b>Found $totalrows product(s)   </b></font></strong><img src =./images/folder.gif><a href=./store.php><b> Store Home</b></a></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_showcat.php method = POST>";
$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=hidden name=scats value='$scat'>";
$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;
if ($numpages == 1)
echo "<center><font face=verdana size=1>Showing item(s): $from to $to</font></center>";
if ($totalrows > $limit)
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages > 1){echo"Showing item(s): $from to $to</td></table> "; }  
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if ($totalrows >= $limit && $numpages > 1)
echo "<br><tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev=$scat+?$limit\"><img src = ./images/back.gif height=16 width=20 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_showcat.php?$i=$scat+?$limit\">$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=$scat+?$limit\"><img src = ./images/next.gif height=16 width=20 border=0></a>"); 
}
echo "</td><tr></table><br>";

#style 1
if ($style == 1)
{
	$list = "<table border =\"1\" cellpadding =\"2\" align=center bgcolor=$backcolor1>";
	$list.="<tr ><th>Stock ID</th>";
	$list.="<th>Stock Item</th>";
	$list.="<th>Category</th>";
	$list.="<th>Stock</th>";
	$list.="<th>Color</th>";
	$list.="<th>Size</th>";
	$list.="<th>Shopping Link</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=\"100%\" 
borderColorLight=\"#cccccc\" border=\"1\">
  <TBODY>
  <TR><TD width=\"14%\" bgColor=\"#cccccc\" height=\"30\"><FONT style=\"FONT-SIZE: 9pt\" 
      face=\"Arial\">&nbsp; Image</FONT></TD>
    <TD width=\"50%\" bgColor=\"#cccccc\" height=\"30\"><FONT style=\"FONT-SIZE: 9pt\" 
      face=\"Arial\">Stock ID, Title, Category, Stock, Color, Size</FONT></TD>
    <TD width=\"13%\" bgColor=\"#cccccc\" height=\"30\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
face=\"Arial\">Order</FONT></P></TD>
    <TD width=\"11%\" bgColor=\"#cccccc\" height=\"30\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
      face=\"Arial\">Information</FONT></P></TD>
    <TD width=\"40%\" bgColor=\"#cccccc\" height=\"30\">
      <P align=\"center\"><FONT style=\"FONT-SIZE: 9pt\"
    face=\"Arial\">Currency  </FONT></P></TD></TR>
  <TR>";
}
$nrow=mysql_num_rows($sql_result);
if ($nrow == 0)
{
	if ($usecat == "YES")
		include_once("./sidebars.php");
	else
		include_once("./sidebar.php");
}
$category = $scat;
if ($nrow == "0")
{
	$list.="</table><br>";
	$cat = "BAD";
}
else
{
while($row = mysql_fetch_array($sql_result))
{
	$pid = $row["pid"];
	$sitem = $row["sitem"];
	$scat = $row["scat"];
	$spic= $row["spic"];
	$stock = $row["stock"];
	$color = $row["color"];
	$size = $row["size"];

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

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

	$tables = "products";
	$sqlone = "SELECT * from $tables where pid = $pid";
	$resultx = @mysql_query($sqlone,$conn)
	or die("SQL command fail - ".mysql_error());
	$getrows = mysql_fetch_array($resultx);
	$prices = $getrows["price"]; 
	$price = number_format($prices,2); 


	#############################################################

	#style 1
	if ($style == 1)
	{
	$list.= "<tr>";
	$list.="<td>".$row["pid"]."</td>";
	$list.="<td>".$row["sitem"]."</td>";
	$list.="<td>".$row["scat"]."</td>";
	$list.="<td>".$row["stock"]."</td>";
	$list.="<td>".$row["color"]."</td>";
	$list.="<td>".$row["size"]."</td>";
	$list.="<td><li><a href=\"shop_showitem.php?pid=$pid\">$sitem</a></td>";
	$list.="</tr>";
	}
	
	if ($style == 2)
	{
		$list.="<TD width=\"14%\" height=\"110\">
<IMG height=\"72\" src=\"$spic\" 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\">Stock ID: $pid</SPAN><SPAN class=\"smalltext\">&nbsp;<FONT 
      color=\"#804040\"><B>Item:</B></FONT> $sitem&nbsp;</SPAN></FONT>
      <P><FONT style=\"FONT-SIZE: 9pt\" face=\"Arial\"><SPAN class=\"normaltext\"><SPAN 
      class=\"redtext\">&nbsp;<B>Category:</b> $scat</SPAN><SPAN 
      class=\"redtext\">&nbsp;<B>Stock:</b> $stock</SPAN><SPAN 
      class=\"redtext\">&nbsp;<B>Color:</b> $color</SPAN><SPAN 
      class=\"redtext\">&nbsp;<B>Size:</b> $size</SPAN>
</FONT></P></TD>";

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

	if ($admin != 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 alt=Info></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 == "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 == "SGD")
		$list.="<TD width=40% height=136><p align = center>Our Price <img src = ./images/singapor.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) #style 1
$list.="</table><br>";
if ($style == 2) #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>";
}
}

?>
<?php 
if ($nrow > 0)
echo($list); 
?>

<?php 
if ($nrow > 0)
if ($style == 1)
echo"<br><center><table width=60% cellpadding=0 cellspacing=0 border=0 bgcolor=FFFFFF align = middle><tr><td valign=top>
<table width=100% cellpadding=1 cellspacing=3 border=0 align = middle>
<tr bgcolor=ffffff><td>
&nbsp;<font face=Verdana size=-1><b><a href=./shop_showall.php>Product List</a></b><img src = ./images/home.gif><br><small>&nbsp;</small></font>
<td>&nbsp;<font face=Verdana size=-1><b><a href=./shop_delcart.php>Empty Cart</a></b><img src = ./images/trashicon.gif><br><small>&nbsp;</small></font></td>
<td>&nbsp;<font face=arial size=-1><b><a href=./shop_viewcart.php>View Cart</a></b><img src = ./images/shoppingcart.gif width=18 height = 18><br><small>&nbsp;</small></font></td>
</table></td></tr></table></center><br>";
echo "<table align=\"center\" width=\"65%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if ($totalrows >= $limit && $numpages > 1)
echo "<br><tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page: </b>";
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev=$scat+?$limit\"><img src = ./images/back.gif height=16 width=20 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_showcat.php?$i=$scat+?$limit\">$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=$scat+?$limit\"><img src = ./images/next.gif height=16 width=20 border=0></a>"); 
}
echo "</td><tr></table><br>";
if ($totalrows >= 1)
echo "<strong><font size = 2 color =000000 face=verdana><center>Found $nrow records for category: '$scat'</center></strong></font><hr width=380>";
echo "<center><a href=javascript:history.back()><img src=images/previous-1.gif border = 0 height=20></a></font></center></td></tr></table><br>";
if ($totalrows == 1)
echo "<br><br><br>"; }?>
</body>
</html>