<?php
// Liste de vos pages
$pages = [
    ['loc' => 'https://www.atc-systems.fr/', 'title' => 'Accueil', 'priority' => '1.0', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/pages-generales/plan-du-site.php', 'title' => 'Plan du site', 'priority' => '0.5', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/pages-generales/contact.php', 'title' => 'Contact', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/pages-generales/qui-sommes-nous.php', 'title' => 'Qui sommes-nous', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/pages-generales/commande-consommables.php', 'title' => 'Commande consommables', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/pages-generales/commande-materiel.php', 'title' => 'Commande matériel', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/0-patrimoine/pointeuse-au-musee.php', 'title' => 'La pointeuse au musée', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/0-patrimoine/pointeuse-au-fotomat.php', 'title' => 'La pointeuse au Fotomat', 'priority' => '0.8', 'freq' => 'monthly'],
    ['loc' => 'https://www.atc-systems.fr/0-patrimoine/pointeuse-au-cinema.php', 'title' => 'La pointeuse au cinéma', 'priority' => '0.8', 'freq' => 'monthly'],
];

// 1. Génération automatique du fichier sitemap.xml
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

foreach ($pages as $page) {
    $xml .= "  <url>\n";
    $xml .= "    <loc>" . $page['loc'] . "</loc>\n";
    $xml .= "    <changefreq>" . $page['freq'] . "</changefreq>\n";
    $xml .= "    <priority>" . $page['priority'] . "</priority>\n";
    $xml .= "  </url>\n";
}
$xml .= '</urlset>';

// Enregistrement physique du fichier sitemap.xml à la racine
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/sitemap.xml', $xml);

// 2. Fonction pour afficher le plan du site dynamiquement dans votre page plan-du-site.php
function afficher_plan_du_site($pages) {
    echo '<ul class="sitemap-list">';
    foreach ($pages as $page) {
        echo '<li><a href="' . htmlspecialchars($page['loc']) . '">' . htmlspecialchars($page['title']) . '</a></li>';
    }
    echo '</ul>';
}
?>