<?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 1.0.BETA
#        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
#
#
######################################################################
# 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($cancel) {
        header("Location: modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum");
}

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

$use_forum_password_fix = 1;

$sql = "SELECT 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>"._ERRORE1."</font><hr>Could not connect to the forums database.");
}
$myrow = mysql_fetch_array($result);
$forum_name = $myrow[forum_name];
$forum_access = $myrow[forum_access];
$forum_id = $forum;
$atch = $myrow[forum_atch];

if(is_locked($topic, $db)) {
        die(""._FLOKTOP.".");
}

if(!does_exists($forum, $db, "forum") || !does_exists($topic, $db, "topic")) {
        die("Error - The forum or topic you are attempting to post to does not exist. Please try again.");
}

if($submit) {
        if($message == '') $stop=1;

        if (!$user) {
                if($username == '' && $password == '' && $forum_access == 0) {
                        // Not logged in, and username and password are empty and forum_access is 0 (anon posting allowed)
                        $userdata = array("uid" => 1);
                       // include('header.php');
                }
                else {
                        // no valid session, need to check user/pass.
                        if($username == '' || $password == '') {
                                die("You must enter your username and password. Go back and do so.");
                        }

                        
                        $userdata = get_userdata($username, $db);

$dbpass=$userdata[pass];
$non_crypt_pass = $password;
$old_crypt_pass = crypt($password,substr($dbpass,0,2));
$md_pass = md5($password);
	if (($dbpass == $non_crypt_pass) OR ($dbpass ==
$old_crypt_pass)) {
    	$md_pass=$dbpass;
}

                        if($md_pass == $userdata[pass]) {
                                $info = base64_encode("$userdata[uid]:$userdata[uname]:$userdata[pass]:$userdata[storynum]:$userdata[umode]:$userdata[uorder]:$userdata[hold]:$userdata[noscore]:$userdata[ublockon]:$userdata[theme]:$userdata[commentmax]");
                                setcookie("user","$info",time()+15552000);
                             //   include('header.php');
                        }
                        else {
                        die("You have entered an incorrect password. Go back and try again.");
                        }
                }
        }
        else {
     //   include('header.php');
               $user = base64_decode($user);
               $userdata = explode(":", $user);
               $userdata = get_userdata($userdata[1], $db);
        }
        // Either valid user/pass, or valid session. continue with post.

        if ($stop != 1) {
        $poster_ip = $REMOTE_ADDR;
        if($allow_html == 0 || isset($html)) $message = htmlspecialchars($message);
        if($sig && $userdata[uid] != 1) $message .= "[addsig]";
        if($allow_bbcode == 1 && !isset($bbcode)) $message = bbencode($message);
        $message = str_replace("\n", "<BR>", $message);
        if(!$smile) $message = smile($message);
        $Message = $message;
        $message = check_words($Message);
        $message = make_clickable($message);
        $message = addslashes($message);
        $time = date("Y-m-d H:i");
        $sql = "INSERT INTO ${prefix}_posts (topic_id, image, forum_id, poster_id, post_text, post_time, poster_ip) VALUES ('$topic', '$image_subject', '$forum', '$userdata[uid]', '$message', '$time', '$poster_ip')";
        if(!$result = mysql_query($sql, $db)) {
                die("Error - Could not enter data into the database. Please go back and try again");
        }
$post_id = mysql_insert_id($db);
        ConfirmAttach($post_id);
        include('header.php');
        $sql = "UPDATE ${prefix}_forumtopics SET topic_time = '$time' WHERE topic_id = '$topic'";
        if(!$result = mysql_query($sql, $db)) {
                die("Error - Could not enter data into the database. Please go back and try again");
        }
        if($userdata["uid"] != 1) {
                $sql = "UPDATE ${prefix}_users SET user_posts=user_posts+1 WHERE (uid = $userdata[uid])";
                $result = mysql_query($sql, $db);
                if (!$result) {
                        echo mysql_error() . "<br>\n";
                        die("Error updating post count.");
                }
        }
        $sql = "SELECT t.topic_notify, u.email, u.uname FROM ${prefix}_forumtopics t, ".$prefix."_users u WHERE t.topic_id = '$topic' AND t.topic_poster = u.uid";
        if(!$result = mysql_query($sql, $db)) {
                die("Error - Could not query the database.");
        }
        $m = mysql_fetch_array($result);

        if($m[topic_notify] == 1 && $m[uname] != $username) {

                $subject = ""._NOTIFSUB."";
                $message = ""._CIAO." $m[uname]\r\n"._NOTIFM1."";
                $message .= ""._NOTIFM2."";
                $message .= $nukeurl."/modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum\r\n"._NOTIFM3."".$nukeurl."/index.php";
                $message .= "\r\n\r\n"._GRAZ.". \r\n "._APRSTAF.".";
                // if (!$system)
                mail($m[email], $subject, $message, "From: $adminmail\r\nX-Mailer: phpNuke_forum");

        }


        // Keledan
        $total = get_total_posts($topic, $db, "topic");
        if($total > $posts_per_page) {
           $start = floor ($total / $posts_per_page) * $posts_per_page ;
           $pagina = "modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum&start=$start";
        } else $pagina = "modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic&forum=$forum";
        // Keledan

        echo "<center>"._FPOSTED."<br><a href=\"$pagina\">"._FVIEW."</center><P></font>";
        ?>
        <script language="Javascript" type="text/javascript">
        <!--
        function gotoThread(){
        window.location.href="<?php print "$pagina" ?>";
        }
        window.setTimeout("gotoThread()", 3000);
        //-->
        </script>
        <?php
       }
       else echo _YOUMUST;

} else {
resetAtchCookie();
        include('header.php');
$moderator = get_moderator($mod,$db);
$moderators = get_moderators($forum, $db);

list($topic_title) = mysql_fetch_array(mysql_query("select topic_title from ${prefix}_forumtopics where topic_id='$topic'"));
?>
        <P ALIGN=LEFT><FONT SIZE="1"><br><b>

        <!--
        <b><?php echo ""._MODERATED."<a href=modules.php?name=Your_Account&op=userinfo&uname=$moderator>$moderator";?></a>
        -->

        <?
$topic_title = stripslashes($topic_title);

        echo ""._MODERATED."</b>";

        $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++;
                }
        }


        ?>

        <br><b>
        <?php echo _FORUM;?>: </b>&nbsp;<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum&forum=<?php echo $forum?>"><?php echo  $forum_name?></a><br><b>
        <?php echo _POSTIN;?></b>&nbsp;<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewtopic&forum=<?php echo $forum?>&topic=<?php echo $topic?>"><?php echo $topic_title?></a>
        </b></font></p>
        <FORM ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=reply" METHOD="POST" NAME="coolsus">
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACING=0" ALIGN="CENTER" VALIGN="TOP" WIDTH="100%"><TR><TD>
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACING=1" WIDTH="100%">
        <TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
                <TD width=25%><FONT COLOR="<?php echo $textcolor1;?>"><b><?php echo _TYPES;?></b></FONT></TD>
