<?php require("variables.inc"); ?>
<?php require("functions.inc"); ?>
<?php require("classes.inc");

$currentforum = new Forum;
$currentforum->loadInfo($forum);

$currentthread = new Thread;
$currentthread->loadInfo($forum,$threadid);
$currentthread->loadMessages($forum,$threadid);

?>
<html>
<head>
 <title><?php echo $boardname; ?>: <?php echo $currentforum->getFullName(); ?>: <?php echo $currentthread->getSubject(); ?></title>
 <?php echo stylesheetLink(); ?>
</head>

<body bgcolor="#<?php echo $bgcolour; ?>" text="#<?php echo $textcolour; ?>" link="#<?php echo $linkcolour; ?>" vlink="#<?php echo $vlinkcolour; ?>" alink="#<?php echo $alinkcolour; ?>"<?php if (!$margins) { print " marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" topmargin=\"0\""; } ?>>

<?php include("options/header.txt"); ?>

<div align="center">
<table border="0" width="98%" cellspacing="3">
 <tr valign="top">
  <td><a href="index.php3?serve=cached"><b><?php echo $boardname ?></b></a>: <a href="viewforum.php3?forum=<?php echo $forum; ?>"><b><?php echo $currentforum->getFullName(); ?></b></a>: <b><?php echo $currentthread->getSubject(); ?></b><br><small><?php

if (isset($cookieusername))
   {
   print "Logged in as $cookieusername | <a href=\"editprofile.php3?username=$cookieusername\">Edit profile</a> | <a href=\"logout.php3\">Logout</a>\n";
   }
else
   {
   print "<a href=\"login.php3\">Login</a> | <a href=\"register.php3\">Register</a>\n";
   }

?></small></td>
  <td align="right"><a href="post.php3?postto=<?php echo $forum; ?>">Post new topic</a> | <a href="register.php3">Register</a> | <a href="faq.php3">FAQ</a><?php

if (isset($cookieoldlastvisit))
   {
   print "<br><small>You last visited: ";
   echo date("H:i, j/n/Y",$cookieoldlastvisit);
   }

?></td>
 </tr>
</table>
</div>

<p>&nbsp;</p>

<div align="center">
<table border="0" cellspacing="2" cellpadding="3" width="90%">
<?php

