<?php

######################################################################
# Modulo Splatt Forum per PHP-NUKE ver.5.X
#-------------------------
# Versione: 3.1
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
# 
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# PHP-NUKE Add-On 2.0 :
# =====================
#
#              PHPBB Integration 
#        Brought to you by PHPNuke Add-On Team
#
# Copyright (c) 2000 by Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)
#                       Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)
# http://www.phpnuke.web.id
#
#
######################################################################
# PHPBB 
# ==============
#
# Copyright (C) 2000 by James Atkinson (james@totalgeek.org)
# http://www.phpbb.com
#
#  Updates:
#  Yokhannan (support@4cm.com)
#         Added AIM feature.
#        Added YIM & MSNM Feature
#
#  James Atkinson (james@totalgeek.org)
#        Changed ths file over to use posters ID number
#        insteed of their username.
#
# Nathan (nate@codding.org)
#        using users.user_posts for the post count.
#
# John B. Abela (abela@4cm.com)
#         Changed the ICQ Issues.
#
######################################################################
# Splatt Forum 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.
# Splatt Forum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   
# 02111-1307  USA
######################################################################

$module_name = "$name";

if (!eregi("modules.php", $PHP_SELF)) {
    die ("You can't access this file directly...");
}

include("config.php");
include("modules/".$module_name."/functions.php");
include("modules/".$module_name."/auth.php");
include("modules/$module_name/attachment.php");


$sql = "SELECT forum_type, forum_id, forum_pass, forum_name, forum_access, forum_moderator, forum_atch FROM ${prefix}_forums WHERE forum_id = '$forum'";

if(!$result = mysql_query($sql, $db))
        die("<font size=+1>An Error Occured</font><hr>"._FCOULDNOT."");
$myrow = mysql_fetch_array($result);
$forum_name = $myrow[forum_name];
$mod = $myrow[forum_moderator];
$moderators = get_moderators($forum, $db);
$mypass = $myrow[forum_pass];
$forum_id = $myrow[forum_id];
$atch = $myrow[forum_atch];


	if($myrow[forum_type] == 1 && (($myrow[forum_name] != $forum_name) || ($bypass != 1))) {

		$valore = "$passwd:$forum_id";
		$info = explode(":",$HTTP_COOKIE_VARS["Accessfpriv"]);	
			if($info[0] !=$mypass && $myrow[forum_type] == 1){
header("Location:modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum_id");
			}
		}

include('header.php');


	if ($user) {
        $userdata = base64_decode($user);
        $userdata = explode(":", $userdata);
		}

reset ($moderators);
while(list($null, $mods) = each($moderators)) {
        while(list($mod_id, $mod_name) = each($mods)) {

                if ($userdata[0] == $mod_id) {
                        $mod = $mod_id;
                        break 2;
                }
       	 	}
		}


$sql = "SELECT topic_title, topic_status FROM ${prefix}_forumtopics WHERE topic_id = '$topic'";

$total = get_total_posts($topic, $db, "topic");
	
		if($total > $posts_per_page) {
        	$times = 0;
        	for($x = 0; $x < $total; $x += $posts_per_page)
                $times++;
        	$pages = $times;
			}

		if(!$result = mysql_query($sql, $db))
        	die("<font size=+1>"._ERRORE1."</font><hr>"._FCOULDNOT."");

$myrow = mysql_fetch_array($result);
$topic_subject = stripslashes($myrow[topic_title]);
$lock_state = $myrow[topic_status];

?>

<br><TABLE BORDER="0" WIDTH="100%"><TR><TD ALIGN=LEFT>
<FONT SIZE=1><b>

<?
echo _MODERATED;

$count = 0;
reset ($moderators);
while(list($null, $mods) = each($moderators)) {
        while(list($mod_id, $mod_name) = each($mods)) {

                if($count > 0) { echo " , "; }

                echo "<a href=\"modules.php?name=Your_Account&op=userinfo&uname=$mod_name\">$mod_name</a>";

                $count++;
        }
	}

?>

</b><br><br>

