<?php

if ($action == "set")
{
    include ("inc/inc_common.php");
    include ("inc/inc_connect.php");
    $reply = $tsttxt;
    if ($softedit == "1")
    {
        include ("inc/inc_getdate.php");
        //set this post to be soft hidden...
        $query = "UPDATE $forumtable SET intEdited = '1', strEditor = '$gfcookie[1]' WHERE intId = $postid";
        mysql_query( $query, $link ) or die ( "Could4 not update in \"$forumtable\" table: ".mysql_error() );

        //copy it to a new location...
        $result=mysql_query("SELECT * FROM $forumtable WHERE intId = $postid LIMIT 0,1");
        $num_rows = mysql_num_rows( $result );
        while ( $a_row = mysql_fetch_object( $result ) )
        {
            $query = "INSERT INTO $forumtable ( strName, strTopicName, memPost, strGalleryThumb, strGalleryImage, strForumComment, ynTopicRow, ynGalleryRow, strDate, intTopicId, intPostId, strTime, strAvatar, memSig, strEmail, intPosts, strHomepage, strIp, ynShowEmail, strIcqNumber, strMsnName, strYahooId, strLocation, intLastPost, intReplies, intViews, strSmilieUrl, strLastPostName, strLastPostTime, strLastPostDate, strEpochTime, ynLocked, strLockedBy, ynPriority, intForumId, intForumGroup, intVoteId, strEdit, intHbhForum, intOpenForum, intPostHidden, strHider, intEdited, strEditor, intNewId, intFromEdit, intEditId, intRateTopic, intRating, strRateThis, strEditDate, strEditTime ) VALUES ( '$a_row->strName', '$a_row->strTopicName', '$reply', '$a_row->strGalleryThumb', '$a_row->strGalleryImage', '$a_row->strForumComment', '$a_row->ynTopicRow', '$a_row->ynGalleryRow', '$a_row->strDate', '$a_row->intTopicId', '$a_row->intPostId', '$a_row->strTime', '$a_row->strAvatar', '$a_row->memSig', '$a_row->strEmail', '$a_row->intPosts', '$a_row->strHomepage', '$a_row->strIp', '$a_row->ynShowEmail', '$a_row->strIcqNumber', '$a_row->strMsnName', '$a_row->strYahooId', '$a_row->strLocation', '$a_row->intLastPost', '$a_row->intReplies', '$a_row->intViews', '$a_row->strSmilieUrl', '$a_row->strLastPostName', '$a_row->strLastPostTime', '$a_row->strLastPostDate', '$a_row->strEpochTime', '$a_row->ynLocked', '$a_row->strLockedBy', '$a_row->ynPriority', '$a_row->intForumId', '$a_row->intForumGroup', '$a_row->intVoteId', '$a_row->strEdit', '$a_row->intHbhForum', '$a_row->intOpenForum', '$a_row->intPostHidden', '$a_row->strHider', '0', '$a_row->strEditor', '$a_row->intNewId', '$postid', '$a_row->intEditId', '$a_row->intRateTopic', '$a_row->intRating', '$a_row->strRateThis', '$date', '$ftime')";
            mysql_query( $query, $link ) or die ( "Error1! : ".mysql_error() );
        }

        //find out the new locations number and insert it into the original
        $result=mysql_query("SELECT * FROM $forumtable WHERE intFromEdit = $postid ORDER BY intId DESC LIMIT 0,1");
        $num_rows = mysql_num_rows( $result );
        while ( $a_row = mysql_fetch_object( $result ) )
        {
            $query = "UPDATE $forumtable SET intNewId = '$a_row->intId' WHERE intId = '$postid'";
            mysql_query( $query, $link ) or die ( "Error2! : ".mysql_error() );
        }
        //done!
        header("Location: topic.php?groupid=$groupid&topicid=$topicid#post$postid");
        exit;
    }
    else
    {
        $query = "UPDATE $forumtable SET memPost = '$reply' WHERE intId = '$postid'";
        mysql_query( $query, $link ) or die ( "Could3 not update in \"$forumtable\" table: ".mysql_error() );

        header("Location: topic.php?groupid=$groupid&topicid=$topicid#post$postid");
        exit;
    }
}

