<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* 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.       */
/************************************************************************/
function Access_Error () {
  if (file_exists("meta/meta.php"))
     include ("meta/meta.php");
  echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
  echo "Access Denied / Acc&egrave;s Refus&eacute;";
  if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
  echo "</span>";
  echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
  echo "</span></p></body></html>";
  die();
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }
global $pdst; $pdst="0";

global $language;
$hlpfile = "manuels/$language/topics.html";
$result = mysql_query("select radmintopic, radminsuper from authors where aid='$aid'");
list($radmintopic, $radminsuper) = mysql_fetch_row($result);
if (($radmintopic!=1) AND ($radminsuper!=1)) {
   Access_Error();
}

function topicsmanager() {
    global $hlpfile, $tipath;
    include("header.php");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select topicid, topicname, topicimage, topictext from topics order by topicname");
    if (mysql_num_rows($result) > 0) {
       OpenTable();
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
       echo adm_translate("Sujets actifs")."&nbsp;".adm_translate("Cliquez pour éditer");
       echo "</td></tr></table>\n";
       echo "<br /><table  width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" align=\"center\"><tr>";
       while (list($topicid, $topicname, $topicimage, $topictext) = mysql_fetch_array($result)) {
          echo "<td width=\"20%\" align=\"center\">";
          if (($topicimage) or ($topicimage!="")) {
             echo "<a href=\"admin.php?op=topicedit&amp;topicid=$topicid\"><img src=\"$tipath$topicimage\" border=\"0\" alt=\"$topicimage\" /></a><br />";
             echo "<a href=\"admin.php?op=topicedit&amp;topicid=$topicid\" class=\"NOIR\">".aff_langue($topictext)."</a>";
          } else {
             if ($topictext=="") {$topictext=adm_translate("Sans titre");}
             echo "<a href=\"admin.php?op=topicedit&amp;topicid=$topicid\" class=\"NOIR\">".aff_langue($topictext)."</a><br />";
          }
          echo "</td>";

          $count++;
          if ($count == 5) {
             echo "</tr>\n<tr>";
             $count = 0;
          }
       }
       echo "</tr></table>";
    }
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Ajouter un nouveau Sujet");
    echo "</td></tr></table>\n";
    echo "<br /><form action=\"admin.php\" method=\"post\">";
    echo "<b>".adm_translate("Intitulé du Sujet :")."</b> ".adm_translate("(un simple nom sans espaces - 20 caractères max.)")."<br />";
    echo adm_translate("par exemple : cesiteestgénial")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicname\" size=\"21\" maxlength=\"20\" value=\"$topicname\"><br /><br />";
    echo "<b>".adm_translate("Texte du Sujet :")."</b> ".adm_translate("(description ou nom complet du Sujet - max : 40 caractères)")."<br />";
    echo adm_translate("par exemple : ce site est génial")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topictext\" size=\"40\" maxlength=\"250\" value=\"$topictext\"><br /><br />";
    echo "<b>".adm_translate("Image du Sujet :")."</b> ".adm_translate("(nom de l'image + extension)")." ($tipath)<br />";
    echo adm_translate("par exemple : genial.png")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicimage\" size=\"21\" maxlength=\"20\" value=\"$topicimage\"><br /><br />";

    echo "<b>".adm_translate("Administrateur(s) du Sujet :")."</b><br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicadmin\" size=\"41\" maxlength=\"255\" value=\"$topicadmin\"><br /><br />";

    echo "<input type=\"hidden\" name=\"op\" value=\"topicmake\">";
    echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Ajouter un Sujet")."\">";
    echo "</form>";
    closetable();
    mysql_free_result($result);
    include("footer.php");
}

