<?php
  $request  = str_replace("/var/www/trains.im/", "", $_SERVER['REQUEST_URI']); 
  $params   = explode('/', $request);

if ( ($params[1] == "location") && (substr($params[2],0,7) == "search?") ) {	
	if (($_GET["station"] != "") && ($_GET["date"] != "")) {
		include_once('./railclasses.php');
		$db = new railServiceSearch();
		$loc = $db->getCRSFromLocation($_GET["station"]) . "/" . $_GET["date"] . "/";
		if ($_GET["destination"] != "") {
			if ($_GET["period"] == "") {
				$loc = $loc . "/" . $db->getCRSFromLocation($_GET["destination"]);
			} else {
				$loc = $loc . $_GET["period"] . "/" . $db->getCRSFromLocation($_GET["destination"]);
			}
		} else {
			$loc = $loc . $_GET["period"];
		}
		header('Location: http://trains.im/location/' . $loc);
	} else {
		header('Location: http://trains.im/');
	}
} else {

  $safe_pages = array("about", "disclaimer", "hsp", "contact", "donation", "nationalmap", "ppm", "ppmhistorical");
include("header.php");
  if($params[1] == "") {
    include("main.php");
  } elseif(in_array($params[1], $safe_pages)) {  
    include($params[1].".php");  
  } else {  
    include("404.php");  
  }  
include("footer.php");

}
?>
