<?
header("Content-Type: text/xml; charset=utf-8");  
ini_set('max_execution_time', 0); 
$dir = '../inc/';
require_once $dir."database.php";
require_once $dir."DW_class.php";
$dw = new DWDB();
$tarih = date('Y-m-d H:i');
//* Seo Link oluşturma
function seo_link($link) {
$link = trim($link);
$eski = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü',' ','\'','|','/','`','&#39;','&quot;','&',',','.','?','®',')','(','{','}','[',']');
$yeni = array('c','c','g','g','i','i','o','o','s','s','u','u','-','-','','-','','','','','','','','','','','','','','');
$seo_link = str_replace($eski,$yeni,$link);
$seo_link = strtolower($seo_link);
return $seo_link;
}
//* Seo Link oluşturma
//* Güvenlik 
function guvenlik($verim) {
$verim =addslashes($verim);
$verim = strip_tags($verim);
$verim = htmlentities($verim);
$verim = htmlspecialchars($verim);
return $verim;
}
//* Güvenlik
//* Ayar Cek
$ayarcek = $dw->getRow('SELECT * FROM ayarlar WHERE id = ?', array('bindValues' => array(1)));
$firmacek = $dw->getRow('SELECT * FROM firma WHERE id = ?', array('bindValues' => array(1)));
$usdcek = $dw->getRow('SELECT * FROM kur WHERE id = ?', array('bindValues' => array(1)));
$eurcek = $dw->getRow('SELECT * FROM kur WHERE id = ?', array('bindValues' => array(2)));
//* Ayar Cek
?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="<?=$tarih;?>">
    <shop>
        <name><?=$firmacek->firmaadi;?></name>
        <url><?=$ayarcek->sitelink;?></url>
        <shop_address><?=$firmacek->adres;?></shop_address>
        <shop_phone><?=$firmacek->telefon;?></shop_phone>
        <email><?=$firmacek->email;?></email>
        <shop_logo><?=$ayarcek->sitelink;?>images/logo.ong</shop_logo>
        
        <currencies>
            <currency id="TL" rate="1"/>
            <currency id="USD" rate="<?=$usdcek->oran;?>"/>
            <currency id="EUR" rate="<?=$eurcek->oran;?>"/>
        </currencies>
        
        <categories>
<?
$results = $dw->getResults('SELECT * FROM kategoriler where ustkategori = 0 and durum = 1 order by id');
foreach ($results as $read) {
?>
<category id="<?=$read->id;?>"><![CDATA[<?=$read->kategori;?>]]></category>
<?
$results2 = $dw->getResults('SELECT * FROM kategoriler where ustkategori = '.$read->id.' and durum = 1 order by id');
foreach ($results2 as $read2) {
?>
<category id="<?=$read2->id;?>" parentId="<?=$read2->ustkategori;?>"><![CDATA[<?=$read2->kategori;?>]]></category>
<?
$results3 = $dw->getResults('SELECT * FROM kategoriler where ustkategori = '.$read2->id.' and durum = 1 order by id');
foreach ($results3 as $read3) {
?>
<category id="<?=$read3->id;?>" parentId="<?=$read3->ustkategori;?>"><![CDATA[<?=$read3->kategori;?>]]></category>
<?
}
}
}
?>
        </categories>
        <delivery_cost>10</delivery_cost>
        <delivery_details>Tüm Türkiye, 3-6 gün içinde</delivery_details>
        <offers>
<?
$resultss = $dw->getResults('SELECT * FROM urunler where anaurun = 0 and durum = 1 order by id');
foreach ($resultss as $urunyaz) {
//* Marka cek
$markacek = $dw->getRow('SELECT * FROM markalar WHERE id = ?', array('bindValues' => array($urunyaz->marka)));
//* Marka cek
//* Resim cek
$resimcek = $dw->getRow('SELECT * FROM resimler WHERE urunid = ?', array('bindValues' => array($urunyaz->id)));
$resimsayisi = $dw->numRows();
if($resimsayisi == 0) {
$resim = "gorselhazir.png";
} else {
$resim = $resimcek->ortaresim;
}
//* Resim cek
$kategorisi = $dw->getRow('SELECT * FROM kategoriler WHERE id = ?', array('bindValues' => array($yaz->ustkategori)));
$link = "u/".$yaz->id."/".seo_link("$kategorisi->kategori")."/".seo_link("$yaz->urun");
?>
            <offer id="<?=$urunyaz->id;?>" available="true">
                <url><?=$ayarcek->sitelink;?><?=$link;?></url>
                <price_KDV><?=$urunyaz->satis_fiyat;?></price_KDV>
                <price_sale_KDV><?=$urunyaz->indirimli_fiyat;?></price_sale_KDV>
                <currencyId><?=$urunyaz->fiyatbirimi;?></currencyId>
                <categoryId><?=$urunyaz->kategori;?></categoryId>
                <picture><?=$ayarcek->sitelink;?>yukleme/urun/<?=$resim;?></picture>
                <delivery>true</delivery>
                <delivery_cost>10</delivery_cost>
                <delivery_details>Tüm Türkiye, 3-6 gün içinde</delivery_details>
                <vendor><?=$markacek->marka;?></vendor>
                <name><?=guvenlik("$urunyaz->urun");?></name>
                <vendorCode><?=$urunyaz->kod;?></vendorCode>
                <description><![CDATA[<?=$urunyaz->detay;?>]]></description>
                <barcode><?=$urunyaz->kod;?></barcode>
            </offer>
<?
}
?>
        </offers>      
    </shop>
</yml_catalog>
<?
error_reporting(0);
?>