<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {
   include ("mainfile.php");
}
   $segment=4; // you can put more (or less) segment

   if ($op!="maj_subscribe") {
        include("header.php");
        $result = sql_query("select topicid, topicname, topicimage, topictext from ".$NPDS_Prefix."topics order by topicname");
        if (sql_num_rows($result)==0) {
           opentable();
        } else {
           opentable();
           echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
           echo translate("Current Active Topics");
           echo "</td></tr></table>\n";
           echo "<br />".translate("Click to list all articles in this topic")."<br /><br />
           <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr>";
           while(list($topicid, $topicname, $topicimage, $topictext) = sql_fetch_row($result)) {
               echo "<td align=\"center\">";
               if ((($topicimage) or ($topicimage!="")) and (file_exists("$tipath$topicimage"))) {
                  echo "<a href=\"index.php?op=newtopic&amp;topic=$topicid\" class=\"noir\"><img src=\"$tipath$topicimage\" border=\"0\" alt=\"\" />";
                  echo "<br />".aff_langue($topictext)."</a></td>";
               } else {
                  echo "<a href=\"index.php?op=newtopic&amp;topic=$topicid\" class=\"noir\">".aff_langue($topictext)."</a></td>";
               }
               $count++;
               if ($count == $segment) {
                  echo "</tr><tr>";
                  $count = 0;
               }
           }
           echo "</tr></table>";
           if ($subscribe) {
              if ($user) {
                 $result = sql_query("select topicid, topictext from ".$NPDS_Prefix."topics order by topicname");
                 echo "<form action=\"topics.php\" method=\"post\">";
                 echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
                 echo translate("Manage your subscribes");
                 echo "</td></tr></table>\n";
                 echo "<br />";
                 echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr>";
                 $pas=0;
                 while(list($topicid, $topictext) = sql_fetch_row($result)) {
                    $pas++;
                    $resultX = sql_query("select topicid from ".$NPDS_Prefix."subscribe where uid='$cookie[0]' and topicid='$topicid'");
                    if (sql_num_rows($resultX)=="1") {
                       echo "<td nowrap=\"nowrap\"><input class=\"texbox\" type=\"checkbox\" name=\"Subtopicid[$topicid]\" checked> ".aff_langue($topictext)."</td><td width=\"4%\">&nbsp;</td>";
                    } else {
                       echo "<td nowrap=\"nowrap\"><input class=\"texbox\" type=\"checkbox\" name=\"Subtopicid[$topicid]\"> ".aff_langue($topictext)."</td><td width=\"4%\">&nbsp;</td>";
                    }
                    if ($pas>=3) {
                       echo "</tr><tr>";
                       $pas=0;
                    }
                 }
                 echo "</tr><tr><td colspan=\"10\" align=\"right\">";
                 echo "<input type=\"hidden\" name=\"op\" value=\"maj_subscribe\">";
                 echo "<input class=\"bouton_standard\" type=\"submit\" name=\"ok\" value=\"".translate("Submit")."\">";
                 echo "</td></tr></table>";
                 echo "</form>";
              }
           }
        }
        closetable();
        sql_free_result($result);
        include("footer.php");
   } else {
      if ($subscribe) {
         if ($user) {
            $result = sql_query("delete from ".$NPDS_Prefix."subscribe where uid='$cookie[0]' and topicid!='NULL'");
            $result = sql_query("select topicid from ".$NPDS_Prefix."topics order by topicid");
            while(list($topicid) = sql_fetch_row($result)) {
               if ($Subtopicid[$topicid]=="on") {
                  $resultX = sql_query("insert into ".$NPDS_Prefix."subscribe (topicid, uid) values ('$topicid','$cookie[0]')");
               }
            }
            redirect_url("topics.php");
         }
      }
   }
?>