home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / admin / modules / encyclopedia.php < prev    next >
PHP Script  |  2004-01-10  |  20KB  |  462 lines

  1. <?php
  2.  
  3. /************************************************************************/
  4. /* PHP-NUKE: Web Portal System                                          */
  5. /* ===========================                                          */
  6. /*                                                                      */
  7. /* Copyright (c) 2002 by Francisco Burzi                                */
  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("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
  16. global $prefix, $db;
  17. $aid = substr(trim($aid), 0,25);
  18. $result = $db->sql_query("select radminency, radminsuper from ".$prefix."_authors where aid='$aid'");
  19. list($radminency, $radminsuper) = $db->sql_fetchrow($result);
  20. if (($radminency==1) OR ($radminsuper==1)) {
  21.  
  22. /*********************************************************/
  23. /* Sections Manager Functions                            */
  24. /*********************************************************/
  25.  
  26. function alpha($eid) {
  27.     global $module_name, $prefix, $db;
  28.     $alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
  29.                        "N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  30.     $num = count($alphabet) - 1;
  31.     echo "<center>[ ";
  32.     $counter = 0;
  33.     while (list(, $ltr) = each($alphabet)) {
  34.         $result = $db->sql_query("select * from ".$prefix."_encyclopedia_text where eid='$eid' AND UPPER(title) LIKE '$ltr%'");
  35.         if ($db->sql_numrows($result) > 0) {
  36.             echo "<a href=\"admin.php?op=encyclopedia_terms&eid=$eid<r=$ltr\">$ltr</a>";
  37.         } else {
  38.             echo "$ltr";
  39.         }
  40.         if ( $counter == round($num/2) ) {
  41.             echo " ]\n<br>\n[ ";
  42.         } elseif ( $counter != $num ) {
  43.             echo " | \n";
  44.         }
  45.         $counter++;
  46.     }
  47.     echo " ]</center><br><br>\n\n\n";
  48. }
  49.  
  50. function encyclopedia() {
  51.     global $prefix, $db, $language, $multilingual, $bgcolor2;
  52.     include("header.php");
  53.     GraphicAdmin();
  54.     title(""._ENCYCLOPEDIAMANAGER."");
  55.     OpenTable();
  56.     echo "<table border=\"0\" width=\"100%\"><tr>"
  57.         ."<td bgcolor=\"$bgcolor2\"><b>"._TITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._TERMS."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._CURRENTSTATUS."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>";
  58.     $result = $db->sql_query("select * from ".$prefix."_encyclopedia order by eid");
  59.     while($ency = $db->sql_fetchrow($result)) {
  60.         $num = $db->sql_numrows($db->sql_query("select * from ".$prefix."_encyclopedia_text WHERE eid='$ency[eid]'"));
  61.         if ($ency[active] == 1) {
  62.             $status = _ACTIVE;
  63.             $status_chng = _DEACTIVATE;
  64.             $active = 1;
  65.         } else {
  66.             $status = "<i>"._INACTIVE."</i>";
  67.             $status_chng = _ACTIVATE;
  68.             $active = 0;
  69.         }
  70.         echo "<tr><td><a href=\"modules.php?name=Encyclopedia&op=list_content&eid=$ency[eid]\">$ency[title]</a></td><td align=\"center\">$num</td><td align=\"center\">$status</td><td align=\"center\">[ <a href=\"admin.php?op=encyclopedia_edit&eid=$ency[eid]\">"._EDIT."</a> | <a href=\"admin.php?op=encyclopedia_change_status&eid=$ency[eid]&active=$active\">$status_chng</a> | <a href=\"admin.php?op=encyclopedia_delete&eid=$ency[eid]\">"._DELETE."</a> ]</td></tr>";
  71.     }
  72.     echo "</table>";
  73.     CloseTable();
  74.     echo "<br>";
  75.     OpenTable();
  76.     echo "<center><b>"._ADDNEWENCYCLOPEDIA."</b></center><br><br>"
  77.         ."<form action=\"admin.php\" method=\"post\">"
  78.         ."<b>"._TITLE.":</b><br>"
  79.         ."<input type=\"text\" name=\"title\" size=\"50\"><br><br>"
  80.         ."<b>"._DESCRIPTION.":</b><br>"
  81.         ."<textarea name=\"description\" cols=\"60\" rows=\"10\"></textarea><br><br>";
  82.     if ($multilingual == 1) {
  83.         echo "<br><b>"._LANGUAGE.": </b>"
  84.             ."<select name=\"elanguage\">";
  85.         $handle=opendir('language');
  86.         while ($file = readdir($handle)) {
  87.             if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  88.                 $langFound = $matches[1];
  89.                 $languageslist .= "$langFound ";
  90.             }
  91.         }
  92.         closedir($handle);
  93.         $languageslist = explode(" ", $languageslist);
  94.         sort($languageslist);
  95.         for ($i=0; $i < sizeof($languageslist); $i++) {
  96.             if($languageslist[$i]!="") {
  97.                 echo "<option value=\"$languageslist[$i]\" ";
  98.                 if($languageslist[$i]==$language) echo "selected";
  99.                 echo ">".ucfirst($languageslist[$i])."</option>\n";
  100.             }
  101.         }
  102.         echo "</select><br><br>";
  103.     } else {
  104.         echo "<input type=\"hidden\" name=\"elanguage\" value=\"$language\">";
  105.     }
  106.     echo "<b>"._ACTIVATEPAGE."</b><br>"
  107.         ."<input type=\"radio\" name=\"active\" value=\"1\" checked> "._YES."  <input type=\"radio\" name=\"active\" value=\"0\"> "._NO."<br><br>"
  108.         ."<input type=\"hidden\" name=\"op\" value=\"encyclopedia_save\">"
  109.         ."<input type=\"submit\" value=\""._SEND."\">"
  110.         ."</form>";
  111.     CloseTable();
  112.     $result = $db->sql_query("select eid, title from ".$prefix."_encyclopedia");
  113.     if ($db->sql_numrows($result) > 0) {
  114.         echo "<br>";
  115.         OpenTable();
  116.         echo "<center><b>"._ADDNEWENCYTERM."</b></center><br><br>"
  117.             ."<form action=\"admin.php\" method=\"post\">"
  118.             ."<b>"._TITLE.":</b><br>"
  119.             ."<input type=\"text\" name=\"title\" size=\"50\"><br><br>"
  120.             ."<b>"._TERMTEXT.":</b><br>"._PAGEBREAK."<br>"
  121.             ."<textarea name=\"text\" cols=\"60\" rows=\"20\"></textarea><br><br>";
  122.         if ($multilingual == 1) {
  123.             echo "<br><b>"._LANGUAGE.": </b>"
  124.                 ."<select name=\"elanguage\">";
  125.             $handle=opendir('language');
  126.             while ($file = readdir($handle)) {
  127.                 if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  128.                         $langFound = $matches[1];
  129.                     $languageslist .= "$langFound ";
  130.                 }
  131.             }
  132.             closedir($handle);
  133.             $languageslist = explode(" ", $languageslist);
  134.             sort($languageslist);
  135.             for ($i=0; $i < sizeof($languageslist); $i++) {
  136.                 if($languageslist[$i]!="") {
  137.                         echo "<option value=\"$languageslist[$i]\" ";
  138.                         if($languageslist[$i]==$language) echo "selected";
  139.                     echo ">".ucfirst($languageslist[$i])."</option>\n";
  140.                 }
  141.             }
  142.             echo "</select><br><br>";
  143.         } else {
  144.             echo "<input type=\"hidden\" name=\"elanguage\" value=\"$language\">";
  145.         }
  146.         echo "<b>"._ENCYCLOPEDIA.":</b><br><select name=\"eid\">";
  147.         while(list($eid, $title) = $db->sql_fetchrow($result)) {
  148.         $eid = intval($eid);
  149.             echo "<option value=\"$eid\" name=\"eid\">$title</option>";
  150.         }
  151.         echo "</select><br><br>"
  152.             ."<input type=\"hidden\" name=\"op\" value=\"encyclopedia_text_save\">"
  153.             ."<input type=\"submit\" value=\""._ADD."\">"
  154.             ."</form>";
  155.         CloseTable();
  156.  
  157.     }
  158.     $result = $db->sql_query("select eid, title from ".$prefix."_encyclopedia");
  159.     $result2 = $db->sql_query("select eid, title from ".$prefix."_encyclopedia");
  160.     if ($db->sql_numrows($result) > 1) {
  161.         echo "<br>";
  162.         OpenTable();
  163.         echo "<center><b>"._MOVETERMS."</b><br><br>"
  164.             ."<form action=\"admin.php\" method=\"post\">"
  165.             .""._MOVEALLTERMSFROM.": <select name=\"eid\">";
  166.         while(list($eid, $title) = $db->sql_fetchrow($result)) {
  167.         $eid = intval($eid);
  168.             echo "<option name=\"eid\" value=\"$eid\">$title";
  169.         }
  170.         echo "</select> "._TO.": <select name=\"new_eid\">";
  171.         while(list($eid, $title) = $db->sql_fetchrow($result2)) {
  172.         $eid = intval($eid);
  173.             echo "<option name=\"new_eid\" value=\"$eid\">$title";
  174.         }
  175.         echo "</select>  "
  176.             ."<input type=\"hidden\" name=\"op\" value=\"move_terms\">"
  177.             ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
  178.             ."</form></center>";
  179.         CloseTable();
  180.     }
  181.     include("footer.php");
  182. }
  183.  
  184. function encyclopedia_edit($eid) {
  185.     global $prefix, $db, $language, $multilingual, $bgcolor2;
  186.     include("header.php");
  187.     GraphicAdmin();
  188.     title(""._ENCYCLOPEDIAMANAGER."");
  189.     $result = $db->sql_query("select * from ".$prefix."_encyclopedia WHERE eid='$eid'");
  190.     $ency = $db->sql_fetchrow($result);
  191.         if ($ency[active] == 1) {
  192.             $sel1 = "checked";
  193.             $sel2 = "";
  194.         } else {
  195.             $sel1 = "";
  196.             $sel2 = "checked";
  197.         }
  198.     OpenTable();
  199.     echo "<center><b>"._EDITENCYCLOPEDIA."</b></center><br><br>"
  200.         ."<form action=\"admin.php\" method=\"post\">"
  201.         ."<b>"._TITLE.":</b><br>"
  202.         ."<input type=\"text\" name=\"title\" size=\"50\" value=\"$ency[title]\"><br><br>"
  203.         ."<b>"._DESCRIPTION.":</b><br>"
  204.         ."<textarea name=\"description\" cols=\"60\" rows=\"10\">$ency[description]</textarea><br><br>";
  205.     if ($multilingual == 1) {
  206.         echo "<br><b>"._LANGUAGE.": </b>"
  207.             ."<select name=\"elanguage\">";
  208.         $handle=opendir('language');
  209.         while ($file = readdir($handle)) {
  210.             if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
  211.                 $langFound = $matches[1];
  212.                 $languageslist .= "$langFound ";
  213.             }
  214.         }
  215.         closedir($handle);
  216.         $languageslist = explode(" ", $languageslist);
  217.         sort($languageslist);
  218.         for ($i=0; $i < sizeof($languageslist); $i++) {
  219.             if($languageslist[$i]!="") {
  220.                 echo "<option value=\"$languageslist[$i]\" ";
  221.                 if($languageslist[$i]==$language) echo "selected";
  222.                 echo ">".ucfirst($languageslist[$i])."</option>\n";
  223.             }
  224.         }
  225.         echo "</select><br><br>";
  226.     } else {
  227.         echo "<input type=\"hidden\" name=\"elanguage\" value=\"$ency[elanguage]\">";
  228.     }
  229.     echo "<b>"._ACTIVATEPAGE."</b><br>"
  230.         ."<input type=\"radio\" name=\"active\" value=\"1\" $sel1> "._YES."  <input type=\"radio\" name=\"active\" value=\"0\" $sel2> "._NO."<br><br>"
  231.         ."<input type=\"hidden\" name=\"eid\" value=\"$ency[eid]\">"
  232.         ."<input type=\"hidden\" name=\"op\" value=\"encyclopedia_save_edit\">"
  233.         ."<input type=\"submit\" value=\""._SAVECHANGES."\">"
  234.         ."</form>";
  235.     CloseTable();
  236.     echo "<br>";
  237.     OpenTable();
  238.     echo "<center><b>"._ENCYTERMSEDIT."</b></center><br><br>";
  239.     alpha($eid);
  240.     CloseTable();
  241.     include("footer.php");
  242. }
  243.  
  244. function encyclopedia_terms($eid, $ltr) {
  245.     global $prefix, $db;
  246.     include("header.php");
  247.     GraphicAdmin();
  248.     title(""._ENCYCLOPEDIAMANAGER."");
  249.     $result = $db->sql_query("select title from ".$prefix."_encyclopedia where eid='$eid' AND UPPER(title) LIKE '%$ltr%'");
  250.     list($title) = $db->sql_fetchrow($result);
  251.     title("$title");
  252.     OpenTable();
  253.         echo "<center>"._SELECTONETERM."</center><br><br>"
  254.             ."<table border=\"0\" align=\"center\">";
  255.         $result = $db->sql_query("select tid, title from ".$prefix."_encyclopedia_text WHERE UPPER(title) LIKE '$ltr%' AND eid='$eid'");
  256.         if ($db->sql_numrows($result) == 0) {
  257.             echo "<center><i>"._NOCONTENTFORLETTER." $ltr.</i></center>";
  258.         }
  259.         while(list($tid, $title) = $db->sql_fetchrow($result)) {
  260.         $tid = intval($tid);
  261.             echo "<tr><td><a href=\"admin.php?op=encyclopedia_text_edit&tid=$tid\">$title</a></td></tr>";
  262.         }
  263.         echo "</table><br><br>";
  264.         alpha($eid);
  265.         echo "<center>"._GOBACK."</center>";
  266.     CloseTable();
  267.     include("footer.php");
  268. }
  269.  
  270. function encyclopedia_text_edit($tid) {
  271.     global $prefix, $db, $language, $multilingual, $bgcolor2;
  272.     include("header.php");
  273.     GraphicAdmin();
  274.     title(""._ENCYCLOPEDIAMANAGER."");
  275.     $tid = intval($tid);
  276.     $result = $db->sql_query("select * from ".$prefix."_encyclopedia_text WHERE tid='$tid'");
  277.     $ency = $db->sql_fetchrow($result);
  278.     OpenTable();
  279.     echo "<center><b>"._ENCYTERMSEDIT."</b></center><br><br>"
  280.         ."<form action=\"admin.php\" method=\"post\">"
  281.         ."<b>"._TITLE.":</b><br>"
  282.         ."<input type=\"text\" name=\"title\" size=\"50\" value=\"$ency[title]\"><br><br>"
  283.         ."<b>"._TERMTEXT.":</b><br>"._PAGEBREAK."<br>"
  284.         ."<textarea name=\"text\" cols=\"60\" rows=\"20\">$ency[text]</textarea><br><br>"
  285.         ."<b>"._CHANGETOENCY.":</b><br>"
  286.         ."<select name=\"eid\">";
  287.     $result = $db->sql_query("select eid, title from ".$prefix."_encyclopedia");
  288.     while(list($eid, $title) = $db->sql_fetchrow($result)) {
  289.         $eid = intval($eid);
  290.         if ($eid == $ency[eid]) {
  291.             $sel = "selected";
  292.         } else {
  293.             $sel = "";
  294.         }
  295.         echo "<option value=\"$eid\" name=\"eid\" $sel>$title</option>";
  296.     }
  297.     echo "</select><br><br>"
  298.         ."<input type=\"hidden\" name=\"op\" value=\"encyclopedia_text_save_edit\">"
  299.         ."<input type=\"hidden\" name=\"tid\" value=\"$tid\">"
  300.         ."<input type=\"submit\" value=\""._SAVECHANGES."\">    [ <a href=\"admin.php?op=encyclopedia_text_delete&tid=$tid&ok=0\">"._DELETE."</a> ]"
  301.         ."</form>";
  302.     CloseTable();
  303.     include("footer.php");
  304. }
  305.  
  306. function encyclopedia_save($title, $description, $elanguage, $active) {
  307.     global $prefix, $db;
  308.     $title = stripslashes(FixQuotes($title));
  309.     $description = stripslashes(FixQuotes($description));
  310.     $db->sql_query("insert into ".$prefix."_encyclopedia values(NULL, '$title', '$description', '$elanguage', '$active')");
  311.     Header("Location: admin.php?op=encyclopedia");
  312. }
  313.  
  314. function encyclopedia_text_save($eid, $title, $text) {
  315.     global $prefix, $db;
  316.     $eid = intval($eid);
  317.     $text = stripslashes(FixQuotes($text));
  318.     $title = stripslashes(FixQuotes($title));
  319.     $db->sql_query("insert into ".$prefix."_encyclopedia_text values(NULL, '$eid', '$title', '$text', '0')");
  320.     Header("Location: admin.php?op=encyclopedia");
  321. }
  322.  
  323. function encyclopedia_save_edit($eid, $title, $description, $elanguage, $active) {
  324.     global $prefix, $db;
  325.     $eid = intval($eid);
  326.     $title = stripslashes(FixQuotes($title));
  327.     $description = stripslashes(FixQuotes($description));
  328.     $db->sql_query("update ".$prefix."_encyclopedia set title='$title', description='$description', elanguage='$elanguage', active='$active' where eid='$eid'");
  329.     Header("Location: admin.php?op=encyclopedia");
  330. }
  331.  
  332. function encyclopedia_text_save_edit($tid, $eid, $title, $text) {
  333.     global $prefix, $db;
  334.     $tid = intval($tid);
  335.     $text = stripslashes(FixQuotes($text));
  336.     $title = stripslashes(FixQuotes($title));
  337.     $db->sql_query("update ".$prefix."_encyclopedia_text set eid='$eid', title='$title', text='$text' WHERE tid='$tid'");
  338.     Header("Location: admin.php?op=encyclopedia");
  339. }
  340.  
  341. function encyclopedia_change_status($eid, $active) {
  342.     global $prefix, $db;
  343.     $eid = intval($eid);
  344.     if ($active == 1) {
  345.         $new_active = 0;
  346.     } elseif ($active == 0) {
  347.         $new_active = 1;
  348.     }
  349.     $db->sql_query("update ".$prefix."_encyclopedia set active='$new_active' WHERE eid='$eid'");
  350.     Header("Location: admin.php?op=encyclopedia");
  351. }
  352.  
  353. function encyclopedia_delete($eid, $ok=0) {
  354.     global $prefix, $db;
  355.     $eid = intval($eid);
  356.     if ($ok==1) {
  357.         $db->sql_query("delete from ".$prefix."_encyclopedia where eid='$eid'");
  358.         $db->sql_query("delete from ".$prefix."_encyclopedia_text where eid='$eid'");
  359.         Header("Location: admin.php?op=encyclopedia");
  360.     } else {
  361.         include("header.php");
  362.         GraphicAdmin();
  363.         title(""._ENCYCLOPEDIAMANAGER."");
  364.         $result = $db->sql_query("select title from ".$prefix."_encyclopedia where eid='$eid'");
  365.         list($title) = $db->sql_fetchrow($result);
  366.         OpenTable();
  367.         echo "<center><b>"._DELENCYCLOPEDIA.": $title</b><br><br>"
  368.             .""._DELENCYCONTWARNING."<br><br>"
  369.             ."[ <a href=\"admin.php?op=encyclopedia\">"._NO."</a> | <a href=\"admin.php?op=encyclopedia_delete&eid=$eid&ok=1\">"._YES."</a> ]</center>";
  370.         CloseTable();
  371.         include("footer.php");
  372.     }
  373. }
  374.  
  375. function encyclopedia_text_delete($tid, $ok=0) {
  376.     global $prefix, $db;
  377.     $tid = intval($tid);
  378.     if ($ok==1) {
  379.         $db->sql_query("delete from ".$prefix."_encyclopedia_text where tid='$tid'");
  380.         Header("Location: admin.php?op=encyclopedia");
  381.     } else {
  382.         include("header.php");
  383.         GraphicAdmin();
  384.         title(""._ENCYCLOPEDIAMANAGER."");
  385.         $result = $db->sql_query("select title from ".$prefix."_encyclopedia_text where tid='$tid'");
  386.         list($title) = $db->sql_fetchrow($result);
  387.         OpenTable();
  388.         echo "<center><b>"._DELENCYCLOPEDIATEXT.": $title</b><br><br>"
  389.             .""._DELENCYTEXTWARNING."<br><br>"
  390.             ."[ <a href=\"admin.php?op=encyclopedia\">"._NO."</a> | <a href=\"admin.php?op=encyclopedia_text_delete&tid=$tid&ok=1\">"._YES."</a> ]</center>";
  391.         CloseTable();
  392.         include("footer.php");
  393.     }
  394. }
  395.  
  396. function move_terms($eid, $new_eid) {
  397.     global $prefix, $db;
  398.     $eid = intval($eid);
  399.     $result = $db->sql_query("select tid from ".$prefix."_encyclopedia_text WHERE eid='$eid'");
  400.     while(list($tid) = $db->sql_fetchrow($result)) {
  401.         $db->sql_query("update ".$prefix."_encyclopedia_text set eid='$new_eid' WHERE tid='$tid'");
  402.     }
  403.     Header("Location: admin.php?op=encyclopedia");
  404. }
  405.  
  406. switch ($op) {
  407.  
  408.     case "encyclopedia":
  409.     encyclopedia();
  410.     break;
  411.  
  412.     case "move_terms":
  413.     move_terms($eid, $new_eid);
  414.     break;
  415.  
  416.     case "encyclopedia_terms":
  417.     encyclopedia_terms($eid, $ltr);
  418.     break;
  419.  
  420.     case "encyclopedia_edit":
  421.     encyclopedia_edit($eid);
  422.     break;
  423.  
  424.     case "encyclopedia_text_edit":
  425.     encyclopedia_text_edit($tid);
  426.     break;
  427.  
  428.     case "encyclopedia_delete":
  429.     encyclopedia_delete($eid, $ok);
  430.     break;
  431.  
  432.     case "encyclopedia_text_delete":
  433.     encyclopedia_text_delete($tid, $ok);
  434.     break;
  435.  
  436.     case "encyclopedia_save":
  437.     encyclopedia_save($title, $description, $elanguage, $active);
  438.     break;
  439.  
  440.     case "encyclopedia_text_save":
  441.     encyclopedia_text_save($eid, $title, $text);
  442.     break;
  443.  
  444.     case "encyclopedia_save_edit":
  445.     encyclopedia_save_edit($eid, $title, $description, $elanguage, $active);
  446.     break;
  447.  
  448.     case "encyclopedia_text_save_edit":
  449.     encyclopedia_text_save_edit($tid, $eid, $title, $text);
  450.     break;
  451.  
  452.     case "encyclopedia_change_status":
  453.     encyclopedia_change_status($eid, $active);
  454.     break;
  455.  
  456. }
  457.  
  458. } else {
  459.     echo "Access Denied";
  460. }
  461.  
  462. ?>