<?php
header("Content-type: text/xml");

$host ="xxxxxxxx";
$user = "xxxxx"; 
$password = "xxxxxxxxxxxxx";
$site = "http://www.xxxxxxxxxx.cz";
$img_path = "/media/catalog/product";    
$link = mysql_connect($host, $user, $password);
mysql_select_db("xxxxxxxxxxxx");    
mysql_query("SET NAMES 'utf8';");
        
function getValue($table,$entity_id,$attribute_id) {
global $link;
    
$q = "SELECT * FROM `catalog_$table` WHERE entity_id='".$entity_id."' AND attribute_id='".$attribute_id."'";
//echo $q;
//echo "<br />";
$result = mysql_query($q, $link);
$value = "";
if($row = mysql_fetch_assoc($result)){ 

$value = $row['value'];
$trans = array("?"=>" ", "&nbsp;"=>" ");
$value = strtr($value, $trans);
}
return $value;
}
    
$q1 = "SELECT * FROM `catalog_product_entity`";
     
$result = mysql_query($q1, $link);
    
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$xml .= "<SHOP>\n";  
while($row = mysql_fetch_assoc($result)){ 
$entity_id = $row['entity_id'];
$sku = $row['sku'];
    
$category_path = "";
$category_ids = $row['category_ids'];
$cat_id = explode(",", $category_ids);
foreach($cat_id as $cat){
$category_path .= "/";
$category_path .= getValue("category_entity_varchar",$cat,47);
}

$cena = getValue("product_entity_decimal",$entity_id,60);
$cena_specialni = getValue("product_entity_decimal",$entity_id,0);
    
$price = $cena;
    
if($cena_specialni!="" OR $cena_specialni!="0"){
        
$dnes = date(Ymd);
        
$trans = array("-"=>"");
        
$od = strtr(substr(getValue("product_entity_datetime",$entity_id,568),0,10),$trans)-1;
$do = strtr(substr(getValue("product_entity_datetime",$entity_id,569),0,10),$trans)+1;
        
if($dnes>$od AND $dnes<$do) {
$price = $cena_specialni;
}
}
    
     // if($produkt[visibility] == 4) {
            $xml .= " <SHOPITEM>\n";
            $xml .= "  <PRODUCT>".getValue("product_entity_varchar",$entity_id,56)."</PRODUCT>\n";
            $xml .= "  <DESCRIPTION>".strip_tags(getValue("product_entity_text",$entity_id,58))."</DESCRIPTION>\n";
	        $xml .= "  <URL>".$site."/".getValue("product_entity_varchar",$entity_id,83)."</URL>\n";
            $xml .= "  <ITEM_TYPE>new</ITEM_TYPE>\n";
            $xml .= "  <IMGURL>".$site.$img_path.getValue("product_entity_varchar",$entity_id,70)."</IMGURL>\n";
            $xml .= "  <PRICE>".$price."</PRICE>\n";
            $xml .= "  <VAT>20</VAT>\n";
            $xml .= " </SHOPITEM>\n";    
      //}
    }
    
    $xml .= "</SHOP>\n"; 
    echo $xml;
?>