<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=index"><?php echo "$sitename : "._FINDEX;?></a> <b>» »</b>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum&forum=<?php echo $forum?>"><?php echo stripslashes($forum_name)?></a> <b>» »</b> <?php echo $topic_subject;?></FONT>
</TD><TD>
<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=newtopic&forum=<?php echo $forum?>&mod=<?php echo $mod?>"><IMG SRC="images/forum/nuovomess<? if($currentlang == english || $currentlang == french || $currentlang == german){echo "-$currentlang";}?>.gif" BORDER="0"></a>&nbsp;&nbsp;
<?php
                if($lock_state != 1) {
?>
                        <a href="modules.php?op=modload&name=<?php echo $module_name?>&file=reply&topic=<?php echo $topic ?>&forum=<?php echo $forum ?>&mod=<?php echo $mod ?>"><IMG SRC="images/forum/rispondimess<? if($currentlang == english || $currentlang == french || $currentlang == german){echo "-$currentlang";}?>.gif" BORDER="0"></a></TD>
<?php
                }
                else {
?>
                        <IMG SRC="images/forum/icons/reply_locked-dark.jpg" BORDER="0"></TD>
<?php
                }
echo "</TR><TABLE>";
		if($total > $posts_per_page) {
        echo "<TABLE BORDER=0 WIDTH=100% ALIGN=CENTER>";
        $times = 1;
        echo "<TR ALIGN=\"RIGHT\"><TD><font size=1><b>$pages</b> "._FPAGES." ( ";
        for($x = 0; $x < $total; $x += $posts_per_page) {
                if($times != 1)
                        echo " | ";
                echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum&start=$x\">$times</a>";
                $times++;
        }
        echo " ) </TD></TR></TABLE>\n";
}
?>

<TABLE BORDER="0" CELLPADDING="1" CELLPADDING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="100%"><TR><TD>
<TABLE BORDER="0" CELLPADDING="3" CELLPADDING="1" WIDTH="100%">
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
        <TD WIDTH=20%><B><font COLOR="<?php echo $textcolor1?>"><?php echo _FAUTHOR;?></FONT></B></TD>
        <TD><B><font COLOR="<?php echo $textcolor1?>"><?php echo $topic_subject?></FONT></B></TD>
</TR>
<?php
		if(isset($start)) {
        $sql = "SELECT * FROM ${prefix}_posts WHERE topic_id = '$topic' ORDER BY post_id LIMIT $start, $posts_per_page";
			}
			else {
        $sql = "SELECT * FROM ${prefix}_posts WHERE topic_id = '$topic' ORDER BY post_id LIMIT $posts_per_page";
}
		if(!$result = mysql_query($sql, $db))
        die("<font size=+1>"._ERRORE1."</font><hr>"._FCOULDNOT."");
$myrow = mysql_fetch_array($result);
$row_color = $color2;
$count = 0;


if(isset($userdata[0]) && $userdata[0] == $mod) { $viewip = 1; }

