<?php
/***************************************************************************
* Copyright 2003 Ian Meyer, Ian Pitcher
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
require("include.php");
$order = '';
switch ($_GET['order']) {
case "asc":
$order = "asc";
break;
case "desc":
$order = "desc";
break;
default:
$order = "desc";
break;
}
if ((isset($_GET['start'])) && (is_numeric($_GET['start']))) {
$start = $_GET['start'];
} else {
$start = 0;
}
/*
// If the person is logged in, let's update the last view field to the current time.
if ($logged_in) {
pg_query("BEGIN");
$query = "INSERT INTO active_users
(username, date, posted)
values
('$user_array[username]', NOW(), 'f')";
if (!pg_query($pg_result, $query)) {
echo "\n<br />My bad, as they say.<br />" . pg_last_error() . "<br />";
}
pg_query("COMMIT");
}
*/
$query = "select config_value from bco_config where config_name='thread_amount'";
$thread_amount = pg_fetch_result(pg_query($pg_result, $query), 0);
// Sticky query.
if ($logged_in) {
$query = "select
id,
createdby,
username,
lastpost_by,
subject,
extract(epoch from lastpost_date) as lastpost_date_epoch,
(SELECT
count(*) > 0
FROM
messages
where
id_subject = subject_index.id
and messages.username = '$user_array[username]'
and subject_index.lastpost_by != '$user_array[username]')
AS dot,
locked,
replies,
views,
sticky
from subject_index
where sticky='t'
order by date_created desc";
} else {
$query = "select
id,
createdby,
username,
lastpost_by,
subject,
extract(epoch from lastpost_date) as lastpost_date_epoch,
'f' AS dot,
locked,
replies,
views,
sticky
from subject_index
where sticky='t'
order by date_created desc";
}
if (!$sticky_result = pg_query($pg_result, $query)) {
bco_error("Sticky query failed.<br />" . pg_last_error());
}
//
// How many sticky threads? Needed to decide limit and offset.
//
//$sticky_amount = pg_num_rows($sticky_result);
//
// Don't know how to describe this yet.
//
//echo $query;
if ($logged_in) {
$query = "select
id,
createdby,
username,
lastpost_by,
subject,
extract(epoch from lastpost_date) as lastpost_date_epoch,
(SELECT
count(*) > 0
FROM
messages
where
id_subject = subject_index.id
and messages.username = '$user_array[username]'
and subject_index.lastpost_by != '$user_array[username]')
AS dot,
locked,
replies,
views,
sticky
from subject_index
where sticky='f'
order by lastpost_date desc
LIMIT $thread_amount OFFSET $start";
} else {
$query = "select
id,
createdby,
username,
lastpost_by,
subject,
extract(epoch from lastpost_date) as lastpost_date_epoch,
'f' AS dot,
locked,
replies,
views,
sticky
from subject_index
where sticky='f'
order by lastpost_date desc
LIMIT $thread_amount OFFSET $start";
}
if (!$subject_result = pg_query($pg_result, $query)) {
bco_error("Topic query failed.<br />" . pg_last_error());
}
bco_html_header(BOARD_TITLE);
bco_index_menu(BOARD_TITLE);
// Display a nice message about no new messages.
if ($number_of_threads == 0) {
echo "\n<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"replytable\">";
echo "\n <tr>";
echo "\n <td class=\"tr1\" colspan=\"5\">";
echo "\n <div align=\"center\"><h3>Sorry, no messages have been added yet.</h3></div>";
echo "\n </td>";
echo "\n </tr>";
echo "\n</table>";
bco_html_footer();
exit;
}
if ($number_of_threads < $thread_amount) {
$page_numbers = "";
} else {
$page_numbers = bco_makepagenumbers("index.php?", $number_of_threads, $thread_amount, $start, $order);
}
echo "\n<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"replytbl\">";
echo "\n <tr>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\">username</span></td>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\"> </span></td>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\"> </span></td>";
echo "\n <td align=\"left\" width=\"60%\" class=\"header\"><span class=\"smallfont\">subject</span></td>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\">last post</span></td>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\">replies</span></td>";
echo "\n <td align=\"left\" class=\"header\"><span class=\"smallfont\">views</span></td>";
echo "\n </tr>\n";
$thread_data = array();
while ($row = pg_fetch_assoc($sticky_result)) {
$thread_data[] = $row;
}
unset($row);
while ($row = pg_fetch_assoc($subject_result)) {
$thread_data[] = $row;
}
$array_count = count($thread_data);
for ($i = 0; $i < $array_count; $i++) {
$id = $thread_data[$i]['id'];
$createdby = $thread_data[$i]['createdby'];
$subject = ereg_replace("&", "&", strip_tags(stripslashes(trim($thread_data[$i]['subject']))));
$lastpost_date = date("h:i A m-d-y", $thread_data[$i]['lastpost_date_epoch']);
$replies = $thread_data[$i]['replies'];
$views = $thread_data[$i]['views'];
$sticky = $thread_data[$i]['sticky'];
$lastpost_by = $thread_data[$i]['lastpost_by'];
$username = $thread_data[$i]['username'];
$locked = $thread_data[$i]['locked'];
$dot = $thread_data[$i]['dot'];
// $has_posted = $thread_data[$i]['has_posted'];
if ($createdby == $user_array['myuserid']) {
$row_class = " class=\"mypost\"";
$link_class = "mypost";
} elseif ($i % 2 == 0) {
$row_class = " class=\"tr2\"";
$link_class = "tr2";
} else {
$row_class = " class=\"tr1\"";
$link_class = "tr1";
}
$string_array = array();
$string_array[] = split(" ", $subject);
$new_array = array();
// Sometimes people make threads with no spaces in them thus breaking the html breaks!
// This will chop up any word that is longer than 26 chars and make it into something small
foreach($string_array as $value) {
foreach ($value as $key => $value2) {
if (strlen($value2) > 26) {
$value2 = substr($value2, 0, 13) . "-...";
}
$new_array[] = $value2;
}
}
$subject = implode(" ", $new_array);
if ($sticky == "t") {
$subject = "<strong>Sticky:</strong> " . $subject;
}
echo "\n <tr>";
echo "\n <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>";
echo "<a href=\"view_profile.php?id=$createdby\" class=\"$link_class\">$username</a></td>";
// Display the nice little image if the thread is locked.
if ($locked) {
echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class><img src=\"./lock.png\" alt=\"Thread is locked\" /></td>";
} else {
echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class> </td>";
}
if ($dot == "t") {
if ($lastpost_by != $user_array['username']) {
echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>•</td>";
} else {
echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class> </td>";
}
} else {
echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class> </td>";
}
echo "\n <td align=\"left\" valign=\"top\" width=\"60%\"$row_class>";
echo "<a href=\"view_topic.php?id=$id&r=$replies\" class=\"$link_class\">$subject</a></td>";
echo "\n <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>";
echo "$lastpost_date <span class=\"smallfont\">by: $lastpost_by</span></td>";
echo "\n <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>$replies</td>";
echo "\n <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>$views</td>";
echo "\n </tr>";
}
echo "\n</table>";
echo "\n<div align=\"left\">$page_numbers</div>";
bco_html_footer();
?>