\n\n"; } function startPage($title,$doctype="",$subTitle="") { $home = HOME; $ccode = CCODE; $cterm = CTERM; $cname = CNAME; $titl = str_replace("
"," - ",$title); $html = << $ccode $cterm - $titl xxHTMLxx ; if (strpos($doctype,"q+a") !== false) { $html .= << function changeText(el, newText) { // Safari work around if (el.innerText) el.innerText = newText; else if (el.firstChild && el.firstChild.nodeValue) el.firstChild.nodeValue = newText; } function toggleVisible(elid) { el1 = document.getElementById(elid); el2 = document.getElementById(elid+"a"); if (el1.style.display == "") { el1.style.display = "none"; changeText(el2,"show answer"); } else { el1.style.display = ""; changeText(el2,"hide answer"); } } xxHTMLxx ; } $html .= <<
$ccode $cterm $title
$subTitle
$cname
xxHTMLxx ; if (strpos($doctype,"draft") !== false) { $html .= <<Draft xxHTMLxx ; } return $html; } function courseURL($path) { return HOME."/$path"; } function courseFile($path) { return HOMEDIR."/$path"; } function pgURL($path) { return PGDOC."/$path"; } function href($url, $label, $new_win=true) { if (strpos($url,"http://") === false) $url = "http://$url"; $target = $new_win ? "target=\"_blank\"" : ""; return "$label"; } function scriptMenu($menu) { $scriptFile = $_SERVER['SCRIPT_FILENAME']; $items = array(); foreach ($menu as $script => $title) { if (strpos($scriptFile,$script) !== false) $items[] = "[$title]"; else $items[] = "[$title]"; } return "

".join("  ",$items)."

\n"; } function showContents($contents) { $nmissing = 0; $nfound = 0; echo "
\n"; foreach ($contents as $item) { if (!preg_match('/^https?:/',$item[0]) && !file_exists($item[0])) $nmissing++; else { $nfound++; echo "

", "$item[1]"; if (count($item) > 2) echo "
($item[2])"; echo "

\n"; } } if ($nfound == 0 || $nmissing > 0) echo "

More to come ...

\n"; echo "
\n"; } function showAnswer($a) { global $qid; $qid++; $view = isset($_GET["view"]) ? $_GET["view"] : ""; switch ($view) { case "qo": # questions only => nothing to show for answers break; case "all": echo "
", "

Answer:

\n$a
\n"; break; default: $noshow = "color:#000099;display:none"; echo "

[", "show answer]

\n", "
\n", "$a\n

\n"; } } function startAnswer() { global $qid; $qid++; $view = isset($_GET["view"]) ? $_GET["view"] : ""; switch ($view) { case "qo": # questions only => nothing to show for answers break; case "all": echo "
", "

Answer:

\n"; break; default: $noshow = "color:#000099;display:none"; echo "

[", "show answer]

\n", "
\n"; } } function endAnswer() { echo "
\n"; } function alternativeViews() { if (isset($_GET["view"])) return; $url = $_SERVER['SCRIPT_NAME']; echo "

", "[Show with no answers]", "   ", "[Show with all answers]", "

\n"; } function codeFile($fname,$label="") { $code = codeIn($fname); if ($label == "") $label = $fname; if (strpos($code,"Can't find code") !== false) return "

$code

\n"; else return "

$label". "

$code
\n"; } function newCodeIn($fname,$language="C") { if (!file_exists($fname)) return "Can't find code file $fname\n"; else return codeString(file_get_contents($fname),$language); } function codeIn($fname,$language="C") { $lines = @file_get_contents($fname); if ($lines !== false) return htmlentities($lines); else return "Can't find code file $fname\n"; } function codeString($str,$language="C",$line_nums=true) { require_once(HOMEDIR."/lib/geshi.php"); $g = new GeSHi($str,$language); if ($line_nums) $g->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); return $g->parse_code(); //return htmlentities($str); } function showQandA($q,$a) { echo "
    \n"; for ($i = 0; $i < count($q); $i++) { $n = $i+1; $id1 = "Q$n"; $id2 = "Q$n"."a"; echo "

  1. $q[$i]\n", "

    [", "show answer]

    \n", "
    \n", "$a[$i]\n
  2. \n"; } echo "
\n"; } function showItems($items) { echo "
\n"; foreach ($items as $item => $info) { echo "", "\n"; } echo "
$item ", "(Posted $info[0])
$info[1]
\n"; } function updateBlurb() { $mtime = lastChanged(); return << Last updated: $mtime
Most recent changes are shown in red;
older changes are shown in brown. xxHTMLxx ; } function lastChanged() { $mtime = filemtime($_SERVER["SCRIPT_FILENAME"]); return date("l jS F g:ia",$mtime); } function diagram($pic) { return "
\n"; } class QA { var $qno = 0; var $subqno = 0; var $qas = array(); function add($q,$a=null) { $this->qno++; $this->subqno = 0; $arr = array($q,$a,null); $this->qas[$this->qno] = $arr; } function addSub($q,$a) { $arr = $this->qas[$this->qno]; $subs = $arr[2]; if (is_null($subs)) $subs = array(); $subqa = array($q,$a); $subs[] = $subqa; $arr[2] = $subs; $this->qas[$this->qno] = $arr; } function show() { echo "
    \n"; $i = 0; foreach ($this->qas as $qa) { $i++; $id1 = "Q$i"; $id2 = "Q$i"."a"; echo "

  1. \n$qa[0]\n\n"; if (!is_null($qa[2])) { echo "
      \n"; $j = 0; foreach ($qa[2] as $subqa) { $j++; $id3 = "Q$i.$j"; $id4 = "Q$i.$j"."a"; echo "
    1. \n$subqa[0]\n", "
      [", "show answer]

      \n", "

      \n", "$subqa[1]\n
    2. \n"; } echo "
    \n"; } if (!is_null($qa[1])) { echo "

    [", "show answer]

    \n", "
    \n", "$qa[1]\n
  2. \n"; } } echo "
\n"; } } function demo($cmd,$head=0,$tail=0) { $all = split("\n",shell_exec($cmd)); $nlines = count($all); if ($head == 0 && $tail == 0) { # show all lines in command output # so no filtering required here $lines = $all; } elseif ($tail == 0) { if ($nlines <= $head) $lines = $all; else { $lines = array_slice($all,0,$head); $lines[] = "...\n"; } } elseif ($head == 0) { if ($nlines <= $tail) $lines = $all; else { $t = array_slice($all,$nlines-$tail-1); $lines = array_merge(array("..."),$t); } } else { if ($nlines <= ($head+$tail+1)) $lines = $all; else { $h = array_slice($all,0,$head); $h[] = "..."; $t = array_slice($all,$nlines-$tail-1); $lines = array_merge($h,$t); } } $cmd = str_replace("\n","\n>\t",$cmd); echo "$ $cmd\n"; echo join("\n",$lines); } function tableOfContents($dir,$files) { $html = "\n"; foreach ($files as $name => $description) { if (strpos($name,".php") !== false) $link = "$name.txt"; else $link = $name; if ($dir == "" || $dir == ".") $fileLink = "$name"; else $fileLink = "$dir/$name"; $html .= "\n"; } return "$html\n
File Description
$fileLink$description
\n"; } function dueDate($item) { $ccode = CCODE; $cterm = CTERM; $item = str_replace(" ","+",$item); $url = "http://webapps.cse.unsw.edu.au/webcms2/assessment/". "due_date.php?course=$ccode+$cterm&item=$item"; $date = file_get_contents($url); return empty($date) ? "???" : $date; } ?>