<?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
#
#
######################################################################
# 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";

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


$sql = "SELECT forum_name, forum_access, forum_moderator, forum_atch FROM ${prefix}_forums WHERE forum_id = '$forum'";
if(!$result = mysql_query($sql, $db))
        die(""._ERRORE1.":<hr>"._FCOULDNOT.".");
$myrow = mysql_fetch_array($result);
$forum_name = $myrow[forum_name];
$moderator = $myrow[forum_moderator];
$moderators = get_moderators($forum, $db);
$atch = $myrow[forum_atch];

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

$use_forum_password_fix = 1;

if($submit1) {
   //include('header.php');
   $sql = "SELECT poster_id FROM ${prefix}_posts WHERE (post_id = $post_id)";

   $result = mysql_query($sql, $db);
   if (!$result) {
      die("<br>"._ERRORE1.":<ul>"._ERRQUERY.".</ul><P>");
   }
   $row = mysql_fetch_array($result);

   $posterdata = get_userdata_from_id($row[poster_id], $db);
   $date = date("d-m-Y H:i");
   if ($user) {
//	include('header.php');
               $cookie = base64_decode($user);
               $cookie = explode(":", $cookie);
  			$userdata = get_userdata($cookie[1], $db);

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

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

      // valid session.. just check it's the right user.
      if (($posterdata[uid] != $userdata[uid] && $userdata[user_level] == 1)) {
         $die = 1;
      }
      // else if($userdata[level] == 2 && $userdata[uid] != get_forum_mod($forum_id, $db)) {
      else if($userdata[user_level] == 2 && $userdata[uid] != $mod) {
         die("<br>"._FERRORE.":<ul>"._FNONTUO.".</ul><P>");
      }
   } else {
               die("<br>"._FERRORE.":<ul>"._NOPERMESS.".</ul><P>");
   }

   // IF we made it this far we are allowed to edit this message!

   $Message = $message;
   $message = check_words($Message);
   $message = eregi_replace("-----------------", "", $message);
   $message = str_replace("\n", "<BR>", $message);
   if ($user_sig)
   $message = str_replace(nl2br($user_sig), "[addsig]", $message);

   if($allow_html == 0 || isset($html) )
     $message = htmlspecialchars($message);
   if($allow_bbcode == 1 && !isset($bbcode))
     $message = bbencode($message);
   if(!$smile)
     $message = smile($message);

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

   $message .= "<BR><BR><font size=1>[ "._MODBY.": $userdata[uname] "._FIL." $date ]</font>";
//$message = strip_tags($message);
   $message = addslashes($message);
        if(!$delete) {
                $topic = $topic_id;
                $forum = $forum_id;
                $sql = "UPDATE ${prefix}_posts SET post_text = '$message', image='$image_subject' WHERE (post_id = '$post_id')";

				ConfirmAttach($post_id);
                include('header.php');

                if(!$result = mysql_query($sql, $db))
                        die("<br>"._ERRORE1.":<ul>"._CHECKCONF.".</ul><br>");



                echo "<center>"._PUPD."<br><a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$topic_id&forum=$forum_id\">"._CLIKVUPD.".<br><a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum_id\">"._CLIKRETL.".</center><P></font>";
        }
        else {
                $sql = "DELETE FROM ${prefix}_posts WHERE post_id = '$post_id'";

delAllAtchFile($post_id);
                include('header.php');

                if(!$r = mysql_query($sql))
                        die("<br>"._ERRORE1.":<ul>"._CHECKCONF.".</ul><P>");
                if(get_total_posts($topic_id, $db, "topic") == 0) {
                        $sql = "DELETE FROM ${prefix}_forumtopics WHERE topic_id = '$topic_id'";
                        if(!$r = mysql_query($sql, $db))
                                die("<br>"._ERRORE1.":<ul>"._CHECKCONF.".</ul><P>");
                }
                echo "<center>"._POSTCANC."<br><a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$forum_id\">"._CLIKRETL.".<br><a href=\"modules.php?op=modload&name=".$module_name."&file=index\">"._CLIKRET.".</center><P></font>";
        }
}
else {
if (!isset($AtchOp)){
      resetAtchCookie();
   }
   include('header.php');
   $sql = "SELECT p.*, u.uname, u.uid, u.user_sig FROM ${prefix}_posts p, ".$prefix."_users u WHERE (p.post_id = '$post_id') AND (p.poster_id = u.uid)";
   if(!$result = mysql_query($sql, $db))
     die("<br>"._ERRORE1.":<ul>"._CHECKCONF.".</ul><P>");
   $myrow = mysql_fetch_array($result);
   if (isset($user)) {
                  $cookie = base64_decode($user);
               $cookie = explode(":", $cookie);
               $userdata = get_userdata($cookie[1], $db);

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

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


       if ($userdata[uid] != $myrow[uid] && $userdata[uid] != $mod)
           die("<br>"._FERRORE.":<ul>"._FNONTUO.".</ul><P>");
   }


if (!isset($message)){
   $message = $myrow[post_text];
   $message = eregi_replace("\[addsig]", "\n-----------------\n" .    $myrow[user_sig], $message);
   $message = str_replace("<BR>", "\n", $message);
   $message = stripslashes($message);
   $message = desmile($message);
   $message = bbdecode($message);
   $message = undo_htmlspecialchars($message);
} else {
   $message = stripslashes($message);
}
   list($day, $time) = split(" ", $myrow[post_time]);
addForumScripts();
?>
<FORM ACTION="modules.php?op=modload&name=<?php echo $module_name ?>&file=editpost" METHOD="POST" name="coolsus">
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="95%"><TR><TD  BGCOLOR="<?php echo $table_bgcolor?>">
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="1" WIDTH="100%">
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
        <TD ALIGN="CENTER" COLSPAN="2"><FONT COLOR="<?php echo $textcolor1; ?>"><B><?php echo _MODPOST;?></B></FONT></TD>
</TR>

<?PHP
        if (isset($user)) {
                if ($use_forum_password_fix == 1) {
                        $password = $userdata[pass];
                } else {
                        // if (!$system) $password = base64_decode($userdata[pass]);


                        // KingRichard Fix
                        if (!$system) $password = crypt($userdata[pass],substr($userdata[pass],0,2));
                        else $password = $userdata[pass];
                }
                if ($password == $cookie[2]) {
                echo "<TR>";
                echo "<TD  BGCOLOR=$bgcolor3  width=25%><b>"._FNICK."<b></TD>";
                echo "<TD  BGCOLOR=$bgcolor1>";
                echo $userdata[uname] . " \n";
                echo "</TD></TR> \n";
                }
                else {
                die("<br>"._ERRORE1.":<ul>"._FERRPASS."</ul><P>");
                }
        }
        else {
                die("<br>"._ERRORE1.":<ul>"._NOPERMESS."</ul><P>");
        }


?>
<TR ALIGN="LEFT">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25% VALIGN="TOP"><b><?php echo _MESSICON;?></b></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>">
        <?php
                $handle=opendir("./images/forum/subject");
if (!isset($topic)){
                    $topic=$topic_id;
                }
                if (!isset($image_subject)){
                     $image_subject = $myrow[image];
                }
                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 {
                        if ($file == $image_subject) echo "<input type=\"radio\" value=\"$file\" name=\"image_subject\" checked>&nbsp;";
                        else echo "<input type=\"radio\" value=\"$file\" name=\"image_subject\">&nbsp;";
                        echo "<IMG SRC=\"images/forum/subject/$file\" BORDER=0>&nbsp;";
                        }
                if ($count == "9") { echo "<br>"; $count = 1; }
                $count++;
                }
        ?>
                 </TD>
        </TR>
        <TR ALIGN="LEFT" VALIGN="TOP">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25%><b><?php echo _FMESS;?>:</b><br><br>
                <font size=-1>
                <?php
                echo "HTML : ";
                if($allow_html == 1)
                        echo "On<BR>\n";
                else
                        echo "Off<BR>\n";
                echo "<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";
                ?>
                </font></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>"><TEXTAREA CLASS=textbox NAME="message" ROWS=10 COLS=65 WRAP="VIRTUAL"><?php echo $message ?></TEXTAREA><br>

