Location: PHPKode > projects > top serious project > bco/view_watched_topics.php
<?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"); 

include("include.php");

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.
$message_alert = '';
if ($logged_in) {
    $last_view_query = "update users set last_view=NOW() where id=$user_array[myuserid]";
    if (!pg_query($last_view_query)) {
        echo "\n<br />Update last_view time failed.<br />";
    }
} else {
    header("Location: http://board.crewcial.org/login.php");
    exit;
}

/* select subject_index.username as created_by_user, subject_index.createdby as created_by_id, messages.id, messages.id_subject, UNIX_TIMESTAMP(messages.postdate) as postdate, messages.subject from messages left join subject_index on subject_index.id=messages.id_subject where messages.msgbody like "% ian %" or messages.subject like "% ian %" or messages.msgbody like "ian %" or messages.subject like "ian %" or messages.msgbody like "% ian" or messages.subject like "% ian" group by messages.id_subject order by postdate desc limit 0, 100 */

$subject_query  = "select a.id as id, a.createdby as createdby, a.username as username,";
$subject_query .= " a.lastpost_by as lastpost_by, a.subject as subject,";
$subject_query .= " extract(epoch from a.lastpost_date) as lastpost_date,";
$subject_query .= " a.replies as replies, a.views as views, a.sticky as sticky, b.last_post_id as last_post_id"; 
$subject_query .= " from subject_index as a left join threads_watched as b on a.id=b.thread_id where b.user_id=$user_array[myuserid]";
$subject_query .= " and b.thread_id=a.id";
$subject_query .= " order by a.lastpost_date $order";

if (!$subject_result = pg_query($subject_query)) {
    bco_error("Oops!<br />" . pg_last_error());
}

$number_of_threads = pg_num_rows($subject_result);

/* $number_of_threads_query = "select count(id) from subject_index";
$number_of_threads = pg_fetch_result(pg_query($number_of_threads_query), 0);*/

bco_html_header(BOARD_TITLE);

bco_index_menu(BOARD_TITLE . " - $number_of_threads threads.");

// 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\"><div align=\"center\"><h3>Sorry, you are not watching any threads.</h3></div></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 $message_alert;
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\">&nbsp;</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($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("&", "&amp;", strip_tags(stripslashes(trim($thread_data[$i]['subject']))));
    $lastpost_date  = date("h:i A m-d-y", $thread_data[$i]['lastpost_date']);
    $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'];
	$last_post_id	= $thread_data[$i]['last_post_id'];
 
    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 == 1) {
        $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>";
    if ($logged_in) {
        $reply_query = "select username from messages where id_subject=$id";
        $reply_result = pg_query($reply_query);
        $reply_count = 0;
        while ($reply_row = pg_fetch_row($reply_result)) {
            $reply_array[] = $reply_row;
        }
        for ($x = 0; $x < count($reply_array); $x++) {
            $reply_array2[] = $reply_array[$x][0];
        }
        $last_reply = count($reply_array) - 1;
        if ((in_array($user_array['username'], $reply_array2)) && ($reply_array2[$last_reply] != $user_array['username'])) {
            echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class><strong>&#149;</strong></td>";
        } else {
            echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>&nbsp;</td>";
        }
    } else {
        echo "\n<td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>&nbsp;</td>";                                    }
    echo "\n        <td align=\"left\" valign=\"top\" width=\"60%\"$row_class>$announcement";
	if ($last_post_id == "") {
    	echo "<a href=\"view_topic.php?id=$id&amp;r=$replies\" class=\"$link_class\">$subject</a></td>";
	} else {
		echo "<a href=\"view_topic.php?id=$id&amp;r=$replies#$last_post_id\" 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>";
    unset($reply_array2);
    unset($reply_array);
}

echo "\n</table>";
echo "\n<div align=\"left\">$page_numbers</div>";

bco_html_footer();

?>
Return current item: top serious project