<?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
/*currency section starts*/

	//print_r($_SESSION);

		//session_register('SESS_currency_type');

		$currency_selected = "";
		
		//(isset($_SESSION['SESS_currency_type']))?session_unregister('SESS_currency_type'):session_register('SESS_currency_type');;
										
		if(isset($_POST['currency_type']))
		{
		
			//activateCurrencyType($_POST['currency_type']);
			$currency_type = $_POST['currency_type'];
			
			$_SESSION['SESS_currency_type'] = $currency_type;
					
			echo "<script type='text/javascript'> window.location='".$_SERVER['HTTP_REFERER']."';</script>";
	
		}
		else
		{
						
			if (!isset($_SESSION['SESS_currency_type']) OR $_SESSION['SESS_currency_type'] == "")
			{
				
				/*$_SESSION['SESS_currency_type']	= "1";
				$currency_type					= "1";*/
				/*$select_currency_id = "SELECT ncurrency_id FROM ".$tableprefix."currency_master WHERE vactive = 'Y'";
				$result_currency_id = mysql_query($select_currency_id) or die(mysql_error());
				$currency_rowid = mysql_fetch_assoc($result_currency_id);
				$_SESSION['SESS_currency_type']	= $currency_rowid['ncurrency_id'];
				$currency_type = $currency_rowid['ncurrency_id'];*/
				
				$select_currency_id = "SELECT ncurrency_id,vcurrency_code FROM ".$tableprefix."currency_master WHERE vactive = 'Y'";
				$result_currency_id = mysql_query($select_currency_id) or die(mysql_error());
				$currency_rowid = mysql_fetch_assoc($result_currency_id);
				$_SESSION['SESS_currency_type']	= $currency_rowid['vcurrency_code'];
				$currency_type = $currency_rowid['vcurrency_code'];
				
			}
			/*$select_currency_id = "SELECT ncurrency_id FROM ".$tableprefix."currency_master WHERE vactive = 'Y'";
			$result_currency_id = mysql_query($select_currency_id) or die(mysql_error());
			$currency_rowid = mysql_fetch_assoc($result_currency_id);
		
			$currency_type = $currency_rowid['ncurrency_id'];*/
		}
		
		
		/*currency section ends*/
		
?>


<!-- categories-->


				<div id="categories">
				<!--categories area start -->
				
						<div id="category_list" class="rmm">
						<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' ";
                if(getSettingsValue('product_listing_fee') > 0){ 
                                 $sql_product_categories .= " AND p.payment_status='COMPLETED' ";
                            }                        
                $sql_product_categories .= " AND  p.deleted ='N'  ";
                
               // echo $sql_product_categories;
    $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);
	}
	
	
	
 $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();
$categoryCnt = 1;//mysql_num_rows($resultcategories);
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'];
		}	
	 }
	 
         
         //print_r($current_catlist);
         
	 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."product_options po ON po.product_id = p.product_id AND po.default_option = 'YES'
	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' ";
                if(getSettingsValue('product_listing_fee') > 0){ 
                                 $sql .= " AND p.payment_status='COMPLETED' ";
                            }                        
                $sql .= " AND  p.deleted ='N' ";
    $result22 = mysql_query($sql);
	//echo $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 count
                                              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 p.deleted='N' AND s.vapproved='Y' AND s.is_vacation_mode = 'N' 
                                              AND gm.vgift_delete_status = 'N'  ";
                            if(getSettingsValue('product_listing_fee') > 0){ 
                                 $product_count_sql .= " AND p.payment_status='COMPLETED' ";
                            }                        
                
                                         
			  
				//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->count;
                   }
               }
			   
			    }
               
		if(strlen($rowcategories["category_name"])>30)
			  $category_name=substr($rowcategories["category_name"],0,30)."...";
			else
			   $category_name =$rowcategories["category_name"];

?>	<?php if($categoryCnt<=4) {
        if (strstr($_SERVER['SCRIPT_FILENAME'], 'categorydetail.php') == TRUE && $_GET['catid']== $rowcategories["category_id"]) {
            $link_selected_index = "category_act";              
            }else{$link_selected_index = ""; }
        ?>				
	<li class="<?php echo $link_selected_index;?>"><a href="<?php echo SITE_URL?>/categorydetail.php?catid=<?php echo htmlentities($rowcategories["category_id"])?>" title="<?php echo (stripslashes($rowcategories["category_name"]));?>"><?php echo (($category_name));?></a></li>
	<?php }else{
            if (strstr($_SERVER['SCRIPT_FILENAME'], 'categorydetail.php') == TRUE && $_GET['catid']== NULL) {
            $link_selected_index = "category_act";              
            }else{$link_selected_index = ""; }
            ?>        
	<li class="<?php echo $link_selected_index;?>"><a href="<?php echo SITE_URL?>/categorydetail.php" title="Category List"><?php echo MORELINK;?></a></li>	
	<?php break; } ?>
<?php $categoryCnt++;
	}
}
?>
            <?php 
            if (strstr($_SERVER['SCRIPT_FILENAME'], 'index.php') == TRUE && $_GET['featured']== "N") {
            $link_selected_index = "category_act";              
            }else{$link_selected_index = ""; }
            ?>
        <li class="<?php echo $link_selected_index;?>">          
			<a class="newproduct_link" href="<?php echo SITE_URL ?>/index.php?featured=N"><?php echo NEW_PRODUCTS_TEXT; ?></a>
	</li>

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

				
				
				