<?php
	if ($atch == 1){
                // JoyDivision Start
                echo ShowAttach($myrow[post_id],true,"coolsus");
                echo "<br>".getAttachCode($myrow[post_id])."<br>";
                // JoyDivision End
}
?>              <br>

<?php

 putitems();
?>

</TD>
        </TR>
        <TR ALIGN="LEFT">
                <TD  BGCOLOR="<?php echo $bgcolor3?>" width=25%><b><?php echo _FOPT;?></b></TD>
                <TD  BGCOLOR="<?php echo $bgcolor1?>" >
                <?php
                        $now_hour = date("H");
                        $now_min = date("i");
                        list($hour, $min) = split(":", $time);
                       // if(($now_hour == $hour && $min_now - 30 < $min) || ($now_hour == $hour +1 && $now_min - 30 > 0) ) {
                ?>
                                <INPUT TYPE="CHECKBOX" NAME="delete"><?php echo _FDELP;?><BR>
                <?php
                     //   }
                
                        if($allow_html == 1) {
                ?>
                                <INPUT TYPE="CHECKBOX" NAME="html"><?php echo _DISHTML;?><BR>
                <?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>".$module_name." "._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>
                </TD>
        </TR>
<TR>
        <TD  BGCOLOR="<?php echo $bgcolor1?>" colspan=2 ALIGN="CENTER">
        <INPUT TYPE="HIDDEN" NAME="post_id" VALUE="<?php echo $post_id?>">
        <INPUT TYPE="HIDDEN" NAME="forum_id" VALUE="<?php echo $forum?>">
        <INPUT TYPE="HIDDEN" NAME="forum" VALUE="<?php echo $forum?>">
        <INPUT TYPE="HIDDEN" NAME="topic_id" VALUE="<?php echo $topic?>">
        
        <INPUT TYPE="SUBMIT" NAME="submit1" VALUE="<?php echo _INVIA;?>">&nbsp;<INPUT TYPE="RESET" VALUE="<?php echo""._RESETTA."" ?>" NAME="clear">
</TR>
</TABLE></TD></TR></TABLE>
</FORM>
<!-- 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');
?>