<?php
/**
 * Dynamic sitemap. Rebuilds on each request.
 */
header('Content-Type: application/xml; charset=UTF-8');
$base = 'https://www.kubenative.com.my';

require __DIR__ . '/includes/db.php';
$pdo = get_db();
$jobs = $pdo->query("SELECT id, updated_at FROM jobs WHERE is_active = 1 ORDER BY updated_at DESC")->fetchAll();

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <url>
        <loc><?= $base ?>/</loc>
        <changefreq>monthly</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc><?= $base ?>/careers.php</loc>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    <url>
        <loc><?= $base ?>/case-study-swcorp-ispemos.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc><?= $base ?>/case-study-mcmcpay.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php foreach ($jobs as $job): ?>
    <url>
        <loc><?= $base ?>/careers.php?job=<?= (int)$job['id'] ?>#apply</loc>
        <lastmod><?= htmlspecialchars($job['updated_at'], ENT_QUOTES) ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php endforeach; ?>
</urlset>
