<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Santhosh Thomas Alexander<santhosh.thomas@armiasystems.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 OptimizedUrl=$(this).attr('data');          
         window.location = OptimizedUrl;
        });
    });
</script>
<?php
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();
$productListingFee = getSettingsValue('product_listing_fee');*/
$userid = $_SESSION['sess_userid'];
$sql="SELECT p.product_id,p.product_name,p.alias,p.product_category,(p.product_price + po.additional_price) AS product_price,po.image_small,po.image_big,po.product_option_id,po.product_stock,po.discount,s.artist_name,s.storename,
    (SELECT pm.vimage_name FROM ".$tableprefix."product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage, AVG(r.nrating_id) as rating                 
                  FROM ".$tableprefix."favourites f
                  INNER JOIN ".$tableprefix."product_options po ON po.product_option_id = f.nProductOptionId
                  INNER JOIN ".$tableprefix."products p ON p.product_id = po.product_id
                  LEFT JOIN ".$tableprefix."artists s on p.product_artist_id=s.artist_id LEFT JOIN ".$tableprefix."record_ratings r ON p.product_id = r.nrseller_id 
                  WHERE f.nUserId = '".addslashes($userid)."' AND p.vapproved='Y' AND p.deleted ='N' AND p.publish_status='Y' " ;

if($productListingFee > 0) {
    $sql .= " AND p.payment_status='COMPLETED' ";
}
$sql .= "  AND s.vapproved='Y' AND p.seller_vacation_mode='N' AND s.plan_expired='N' ";


$qrystring= " ";

if($txtSearch != "" || $catid!='') { // check for searching

    $qrystring.=" AND ";

    if(!empty($catid)) { // check category Id is empty or not

        $qrystring.=" p.product_category =".GetSQLValueString($catid,"text")." AND ";

    } //

    if($txtSearch!='') {
        $qrystring .= ' ( p.product_name like "%' . addslashes($txtSearch) . '%" || p.product_description like "%' . addslashes($txtSearch) . '%") AND  ';
    }

} // end if search 

$query1=rtrim($qrystring, " AND");	

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 s.artist_name DESC ";
	}
	else if($_REQUEST['sel_order_by']=="vendor asc"){
		$order = "GROUP BY p.product_id ORDER BY s.artist_name ASC";
	}
	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 ASC";
	}
	else {
		$order = "GROUP BY p.product_id ";
	}
}
else {
	$order = "GROUP BY p.product_id ";
}

$query=$sql.$query1.$order;

if(!(isset($pagenum))) {
    $pagenum = 1;
} 

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

$totalrows = mysql_num_rows($result);

$limit=12;
//$limit=3;

$sql_qr=dopaging($query,'',$limit);	

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

