File: //home/awaldron/public_html/archive/demo/thread_edit.php
<?php
session_start();
include("_functions.php");
echo dbconnect();
$admin = is_admin();
$sql = "SELECT A.*, C.notice_id, C.notice_headline, B.notice_type_id, B.parent_id, B.notice_type_name ";
$sql .= "FROM tbl_threads as A, tbl_notice_types as B, tbl_notices as C ";
$sql .= "WHERE A.thread_id=".$_GET["tid"]." ";
$sql .= "AND A.notice_id=C.notice_id ";
$sql .= "AND C.notice_type_id=B.notice_type_id";
$result = mysql_query($sql);
$n = mysql_fetch_array($result);
$page_title = "Edit Comment : ".$n["thread_headline"];
if (isset($_GET["sf"])) {
$GLOBALS["breadcrumb"] = "<a href=\"/content.php?p=1\">Intranet Home</a> > <a href=\"/content.php?p=209\">Social</a> > <a href=\"/forums.php\">Discussion Forums</a> > <a href=\"/noticeboard.php?ntid=".$n["notice_type_id"]."&sf=1\">".$n["notice_type_name"]."</a> > <a href=\"/notice.php?nid=".$n["notice_id"]."&sf=1\">".(strlen($n["notice_headline"])>37?substr($n["notice_headline"],0,37)."...":$n["notice_headline"])."</a> > Edit Comment";
$_GET["p"] = 5;
} else $_GET["p"] = $n["parent_id"]; // SET FAUX PARENT ID
$lnav_mods = get_layout($_GET["p"],1);
$rnav_mods = get_layout($_GET["p"],3);
if (!isset($_POST["post"])) $bbjava = true;
include("_pagestart.php");
echo "<P><div class=\"headline\">".$page_title."</div>\n";
if (authorize($n["username"]) || check_pgroup($_SESSION["auth_user"],$n["board_admins"])) { // CHECK IF USER ATTEMPTING THE EDIT IS THE USER WHO POSTED IT
if (isset($_POST["post"])) { // IF POST IS BEING SUBMITTED
$query = "UPDATE tbl_threads SET ";
$query .= "username='".$_POST["username"]."', ";
$query .= "thread_headline='".$_POST["thread_headline"]."', ";
$query .= "thread_body='".$_POST["message"]."', ";
$query .= "thread_updated=".time().", ";
$query .= "thread_active=".$_POST["thread_active"]." ";
$query .= "WHERE thread_id=".$_POST["thread_id"];
$result = mysql_query($query);
$latest_thread = quickSQL("SELECT latest_thread FROM tbl_notices WHERE notice_id=".$_POST["notice_id"]);
$thread_date = $_POST["thread_date"];
if ($_POST["thread_active"] == "0") {
if ($latest_thread == $thread_date) {
$new_latest_thread = quickSQL("SELECT MAX(thread_date) FROM tbl_threads WHERE notice_id=".$_POST["notice_id"]." AND thread_active=1");
//echo "New_latest_thread : ".$new_latest_thread;
if ($new_latest_thread == FALSE) {
//echo "New_latest_thread not found.";
$notice_date = quickSQL("SELECT notice_date FROM tbl_notices WHERE notice_id=".$_POST["notice_id"]);
quickUPDATE("UPDATE tbl_notices SET latest_thread='".$notice_date."' WHERE notice_id=".$_POST["notice_id"]);
} else quickUPDATE("UPDATE tbl_notices SET latest_thread='".$new_latest_thread."' WHERE notice_id=".$_POST["notice_id"]);
}
} else if ($_POST["thread_active"] == "1") {
if ($latest_thread < $thread_date)
quickUPDATE("UPDATE tbl_notices SET latest_thread='".$thread_date."' WHERE notice_id=".$_POST["notice_id"]);
}
echo "<center><br><br><br><br>";
if ($result > 0) {
echo "<b>Your changes have been submitted successfully.</b>\n";
echo "<P><a href=\"".$_POST["update_url"]."\">Back to Your Message</a><br><br><br><br>\n";
} else {
echo "<P>".$query;
echo error("There was an error while confirming your changes.");
echo error(mysql_error());
echo "<br><br><br><br>";
}
}
if (!isset($_POST["post"]) && !isset($_POST["preview"])) echo "<body onload=\"disableBody()\"></body>\n";
if (!isset($_POST["post"])) {
$preview = FALSE;
if (isset($_POST["preview"])) { // IF POST IS BEING PREVIEWED
$preview = TRUE;
echo "<br><center><div style=\"width:95%;text-align:left;\"><span style=\"font-size:14px\"><b>Preview of Your Post:</b></span><br>\n";
echo "<div style=\"background:#EEEEEE;width:100%;text-align:left;border:solid 2px #999999;padding:10px;\">\n";
if ($_POST["thread_headline"] != "0") echo "<P><span style=\"font-size:12px\"><b>".stripslashes($_POST["thread_headline"])."</b></span>\n";
if ($_POST["message"] != "0") echo "<P>".stripslashes(format_body($_POST["message"]))."\n";
echo "</div><P><div id=\"stamp\"> </div>\n";
echo "</div></center>\n";
}
echo "<center>\n";
if (!$preview) echo "<br><br><b>Use this page to update your comment with headline:<br>".$n["thread_headline"]."</b>\n";
echo "<form action=\"thread_edit.php?tid=".$_GET["tid"].(isset($_GET["sf"])?"&sf=1":"")."\" method=\"post\" name=\"post\" onSubmit=\"MM_validateForm('username','','R');return document.MM_returnValue\">\n";
echo "<input type=\"hidden\" name=\"thread_id\" value=\"".$n["thread_id"]."\">\n";
echo "<input type=\"hidden\" name=\"notice_id\" value=\"".$n["notice_id"]."\">\n";
echo "<input type=\"hidden\" name=\"thread_date\" value=\"".$n["thread_date"]."\">\n";
echo "<input type=\"hidden\" name=\"update_url\" value=\"/notice.php?nid=".$n["notice_id"].(isset($_GET["sf"])?"&sf=1":"")."\">\n";
if (!$admin) echo "<input type=\"hidden\" name=\"username\" value=\"".$n["username"]."\">\n";
echo "<P><table border=\"0\" cellpadding=\"3\" cellspacing=\"1\">\n";
echo "<tr><td><b>Delete Comment?</b></td><td><SELECT name=\"thread_active\" onMouseOver=\"helpline('del')\"><option value=\"1\" SELECTED>No</option><option value=\"0\">Yes</option></SELECT></td></tr>\n";
if ($admin) echo "<tr><td><b>Username</b></td><td><input type=\"text\" name=\"username\" size=\"45\" maxlength=\"32\" style=\"width:150px\" value=\"".$n["username"]."\"></td></tr>\n";
else echo "<tr><td><b>Username</b></td><td><input type=\"text\" name=\"dummy_username\" size=\"45\" maxlength=\"32\" style=\"width:150px\" value=\"".$_SESSION["auth_user"]."\" DISABLED></td></tr>\n";
echo "<tr><td><b>Date</b></td><td><input DISABLED type=\"text\" name=\"thread_date_fake\" style=\"width:80px\" value=\"".(!$preview?date("m/d/Y",$n["thread_date"]):date("m/d/Y",$_POST["thread_date"]))."\" onMouseOver=\"helpline('nd')\"> (mm/dd/yyyy)</td></tr>\n";
echo "<tr><td><b>Headline</b></td><td><input type=\"text\" name=\"thread_headline\" size=\"45\" maxlength=\"255\" style=\"width:550px\" value=\"".(!$preview?stripslashes($n["thread_headline"]):stripslashes($_POST["thread_headline"]))."\" onMouseOver=\"helpline('hl')\" /></td></tr>\n";
echo "<tr><td colspan=3> </td></tr>\n";
echo "<tr><td valign=\"top\" colspan=3><b>Message Body</b> : <a href=\"#\" onClick=\"openWindow('/button_buddy.php','','resizable=yes,width=650,height=425')\">Need help? Click Here to Open the Button Buddy</a></td></tr>\n";
echo "<tr><td colspan=3 class=\"row2\" valign=\"top\" bgcolor=\"#EBEFF5\" style=\"border:solid 1px #999999;\">\n";
echo ins_textarea((!$preview?$n["thread_body"]:stripslashes($_POST["message"])));
// Preview & Submit Buttons
echo "<P><center><input type=\"submit\" name=\"preview\" value=\" Preview \"> <input type=\"submit\" name=\"post\" value=\" Submit \" /></center>\n";
echo "</td></tr></table>\n";
echo "</form>\n";
echo "</center>\n";
}
} else { // ELSE IF USER DOES NOT HAVE PERMISSION TO EDIT THREAD MESSAGE
echo "<br><br><br>".error("You do not have the proper privileges to edit this message.")."<br><br><br>";
echo "<center><a href=\"/notice.php?nid=".$n["notice_id"]."\">Back To The Notice</a></center><br><br><br>";
}
include("_pageend.php");
?>