<?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
//* Firma Cek
$firmacek = $dw->getRow('SELECT * FROM firma WHERE id = ?', array('bindValues' => array(1)));
//* Firma Cek
$xml ='<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
  <channel>';
$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;
    }
}
if ($yaz->fiyatbirimi == 0) {
    $fiyatbirim = "TL";
} elseif ($yaz->fiyatbirimi == 1) {
    $fiyatbirim = "USD";
} elseif ($yaz->fiyatbirimi == 2) {
    $fiyatbirim = "EUR";
} elseif ($yaz->fiyatbirimi == 3) {
    $fiyatbirim = "RUB";
} elseif ($yaz->fiyatbirimi == 4) {
    $fiyatbirim = "ALTIN";
}
$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.= '
<item>
      <g:id>'.$yaz->id.'</g:id>
      <title>'.$yaz->urun.'</title>
      <description>'.$yaz->urun.'</description>
      <g:google_product_category></g:google_product_category>
      <g:product_type></g:product_type>
      <link>'.$ayarcek->sitelink.''.$link.'.html</link>
      <g:image_link>'.$ayarcek->sitelink.'yukleme/urun/'.$resim.'</g:image_link>
      <g:condition>new</g:condition>
      <g:availability>in stock</g:availability>
      <g:gtin></g:gtin>
      <g:mpn>'.$yaz->barkod.'</g:mpn>
      <g:brand>'.$markacek->marka.'</g:brand>
      <g:price>'.$yaz->satis_fiyat.' '.$fiyatbirim.'</g:price>
</item>';
}
$xml .= '</channel></rss>';
echo $xml;
error_reporting(0);
?>