do {
   if(!($count % 2))
     $row_color = $bgcolor3;
   else
     $row_color = $bgcolor1;

   echo "<TR BGCOLOR=\"$row_color\" ALIGN=\"LEFT\">\n";
   if($myrow[poster_id] != 1) {
           $posterdata = get_userdata_from_id($myrow[poster_id], $db);
        }
   else
     $posterdata = array("uid" => 1, "uname" => ""._FANONIMO."", "posts" => "0", "rank" => -1);
   echo "<TD rowspan=\"2\" valign=top><b>$posterdata[uname]</b><br><br>\n";

if ($posterdata[user_avatar] != '') {
   echo "<img src=\"images/forum/avatar/$posterdata[user_avatar]\"><br>";
	}
   $posts = $posterdata[user_posts];

		
/*
list($level) = mysql_fetch_array(mysql_query("SELECT user_id FROM ${prefix}_forum_mods WHERE forum_id = '$forum'"));
*/
$sql = "SELECT * FROM ${prefix}_forum_mods WHERE forum_id = '$forum' and user_id = '$posterdata[uid]'";
$risultato = mysql_query($sql) or
		die(mysql_error());
        if(mysql_num_rows($risultato) == 0) {
                $moderatore = 0;
		}
		else {
        		$moderatore = 1;
}

	
if($posterdata[user_level] == 3)

	{
echo "<br><img src=\"images/forum/pips_admin.gif\"><br>";
}

   if($posterdata[uid] != 1)

 	{

		if($moderatore == 1 && $posterdata[user_level] != 3)


 		{
		echo "<br><img src=\"images/forum/pips_moderator.gif\"><br>";
		}

			else {

     			if($posterdata[user_rank] != 0)
             $sql = "SELECT rank_title, rank_image FROM ${prefix}_ranks WHERE rank_id = '$posterdata[user_rank]'";
           		else
             $sql = "SELECT rank_title, rank_image FROM ${prefix}_ranks WHERE rank_min <= " . $posterdata[user_posts] . " AND rank_max >= " . $posterdata[user_posts] . " AND rank_special = 0";
           if(!$rank_result = mysql_query($sql, $db))
             die("Error connecting to the database!");
           list($rank, $rankimage) = mysql_fetch_array($rank_result);
			if($rankimage == ""){
           echo "<font size=1>" . stripslashes($rank) . "</font>";
		}else
				{
if($posterdata[user_level] != 3) {
			echo "<br><img src=\"images/forum/special/$rankimage\" alt=\"$rank\"><br>";
}
		}

	
}

           echo "<BR>"._FJOINED."<br>".convertidatasolo($posterdata[user_regdate])." \n";
           
if($posterdata[user_from]!="")
           
           echo "<br><br>"._FFROM."$posterdata[user_from]\n";
echo "<br><br>"._FAPOSTS."&nbsp;<b>$posts</b><br><br>\n";


$result2 = mysql_query("SELECT username,guest FROM $prefix"._session." where username='$posterdata[uname]'");
            $member_online_num = mysql_num_rows($result2);
if ($member_online_num != 0)
	      echo"<img src=\"images/forum/subject/rose.gif\" height=\"19\" width=\"19\"><font color=\"red\"><b>ON-Line</b></font><br><br>";
	else
          echo"<img src=\"images/forum/subject/icon20.gif\" height=\"19\" width=\"19\"><font color=\"blue\"><b>OFF-Line</b></font><br><br>";	

}
        
   		else {
           echo"<img src=\"images/forum/avatar/018.gif\"><br>";
			echo "<font size=1>"._NOTREG."</font>";
        }


   echo"</td>";

   if ($myrow[image] != "") echo "<TD valign=\"top\"><img src=\"images/forum/subject/$myrow[image]\"><font size=1>";
   else echo "<TD valign=\"top\"><img src=\"images/forum/icons/posticon.gif\"><font size=1>";


   echo "&nbsp;"._FTPOSTED."&nbsp;".convertiData($myrow[post_time])."&nbsp;&nbsp;&nbsp";
   echo "<HR></font>\n";
   $message = stripslashes($myrow[post_text]);
Opentable();
   $message = eregi_replace("\[addsig]", "<br><br><BR>-----------------<BR>" . bbencode($posterdata[user_sig]), $message);

   echo $message . "<BR>";
Closetable();

echo"</td></tr><TR BGCOLOR=\"$row_color\"><td>";
   echo "<HR>\n";

if ($atch==1){
echo ShowAttach($myrow[post_id]);
}
   if($posterdata[uid] != 1)
   echo "&nbsp<a href=\"modules.php?name=Your_Account&op=userinfo&uname=$posterdata[uname]\"><img src=\"images/forum/icons/profile.gif\" border=0></a><FONT SIZE=1>"._FAPROFIL."</FONT>\n";
   if($posterdata["femail"] != '')
     echo "&nbsp;<a href=\"mailto:$posterdata[femail]\"><IMG SRC=\"images/forum/icons/email.gif\" BORDER=0></a><FONT SIZE=1>"._FAEMAIL."</FONT>\n";
   if($posterdata["url"] != '') {
      if(strstr("http://", $posterdata["url"]))
        $posterdata["url"] = "http://" . $posterdata["url"];
      echo "&nbsp;<a href=\"$posterdata[url]\" TARGET=\"_blank\"><IMG SRC=\"images/forum/icons/www_icon.gif\" BORDER=0></a><FONT SIZE=1>www</FONT>\n";
   }
   if($posterdata["user_icq"] != '')
     echo "&nbsp;<a href=\"http://wwp.icq.com/$posterdata[user_icq]#pager\" target=\"_blank\"><img src=\"http://online.mirabilis.com/scripts/online.dll?icq=$posterdata[user_icq]&img=5\" border=\"0\"></a>&nbsp;<a href=\"http://wwp.icq.com/scripts/search.dll?to=$posterdata[user_icq]\"><img src=\"images/forum/icons/icq_add.gif\" border=\"0\"></a><FONT SIZE=1>"._FAADD."</FONT>";

   if($posterdata["user_aim"] != '')
     echo "&nbsp;<a href=\"aim:goim?screenname=$posterdata[user_aim]&message=Hi+$posterdata[user_aim].+Are+you+there?\"><img src=\"images/forum/icons/aim.gif\" border=\"0\"></a><FONT SIZE=1>aim</FONT>";

   if($posterdata["user_yim"] != '')
     echo "&nbsp;<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=$posterdata[user_yim]&.src=pg\"><img src=\"images/forum/icons/yim.gif\" border=\"0\"></a>";

   if($posterdata["user_msnm"] != '')
     echo "&nbsp;<a href=\"modules.php?name=Your_Account&op=userinfo&uname=$posterdata[uname]\"><img src=\"images/forum/icons/msnm.gif\" border=\"0\"></a>";

   echo "&nbsp;<IMG SRC=\"images/forum/icons/div.gif\">\n";
   if($posterdata[uid]==$userdata[0] || $mod==$userdata[0])
     echo "&nbsp;<a href=\"modules.php?op=modload&name=".$module_name."&file=editpost&post_id=$myrow[post_id]&topic=$topic&forum=$forum\"><img src=\"images/forum/icons/edit.gif\" border=0></a><FONT SIZE=1>"._FAEDIT."</FONT>\n";
     echo "&nbsp;<a href=\"modules.php?op=modload&name=".$module_name."&file=reply&topic=$topic&forum=$forum&post=$myrow[post_id]&quote=1&mod=$mod\"><IMG SRC=\"images/forum/icons/quote.gif\" BORDER=\"0\"></a><FONT SIZE=1>"._FAQOUTE."</FONT>\n";
   if($viewip == 1) {
      echo "&nbsp;<IMG SRC=\"images/forum/icons/div.gif\">\n";
      echo "&nbsp;<a href=\"modules.php?op=modload&name=".$module_name."&file=topicadmin&mode=viewip&post=$myrow[post_id]&forum=$forum\"><IMG SRC=\"images/forum/icons/ip_logged.gif\" BORDER=0></a><FONT SIZE=1>ip</FONT>\n";
   }
   echo "</TD></TR>";
   $count++;
} while($myrow = mysql_fetch_array($result));
$sql = "UPDATE ${prefix}_forumtopics SET topic_views = topic_views + 1 WHERE topic_id = '$topic'";
@mysql_query($sql, $db);
?>

