Location: PHPKode > projects > top serious project > bco/view_post_history.php
<?php

exit("Bringing the old histories back soon.");

require("include.php");

// If they're not logged in, don't let them see this.
if (!$logged_in) {
    //redirect("login.php?back=ph.php" . htmlentities(urlencode("?") . urlencode($_SERVER[QUERY_STRING])));
    header("Location: $GLOBALS[base_url]" . "login.php?back=view_post_history.php" . htmlentities(urlencode("?") . urlencode($_SERVER['QUERY_STRING'])));
}

// Run some started checks, since we may or may not be using $_GET
if (!isset($_GET['id'])) {
    bco_error("You can't access this page without a userid");
}

// If this isn't a number... 
if (!is_numeric($_GET['id'])) {
    bco_error("userid is not a number.");
}

if ((is_numeric($_GET['start'])) && (isset($_GET['start']))) {
    $start = $_GET['start'];
} else {
    $start = 0;
}

switch ($_GET['order']) {
case "asc":
    $order = "asc";
    break;

case "desc":
    $order = "desc";
    break;

default:
    $order = "desc";
    break;

}

$thread_amount_query = "select config_value from bco_config where config_name='thread_amount'";
$thread_amount = pg_fetch_result(pg_query($thread_amount_query), 0);

$query = "select id from messages where createdby=$_GET[id] group by id_subject";

if (!$result = pg_query($query)) {
	bco_error(pg_last_error());
}

$total_replies = pg_num_rows($result);

// Set the query for subjects here.
$query  = "select a.id, a.username, a.subject,";
$query .= " MAX(extract(epoch from b.postdate)) as lastpost_date, a.locked,";
$query .= " a.createdby, a.replies, a.views, a.sticky from messages b";
$query .= " left join subject_index a on a.id=b.id_subject where b.createdby=$_GET[id]";
//$query .= " group by id_subject order by sticky desc, postdate $order limit $start, $thread_amount";
$query .= " group by id_subject, b.id order by postdate $order limit $start, $thread_amount";

echo $query;

if (!$result = pg_query($query)) {
    bco_error("Message retrieval failed:<br />MySQL said: " . pg_last_error());
}

// Get total number of threads user has created
$total_rows = pg_num_rows($result);

// Get the username here.
$username = bco_get_username($_GET['id']);

bco_html_header("$total_replies topics replied to, started by $username.");

bco_index_menu("$total_replies topics replied to, started by $username.");

// Make page numbers here!
$page_numbers = bco_makepagenumbers($base_url . "view_post_history.php?id=$_GET[id]", $total_replies, $thread_amount, $start, $order);

// Column headers
echo "\n<br />";
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\">&nbsp;</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&nbsp;post</span></td>";
echo "\n        <td align=\"left\" class=\"header\"><span class=\"smallfont\">reply</span></td>";
echo "\n        <td align=\"left\" class=\"header\"><span class=\"smallfont\">view</span></td>";
echo "\n    </tr>\n";

if ($total_replies == 0) {
    echo "\n	<tr>";
	echo "\n        <td class=\"tr1\" colspan=\"5\">No threads have been created by $username.</td>";
	echo "\n    </tr>";
	echo "\n    <tr>";
	echo "\n        <td colspan=\"5\" class=\"footer\"><a href=\"index.php\" class=\"footer\">index</a></td>";
	echo "\n    </tr>";
	echo "\n</table>";
	bco_html_footer();
	exit;
}

// How many rows do we have?
$number_of_results = pg_num_rows($result);

// Name our links with a number on the expand row so the page goes right to where we expand.
$j = "0";