function topicedit($topicid) {
    global $hlpfile, $tipath;
    include("header.php");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select topicid, topicname, topicimage, topictext, topicadmin from topics where topicid='$topicid'");
    list($topicid, $topicname, $topicimage, $topictext, $topicadmin) = mysql_fetch_array($result);
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Editer le Sujet :")." ".aff_langue($topictext);
    echo "</td></tr></table>\n";
    echo "<br />";
    if ($topicimage!="") {
       echo "<p align=\"center\"><img src=\"$tipath$topicimage\" border=\"0\" alt=\"\" /></p>";
    }
    echo "<form action=\"admin.php\" method=\"post\"><br />";
    echo "<b>".adm_translate("Intitulé du Sujet :")."</b> ".adm_translate("(un simple nom sans espaces - 20 caractères max.)")."<br />";
    echo adm_translate("par exemple : cesiteestgénial")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicname\" size=\"21\" maxlength=\"20\" value=\"$topicname\"><br /><br />";
    echo "<b>".adm_translate("Texte du Sujet :")."</b> ".adm_translate("(description ou nom complet du Sujet - max : 40 caractères)")."<br />";
    echo adm_translate("par exemple : ce site est génial")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topictext\" size=\"41\" maxlength=\"250\" value=\"$topictext\"><br /><br />";
    echo "<b>".adm_translate("Image du Sujet :")."</b> ".adm_translate("(nom de l'image + extension)")." ($tipath)<br />";
    echo adm_translate("par exemple : genial.png")."<br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicimage\" size=\"21\" maxlength=\"20\" value=\"$topicimage\"><br /><br />";

    echo "<b>".adm_translate("Administrateur(s) du Sujet :")."</b><br />";
    echo "<input class=\"textbox\" type=\"text\" name=\"topicadmin\" size=\"41\" maxlength=\"255\" value=\"$topicadmin\"><br /><hr noshade class=\"ONGL\">";

    echo "<b>".adm_translate("Ajouter des Liens relatifs au Sujet : ")."</b><br />";
    echo adm_translate("Nom du site : ")."<br /><input class=\"textbox\" type=\"text\" name=\"name\" size=\"31\" maxlength=\"30\"><br />";
    echo adm_translate("URL : ")."<br /><input class=\"textbox\" type=\"text\" name=\"url\" value=\"http://\" size=\"50\" maxlength=\"200\"><br /><br />";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Gérer les Liens Relatifs : ")." ".aff_langue($topictext);
    echo "</td></tr></table>\n";
    $res=mysql_query("select rid, name, url from related where tid='$topicid'");
    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n";
    while (list($rid, $name, $url) = mysql_fetch_row($res)) {
       $rowcolor = tablos();
       echo "<tr $rowcolor><td>$name</td><td width=\"60%\">";
       echo "<a href=\"$url\" target=\"_blank\" class=\"NOIR\">$url</a></td><td align=\"center\">[ <a href=\"admin.php?op=relatededit&amp;tid=$topicid&amp;rid=$rid\" class=\"NOIR\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=relateddelete&amp;tid=$topicid&amp;rid=$rid\" class=\"ROUGE\">".adm_translate("Effacer")."</a> ]</td></tr>";
    }
    echo "</table>";
    echo "<hr noshade class=\"ONGL\">";
    echo "<br />";
    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr><td>\n";
    echo "<input type=\"hidden\" name=\"topicid\" value=\"$topicid\">";
    echo "<input type=\"hidden\" name=\"op\" value=\"topicchange\">";
    echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\">";
    echo "&nbsp;&nbsp;<input class=\"BOUTON_STANDARD\" type=\"button\" onClick=\"javascript:document.location.href='admin.php?op=topicsmanager'\" value=\"".adm_translate("Retour en arrière")."\"></form>";
    echo "</td><td>";
    echo "<form action=\"admin.php\" method=\"post\">";
    echo "<input type=\"hidden\" name=\"topicid\" value=\"$topicid\">";
    echo "<input type=\"hidden\" name=\"op\" value=\"topicdelete\">";
    echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Effacer le Sujet !")."\"></form>";
    echo "</td></tr></table>";
    closetable();
    include("footer.php");
}

function relatededit($tid, $rid) {
    global $hlpfile, $tipath;
    include("header.php");
    GraphicAdmin($hlpfile);
    $result=mysql_query("select name, url from related where rid='$rid'");
    list($name, $url) = mysql_fetch_row($result);
    $result2=mysql_query("select topictext, topicimage from topics where topicid='$tid'");
    list($topictext, $topicimage) = mysql_fetch_row($result2);
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Editer les Liens Relatifs");
    echo "</td></tr></table>\n";
    echo "<br />";
    if ($topicimage!="") {echo "<p align=\"center\"><img src=\"$tipath$topicimage\" border=\"0\" alt=\"$topictext\" /></p>";}
    echo "<br />
    <b>".adm_translate("Sujet : ")."</b> $topictext
    <form action=\"admin.php\" method=\"post\">
    ".adm_translate("Nom du site : ")."<br /><input type=\"text\" class=\"textbox\" name=\"name\" value=\"$name\" size=\"31\" maxlength=\"30\"><br /><br />
    ".adm_translate("URL : ")."<br /><input type=\"text\" class=\"textbox\" name=\"url\" value=\"$url\" size=\"50\" maxlength=\"200\"><br /><br />
    <input type=\"hidden\" name=\"op\" value=\"relatedsave\">
    <input type=\"hidden\" name=\"tid\" value=\"$tid\">
    <input type=\"hidden\" name=\"rid\" value=\"$rid\">
    <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\">
    </form>";
    closetable();
    include("footer.php");
}