</TABLE></TD></TR></TABLE>
<TABLE ALIGN="CENTER" BORDER="0" WIDTH="95%">
<?php
if($total > $posts_per_page) {
        $times = 1;
        echo "<TR ALIGN=\"RIGHT\"><TD COLSPAN=2><font size=1>"._FGOTO."";
        for($x = 0; $x < $total; $x += $posts_per_page) {
                if($times != 1)
                        echo " | ";
                echo "  <a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum&start=$x\">$times</a>";
                $times++;
        }
        echo "</TD></TR>\n";
}
?>
<TR>
        <TD>
                <a href="modules.php?op=modload&name=<?php echo $module_name?>&file=newtopic&forum=<?php echo $forum?>&mod=<?php echo $mod?>"><IMG SRC="images/forum/nuovomess<? if($currentlang == english || $currentlang == french || $currentlang == german){echo "-$currentlang";}?>.gif" BORDER="0"></a>&nbsp;&nbsp;
<?php
                if($lock_state != 1) {
?>
                        <a href="modules.php?op=modload&name=<?php echo $module_name?>&file=reply&topic=<?php echo $topic ?>&forum=<?php echo $forum ?>&mod=<?php echo $mod ?>"><IMG SRC="images/forum/rispondimess<? if($currentlang == english || $currentlang == french || $currentlang == german){echo "-$currentlang";}?>.gif" BORDER="0"></a></TD>
<?php
                }
                else {
?>
                        <IMG SRC="images/forum/icons/reply_locked-dark.jpg" BORDER="0"></TD>
<?php
                }
