<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x                                                 */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2007 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 () {
  include("admin/die.php");
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }

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

function topicsmanager() {
    global $hlpfile, $tipath;
    global $NPDS_Prefix;

    include("header.php");
    GraphicAdmin($hlpfile);
    $result = sql_query("select topicid, topicname, topicimage, topictext from ".$NPDS_Prefix."topics order by topicname");
    if (sql_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) = sql_fetch_row($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();
    sql_free_result($result);
    include("footer.php");
}

function topicedit($topicid) {
    global $hlpfile, $tipath;
    global $NPDS_Prefix;

    include("header.php");
    GraphicAdmin($hlpfile);
    $result = sql_query("select topicid, topicname, topicimage, topictext, topicadmin from ".$NPDS_Prefix."topics where topicid='$topicid'");
    list($topicid, $topicname, $topicimage, $topictext, $topicadmin) = sql_fetch_row($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=sql_query("select rid, name, url from ".$NPDS_Prefix."related where tid='$topicid'");
    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n";
    while (list($rid, $name, $url) = sql_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;
    global $NPDS_Prefix;

    include("header.php");
    GraphicAdmin($hlpfile);
    $result=sql_query("select name, url from ".$NPDS_Prefix."related where rid='$rid'");
    list($name, $url) = sql_fetch_row($result);
    $result2=sql_query("select topictext, topicimage from ".$NPDS_Prefix."topics where topicid='$tid'");
    list($topictext, $topicimage) = sql_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) {
    global $NPDS_Prefix;

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

function relateddelete($tid, $rid) {
    global $NPDS_Prefix;

    sql_query("delete from ".$NPDS_Prefix."related where rid='$rid'");
    Header("Location: admin.php?op=topicedit&topicid=$tid");
}

function topicmake($topicname, $topicimage, $topictext, $topicadmin) {
    global $NPDS_Prefix;

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

function topicchange($topicid, $topicname, $topicimage, $topictext, $topicadmin, $name, $url) {
    global $NPDS_Prefix;

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

function topicdelete($topicid, $ok=0) {
    global $NPDS_Prefix;

    if ($ok==1) {
       $result=sql_query("select sid from ".$NPDS_Prefix."stories where topic='$topicid'");
       list($sid) = sql_fetch_row($result);
       sql_query("delete from ".$NPDS_Prefix."stories where topic='$topicid'");
       sql_query("delete from ".$NPDS_Prefix."topics where topicid='$topicid'");
       sql_query("delete from ".$NPDS_Prefix."related where tid='$topicid'");
       // commentaires
       if (file_exists("modules/comments/article.conf.php")) {
           include ("modules/comments/article.conf.php");
           sql_query("DELETE FROM ".$NPDS_Prefix."posts WHERE forum_id='$forum' and topic_id='$topic'");
       }
       Header("Location: admin.php?op=topicsmanager");
    } else {
       global $hlpfile, $tipath, $topicimage;
       include("header.php");
       GraphicAdmin($hlpfile);
       $result2=sql_query("select topicimage, topictext from ".$NPDS_Prefix."topics where topicid='$topicid'");
       list($topicimage, $topictext) = sql_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;
}
?>