<?php

######################################################################
# Modulo Splatt Forum per PHP-NUKE
#-------------------------
# Versione: 3.2
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# 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=viewforum&forum=$forum");

}

$new_forumtopic_notify = 1;

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_type, 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\">Error:</font><font size=\"2\"><ul>"._FCOULDNOT."</ul><P></font>");

$myrow = mysql_fetch_array($result);
$mypass = $myrow[forum_pass];
$forum_name = $myrow[forum_name];
$forum_access = $myrow[forum_access];
$forum_id = $forum;
$atch = $myrow[forum_atch];

if($myrow[forum_type] == 1) {
	$valore = "$passwd:$forum_id";
	$info = explode(":",$HTTP_COOKIE_VARS["Accessfpriv"]);

if($myrow[forum_type] == 1 && ($info[0] != $mypass || $info[1] != $forum_id) && (($myrow[forum_name] != $forum_name)  || ($bypass != 1))){
header("Location:modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum_id");
	}
}

list($forum_notify_email) = mysql_fetch_array(mysql_query("SELECT forum_notify_email FROM ${prefix}_forums WHERE forum_id = '$forum'"));

if(!does_exists($forum, $db, "forum")) {
        die("<font size=\"+1\">Error:</font><font size=\"2\"><ul>"._FNOTEXIST."</ul><P></font>");
}

if($submit) {
        if($message == '')  {
                $stop=1;
                }
        if($subject == '') {
                $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(""._WRONGPASS."");

                        }

                }

        }

        else {

        include('header.php');          

		$userdata = $cookie;

        $userdata = get_userdata($userdata[1], $db);

        }



        // Either valid user/pass, or valid session. continue with post.



        if ($stop != 1) {

	

        if($allow_html == 0 || isset($html))

                $message = htmlspecialchars($message);

        if($sig && $userdata[uid] != 1) {

                $message .= "[addsig]";

        }

        if($allow_bbcode == 1 && !($HTTP_POST_VARS[bbcode]))

                $message = bbencode($message);

        $message = str_replace("\n", "<BR>", $message);

        if(!$smile) {

                $message = smile($message);

        }
        
	    $message = secure($message);
		$Message = $message;
        $message = check_words($Message);
        $message = make_clickable($message);
        $message = addslashes($message);
        $subject = strip_tags($subject);
        $subject = addslashes($subject);
        $poster_ip = $REMOTE_ADDR;

        $time = date("Y-m-d H:i");

        $sql = "INSERT INTO ${prefix}_forumtopics (topic_title, topic_poster, forum_id, topic_time, topic_notify) VALUES ('$subject', '$userdata[uid]', '$forum', '$time'";

//      Keledan fix

        if($HTTP_POST_VARS[notify] == 1 && $userdata[uid] != 1)

                $sql .= ", '1'";

        else

                $sql .= ", '0'";

        $sql .= ")";

        if(!$result = mysql_query($sql, $db)) {

                die("<font size=\"+1\">Error:</font><font size=\"2\"><ul>"._FCOULDNOTINSERT."</ul><P></font>");

        }

        $topic_id = mysql_insert_id($db);

        $sql = "INSERT INTO ${prefix}_posts (topic_id, image, forum_id, poster_id, post_text, post_time, poster_ip) VALUES ('$topic_id', '$image_subject', '$forum', '$userdata[uid]', '$message', '$time', '$poster_ip')";

        if(!$result = mysql_query($sql, $db)) {

                die("<font size=\"+1\">Error:</font><font size=\"2\"><ul>"._FCOULDNOTINSERT."</ul><P></font>");

        }



$post_id = mysql_insert_id($db);

        ConfirmAttach($post_id);

        //include('header.php');



        if($userdata[uid] != 1) {

                $sql = "UPDATE ${user_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("<font size=\"+1\">"._FERRORE.":</font><font size=\"2\"><ul>"._FPOSTCOUNT."</ul><P></font>");

                }

        }



        $topic = $topic_id;

        // 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



        ?>

        <script language="Javascript" type="text/javascript">

        <!--

        function gotoThread(){

        window.location.href="<?php print "$pagina" ?>";

        }

        window.setTimeout("gotoThread()", 3000);

        //-->

        </script>

        <?php



        echo "<center>"._FPOSTED."<br><a href=\"$pagina\">"._FVIEW."</center></a>";



        if (isset($forum_notify_email)) {



                $email = $forum_notify_email;

                $from = $adminmail;

                $message = "A new topic has been posted to the forums: " . $subject . ".\n\n";

                $message .= $nukeurl."/modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic_id&forum=$forum" . "\n\n";

                $subject = "New topic in the Forums";



/*

                echo "\$email: $email<br>";

                echo "\$from: $from<br>";

                echo "\$subject: $subject<br>";

                echo "\$message: <br>$message<br>";

*/

                mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());



        }





        }

        else echo _YOUMUST;





} else {

resetAtchCookie();

include('header.php');

$moderator = get_moderator($mod,$db);

$moderators = get_moderators($forum, $db);



?>

        <P 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++;

        }

}