<?php
        if($forum_access == 0) {
?>
                <TD><FONT COLOR="<?php echo $textcolor1;?>"><?php echo ""._FANON."&nbsp;"._FCANWRITE.""?></FONT></TD>

<?php
        }
        else if($forum_access == 1) {
?>
                <TD><FONT COLOR="<?php echo $textcolor1;?>"><?php echo ""._FREG."&nbsp;"._FCANWRITE."";?></FONT></TD>
<?php
        }
        else if($forum_access == 2) {
?>
                <TD><FONT COLOR="<?php echo $textcolor1;?>"><?php echo ""._FMODS."&nbsp;"._FCANWRITE."";?></FONT></TD>
<?php
        }
?>
        </TR>
<?PHP
        if (isset($user) && $forum_access == 1) {
                $user = base64_decode($user);
                $userdata = explode(":", $user);
                $sql = "SELECT pass, user_level FROM ".$prefix."_users WHERE uid = '$userdata[0]'";
                $result = mysql_query($sql, $db);
                $user = mysql_fetch_array($result);

                if ($use_forum_password_fix == 1) {
                        $password = $user[pass];
                } else {
                        if (!$system) $password = base64_decode($user[pass]);
                        else $password = $user[pass];
                }

                if ($password == $userdata[2] && $forum_access <= $user[user_level]) {
                echo "<TR ALIGN=LEFT>";
                echo "<TD  BGCOLOR=$bgcolor3  width=25%><b>"._FNICKNAME."<b></TD>";
                echo "<TD  BGCOLOR=$bgcolor1>";
                echo $userdata[1] . " \n";
                echo "</TD></TR> \n";
                $allow_to_reply= 1;
                }
                else {
                echo "<TR>";
                echo "<TD BGCOLOR=$bgcolor3 COLSPAN=2 ALIGN=CENTER>"._YOUNOT."<BR><A HREF=javascript:history.go(-1)>"._FBACK."</A></TD>";
                echo "</TR>";
                }
        } elseif (!isset($user) && $forum_access == 1) {
                echo "<TR ALIGN=LEFT>";
                echo "<TD  BGCOLOR=$bgcolor3  width=25%><b>"._FNICKNAME."<b></TD>";
                echo "<TD  BGCOLOR=$bgcolor1>";
                echo "<INPUT CLASS=textbox TYPE=\"TEXT\" NAME=\"username\" SIZE=\"25\" MAXLENGTH=\"40\" ></TD> \n";
                echo "<TR ALIGN=\"LEFT\"> \n";
                echo "<TD BGCOLOR=\"$bgcolor3\" width=25%><b>"._FPASSWORD."</b></TD> \n";
                echo "<TD BGCOLOR=\"$bgcolor1\"><INPUT CLASS=textbox TYPE=\"PASSWORD\" NAME=\"password\" SIZE=\"25\" MAXLENGTH=\"25\"></TD> \n";
                echo "</TR> \n";
                $allow_to_reply = 1;
        } elseif ($forum_access == 2) {
                echo "<TR ALIGN=LEFT>";
                echo "<TD  BGCOLOR=$bgcolor3  width=25%><b>"._FNICKNAME."<b></TD>";
                echo "<TD  BGCOLOR=$bgcolor1>";
                echo "<INPUT CLASS=textbox TYPE=\"TEXT\" NAME=\"username\" SIZE=\"25\" MAXLENGTH=\"40\"></TD> \n";
                echo "<TR ALIGN=\"LEFT\"> \n";
                echo "<TD BGCOLOR=\"$bgcolor3\" width=25%><b>"._FPASSWORD."</b></TD> \n";
                echo "<TD BGCOLOR=\"$bgcolor1\"><INPUT CLASS=textbox TYPE=\"PASSWORD\" NAME=\"password\" SIZE=\"25\" MAXLENGTH=\"25\"></TD> \n";
                echo "</TR> \n";
                $allow_to_reply = 1;
        } elseif ($forum_access == 0) {
                $allow_to_reply = 1;
        }

