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']);}
$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;
}
$pagetitle=$TopicName;
SetRead($TopicID);
fHeader();
$TopicInfo = GrabTopicInfo($TopicID);
if (!CheckViewAccess($BoardID))
LogInFirst($txt['CantRead']);
$d_BoardModerator = d_mod_is($BoardID);
//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 = ""."";
$MessageOptions.= " "."";
if ($TopicStatus == 0)
$MessageOptions .= " "."";
if ($TopicInfo["IsPoll"])
$ent["PollResults"] = GrabPollBox($TopicID);
$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);
if (in_array($CurrentUserInfo["UserName"], $d_BoardModerator))
$ent["ModFunctions"] = "Moderator Functions: $txt[LockTopic] | $txt[MoveTopic] | $txt[TopTopic]";
$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"]);
$PosterInfo = "$UserInfo[UserName]";
$PosterInfo .= "";
$PosterInfo .= "
$txt[UserLevel]: $UserInfo[UserLevel]";
if ($UserInfo["Icon"]) {$PosterInfo .= "
";}
if ($UserInfo["Avatar"]) {$PosterInfo .= "
";}
if ($UserInfo["RegDate"]) {$PosterInfo .= "
$txt[Registered]: ".FormatDate($UserInfo[RegDate],$CurrentUserInfo[timezone]);}
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 .= " ";
$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"],$CurrentUserInfo[timezone]);
$ent["TimePosted"] = FormatTime($msgInfo["DatePosted"],$CurrentUserInfo[timezone]);
if (($CurrentUserInfo["UserName"] == $UserInfo["UserName"]) || in_array($CurrentUserInfo["UserName"], $d_BoardModerator))
$ent["MsgOptions"] = "$txt[Edit]";
if ($msgInfo["Locked"] == 0)
$ent["MsgOptions"] .= " | $txt[QuoteReply]";
if (($UserInfo["Signature"]) && ($msgInfo["AddSig"])){$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();
?>