?>
        </TD>
<TD ALIGN="RIGHT">
<FORM ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum" METHOD="POST">
<font face="Verdana" size="2"><?php echo _JUMPTO;?></font> <SELECT NAME="forum"><OPTION VALUE="-1"><?php echo _FSELECTF;?></OPTION>
<?php
        $sql = "SELECT cat_id, cat_title FROM ${prefix}_catagories ORDER BY cat_id";
        if($result = mysql_query($sql, $db)) {
                $myrow = mysql_fetch_array($result);
                do {
                        echo "<OPTION VALUE=\"-1\">&nbsp;</OPTION>\n";
                        echo "<OPTION VALUE=\"-1\">$myrow[cat_title]</OPTION>\n";
                        echo "<OPTION VALUE=\"-1\">----------------</OPTION>\n";
                        $sub_sql = "SELECT forum_id, forum_name FROM ${prefix}_forums WHERE cat_id = '$myrow[cat_id]' ORDER BY forum_id";
                        if($res = mysql_query($sub_sql, $db)) {
                                if($row = mysql_fetch_array($res)) {
                                        do {
                                                $name = stripslashes($row[forum_name]);
                                                echo "<OPTION VALUE=\"$row[forum_id]\">$name</OPTION>\n";
                                        } while($row = mysql_fetch_array($res));
                                }
                                else {
                                        echo "<OPTION VALUE=\"0\">"._FNOMORE."</OPTION>\n";
                                }
                        }
                        else {
                                echo "<OPTION VALUE=\"0\">"._FCOULDNOT."</OPTION>\n";
                        }
                } while($myrow = mysql_fetch_array($result));
        }
        else {
                echo "<OPTION VALUE=\"-1\">"._FERRORE."</OPTION>\n";
        }
?>
</SELECT>
<INPUT TYPE="SUBMIT" VALUE="Go">
</FORM>
</TR></TABLE>

<?php
if(isset($userdata[0]))
{
list($level) = mysql_fetch_array(mysql_query("SELECT user_level FROM ${prefix}_users WHERE uid = '$userdata[0]'"));

if(($userdata[0] == $mod) or ($level == 3))
{
echo "<CENTER>";
echo "<font size=1><b>"._FADMINT."</b></font><br>";
echo "-------------------------<br>";
if($lock_state != 1)
        echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=topicadmin&mode=lock&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/lock_topic.gif\" ALT=\""._LOCKTHIS."\" BORDER=0></a> ";
else
        echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=topicadmin&mode=unlock&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/unlock_topic.gif\" ALT=\""._UNLOCKTHIS."\" BORDER=0></a> ";

echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=topicadmin&mode=move&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/move_topic.gif\" ALT=\""._FMOVET."\" BORDER=0></a> ";
echo "<a href=\"modules.php?op=modload&name=".$module_name."&file=topicadmin&mode=del&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/del_topic.gif\" ALT=\""._FDELT."\" BORDER=0></a></CENTER>\n";

}
}

?>
<!-- Don't touch the lines above please! --> 
<p align="center"><font size="1">Splatt Forum By: <a href="http://www.splatt.it">Splatt.it</a><br>Versione: 3.1</font></p>

<?php
include("footer.php");
?>