<?php
/**
 * Dynamic XML Sitemap Generator
 * Save this as sitemap.php and configure your .htaccess to serve it as sitemap.xml
 * Or create a cron job to generate static sitemap.xml periodically
 */

header('Content-Type: application/xml; charset=utf-8');

// Website base URL
$base_url = 'https://wearwaze.com';

// Define all pages
$pages = [
    ['loc' => $base_url . '/index.php', 'priority' => '1.0', 'changefreq' => 'daily'],
    ['loc' => $base_url . '/about.php', 'priority' => '0.8', 'changefreq' => 'monthly'],
    ['loc' => $base_url . '/why-us.php', 'priority' => '0.8', 'changefreq' => 'monthly'],
    ['loc' => $base_url . '/contact.php', 'priority' => '0.9', 'changefreq' => 'weekly'],
];

// Get products from database (if needed)
// Uncomment if you want to include product pages dynamically
/*
$conn = new mysqli("localhost", "username", "password", "database");
$result = $conn->query("SELECT id, updated_at FROM products WHERE status = 'active'");
while ($row = $result->fetch_assoc()) {
    $pages[] = [
        'loc' => $base_url . '/product.php?id=' . $row['id'],
        'priority' => '0.6',
        'changefreq' => 'weekly',
        'lastmod' => date('c', strtotime($row['updated_at']))
    ];
}
*/

// Generate XML
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";

foreach ($pages as $page) {
    echo "\t<url>\n";
    echo "\t\t<loc>" . htmlspecialchars($page['loc']) . "</loc>\n";
    if (isset($page['lastmod'])) {
        echo "\t\t<lastmod>" . $page['lastmod'] . "</lastmod>\n";
    } else {
        echo "\t\t<lastmod>" . date('c') . "</lastmod>\n";
    }
    echo "\t\t<changefreq>" . $page['changefreq'] . "</changefreq>\n";
    echo "\t\t<priority>" . $page['priority'] . "</priority>\n";
    echo "\t</url>\n";
}

echo '</urlset>';
?>