<?php
require_once 'includes/db.php';
require_once 'includes/functions.php';
header('Content-Type: application/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php
$baseUrl = 'http://localhost/school-website';
$pages = ['index.php', 'about.php', 'admission.php', 'academics.php', 'staff.php', 'news.php', 'gallery.php', 'downloads.php', 'contact.php', 'notices.php', 'events.php', 'faqs.php'];
foreach ($pages as $page): ?>
    <url>
        <loc><?= $baseUrl ?>/<?= $page ?></loc>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
<?php endforeach;

$news = $pdo->query("SELECT slug, updated_at FROM news WHERE is_active = 1 ORDER BY created_at DESC LIMIT 50")->fetchAll();
foreach ($news as $item): ?>
    <url>
        <loc><?= $baseUrl ?>/news.php?slug=<?= $item['slug'] ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($item['updated_at'])) ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
<?php endforeach;

$events = $pdo->query("SELECT slug, updated_at FROM events WHERE is_active = 1 ORDER BY event_date DESC LIMIT 50")->fetchAll();
foreach ($events as $item): ?>
    <url>
        <loc><?= $baseUrl ?>/events.php?slug=<?= $item['slug'] ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($item['updated_at'])) ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
<?php endforeach; ?>
</urlset>
