<?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.                                                       |
// +----------------------------------------------------------------------+
?>
<!-- categories-->


				<div align="left" id="categories">
				<!--categories area start -->
				
						<div align="center" style="width:193; height:24;" class="subheading"><?php echo CATEGORY_CAPTION_TEXT;?></div>
						<div align="left" id="category_list">
						<ul>
<?php

 $sql_product_categories="SELECT DISTINCT p.product_category,cat.route
							FROM ".$tableprefix."products p
							INNER JOIN ".$tableprefix."categories cat ON cat.category_id =p.product_category 
							INNER JOIN ".$tableprefix."artists ar ON ar.artist_id =p.product_artist_id 
							WHERE ar.vapproved ='Y' AND ar.deleted='N' AND ar.plan_expired='N'
							AND p.vapproved = 'Y' AND p.product_artist_id='".$artistid."' AND p.publish_status='Y' AND p.seller_vacation_mode='N'
							AND  p.deleted ='N'  ";
    $rs_product_categories	= mysql_query($sql_product_categories) or die(mysql_error());
	
	if(mysql_num_rows($rs_product_categories)>0)
	{
			while($productObj	= mysql_fetch_object($rs_product_categories))
			{
				
				if($productObj->route!='')
				{
				 	$exp_category			= explode(",",$productObj->route);
					
					$primary_category		= $exp_category[0];
				}	
				else
				{
					 $primary_category		= $productObj->product_category;
				}
				 
				 $productcategories[]	= $primary_category;
			}
	
				
	}
	
	if(count($productcategories)>0)
	{
		$current_product_categories=@implode("','",$productcategories);
	}
	
$sellerCategories = array();

 $sql=" SELECT c.category_id,c.category_name,c.gift_certificate_flag,c.count FROM ".$tableprefix."categories c  
 		WHERE c.category_id IN ('".$current_product_categories."') AND c.parent_id='0' ORDER BY c.category_name ";
 $resultcategories=mysql_query($sql) or die(mysql_error());
 
 $parentCat[]	=array();
  
if(mysql_num_rows($resultcategories) > 0 )
{
	while($rowcategories = mysql_fetch_array($resultcategories))
	{
	
	 $sql_route="SELECT route,category_id from ".$tableprefix."categories cat  where cat.route REGEXP '^".$rowcategories['category_id'].",|,^".$rowcategories['category_id']."|,".$rowcategories['category_id'].",|,".$rowcategories['category_id']."$|^".$rowcategories['category_id']."$'  ";
	 $rs_route=mysql_query($sql_route) or die(mysql_error());
	
	$current_catlist=array(); 
	 if(mysql_num_rows($rs_route)>0)
	 {
	 	while($List_cat=mysql_fetch_array($rs_route))
		{
	 		$current_catlist[]=$List_cat['category_id'];
		}	
	 }
	 
	 if(count($current_catlist)>0)
	 {
			 $categoryString=@implode("','",$current_catlist);
	 }	
	 else
	 {
		$categoryString=$current_catlist;
	 }
	$count_product = 0;
	
	$sql="SELECT count(*) AS pcount
	FROM ".$tableprefix."products p
	INNER JOIN ".$tableprefix."categories cat ON  p.product_category=cat.category_id
	INNER JOIN ".$tableprefix."artists ar ON ar.artist_id =p.product_artist_id 
	WHERE ar.vapproved ='Y' AND ar.deleted='N' AND ar.plan_expired='N'
	AND p.product_category IN  ('".$categoryString."')
	AND p.vapproved = 'Y'
	AND  p.deleted !='Y'  AND p.publish_status='Y' AND p.seller_vacation_mode='N'  AND ar.artist_id='".$artistid."' ";
    $result22 = mysql_query($sql);
	
	 if (mysql_num_rows($result22) != 0) 
	 {
            $rw = mysql_fetch_array($result22);
            $count_product =$rw['pcount'];
        }
		
			   
			   if($rowcategories["gift_certificate_flag"]=="Y")
			   {
			 		 $product_count_sql = "SELECT COUNT(p.product_id) AS gcount
                                              FROM ".$tableprefix."products p JOIN ".$tableprefix."artists s on p.product_artist_id=s.artist_id 
											  INNER JOIN ".$tableprefix."giftcoupon_master gm oN gm.ngift_product_id=p.product_id 
                                              AND p.product_category IN (".$rowcategories['category_id'].")
                                              AND p.vapproved = 'Y' AND s.is_vacation_mode = 'N' AND s.vapproved='Y' AND gm.vgift_delete_status = 'N' AND s.artist_id='".$artistid."' "; 
			  
				//echo $product_count_sql;
               $product_count_reslt = mysql_query($product_count_sql)or die(mysql_error());
               if(mysql_num_rows($product_count_reslt) > 0)
               {
                   $count_product = 0;
                   while($product_counts = mysql_fetch_object($product_count_reslt))
                   {
                       $count_product = $product_counts->gcount;
                   }
               }
			   
			    }
               
			if(strlen($rowcategories["category_name"])>20)
				  $category_name=substr($rowcategories["category_name"],0,20)."...";
				else
				   $category_name =$rowcategories["category_name"];
				   
									$portfolio_link= SITE_URL."/showportfolio.php?artistid=".$artistid."&catid=".$rowcategories["category_id"];
							 
		?>

	<li><a href="<?php echo $portfolio_link;?>" title="<?php echo (stripslashes($rowcategories["category_name"]));?>"><?php echo (stripslashes($category_name));?></a>&nbsp;(<?php echo htmlentities($count_product);?>)</li>
<?php
	}
}


?>
				</ul>
				</div>
<!--categories area end -->
				</div>

				
				
				
