<?php
  $title = "Notes";
  $styles = array("css/template.css", "css/notes.css");
  require("include/header.php");

  $file = fopen("data/course/lecture_notes/order.txt", "r");
  if (!$file)
  {
    echo "<span class='error'>Fatal error, file missing</span>";
    exit();
  }
  echo "<form action='notes.php' method='post'>";
  echo "<select name='pdf-select' onchange='this.form.submit()'>";
  while (($line = fgets($file)))
  {
    if (substr($line, 0, 2) != "//")
    {
      $line_array = explode("\t", $line);
      $value = trim($line_array[1]);
      $text = trim($line_array[0]);

      $select = " selected";
      if (!$_POST["pdf-select"])
        $_POST["pdf-select"] = $value;
      else if ($_POST["pdf-select"] != $value)
	$select = "";
      echo "<option value='".$value."'".$select.">".$text."</option>";
    }
  }
  fclose($file);
  echo "</select>";
  echo "</form>";
?>
    <a id="back" href="course.php">&laquo; Return</a>
    <object data=<?="data/course/lecture_notes/".$_POST["pdf-select"]?>
    type="application/pdf">
      You don't have a working PDF viewer!
        <a href="notes-back.php">&lsaquo;Click here&rsaquo;</a>
      for the lecture notes.
    </object>
  </body>
</html>