#!/usr/bin/php
<?php header("Content-type: application/xml");
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">';
 include_once($_SERVER['DOCUMENT_ROOT'] . "/common/includes/pre_html_include.php"); 


$exclude_books = " AND menuID NOT IN (1) "; // Exlude books
$books = getAllRows("*", "menu", "parentID=0 AND hidden=0".$exclude_books, "nav_order ASC");
if($books){
	foreach($books as $book){
		echo '<url>
				<loc>'.$config["site_url"].''.$book['url'].'</loc>
				<lastmod>'.date("Y-m-d").'</lastmod>
				<priority>1.00</priority>
				<changefreq>daily</changefreq>
			</url>';
			
			$chapters = getAllRows("*", "menu", "visible=1 AND hidden=0 AND parentID=".$book['menuID'], "nav_order ASC");
			if($chapters){
				foreach($chapters as $chapter){
					echo '<url>
						<loc>'.$config["site_url"].''.$chapter['url'].'</loc>
						<lastmod>'.date("Y-m-d").'</lastmod>
						<priority>1.00</priority>
						<changefreq>daily</changefreq>
					</url>';
					
					
					//Insert Blog Posts
					if($chapter['menuID']==16){
						$blogs = getAllRows("*", "blog", "visible=1", "blog_timestamp DESC");
						if($blogs){
							foreach($blogs as $blog){
								echo '<url>
									<loc>'.$config["site_url"].rewriteBlogURL($blog['blogID']).'</loc>
									<lastmod>'.date("Y-m-d", strtotime($blog['blog_timestamp'])).'</lastmod>
									<priority>1.00</priority>
									<changefreq>daily</changefreq>
								</url>';
							}//foreach($blogs as $blog){
						}//if($blogs){
					}//if($page['menuID']==16){
					
					
					
					
						$pages = getAllRows("*", "menu", "visible=1 AND hidden=0 AND parentID=".$chapter['menuID'], "nav_order ASC");
						if($pages){
							foreach($pages as $page){
								echo '<url>
									<loc>'.$config["site_url"].''.$page['url'].'</loc>
									<lastmod>'.date("Y-m-d").'</lastmod>
									<priority>1.00</priority>
									<changefreq>daily</changefreq>
								</url>';
							}//foreach($pages as $page){
						}//if($pages){
					

					
				}//foreach($chapters as $chapter){
			}//if($chapters){
			
	}//foreach($books as $book){
}//if($books){

?>

</urlset>