<?php

define( "CMS", 1 );define( "STORE", 1 );define( "BLOG", 1 );

$cms = "";
$store = "";
$blog = "";

header("Content-type: application/xml+xhtml");require_once "./inc/userdb.php";
$q = $dbh->query("SELECT * FROM `SiteDetails` LIMIT 1");
$siteDetails = $q->fetch(PDO::FETCH_ASSOC);
if( CMS ){
	$q = $dbh->query("SELECT * FROM `CMSPages` WHERE `active` = 1 AND `noindex` = 0");
	while( $page = $q->fetch(PDO::FETCH_ASSOC) )
	{	
		if( !( $page['id'] == $siteDetails['storePage'] || $page['id'] == $siteDetails['blogPage'] ) )		{			if( $page['id'] == $siteDetails['defaultPage'] )				$cms .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/</loc></url>";
			else				$cms .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/{$page['type']}/{$page['nameId']}</loc></url>";		}
	}
}if( STORE ){	if( $siteDetails['storePage'] == $siteDetails['defaultPage'] )		$store .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/</loc></url>";	else		$store .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/store/</loc></url>";	
	$q = $dbh->query("SELECT * FROM `ProductDesc` WHERE `active` = 1");
	while( $prod = $q->fetch(PDO::FETCH_ASSOC) )
		$store .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/product/{$prod['nameId']}</loc></url>";

	$q = $dbh->query("SELECT * FROM `Categories` WHERE `active` = 1");
	while( $cat = $q->fetch(PDO::FETCH_ASSOC) )
		$store .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/category/{$cat['nameId']}</loc></url>";}if( BLOG ){	if( $siteDetails['blogPage'] == $siteDetails['defaultPage'] )		$blog .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/</loc></url>";	else		$blog .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/blog/</loc></url>";			$q = $dbh->query("SELECT * FROM `BlogEntries`");	while( $entry = $q->fetch(PDO::FETCH_ASSOC) )	{		$blog .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/blog/{$entry['nameId']}</loc></url>";	}		$q = $dbh->query("SELECT * FROM `BlogTags`");	while( $tag = $q->fetch(PDO::FETCH_ASSOC) )	{		$blog .= "<url><loc>http://{$_SERVER['HTTP_HOST']}/blog/{$tag['nameId']}</loc></url>";	}}

echo <<<OUT
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	$cms
	$store
	$blog
</urlset>
OUT;
?>
