<?php

include "navigation.php";

function emit($string) {
  echo $string . "\n";
}

function user2author($user) {
  if ($user == "koller") {
    return "<a href='mailto:koller@coli.uni-sb.de'>Alexander Koller</a>";
  } else if ($user == "mcqm" || $user == "kuhlmann") {
    return "<a href='mailto:kuhlmann@ps.uni-sb.de'>Marco Kuhlmann</a>";
  } else if ($user == "stth") {
    return "<a href='mailto:stth@coli.uni-sb.de'>Stefan Thater</a>";
  } else {
    return $user;
  }
}

function emit_header($title) {
  $dtd_tag = "-//W3C//DTD XHTML 1.0 Strict//EN";
  $dtd_url = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";

  emit('<?xml version="1.0" encoding="ISO-8859-1"?>');
  emit('<!DOCTYPE html PUBLIC "' . $dtd_tag . '" "' . $dtd_url . '">');
  emit('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">');
  emit('<head>');
  emit('<title>' . $title . '</title>');
  emit('<link rel="stylesheet" type="text/css" href="style.css" />');

  # Google Analytics code
  emit('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">');
  emit('</script>');
  emit('<script type="text/javascript">');
  emit('_uacct = "UA-3077708-1";');
  emit('urchinTracker();');
  emit('</script>');

  emit('</head>');



  emit('<body>');
  emit('<div class="imagebar">');
  emit('<img src="utool.png" alt="utool logo" />');
  emit('</div>');
}

function emit_footer($filename) {
  $change = filemtime("$filename");
  $fowner = posix_getpwuid(fileowner("$filename"));
  $author = user2author($fowner["name"]);

  setlocale (LC_TIME, "en_GB");

  emit('<div class="footer">');
  emit('<address>');
  emit('Last Change: ' . strftime ("%c", $change));
  emit(' | ');
  emit($author);
  emit('</address>');
  emit('</div>');
  emit('</body>');
  emit('</html>');
}

function start_mainpage() {
  emit("<!-- main page -->");
  emit("<div class='main'>");
}

function end_mainpage() {
  emit("</div>");
}

if (! isset($whoami)) {
  $whoami = $_GET['id'];
}

if (! isset($whoami)) {
  $whoami = 'index';
}

$pt = readtree();

emit_header($pt->title);

// output navigation
$thispage = navigation($pt, $whoami);

// output contents
start_mainpage();
contents($thispage);
end_mainpage();

emit_footer("contents/$whoami.html");

?>
