<?php
header('Content-Type: application/xml; charset=utf-8');
include('includes/config.php');
error_reporting(0);

// Fetch all visible vehicles
$vehicles = $dbh->query("SELECT id, UpdateDate, RegDate FROM tblvehicles WHERE IsHidden=0 ORDER BY id DESC")->fetchAll(PDO::FETCH_OBJ);

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

  <!-- Static Pages -->
  <url>
    <loc>https://juhamajp.com/</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
    <lastmod><?= date('Y-m-d') ?></lastmod>
  </url>
  <url>
    <loc>https://juhamajp.com/index.php</loc>
    <changefreq>daily</changefreq>
    <priority>0.9</priority>
    <lastmod><?= date('Y-m-d') ?></lastmod>
  </url>
  <url>
    <loc>https://juhamajp.com/contact-us.php</loc>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
    <lastmod><?= date('Y-m-d') ?></lastmod>
  </url>

  <!-- Vehicle Pages -->
  <?php foreach ($vehicles as $v):
    $lastmod = !empty($v->UpdateDate) ? date('Y-m-d', strtotime($v->UpdateDate)) : date('Y-m-d', strtotime($v->RegDate));
  ?>
  <url>
    <loc>https://juhamajp.com/vehical-details.php?vhid=<?= $v->id ?></loc>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
    <lastmod><?= $lastmod ?></lastmod>
  </url>
  <?php endforeach; ?>

</urlset>
