<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    
    <!-- Main Pages -->
    <url>
        <loc>https://journal.hakmahcollege.com.ng/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/about.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/guidelines.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/ethics.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/review-process.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/archives.php</loc>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/contact.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/login.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.5</priority>
    </url>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/register.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.5</priority>
    </url>
    
    <!-- Dynamic Pages - Articles -->
    <?php
    // This part dynamically adds all published articles to the sitemap
    require_once 'includes/config.php';
    // Get database connection
$db = Database::getInstance();
$conn = $db->getConnection();

$articles = $conn->query("
        SELECT a.id, a.publication_date, a.updated_at
        FROM articles a 
        JOIN manuscripts m ON a.manuscript_id = m.id 
        WHERE m.status = 'published'
        ORDER BY a.publication_date DESC
    ");
    while($article = $articles->fetch_assoc()):
    ?>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/article.php?id=<?php echo $article['id']; ?></loc>
        <lastmod><?php echo date('Y-m-d', strtotime($article['publication_date'])); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.9</priority>
    </url>
    <?php endwhile; ?>
    
    <!-- Dynamic Pages - Volumes and Issues -->
    <?php
    $volumes = $conn->query("SELECT id, volume_number, year FROM volumes ORDER BY volume_number DESC");
    while($volume = $volumes->fetch_assoc()):
    ?>
    <url>
        <loc>https://journal.hakmahcollege.com.ng/archives.php?volume=<?php echo $volume['id']; ?></loc>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    <?php endwhile; ?>
    
</urlset>