<?php
require_once __DIR__.'/../app/config.php';
require_once __DIR__.'/../app/db.php';
header('Content-Type: application/xml; charset=utf-8');

$base = rtrim(BASE_URL,'/');
$urls = [
  "$base/",
  "$base/login.php",
  "$base/register.php",
  "$base/surveys.php",
  "$base/wallet.php",
  "$base/profile.php",
];

try {
  $pdo = DB::pdo();
  $st = $pdo->query("SELECT id, updated_at FROM surveys ORDER BY id DESC LIMIT 1000");
  foreach ($st->fetchAll() as $r) {
    $urls[] = "$base/survey_take.php?id=".$r['id'];
  }
} catch (\Throwable $e) {}

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach(array_unique($urls) as $u): ?>
  <url><loc><?= htmlspecialchars($u,ENT_XML1) ?></loc></url>
<?php endforeach; ?>
</urlset>
