<?php
/**
* Show the books that are available in the library.
*
* Copyright (C) 2005 Wayne Davison <hide@address.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require 'lib/main.inc';
main();
function main()
{
open_db();
list($uID, $scrname, $can_add) = get_auth_cookie();
if ($uID) {
add_sidebar_divider();
add_sidebar_image('btn-bookmarks', 'bkmk.php');
}
if ($can_add) {
add_sidebar_divider();
add_sidebar_image('btn-newbook', 'books.php');
}
sidebar_signin($uID, $scrname);
$early_html = <<<EOT
<div id="pbBookMenuDiv" class="menulist" onmouseover="mousein_menu()" onmouseout="mouseout_menu()"><ul>
<li><a href="javascript:first_page()">Go to First Page</a></li>
<li><a href="javascript:list_sections()">Go to Section List</a></li>
<li id=bkmk_action><a href="javascript:newest_bkmk()">Go to Newest Bookmark</a></li>
<li id=bkmk_inaction><div>Go to Newest Bookmark</div></li>
</ul></div>
EOT;
start_content('PBOS: An implementation of the Processed Book', 'wide', $early_html);
echo <<<EOT
<style>body { font-family: Tahoma; }</style>
<h2 style="margin-top:0">The Processed Book Project</h2>
EOT;
$the_overview = '<a href="http://www.prosaix.com/pbos/book-2-2.html#overview">the PBOS overview</a>';
if ($uID) {
echo <<<EOT
Please choose a book to read, or read $the_overview:
EOT;
} else {
echo <<<EOT
<blockquote style="border: solid black 1px; padding: 1em"><small>
If you're new, you may be interested in reading $the_overview.
Alternately, make note of a few simple tips to get started instantly:
<ul>
<li>Selecting text in a Book brings up a menu that will guide you in adding any of the Annotation types.
<li>The boxes in the right column are existing Annotations: clicking/right-clicking on them will do interesting things.
<li>Most buttons, menus, etc. have rollover help.
</ul>
</small></blockquote>
<p>To begin reading, choose one of these documents:
EOT;
}
echo '<ul>';
$bookmarks = array();
if ($uID) {
$do = "SELECT ID, BookID, ParentID
FROM BookAnnotations
WHERE UserID = $uID AND TypeID = 1 AND ParentID >= 0
ORDER BY ID";
$result = mysql_query($do) or die('SELECT failed: ' . mysql_error() . " (cmd: $do)");
while (($obj = mysql_fetch_object($result)) !== FALSE)
$bookmarks[$obj->BookID] = $obj->ParentID . '&t=' . $obj->ID;
}
if ($uID == 1) {
$extra = ', SectionCount, Access';
$where = '';
} else
$where = "WHERE UserID = $uID OR (SectionCount > 0 AND Access REGEXP '(^|,)($uID|0)(,|$)')";
$do = "SELECT BookID, Title, Author, Description, UserID$extra
FROM Books $where
ORDER BY Title";
$result = mysql_query($do) or die('SELECT failed: ' . mysql_error() . " (cmd: $do)");
while (($obj = mysql_fetch_object($result)) !== FALSE) {
$bn = $obj->BookID;
if ($uID == $obj->UserID || $uID == 1) {
$edit = ' ' . button('btn-editbook', "books.php?b=$bn", 'width=34 height=20');
if ($uID == 1) {
if (!$obj->SectionCount)
$edit .= ' <b>(empty)</b>';
else if ($obj->Access == '')
$edit .= ' <b>(invisible)</b>';
else if (!preg_match('/(^|,)0(,|$)/', $obj->Access))
$edit .= ' <b>(limited visibility)</b>';
}
} else
$edit = '';
echo "<li><a href='read.php?b=$bn&s=0' onclick='hide_menu()'",
" onmouseover='mousein_booktitle(this,$bn,\"{$bookmarks[$bn]}\")'",
" onmouseout='mouseout_trigger()'>",
$obj->Title, '</a> <small>by ', $obj->Author,
$edit, '</small><table width=512><tr><td><small>', $obj->Description, "</small></td></tr></table>\n";
}
if (mysql_num_rows($result) == 0)
echo "<i>There are no books in the library yet.</i>\n";
echo <<<EOT
</ul>
<script>
document.onmousedown = maybe_hide_menu;
</script>
EOT;
close_db();
end_content();
}
?>