<?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.                                                       |
// +----------------------------------------------------------------------+
?>
<script  type="text/javascript">
  $(document).ready(function(){
       $('.prod_green').click(function(){
         /*var pid=$(this).attr('id');           
         window.location = "<?php echo SITE_URL ?>/productdetails.php?productid="+pid;*/
         var OptimizedUrl=$(this).attr('data');          
         window.location = OptimizedUrl;
        });
  })
</script>
<?php
$currency_attributes = displayCurrencyType();
/*----------Multicart 2.0 Upgradation Starts------------*/


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

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

	if($enable_seller_friendly == "Y")
{
	 $select_artist_id = "SELECT artist_id,artist_name,is_vacation_mode FROM ".$tableprefix."artists WHERE artist_name = ".GetSQLValueString($artistid,"text");

	$result_artist_id = mysql_query($select_artist_id) or die(mysql_error());

	if(mysql_num_rows($result_artist_id) > 0)
	{

		$artist_row = mysql_fetch_assoc($result_artist_id);
		$artistid = $artist_row['artist_id'];
		$artist_name = $artist_row['artist_name'];
               
	}
}

else
{

	 $select_artist_id = "SELECT artist_id,artist_name,is_vacation_mode FROM ".$tableprefix."artists WHERE artist_id = ".GetSQLValueString($artistid,"text");

	$result_artist_id = mysql_query($select_artist_id) or die(mysql_error());

	if(mysql_num_rows($result_artist_id) > 0)
	{

		$artist_row = mysql_fetch_assoc($result_artist_id);
		$artistid = $artist_row['artist_id'];
		$artist_name = $artist_row['artist_name'];
               

	}

}




	if($catid!='')
	{

				 $sql_seller_route_cat="SELECT route,category_id from ".$tableprefix."categories cat  where cat.route REGEXP '^".$catid.",|,^".$rowcategories['category_id']."|,".$catid.",|,".$catid."$|^".$catid."$'  ";
				 $rs_seller_route_cat=mysql_query($sql_seller_route_cat) or die(mysql_error());

				 if(mysql_num_rows($rs_seller_route_cat)>0)
				 {
						while($rows_seller_categores=mysql_fetch_array($rs_seller_route_cat))
						{

							$seller_products_category[]=$rows_seller_categores['category_id'];

						}
				 }


				 if(count($seller_products_category)>0)
				 {
						 $seller_products_category_list	= @implode("','",$seller_products_category);

					     $current_product_category		= @end($seller_products_category);
				 }


	 }
