<?php
$set = $func->globalset("semua");
$text = (isset($titel)) ? $set->nama . " " . $titel : $set->nama . " " . $set->slogan;
$nama = preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', $text);
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

	<url>
		<loc><?= $nama; ?></loc>
		<lastmod><?= date('d-m-Y H:i:s') ?></lastmod>
		<changefreq>daily</changefreq>
		<priority>0.1</priority>
	</url>

	<?php
	$kategoriList = $db->table("kategori")->where("parent", 0)->get();
	foreach ($kategoriList->getResult() as $r) {
	?>
		<url>
			<loc><?= site_url("kategori/" . $r->url) ?></loc>
			<changefreq>daily</changefreq>
			<priority>0.1</priority>
		</url>
	<?php
	}
	?>

	<?php
	$produkList = $db->table("produk")
		->where("status", 1)
		->where("preorder !=", 1)
		->get();

	foreach ($produkList->getResult() as $r) {
		$variasiList = $db->table("produkvariasi")->where("idproduk", $r->id)->get();
		$totalstok = ($variasiList->getNumRows() > 0) ? 0 : $r->stok;
		foreach ($variasiList->getResult() as $rv) {
			$totalstok += $rv->stok;
		}

		if ($totalstok > 0) {
	?>
			<url>
				<loc><?= site_url('produk/' . $r->url) ?></loc>
				<lastmod><?= $r->tglupdate ?></lastmod>
				<changefreq>daily</changefreq>
				<priority>0.1</priority>
			</url>
	<?php
		}
	}
	?>

	<?php
	$blogList = $db->table("blog")->get();
	foreach ($blogList->getResult() as $blog) {
	?>
		<url>
			<loc><?= site_url('blog/' . $blog->url) ?></loc>
			<lastmod><?= $blog->tgl ?></lastmod>
			<changefreq>daily</changefreq>
			<priority>0.1</priority>
		</url>
	<?php
	}
	?>
</urlset>
