<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

header("Location:categorydetail.php");
exit;

/*if(!isset( $_SESSION["sess_userid"]) or $_SESSION["sess_userid"]!= ""){
	header("Location:login.php");
	exit;
}*/

if (isset($_GET["catid"]) and $_GET["catid"] != "") {
    $catid = $_GET["catid"];
} else if (isset($_POST["catid"]) and $_POST["catid"] != "") {
    $catid = $_POST["catid"];
}

if($_GET["begin"] == ""){
	$begin=0;
	$num=1;
	$numBegin=1;
}else{
	$begin=$_GET["begin"];
	$num=$_GET["num"];
	$numBegin=$_GET["numBegin"];;
}

if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!=""){
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!=""){
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}

$txtCategoryName = trim($_POST["txtCategoryName"]);
$txtProductName = $_POST["txtProductName"];
$txtDescription = $_POST["txtDescription"];
$txtPrice = $_POST["txtPrice"];
$ddlArtist =$_POST["ddlArtist"];
$productlist = $_POST["chkproducts"];


$artistlist = makeArtistList();



$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "artistname"){
            $qryopt .= "  AND  s.artist_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "dateadded"){
   		$dt = $txtSearch;
		$arrdt = explode("-",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  AND  p.date_added like '" . addslashes($dt) . "%'";
   }else if($cmbSearchType == "productname"){
            $qryopt .= "  AND  p.product_name like '" . addslashes($txtSearch) . "%'";
   }
}
$sql=" SELECT p.*, s.artist_name FROM ".$tableprefix."products p INNER JOIN ".$tableprefix."artists s ON p.product_artist_id = s.artist_id WHERE product_category = '".addslashes($catid)."' " . $qryopt . "   ORDER BY p.product_name  ";
$sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch."&catid=" . $catid;
$_SESSION["gbackurl"] = $sess_back;

$totalrows = mysql_num_rows(mysql_query($sql));

$navigate = pageBrowser($totalrows,10,9,"&cmbSearchType=$cmbSearchType&txtSearch=$txtSearch&catid=$catid",$_GET[numBegin],$_GET[start],$_GET[begin],$_GET[num]);
$sql = $sql.$navigate[0];
$rs = mysql_query($sql);
include "includes/htmltop.php";

/*display the active template*/

$active_template = displayTemplate();

?>
<script language="javascript" type="text/JavaScript"><!--
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}


function clickSearch()
{
	document.frmCatalog.submit();
}
function confirmDelete(){
	if(confirm('<?php echo CONFIRM_DELETE_RECORDS_TEXT;?>') ){
		return true;
	}
	return false;
}
//-->
</script>