if (accessAllowed($currentforum) == true)
   {
   if (isset($cookieusername))
      {
      $reader = new Member(getMemberNumber($cookieusername));
      $ismoderator = $reader->isModerator();
      }

   if ($displaythreadedlist)
      {
      if ($currentthread->getNumMessages() > $maxmessagesonapage)
         {
         print " <tr>\n";
         print "  <td width=\"20%\">&nbsp;</td>\n";
         print "  <td bgcolor=\"$main_tdbgcolor\"><font color=\"#$secondary_textcolor\"><b>";
         echo $currentthread->getSubject();
         print "</b></font></td>\n";
         print " </tr>\n";
         print " <tr>\n";
         print "  <td>&nbsp;</td>\n";
         print "  <td bgcolor=\"$secondary_tdbgcolor\">This is a long thread.  Click <a href=\"viewthreadedlist.php3?forum=$forum&threadid=$threadid\">here</a> to view the threaded list.</td>\n";
         print " </tr>\n";
         }
      else
         {
         print " <tr>\n";
         print "  <td width=\"20%\">&nbsp;</td>\n";
         print "  <td bgcolor=\"$main_tdbgcolor\"><font color=\"#$secondary_textcolor\"><b>";
         echo $currentthread->getSubject();
         print "</b></font></td>\n";
         print " </tr>\n";
         print " <tr>\n";
         print "  <td>&nbsp;</td>\n";
         print "  <td bgcolor=\"$secondary_tdbgcolor\">";
         echo $currentthread->listThreadedMessages();
         print "  </td>";
         print " </tr>";
         }
      }
   print "</table><br>\n";


   if (!isset($page))
      {
      $page = 1;
      }
   $startfrom = (($page - 1) * $maxmessagesonapage);
   for ($x = $startfrom; $x < $currentthread->getNumMessages(); $x++)
      {
      if (($x - $startfrom) < $maxmessagesonapage)
         {
         $message = $currentthread->getMessage($x);

         if ($message->getStatus() == "deleted")
            {
            print "<table border=\"0\" cellspacing=\"2\" cellpadding=\"3\" width=\"90%\">\n";
            print " <tr>\n";
            print "  <td bgcolor=\"#$main_tdbgcolor\"><b><font color=\"#$secondary_textcolor\"><a name=\"";
            echo $message->getMessagePostTime("U");
            print "\">";
            print "Message deleted</a></font></b></td>\n";
            print " </tr>\n";
            print " <tr>\n  <td>&nbsp;</td>\n </tr>\n";
            print "</table>\n";
            }
         else
            {
            $author = $message->getAuthor($x);

            // Display message
            print "<table border=\"0\" cellspacing=\"2\" cellpadding=\"3\" width=\"90%\">\n";
            print " <tr>\n";
            print "  <td bgcolor=\"#$main_tdbgcolor\" width=\"20%\"><b><font color=\"#$secondary_textcolor\"><a name=\"";
            echo $message->getMessagePostTime("U");
            print "\">";
            if ($displayrealnames)
               {
               echo str_replace(" ","&nbsp;",$author->getFullName());
               }
            else
               {
               echo $author->getUsername();
               }
            print "</a>&nbsp;&nbsp;</font></b></td>\n";
            print "  <td bgcolor=\"#$main_tdbgcolor\"><small>Posted by <a href=\"profile.php3?username=";
            echo $author->getUsername();
            print "\">";
            echo $author->getUsername();
            print "</a> at ";
            echo $message->getMessagePostTime("H:i");
            print ", on ";
            echo $message->getMessagePostTime("j/n/Y");
      /*      if (isset($currentthread->messageindex[$message->getParent()]))
               {
               $parentmessage = $currentthread->messageindex[$message->getParent()];
               print ", in reply to <a href=\"#";
               echo $parentmessage->getMessagePostTime("U");
               print "\">";
               if ($displayrealnames)
                  {
                  echo $parentmessage->getAuthorFullName();
                  }
               else
                  {
                  echo $parentmessage->getAuthorUsername();
                  }
               print "</a>.";
               }      */
            print "</small></td>\n";
            print " </tr>\n";
            print " <tr valign=\"top\">\n";
            print "  <td bgcolor=\"#$secondary_tdbgcolor\"><small>";
            if (isset($siteabbrev))
               {
               echo str_replace($siteabbrev,"<b><a href=\"$siteurl\">$siteabbrev</a></b>",$author->getStatus());
               }
            print "<br><br>Posts: " . $author->getTotalPosts() . "</small>";
            print "</td>\n";
            print "  <td bgcolor=\"#$secondary_tdbgcolor\">";

            $year = date("Y",time());
            $messagetext = $message->getMessageText();
            $messagetext = str_replace("[Edited by","<small>[Edited by",$messagetext);
            $messagetext = str_replace("$year]","$year]</small>",$messagetext);
            $messagetext = str_replace("[quote]",$quoteson,$messagetext);
            $messagetext = str_replace("[/quote]",$quotesoff,$messagetext);
            echo $messagetext;

            if (($message->displaySignature()) && ($author->hasSignature()))
               {
               print "<br>________<br>";
               echo $author->getSignature();
               }
            print "<small><br>&nbsp;</small></td>\n";
            print " </tr>\n";
            print "  <td bgcolor=\"#$main_tdbgcolor\"><small>";
            if (isAdministrator($author->getUsername()))
               {
               print "<font color=\"#$secondary_textcolor\">Administrator</font>";
               }
            else if (isModerator($author->getUsername()))
               {
               print "<font color=\"#$secondary_textcolor\">Moderator</font>";
               }
            else
               {
               print "&nbsp;";
               }
            print "</samll></td>\n";
            print "  <td bgcolor=\"#$main_tdbgcolor\"><a href=\"#top\"><img src=\"images/uparrow.gif\" width=\"15\" height=\"14\" alt=\"^\" align=\"right\" border=\"0\"></a><small>";
            if ($currentthread->getStatus() != "closed")
               {
               print "[ <a href=\"reply.php3?forum=";
               echo $forum;
               print "&message=";
               echo $x;
               print "&threadid=";
               echo $threadid;
               print "\">Reply to this message</a> ";
               print "| <a href=\"reply.php3?forum=";
               echo $forum;
               print "&message=";
               echo $x;
               print "&threadid=";
               echo $threadid;
               print "&quote=true\">Reply and quote</a> ";
               if (($cookieusername == $author->getUsername()) || ($ismoderator))
                  {
                  // Display 'Edit message' link
                  print "| <a href=\"/alpha-board/editpost.php3?forum=";
                  echo $forum;
                  print "&message=";
                  echo $x;
                  print "&threadid=";
                  echo $threadid;
                  print "\">Edit</a> ";
                  }
               if ($ismoderator)
                  {
                  print "| <a href=\"/alpha-board/deletemessage.php3?forum=";
                  echo $forum;
                  print "&message=";
                  echo $x;
                  print "&threadid=";
                  echo $threadid;
                  print "\">Delete</a> ";
                  }
               print "]";
               }
            print "</small></td>\n";
            print " </tr>\n";
            print " <tr>\n";
            print "  <td>&nbsp;</td>\n";
            print " </tr>\n";
            print "</table>\n";
            }
         }
      }

   if ($currentthread->getStatus() == "closed")
      {
      print "<table border=\"0\" cellspacing=\"2\" cellpadding=\"3\" width=\"90%\">\n";
      print " <tr>\n";
      print "  <td colspan=\"2\" bgcolor=\"#$main_tdbgcolor\" align=\"center\"><font color=\"#$secondary_textcolor\"><b>This thread is closed</b></font></td>\n";
      print " </tr>\n";
      print " <tr>\n";
      print "  <td>&nbsp;</td>\n";
      print " </tr>\n";
      print "</table><br>\n";
      }

   // Display page links
   if ($currentthread->getNumMessages() > $maxmessagesonapage)
      {
      print "<table border=\"0\" cellspacing=\"2\" cellpadding=\"3\" width=\"90%\">\n";
      print " <tr>\n";
      print "  <td align=\"right\">";
      print "<b>Page</b>: ";
      $numpages = ceil($currentthread->getNumMessages()/$maxmessagesonapage);
      for ($y = 0; $y < $numpages; $y++)
         {
         if ($page == ($y + 1))
            {
            echo ($y + 1);
            print " ";
            }
         else
            {
            print "<a href=\"viewthread.php3?forum=$forum&threadid=$threadid&page=" . ($y + 1) . "\">" . ($y + 1) . "</a> ";
            }
         }
      print "</td>\n";
      print " </tr>\n";
      print "</table>\n";
      }

   if ($ismoderator)
      {
      print "<table border=\"0\" cellspacing=\"2\" cellpadding=\"3\" width=\"90%\">\n";
      print " <tr>\n";
      print "  <td bgcolor=\"#$main_tdbgcolor\" colspan=\"2\"><font color=\"#$secondary_textcolor\"><b>Moderator functions</b></font></td>\n";
      print " </tr>\n";
      print "  <td bgcolor=\"#$secondary_tdbgcolor\" width=\"20%\">&nbsp;</td>\n";
      print "  <td bgcolor=\"#$secondary_tdbgcolor\">";
      if ($currentthread->getStatus() != "closed")
         {
         print "[ <a href=\"/alpha-board/closethread.php3?forum=$forum&threadid=$threadid\">Close thread</a> ] ";
         }
      print "[ <a href=\"/alpha-board/deletethread.php3?forum=$forum&threadid=$threadid\">Delete thread</a> ] ";
      print "[ <a href=\"/alpha-board/renamethread.php3?forum=$forum&threadid=$threadid\">Rename thread</a> ] ";;
      print "</td>\n";
      print " </tr>\n";
      print "</table>\n";
      }
   }
else
   {
   print " <tr>\n  <td>";
   echo accessAllowed($currentforum);
   print "  </td>\n </tr>\n</table>\n";
   }

?>
</div>


<p align="center"><small>Powered by alpha board version <?php echo $versionnum; ?>.<br>
&copy; <a href="http://www.tfountain.co.uk/">Tim Fountain</a>, 2000 - <?php echo $year ?>.</small></p>

<?php include("options/footer.txt"); ?>

</body>
</html>