<?php
	//1. check to see if a "real" file exists..
	
	if(file_exists($DOCUMENT_ROOT.$REQUEST_URI)	and ($SCRIPT_FILENAME!=$DOCUMENT_ROOT.$REQUEST_URI) and ($REQUEST_URI!="/")){
		$url=$REQUEST_URI;
		include($DOCUMENT_ROOT.$url);
		exit();
	}
	
	//2. if not, go ahead and check for dynamic content.
	$url=strip_tags($REQUEST_URI);
	$url_array=explode("/",$url);
	array_shift($url_array); //the first one is empty anyway 
	
	if(empty($url_array)){ //we got a request for the index
		$pageid = $defaultStartPageID;
	}
	
	//Look if anything in the Database matches the request 
	//This is an empty prototype. Insert your solution here.
		
	include($_SERVER['DOCUMENT_ROOT'] . "/include/settings.php");
	include($_SERVER['DOCUMENT_ROOT'] . "/include/functions.php");
	
	if (sizeof($url_array)>0){
		if(is_numeric($url_array[0])){
			$pageid = $url_array[0];
		} else {
			$pageid = $defaultStartPageID;
		}
	} else {
		$pageid = $defaultStartPageID;
	}
	
	$arrPage = GetPage($pageid,false); 
	
	extract($arrPage[0]);
	OpenDatabase();
	$arrMenuArray = ReturnMenuArray($pageid);
	$template = ReturnQuery("select * from templates where templateid = " . $templateid ); 
	CloseDatabase();
	$templateurl = $_SERVER['DOCUMENT_ROOT'] . $template[0][1];

	include($templateurl);

?>