<?php
include("../lib/Template.inc");

if (isset($_GET["contents"])) {
	//get rid of undesired formatting of the get parameters
	$correctedString = str_replace(" ", "_", strtolower(urldecode($_GET["contents"])));
    $filename = "contents/".$correctedString.".html.brick";
}
if (empty($_GET["contents"])) { //default page
    $filename = "contents/main.html.brick";
}
if (!file_exists($filename))
	$filename = "contents/404.html.brick";
	
//contents
$handle = fopen($filename, "r");
$contents["text"] = fread($handle, filesize($filename));
$contents["last_update"] = date("F jS Y", filemtime($filename));
fclose($handle);

//navigation menu
$filename = "contents/menu.html.brick";
$handle = fopen($filename, "r");
$contents["menu"] = fread($handle, filesize($filename));
fclose($handle);

$tpl = new Template("tpl_tools_workshop.htm");
$tpl->insertValues($contents, false);
echo $tpl->getText();
?>
