<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 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();
}
include('auth.php');

$rowQ1=Q_Select ("SELECT forum_id FROM forumtopics WHERE topic_id='$topic'", 3600);
if (!$rowQ1)
   forumerror('0001');
list(,$myrow) = each($rowQ1);
$forum=$myrow[forum_id];

$rowQ1=Q_Select ("SELECT forum_name, forum_moderator, forum_type, forum_pass, forum_access, arbre FROM forums WHERE forum_id = '$forum'", 3600);
if (!$rowQ1)
   forumerror('0001');
list(,$myrow) = each($rowQ1);
$forum_name = $myrow[forum_name];
$mod = $myrow[forum_moderator];
$forum_type=$myrow[forum_type];
$forum_access=$myrow[forum_access];

if ( ($forum_type == 1) and ($Forum_passwd != $myrow[forum_pass]) ) {
   header("Location: forum.php");
}
if (($forum_type == 5) or ($forum_type == 7)) {
   $ok_affiche=false;
   $tab_groupe=valid_group($user);
   $ok_affiche=groupe_forum($myrow[forum_pass], $tab_groupe);
   if (!$ok_affiche) {
      header("location: forum.php");
   }
}
if (($forum_type==9) and (!$user)) {
   header("location: forum.php");
}
// Moderator
if ($user) {
   $userX = base64_decode($user);
   $userdata = explode(":", $userX);
}
$moderator=get_moderator($mod);
$moderator=explode(" ",$moderator);
$Mmod=false;
for ($i = 0; $i < count($moderator); $i++) {
   if (($userdata[1]==$moderator[$i])) { $Mmod=true; break;}
}

$sql = "SELECT topic_title, topic_status FROM forumtopics WHERE topic_id = '$topic'";
if (!$result = mysql_query($sql))
   forumerror(0001);
$myrow = mysql_fetch_array($result);
$topic_subject = stripslashes($myrow[topic_title]);
$lock_state = $myrow[topic_status];

