<?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);
}

$currency_attributes = displayCurrencyType();
// setting pagination limit From Admin settings

$limit=getPaginationLimit();

if($limit==0)
{
	$limit=10;
}	


$page=$_GET['page'];

if(empty($page))
	{
		$page = 1;
	}

//End pagination settings


/*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(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"];
}


$giftCategoryFlag=CheckGiftCertificateCategory($catid);

if(!isset($catid) && $catid =="" && $txtSearch=="")
			{
				$showproductlisting="false";
				
			}
			if((isset($catid) && $catid!="")  ||  $txtSearch!="" || $giftCategoryFlag=='Y')
			{
				$showproductlisting="true";
			}

/*display the active template*/

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/".$active_template[0]);

// Check Category is a Gift Certificate Category 


?>
<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("Are you sure you want to delete the selected records?") ){
		return true;
	}
	return false;
}
//-->
</script>

				<div align="left" class="main_body">
							<!--mainbody area start -->
			
						<div align="left" id="body_left_area">
							<!--body left area start -->
							
							<!--categories area start -->
			
			<?php
			$limit=getPaginationLimit();

				if($limit==0)
				{
					$limit=12;
				}	
			$sql_category = " SELECT * FROM ".$tableprefix."categories WHERE parent_id LIKE ".GetSQLValueString($catid,"text")." ORDER BY category_name ";	
			
			$sql_qr=dopaging($sql_category,'',$limit);	
			
			$totalrows=mysql_num_rows(mysql_query($sql_category));
			
			$result_category = mysql_query($sql_qr) or die(mysql_error());

			?>			
			
			<!--categories area end -->	
			
			<!--body left area end -->
						</div>
 
		   <!--center content area start-->		

		 <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);?>" >
		 <div align="left" id="item_details">
	
               <!--items display area start -->

	              <div align="left" id="items_top_area">
	                         <div align="left" id="items_top_area_ttl">
							
							<div style="font-size:13px;"> Categories
               							<?php  echo stripslashes(getCategoryLinkNew("categorydetail.php",GetSQLValueString($catid,"text")));?>
			  				</div>
			   
                    </div>
			                      
           </div>
		
	       <div class="text_information" align="center"><?php echo $message?></div>		
		
		 <?php	
   
			if(!isset($catid) || $catid =="")
			{
				$catid = 0;
			}
	        	$showproducts = false;
			if(mysql_num_rows($result_category) > 0 )
			{
				$rowcnt1=0;
	?>
	<div class="category_listings">
				<div align="left" id="category_list" >
				
				<table width="100%"  border="0" cellspacing="1" cellpadding="5">
						 <tr>
<?php 						
			while($row_category = mysql_fetch_array($result_category))
		    {
			
				 if($rowcnt1%2=='0')
			   {
			   		$rowcnt1='0';
					echo '</tr><tr>';
			   }//end if
			   
			   if(strlen($row_category["category_name"])>15)
									 	 $category_name = substr($row_category["category_name"],0,15)."...";
									else
									  	 $category_name = $row_category["category_name"];
									   
									     //echo  "<a href=".$PHP_SELF."?catid=".$row_category["category_id"]."&page=".$page.">".$category_name."(" . $row_category["count"] . ")</a>";
									
			?>																										
					
					<td align="left" width="50%">&nbsp;&nbsp;<a href="categorydetail.php?catid=<?php echo htmlentities($row_category["category_id"])?>"><?php echo stripslashes($category_name);?></a>&nbsp;(<?php echo htmlentities($row_category["count"]);?>)</td>
<?php
				$rowcnt1++;
			}//end while
			
	?>
	
			 </tr>
		</table>
				</div>
				<div class="clear"></div>
				</div>
<?php 						
	 }//end if
		else
		{
			$showproducts = true;

		}
		
?>

<?php if($totalrows>$limit)
{?>
<div  class="pagination"> <?php echo rightpaging();?></div>
<?php  } ?>

<?php 		
		if($showproducts)
		{
			
?>					
<div class="category_searchdiv">
<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td align="right">
					<label>Search</label>
						<select name="cmbSearchType" class="textarea">
							<option value="productname"  <?php if($cmbSearchType == "productname" || $cmbSearchType == ""){ echo("selected"); } ?>>Product Name</option>
							<option value="artistname"  <?php if($cmbSearchType == "artistname"){ echo("selected"); } ?>>Seller Name</option>
							<option value="dateadded"  <?php if($cmbSearchType == "dateadded"){ echo("selected"); } ?>>Date Added (mm-dd-YYYY)</option>
						</select> &nbsp;<input type="text" name="txtSearch"  class="textarea"/>

					  <input name="Submit" type="submit" class="button" value="GO "/>
					  </td>
		  </tr>
					  <tr><td>&nbsp;</td></tr>
					  <?php
					  
					   if($_GET['catid']=='' && $txtSearch=='')
					        {
					  ?>
					  <tr><td align="center">					  <?php include_once("includes/categorylist_catalog.php");?>
					  </td>
					  </tr>
					  <?php 
					  
					  }//end if
					?>
			            </td>
				</tr>
					    		
						</table>
						</div>
							
				
		
		
<?php
 
 if($showproductlisting=="true")
 
 { // display products
 		
	include_once("includes/productlist.php");
	
 } 

} // end if show products
?>

	
		<div align="left" class="float_clear1"></div>
			

		</div>
								
	<!--items display area end -->
	</form>
	<!--center content area end-->		
		<!--mainbody area end -->
        </div>
<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>																		