function relatedsave($tid, $rid, $name, $url) {
    mysql_query("update related set name='$name', url='$url' where rid='$rid'");
    Header("Location: admin.php?op=topicedit&topicid=$tid");
}

function relateddelete($tid, $rid) {
    mysql_query("delete from related where rid='$rid'");
    Header("Location: admin.php?op=topicedit&topicid=$tid");
}

function topicmake($topicname, $topicimage, $topictext, $topicadmin) {
    $topicname = stripslashes(FixQuotes($topicname));
    $topicimage = stripslashes(FixQuotes($topicimage));
    $topictext = stripslashes(FixQuotes($topictext));
    mysql_query("INSERT INTO topics VALUES (NULL,'$topicname','$topicimage','$topictext','0', '$topicadmin')");
    Header("Location: admin.php?op=topicsmanager#Add");
}

function topicchange($topicid, $topicname, $topicimage, $topictext, $topicadmin, $name, $url) {
    $topicname = stripslashes(FixQuotes($topicname));
    $topicimage = stripslashes(FixQuotes($topicimage));
    $topictext = stripslashes(FixQuotes($topictext));
    $name = stripslashes(FixQuotes($name));
    $url = stripslashes(FixQuotes($url));
    mysql_query("update topics set topicname='$topicname', topicimage='$topicimage', topictext='$topictext', topicadmin='$topicadmin' where topicid='$topicid'");
    if ($name) {
       mysql_query("insert into related VALUES (NULL, '$topicid','$name','$url')");
    }
    Header("Location: admin.php?op=topicedit&topicid=$topicid");
}

function topicdelete($topicid, $ok=0) {
    if ($ok==1) {
       $result=mysql_query("select sid from stories where topic='$topicid'");
       list($sid) = mysql_fetch_row($result);
       mysql_query("delete from stories where topic='$topicid'");
       mysql_query("delete from topics where topicid='$topicid'");
       mysql_query("delete from related where tid='$topicid'");
       $result=mysql_query("select sid from comments where sid='$sid'");
       list($sid) = mysql_fetch_row($result);
       mysql_query("delete from comments where sid='$sid'");
       Header("Location: admin.php?op=topicsmanager");
    } else {
       global $hlpfile, $tipath, $topicimage;
       include("header.php");
       GraphicAdmin($hlpfile);
       $result2=mysql_query("select topicimage, topictext from topics where topicid='$topicid'");
       list($topicimage, $topictext) = mysql_fetch_row($result2);
       OpenTable();
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
       echo adm_translate("Effacer le Sujet")." ".aff_langue($topictext);
       echo "</td></tr></table>\n";
       echo "<br />";
       echo "<p align=\"center>";
       if ($topicimage!="") {echo "<img src=\"$tipath$topicimage\" border=\"0\" alt=\"\" />";}
       echo "<br /><b>
            ".adm_translate("Etes-vous sûr de vouloir effacer ce Sujet ?")." : $topictext</b><br /><br />
            <span class=\"ROUGE\">".adm_translate("Ceci effacera tous ses Articles et ses Commentaires !")."</span><br /><br />
            [ <a href=\"admin.php?op=topicdelete&amp;topicid=$topicid&amp;ok=1\" class=\"ROUGE\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=topicsmanager\" class=\"NOIR\">".adm_translate("Non")."</a> ]</p>";
       closetable();
       include("footer.php");
    }
}

switch ($op) {
   case "topicsmanager":
        topicsmanager();
        break;

   case "topicedit":
        topicedit($topicid);
        break;

   case "topicmake":
        topicmake($topicname, $topicimage, $topictext, $topicadmin);
        break;

   case "topicdelete":
        topicdelete($topicid, $ok);
        break;

   case "topicchange":
        topicchange($topicid, $topicname, $topicimage, $topictext, $topicadmin, $name, $url);
        break;

   case "relatedsave":
        relatedsave($tid, $rid, $name, $url);
        break;

   case "relatededit":
        relatededit($tid, $rid);
        break;

   case "relateddelete":
        relateddelete($tid, $rid);
        break;
}
?>