<?php
include ("config.inc");
include ("forum.inc");
# -----------------
# Get the form input
$FORM = get_input();
# --------------------
# Assign the variables
$Board = $FORM[Board];
$Number = $FORM[Number];
$page = $FORM[page];
$view = $FORM[view];
$mode = $FORM[mode];
$sb = $FORM[sb];
$search = $FORM[Search];
$original = '';
$count = '';
# ---------------------------------------------------
# Grab the cookie to mark the posts as read or unread
$cookie = get_cookie();
$b_id = "$Board.temp";
$unread = $cookie[b_id];
# -----------------------
# Connect to the database
$dbh = db_connect();
# ---------------
# Grab their prefs
$Username = $cookie[Username];
$Password = $cookie[Password];
$user = authenticate($Username,$Password);
# -----------------------------------------
# If mode is not set, then mode = $postlist
if ( (!$mode) && ($user[Display]) ) {
$mode = $user[Display];
} elseif ( (!$mode) && (!$user[Display]) ) {
$mode = $config[postlist];
}
$Board_q = db_quote($Board);
# ------------------------------------------------------
# Let's find out what Security level we are dealing with
$user_security = $user[Security];
if (empty($user_security)) { $user_security = $config[anon_security];}
# ----------------------------------------------------
# Check if this board is locked and grab the Moderator
$query = <<<END_SQL
SELECT Locked,Moderator,Security
FROM Boards
WHERE Keyword = $Board_q
END_SQL;
$sth = mysql_query($query) or die ("Query Syntax Error: " . mysql_error() . ". Query: $query");
list($locked,$moderator,$security) = mysql_fetch_array($sth);
mysql_free_result($sth);
# ------------------------------------------------------------------
# If this board has a higher security level, then they cannot see it
if ($user_security < $security) {
not_right("You do not have a high enough security level to view this board.");
}
# -----------------------------------------------------------------------------
# Once and a while it people try to just put a number into the url, lets trap it
if (!$Number) {
not_right("There was a problem looking up the Post in our database. Please try again.");
}
# ------------------------------------------
# Grab the main post number for this thread
$query = <<<END_SQL
SELECT Main,Last_Post
FROM $Board
WHERE Number=$Number
END_SQL;
$sth = mysql_query ($query) or die ("Query Syntax Error: " . mysql_error() . ". Query: $query");
list($current,$posted) = mysql_fetch_array($sth);
mysql_free_result($sth);
# --------------------------------------------------------------------------
# Give them a cookie marking this message as read appending it to the others
$bname = $Board . "_read";
$read = $cookie[$bname];
$check = ",$Number,";
if( (!(ereg("$check", $read))) && ($posted > $unread) ) {
$read = $read . ",$Number,";
set_cookie($bname,"$read",0);
}
# ---------------------------------------------
# Check if there are any replies in this thread
$query = <<<END_SQL
SELECT Number
FROM $Board
WHERE Main=$current
END_SQL;
$sth = mysql_query ($query) or die ("Query Syntax Error: " . mysql_error() . ". Query: $query");
$checkreplies = mysql_num_rows($sth);
# ---------------------------------------------------------------------
# If we are doing flat mode then we need to mark every post on the page
# as read
if( ($mode == "flat") || ($config[postlist] == "flat") ){
for ($i = 0; $i< $checkreplies; $i++){
list($Marknumber) = mysql_fetch_array($sth);
$check = ",$Marknumber,";
if( (!(ereg($check,$read))) && ($posted > $unread) ) {
$notread{$Marknumber} = "true";
$read = $read.",$Marknumber,";
set_cookie($bname,"$read",0);
}
}
}
# -------------------------------
# Lets give the start of the page
send_header("$config[title]");
print"<table border=0 width=100% cellspacing=0>";
print"<tr><td colspan=2 bgcolor=$config[tdlight]><p align=right>";
# -----------------
# Assign the sort order
# If dateslip is on, we sort by Last_Post, otherwise we sort by Posted
$sort_opt;
$sort_by;
if ($config[dateslip] == "off") {
$sort_opt = array(
1 => 'Subject DESC',
2 => 'Subject ASC',
3 => 'Username DESC',
4 => 'Username ASC',
5 => 'Posted DESC',
6 => 'Posted ASC'
);
$sort_by = $sort_opt{$sb};
if(!$sort_by) { $sort_by = "Posted DESC";}
} else {
$sort_opt = array(
1 => 'Subject DESC',
2 => 'Subject ASC',
3 => 'Username DESC',
4 => 'Username ASC',
5 => 'Last_Post DESC',
6 => 'Last_Post ASC'
);
$sort_by = $sort_opt[$sb];
if(!$sort_by) {$sort_by = "Last_Post DESC";}
}
# ----------------------------------------------------------------------
# Grab all the main posts from the database that are on the current page
# We also need to grab one from the page before and one from the next
# page just so we can check if there needs to be a previous or next
# thread link.
$PostsPer = $user[PostsPer];
if (empty($PostsPer)) { $PostsPer = $config[postsperpage];}
$Totalgrab = '';
if($page < 1) {
$Totalgrab = $PostsPer + 2;
} else {
$Startat = $page *$PostsPer -1;
$Posts = $PostsPer +2;
$Totalgrab = "$Startat, $Posts";
}
$query = <<<END_SQL
SELECT Number,Main,Username,Subject,Posted
FROM $Board
WHERE Number = Main
ORDER BY $sort_by
LIMIT $Totalgrab
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
$total = mysql_num_rows($sth);
$newpage = 0;
# --------------------------------------------------------------------
# Set up some variables that we will be using at the end of flat mode
$previouspage = '';
$currentpage = '';
$nextpage = '';
# ----------------------------------------------------------------
# Cycle through all the posts to see if there are previous and next
# threads
#( $PNumber,$OldNumber,$Main,$OldMain,$Username,$OldUsername,$Subject,$OldSubject,$Posted,$OldPosted);
for($i=0;$i<$total;$i++){
$OldNumber = $PNumber;
$OldMain = $Main;
$OldUsername = $Username;
$OldSubject = $Subject;
$OldPosted = $Posted;
list($PNumber,$Main,$Username,$Subject,$Posted) = mysql_fetch_array($sth);
# --------------------------------------------------------------------
# We are checking here to see if they get a previous link button or not
if( ( ($PNumber == $current) && ($page ==0) && ($i > 0) && ($search != "true") ) ||
( ($PNumber == $current) && ($page !=0) && ($search != "true") ) ){
$whichpage = '';
if ($i == 1) {
$whichpage = $page -1;
} else {
$whichpage = $page;
}
if ($whichpage < 0) { $whichpage =0; }
$previouspage = "<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$OldNumber&page=$whichpage&view=$view&mode=$mode&sb=$sb\"><img src = \"$config[images]/previous.gif\" alt = \"Previous Thread\" border=0></a>";
$previous = 1;
} elseif ( ($PNumber == $current) && ($page == 0) && ($i == 0) && ($search != "true") ) {
$previouspage = "<img alt=\"*\" src = \"$config[images]/greyprevious.gif\">";
}
print $previouspage;
# ---------------------------------------------------------------------
# If we are on the current thread then we give the link for all threads
# unless they came from the search engine then we give them a link back
# to that.
if($PNumber == $current){
# --------------------------------------------------------------------
# If we didn't come from the search engine then they get a link to all
if ($search != "true"){
$currentpage = "<a href = \"$config[cgiurl]/index.php?action=list&Board=$Board&page=$page&view=$view&sb=$sb\"><img src = \"$config[images]/all.gif\" alt = \"View All Threads\" border=0></a>";
# -----------------------------------------------------------
# We came from the search engine so they get a link back to it.
} else {
$Words = $FORM[Words];
$Forum = $FORM[Forum];
$Old = $FORM[Old];
$Words = url_encode($Words);
$Forum = url_encode($Forum);
$Match = $FORM[Match];
$Match = url_encode($Match);
$Searchpage = $FORM[Searchpage];
$Limit = $FORM[Limit];
$currentpage = "<a href = \"$config[cgiurl]/dosearch.php?Forum=$Forum&Words=$Words&Match=$Match&Searchpage=$Searchpage&Limit=$Limit&Old=$Old\"><img src = \"$config[images]/all.gif\" alt = \"Return to the search engine.\" border=0></a>";
}
print $currentpage;
# --------------------------------------------------------------------
# Now also grab the the next thread
list($PNumber,$Main,$Username,$Subject,$Posted) = mysql_fetch_array($sth);
# --------------------------------------------------------------------
# If there is a next thread then give them a link to it otherwise they
# get a greyed out image
if(($PNumber) && ($search != "true") ) {
$i = $i + 2;
$whichpage = '';
if ( ($i == $total) && ($i > $PostsPer) ) {
$whichpage = $page + 1;
} else {
$whichpage = $page;
}
$nextpage = "<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$PNumber&page=$whichpage&view=$view&mode=$mode&sb=$sb\"><img src = \"$config[images]/next.gif\" alt = \"Next Thread\" border = 0></a>";
} elseif ($search != "true") {
$nextpage = "<img alt=\"*\" src=\"$config[images]/greynext.gif\">";
}
print $nextpage;
# -------------------------------------------------------------------
# If we got here then we are listing the original thread starting post
# so we set original to 1
$original = 1;
break;
}
}
# -----------------------------------------------------------------------
# If $original was not set by the previous for loop then we are showing a
# reply, so just give a link back to the list of all threads
if (!$original){
# --------------------------------------------------------------------
# If we didn't come from the search engine then they get a link to all
if ($search != "true"){
$currentpage = "<a href = \"$config[cgiurl]/index.php?action=list&Board=$Board&page=$page&view=$view&sb=$sb\"><img src = \"$config[images]/all.gif\" alt = \"View All Threads\" border=0></a>";
# ------------------------------------------------------------
# We came from the search engine so they get a link back to it.
} else {
$Words = $FORM[Words];
$Forum = $FORM[Forum];
$Old = $FORM[Old];
$Words = url_encode($Words);
$Forum = url_encode($Forum);
$Match = $FORM[Match];
$Match = url_encode($Match);
$Searchpage = $FORM[Searchpage];
$Limit = $FORM[Limit];
$currentpage = "<a href = \"$config[cgiurl]/dosearch.php?Forum=$Forum&Words=$Words&Match=$Match&Searchpage=$Searchpage&Limit=$Limit&Old=$Old\"><img src = \"$config[images]/all.gif\" alt = \"Return to the search engine.\" border=0></a>";
}
print $currentpage;
}
# --------------------------------------------------------------------------
# If $checkreplies = 1 and mode doesn't ==ual flat then we need to give them
# a link to show entire thread
if (($checkreplies > 1) && ($mode != "flat") && ($config[postlist] != "flat")){
print "<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$Number&page=$page&view=$view&mode=flat&sb=$sb\"><img src=\"$config[images]/flat.gif\" alt = \"Show in Flat Mode\" border=0></a>";
print "<img alt=\"*\" src=\"$config[images]/greythreaded.gif\">";
# -----------------------------------------------------------------------
# Otherwise if $checkreplies < 2 and we are not doing flat mode then they
# dont get a flat or a threaded image.
} elseif ( ($checkreplies < 2) && ($mode != "flat") ) {
print "<img alt=\"*\" src=\"$config[images]/greyflat.gif\">";
print "<img alt=\"*\" src=\"$config[images]/greythreaded.gif\">";
# ---------------------------------------------------
# Otherwise they geta link to switch back to threaded
} elseif ( ($checkreplies > 1) && ($mode == "flat") && ($config[postlist] != "flat")){
print "<img alt=\"*\" src=\"$config[images]/greyflat.gif\">";
print "<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$Number&page=$page&view=$view&mode=threaded&sb=$sb\"><img src=\"$config[images]/threaded.gif\" alt = \"Show in Threaded Mode\" border=0></a>";
} else {
print "<img alt=\"*\" src=\"$config[images]/greyflat.gif\">";
print "<img alt=\"*\" src=\"$config[images]/greythreaded.gif\">";
}
print"</td></tr></table>";
print"<br>";
# ---------------------------------------------------
# If we are doing flat mode then show the entire thread
if( ($mode == "flat") || ($config[postlist] == "flat") ){
# -------------------------------
# Now cycle through all the posts
$query = <<<END_SQL
SELECT Number,Posted,Username,IP,Subject,Body,File,Status
FROM $Board
WHERE Main = $current
ORDER BY Number
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
$totalthread = mysql_num_rows($sth);
for ($i = 0;$i< $totalthread;$i++){
list($Number,$Posted,$Username,$IP,$Subject,$Body,$File,$Open) = mysql_fetch_array($sth);
$time = convert_time($Posted);
$EUsername = url_encode($Username);
# ------------------------------------------------------------------
# If we came from the search engine then we bold the search keywords
if ($search == "true") {
$searchwords = split(" +",$FORM[Words]);
for ($i = 0; $i < sizeof($searchwords); $i++) {
$Body = preg_replacei("/$searchwords[$i]/", "<b><i>$searchwords[$i]<\/i><\/b>", $Body);
}
}
$newimage = '';
if ( ($notread{$Number} == "true") && ($Posted > $unread) ) {
$newimage = "<img alt=\"new\" src=\"$config[images]/new.gif\">";
}
$tablerows = 3;
if ( ($config[showip]) && ($IP) ) {
$tablerows++;
}
if ($File) {
$tablerows++;
}
# ------------------------------------------
# Set both the reply and edit buttons to off
$reply = "off";
$edit = "off";
# -------------------------------------------------------
# If the board is not locked then give them a reply button
if ( ($locked == "Open") && ($Open != "C") ){
$reply = "on";
} else {
# --------------------------------------------------------------
# If the board is locked then we need to see if they are an admin
# or moderator to see if they get a reply button.
$Username = $user[Username];
if (!$Username) { $Username = " "; }
$Username_q = db_quote($Username);
$query =<<<END_SQL
SELECT Status
FROM Users
WHERE Username=$Username_q
END_SQL;
$sti = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($checkstat) = mysql_fetch_array($sti);
# -------------------------------------------
# here we check for admin or moderator status
if (($checkstat == "Administrator") || ($checkstat == "Moderator")) {
$reply = "on";
}
}
# -----------------------------------
# lets see if they get a edit button
if($user[Username]) {
# -------------------------------------------------
# If they own the post or they are a moderator give
# them an edit button
if( ($user[Username] == $Username) || ($user[Username] == "$moderator") ) {
$edit = "on";
# ----------------------------------------------------------------------
# otherwise the only way they get an edit button is if they are an admin
} else {
$Username = $user[Username];
if (!$Username) { $Username = " "; }
$Username_q = db_quote($Username);
$query = <<<END_SQL
SELECT Status
FROM Users
WHERE Username = $Username_q
END_SQL;
$stj = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($admin) = mysql_fetch_array($stj);
if ($admin == "Administrator") {
$edit = "on";
}
}
}
$post_format = $user[Post_Format];
if (empty($post_format)) { $post_format = $config[post_format];}
if ($post_format == "top") {
print <<<END_HTML
<a name="Post$Number"></a>
<table width=100% cellspacing=0 cellpadding=0 border=0>
<tr bgcolor=$config[tddark]><td width=20% valign=top>Subject</td><td>$Subject $newimage</td>
<td rowspan=$tablerows valign=bottom align=right>
END_HTML;
if ($edit == "on") {
print "<a href=\"$config[cgiurl]/editpost.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img alt =\"Edit this post\" src=\"$config[images]/edit.gif\" border=0></a>";
}
if ($reply == "on") {
print"<a href=\"$config[cgiurl]/newreply.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img src=\"$config[images]/reply.gif\" alt = \"Reply to this message\" border=0></a>";
} else {
print " ";
}
print "</td>";
# ---------------------------------------------------------
# If its an anonymous post, dont' give a link to the profile
if($Username == "Anonymous") {
print "<tr bgcolor=$config[tddark]><td>Posted by</td><td>";
print "Anonymous</td></tr>";
} else {
print "<tr bgcolor=$config[tddark]><td>Posted by</td><td><a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a></td></tr>";
}
print"<tr bgcolor=$config[tddark]><td>Posted on</td><td>$time</td></tr>";
if ( ($config[showip]) && $IP) {
print "<tr bgcolor=$config[tddark]><td>From IP</td><td>$IP </td></tr>";
}
if ($File){
print "<tr bgcolor=$config[tddark]><td>Attachment</td><td><a href=\"$config[fileurl]/$File\">$File</a>";
}
print <<<END_HTML
<tr><td colspan=3 bgcolor=$config[tdlight]>
<p>
<br><br>$Body
<br><br>
</td></tr></table>
END_HTML;
}
elseif ($post_format == "side") {
print "\n<a name=\"Post$Number\"></a>\n";
print "<table width=\"100%\" cellspacing=0 border=0>\n";
# ---------------------------------------------------------
# If its an anonymous post, dont' give a link to the profile
if($Username == "Anonymous") {
print "<tr><td rowspan=2 width=17% valign=top bgcolor=$config[tddark]>\n";
print "Anonymous<br>\n";
} else {
print "<tr><td width=17% rowspan=2 bgcolor=$config[tddark] valign=top>\n<a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a><br>\n";
}
print"$time<br>\n";
if ( ($config[showip]) && $IP && (ereg("^[0123456789]", $IP)) ) {
print "$IP<br>\n";
}
if ($File){
print "<a href=\"$config[fileurl]/$File\">Attachment</a>\n";
}
print "</td><td rowspan=2 width=1>\n<img src=\"$config[images]/clear.gif\" width=1 height=1>\n";
print "</td><td bgcolor=$config[tdlight] align=left>\n";
print "$Subject $newimage\n";
print "</td><td bgcolor=$config[tdlight] align=right>\n";
if ($edit == "on") {
print "<a href=\"$config[cgiurl]/editpost.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img alt =\"Edit this post\" src=\"$config[images]/edit.gif\" border=0></a>\n";
}
if ($reply == "on") {
print"<a href=\"$config[cgiurl]/newreply.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img src=\"$config[images]/reply.gif\" alt = \"Reply to this message\" border=0></a>\n";
} else {
print " \n";
}
print "</td></tr>\n";
print "<tr><td width=83% colspan=2 bgcolor=$config[tdlight]>\n";
print "<hr width=100% size=1 noshade>\n";
print "<p>$Body<br><br>\n</td></tr></table>\n";
}
print "\n\n<br>\n\n";
}
# --------------------------------------------
# Now give them nav links at the bottom as well
if ($checkreplies > 1) {
print "<table cellspacing=0 border=0 width=100% bgcolor=$config[tdlight]>";
print "<tr><td align=right>";
print "$previouspage";
print "$currentpage";
print "$nextpage";
print "<img alt=\"*\" src=\"$config[images]/greyflat.gif\">";
print "<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$Number&page=$page&view=$view&mode=threaded&sb=$sb\"><img src=\"$config[images]/threaded.gif\" alt = \"Show in Threaded Mode\" border=0></a>";
print "</tr></td></table>";
}
# --------------------------
# we are doing threaded mode
} else {
$query = <<<END_SQL
SELECT Number,Posted,Username,IP,Subject,Body,Parent,File,Status
FROM $Board
WHERE Number=$Number
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($Number,$Posted,$Username,$IP,$Subject,$Body,$Parent,$File,$Open) = mysql_fetch_array($sth);
$time = convert_time($Posted);
$EUsername = url_encode($Username);
# ------------------------------------------------------------------
# If we came from the search engine then we bold the search keywords
if ($search == "true") {
$searchwords = split(" +",$FORM[Words]);
for ($i = 0; $i < sizeof($searchwords); $i++) {
$Body = preg_replacei("/$searchwords[$i]/", "<b><i>$searchwords[$i]<\/i><\/b>", $Body);
}
}
$tablerows =3;
if ( ($config[showip]) && ($IP) ) {
$tablerows++;
}
if ($File) {
$tablerows++;
}
# ------------------------------------------
# Set both the reply and edit buttons to off
$reply = "off";
$edit = "off";
# --------------------------------------------
# If the board is open, give them a reply button
if( ($locked == "Open") && ($Open != "C") ){
$reply = "on";
} else {
# ----------------------------------------------------------------
# If the board is locked then we need to see if they are an admin
# or moderator to see if they get a reply button.
$Username = $user[Username];
if(!$Username) { $Username = " "; }
$Username_q = db_quote($Username);
$query = <<<END_SQL
SELECT Status
FROM Users
WHERE Username = $Username_q
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Quer: $query");
list($checkstat) = mysql_fetch_array($sth);
# -----------------------------------------
# Check if they are a moderator or an admin
if (($checkstat == "Administrator") || ($checkstat == "Moderator")) {
$reply = "on";
}
}
# --------------------------------------------------------
# lets see if they get a edit button
if($user[Username]) {
if( ($user[Username] == $Username) || ($user[Username] == "$moderator") ) {
$edit = "on";
} else {
$Username = $user[Username];
if (!$Username) { $Username = " "; }
$Username_q = db_quote($Username);
$query =<<<END_SQL
SELECT Status
FROM Users
WHERE Username = $Username_q
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($admin) = mysql_fetch_array($sth);
if ($admin == "Administrator") {
$edit = "on";
}
}
}
$post_format = $user[Post_Format];
if (empty($post_format)) { $post_format = $config[post_format];}
if ($post_format == "top") {
print <<<END_HTML
<a name="Post$Number"></a>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr bgcolor=$config[tddark]><td width=20% valign=top>Subject</td><td>$Subject</td>
<td rowspan=$tablerows valign=bottom align=right>
END_HTML;
if ($edit == "on") {
print "<a href=\"$config[cgiurl]/editpost.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img alt =\"Edit this post\" src=\"$config[images]/edit.gif\" border=0></a>";
}
if ($reply == "on") {
print"<a href=\"$config[cgiurl]/newreply.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img src=\"$config[images]/reply.gif\" alt = \"Reply to this message\" border=0></a>";
} else {
print " ";
}
print "</td></tr>";
if ($Username == "Anonymous"){
print "<tr bgcolor=$config[tddark]><td>Posted by</td><td>";
print "Anonymous</td></tr>";
} else {
print "<tr bgcolor=$config[tddark]><td>Posted by</td><td><a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a></td></tr>";
}
print"<tr bgcolor=$config[tddark]><td>Posted on</td><td>$time</td></tr>";
if ( ($config[showip]) && ($IP) ){
print "<tr bgcolor=$config[tddark]><td>From IP</td><td>$IP </td></tr>";
}
if ($File){
print "<tr bgcolor=$config[tddark]><td>Attachment</td><td><a href=\"$config[fileurl]/$File\">$File</a>";
}
print <<<END_HTML
<tr><td colspan=3 bgcolor=$config[tdlight]>
<p><br><br>$Body
<br><br>
</td></tr></table>
END_HTML;
} elseif ($post_format == "side") {
print"<a name=\"Post$Number\"></a>";
print"<table width=100% cellspacing = 0 border=0>";
# ---------------------------------------------------------
# If its an anonymous post, dont' give a link to the profile
if($Username == "Anonymous") {
print "<tr><td rowspan=2 width=17% valign=top bgcolor=$config[tddark]>";
print "Anonymous<br>";
} else {
print "<tr><td width=17% rowspan=2 bgcolor=$config[tddark] valign=top><a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a><br>";
}
print"$time<br>";
if ( ($config[showip]) && $IP && (ereg("^[0123456789]", $IP)) ) {
print "$IP<br>";
}
if ($File){
print "<a href=\"$config[fileurl]/$File\">Attachment</a>";
}
print "</td><td rowspan=2 width=1><img src=\"$config[images]/clear.gif\"width=1 height=1>";
print "</td><td bgcolor=$config[tdlight] align=left>";
print "$Subject";
print "</td><td bgcolor=$config[tdlight] align=right>";
if ($edit == "on") {
print "<a href=\"$config[cgiurl]/editpost.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img alt =\"Edit this post\" src=\"$config[images]/edit.gif\" border=0></a>";
}
if ($reply == "on") {
print"<a href=\"$config[cgiurl]/newreply.php?Board=$Board&Number=$Number&page=$page&view=$view&what=showpost&mode=$mode&sb=$sb\"><img src=\"$config[images]/reply.gif\" alt = \"Reply to this message\" border=0></a>";
} else {
print " ";
}
print "</td></tr>";
print "<tr><td colspan=2 bgcolor=$config[tdlight] width=83%>";
print "<hr size=1 noshade>";
print "<p>$Body<br><br></td></tr></table>";
}
# -------------------------------------------------
# Lets see if there are any replies to this message
if($checkreplies > 1) {
print <<<END_HTML
<table cellpading=0 cellspacing=0 border=0 width=100% bgcolor=$config[tdalt]>
<tr><td><img alt=\"-\" src="$config[images]/hr.gif"></td></tr>
</table>
<TABLE BORDER=0 WIDTH=100% cellspacing=0>
<tr><td align=center colspan=3 bgcolor=$config[tddark]><b>Entire Thread</b></center></td></tr>
<tr bgcolor=$config[tddark]><td width=50%>Subject</td><td width=20%> Posted by</td><td width=30%>Posted On</td></tr>
END_HTML;
$color = $config[tdlight];
$indent = 0;
# -----------------------------------
# List the first post for this thread
$query =<<<END_SQL
SELECT Number,Parent,Posted,Username,Subject,Status
FROM $Board
WHERE Number = $current
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
list($PNumber,$Parent,$Posted,$Username,$Subject,$Locked) = mysql_fetch_array($sth);
print "<tr bgcolor=$color><td>";
$time = convert_time($Posted);
$folder = "closedfolder.gif";
$thisone = ",$PNumber,";
$alt = ".";
if( ($Posted > $unread) && (!(ereg($thisone, $read))) ){
$alt = "*";
$folder = "newclosedfolder.gif";
} else {
$alt = ".";
$folder = "closedfolder.gif";
}
if ($Locked == "C") {
$alt = "-";
$folder = "lock.gif";
}
if( $PNumber == $Number ) {
print "<img src=\"$config[images]/$folder\" alt =$alt hspace=5><b>$Subject</b>";
} else {
print"<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$PNumber&page=$page&view=$view&mode=$mode&sb=$sb#Post$PNumber\"><img src=\"$config[images]/$folder\" alt=\"*\" border=0 hspace=5>$Subject</a>";
}
if ($Username == "Anonymous") {
print"</td><td width=150 valign=top> Anonymous</td>";
} else {
$EUsername = url_encode($Username);
print"</td><td width=150 valign=top> <a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a></td>";
}
print "<td valign=top>$time</td></tr>";
# alternate the colors
if ($color == "$config[tdlight]") {
$color = "$config[tddark]";
} else {
$color = "$config[tdlight]";
}
$color = show_replies($Board,$current,$Number,$page,$view,$sb,$indent,$color,$unread,$mode);
}
}
# -------------------
# Give the jumper box
mysql_free_result($sth);
print "</table>";
print "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td align=right>";
$query = <<<END_SQL
SELECT Number,Title,Keyword,Security
FROM Boards
WHERE Security <= $user_security
ORDER BY Title
END_SQL;
$sth = mysql_query($query) or die ("Can't prepare $query. Reason: " . mysql_error() . ".");
print "<FORM METHOD=POST action =\"$config[cgiurl]/jumper.php\">";
print "Jump to ";
print "<SELECT NAME=board>";
while ($varlist = mysql_fetch_array($sth)) {
print "<option value=\"$varlist[2]\">$varlist[1]\n";
}
print "</select>";
print "<input type=submit name=Jump value=Jump>";
print "</form>";
print "</td></tr>";
print "</table>";
# ----------------
# Send the footer
send_footer();
#######################################################################
# Show replies
#######################################################################
function show_replies($Board,$current,$Number,$page,$view,$sb,$indent,$color,$unread,$mode) {
global $config;
$rname = $Board . "_read";
$cookie = get_cookie();
$read = $cookie[$rname];
# ---------------------------------------
# Heres where we actually list the replies
$query =<<<END_SQL
SELECT Number,Parent,Posted,Username,Subject,Status
FROM $Board
WHERE Parent = $current
ORDER BY Number DESC
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
$followups = mysql_num_rows($sth);
$indent++;
for($x=0;$x<$followups;$x++){
list($PNumber,$Parent,$Posted,$Username,$Subject,$Open) = mysql_fetch_array($sth);
print "<tr bgcolor=$color><td>";
for ($y=0;$y<$indent;$y++){
print "<img alt=\".\" src=\"$config[images]/blank.gif\">";
}
$time = convert_time($Posted);
$folder = "closedfolder.gif";
$thisone = ",$PNumber,";
$alt = ".";
if( ($Posted > $unread) && (!(ereg($thisone, $read))) ){
$alt = "*";
$folder = "newclosedfolder.gif";
} else {
$alt = ".";
$folder = "closedfolder.gif";
}
if ($PNumber == $Number) {
$alt = ".";
$folder = "closedfolder.gif";
}
if ($Open == "C") {
$alt = "-";
$folder = "lock.gif";
}
if( $PNumber == $Number ) {
print "<img src=\"$config[images]/$folder\" alt =$alt hspace=5><b>$Subject</b>";
} else {
print"<a href=\"$config[cgiurl]/showpost.php?Board=$Board&Number=$PNumber&page=$page&view=$view&mode=$mode&sb=$sb#Post$PNumber\"><img src=\"$config[images]/$folder\" alt=\"*\" border=0 hspace=5>$Subject</a>";
}
if ($Username == "Anonymous") {
print"</td><td width=20% valign=top> Anonymous</td>";
} else {
$EUsername = url_encode($Username);
print"</td><td width=20% valign=top> <a href=\"$config[cgiurl]/showprofile.php?User=$EUsername&Number=$Number&Board=$Board&what=showpost&page=$page&view=$view&mode=$mode&sb=$sb\">$Username</a></td>";
}
print "<td valign=top>$time</td></tr>";
# alternate the colors
if ($color == "$config[tdlight]") {
$color = "$config[tddark]";
} else {
$color = "$config[tdlight]";
}
$query = <<<END_SQL
SELECT Number
FROM $Board
WHERE Parent = $PNumber
END_SQL;
$sth = mysql_query ($query) or die ("Query syntax error: " . mysql_error() . ". Query: $query");
$follows = mysql_num_rows($sth);
if ($follows > 0) {
$color = show_replies($Board,$PNumber,$Number,$page,$view,$sb,$indent,$color,$unread,$mode);
}
}
$indent--;
mysql_free_result($sth);
return $color;
}
?>