<?
	$includes_path = '../includes/website'; 
	include $includes_path.'/config.php'; //settings for the web
	include $includes_path.'/dbconfig.inc'; //database login
	include $includes_path.'/language.php'; //database login
	include $includes_path.'/main_functions.php'; //common functions
	include $includes_path.'/menu_lists.php'; //lists of all pages used in menu and some pages
	
	
	function map ($link, $priority) 
	{
		$link = htmlspecialchars($link);
		
		$out  = 	"\t<url>\n\t\t<loc>$link</loc>\n\t\t<changefreq>daily</changefreq>\n\t\t<priority>$priority</priority>\n\t</url>\n";
		return $out;
	}

$map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<urlset
      xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
      xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";

//LEVEL 1
foreach ($level1 as $k1=>$v1)
{ 
	$link1 = 'http://' . $_SERVER['SERVER_NAME'] . '/index.php?page='.$v1['link']; 
	
	$map .= map($link1, '0.25');
	
	// LEVEL2 
	if (isset($level2[$k1])) 
	{
		foreach($level2[$k1] as $k2=>$v2)
		{ 
			 $link2 =  'http://' . $_SERVER['SERVER_NAME'] . '/index.php?page='.$v2['link'];
			 $map .= map($link2, '0.5');
			
			//LEVEL3
			if (isset($level3[$k2]))
			{
				foreach($level3[$k2] as $k3=>$v3)
				{ 
					 $link3 =  'http://' . $_SERVER['SERVER_NAME'] . '/index.php?page='.$v3['link'];
					 $map .= map($link3, '0.75');
			
					//LEVEL4
					if (isset($level4[$k3]))
					{
						foreach($level4[$k3] as $k4=>$v4)
						{ 	
							$link4 =  'http://' . $_SERVER['SERVER_NAME'] . '/index.php?page='.$v4['link'];
			 				$map .= map($link4, '1');
						}
					}
				}
			}
		 } 
	}
}
$map .= '</urlset>';

print $map;

?>