// show the friendly url  based on config settings
if($enable_seller_friendly == "Y")
{
        // if (function_exists('session_unregister'))
	  //(isset($_SESSION['SESS_seller_name']))?session_unregister('SESS_seller_name'):session_register('SESS_seller_name');
	$_SESSION['SESS_seller_name'] = $artist_name;
}
/*----------Multicart 2.0 Upgradation Ends------------*/
	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"];
	}
	$cmbSearchType==($_GET["cmbSearchType"] != "")?$_GET["cmbSearchType"]:$_POST["cmbSearchType"];
	$qryopt="";
	if(($catid!=''))
	{
		$qryopt .= " AND p.product_category IN  ('".$seller_products_category_list."') ";
	}
	if($txtSearch != ""){
	  $qryopt = "  AND  (p.product_name like '%" . addslashes($txtSearch) . "%' || p.product_description like '%" . addslashes($txtSearch) . "%') ";
	}
        $productListingFee = getSettingsValue('product_listing_fee');

        $whereCondition =   '';
        
	if(CheckGiftCertificateCategory($_GET['catid'])=='Y')
	{
		$sql    =   "SELECT p.*, (p.product_price + p.default_additional_price) AS product_price FROM " . $tableprefix . "products p
                 INNER JOIN ".$tableprefix."giftcoupon_master gm oN gm.ngift_product_id=p.product_id
                 LEFT JOIN ".$tableprefix."record_ratings r ON p.product_id = r.nrseller_id  where p.vapproved = 'Y' ";
                
                // Getting total rows count without limit
                $sql_total_rows   =   "SELECT count(p.product_id) as cnt FROM " . $tableprefix . "products p
                                        INNER JOIN ".$tableprefix."giftcoupon_master gm oN gm.ngift_product_id=p.product_id
                                        LEFT JOIN ".$tableprefix."record_ratings r ON p.product_id = r.nrseller_id  where p.vapproved = 'Y' ";

                $whereCondition.=" AND p.deleted='N' ";  // check deleted status
                $whereCondition.=" AND p.publish_status='Y' ";  // check published status
                $whereCondition.=" AND p.seller_vacation_mode='N' ";  // check seller vacation ode settings
                $whereCondition.=" AND p.vSellerStatus='Y' ";  // check seller approved or plan expiry status
                $whereCondition.=" AND p.product_artist_id='".$artistid."' ";
            
	}
	else
	{
                 $sql    =   "SELECT p.*, (p.product_price + p.default_additional_price) AS product_price FROM " . $tableprefix . "products p
                    LEFT JOIN ".$tableprefix."record_ratings r ON p.product_id = r.nrseller_id
                    where p.vapproved = 'Y' ";
                
                 $sql_total_rows   = "SELECT count(p.product_id) as cnt FROM " . $tableprefix . "products p
                                      LEFT JOIN ".$tableprefix."record_ratings r ON p.product_id = r.nrseller_id
                                      where p.vapproved = 'Y' ";
                 
                 $whereCondition.=" AND p.deleted='N' ";  // check deleted status
                $whereCondition.=" AND p.publish_status='Y' ";  // check published status
                $whereCondition.=" AND p.seller_vacation_mode='N' ";  // check seller vacation ode settings
                $whereCondition.=" AND p.vSellerStatus='Y' ";  // check seller approved or plan expiry status
                $whereCondition.=" AND p.product_artist_id='".$artistid."' ";
                if ($productListingFee > 0) {
                        $whereCondition .= " AND p.payment_status='COMPLETED' ";  // Check seller payment completed
                    }
        }
            if(isset($_REQUEST['sel_order_by']))
            {
            	//die("Here I'm");
            	if($_REQUEST['sel_order_by']=="rating desc"){
            		$order = "GROUP BY p.product_id ORDER BY AVG(r.nrating_id) DESC ";
            	}
            	else if($_REQUEST['sel_order_by']=="vendor desc"){
            		$order = "GROUP BY p.product_id ORDER BY p.product_artist_id DESC ";
            	}
            	else if($_REQUEST['sel_order_by']=="vendor asc"){
            		$order = "GROUP BY p.product_id ORDER BY p.product_artist_id ";
            	}
            	else if($_REQUEST['sel_order_by']=="price desc"){
            		$order = "GROUP BY p.product_id ORDER BY product_price DESC ";
            	}
            	else if($_REQUEST['sel_order_by']=="price asc"){
            		$order = "GROUP BY p.product_id ORDER BY product_price ";
            	}
            	else {
            		$order = "GROUP BY p.product_id  ORDER BY p.product_name ";
            	}
            }
            else {
            	$order = "GROUP BY p.product_id  ORDER BY p.product_id DESC ";
            }

            //$order = '';

           $sql             =   $sql .$whereCondition . $order ;
           $sql_total_rows  =   $sql_total_rows.$whereCondition;
           
           

	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	}
	//$result=mysql_query($sql) or die(mysql_error());
	//$totalrows = mysql_num_rows($result);
        $totalrows = mysql_result(mysql_query($sql_total_rows),0,'cnt');
        
       
        if($txtNumCols>0 && $txtNumRows>0)
            {
                $limit = $txtNumCols*$txtNumRows;
            }
        else
            {
                $limit=getPaginationLimit();
        }
	//$limit=getPaginationLimit();
	if($limit==0)
	{
		$limit=12;
	}
	$sql_qr=dopaging($sql,'',$limit);

	$result=mysql_query($sql_qr) or die(mysql_error());

	$prodimagedir = "products/";