?>

        <br>

        <?php echo _POSTINN;?>

        &nbsp;<a href="modules.php?op=modload&name=<?php echo $module_name?>&file=viewforum&forum=<?php echo $forum?>"><?php echo $forum_name?></a></b><br><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> <?php echo $topic_subject;?>

        </font></p>

        <FORM ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=newtopic" 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?>">

                <TD align="left" valign="middle" height="15"><FONT COLOR="<?php echo $textcolor1;?>">&nbsp;<img src="images/forum/question.gif" >&nbsp;&nbsp;
<?php echo "<b>"._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 ".$user_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_post = 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_post = 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_post = 1;

        } elseif ($forum_access == 0) {

                if (isset($user)) {



                        $user = base64_decode($user);

                        $userdata = explode(":", $user);



                        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_post = 1;

        }



if ($allow_to_post) {

addForumScripts();

?>

        <TR ALIGN="LEFT">

                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25%><b><?php echo _FSUBJECT;?></b></TD>

                <TD  BGCOLOR="<?php echo $bgcolor1?>"> <INPUT CLASS=textbox TYPE="TEXT" NAME="subject" SIZE="75" MAXLENGTH="100"></TD>

        </TR>

        <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);

$count = 1;

                while (list ($key, $file) = each ($filelist))

                {

                if (strtoupper(stristr($file,".gif")) == ".GIF" || strtoupper(stristr($file,".jpg")) == ".JPG") {

                        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">

                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25% VALIGN="TOP"><b><?php echo _FMESSAGE;?></b><br><br>

                <font size=-1>

                <?php

                echo "HTML : ";

                if($allow_html == 1)

                        echo "On<BR>\n";

                else

                        echo "Off<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 "On<br>\n";

                else

                        echo "Off<BR>\n";

				echo "<br>"._FORUMATCHM." : ";

				if($atch == 1){

						echo "On<br>\n";

						}

				else {

						echo "Off<br>\n";

						}		

                ?>

                </font></TD>

                <TD  BGCOLOR="<?php echo $bgcolor1?>"><TEXTAREA  NAME="message" ROWS=10 COLS=75 WRAP="VIRTUAL"></TEXTAREA>





                <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 ($atch == 1) {

                echo "<br>".getAttachCode()."<br><br>";

}

                        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=&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



                        }

                ?>



                <?



                if ($user) {

                        echo "<INPUT TYPE=\"CHECKBOX\" NAME=\"notify\" VALUE=\"1\">" ._FNOTIFY. "<BR>";

                } else {

                        echo "<INPUT TYPE=\"HIDDEN\" NAME=\"notify\" VALUE=\"0\">";

                }

                ?>

                </TD>

        </TR>

        <TR>

                <TD  BGCOLOR="<?php echo $bgcolor1?>" colspan=2 ALIGN="CENTER">

                <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
                <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; ?>">
                </FORM>
        </TR>
<?php
}
echo"</TABLE></TD></TR></TABLE>";

//<!-- Don't touch the lines below please! --> 
echo"<p align=\"center\">Splatt Forum &copy; By: <a href=\"http://www.splatt.it\" target=\"_blank\">Splatt.it</a><br>Version: $forumver</font></p><br><br>";

}
include('footer.php');
?>