<?php
include ("config.inc");
include ("forum.inc");
# -------------------
# Get the form input
$FORM = get_input();
# --------------------
# Assign the variables
$Subject = $FORM[Subject];
$Body = $FORM[Body];
$Board = $FORM[Board];
$page = $FORM[page];
$view = $FORM[view];
$what = $FORM[what];
$Number = $FORM[Number];
$mode = $FORM[mode];
$oldnumber = $Number;
$sb = $FORM[sb];
$option = $FORM[option];
$Body = url_decode($Body);
$Subject = url_decode($Subject);
# --------------------------------
# Check that this is a valid table
$Board = valid_table($Board);
$Number = number_check($Number);
# -----------------------
# Connect to the database
$dbh = db_connect();
# --------------------
# Authenticate the user
$cookie = get_cookie();
$Username = $cookie[Username];
$Password = $cookie[Password];
$user = authenticate($Username,$Password);
if (empty($user[Username]) ) {
not_right ("We could not authenticate your Username/Passord.");
}
# --------------------------------------------------
# If we are deleting this post, then we execute this
if ($option == "Delete this post") {
# --------------------
# Send them their page
send_header("Delete this post");
table_header("Delete this post");
print <<<END_HTML
You have chosen to delete this post. If you are sure you want to do this
click the button below , otherwise use your back button to return to the last sc
reen.
<p>
<form method=POST action="$config[cgiurl]/deletepost.php">
<input type=hidden name=Username value="$Username">
<input type=hidden name=Board value="$Board">
<input type=hidden name=what value="$what">
<input type=hidden name=page value="$page">
<input type=hidden name=view value="$view">
<input type=hidden name=Number value="$Number">
<input type=hidden name=mode value="$mode">
<input type=hidden name=sb value="$sb">
<p>
<input type=submit value="Yes, I want to delete this post">
</form>
END_HTML;
# ---------------
# Send the footer
send_footer();
exit();
}
# --------------------------
# Grab the board information
$Board_q = db_quote($Board);
$query = <<<END_SQL
SELECT HTML,Markup
FROM Boards
WHERE Keyword = $Board_q
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($HTML,$Markup) = mysql_fetch_array($sth);
# ---------------------------------
# Get rid of < and > in the subject
$Subject = preg_replace ( "/</", "<", $Subject);
$Subject = preg_replace ( "/>/", ">", $Subject);
# -------------------------------------------------------------
# If HTML is off then we need to get rid of < and > in the body
if ($HTML == "Off") {
$Body = preg_replace ( "/</", "<", $Body);
$Body = preg_replace ( "/</", "<", $Body);
$Body = preg_replace ( "/<br>/", "<br>", $Body);
}
# -----------------------------------------------------
# Let's find out if they get the default preview or not.
$Preview = $user[Preview];
if (empty($Preview)) { $Preview = $config[Preview];}
# -------------------------------------------
# If Markup is on the we format the markup code
if ($Markup == "On") {
$Body = preg_replace ( "/\[b\]/", "<b>", $Body);
$Body = preg_replace ( "/\[\/b\]/", "</b>", $Body);
$Body = preg_replace ( "/\[i\]/", "<i>", $Body);
$Body = preg_replace ( "/\[\/b\]/", "</i>", $Body);
# -----------------------
# Convert the color codes
$Body = preg_replace ( "/\[red\]/", "<font color=red>", $Body);
$Body = preg_replace ( "/\[\/red\]/", "</font>", $Body);
$Body = preg_replace ( "/\[green\]/", "<font color=green>", $Body);
$Body = preg_replace ( "/\[\/green\]/", "</font>", $Body);
$Body = preg_replace ( "/\[blue\]/", "<font color=blue>", $Body);
$Body = preg_replace ( "/\[\/blue\]/", "</font>", $Body);
$Body = preg_replace ( "/\[orange\]/", "<font color=orange>", $Body);
$Body = preg_replace ( "/\[\/orange\]/", "</font>", $Body);
$Body = preg_replace ( "/\[purple\]/", "<font color=purple>", $Body);
$Body = preg_replace ( "/\[\/purple\]/", "</font>", $Body);
$Body = preg_replace ( "/\[white\]/", "<font color=white>", $Body);
$Body = preg_replace ( "/\[\/white\]/", "</font>", $Body);
$Body = preg_replace ( "/\[black\]/", "<font color=black>", $Body);
$Body = preg_replace ( "/\[\/black\]/", "</font>", $Body);
$Body = preg_replace ( "/\[yellow\]/", "<font color=yellow>", $Body);
$Body = preg_replace ( "/\[\/yellow\]/", "</font>", $Body);
# --------------------
# Convert the smiley's
$Body = preg_replace (",\[smile\],", "<img src=\"$config[images]/smile.gif\">", $Body);
$Body = preg_replace (",\[frown\],", "<img src=\"$config[images]/frown.gif\">", $Body);
$Body = preg_replace (",\[wink\],", "<img src=\"$config[images]/wink.gif\">", $Body);
# ----------------------------
# Replace quote markup -> html
$Body = preg_replace (",\[quote\](.*)\[/quote\],", "<blockquote><font size=1>In reply to:</font><hr><p>\\1<p><hr></blockquote><p>", $Body);
# ---------------------------
# Convert code markup -> html
$Body = preg_replace(",\[pre\](.*)\[/pre\],", "<pre>\\1</pre><p>", $Body);
# ---------------------------
# Convert url markup -> html
$Body = preg_replace(",\[url\]http://(.*)\[/url\],", "<A HREF=\"http://\\1\">http://\\1</A>", $Body);
$Body = preg_replace(",\[url\](.*)\[/url\],", "<A HREF=\"http://\\1\">http://\\1</A>", $Body);
# ----------------------------
# Convert email markup -> html
$Body = preg_replace(",\[email\](.*)\[/email\],", "<A HREF=\"mailto:\\1\">\\1</A>", $Body);
# -------------------------------------------------
# Convert image markup -> html if allowimages is on
if ($config[allowimages]) {
$Body = preg_replace (",\[image\](.*)\[/image\],", "<IMG SRC=\"\\1\">", $Body);
}
# ---------------------------------------------
# Get rid of the trailing br's on certain codes
$Body = preg_replace ("/<\/blockquote><p><br>/", "<\/blockquote><p>", $Body);
$Body = preg_replace ("/<\/pre><p><br>/", "<\/pre><p>", $Body);
$Body = preg_replace ("/<pre><br>/", "<pre>", $Body);
}
# -------------------
# Update the database
$Username_q = db_quote($user[Username]);
$Subject_q = db_quote($Subject);
$Body_q = db_quote($Body);
$query = <<<END_SQL
UPDATE $Board
SET Subject = $Subject_q, Body = $Body_q
WHERE Number = $Number
END_SQL;
mysql_query($query) or die ("Can't execute query: $query. Reason: " . mysql_error() . ".");
# ----------------------------------------------
# Make sure they get refeshed to the proper page
if($what == "showpost") {
send_header("The post has been modified","<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;url=$config[cgiurl]/showpost.php?Board=$Board&Number=$oldnumber&page=$page&view=$view&mode=$mode&sb=$sb\">");
} else {
send_header("The post has been modified","<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;url=$config[cgiurl]/index.php?action=list&Board=$Board&page=$page&view=$view&sb=$sb\">");
}
table_header("Your post has been entered");
print "The post has been modified. You will now be returned to the forum.";
# ---------------
# Send the footer
send_footer();
?>