// Start the output crap in this loop
while (($row = pg_fetch_assoc($result)) && ($count++ < $number_of_results)) {
    $id             = $row['id'];
    $createdby      = $row['createdby'];
    $subject        = ereg_replace("&", "&amp;", strip_tags(trim($row['subject'])));
    $lastpost_date  = date("h:i A m-d-y", $row['lastpost_date']);
    //$lastpost_date = $row['lastpost_date'];
    $replies        = $row['replies'];
    $views          = $row['views'];
    $sticky         = $row['sticky'];
    $username       = $row['username'];
/*
    if ($createdby == $user_array['myuserid']) {
        $row_class = " class=\"mypost\"";
        $link_class = "mypost";
    } elseif ($count%2 == 0) {
        $row_class   = " class=\"tr2\"";
        $link_class = "tr2";
    } else {
        $row_class   = " class=\"tr1\"";
        $link_class = "tr1";
    }
*/
	$row_class = " class=\"tr1\"";
	$link_class = "tr1";
    // We want to bold "sticky" topics.
    if ($sticky == 1) {
        $subject = "<strong>Sticky:</strong> $subject";
    }

	echo "\n    <tr>";
	echo "\n        <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>";
	echo "<a name=\"$j\"></a><a href=\"view_profile.php?id=$createdby\" class=\"$link_class\">$username</a></td>";
	echo "\n        <td align=\"left\" valign=\"top\"$row_class>";
	if ((isset($_GET['expand'])) && ($_GET['expand'] == $id)) {
		echo "<a href=\"view_post_history.php?id=$_GET[id]\" class=\"$link_class\">[contract]</a>";
	} else {
		echo "<a href=\"view_post_history.php?id=$_GET[id]&amp;expand=$id#$j\" class=\"$link_class\">[expand]</a>";
	}
	echo "</td>";
	echo "\n        <td align=\"left\" valign=\"top\" width=\"60%\"$row_class>";
	echo "<a href=\"view_topic.php?id=$id&amp;r=$replies\" class=\"$link_class\">$subject</a>";
	if ((isset($_GET['expand'])) && ($_GET['expand'] == $id)) {
		// prepend anything in this loop with r_ so we don't cancel the real vars out.
		$r_query = "select id, msgbody from messages where id_subject=$id and createdby=$_GET[id] order by postdate asc";
		
		if (!$r_result = pg_query($r_query)) {
			bco_error("Reply fail.");
		}
		
		$i = 0;	
		// Clean the html up and dump it into an multi-dimensional array.
		while ($r_row = pg_fetch_array($r_result)) {
			$r_array[$i]['msgbody'] = substr(strip_tags(html_entity_decode($r_row['msgbody'])), 0, 75);
			$r_array[$i]['id'] = $r_row['id'];
			$i++;
		}

		// How many replies do we have?
		$r_array_total = count($r_array);
	
		echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"replytbl\">";
		echo "<tr><td align=\"left\" valign=\"top\" colspan=\"2\"$row_class>$r_array_total replies.</td></tr>";
	
		for ($x = 0; $x < $r_array_total; $x++) {
			$post_id = $r_array[$x]['id'];
			$msgbody = $r_array[$x]['msgbody'];
			// I wanted output similar to `ps f` so we calcuate where in the array we're located
			// and if it's equal to the total amount of replies minus one.. echo a \ instead of a |
			if ($x == $r_array_total - 1) {
				$tree_char = '\\';
			} else {
				$tree_char = '|';
			}

			if ($x%2 == 0) {
     			$r_row_class   = " class=\"tr1\"";
        		$r_link_class = "tr1";
    		} else {
        		$r_row_class   = " class=\"tr2\"";
        		$r_link_class = "tr2";
    		}

			echo "<tr>";
			echo "<td width=\"10\" align=\"left\" valign=\"top\"$r_row_class><span class=\"mono\">$tree_char</span></td>";
			echo "<td align=\"left\" valign=\"top\"$r_row_class><a href=\"view_topic.php?id=$id#$post_id\" class=\"$r_link_class\">$msgbody</a></td></tr>";
		}

		echo "</table>";
	}
	echo "</td>";
	echo "\n        <td align=\"left\" valign=\"top\" nowrap=\"nowrap\"$row_class>";
	echo "$lastpost_date</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>\n";
	$j++;
}

echo "</table>$page_numbers";

bco_html_footer();

?>
Return current item: top serious project