if ($allow_to_reply) {

addForumScripts();
?>
        <TR ALIGN="LEFT">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25% VALIGN="TOP"><b><?php echo _FMICON;?></b></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>">
        <?php
                $handle=opendir("./images/forum/subject");
                while ($file = readdir($handle))
                        {
                        $filelist[] = $file;
                }
                asort($filelist);
                while (list ($key, $file) = each ($filelist))
                {
                ereg(".gif|.jpg",$file);
                if ($file == "." || $file == ".." || $file == "index.html") $count=1;
                else {
                        echo "<input type=\"radio\" value=\"$file\" name=\"image_subject\">&nbsp;";
                        echo "<IMG SRC=\"images/forum/subject/$file\" BORDER=0>&nbsp;";
                        $count++;
                        }
                if ($count == "9") { echo "<br>"; $count = 1; }

                }
        ?>
                 </TD>
        </TR>
        <TR ALIGN="LEFT" VALIGN="TOP">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25%><b><?php echo _FMESSAGE;?></b><br><br>
                <font size=-1>
                <?php
                echo "HTML : ";
                if($allow_html == 1)
                        echo ""._FON."<BR>\n";
                else
                        echo ""._FOFF."<BR>\n";
                echo "<br><a href=\"modules.php?op=modload&name=".$module_name."&file=bbcode_ref\" TARGET=\"blank\">BBCode</a> : ";
                if($allow_bbcode == 1)
                        echo ""._FON."<br>\n";
                else
                        echo ""._FOFF."<BR>\n";
				echo "<br>"._FORUMATCHM." : ";
                if($atch == 1)
                        echo ""._FON."<BR>\n";
                else
                        echo ""._FOFF."<BR>\n";

                if($quote) {

                        $sql = "SELECT p.post_text, p.post_time, u.uname FROM ${prefix}_posts p left outer join ".$prefix."_users u on p.poster_id = u.uid WHERE post_id = '$post' " ;
                        if($r = mysql_query($sql, $db)) {
                                $m = mysql_fetch_array($r);
                                $text = desmile($m[post_text]);
                                $text = str_replace("<BR>", "\n", $text);
                                $text = stripslashes($text);
                                $text = bbdecode($text);
                                if ($m[uname]) {
                                        $poster = $m[uname];
                                } else {
                                        $poster = ""._FANONIMO."";
                                }
                                $reply = "[quote]\nOn $m[post_time], $poster wrote:\n$text\n[/quote]";
                        }
                        else {
                                $reply = "Error Contacting database. Please try again.\n";
                        }
                }
                ?>
                </font></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>"><TEXTAREA CLASS=textbox NAME="message" ROWS=10 COLS=50 WRAP="VIRTUAL"><?php echo $reply?></TEXTAREA>
<?php
			if($atch == 1)
				{
                // JoyDivision Start
                echo "<br>".getAttachCode()."<br>";
                // JoyDivision End
				}
?>
<br>
                <?php putitems();?></TD>
        </TR>
        <TR ALIGN="LEFT">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25%><b><?php echo _FOPTIONS;?></b></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>" >
                <?php
                        if($allow_html == 1) {
                ?>
                                <INPUT TYPE="CHECKBOX" NAME="html"><?php echo _DISHTML;?><BR>
                <?php
                        }
                ?>
                <?php
                        if($allow_bbcode == 1) {
                ?>
                                <INPUT TYPE="CHECKBOX" NAME="bbcode"><?php echo ""._FDIS." <a href=\"modules.php?op=modload&name=".$module_name."&file=bbcode_ref\" target=\"_blank\"><i>BBCode</i></a> "._FTHISMAIL;?><BR>
                <?php
                        }
                ?>

                <INPUT TYPE="CHECKBOX" NAME="smile"><?php echo ""._FDIS." <a href=\"modules.php?op=modload&name=".$module_name."&file=bb_smilies\" target=\"_blank\"><i>Smilies</i></a> "._FTHISMAIL;?><BR>
                <?php
                        if($allow_sig == 1) {
                                if($userdata[sig] == 1)
                                        $s = "CHECKED";
                ?>
                                <INPUT TYPE="CHECKBOX" NAME="sig" <?php echo $s?>><?php echo _FSHOWSIG;?> <font size=-2>(<?php echo _WHATISSIG;?>)</font><BR>
                <?php
                        }
                ?>
                </TD>
        </TR>
        <TR>
                <TD  BGCOLOR="<?php echo $bgcolor1?>" colspan=2 ALIGN="CENTER">
                <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
                <INPUT TYPE="HIDDEN" NAME="topic" VALUE="<?php echo $topic?>">
                <INPUT TYPE="SUBMIT" NAME="submit" VALUE="<?php echo _INVIA; ?>">&nbsp;<INPUT TYPE="RESET" VALUE="<?php echo _FRESET; ?>">
                &nbsp;<INPUT TYPE="SUBMIT" NAME="cancel" VALUE="<?php echo _FCANC; ?>">
        </TR>
<?php
}
?>
        </TABLE></TD></TR></TABLE>
        </FORM>
        <BR>
        <CENTER>
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="100%"><TR><TD>
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%">
        <TR><TD COLSPAN=2 BGCOLOR="<?php echo $bgcolor2;?>" ALIGN="CENTER"><b><FONT SIZE=1 COLOR="<?php echo $textcolor1;?>"><?php echo _TREVIEW;?></b></FONT></TD></TR>
