<?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
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";
include_once "classes/cls_user.php";
include_once "classes/cls_products.php";
if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_userid"]) and $_SESSION["sess_userid"]!= ""){
	$userid = $_SESSION["sess_userid"];
}else{
	header("Location:login.php");
	exit;
}

$adminCurrency	= GetAdminCurrency();

/*if($begin == ""){
        $begin=0;
        $num=1;
        $numBegin=1;
}*/
$currency_attributes = displayCurrencyType();

$Query_Wish_Products = "SELECT f.*,po.product_option_id,p.product_id,p.product_name,p.product_category,(p.product_price+po.additional_price) AS product_price,po.*,p.product_artist_id,po.image_small,po.image_big,p.alias,
             (SELECT pm.vimage_name FROM ".$tableprefix."product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage
					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
                                        INNER JOIN ".$tableprefix."categories c ON c.category_id  = p.product_category
					WHERE f.nUserId = '".addslashes($userid)."' AND f.status='Y' AND p.vapproved='Y'  AND  p.publish_status='Y'  ";

//echo $Query_Wish_Products;
$wishListResult = mysql_query($Query_Wish_Products);
//echo "<pre>";print_r($result);
$totalrows = mysql_num_rows($wishListResult);

$limit=getPaginationLimit();

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

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

$page = isset($_GET['page'])? trim($_GET['page']):1;

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

$sql_qr=dopaging($Query_Wish_Products,'',$limit);
//echo $sql_qr;
$resultWishItems    =   mysql_query($sql_qr);

/*display the active template*/

$wishListNumRows = mysql_num_rows($wishListResult);

$active_template = displayTemplate();

$prodimagedir = SITE_URL."/products/";

/*display the active template*/

$active_template = displayTemplate();

include "includes/htmltop.php";

/* Top File Name */

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

?>
<script src="<?php echo SITE_URL?>/js/common.js"></script>
<link href="<?php echo $site_url; ?>/themes/<?php echo $active_template[5] ?>/jquery-confirm.css" rel="stylesheet" type="text/css">
<script src="<?php echo SITE_URL?>/js/jquery-confirm.js"></script>
<!--mainbody area start -->
<div class="main_body">
	<div class="container">
		<div class="row">			

		<!--center content area start-->		

		<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmFeedbacks">
		
		<section class="sec_marg">
		<div class="col-sm-12 col-lg-12 col-md-12 ">
			<h3><?php echo MY_FAVOURITES_TEXT;?></h3>
		</div>
		</section>
		<div class="clear"></div>
		
		<div class="col-sm-12 col-lg-12 col-md-12 ">
		<!--items display area start -->
		
		<div>&nbsp;</div>
		<div class="text_information" align="center"><?php echo $message?></div>
		<div>
			
			<div class="order_listings">
			
			
			 <table width="100%"  border="0" cellpadding="0" cellspacing="0" align="center" class="responsive">
                            <tr class="ordheads_heads">
                                <th width="6%">#</th>
                                <th width="30%" align="left"><b><?php echo FAVOURITES_PRODUCT_TEXT;?></b> </th>
                                <th width="14%" align="left" ><b><?php echo FAVOURITES_PRODUCT_PRICE;?> (<?php  echo $adminCurrency['currency_symbol'];?>) </b></th>
                                <th width="12%" align="left" ><b><?php echo FAVOURITES_DATE_ADDED;?> </b></th>
                                <th width="20%" align="center"><b><?php echo FAVOURITES_ACTION_TEXT;?> </b></th>
                            </tr>

                            <?php $ct = 1;?>
                            <?php if($totalrows > 0) {?>
                                <?php while ($wishlistRow =  mysql_fetch_array($resultWishItems)) { ?>
                                    <?php

                                    $product_id = $wishlistRow["product_id"];
                                    $productname = $wishlistRow["product_name"];
                                    $product_option_id = $wishlistRow["product_option_id"];
                                    $aliasname         = $wishlistRow["alias"];
                                    $categoryid         = $wishlistRow["product_category"];
                                    // Currency Conversion

                                    $conversionRate	= 	ConvertedCurrencyRate($currency_attributes[2]);
                                    $converted_price 	= 	$wishlistRow['product_price'] * $conversionRate;

                                    $rate = $converted_price;
                                    // End currency Conversion
                                    /*------------Multicart 2.0 Upgradation------------*/

                                    $qty = $wishlistRow["quantity"];
                                    $price = $qty * $rate;
                                    $discountstr="";
                                    $discountprice =0;
                                    if($wishlistRow["discount"] !="0") {
                                        $price			=	number_format($price,2,".","");
                                        $discountprice		=	$rate-($rate*$wishlistRow["discount"])/100;
                                        $discountprice 		=	number_format($discountprice,2,".","");
                                        $discountrate 		=  ($discountprice*$qty);
                                        $price		 =	$discountrate;
                                        $discountstr="<br>discount(".$wishlistRow["discount"]."%)";
                                    }
                                    $optionsStr = "";
                                    $optionVal = getProductOptionsName($product_option_id);
                                    if($optionVal!="") {
                                        $optionsStr = "<br>".$optionVal;
                                    }

                                    $total += $price;
                                    $product_image = "";
                                    $imageurl='';
                                    if($wishlistRow["image_small"]!="") {
                                        $product_image = $wishlistRow["image_small"];

                                    }  // end if product image null check
                                    elseif($wishlistRow["image_big"]!= "") {
                                        $product_image = $wishlistRow["image_big"];
                                    }
                                    else {
                                            $product_image=$wishlistRow["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;
                }*/
                                        else {
                                                if(file_exists("products/".$product_image))
                                                    {
                                                            $imageurl = $prodimagedir.$product_image;
                                                    }else{
                                                            $imageurl = $prodimagedir."noimage.jpg";
                                                    }

                                             }
                                    }

                      /********************Multicart 3.0 Modifications******************************************/
                            $SEOFriendlyLink = getOptimisedLink(SITE_URL, $categoryid, $aliasname);
                     // End Settings
                            $product_option_stock   =   Products::getProductOptionStock($wishlistRow['product_option_id']);
                                   
                                    //echo "\n ".$stockRec['product_stock'];
                                    ?>

                            <tr id="jQwish<?php echo $wishlistRow["nId"];?>">
                                <td valign="top"><?php echo (($page*$limit)+$ct-$limit)?></td>
                                <td>

                                    <div class="cart_temlist">
                                        <div class="prdct_img">
                                            <a href="<?php echo $SEOFriendlyLink;?>" target="_blank">
                                                <img src="<?php echo $imageurl;?>" alt="<?php echo stripslashes($productname);?>" title="<?php echo stripslashes($wishlistRow ['product_name']);?>" height="105" width="110"/>
                                            </a>
                                        </div>
                                        <div class="prdct_name">
                                            <a href="<?php echo $SEOFriendlyLink;?>" target="_blank">
                                                        <?php echo htmlentities(stripslashes($wishlistRow ['product_name'])).$discountstr.$optionsStr;?>
                                            </a>
                                        </div>
                                        <div class="clear"></div>
                                    </div>
                                </td>

                                <td><p class="item_price"><?php
                                                            
                                                            echo $currency_attributes[0]."&nbsp;".number_format($wishlistRow ['product_price'],2,".","");
                                                           ?>
                                    </p></td>
                                <td><p class="item_price"><?php
                                                            
                                                            echo dateFormat($wishlistRow["dDate"], "Y-m-d", "m/d/Y");
                                                           ?>
                                    </p></td>
                                <td class="wishlist_actions">
                                 <?php if($product_option_stock>0) { ?>
                                    <a href="#" class="cart_addtobasket" onclick="addfavouriteitemtoCart(<?php echo $wishlistRow ['nProductId'];?>,<?php echo $wishlistRow['nProductOptionId'];?>,<?php echo $wishlistRow['nId'];?>)" > <?php echo FAVOURITES_ADD_BASKET;?></a>
                                    <?php } else { echo FAVORITES_NO_STOCK_TEXT; } ?>
                                   | &nbsp; <a href="#" class="cart_delete" id="delete" onclick ="return deletefavouriteitems(<?php echo $wishlistRow['nId'];?>);"><?php echo FAVOURITES_DELETE;?></a>
                                </td>
                            </tr>
                                    <?php $ct++;?>
                                    <?php } ?>
                                <?php } else {  ?>
                            <tr>
                                <td colspan="5" class="text_information" align="center"><?php echo FAVOURITES_LIST_NOT_FOUND;?></td>
                            </tr>
                                <?php } ?>
                           

                        </table>
			<div class="clear"></div>
			</div>
			<div class="row">
			<div class="col-sm-12 col-lg-6 col-md-6">
				<input type="button" value="<?php echo ACCOUNT_BACK_BUTTON;?>" name="btnBack"  class="button" onClick="window.location.href='myaccount.php'">
			</div>  	
			<div class="col-sm-12 col-lg-6 col-md-6">
				<?php 
				if($totalrows>$limit)
				{
				
				?>	
										<div  class="pagination"> <?php echo rightpaging();?></div>
				<?php } ?>					
			</div>
			</div>
			<div class="clear"></div>
		  
							
							
						
																										
		</div>	
	
	
		<div align="left" class="float_clear1"></div>
					
					
		 <!--items display area end -->
		  </div>
		
			</form>
		<!--center content area end-->	

	</div>
	</div>
</div>
<!--mainbody area end -->
<div class="clear"></div>
<?php
include "includes/".$active_template[2];	/* Bottom File Name */
?>																										
																										
																										
																									