<?php
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();
$zaman = date('d.m.Y H:i:s');
//* 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
//* Ayar Cek
$ayarcek = $dw->getRow('SELECT * FROM ayarlar WHERE id = ?', array('bindValues' => array(1)));
//* Ayar Cek
$xml ='<mywebstore>
    <created_at>'.$zaman.'</created_at>
    <products>';
$results = $dw->getResults('SELECT * FROM urunler where anaurun = 0 and durum = 1 order by id');
foreach ($results as $yaz) {
//* Marka cek
$markacek = $dw->getRow('SELECT * FROM markalar WHERE id = ?', array('bindValues' => array($yaz->marka)));
//* Marka cek
//* Resim cek
$resimcek = $dw->getRow('SELECT * FROM resimler WHERE urunid = ?', array('bindValues' => array($yaz->id)));
$resimsayisi = $dw->numRows();
if($resimsayisi == 0) {
$resim = "gorselhazir.png";
} else {
$resim = $resimcek->ortaresim;
}
//* Resim cek
$kategoriadi = array();
$kategoriidler1 = explode("-", $yaz->kategori);
foreach ($kategoriidler1 as $kategoriids) {
    
    if ($kategoriids == "") {
    } else {
       $kategoricek = $dw->getRow('SELECT * FROM kategoriler WHERE id = ?', array('bindValues' => array($kategoriids))); 
       $kategoriadi[] = $kategoricek->kategori;
    }
}
$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");
$kategoriad = implode(", ", $kategoriadi);
$xml.= '<product>
    <id>'.$yaz->id.'</id>
    <name><![CDATA['.$yaz->kod.' - '.$yaz->urun.']]></name>
    <link><![CDATA['.$ayarcek->sitelink.''.$link.'.html]]></link>
    <image><![CDATA['.$ayarcek->sitelink.'yukleme/urun/'.$resim.']]></image>
    <category><![CDATA['.$kategoriad.']]></category>
    <price_with_vat>'.$yaz->satis_fiyat.'</price_with_vat>
    <manufacturer><![CDATA['.$markacek->marka.']]></manufacturer>
    <instock>Y</instock>
    <availability>Hemen Teslim</availability>
</product>';
}
$xml .= '</products>
</mywebstore>';
echo $xml;
error_reporting(0);
?>