<?php // $Id: functions.php,v 1.17 2002/02/15 11:16:18 micha Exp $
// ----------------------------------------------------------------------
// BOOKS module
// Copyright (C) 2001, 2002 by IB Rahn, http://www.ib-rahn.de
// Written by Michael Schatz, hide@address.com
// get the newest version at http://www.bauphysik.com
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// This software is GPL'd. Please read /docs/credits.txt and /docs/license.txt
// ----------------------------------------------------------------------
/*--------------------------------------------------------------------------
* function menu
*--------------------------------------------------------------------------
* purpose write main menu
* input mainlink : > 0 writes a link to index page
* output -
* changes 2001-09-21 [MS] show ADDBOOK only for users
* 2001-11-19 [MS] $menulink defaults to zero
*--------------------------------------------------------------------------*/
function menu($mainlink=0) {
global $sitename, $user, $modset, $query;
OpenTable();
echo "<br><center><a class=\"pn-logo\" href=\"$modset[baseurl]\">$sitename -- "._BOOKPAGETITLE."</a><br><br>";
echo "<form action=\"$modset[baseurl]&req=search&query=$query\" method=\"post\">"
."<font class=\"pn-normal\"><input type=\"text\" size=\"25\" name=\"query\" style=\"width:80%\"> <input type=\"submit\" value=\""._SEARCH."\"></font>"
."</form>";
echo "<font class=\"pn-normal\">[ ";
if ($mainlink > 0) {
echo "<a class=\"pn-normal\" href=\"$modset[baseurl]\">"._BOOKSMAIN."</a> | ";
}
if (is_user($user)) {
echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]add_book_form\">"._ADDBOOK."</a> | ";
}
echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]new_books\">"._NEWBOOKS."</a> | "
."<a class=\"pn-normal\" href=\"$modset[baseurl3]most_popular\">"._POPULAR."</a> | "
."<a class=\"pn-normal\" href=\"$modset[baseurl3]top_rated\">"._TOPRATED."</a> | "
."<a class=\"pn-normal\" href=\"$modset[baseurl3]random_book\">"._RANDOM."</a> ]"
."</font></center>";
CloseTable();
}
/*--------------------------------------------------------------------------
* function SearchForm
*--------------------------------------------------------------------------
* purpose write search form to screen
* input -
* output -
* changes -
*--------------------------------------------------------------------------*/
function SearchForm($query) {
global $modset, $query;
echo "<form action=\"$modset[baseurl]&req=search&query=$query\" method=\"post\">"
."<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">"
."<tr><td><font class=\"pn-normal\"><input type=\"text\" size=\"25\" name=\"query\"> <input type=\"submit\" value=\""._SEARCH."\"></td></tr>"
."</table>"
."</form>";
}
/*--------------------------------------------------------------------------
* function BookInfoMenu
*--------------------------------------------------------------------------
* purpose write a info-menu for a given book
* input bkid : a book id
* ttitle : templated title
* output -
* changes -
*--------------------------------------------------------------------------*/
function BookInfoMenu($bkid, $ttitle) {
global $modset;
echo "<br><font class=\"pn-normal\">[ "
."<a class=\"pn-normal\" href=\"$modset[baseurl3]view_book_comments&bkid=$bkid&ttitle=$ttitle\">"._BOOKCOMMENTS."</a>"
." | <a class=\"pn-normal\" href=\"$modset[baseurl3]view_book_details&bkid=$bkid&ttitle=$ttitle\">"._ADDITIONALDET."</a>"
." | <a class=\"pn-normal\" href=\"$modset[baseurl3]view_book_editorial&bkid=$bkid&ttitle=$ttitle\">"._EDITORREVIEW."</a>"
." | <a class=\"pn-normal\" href=\"$modset[baseurl3]modify_link_request&bkid=$bkid\">"._MODIFY."</a>"
." | <a class=\"pn-normal\" href=\"$modset[baseurl3]broken_link&bkid=$bkid\">"._REPORTBROKEN."</a> ]</font>";
}
/*--------------------------------------------------------------------------
* function PopGraphic
*--------------------------------------------------------------------------
* purpose show a graphic for 'popular' links
* input $hits
* output -
* changes -
*--------------------------------------------------------------------------*/
function PopGraphic($hits) {
global $popular, $modset;
if ($hits >= $popular) {
echo " <img src=\"$modset[imagepath]/pop.gif\" alt=\""._POPULAR."\" border=\"0\">";
}
} // end PopGraphic
/*--------------------------------------------------------------------------
* function NewBookGraphic
*--------------------------------------------------------------------------
* purpose print a grafic, if it is a "new" book
* input $adate : date to check
* output -
* changes 2001-09-24 [MS] only $adate input, error fixed
*--------------------------------------------------------------------------*/
function NewBookGraphic($adate) {
global $modset;
echo " ";
setlocale ("LC_TIME", "$locale");
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $adate, $tmpdate);
$bookdate = date("d-M-Y",mktime(0,0,0,$tmpdate[2],$tmpdate[3],$tmpdate[1]));
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = date("d-M-Y", $startdate);
if ("$daysold" == "$bookdate") {
if ($count<=1) {
echo "<img src=\"$modset[imagepath]/newred.gif\" alt=\""._NEWTODAY."\" border=\"0\">";
}
if ($count<=3 && $count>1) {
echo "<img src=\"$modset[imagepath]/newgreen.gif\" alt=\""._NEWLAST3DAYS."\" border=\"0\">";
}
if ($count<=7 && $count>3) {
echo "<img src=\"$modset[imagepath]/newblue.gif\" alt=\""._NEWTHISWEEK."\" border=\"0\">";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
}
/*--------------------------------------------------------------------------
* function web_links_rateMakeStar
*--------------------------------------------------------------------------
* purpose
* input $score
* $max_score
* output
* changes this code is take from harpia project http://sourceforge.net/projects/harpia
*--------------------------------------------------------------------------*/
function web_links_rateMakeStar($score, $max_score) {
global $modset;
$score /= 2;
$max_score /=2; // 5 stars. comment for 10 stars
$rateImgFull = "";
$rateImgHalf = "$modset[imagepath]/rate_half.gif";
$rateImgNone = "$modset[imagepath]/rate_none.gif";
if (strpos($score,".")==0){ // Break up score
$full_stars=$score;
} else {
$full_stars=substr($score,0,strpos($score,"."));
}
if (substr($score,strpos($score,".")+1)==0){ // *** Is there half star
$half_stars=0;
} else {
$half_stars=1;
}
$blank_stars=$max_score-($full_stars+$half_stars); // *** Build Star Line
$star_line="";
for ($i=1;$i<=$max_score;$i++){
if ($i<=$full_stars){
$star_line.="<img src=\"$modset[imagepath]/rate_full.gif\" border=\"0\">";
}elseif ($i<=($half_stars+$full_stars)){
$star_line.="<img src=\"$modset[imagepath]/rate_half.gif\" border=\"0\">";
}elseif ($i<=$max_score){
$star_line.="<img src=\"$modset[imagepath]/rate_none.gif\" border=\"0\">";
}
}
return $star_line;
}
/*--------------------------------------------------------------------------
* function str_emphasize
*--------------------------------------------------------------------------
* purpose emphasize aword in atext
* input $atext text wich MAY conatain aword
* $aword word to emphasize
* $acolor emphasize color
* output -
* changes 2002-02-15 [MS] introduced
*--------------------------------------------------------------------------*/
function str_emphasize($atext, $aword="", $acolor="#ffff66") {
if ($aword < "!") return $atext; // do nothing if no word is given
$atext = ereg_replace($aword, "<B style=\"color:black;background-color:".$acolor."\">".$aword."</B>", $atext);
$aword = strtoupper($aword);
$atext = ereg_replace($aword, "<B style=\"color:black;background-color:".$acolor."\">".$aword."</B>", $atext);
$aword = strtolower($aword);
$atext = ereg_replace($aword, "<B style=\"color:black;background-color:".$acolor."\">".$aword."</B>", $atext);
$aword = ucfirst($aword);
$atext = ereg_replace($aword, "<B style=\"color:black;background-color:".$acolor."\">".$aword."</B>", $atext);
return $atext;
}
/*--------------------------------------------------------------------------
* 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
* $emptext a text to emphasize
* 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, $emptext="") {
global $pntable, $modset, $emptyimage;
$result = mysql_query("select bkid, cid, sid, isbn, title, author, description, date, order1, order2, order3, cover, submitter, hits, bookratingsummary, totalvotes, totalcomments from $pntable[books_books] where bkid = $abkid");
$numrows = @mysql_num_rows($result);
if ($numrows == 1) {
list($bkid, $cid, $sid, $isbn, $title, $author, $description, $time, $order1, $order2, $order3, $cover, $submitter, $hits, $bookratingsummary, $totalvotes, $totalcomments)=mysql_fetch_row($result);
$bookratingsummary = number_format($bookratingsummary, $mainvotedecimal);
$title = stripslashes($title);
$title = str_emphasize($title, $emptext);
$author = stripslashes($author);
$author = str_emphasize($author, $emptext);
$description = stripslashes($description);
$description = str_emphasize($description, $emptext);
$coverimg = CheckImgFile($cover, $modset[imagepath].'/'.$emptyimage);
echo "<!--- Book Details for ID:$abkid --->\n";
OpenTable();
echo "<tr valign=\"top\"><td valign=\"top\" rowspan=\"4\"><img src=\"$coverimg\" border=\"0\"></td>\n";
echo "</tr>\n";
echo "<tr valign=\"top\"><td valign=\"top\"><font class=\"pn-title\"><b>$title</b></font><font class=\"pn-normal\">\n";
NewBookGraphic($time);
PopGraphic($hits);
echo "<br><br>\n";
/* get the categories */
$result2 = mysql_query("select title from $pntable[books_categories] where cid=$cid");
list($ctitle) = mysql_fetch_row($result2);
echo "<i>"._CATEGORY." </i>: <a class=\"pn-normal\" href=\"$modset[baseurl3]view_cat&cid=$cid\">$ctitle</a>";
$result3 =mysql_query("select title from $pntable[books_subcategories] where sid=$sid");
while(list($stitle) = mysql_fetch_row($result3)) {
echo " / <a class=\"pn-normal\" href=\"$modset[baseurl3]view_subcat&sid=$sid\">$stitle</a>";
}
echo "</font><br><br>\n";
echo "<font class=\"pn-normal\"><i>"._BOOKAUTHOR." </i>: $author <br><br>\n";
echo "<i>"._BOOKISBN." </i>: $isbn <br></td>\n";
echo "<td valign=\"top\" align=right>";
if ($order1 > "!") echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]visit&bkid=$bkid&orderid=1\" alt=\""._BOOKORDER._ORDER1."\" target=\"new\"><img src=\"$modset[imagepath]/"._BOOKLOGO1."\" border=\"0\" alt=\""._BOOKORDER._ORDER1."\"></a><br>\n";
if ($order2 > "!") echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]visit&bkid=$bkid&orderid=2\" alt=\""._BOOKORDER._ORDER2."\" target=\"new\"><img src=\"$modset[imagepath]/"._BOOKLOGO2."\" border=\"0\" alt=\""._BOOKORDER._ORDER2."\"></a><br>\n";
if ($order3 > "!") echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]visit&bkid=$bkid&orderid=3\" alt=\""._BOOKORDER._ORDER3."\" target=\"new\"><img src=\"$modset[imagepath]/"._BOOKLOGO3."\" border=\"0\" alt=\""._BOOKORDER._ORDER3."\"></a><br>\n";
echo "</td></tr>\n";
echo "<tr valign=\"top\"><td valign=\"top\" colspan=\"2\"><font class=\"pn-normal\">\n";
echo "<i>"._DESCRIPTION." </i>: $description<br></font>";
/* editor review*/
$result4 = mysql_query("SELECT adminid, editorialtimestamp, editorialtext, editorialtitle FROM $pntable[books_editorials] WHERE bookid = $bkid");
$recordexist = mysql_num_rows($result4);
if ($recordexist != 0) {
while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle) = mysql_fetch_row($result4)) {
$editorialtitle = stripslashes($editorialtitle);
$editorialtext = stripslashes($editorialtext);
$formatted_date = FormatDateTime(_LINKSDATESTRING,$editorialtimestamp);
echo "<br><font class=\"pn-normal\"><i>"._BOOKEDITORIAL." </i>: $editorialtitle<br>\n"
."$editorialtext <br>[$adminid - $formatted_date]</font><br>\n";
}
}
echo "</font></td></tr>\n";
$datetime = FormatDateTime(_LINKSDATESTRING, $time);
echo "<tr><td colspan=\"2\">"
."<font class=\"pn-normal\">"._ADDEDON.": $datetime "._BY." <a href=\"user.php?op=userinfo&uname=$submitter\" class=\"pn-normal\">$submitter</a><br>\n"
.""._HITS.": $hits ";
/* voting & comments stats */
if ($totalvotes != 0) {
$votestring = (($totalvotes == 1) ? "._VOTE." : "._VOTES.");
if ($bookratingsummary!="0" || $bookratingsummary!="0.0") {
echo " <a class=\"pn-normal\" href=\"$modset[baseurl3]view_book_details&bkid=$bkid\">"._RATING."</a>: ".web_links_rateMakeStar($bookratingsummary, 10)." \n";
}
}
if ($totalcomments != 0) {
echo " <a class=\"pn-normal\" href=\"$modset[baseurl3]view_book_comments&bkid=$bkid\">"._SCOMMENTS."</a> \n";
}
echo "<br>\n";
echo "<a class=\"pn-normal\" href=\"$modset[baseurl3]rate_book&bkid=$bkid\">"._RATEBOOK." ($totalcomments)</a> \n";
echo " <a class=\"pn-normal\" href=\"$modset[baseurl3]broken_link&bkid=$bkid\">"._REPORTBROKEN."</a> \n";
if (is_user($user)) {
echo " <a class=\"pn-normal\" href=\"$modset[baseurl3]modify_link_request&bkid=$bkid\">"._REQUESTBOOKMOD."</a>\n";
}
if (is_admin($admin)) {
echo " <a class=\"pn-normal\" href=\"admin.php?op=BooksModBook&bkid=$bkid\">"._MODIFY."</a>\n";
}
echo "</font></td></tr>\n";
CloseTable();
echo "<br>\n";
}
}
/*--------------------------------------------------------------------------
* function ConvertOrderByIN
*--------------------------------------------------------------------------
* purpose convert "order by" to SQL representation
* input $orderby
* output $orderby
* changes -
*--------------------------------------------------------------------------*/
function ConvertOrderByIN($orderby) {
if ($orderby == "titleA") $orderby = "title ASC";
if ($orderby == "dateA") $orderby = "date ASC";
if ($orderby == "hitsA") $orderby = "hits ASC";
if ($orderby == "ratingA") $orderby = "bookratingsummary ASC";
if ($orderby == "titleD") $orderby = "title DESC";
if ($orderby == "dateD") $orderby = "date DESC";
if ($orderby == "hitsD") $orderby = "hits DESC";
if ($orderby == "ratingD") $orderby = "bookratingsummary DESC";
return $orderby;
}
/*--------------------------------------------------------------------------
* function ConvertOrderByTRANS
*--------------------------------------------------------------------------
* purpose translate a "order by" clause
* input $orderby
* output $orderbyTrans
* changes -
*--------------------------------------------------------------------------*/
function ConvertOrderByTRANS($orderby) {
if ($orderby == "hits ASC") $orderbyTrans = ""._POPULARITY1."";
if ($orderby == "hits DESC") $orderbyTrans = ""._POPULARITY2."";
if ($orderby == "title ASC") $orderbyTrans = ""._TITLEAZ."";
if ($orderby == "title DESC") $orderbyTrans = ""._TITLEZA."";
if ($orderby == "date ASC") $orderbyTrans = ""._DATE1."";
if ($orderby == "date DESC") $orderbyTrans = ""._DATE2."";
if ($orderby == "bookratingsummary ASC") $orderbyTrans = ""._RATING1."";
if ($orderby == "bookratingsummary DESC") $orderbyTrans = ""._RATING2."";
return $orderbyTrans;
}
/*--------------------------------------------------------------------------
* function ConvertOrderByOUT
*--------------------------------------------------------------------------
* purpose convert a SQL statement to a "order by" which can be used in URL
* input $orderby
* output $orderby
* changes -
*--------------------------------------------------------------------------*/
function ConvertOrderByOUT($orderby) {
if ($orderby == "title ASC") $orderby = "titleA";
if ($orderby == "date ASC") $orderby = "dateA";
if ($orderby == "hits ASC") $orderby = "hitsA";
if ($orderby == "bookratingsummary ASC") $orderby = "ratingA";
if ($orderby == "title DESC") $orderby = "titleD";
if ($orderby == "date DESC") $orderby = "dateD";
if ($orderby == "hits DESC") $orderby = "hitsD";
if ($orderby == "bookratingsummary DESC") $orderby = "ratingD";
return $orderby;
}
function bookfooter($bkid,$ttitle) {
global $modset;
// echo "<font class=\"pn-normal\">[ <a class=\"pn-normal\" href=\"$modset[baseurl3]visit&bkid=$bkid\" target=\"_blank\">"._VISITTHISBOOK."</a> | <a class=\"pn-normal\" href=\"$modset[baseurl3]rate_book&bkid=$bkid&ttitle=$ttitle\">"._RATETHISBOOK."</a> ]</font><br><br>";
bookfooterchild($bkid);
}
function bookfooterchild($bkid) {
global $useoutsidevoting, $modset;
if ($useoutsidevoting = 1) {
echo "<br><font class=\"pn-normal\">"._ISTHISYOURBOOK."<br> <a class=\"pn-normal\" href=\"$modset[baseurl3]outsidelink_setup&bkid=$bkid\">"._ALLOWTORATEBOOK."</a></font>";
}
}
/*--------------------------------------------------------------------------
* function ShowAMessage
*--------------------------------------------------------------------------
* purpose show a (error) message on screen
* input $message : message to show
* output -
* changes 2001-09-26 [MS] introduced
*--------------------------------------------------------------------------*/
function ShowAMessage($message) {
include("header.php");
menu(1);
echo "<br>";
OpenTable();
echo "<font class=\"pn-normal\"><center><b>$message</b><br><br>"._GOBACK."</font>";
CloseTable();
include("footer.php");
}
?>