?>
<form name="frmCatalog" action="<?php echo SITE_URL?>/showportfolio.php?artistid=<?php echo $artistid?>" method="POST" enctype="multipart/form-data">
			<div align="left" class="prdct_search_container">
				<input type="hidden" name="catid" value="<?php echo $catid;?>">
					<div class="sellerhd">
						<div class="col-sm-12 col-lg-6 col-md-6">
							<h3 id="items_top_area_ttl_3"><?php echo PRODUCTS_TEXT;?></h3>
						</div>
						<div class="col-sm-12 col-lg-6 col-md-6">
							<div class="top_sortlist">
								<span align="right" id="items_top_area_ttl_4" class="f_right_marg"><?php echo SORT_BY_TEXT;?></span>
								 &nbsp;<select onchange="clickSearch()" class="topsearch_fld f_right_marg" name="sel_order_by" id="sel_order_by">
								<option value=""><?php echo SELECT_ORDER_TEXT;?></option>
								<option value="price asc" <?php if($_REQUEST['sel_order_by']=="price asc"){ echo "selected";}?>><?php echo PRICE_ORDER_LOW_HIGH_TEXT;?></option>
								<option value="price desc" <?php if($_REQUEST['sel_order_by']=="price desc"){ echo "selected";}?>><?php echo PRICE_ORDER_HIGH_LOW_TEXT;?></option>
								<!-- <option value="vendor asc" <?php if($_REQUEST['sel_order_by']=="vendor asc"){ echo "selected";}?>><?php echo VENDOR_ORDER_ASC_TEXT;?></option>
								<option value="vendor desc" <?php if($_REQUEST['sel_order_by']=="vendor desc"){ echo "selected";}?>><?php echo VENDOR_ORDER_DESC_TEXT;?></option> -->
								<option value="rating desc" <?php if($_REQUEST['sel_order_by']=="rating desc"){ echo "selected";}?>><?php echo RATING_ORDER_HIGH_LOW_TEXT;?></option>
								</select>
							</div>
						</div>
						<div class="clear"></div>
					</div>
			</div>

