<?php

require $_SERVER["DOCUMENT_ROOT"] . "/includes/config.php";

$smarty->setCaching(false);

// Load the home page
$gzQuery = "
	SELECT
		pb_updated as date
	FROM
		pages_built_in
	WHERE
		pb_id = '999'
";
$gzResult = mysql_query($gzQuery) or gzError();
if(mysql_num_rows($gzResult) > 0){
	while ($row = mysql_fetch_assoc($gzResult)) {
		$pages[] = array('url' => "/index.html", 'date' => $row["date"]);
	}
}

// Add the active content pages
$gzQuery = "
	SELECT
		pg_url as url,
		pg_updated as date
	FROM
		pages
	WHERE
		pg_active = '1'
";
$gzResult = mysql_query($gzQuery) or gzError();
if(mysql_num_rows($gzResult) > 0){
	while ($row = mysql_fetch_assoc($gzResult)) {
		$pages[] = array('url' => "/content/" . $row["url"], 'date' => $row["date"]);
	}
}

// Add the active articles
$gzQuery = "
	SELECT
		art_url as url,
		art_updated as date
	FROM
		articles,
		article_categories
	WHERE
		art_catid = acat_id AND
		art_active = '1' AND
		acat_active = '1'
";
$gzResult = mysql_query($gzQuery) or gzError();
if(mysql_num_rows($gzResult) > 0){
	while ($row = mysql_fetch_assoc($gzResult)) {
		$pages[] = array('url' => "/article/" . $row["url"], 'date' => $row["date"]);
	}
}

// Add the active links pages
$gzQuery = "
	SELECT
		lp_url as url,
		lp_updated as date
	FROM
		link_pages
	WHERE
		lp_active = '1'
";
$gzResult = mysql_query($gzQuery) or gzError();
if(mysql_num_rows($gzResult) > 0){
	while ($row = mysql_fetch_assoc($gzResult)) {
		$pages[] = array('url' => "/links/" . $row["url"], 'date' => $row["date"]);
	}
}

// Add the gallery pages
$gzQuery = "
	SELECT
		gls_parent_id as url_1,
		gls_id as url_2,
		gls_updated as date
	FROM
		galleries
	WHERE
		gls_active = '1'
";
$gzResult = mysql_query($gzQuery) or gzError();
if(mysql_num_rows($gzResult) > 0){
	while ($row = mysql_fetch_assoc($gzResult)) {
		$pages[] = array('url' => "/gallery/" . $row["url_1"] . "/" . $row["url_2"] . "/", 'date' => $row["date"]);
	}
}

$smarty->assign("pages", $pages);

header('Content-Type: text/xml');
header('Content-Disposition: inline; filename=sitemap.xml');

$smarty->display("sitemap_xml.tpl");

