<?php

require_once("Connections/db_connect.php");

$domain = "https://www.collegegolf.us";

$xml = new DOMDocument("1.0", "UTF-8");
$xml->formatOutput = true;

$urlset = $xml->createElement("urlset");
$urlset->setAttribute(
    "xmlns",
    "http://www.sitemaps.org/schemas/sitemap/0.9"
);

$xml->appendChild($urlset);

//
// Forsiden
//

$url = $xml->createElement("url");

$loc = $xml->createElement("loc",$domain);
$last = $xml->createElement("lastmod",date("Y-m-d"));
$change = $xml->createElement("changefreq","daily");
$priority = $xml->createElement("priority","1.0");

$url->appendChild($loc);
$url->appendChild($last);
$url->appendChild($change);
$url->appendChild($priority);

$urlset->appendChild($url);

//
// Universiteter
//

$sql = "
SELECT id
FROM universities
ORDER BY id
";

$result = $conn->query($sql);

while($row = $result->fetch_assoc())
{

    $url = $xml->createElement("url");

    $loc = $xml->createElement(
        "loc",
        $domain."/university/".$row['id']
    );

    $last = $xml->createElement("lastmod",date("Y-m-d"));
    $change = $xml->createElement("changefreq","weekly");
    $priority = $xml->createElement("priority","0.8");

    $url->appendChild($loc);
    $url->appendChild($last);
    $url->appendChild($change);
    $url->appendChild($priority);

    $urlset->appendChild($url);

}

//
// Trænere
//

$sql = "
SELECT coach_id
FROM XLS_GOLF_NCAA_ALL_COACHES_X
";

$result = $conn->query($sql);

while($row = $result->fetch_assoc())
{

    $url = $xml->createElement("url");

    $loc = $xml->createElement(
        "loc",
        $domain."/coach/".$row['coach_id']
    );

    $last = $xml->createElement("lastmod",date("Y-m-d"));
    $change = $xml->createElement("changefreq","weekly");
    $priority = $xml->createElement("priority","0.7");

    $url->appendChild($loc);
    $url->appendChild($last);
    $url->appendChild($change);
    $url->appendChild($priority);

    $urlset->appendChild($url);

}

$xml->save("sitemap.xml");

echo "Sitemap oprettet.";

?>
