\n";
return $nav;
}
function _navbarlangs ($what, $where, $dir) {
global $db;
$nav = "
$what:\n";
$db->Exec ("select pk, lang, cnt from langs join (select fk_langs, count (fk_langs) as cnt from mn_books_langs group by fk_langs having count (fk_langs) $where) as sums on pk = fk_langs order by lang;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$lang = $db->Get ("lang", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " $lang \n";
} while ($db->NextRow ());
}
$nav .= "
\n";
return $nav;
}
function _navbarloccs ($what, $dir) {
global $db;
$nav = "
$what:\n";
$db->Exec ("select pk, locc, cnt from loccs join (select fk_loccs, count (fk_loccs) as cnt from mn_books_loccs group by fk_loccs) as sums on pk = fk_loccs order by fk_loccs;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$pku = strtoupper ($pk);
$locc = $db->Get ("locc", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " $pku \n";
} while ($db->NextRow ());
}
$nav .= "
\n";
return $nav;
}
function _navbarcategories ($what, $dir) {
global $db;
$nav = "
$what:\n";
$db->Exec ("select pk, category, cnt from categories join (select fk_categories, count (fk_categories) as cnt from mn_books_categories group by fk_categories) as sums on pk = fk_categories order by category;");
if ($db->FirstRow ()) {
do {
$pk = $db->Get ("pk", SQLINT);
$category = $db->Get ("category", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " $category \n";
} while ($db->NextRow ());
}
$nav .= "
\n";
return $nav;
}
function navbar () {
global $dir_authors, $dir_titles, $dir_langs, $dir_loccs, $dir_categories, $dir_recent, $lang_thres;
$nav = "
\n";
$nav .= _navbar ("Authors", $dir_authors);
$nav .= _navbar ("Titles", $dir_titles);
$nav .= _navbarlangs ("Languages with more than $lang_thres books", "> $lang_thres", $dir_langs);
$nav .= _navbarlangs ("Languages with up to $lang_thres books", "<= $lang_thres", $dir_langs);
// $nav .= _navbarloccs ("LoC Class", $dir_loccs);
$nav .= _navbarcategories ("Special Categories", $dir_categories);
$nav .= _navbarrecent ("Recent", $dir_recent);
$nav .= "
\n\n";
return $nav;
}
function pagefooterfile ($file) {
global $page;
$page->footer ();
$output = ob_get_contents ();
ob_clean ();
$hd = fopen ($file, "w");
if ($hd) {
fwrite ($hd, $output);
fclose ($hd);
}
$hd = gzopen ("$file.gzip", "w9");
if ($hd) {
gzwrite ($hd, $output);
gzclose ($hd);
}
}
function LoadTitles () {
global $db, $authors;
foreach ($authors as $fk_authors => $dummy) {
$authors[$fk_authors]['titles'] = array ();
// echo ("$fk_authors\n");
}
if ($db->FirstRow ()) {
do {
$o = array ();
$fk_authors = $db->get ("fk_authors", SQLINT);
if (empty ($fk_authors))
$fk_authors = 0;
// echo ("fk_authors: $fk_authors\n");
$o['title'] = str_replace ("\n", " endtag>",
strip_marc_subfields (htmlspecialchars ($db->get ("title", SQLCHAR))));
$o['lang'] = $db->get ("lang", SQLCHAR);
$o['etext'] = $db->get ("fk_books", SQLINT);
$o['is_audio'] = $db->get ("is_audio", SQLBOOL);
$o['role'] = $db->get ("role", SQLCHAR);
array_push ($authors[$fk_authors]['titles'], $o);
} while ($db->NextRow ());
}
}
function pklist ($aa) {
// make a list of all authors with titles
$pklist = array ();
foreach ($aa as $fk_authors => $o) {
if (count ($o['titles'])) {
$pklist[] = $fk_authors;
}
}
return $pklist;
}
function FormatAliases ($pklist, $mode = 0, $regex = "") {
global $db, $lines, $authors;
if (count ($pklist) == 0)
return;
$list = join (",", $pklist);
$db->exec ("select fk_authors, alias from aliases " .
"where aliases.alias_heading = 1 and fk_authors in ($list)");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$alias = $db->get ("alias", SQLCHAR);
$author = $authors[$fk_authors]['author'];
if ($mode == 1) {
if (!preg_match ("/$regex/i", $alias))
continue;
// the by-author pages need a different url
$href = find_browse_page ($author) . "#a$fk_authors";
} else {
$href = "#a$fk_authors";
}
$html_alias = htmlspecialchars ($alias);
$html_author = htmlspecialchars ($author);
$lines[$alias] = "