home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / encyclopedia / index.php < prev    next >
Encoding:
PHP Script  |  2002-09-16  |  9.9 KB  |  250 lines

  1. <?php
  2.  
  3. ######################################################################
  4. # PHP-NUKE: Web Portal System
  5. # ===========================
  6. #
  7. # Copyright (c) 2002 by Francisco Burzi (fbc@mandrakesoft.com)
  8. # http://phpnuke.org
  9. #
  10. # This program is free software. You can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License.
  13. ######################################################################
  14.  
  15. if (!eregi("modules.php", $PHP_SELF)) {
  16.     die ("You can't access this file directly...");
  17. }
  18.  
  19. require_once("mainfile.php");
  20. $module_name = basename(dirname(__FILE__));
  21. get_lang($module_name);
  22.  
  23. $pagetitle = "- "._ENCYCLOPEDIA."";
  24.  
  25. function encysearch($eid) {
  26.     global $module_name;
  27.     echo "<center><form action=\"modules.php?name=$module_name&file=search\" method=\"post\">"
  28.     ."<input type=\"text\" size=\"20\" name=\"query\">  "
  29.     ."<input type=\"hidden\" name=\"eid\" value=\"$eid\">"
  30.     ."<input type=\"submit\" value=\""._SEARCH."\">"
  31.     ."</form>"
  32.     ."</center>";
  33. }
  34.  
  35. function alpha($eid) {
  36.     global $module_name, $prefix, $dbi;
  37.     echo "<center>"._ENCYSELECTLETTER."</center><br><br>";
  38.     $alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
  39.                        "N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  40.     $num = count($alphabet) - 1;
  41.     echo "<center>[ ";
  42.     $counter = 0;
  43.     while (list(, $ltr) = each($alphabet)) {
  44.     $result = sql_query("select * from ".$prefix."_encyclopedia_text where eid='$eid' AND UPPER(title) LIKE '$ltr%'", $dbi);
  45.     if (sql_num_rows($result) > 0) {
  46.         echo "<a href=\"modules.php?name=$module_name&op=terms&eid=$eid<r=$ltr\">$ltr</a>";
  47.     } else {
  48.         echo "$ltr";
  49.     }
  50.         if ( $counter == round($num/2) ) {
  51.             echo " ]\n<br>\n[ ";
  52.         } elseif ( $counter != $num ) {
  53.             echo " | \n";
  54.         }
  55.         $counter++;
  56.     }
  57.     echo " ]</center><br><br>\n\n\n";
  58.     encysearch($eid);
  59.     echo "<center>"._GOBACK."</center>";
  60. }
  61.  
  62. function list_content($eid) {
  63.     global $module_name, $prefix, $sitename, $dbi;
  64.     $result = sql_query("select title, description from ".$prefix."_encyclopedia where eid='$eid'", $dbi);
  65.     list($title, $description) = sql_fetch_row($result, $dbi);
  66.     include("header.php");
  67.     title("$title");
  68.     OpenTable();
  69.     echo "<center><b>$title</b></center><br>"
  70.     ."<p align=\"justify\">$description</p>";
  71.     CloseTable();
  72.     echo "<br>";
  73.     OpenTable();
  74.     alpha($eid);
  75.     CloseTable();
  76.     echo "<br>";
  77.     OpenTable();
  78.     echo "<center><font class=\"tiny\">"._COPYRIGHT." © "._BY." $sitename</font></center>";
  79.     CloseTable();
  80.     include("footer.php");
  81. }
  82.  
  83. function terms($eid, $ltr) {
  84.     global $module_name, $prefix, $sitename, $dbi, $admin;
  85.     $result = sql_query("select active from ".$prefix."_encyclopedia where eid='$eid'", $dbi);
  86.     list($active) = sql_fetch_row($result, $dbi);
  87.     $result = sql_query("select title from ".$prefix."_encyclopedia where eid='$eid'", $dbi);
  88.     list($title) = sql_fetch_row($result, $dbi);
  89.     include("header.php");
  90.     title("$title");
  91.     OpenTable();
  92.     if (($active == 1) OR (is_admin($admin))) {
  93.     if (($active != 1) AND (is_admin($admin))) {
  94.         echo "<center>"._YOURADMINENCY."</center><br><br>";
  95.     }
  96.     echo "<center>Please select one term from the following list:</center><br><br>"
  97.         ."<table border=\"0\" align=\"center\">";
  98.     $result = sql_query("select tid, title from ".$prefix."_encyclopedia_text WHERE UPPER(title) LIKE '$ltr%' AND eid='$eid'", $dbi);
  99.     if (sql_num_rows($result, $dbi) == 0) {
  100.         echo "<center><i>"._NOCONTENTFORLETTER." $ltr.</i></center>";
  101.     }
  102.     while(list($tid, $title) = sql_fetch_row($result, $dbi)) {
  103.         echo "<tr><td><a href=\"modules.php?name=$module_name&op=content&tid=$tid\">$title</a></td></tr>";
  104.     }
  105.     echo "</table><br><br>";
  106.     alpha($eid);
  107.     } else {
  108.     echo "<center>"._ENCYNOTACTIVE."<br><br>"
  109.         .""._GOBACK."</center>";
  110.     }
  111.     CloseTable();
  112.     include("footer.php");
  113. }
  114.  
  115. function content($tid, $ltr, $page=0, $query="") {
  116.     global $prefix, $dbi, $sitename, $admin, $module_name;
  117.     include("header.php");
  118.     OpenTable();
  119.     $result = sql_query("SELECT * from ".$prefix."_encyclopedia_text where tid='$tid'", $dbi);
  120.     $ency = sql_fetch_array($result, $dbi);
  121.     $result = sql_query("select active from ".$prefix."_encyclopedia where eid='$ency[eid]'", $dbi);
  122.     list($active) = sql_fetch_row($result, $dbi);
  123.     if (($active == 1) OR ($active == 0 AND is_admin($admin))) {
  124.     sql_query("update ".$prefix."_encyclopedia_text set counter=counter+1 where tid='$tid'", $dbi);
  125.     $result = sql_query("SELECT title from ".$prefix."_encyclopedia where eid='$ency[eid]'", $dbi);
  126.     list($enc_title) = sql_fetch_row($result, $dbi);
  127.     echo "<font class=\"title\">$ency[title]</font><br><br><br>";
  128.     $contentpages = explode( "<!--pagebreak-->", $ency[text] );
  129.     $pageno = count($contentpages);
  130.     if ( $page=="" || $page < 1 )
  131.         $page = 1;
  132.     if ( $page > $pageno )
  133.         $page = $pageno;
  134.     $arrayelement = (int)$page;
  135.     $arrayelement --;
  136.     if ($pageno > 1) {
  137.         echo ""._PAGE.": $page/$pageno<br>";
  138.     }
  139.     if (isset($query)) {
  140.         $contentpages[$arrayelement] = eregi_replace($query,"<b>$query</b>",$contentpages[$arrayelement]);
  141.         $fromsearch = "&query=$query";
  142.     } else {
  143.         $fromsearch = "";
  144.     }
  145.     echo "<p align=\"justify\">".nl2br($contentpages[$arrayelement])."</p>";
  146.     if($page >= $pageno) {
  147.         $next_page = "";
  148.     } else {
  149.         $next_pagenumber = $page + 1;
  150.         if ($page != 1) {
  151.         $next_page .= "- ";
  152.         }
  153.         $next_page .= "<a href=\"modules.php?name=$module_name&op=content&tid=$tid&page=$next_pagenumber$fromsearch\">"._NEXT." ($next_pagenumber/$pageno)</a> <a href=\"modules.php?name=$module_name&op=content&tid=$tid&page=$next_pagenumber\"><img src=\"images/download/right.gif\" border=\"0\" alt=\""._NEXT."\" title=\""._NEXT."\"></a>";
  154.     }
  155.     if($page <= 1) {
  156.         $previous_page = "";
  157.     } else {
  158.         $previous_pagenumber = $page - 1;
  159.         $previous_page = "<a href=\"modules.php?name=$module_name&op=content&tid=$tid&page=$previous_pagenumber$fromsearch\"><img src=\"images/download/left.gif\" border=\"0\" alt=\""._PREVIOUS."\" title=\""._PREVIOUS."\"></a> <a href=\"modules.php?name=$module_name&op=content&tid=$tid&page=$previous_pagenumber$fromsearch\">"._PREVIOUS." ($previous_pagenumber/$pageno)</a>";
  160.     }
  161.     echo "<br><br><br><center>$previous_page $next_page<br><br>"
  162.         .""._GOBACK."</center><br>";
  163.     if (is_admin($admin)) {
  164.         echo "<p align=\"right\">[ <a href=\"admin.php?op=encyclopedia_text_edit&tid=$ency[tid]\">"._EDIT."</a> ]</p>";
  165.     }
  166.     echo "<p align=\"right\"><a href=\"modules.php?name=$module_name&op=list_content&eid=$ency[eid]\">$enc_title</a></p>";
  167.     if ($page == $pageno) {
  168.         echo "<p align=\"right\">"._COPYRIGHT." © "._BY." $sitename - ($ency[counter] "._READS.")</font></p>";
  169.     }
  170.     } else {
  171.     echo "Sorry, This page isn't active...";
  172.     }
  173.     CloseTable();
  174.     include("footer.php");
  175. }
  176.  
  177. function list_themes() {
  178.     global $prefix, $dbi, $sitename, $admin, $multilingual, $module_name;
  179.     include("header.php");
  180.     title("$sitename: "._ENCYCLOPEDIA."");
  181.     OpenTable();
  182.     echo "<center><font class=\"content\">"._AVAILABLEENCYLIST." $sitename:</center><br><br>";
  183.     $result = sql_query("SELECT eid, title, description, elanguage from ".$prefix."_encyclopedia WHERE active='1'", $dbi);
  184.     echo "<blockquote>";
  185.     while(list($eid, $title, $description, $elanguage) = sql_fetch_row($result, $dbi)) {
  186.     if ($multilingual == 1) {
  187.         $the_lang = "<img src=\"images/language/flag-$elanguage.png\" hspace=\"3\" border=\"0\" height=\"10\" width=\"20\">";
  188.     } else {
  189.         $the_lang = "";
  190.     }
  191.         if ($subtitle != "") {
  192.         $subtitle = "<br>($description)<br><br>";
  193.     } else {
  194.             $subtitle = "";
  195.     }
  196.     if (is_admin($admin)) {
  197.         echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&op=list_content&eid=$eid\">$title</a><br>$description<br>[ <a href=\"admin.php?op=encyclopedia_edit&eid=$eid\">"._EDIT."</a> | <a href=\"admin.php?op=encyclopedia_change_status&eid=$eid&active=1\">"._DEACTIVATE."</a> | <a href=\"admin.php?op=encyclopedia_delete&eid=$eid\">"._DELETE."</a> ]<br><br>";
  198.     } else {
  199.         echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&op=list_content&eid=$eid\">$title</a><br> $description<br><br>";
  200.     }
  201.     }
  202.     echo "</blockquote>";
  203.     if (is_admin($admin)) {
  204.     $result = sql_query("SELECT eid, title, description, elanguage from ".$prefix."_encyclopedia WHERE active='0'", $dbi);
  205.     echo "<br><br><center><b>"._YOURADMININACTIVELIST."</b></center><br><br>";
  206.     echo "<blockquote>";
  207.     while(list($eid, $title, $description, $elanguage) = sql_fetch_row($result, $dbi)) {
  208.         if ($multilingual == 1) {
  209.         $the_lang = "<img src=\"images/language/flag-$elanguage.png\" hspace=\"3\" border=\"0\" height=\"10\" width=\"20\">";
  210.         } else {
  211.         $the_lang = "";
  212.         }
  213.             if ($subtitle != "") {
  214.             $subtitle = " ($subtitle) ";
  215.         } else {
  216.                 $subtitle = " ";
  217.         }
  218.         echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&op=list_content&eid=$eid\">$title</a><br>$description<br>[ <a href=\"admin.php?op=encyclopedia_edit&eid=$eid\">"._EDIT."</a> | <a href=\"admin.php?op=encyclopedia_change_status&eid=$eid&active=0\">"._ACTIVATE."</a> | <a href=\"admin.php?op=encyclopedia_delete&eid=$eid\">"._DELETE."</a> ]<br><br>";
  219.     }
  220.     echo "</blockquote>";
  221.     }
  222.     CloseTable();
  223.     include("footer.php");
  224. }
  225.  
  226. switch($op) {
  227.  
  228.     case "content":
  229.     content($tid, $ltr, $page, $query);
  230.     break;
  231.  
  232.     case "list_content":
  233.     list_content($eid);
  234.     break;
  235.  
  236.     case "terms":
  237.     terms($eid, $ltr);
  238.     break;
  239.  
  240.     case "search":
  241.     search($query, $eid);
  242.     break;
  243.  
  244.     default:
  245.     list_themes();
  246.     break;
  247.  
  248. }
  249.  
  250. ?>