<?php
include('config/dbConfig.php');

// Define the date range for editions
$startOfDayTimestamp = strtotime('00:00:00'); // Adjust as needed
$endOfDayTimestamp = strtotime('23:59:59');   // Adjust as needed
$ceditionCategory = "1=1";  // Adjust your WHERE clause condition as per your requirement

// Fetch editions from the database
$queryEditions = "SELECT * FROM `ed_editions` WHERE $ceditionCategory AND `editionDate` BETWEEN '$startOfDayTimestamp' AND '$endOfDayTimestamp'";
$resultEditions = mysqli_query($con, $queryEditions);

// Set header for XML output
header("Content-Type: application/xml; charset=UTF-8");

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

// Loop through editions and generate sitemap entries
while ($editionRow = mysqli_fetch_array($resultEditions)) {
    $editionTitle = htmlspecialchars($editionRow['editionTitle']);
    $editionDate = date('Y-m-d', $editionRow['editionDate']);
    $editionUrl = $baseURL. $editionRow['id']; // Adjust the URL structure as needed

    echo '<url>';
    echo '<loc>' . $editionUrl . '</loc>';
    echo '<lastmod>' . $editionDate . '</lastmod>';
    echo '<changefreq>monthly</changefreq>'; // Adjust change frequency as needed
    echo '<priority>0.8</priority>'; // Adjust priority as needed
    echo '</url>';
}

// XML structure end
echo '</urlset>';

// Close the database connection
mysqli_close($con);
?>