<?php // $Id: index.php,v 1.6 2005/03/22 18:35:16 jmvedrine Exp $
// ----------------------------------------------------------------------
// BOOKS module
// Copyright (C) 2002 by Michael Schatz
// Written by Michael Schatz and Jason Levitt and Olivier Guillet
// Get the newest version at http://sourceforge.net/projects/pn-mod-books
// ----------------------------------------------------------------------
// POSTNUKE Content Management System
// Copyright (C) 2002 by the PostNuke Development Team.
// http://www.postnuke.com
// ----------------------------------------------------------------------
if (!defined("LOADED_AS_MODULE"))
{
die ("You can't access this file directly...");
}
$ModName = basename( dirname( __FILE__ ) );
modules_get_language();
$modurl="modules.php?op=modload&name=$ModName&file=index"; //Shorten url text
// get all of our variables cleanly
list($req,
$query,
$min,
$max,
$orderby,
$show,
$bkid,
$ttitle,
$title,
$author,
$isbn,
$cat,
$description,
$modifysubmitter,
$nname,
$email,
$ratingbkid,
$ratinguser,
$rating,
$ratinghost_name,
$ratingcomments,
$sid,
$cid,
$orderid,
$ratenum,
$ratetype,
$selectdate,
$newbookshowdays,
$highlight) = pnVarCleanFromInput('req',
'query',
'min',
'max',
'orderby',
'show',
'bkid',
'ttitle',
'title',
'author',
'isbn',
'cat',
'description',
'modifysubmitter',
'nname',
'email',
'ratingbkid',
'ratinguser',
'rating',
'ratinghost_name',
'ratingcomments',
'sid',
'cid',
'orderid',
'ratenum',
'ratetype',
'selectdate',
'newbookshowdays',
'highlight');
include("modules/$ModName/bk-config.php");
include("modules/$ModName/bk-util.php");
include("modules/$ModName/bk-navigation.php");
include("modules/$ModName/bk-categories.php");
/*--------------------------------------------------------------------------
* function ShowBook
*--------------------------------------------------------------------------
* purpose write book-content of abkid to screen. Searches in books_books
* for data. this is the place to edit the apearrance of the books.
* the only one.
* input $abkid the book id to show
* $highlight a text to highlight
* output -
* changes 2001-09-20 [MS] introduced this central function
* 2001-09-21 [MS] function enhanced, links to order1..3 added
* 2001-09-24 [MS] show editorial
* 2001-10-04 [MS] Categories as a link
* 2001-11-06 [MS] Better support for Netscape
* 2002-01-15 [MS] admin edit link added; submitter info added
* 2002-02-15 [MS] parameter $emptext added; emphasize functionality added
*--------------------------------------------------------------------------*/
function showbook($abkid, $highlight="") {
$dbconn =& pnDBGetConn(true);
pnModDBInfoLoad('books');
$pntable =& pnDBGetTables();
$prefix = pnConfigGetVar('prefix');
$bookstable = $pntable['books_books'];
$categoriestable = $pntable['books_categories'];
$subcategoriestable = $pntable['books_subcategories'];
$editorialstable = $pntable['books_editorials'];
$booksdir=pnModGetVar('books','booksdir');
$sql = "select bkid, cid, sid, isbn, title, author, description, date, order1,
order2, order3, order4, order5, order6, cover, submitter, hits,
bookratingsummary, totalvotes, totalcomments from $bookstable where bkid = '" . (int)pnVarPrepForStore($abkid) . "'";
$result = $dbconn->Execute($sql);
$numrows = $result->PO_RecordCount();
$urlinsfunc=pnModGetVar('books','urlinsfunc');
$emptyimage=pnModGetVar('books','emptyimage');
if ($numrows == 1) {
list($bkid, $cid, $sid, $isbn, $title, $author, $description, $addedtime, $order1, $order2, $order3, $order4, $order5, $order6, $cover, $submitter, $hits, $bookratingsummary, $totalvotes, $totalcomments)= $result->fields;
//Must have read access to see books in category
if (pnSecAuthAction(0,'books::Category', "$title::$cid", ACCESS_READ))
{
$bookratingsummary = number_format($bookratingsummary, $mainvotedecimal);
// Make authors name clickable
if (pnModGetVar('books','authorsclickable')) {
$authors = explode( pnModGetVar('books','authorsseparator'), $author);
$author = "";
$flag = false;
foreach ($authors as $aut) {
$query = urlencode($aut);
if ($flag) {
$author .= pnModGetVar('books','authorsseparator');
}
$author .= "<a href=\"modules.php?op=modload&name=books&file=index&req=search&query=$query\">$aut</a>";
$flag = true;
}
}
//transform hooks
//set variable for pn_highlight
if ($highlight!='') {
$highlight = urldecode($highlight);
pnSessionSetVar('highlight', $highlight);
$viewdetailsurl = "$urlinsfunc=view_book_details&bkid=$bkid&highlight=".urlencode($highlight);
} else {
$viewdetailsurl = "$urlinsfunc=view_book_details&bkid=$bkid";
}
list($description, $title, $author) = pnModCallHooks('item', 'transform', '', array($description, $title, $author));
pnSessionDelVar('highlight');
if ($cover == "") {
$coverimg = "modules/".pnVarPrepForOS($GLOBALS['name'])."/images/".$emptyimage;
} else {
if (stristr($cover, "http")) {
$coverimg = $cover;
} else {
$coverimg = $booksdir.'/'.$cover;
}
}
echo "<!-- Book Details for ID:$abkid -->\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
echo "<tr valign=\"top\"><td valign=\"top\" rowspan=\"4\"><a href=\"$viewdetailsurl\"><img src=\"$coverimg\" border=\"0\" alt=\"book cover\"></a></td>\n";
echo "</tr>\n";
echo "<tr valign=\"top\"><td valign=\"top\"><font class=\"pn-title\"><strong><a href=\"$viewdetailsurl\">".pnVarPrepHTMLDisplay($title)."</a></strong></font><font class=\"pn-normal\">\n";
newbookgraphic($addedtime);
popgraphic($hits);
echo "<br /><br />\n";
/* get the categories */
$sql = "select title from $categoriestable where cid=$cid";
$result2 = $dbconn->Execute($sql);
list($ctitle) = $result2->fields;
echo "<i>"._CATEGORY." </i>: <a class=\"pn-normal\" href=\"$urlinsfunc=view_cat&cid=$cid\">".pnVarPrepHTMLDisplay($ctitle)."</a>";
$sql = "select title from $subcategoriestable where sid=$sid";
$result3 =$dbconn->Execute($sql);
while(list($stitle) = $result3->fields) {
echo " / <a class=\"pn-normal\" href=\"$urlinsfunc=view_subcat&sid=$sid\">".pnVarPrepHTMLDisplay($stitle)."</a>";
$result3->MoveNext();
}
echo "</font><br /><br />\n";
echo "<font class=\"pn-normal\"><i>"._BOOKAUTHOR." </i>: ".pnVarPrepHTMLDisplay($author)." <br /><br /></font>\n";
echo "<font class=\"pn-normal\"><i>"._BOOKISBN." </i>: $isbn <br /></font></td>\n";
echo "<td valign=\"top\" align=right>";
if ($order1 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=1\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO1."\" border=\"0\" alt=\""._BOOKORDER._ORDER1."\"></a><br />\n";
if ($order2 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=2\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO2."\" border=\"0\" alt=\""._BOOKORDER._ORDER2."\"></a><br />\n";
if ($order3 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=3\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO3."\" border=\"0\" alt=\""._BOOKORDER._ORDER3."\"></a><br />\n";
if ($order4 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=4\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO4."\" border=\"0\" alt=\""._BOOKORDER._ORDER4."\"></a><br />\n";
if ($order5 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=5\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO5."\" border=\"0\" alt=\""._BOOKORDER._ORDER5."\"></a><br />\n";
if ($order6 > "!") echo "<a class=\"pn-normal\" href=\"$urlinsfunc=visit&bkid=$bkid&orderid=6\" target=\"new\"><img src=\"modules/".pnVarPrepForOS($GLOBALS['name'])."/images/"._BOOKLOGO6."\" border=\"0\" alt=\""._BOOKORDER._ORDER6."\"></a><br />\n";
echo "</td></tr>\n";
echo "<tr valign=\"top\"><td valign=\"top\" colspan=\"2\"><font class=\"pn-normal\">\n";
echo "<font class=\"pn-normal\"><i>"._DESCRIPTION." </i>: ".pnVarPrepHTMLDisplay($description)."<br /></font>";
/* editor review*/
$sql = "SELECT adminid, editorialtimestamp, editorialtext, editorialtitle FROM $editorialstable WHERE bookid = '" . (int)pnVarPrepForStore($bkid) . "'";
$result4 = $dbconn->Execute($sql);
$recordexist = $result4->PO_RecordCount();;
if ($recordexist != 0) {
while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle) = $result4->fields) {
//transform hooks
list($editorialtext) = pnModCallHooks('item', 'transform', '', array($editorialtext));
$formatted_date = formatdate(_DATEFORMAT, $editorialtimestamp);
echo "<br /><font class=\"pn-normal\"><i>"._BOOKEDITORIAL." </i>: ".pnVarPrepHTMLDisplay($editorialtitle)."<br />\n"
.pnVarPrepHTMLDisplay($editorialtext)." <br />["._BOOKEDITADDED." ".pnVarPrepForDisplay($formatted_date)." "._BY." $adminid]</font><br />\n";
$result4->MoveNext();
}
}
echo "</font></td></tr>\n";
$formattedaddedtime = formatdate(_DATEFORMAT, $addedtime);
echo "<tr><td colspan=\"2\">";
if ($submitter == "") {
echo "<font class=\"pn-normal\"><i>"._ADDEDON."</i> : ".pnVarPrepForDisplay($formattedaddedtime)."<br />\n";
} else {
echo "<font class=\"pn-normal\"><i>"._ADDEDON."</i> : ".pnVarPrepForDisplay($formattedaddedtime)." <i>"._BY."</i> <a href=\"user.php?op=userinfo&uname=$submitter\" class=\"pn-normal\">$submitter</a><br />\n";
}
echo "<i>"._HITS."</i>: $hits";
/* voting & comments stats */
if ($totalvotes != 0) {
$votestring = (($totalvotes == 1) ? "._VOTE." : "._VOTES.");
if ($bookratingsummary!="0" || $bookratingsummary!="0.0") {
echo " <i>"._RATING."</i> <a class=\"pn-normal\" href=\"$viewdetailsurl\">"._DETAILSP."</a>: ".books_ratemakestar($bookratingsummary, 10)." \n";
}
}
if ($totalcomments != 0) {
echo " <a class=\"pn-normal\" href=\"$urlinsfunc=view_book_comments&bkid=$bkid\">"._SCOMMENTS." ($totalcomments)</a> \n";
}
echo "<br />\n";
//Only show menu options if permissions are sufficient
if (pnSecAuthAction(0,'books::', '::', ACCESS_COMMENT)) {
echo "<a class=\"pn-normal\" href=\"$urlinsfunc=rate_book&bkid=$bkid\">"._RATEBOOK."</a>\n";
echo "| <a class=\"pn-normal\" href=\"$urlinsfunc=modify_book_request&bkid=$bkid\">"._REQUESTBOOKMOD."</a> |\n";
}
if (pnSecAuthAction(0,'books::', '::', ACCESS_READ)) {
echo "<a class=\"pn-normal\" href=\"$urlinsfunc=broken_link&bkid=$bkid\">"._REPORTBROKEN."</a>\n";
}
echo "</font></td></tr>\n";
echo "</table>";
} /* close authorization */
}
}
if (!pnSecAuthAction(0, 'books::', '::', ACCESS_READ)) {
echo _BOOKSNOACCESS;
include 'footer.php';
return;
}
switch($req) {
case "search":
include_once("modules/$ModName/bk-search.php");
include_once("modules/$ModName/bk-showdetails.php");
search($query, $min, $orderby, $show);
break;
case "rate_book":
include_once("modules/$ModName/bk-rating.php");
ratebook($bkid);
break;
case "add_book_form":
include_once("modules/$ModName/bk-modbooks.php");
addbookform();
break;
case "add_book":
include_once("modules/$ModName/bk-modbooks.php");
addbook($title, $author, $isbn, $cat, $description, $nname, $email);
break;
case "add_rating":
include_once("modules/$ModName/bk-rating.php");
addrating($ratingbkid, $ratinguser, $rating, $ratinghost_name, $ratingcomments);
break;
case "broken_link":
include_once("modules/$ModName/bk-modbooks.php");
brokenlink($bkid);
break;
case "broken_link_submit":
include_once("modules/$ModName/bk-modbooks.php");
brokenlinksubmit($bkid, $modifysubmitter);
break;
case "modify_book_request":
include_once("modules/$ModName/bk-modbooks.php");
modifybookrequest($bkid);
break;
case "modify_book_submit":
include_once("modules/$ModName/bk-modbooks.php");
modifybooksubmit($bkid, $cat, $title, $author, $description, $modifysubmitter);
break;
case "view_book_comments":
include_once("modules/$ModName/bk-showdetails.php");
viewbookcomments($bkid);
break;
case "view_book_details":
include_once("modules/$ModName/bk-showdetails.php");
viewbookdetails($bkid, $highlight);
break;
case "random_book":
include_once("modules/$ModName/bk-showcat.php");
randombook();
break;
case "view_subcat":
include_once("modules/$ModName/bk-showcat.php");
viewsubcat($sid, $min, $orderby, $show);
break;
case "view_cat":
include_once("modules/$ModName/bk-showcat.php");
viewcat($cid, $min, $orderby, $show);
break;
case "new_books":
include_once("modules/$ModName/bk-showcat.php");
newbooks($newbookshowdays);
break;
case "new_books_date":
include_once("modules/$ModName/bk-showcat.php");
newbooksdate($selectdate);
break;
case "top_rated":
include_once("modules/$ModName/bk-showcat.php");
toprated($ratenum, $ratetype);
break;
case "most_popular":
include_once("modules/$ModName/bk-showcat.php");
mostpopular($ratenum, $ratetype);
break;
case "visit":
visit($bkid, $orderid);
break;
default:
index($bkid, $highlight);
break;
}
?>