<?php 
// Let us first make sure the php file is 
// interpeted as xml information 
include "includes/config.php";
include "includes/functions.php";
$curdat=date('Y-m-d');

header ("Content-Type: text/xml;charset=iso-8859-1"); 

echo '<?xml version="1.0" encoding="iso-8859-1"?>'; 
echo "\n";

 $sql="SELECT p.product_id,p.product_description,p.product_name,
     (p.product_price + po.additional_price) AS product_price,
     po.image_small,po.product_option_id,po.product_stock,
     po.discount,p.featured,
     ar.artist_name
			  FROM ".$tableprefix."products p 
                          INNER JOIN ".$tableprefix."product_options po ON po.product_id = p.product_id AND po.default_option = 'YES'
INNER JOIN ".$tableprefix."artists ar ON p.product_artist_id=ar.artist_id
WHERE ar.vapproved='Y' AND p.deleted !='Y' AND p.vapproved='Y'
                          AND ar.plan_expired='N'  ORDER BY p.date_added  DESC  LIMIT 0,9";
	
		
$result=mysql_query($sql) or die(mysql_error());

$num = mysql_num_rows($result); 

  	// First we print the overall xml information 
	echo '<rss version="2.0" 
xmlns:g="http://base.google.com/ns/1.0">';
	echo "\n";
  	echo "<channel>\n"; 
	//echo '<atom:link href="'.SITE_URL.'/rss_feed.php" rel="self" type="application/rss+xml" />';
	echo "\n";
  	// Here comes the global title for you rss 
  	echo "<title>".SITE_NAME."</title>\n"; 
  	// Here comes the url for the page that the rss applies for 
  	echo "<link>".SITE_URL."/</link>\n"; 
  	// Here comes a short description of the page 
  	echo "<description>".RSS_LATEST_TEXT."</description>\n"; 
	
	// Now over to the dynamic part 
      
   if($num == 0) 
	{ 
            echo "<item>\n";
            echo "<title>".NO_RECORDS_DISPLAY_MSG."</title>\n"; 
            echo "<link>".SITE_URL."/index.php</link>\n"; 
            echo "<description>\n"; 
            echo NO_RECORDS_DISPLAY_MSG; 
            echo "</description>\n"; 
            echo "<guid isPermaLink='true'>".SITE_URL."/categorydetail.php</guid>\n";
            
            echo "</item>\n"; 
	} 
	else 
	{ 
  		  
		while($row = mysql_fetch_array($result)) 
  		{	
                    $prodimagedir="products/";
                    $product_image=$row["image_small"];
                    $prdImage = '';
                    if($product_image=="")
                    {
                        $prdImage = $prodimagedir . "noimage.jpg";
                    }
                    else
                    {
                        if(strstr($product_image, "http://"))	
                        {
                            $prdImage = $product_image;
                        }
                        else
                        {
                            $prdImage = $prodimagedir.urlencode($product_image);
                        }
                    }
                    
                    
                    $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>discount(".$row["discount"]."%)";

                    }
                    $display_product_price = number_format($converted_price,2,".","");
                    
                    $featured = $row["featured"] == 'Y' ? 'dsd' : 'new';
                    
                    
                    echo "<item>\n"; 
                    echo "<title>".ucfirst($row["product_name"])."</title>\n"; 
                    echo "<link>".SITE_URL."/productdetails.php?productid=".$row["product_id"]."</link>\n"; 
                    echo "<description>\n"; 
                    echo '<![CDATA['.html_entity_decode(stripslashes($row["product_description"])).']]>';
                    echo "</description>\n"; 
                    echo "<guid isPermaLink='true'>".SITE_URL."/productdetails.php?productid=".$row["product_id"]."</guid>\n";
                    echo "<g:image_link>".SITE_URL."/". $prdImage ."</g:image_link>\n";
                    echo "<g:price>". $display_product_price . "</g:price>\n";
                    echo "<g:condition>" . $featured . "</g:condition>\n";
                    echo "<g:id>".$row["product_id"]."</g:id>\n";
                    echo "</item>\n"; 
  		} 
   }
  	// And at last the closing tags for the overall info 
  	echo "</channel>\n"; 
  	echo "</rss>\n"; 
 
?>

