<?

	$rootPath = '';
	
	$kill_debug = true;
	
	require_once($rootPath . 'application.php');
	require_once($rootPath . 'security.php');
	require_once($rootPath . 'initialize.php');

	header('Content-Type: text/xml');
	
	echo '<?xml version="1.0" encoding="' . $_gLang['Charset'] . '" ?>';
	echo "\n";
	echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">';
	echo "\n";
	
		
	$topic = $_gTopics->get('MAIN_MENU');

	if ( !empty($topic) )
	{
		$_gMenu = $_gTopics->getTopics($topic->ID);
		
		foreach ( $_gMenu as $menu )
		{
			echo '<url>
					 <loc>'.$menu->getUrl().'</loc>
				 </url>'; 
		}
	}
	
	// ---
	
	// Récupération des zones
	$filters = array();
	$filters['Language'] = $_gLanguage['LanguageID'];
	$filters['IsActive'] = true;
	
	$zones = fetchZone($filters);
	
	$_gZones = array();
	
	while ( $zone = $db->sql_fetch_assoc($zones) )
	{
		echo '<url>
				 <loc>'.getZoneUrl($zone).'</loc>
			  </url>'; 
		 
		$filters['Zone'] = $zone['ZoneID'];
		//$filters['Type'] = DT_CLASSIC;
		
		$destinations = fetchDestination($filters);
		
		if ( $db->sql_num_rows($destinations) > 0 )
		{
			while ( $destination = $db->sql_fetch_assoc($destinations) )
			{
				echo '<url>
						 <loc>'.getDestinationUrl($destination).'</loc>
					 </url>'; 
					 
				$filters['Destination'] = $destination['DestinationID'];
	
				$hotels = fetchHotel($filters);
				
				if ( $db->sql_num_rows($hotels) > 0 )
				{
					while ( $hotel = $db->sql_fetch_assoc($hotels) )
					{
						echo '<url>
								 <loc>'.getDestinationHotelUrl($hotel).'</loc>
							 </url>'; 
					}
				}
				
				
				$routes = fetchRoute($filters);
				if ( $db->sql_num_rows($routes) > 0 )
				{
					while ( $route = $db->sql_fetch_assoc($routes) )
					{
						echo '<url>
								 <loc>'.getDestinationRouteUrl($route).'</loc>
							 </url>'; 
					}
				}
				
			
			}
		}
	}
	
	// Récupération des thèmes
	$filters = array();
	$filters['Language'] = $_gLanguage['LanguageID'];
	$filters['IsActive'] = true;
	
	$themes = fetchTheme($filters);
	
	$_gThemes = array();
	
	while ( $theme = $db->sql_fetch_assoc($themes) )
	{
		echo '<url>
				 <loc>'.getThemeUrl($theme).'</loc>
			  </url>';
			  
		$filters['Theme'] = $theme['ThemeID'];
	
		$routes = fetchRoute($filters);
		
		if ( $db->sql_num_rows($routes) > 0 )
		{
			while ( $route = $db->sql_fetch_assoc($routes) )
			{
				echo '<url>
						 <loc>'.getThemeRouteUrl($route).'</loc>
					 </url>'; 
			}
		}
		
		$hotels = fetchHotel($filters);
		
		if ( $db->sql_num_rows($hotels) > 0 )
		{
			while ( $hotel = $db->sql_fetch_assoc($hotels) )
			{
				echo '<url>
						 <loc>'.getThemeHotelUrl($hotel).'</loc>
					 </url>'; 
			}
		}		
	}
	
	// ---

	$topic = $_gTopics->get('FOOTER');

	if ( !empty($topic) )
	{
		$_gFooter = $_gTopics->getTopics($topic->ID);

		foreach ( $_gFooter as $menu )
		{
			echo '<url>
					 <loc>'.$menu->getUrl().'</loc>
				 </url>'; 
		}
	}
	
	// --- import
	/*
	$topic = $_gTopics->get('IMPORT');

	if ( !empty($topic) )
	{
		$_gFooter = $_gTopics->getTopics($topic->ID);

		foreach ( $_gFooter as $menu )
		{
			echo '<url>
					 <loc>'.$menu->getUrl().'</loc>
				 </url>'; 
		}
	}	
	*/

	echo '</urlset>';
?>