// glossary.php
// This page will display the definition for a specified term. It can
// also generate/format a page containing the entire glossary.
include("dbsetup.php"); // connect to database
include("patternsubs.php"); // genheader() is here
include("glossarysubs.php"); // common functions
if (!isset($_SERVER["REQUEST_METHOD"]) ||
$_SERVER["REQUEST_METHOD"] != "GET") {
} else if (isset($_GET["termid"])) {
// ok, do we need two things here? One would just return the
// data from the db (in DL/DD format...?) and the other would
// generate a real page?? What will the javascript want?
// we should probably avoid this extra lookup if possible
$termid = $_GET["termid"];
$term = get_glossary_name_by_id($termid);
genheader("Juggling term $term");
print_entry_by_id($termid);
} else if (isset($_GET["term"])) {
// search by name! (use aliases as backup)
} else {
// just dump the whole thing
$qs = "SELECT *
FROM glossary
WHERE parentid = 0
ORDER BY term";
$gr = mysql_query($qs)
or die("Cannot query glossary: " . mysql_error() . "
" . $qs);
genheader("Glossary of juggling/passing terms");
?>
All of the juggling terms you will need to know (or perhaps simply all of the ones which we know)
// loop through the retrieved tuples/rows
while ($gl_row = mysql_fetch_array($gr)) {
// only treat primary entries
if ($gl_row["parentid"]) continue;
// print an entry
print_glossary_entry($gl_row);
}
}
function print_entry_by_id($termid) {
$qs = "SELECT *
FROM glossary
WHERE termid = '$termid'";
$qr = mysql_query($qs)
or die("Cannot query glossary: " . mysql_error() . "
" . $qs);
// shouldn't we first check for direct hit???
if (mysql_num_rows($qr) != 1) {
printf("Termid %s unrecognized
\n", $termid);
return;
}
print_glossary_entry(mysql_fetch_array($qr));
}
function print_glossary_entry(&$term_row) {
// entry header
printf("\n");
// names the term goes by, first the primary name
printf("- %s
\n",
$term_row["term"], $term_row["term"]);
// retrieve any aliases
$as = "SELECT * FROM glossaryalias
WHERE termid = " . $term_row["termid"];
$ar = mysql_query($as)
or die("Cannot query glossary alias: " . mysql_error() . "
" . $as);
while (list($term_alias) = mysql_fetch_row($ar)) {
printf("- %s
\n", $term_alias, $term_alias);
}
// definition time
$do = new specialText($term_row["definition"]);
printf("- %s\n", $do->getHTML());
// children are part of the definition
print_children($term_row["termid"]);
printf("
\n");
}
function print_children($tid) {
$qs = "SELECT * FROM glossary WHERE parentid = " . $tid .
" ORDER BY term";
$qr = mysql_query($qs)
or die("Cannot query children in glossary: " . mysql_error() . "
" . $qs);
while ($term_row = mysql_fetch_array($qr)) {
print_glossary_entry($term_row);
}
}
include("copynotice.php");
?>