<body topmargin="0">
<table width="804" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" >
			<table width="802" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td >
						<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
            				<tr>
              					<td>
									<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="maintext">
                  						<tr>
                    						<td>
												<form name="frmTop" method="post" action="#">
												<?php include "includes/".$active_template[0]; /* Top File Name */?> 
											</form>
												<table width="100%"  border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td valign="top" bgcolor="#FFFFFF">
															<?php
																include "includes/topmenu.php";
																include "includes/dotline.php";
																//include "includes/centermain.php";
															?>
																<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																<tr>

																	<td width="100%">
																		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																			<tr>
																				<td width="15%" valign="top">
																					<?php include "includes/categorylist.php";?>
																					<?php include "includes/newitemslist.php";?>
																				</td>
																				<td align="center" valign="top" >

																						<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																							<tr>
																								<td width="4%">&nbsp;</td>
																								<td width="93%">
																									<?php require("./includes/searchbar1.php"); ?>
																								</td>
																								<td width="3%">&nbsp;</td>
																							</tr>
																						</table>
																						<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																							<tr>
																								<td width="4%">&nbsp;</td>
																								<td width="93%">
																									<table width="100%"  border="0" cellspacing="0" cellpadding="5">
																										<tr>
																											<td  class="headingbig" align=left><?php echo CATALOG_LINK;?> </td>
																											<td width="4%">&nbsp;</td>
																										</tr>
																									</table>
																								</td>
																								<td width="3%">&nbsp;</td>
																							</tr>
																						</table>
																						<table width="100%">
																							<tr>
																								<td width="2%">&nbsp;</td>
																								<td>
																									<!-- ***************************************************** -->
																									<form name="frmCatalog" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" enctype="multipart/form-data">
																									<input type="hidden" name="catid" value="<?php echo htmlentities($catid);?>" >
																										<table cellpadding="2" cellspacing="2" width="95%"  align='left' border=0>
																											<tr><td colspan="3" class="message" align="left"><?php echo $message;?></td></tr>
																											<tr>
																												<td colspan="3">
																													<fieldset>
																														<legend  class='toplinksCopy'><?php echo CATEGORIES_TEXT;?></legend>
																														<table width="100%" border=0 align='left'>

																															<tr><td colspan="2" align='left' class="links" style='word-break:break-all;'><?php echo getCategoryLink("categorydetail.php",$catid )?></td></tr>
																															<tr><td colspan="2" align='left'>
																																<table width="100%"  border=0  align='left' cellpadding="2" cellspacing="2">
																																<?
																																if(!isset($catid) || $catid ==""){
																																	$catid = 0;
																																}
																																$showproducts=false;
																																$sql = "SELECT * FROM ".$tableprefix."categories WHERE parent_id = '".addslashes($catid)."' ORDER BY category_name ";
																																$result = mysql_query($sql) or die(mysql_error());
																																if(mysql_num_rows($result)!= 0){
																																		                while($row = mysql_fetch_array($result) ){
																																		                        echo "<tr>";
																																		                        echo "<td width='10%' align=right style='word-break:break-all;'><img src=images/dot.jpg></td><td width='40%' class=maintext align=left style='word-break:break-all;'><a href=\"".$PHP_SELF."?catid=" . $row["category_id"] . "&categorydesc=" . urlencode($row["category_name"]) . "\" class=\"links\">". $row["category_name"] ."</a>&nbsp;(" . $row["count"] . ")</td>";

																																		                        if($row = mysql_fetch_array($result)){
																																									echo "<td style='word-break:break-all;' width='10%' align=right><img src=images/dot.jpg></td><td width=40% class=maintext valign=middle  align=left style='word-break:break-all;'>";
																																		                           	echo "<a class=\"links\" href=\"".$PHP_SELF."?catid=" . $row["category_id"] . "&categorydesc=" .  urlencode($row["vCategoryDesc"])   . "\" >" . $row["category_name"] ."</a>&nbsp;(" . $row["count"] . ")";
																																									echo "&nbsp;</td>";
																																		                        }

																																		                        echo "</tr>";
																																		                }
																														        }else{
																														                 $showproducts=true;

																														        }




																																?>


																																</table>
																															</td></tr>

																														</table>
																													</fieldset>

																												</td>
																											</tr>
																											<tr><td colspan="3">&nbsp;</td></tr>
																										     <?php
																											   if($showproducts)
																											      require("./includes/productlist.php");
																											 ?>
																											<tr><td colspan="3">&nbsp;</td></tr>
																										</table>
																									</form>
																									<!-- ***************************************************** -->
																								</td>
																							</tr>
																						</table>
																				</td>
                                											</tr>
                           												</table>
                             										</td>
                              										<td style="width:1px" class="siteborder"><img src="./images/spacer.gif"></td>
                                  								</tr>
                     										</table>



																<?php
																include "includes/dotline.php";
																include "includes/bottommenu.php";
																include "includes/bottomband.php";
															?>
														</td>
                          							</tr>
                      							</table>
											</td>
                  						</tr>
									</table>
								</td>
 							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php
include "includes/".$active_template[2];
?>
</body>
</html>




