include("functions.php");
include("forum_template.php");
mysql_connect($db_Hostname, $db_UserName, $db_Password) || die("Can't Connect to Database: ".mysql_error());
mysql_select_db($db_Database);
$fSettings = GetSettings();
if (empty($TopicID) || ($TopicID == 0))
{fHeader();UhOh($txt['errNoTopicID']);}
SetRead($TopicID);
fHeader();
//New Post Icon Grabber --Derrick Hopkins 5-10
$d_Icons = d_GetPostIcons();
$query = "SELECT BoardID,Subject,Locked,numViews from t_messages WHERE TopicID = $TopicID Order By DatePosted ASC LIMIT 1";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result))
{
$TopicName = stripslashes($row["Subject"]); $BoardID = $row["BoardID"]; $TopicStatus = $row["Locked"];
$numViews = $row["numViews"] + 1;
}
$d_BoardModerator = d_mod_is($BoardID);
if (!CheckViewAccess($BoardID))
UhOh($txt['CantRead']);
//DO PAGE SPAN
$messagesperpage = $fSettings['messagesperpage'];
$query = "SELECT numReplies from t_messages where TopicID = $TopicID LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
$totalmessage = $row[0]+1;
$pages = DoPageSpan($messagesperpage,$totalmessage,"viewtopic.php?TopicID=$TopicID");
$CurrentUserPass = GrabUserPass();
$CurrentUserInfo = GrabUserInfo($CurrentUserPass[UserName]);
$query = "UPDATE t_messages SET numViews='$numViews' WHERE TopicID = $TopicID";
$result = mysql_query($query);
$query = "SELECT bName from t_boards WHERE ID = $BoardID";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result))
$BoardName = $row["bName"];
$CurrentLocation = "".$fSettings["ForumName"]." : ".$BoardName." : $TopicName";
if ($TopicStatus == 1)
$CurrentLocation .= " ";
$MessageOptions = ""."";
if ($TopicStatus == 0)
$MessageOptions .= " "."";
$ent["fTitleBGColor"] = $fSettings["title_backcolor"];
$ent["fTitleTColor"] = $fSettings["title_textcolor"];
$ent["fCatBGColor"] = $fSettings["cat_backcolor"];
$ent["fCatTColor"] = $fSettings["cat_textcolor"];
$ent["fMsgBGColor1"] = $fSettings["msg_backcolor"];
$ent["fMsgBGColor2"] = $fSettings["msg_backcolor2"];
$ent["fBorderColor"] = $fSettings["bordercolor"];
$ent["AnnouncementMSG"] = GrabAnnouncement($BoardID);
$ent["NavPath"] = $CurrentLocation;
$ent["NewandReply"] = $MessageOptions;
$ent["PageSpan"] = $pages;
$ent["LoginBox"] = GrabLoginBox("$fSettings[ScriptURL]/viewtopic.php?TopicID=$TopicID");
$ent["Moderator"] = GrabModerators($BoardID);
$CurrentUserPass = GrabUserPass();
// Killing the extra is_mod call --Derrick Hopkins 5-8
if (is_mod($CurrentUserPass[UserName],$CurrentUserPass[Password],$BoardID))
$ent["ModFunctions"] = "Moderator Functions: $txt[LockTopic] | $txt[MoveTopic]";
$template = ReadTemplate("viewtopic");
$pos_start = strpos($template,"")+strlen("");
$pos_end = strpos($template,"",$pos_start);
$first_part = substr($template,0,$pos_start-strlen(""));
$last_part = substr($template,$pos_end,strlen($template)-$pos_end);
print ParseTemp($first_part,$ent);
$first_loop = substr($template,$pos_start,$pos_end-$pos_start);
$table = "";
$limit = $page*$messagesperpage;
$query = "select * from t_messages where TopicID = $TopicID Order By DatePosted ASC LIMIT $limit,$messagesperpage";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result))
{
$i=0;
do
{
$msgInfo = $row;
$ent["MsgOptions"] = "";
if ($i%2)
$ent["fMsgBGColorAlt"] = $fSettings["msg_backcolor2"];
else
$ent["fMsgBGColorAlt"] = $fSettings["msg_backcolor"];
$UserInfo = GrabUserInfo($msgInfo["Poster"]);
//$msgIcon = GrabPostIcon($msgInfo["ID"]);
//New PostIcon Grabber Code --Derrick Hopkins 5-10
$msgIcon = $d_Icons[$msgInfo["PostIcon"]];
$PosterInfo = "$UserInfo[UserName]";
$PosterInfo .= "";
$PosterInfo .= "
$txt[UserLevel]: $UserInfo[UserLevel]";
if ($UserInfo["Icon"]) {$PosterInfo .= "
";}
if ($UserInfo["RegDate"]) {$PosterInfo .= "
$txt[Registered]: ".FormatDate($UserInfo[RegDate]);}
if ($UserInfo["NumPost"]) {$PosterInfo .= "
$txt[Posts]: $UserInfo[NumPost]";}
$PosterInfo .= "
IP: ";
if ($CurrentUserInfo["LevelID"] <= 2) {$PosterInfo .= $msgInfo["PosterIP"];} else {$PosterInfo .= "Logged";}
$PosterInfo .= "
";
if ($UserInfo["UserLevel"] != "Guest")
{
$PosterInfo .= "";
$PosterInfo .= " ";
}
if ($UserInfo["Homepage"])
{$PosterInfo .= " ";}
if ($UserInfo["ICQNumber"]) {$PosterInfo .= " ";}
$ent["PosterInfo"] = $PosterInfo;
$ent["MsgID"] = $msgInfo["ID"];
$ent["MsgIcon"] = "";
$ent["Subject"] = SensorWord(stripslashes($msgInfo["Subject"]));
$ent["DatePosted"] = FormatDate($msgInfo["DatePosted"]);
$ent["TimePosted"] = FormatTime($msgInfo["DatePosted"]);
if (($CurrentUserInfo["UserName"] == $UserInfo["UserName"]) || (is_mod($CurrentUserPass[UserName],$CurrentUserPass[Password],$BoardID)))
$ent["MsgOptions"] = "$txt[Edit]";
if ($msgInfo["Locked"] == 0)
$ent["MsgOptions"] .= " | $txt[QuoteReply]";
if ($UserInfo["Signature"]) {$ent["Message"] = ParseMSG($msgInfo["Message"]."\n\n____________________________\n".$UserInfo["Signature"],$msgInfo["Emoticon"]);}
else {$ent["Message"] = ParseMSG($msgInfo["Message"],$msgInfo["Emoticon"]);}
print ParseTemp($first_loop,$ent);
$i++;
} while ($row = mysql_fetch_array($result));
}
print ParseTemp($last_part,$ent);
PrintForumRules($BoardID);
fFooter();
?>