<?php
// Generate sitemap dynamically
require_once 'config.php';

header('Content-Type: application/xml; charset=utf-8');

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

// Homepage
echo '<url><loc>https://pacifichk.com/</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>1.0</priority></url>' . "\n";

// Category pages
echo '<url><loc>https://pacifichk.com/category.php?type=chair</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.8</priority></url>' . "\n";
echo '<url><loc>https://pacifichk.com/category.php?type=desk</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.8</priority></url>' . "\n";
echo '<url><loc>https://pacifichk.com/category.php?type=table</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.8</priority></url>' . "\n";
echo '<url><loc>https://pacifichk.com/category.php?type=all</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.8</priority></url>' . "\n";

// Content page
echo '<url><loc>https://pacifichk.com/content.php</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.9</priority></url>' . "\n";

// Cart
echo '<url><loc>https://pacifichk.com/cart.php</loc><lastmod>' . date('Y-m-d') . '</lastmod><priority>0.7</priority></url>' . "\n";

// Products from DB
$db = getDb();
$result = mysqli_query($db, "SELECT ID FROM goods LIMIT 50");
while ($row = mysqli_fetch_assoc($result)) {
    $id = htmlspecialchars($row['ID']);
    echo "<url><loc>https://pacifichk.com/product.php?id=" . urlencode($id) . "</loc><lastmod>" . date('Y-m-d') . "</lastmod><priority>0.6</priority></url>\n";
}
mysqli_close($db);

echo '</urlset>';