$prodimagedir = "products/";
?>
<div id="fav_products_div">
<?php
if($totalrows > 0 ) {
    $i=1;
    $cells =4;
    $count_row = 1;

    while($row = mysql_fetch_array($result)) {
       // echo "<pre>";print_r($row);echo "</pre>";
        // Image Selection Modification // Done By Asha
            $imageurl='';
            if($row["image_small"] !="") {
                $product_image = $row["image_small"];

            }  // end if product image null check
            elseif($row["image_big"] != "") {
                $product_image = $row["image_big"];
            }
            else
                {
                     $product_image=$row["smallimage"];
            }

       if($product_image=="") {
                $imageurl = $prodimagedir."noimage.jpg";
            }
            else {
                if(strstr($product_image, "http://")) {
                    $imageurl = $product_image;
                }
                elseif(!is_file($prodimagedir.$product_image) && !file_exists($prodimagedir.$product_image)) {
                            // $imageurl = $prodimagedir.$product_image;
                	$imageurl = $prodimagedir."noimage.jpg";
                }
                else {
                    $imageurl = $site_url."/".$prodimagedir.$product_image;
                }
            }
        
             $imageurl = "<img class='product_img' src='".$imageurl."' border='0' >";
        
        if(checkProductStock($row["product_id"]) > 0) {
            $productinstock = true;
        }
        else {
            $productinstock = false;
        }

     

        if(strlen($row["product_name"])>30) {
            $prd_name = stripslashes(substr($row["product_name"],0,30));
        }
        else {
            $prd_name = stripslashes($row["product_name"]);

        }

        $price=$row['product_price'];

        $discountstr="";

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

        }
        $display_product_price = number_format($converted_price,2,".","");


          /********************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******************************************/

        ?>

<div class="col-sm-12 col-lg-4 col-md-4 " >		
<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>
	<div class="prod_green" id="<?php echo $row["product_id"];?>" data="<?php echo $SEOFriendlyLink; ?>" >	
		<div class="prodover_blk">
			<div class="prodover_blk_row">
                                <?php if ($enable_seller_friendly == "Y") {
                                    $sellerLink = (!empty($row['storename'])) ? SITE_URL . "/stores/" . $row['storename'] : SITE_URL . "/store/" . $row['artist_name'];
                                } else {
                                    $sellerLink = (!empty($row['storename'])) ? SITE_URL."/showportfolio.php?storename=" . $row['storename'] : SITE_URL."/showportfolio.php?artistid=" . $row['artist_id'];
                                } ?>
				<div class="artist_name"><a href="<?php echo $sellerLink; ?>" title="<?php echo $row['artist_name'];?>"><?php echo $row['artist_name'];?></a></div>
				<div class="clear"></div>  
			</div>
			<div class="clear"></div>
			<div class="prodover_blk_row">
				<?php $productRating = ProductRatingStar($row["product_id"]); ?>
				<div class="rating_<?php echo $productRating; ?>" id="rating_<?php echo $productRating; ?>"></div>				                 
				<div class="clear"></div>  
			</div>
			<div class="clear"></div>
			<div class="prodover_blk_row">
				<div width="64%" align="left" class="txt_align" valign="middle"> <?php $productRating = ProductRatingStar($row["product_id"]); ?></div>
				<div class="clear"></div>  
			</div> 
			<div class="clear"></div>  
					<?php
					if($productinstock) {
						?>
                        <?php  // Hide Shop now Button for Subscription Items
                            if(!$subscriptionFlag) { ?>
			<div class="prodover_blk_row">
				<div class="adtocart_tbn_blk">
					<a class="adtocart" href="<?php echo SITE_URL?>/homepage_addtocart.php?productid=<?php echo $row["product_id"]?>&product_option_id=<?php echo $row["product_option_id"]?>"><?php echo ADD_TO_CART_TEXT; ?></a>
					<div class="clear"></div>  
				</div>
				<div class="clear"></div>  
			</div>
                        <?php } ?>
			<div class="clear"></div>
						<?php
					}
					else {
						?>
			<div class="prodover_blk_row">
				<div class="adtocart_tbn_blk"><span class="out_stock">Out of Stock</span></div>
				<div class="clear"></div>  
			</div>
			<div class="clear"></div>
						<?php
		
					} 
					?>
		</div>
	</div>
    <h5><a href="<?php echo $SEOFriendlyLink;?>" title="<?php echo $prd_name; ?>">
                        <?php 
                        if(strlen($prd_name)>24) {
                            echo substr($prd_name,0,24)."...";
                        } 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;?> <span>(<strike><?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> </strike>)</span> <?php }  else { ?> <?php echo  $currency_attributes[0] ?> <?php echo $display_product_price;?> <?php } ?> </p></div>
    <div class="clear"></div>
</div>
</div>

        <?php
        if($count_row ==$cells) {

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

    }
    ?>
    <?php
} 
else {
    ?>
<div class="noproducts" ><?php echo NO_PRODUCT_FOUND_TEXT;?></div>
    <?php
}  // end else
?>
<input type="hidden" value="<?php echo $featured;?>" name="featured">
<div class="clear"></div>

<?php if($totalrows>$limit) { ?>   
<div  class="pagination"> <?php echo rightpaging();?></div>
<?php } ?>
 </div> <!--Products list ends -->
