<?php
header("Content-type: text/xml");

// Sertakan koneksi database
include "config/koneksi.php";

$query3 = "SELECT * FROM identitas";
$hasil3 = mysqli_query($konek, $query3);
$data3  = mysqli_fetch_array($hasil3);

// Mulai XML
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

echo "<url>
<loc>{$data3['alamat_website']}</loc>
<lastmod>2025-03-11T12:25:37+00:00</lastmod>
<priority>1.00</priority>
</url>";

$pages = ['about-us', 'layanan', 'galeri', 'testimoni', 'blog', 'kontak'];
foreach ($pages as $page) {
    echo "<url>
<loc>{$data3['alamat_website']}/{$page}</loc>
<lastmod>2025-03-11T12:25:37+00:00</lastmod>
<priority>0.80</priority>
</url>";
}

// Artikel dari agenda
$query = mysqli_query($konek, "SELECT tema_seo, tgl_posting FROM agenda ORDER BY id_agenda DESC");
while ($r = mysqli_fetch_assoc($query)) {
    $tgl = date('Y-m-d', strtotime($r['tgl_posting']));
    echo "<url>
<loc>{$data3['alamat_website']}/artikel-" . htmlspecialchars($r['tema_seo']) . "</loc>
<lastmod>{$tgl}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>";
}

// Berita
$query = mysqli_query($konek, "SELECT judul_seo, tanggal FROM berita");
while ($r = mysqli_fetch_assoc($query)) {
    $tgl = date('Y-m-d', strtotime($r['tanggal']));
    echo "<url>
<loc>{$data3['alamat_website']}/produk-" . htmlspecialchars($r['judul_seo']) . "</loc>
<lastmod>{$tgl}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>";
}

echo '</urlset>';
?>