if ($allow_forum_hide==true) {
   $show_hide = false;
   if ($Mmod!=true) {
      $sql = "Select count(*) from posts where topic_id = $topic and poster_id = $userdata[0]";
      $result = @mysql_result(@mysql_query($sql),0,0);
      if ($result>0) {
         $show_hide = true;
      }
   } else {
      $show_hide = true;
   }
}

   if (isset($user)) {
      if ($cookie[9]=="") $cookie[9]=$Default_Theme;
      if (isset($theme)) $cookie[9]=$theme;
      $tmp_theme=$cookie[9];
      if (!$file=@opendir("themes/$cookie[9]")) {
         $tmp_theme=$Default_Theme;
      }
   } else {
      $tmp_theme=$Default_Theme;
   }
   include("meta/meta.php");
   global $site_font;
   echo import_css($tmp_theme, $language, $site_font);
   echo "<title>$sitename</title>\n";
   echo "</head>\n<body style=\"background-color: #FFFFFF; background-image: none;\">
   <table border=\"0\"><tr><td>
   <table border=\"0\" width=\"640\" cellpadding=\"0\" cellspacing=\"1\" style=\"background-color: #000000;\"><tr><td>
   <table border=\"0\" width=\"640\" cellpadding=\"20\" cellspacing=\"1\" style=\"background-color: #FFFFFF;\"><tr><td align=\"center\">";
   $pos = strpos($site_logo, "/");
   if ($pos)
      echo "<img src=\"$site_logo\" border=\"0\" alt=\"\" />";
   else
      echo "<img src=\"images/$site_logo\" border=\"0\" alt=\"\" />";

   echo "<br /><br /><table border=\"0\" width=\"640\" cellpadding=\"2\" cellspacing=\"2\"><tr><td>".translate("Forum Index")." » » ";
   echo stripslashes($forum_name);
   echo "</td></tr></table>\n";

   echo "<table border=\"0\" width=\"640\" cellpadding=\"2\" cellspacing=\"1\">";
   echo "<tr>";
   echo "<td width=\"15%\"><hr noshade class=\"ONGL\">".translate("Author")."</td>";
   echo "<td><hr noshade class=\"ONGL\">$topic_subject</td></tr>";
   if ($Mmod) {
      $post_aff=" ";
   } else {
      $post_aff=" and post_aff='1' ";
   }
   $sql = "SELECT * FROM posts WHERE topic_id='$topic' and post_id='$post_id'".$post_aff;
   if (!$result = mysql_query($sql))
      forumerror(0001);
   $myrow = mysql_fetch_array($result);

   if ($allow_upload_forum) {
      $visibility = "";
      if (!$Mmod) {
         $visibility = " and visible = 1";
      }
      $sql = "SELECT att_id FROM $upload_table WHERE apli='forum_npds' && topic_id = '$topic' $visible";
      $att = @mysql_num_rows(@mysql_query($sql));
   }
   if ($att>0) {
      include ("modules/upload/include_forum/upload.func.forum.php");
   }

   echo "<tr style=\"background-color: ".$row_color.";\" align=\"left\">";
   $posterdata = get_userdata_from_id($myrow[poster_id]);
   echo "<td width=\"15%\" valign=\"top\">";
   $posts = $posterdata[posts];

   echo $posterdata[uname];
   echo "<br />";
   echo member_qualif($posterdata[uname], $posts, $posterdata[rank]);
   echo "<br /><br />";
   if ($smilies) {
      if ($posterdata[user_avatar] != '') {
         if (stristr($posterdata[user_avatar],"users_private")) {
            $imgtmp=$posterdata[user_avatar];
         } else {
            if ($ibid=theme_image("forum/avatar/$posterdata[user_avatar]")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/avatar/$posterdata[user_avatar]";}
         }
         if ($posterdata[mns]) {
            echo "<p align=\"center\"><a href=\"minisite.php?op=$posterdata[uname]\" target=\"_blank\"><img src=\"$imgtmp\" alt=\"\" border=\"0\" /></a></p>";
         } else {
            echo "<p align=\"center\"><img src=\"$imgtmp\" border=\"0\" alt=\"\" /></p>";
         }
      }
   }

   echo "</td><td wrap valign=\"top\" width=\"100%\" height=\"100%\">";

   if ($myrow[image] != "") {
      if ($ibid=theme_image("forum/subject/$myrow[image]")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/subject/$myrow[image]";}
      echo "<img src=\"$imgtmp\" border=\"0\" alt=\"\" />";
   } else {
      echo "<img src=\"$imgtmpPI\" border=\"0\" alt=\"\" />";
   }
   echo "&nbsp;&nbsp;".translate("Posted: ").convertdate($myrow[post_time]);
   echo "<br /><br />\n";
   $message=stripslashes($myrow[post_text]);
   if ($allow_bbcode==1) {
      $message = Smilie($message);
   }
   // <A href in the message
   if (stristr($message,"<a href")) {
      $message=eregi_replace("_blank\"", "_blank\" class=\"NOIR\"", $message);
   }
   if ($allow_forum_hide) {
      $message = control_hide_post($message,$show_hide);
   }
   $message=split_string_without_space($message, 80);
   if (($forum_type=="6") or ($forum_type=="5")) {
      highlight_string(stripslashes($myrow[post_text]))."<br /><br />";
   } else {
      echo $message=str_replace("[addsig]", "<br /><br />" . nl2br($posterdata[user_sig]), $message);
   }
   if ($att>0) {
      $post_id=$myrow[post_id];
      echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"1\" width=\"100%\">";
      echo "<tr><td>";
      echo display_upload("forum_npds",$post_id,$Mmod);
      echo "</td></tr></table>";
   }
   echo "</td></tr></table>";
   echo "<br /><hr noshade class=\"ONGL\"><br />
         ".translate("This article comes from")." $sitename<br /><br />
         <a href=\"$nuke_url\">$nuke_url/viewtopic.php?topic=$topic&forum=$forum</a><br />";
   echo "</td></tr></table>
         </td></tr></table>
         </td></tr></table>
         </body></html>";
?>