$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
/*
if ($cAdminLevel < 2 AND $gfcookie[1] != "$name")
{
    //kick out non-moderators...
    header("Location: topics.php?groupid=$groupid");
    exit;
}
*/
include ("inc/inc_forumname.php");
$page = "Edit Post";
$pagelink = $file."?postid=$postid";
include("inc/inc_setonline.php");
$title = "Edit Post";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
include ("inc/inc_title.php");
print "</centeR><table border=0 width=\"100%\" cellpadding=1 cellspacing=0><tr><td  width=\"20%\">
<table border=0 cellpadding=1 cellspacing=0><tr><td>
<font face=\"$font\" size=$fontsize><image src=\"images/folder_icon.gif\">&nbsp;<a href=\"index.php\">$name1&nbsp;Home</a>
</td></tr>
<tr><td><image src=\"images/folder_line.gif\">
<font face=\"$font\" size=$fontsize><image src=\"images/folder_icon.gif\">&nbsp;<a href=\"forums.php\">$name2</a></td></tr>
<tr><td><font face=\"$font\" size=$fontsize>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src=\"images/folder_line.gif\">
<image src=\"images/folder_icon.gif\">&nbsp;<a href=\"topics.php?groupid=$groupid\">$name3</a></td></tr>
<tr><td><font face=\"$font\" size=$fontsize>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src=\"images/folder_line.gif\">
<image src=\"images/open_folder_icon.gif\">&nbsp;Edit Post</td></tr>
</table>
</td><td><center>";

include ("inc/inc_navigation.php");
include ("inc/inc_newmailsdisplay.php");
print "</td></tr></table><br><center>";
$opostid = $postid;
//end of include files.
$edited = 1;
while ($edited == 1)
{
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intId = '$postid' LIMIT 0,1" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        if ($a_row->intEdited == 1)
        {
            $postidb = $a_row->intNewId;
            break;
        }
        else
        {
            $edited = 0;
        }
    }
    if ($edited == 0)
    {
        break;
    }
    $postid = $postidb;
}

$result = mysql_query( "SELECT * FROM $forumtable WHERE intId = $postid" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
        $thistitle = $a_row->strTopicName;
        $thisid = $a_row->intTopicId;
        $locked = $a_row->ynLocked;
        $locker = $a_row->strLockedBy;
        $post = $a_row->memPost;
}

print "<center>
<br><br><br><br>";

if ($locked == "Yes")
{
    print "<br><font face=$font size=$fontsizeb color=\"$fontcolor\">This thread has been locked by $locker. You cannot edit your post.<br><br>";
    print "<br><br>";
    exit;
}

$post = str_replace("[swear]", "", $post);
$post = str_replace("[/swear]", "", $post);

print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"60%\" bgcolor=\"$fgcolour\">
<tr>
<td width=\"100%\">
<p align=\"center\"><br><b><font face=\"$font\">Edit Post</font></b></p>
<form method=\"POST\" action=\"editpost.php\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
<tr>
<td width=\"40%\">";
include("inc_smilies.php");
?>

<td width="40%">
<script language=javascript>
<!--

function markSelection ( txtObj ) {
 if ( txtObj.createTextRange ) {
   txtObj.caretPos = document.selection.createRange().duplicate();
   isSelected = true;
 }
}

function insertTag ( txtName, tag, enclose ) {
 var closeTag = tag;
 if ( enclose ) {
   var attribSplit = tag.indexOf (   );
   if ( tag.indexOf (   ) > -1 )
     closeTag = tag.substring ( 0, attribSplit );
 }
 if ( isSelected ) {
   var txtObj = eval ( "document.forms[0]." + txtName );
   if (txtObj.createTextRange && txtObj.caretPos) {
     var caretPos = txtObj.caretPos;
     caretPos.text = ( ( enclose ) ? "["+tag+"]"+caretPos.text+"[/"+closeTag+"]" : ""+tag+""+caretPos.text );
     markSelection ( txtObj );
     if ( txtObj.caretPos.text== ) {
       isSelected=false;
    txtObj.focus();
     }
   }
 } else {
   // placeholder for loss of focus handler
 }
}

//-->
</script>

<form>

<textarea onfocus="document.onkeypress=function(){};" rows="11" cols="36" style="background-image: url(images/big_area_background.gif)" name="tsttxt" ONSELECT="markSelection(this);" ONCLICK="markSelection(this);" ONKEYUP="markSelection(this);"><?php print "$post"; ?></textarea>
<?php
print "<input type=\"hidden\" name=\"postid\" value=\"$opostid\">";
print "<input type=\"hidden\" name=\"topicid\" value=\"$topicid\">";
print "<input type=\"hidden\" name=\"groupid\" value=\"$groupid\">";
print "<input type=\"hidden\" name=\"action\" value=\"set\">";
include ("inc_buttons.php");
print "</td><td width=\"20%\">&nbsp;</td></tr></table>
<p align=\"center\"><input type=\"submit\" value=\"Update!\"></p>
</form></td></tr></table>";

include("inc/inc_footer.php");
?>