<?php
if(mysql_num_rows($result) > 0 )
	{

	?>

<div class="brdcrumbnbtn_container">

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td>
<div class="brdcrumb_container">
<?php if($_GET['catid']=='') { echo ALL_PRODUCTS_TEXT;} else {   echo stripslashes(getSellerProfileLink("showportfolio.php",$artistid,GetSQLValueString($current_product_category,"text"))); } ?>
 </div> </td>
</tr>
</table>
</div>

<?php

	if($_GET['catid']!='')
	{
		$subCount	= checkSubCategoryCount($_GET['catid'])		;

     }

?>


<?php

                if($txtNumCols>0)
                    {
                        $cells = $txtNumCols;
                        $count_row = 1;
                }
                else
                    {
                        $cells =4;
                        $count_row = 1;
                }

?>
			<div class='featuredproduct_list sellerproducts'>

<?php
	while($row = mysql_fetch_array($result))
		{

            $product_image  =   '';
                // Image Selection Modification // Done By Asha
            $imageurl='';
            if($row["default_image_small"] !="") {
                $product_image = $row["default_image_small"];

            }  // end if product image null check


  
        if($product_image=="") {
                $imageurl = $site_url."/".$prodimagedir."noimage.jpg";
            }
            else {
                if(strstr($product_image, "http://") || strstr($product_image, "https://")) {
                    $imageurl = $product_image;
                }
                else {
                    if(ENABLE_AMAZON_S3_IMAGES=="Y"){ 
                        $imageurl = "<img class='product_img' src='" .AMAZON_S3_DOMAIN_URL.$prodimagedir.$product_image . "' >";
                    }else{
                        $imageurl = $site_url."/".$prodimagedir.$product_image;
                    }
                }
            }
        $imageurl = "<img class='product_img' src='".$imageurl."'>";

 
          // End Image Display Modification

			if($row["default_stock"] > 0)
				{
                                 $productinstock = true;
                            }
			else
			{
				$productinstock = false;
			}

			if(!empty($product_image))
			{ // Rename Image Thumb;
				$imagename=$product_image;
                        }  // end thumb creation
                    $prd_full_name = stripslashes($row["product_name"]);
			if(strlen($row["product_name"])>20)
			{
							  $prd_name = stripslashes(substr($row["product_name"],0,17))."...";
			}
			else
			{
				 $prd_name = stripslashes($row["product_name"]);

		     }

			$price=$row['product_price'];

					$discountstr="";

				
				$conversionRate	= ConvertedCurrencyRate($currency_attributes[2]);
				$converted_price = $price * $conversionRate;
				$discountprice=0;
				if($row["default_discount"] !="0"){
					$discountprice=$converted_price- ($converted_price*$row["default_discount"])/100;
					$discountprice =number_format($discountprice,2,".","");
					$discountstr="<br>".strtolower(MAIL_ORDER_TEXT_DISCOUNT)."(".$row["default_discount"]."%)";

			      }


		        $display_product_price = number_format($converted_price,2,".","");
  $appendStyle = NULL;
//if($count_row==$cells) {
if(true) {
    switch($cells){
        case '4':			
            $appendStyle = 'class="col-sm-12 col-lg-3 col-md-3"';
            break;
        case '3':
            $appendStyle = 'class="col-sm-12 col-lg-4 col-md-4"';
            break;
        case '2':
            $appendStyle = 'class="col-sm-12 col-lg-6 col-md-6"';
            break;
        case '1':
            $appendStyle = 'class="col-sm-12 col-lg-12 col-md-12"';
            break;
    }
}

?>
<?php

  /********************Multicart 3.0 Modifications******************************************/

        $SEOFriendlyLink = getOptimisedLink(SITE_URL, $row["product_category"], $row["alias"]);
        $subscriptionFlag   =    Products::is_subscription_product($row["product_id"]);



     /********************Multicart 3.0 Modifications******************************************/

 ?>
<!--Display the product details-->
<?php if($row["product_id"]!=NULL){?>
<div <?php echo $appendStyle; ?> > 
<div class="products" <?php if ($count_row == 4) { ?> style="margin-right:0px;"  <?php } ?>>
    <a class="product_anchor" href="<?php echo $SEOFriendlyLink;?>">
		<div class="imgblock">
			<?php echo $imageurl?>
		</div>
	</a>
	 <!--GreenOver-->
         <div class="prod_green" id="<?php echo $row["product_id"]?>" data="<?php echo $SEOFriendlyLink; ?>">
             
			<div class="prodover_blk">
				<div class="prodover_blk_row">
					<div width="64%" align="left" class="txt_align" valign="middle"> 
						<?php $productRating = ProductRatingStar($row["product_id"]); ?>
						<div class="rating_<?php echo $productRating; ?>" id="rating_<?php echo $productRating; ?>"></div>
					</div>
					<div class="clear"></div>  
				</div> 
				<div class="clear"></div>
				<?php
				if($productinstock)
				{   
                                    // Hide Shop now Button for Subscription Items and their own items
                                if(!$subscriptionFlag && $sellerprevilegeFlag=='N') { ?>
				
				<div class="prodover_blk_row">
						<div class="adtocart_tbn_blk cart_btn_home">
							<a class="adtocart" href=" <?php echo SITE_URL?>/homepage_addtocart.php?productid=<?php echo $row["product_id"]?>&product_option_id=<?php echo $row["default_option_id"]?> " class="add_cart_small"><?php echo ADD_TO_CART_TEXT; ?></a>
							<div class="clear"></div>  
						</div>
					</div>
                                <?php } ?>
					<div class="clear"></div>
					<?php
				} else {
					?>
					<div class="prodover_blk_row">
						<div class="adtocart_tbn_blk cart_btn_home"><img src="<?php echo SITE_URL ?>/images/home_outfstock.gif"  alt="<?php echo OUT_STOCK_TEXT;?>" border="0"/></div>
						<div class="clear"></div>  
					</div>
					<div class="clear"></div>
					<?php
				}
				?>
			</div>
		</div>
		<h5>
                    <a href="<?php echo $SEOFriendlyLink; ?>" title="<?php echo $prd_full_name; ?>"><?php 
                        if(strlen($prd_name)>20) {
                            echo substr($prd_name,0,20)."...";
                        } else {
                            if(LANGUAGE=='english')
                                echo $prd_name;
                            else
                                echo $prd_name;
                        }
                        ?></a>
          </h5>
		<div class="product_price"><p>  <?php if($discountprice!=0) { ?> <?php echo  $currency_attributes[0] ?> <?php echo $discountprice;?> (<strike><?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> </strike>) <?php }  else { ?> <?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> <?php } ?> </p></div>
	

<div class="clear"></div>
</div>  
</div>
<?php } else {?>
 <!-- If product ID is NULL -->
 <div class="noproducts" >
     
  <?php  echo  NO_PRODUCT_FOUND_TEXT;  ?></div>

 <?php }  // end else ?>
<?php

	if($count_row ==$cells) {

			$count_row = 1;
	}
		else {
		$count_row++;
	 }

	}

?>
</div>
<?php
}
else
{

 ?>
 <div class="noproducts" >
    <?php
      if($vacation_mode=='Y') {  echo "<img src='".SITE_URL."/images/vacation_image.png' border='0'>";  }
        else {  echo  NO_PRODUCT_FOUND_TEXT; } ?>
 </div>

 <?php }  // end else
 ?>

<input type="hidden" value="<?php echo $featured;?>" name="featured">

<div class="clear"></div>
</div>

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

</form>