<?php 
$favorite_seller_query = "SELECT DISTINCT(f.nSellerId),ap.artist_photo,f.dDate,f.nId,ar.company,ar.storename,ar.artist_name,ar.first_name,ar.last_name,ar.artist_id
                                        FROM ".$tableprefix."seller_favourites f
                                        INNER JOIN ".$tableprefix."artists  ar ON ar.artist_id = f.nSellerId
                                        LEFT JOIN ".$tableprefix."artist_portfolios ap ON ar.artist_id = ap.artist_id    
					WHERE f.nUserId = '".$userid."' AND ar.is_vacation_mode = 'N' group by f.nSellerId  ";


$wishListResult = mysql_query($favorite_seller_query);
$totalrows = mysql_num_rows($wishListResult);

/*$limit=getPaginationLimit();
if($limit==0) {
    $limit=10;
}		
$limit = 1;
if(!(isset($pagenum)))
{
	$pagenum = 1;
} 
$page = isset($_GET['page'])? trim($_GET['page']):1;

if(empty($page))
{
	$page = 1;
}
$sql_qr=dopaging($favorite_seller_query,'',$limit);

$resultWishItems    =   mysql_query($sql_qr);*/

/*display the active template*/

$wishListNumRows = mysql_num_rows($wishListResult);

if($wishListNumRows>0){
while($row = mysql_fetch_array($wishListResult))
		{

                        $foto = $row['artist_photo'];
                        
                        
                        if(!(is_file("./portfolios/". $foto) && file_exists("./portfolios/". $foto)))
                        {
                            $foto = 'noimage.jpg';
                        }
                        
                                
                    
                        if($enable_seller_friendly == "Y")
                        {
                           
                            $sellerLink = (!empty($row['storename'])) ? SITE_URL . "/stores/" . $row['storename'] : SITE_URL . "/store/" . $row['artist_name'];
                            //$sellerLink = SITE_URL . "/store/" . $row['artist_name'];
                        }
                        else
                        {
                            $sellerLink = (!empty($row['storename'])) ? SITE_URL."/showportfolio.php?storename=" . $row['storename'] : SITE_URL."/showportfolio.php?artistid=" . $row['artist_id'];
                        }
?>	
<div id="fav_sellers_div">
<section class="sec_marg">
<div class="col-sm-12 col-lg-6 col-md-6 " >
<div class="seller_lst_wrap">
	<div class="row">
		<div class="col-sm-12 col-lg-3 col-md-3 ">
			<div class="image_div">
			   <a href="<?php echo $sellerLink; ?>" target="_blank">  
			   <img src="./portfolios/<?php echo $foto; ?>" />
			   </a>
			</div>
		</div>
		<div class="col-sm-12 col-lg-9 col-md-9 ">
			<div class="sellerlst_content">
			<h3><a href="<?php echo $sellerLink; ?>" target="_blank" >  <?php echo ucfirst($row['artist_name']);?> </a></h3>
			
			<div class="clear"></div>
			</div>
		</div>
	</div>
	<div class="clear"></div>
</div>
<div class="clear"></div>

</div>
</section>			

<?php
            }	// while end
	
		}
		else{
		
		     echo "<br>".SELLER_NOT_FOUND_TEXT;
		}
	
			
		/*if($page > 1)
		{
			$pageprev = $page-1;
			
			$previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev&tab=$currentTabID alt='".PREVIOUS_TEXT."' title='".PREVIOUS_TEXT."' border='0'><img src='".$active_template[3]."/previous_btn.gif' alt='".PREVIOUS_TEXT."' border='0' /></a>";
			
		}
		
		$numofpages = ceil($totalrows / $limit);
					
		if($page < $numofpages)
		{
			$pagenext = ($page + 1);
			
			$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext&tab=$currentTabID alt='".NEXT_TEXT."' title='".NEXT_TEXT."' border='0'><img src='".$active_template[3]."/next_btn.gif' alt='".NEXT_TEXT."' border='0'/></a>&nbsp;";
			
		}*/
		
?>
</div><!---Favorite sellers ends--->
