<?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   */
/*                                                                      */
/* =========================                                            */
/* Based on Parts of phpBB                                              */
/*                                                                      */
/* 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");}
include("functions.php");
if ($SuperCache) {
   $cache_obj = new cacheManager();
}
global $pdst; $pdst="0";

if ($op!="maj_subscribe") {
  include("header.php");
  if (($SuperCache) and (!$user)) {
     $cache_obj->startCachingPage();
  }
  $rowQ1=Q_Select ("SELECT * FROM catagories ORDER BY cat_id", 3600);
  if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache) or ($user)) {
     echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
     echo $sitename." ".translate("Forums!");
     echo "</td></tr></table>\n";
     echo "<br />\n";

     echo translate("Select forums with discussions of your interest, participate and have a lot of fun!")." : ";
     echo translate("The only rule here is: Stay on topic of the discussions.");
     echo "<br /><br />\n";

     echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\">";
     echo "<tr>";
     echo "<td class=\"HEADER\">&nbsp;</td>";
     echo "<td width=\"55%\" class=\"HEADER\">".translate("Forum")." : ";
     echo translate(date("l")).date(" ".translate("dateinternal"),time()+($gmt*3600));
     echo "</td>";
     if (($subscribe) and ($user)) {
        echo "<form action=\"forum.php\" method=\"post\">";
        echo "<input type=\"hidden\" name=\"op\" value=\"maj_subscribe\">";
        echo "<td align=\"center\" width=\"5%\" class=\"HEADER\"><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"Xsub\" value=\"".translate("Sub.")."\"></td>";
        $colspanX=8;
     } else {
        $colspanX=7;
     }
     echo "<td align=\"center\" width=\"8%\" class=\"HEADER\">".translate("Type")."</td>";
     echo "<td align=\"center\" width=\"5%\" class=\"HEADER\">&nbsp;".translate("Topics")."&nbsp;</td>";
     echo "<td align=\"center\" width=\"5%\" class=\"HEADER\">&nbsp;NB&nbsp;</td>";
     echo "<td align=\"center\" width=\"15%\" class=\"HEADER\">".translate("Last Posts")."</td>";
     echo "<td class=\"HEADER\">".translate("Moderator")."</td>";
     echo "</tr>";
     if ($user) {
        $userX = base64_decode($user);
        $userR = explode(":", $userX);
        $tab_groupe=valid_group($user);
     }

     if ($ibid=theme_image("forum/icons/red_folder.gif")) {$imgtmpR=$ibid;} else {$imgtmpR="images/forum/icons/red_folder.gif";}
     if ($ibid=theme_image("forum/icons/folder.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/icons/folder.gif";}
     $linked = "onMouseOver=\"this.className='LIGNB'; this.style.cursor='hand';\" "
     ." onMouseOut=\"this.className='LIGNA';\"";

     // preparation de la gestion des folders
     $result = mysql_query("SELECT forum_id, count(topic_id) AS total FROM forumtopics GROUP BY (forum_id)");
     while (list($forumid, $total)=mysql_fetch_row($result)) {
        $tab_folder[$forumid][0]=$total; // Topic
     }
     $result = mysql_query("SELECT forum_id, count(DISTINCT topicid) AS total FROM forum_read WHERE uid='$userR[0]' and topicid>'0' and status!='0' GROUP BY (forum_id)");
     while (list($forumid, $total)=mysql_fetch_row($result)) {
        $tab_folder[$forumid][1]=$total; // Folder
     }
     // préparation de la gestion des abonnements
     $result = mysql_query("SELECT forumid FROM subscribe WHERE uid='$userR[0]'");
     while (list($forumid, $total)=mysql_fetch_row($result)) {
        $tab_subscribe[$forumid]=true;
     }
     // preparation du compteur total_post
     $rowQ0=Q_Select ("SELECT forum_id, count(post_aff) AS total FROM posts GROUP BY forum_id", 360);
     while (list(,$row0)=each($rowQ0)) {
        $tab_total_post[$row0[0]]=$row0[1];
     }
     if ($rowQ1) {
        while(list(,$row) = each($rowQ1)) {
              $title_aff=true;
              $rowQ2=Q_Select ("SELECT * FROM forums WHERE cat_id = '$row[cat_id]' ORDER BY forum_index,forum_id", 3600);
              if ($rowQ2) {
                 while(list(,$myrow) = each($rowQ2)) {
                    // Gestion des Forums Cachés aux non-membres
                    if (($myrow[forum_type] != "9") or ($userR)) {
                       // Gestion des Forums réservés à un groupe de membre
                       if (($myrow[forum_type] == "7") or ($myrow[forum_type] == "5")) {
                          $ok_affich=groupe_forum($myrow[forum_pass], $tab_groupe);
                       } else {
                          $ok_affich=true;
                       }
                       if ($ok_affich) {
                          if ($title_aff) {
                             $title = stripslashes($row[cat_title]);
                             echo "<tr valign=\"top\"><td colspan=\"$colspanX\" class=\"LIGNB\">$title</td></tr>";
                             $title_aff=false;
                          }
                          $forum_moderator=explode(" ",get_moderator($myrow[forum_moderator]));
                          $Mmod=false;
                          for ($i = 0; $i < count($forum_moderator); $i++) {
                             if (($userR[1]==$forum_moderator[$i])) {$Mmod=true;}
                          }

                          $last_post = get_last_post($myrow[forum_id], "forum","infos",$Mmod);
                          echo "<tr align=\"left\" valign=\"top\">";
                          if (($tab_folder[$myrow[forum_id]][0]-$tab_folder[$myrow[forum_id]][1])>0)  {
                             echo "<td class=\"LIGNB\" align=\"center\" valign=\"middle\" width=\"5%\"><img src=\"$imgtmpR\" border=\"\" alt=\"\" /></td>";
                          } else {
                             echo "<td class=\"LIGNB\" align=\"center\" valign=\"middle\" width=\"5%\"><img src=\"$imgtmp\" border=\"\" alt=\"\" /></td>";
                          }
                          $name = stripslashes($myrow[forum_name]);
                          $redirect=false;
                          if (strstr(strtoupper($name),"<A HREF")) {
                             echo "<td class=\"LIGNA\" $linked>$name";
                             $redirect=true;
                          } else {
                             echo "<td class=\"LIGNA\" $linked onclick=\"window.location.href='viewforum.php?forum=$myrow[forum_id]'\"><a href=\"viewforum.php?forum=$myrow[forum_id]\" class=\"NOIR\">$name</a>";
                          }
                          $desc = stripslashes($myrow[forum_desc]);
                          echo "<br />$desc</td>";

                          // Subcribe
                          if (($subscribe) and ($user)) {
                             if (!$redirect) {
                                if ($tab_subscribe[$myrow[forum_id]]) {
                                   echo "<td class=\"LIGNB\" width=\"5%\" align=\"center\" valign=\"middle\"><input type=\"checkbox\" name=\"Subforumid[$myrow[forum_id]]\" checked></td>";
                                } else {
                                   echo "<td class=\"LIGNB\" width=\"5%\" align=\"center\" valign=\"middle\"><input type=\"checkbox\" name=\"Subforumid[$myrow[forum_id]]\"></td>";
                                }
                             } else {
                                echo "<td class=\"LIGNB\" width=\"5%\" align=\"center\" valign=\"middle\">&nbsp;</td>";
                             }
                          }
                          if (!$redirect) {
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\" style=\"font-size: 10px;\">";
                             if ($myrow[forum_access]=="0" && $myrow[forum_type]=="0")
                                echo translate("Free for All");
                             if ($myrow[forum_type] == "1")
                                echo translate("Protected Area");
                             if ($myrow[forum_type] == "5")
                                echo "PHP Script + ".translate("Group");
                             if ($myrow[forum_type] == "6")
                                echo "PHP Script";
                             if ($myrow[forum_type] == "7")
                                echo translate("Group");
                             if ($myrow[forum_type] == "8")
                                echo translate("Extended Text");
                             if ($myrow[forum_type] == "9")
                                echo translate("Hidden");
                             if ($myrow[forum_access]=="1" && $myrow[forum_type] == "0")
                                echo translate("Registered User");
                             if ($myrow[forum_access]=="2" && $myrow[forum_type] == "0")
                                echo translate("Moderator");
                             if ($myrow[forum_access]=="9")
                                echo " <b>".translate("Closed")."</b>";
                             echo "</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNB\" style=\"font-size: 10px;\">".$tab_folder[$myrow[forum_id]][0]."</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\" style=\"font-size: 10px;\">".$tab_total_post[$myrow[forum_id]]."</td>";
                             echo "<td width=\"15%\" align=\"center\" valign=\"middle\" class=\"LIGNB\" style=\"font-size: 10px;\">$last_post</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\">";
                             for ($i = 0; $i < count($forum_moderator); $i++) {
                                echo "<a href=\"user.php?op=userinfo&amp;uname=$forum_moderator[$i]\" class=\"NOIR\" style=\"font-size: 10px;\">$forum_moderator[$i]</a> ";
                             }
                             echo "</td></tr>";
                          } else {
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\">&nbsp;</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNB\">&nbsp;</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\">&nbsp;</td>";
                             echo "<td width=\"15%\" align=\"center\" valign=\"middle\" class=\"LIGNB\">&nbsp;</td>";
                             echo "<td width=\"5%\" align=\"center\" valign=\"middle\" class=\"LIGNA\">&nbsp;</td></tr>";
                          }
                       }
                    }
                 }
              }
        }
     }

     if (!$user) {
        echo "<tr align=\"left\" class=\"LIGNB\">";
        echo "<td colspan=\"$colspanX\" align=\"center\" style=\"font-size: 10px;\">".translate("Join us ! As a registered user, cool stuff like : forum'subscribing, special forums (hidden, members ...), post and read status, ... are avaliable.")."</td></tr>";
     }
     if (($subscribe) and ($user)) {
        echo "</form>";
        echo "<tr align=\"left\" class=\"LIGNB\">";
        echo "<td colspan=\"$colspanX\" align=\"center\" style=\"font-size: 10px;\">".translate("Check a Forum and Click on [Sub.] button for receive an Email when a new submission is made in it.")."</td></tr>";
     }
     echo "</table>";
     searchblock();
     echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr><td>";
     echo "<img src=\"$imgtmpR\" border=\"\" alt=\"\" /> = ".translate("New Posts since your last visit.")."<br />";
     echo "<img src=\"$imgtmp\" border=\"\" alt=\"\" /> = ".translate("No New Posts since your last visit.")."<br />";
     echo "</td></tr></table>";
   }
   if (($SuperCache) and (!$user)) {
      $cache_obj->endCachingPage();
   }
   include("footer.php");
} else {
  if ($subscribe) {
     if ($user) {
        settype($cookie[0],"integer");
        $result = mysql_query("delete from subscribe where uid='$cookie[0]' and forumid!='NULL'");
        $result = mysql_query("select forum_id from forums order by forum_index,forum_id");
        while(list($forumid) = mysql_fetch_array($result)) {
           if ($Subforumid[$forumid]=="on") {
              $resultX = mysql_query("insert into subscribe (forumid, uid) values ('$forumid','$cookie[0]')");
           }
        }
        redirect_url("forum.php");
     }
  }
}
?>