<?php
$sql = "SELECT p.image, p.poster_id, p.post_text, p.post_time, u.*
                        FROM ${prefix}_posts p, ".$prefix."_users u where p.poster_id = u.uid and topic_id ='$topic'";

if(!$result = mysql_query($sql, $db))
        die("<font size=+1>"._ERRORE1."</font><hr>Could not connect to the forums database.");
$myrow = mysql_fetch_array($result);
$count=0;
do {
   if (($count%2)!=0) $color=$bgcolor3;
   else $color=$bgcolor1;
   if ($myrow[uname]) {
                $poster = $myrow[uname];
   } else {
                $poster = ""._FANONIMO."";
   }

   echo "<TR BGCOLOR=\"$color\" ALIGN=\"LEFT\">\n";
   echo "<TD valign=top WIDTH=\"19%\"><B>$poster</B><BR><br>";
if ($myrow[user_avatar] && $myrow[user_avatar] != '')
           echo "<img src=\"images/forum/avatar/$myrow[user_avatar]\"><br>";
   if($myrow[uname] && $myrow[poster_id] != 1) {
           $posts = $myrow[user_posts];
           if($myrow[rank] != 0)
             $sql = "SELECT rank_title, rank_image FROM ${prefix}_ranks WHERE rank_id = '$myrow[user_rank]'";
           else
             $sql = "SELECT rank_title, rank_image FROM ${prefix}_ranks WHERE rank_min <= " . $myrow[user_posts] . " AND rank_max >= " . $myrow[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
				{
			echo "<br><img src=\"images/forum/special/$rankimage\" alt=\"$rank\"><br>";
		}
           echo "<BR><font size=1>"._FJOINED."<br>".convertidatasolo($myrow[user_regdate])." </font>\n";
           echo "<br><br><font size=1>"._FAPOSTS."<b>$posts</b><br>\n";
if($myrow[user_from]!="")
           echo ""._FFROM."$myrow[user_from]<br></FONT>\n";

$result2 = mysql_query("SELECT username,guest FROM $prefix"._session." where username='$myrow[uname]'");
            $member_online_num = mysql_num_rows($result2);
if ($member_online_num != 0)
	      echo"<br><img src=\"images/forum/subject/rose.gif\" height=\"19\" width=\"19\"><font color=\"red\"><b>ON-Line</b></font><br><br>";
	else
          echo"<br><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;"._FPOSTED."$myrow[post_time]&nbsp;&nbsp;&nbsp";
   echo "<HR></font>\n";
   $message = stripslashes($myrow[post_text]);
   $message = eregi_replace("\[addsig]", "<BR>-----------------<BR>" . $myrow[user_sig], $message);
   echo $message."<BR><BR>";
   echo "</TD></TR>";
   $count++;
} while($myrow = mysql_fetch_array($result));
echo "</TABLE></TD></TR></TABLE>\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');
?>
}
include('footer.php');

?>