Location: PHPKode > projects > ACollab > forums/view.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2004  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may 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.                                               */
/*                                                                                      */
/* This program is distributed in the hope that it will be useful, but                  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of                           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
/* See the GNU General Public License for more details.                                 */
/*                                                                                      */
/* You may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: view.php 426 2005-03-07 14:28:06Z shozubq $

define('AC_INCLUDE_PATH', '../include/');

require(AC_INCLUDE_PATH.'vitals.inc.php');
require(AC_INCLUDE_PATH.'lib/forum_codes.inc.php');
authenticate(USER_CLIENT, USER_GROUP_ADMIN, USER_ADMIN);

$fid = intval($_REQUEST['fid']);
$pid = intval($_REQUEST['pid']);

function print_entry($row) {
	global $page;
	global $_template;
	global $forum_info;

	static $counter;
	$counter++;

	echo '<tr>';
	echo '<td class="row'.(($counter-1)%2).' author" rowspan="2" valign="top" width="15%"><small><a href="profile.php?id='.$row['member_id'].'"><b>'.$row['login'].'</b></a></small>';
	
	if (authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {
		echo '<br /><small><small>[ <a href="forums/edit_post.php?fid='.$row['forum_id'].SEP.'pid='.$row['post_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('edit').'</a> | <a href="forums/delete_post.php?fid='.$row['forum_id'].SEP.'pid='.$row['post_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('delete').'</a> ]</small></small>';
	}

	echo '</td>';

	echo '<td class="row'.(($counter-1)%2).' box"><a name="'.$row['post_id'].'"></a>'._AC('subject').': '.$row['subject'].'</td><td align="right" class="row'.(($counter-1)%2).' box">';

	if (authenticate_forum($forum_info['regular_rights'], FORUM_REPLY)) {
		echo '<a href="forums/view.php?fid='.$row['forum_id'].SEP.'pid=';
		if ($row['parent_id'] == 0) {
			echo $row['post_id'];
		} else {
			echo $row['parent_id'];
		}
		echo SEP.'reply='.$row['post_id'].SEP.'page='.$page.'#post"><img src="images/quote.gif" border="0" width="16" height="15" class="img" alt="'._AC('quote_post').'" /></a>';
	} else {
		echo '&nbsp;';	
	}
	echo '</td></tr>';
	echo '<tr><td class="row'.(($counter-1)%2).'" colspan="2">'.format_final_output(' '.$row['body'].' ');
	echo '<div align="right"><small><small class="bigspacer">'._AC('posted').': ';
	echo AT_date(_AC('forum_date_format'), $row['date'], AT_DATE_MYSQL_DATETIME);
	echo '</small></small></div>';
	echo '</td></tr>';
	echo '<tr><td colspan="3" class="bar"><img src="images/clr.gif" height="2" width="2" alt="" /></td></tr>';
}

if ($_REQUEST['reply']) {
	$onload = 'onload="document.form.subject.focus()"';
}

/* get the first thread first */
$sql	= "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE post_id=$pid AND forum_id=$fid";
$result	= mysql_query($sql, $db);

$forum_info = get_forum_info($fid);
$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('forums');
$_SECTION[1][1] = 'forums/';
$_SECTION[2][0] = _AC('forum').': '.$forum_info['title'];
$_SECTION[2][1] = 'forums/forum.php?fid='.$fid;

if (!($first_row = mysql_fetch_array($result))) {
	$_SECTION[3][0] = _AC('thread_not_found');
	$_SECTION[3][1] = 'forums/';

	require(AC_INCLUDE_PATH.'header.inc.php');
	echo _AC('thread_not_found');
	require(AC_INCLUDE_PATH.'footer.inc.php');
	exit;
}

$_SECTION[3][0] = $first_row['subject'];
$_SECTION[3][1] = 'forums/';

require(AC_INCLUDE_PATH.'header.inc.php');

if (!authenticate_forum($forum_info['regular_rights'], FORUM_VIEW)) {
	echo '<p align="center">'._AC('cannot_view_forum').'</p>';
	require(AC_INCLUDE_PATH.'footer.inc.php');
	exit;
}

if ($_GET['f']) {
	print_feedback($_GET['f']);
}

/*
$sql = "INSERT INTO forums_accessed VALUES ($pid, $_SESSION[member_id], NOW())";
$result = mysql_query($sql, $db);
if (!$result) {
	$sql = "UPDATE forums_accessed SET last_accessed=NOW() WHERE post_id=$pid AND member_id=$_SESSION[member_id]";
	$result = mysql_query($sql, $db);
}
*/

$num_per_page = 10;
if (!$_GET['page']) {
	$page = 1;
} else {
	$page = intval($_GET['page']);
}
$start = ($page-1)*$num_per_page;
	

	$num_threads = $first_row['num_comments']+1;
	$num_pages = ceil($num_threads/$num_per_page);
	$locked = $first_row['locked'];
	if ($locked == 1) {
		echo '<p><b>'.$_template['lock_no_read1'].'</b></p>';
		require(AC_INCLUDE_PATH.'footer.inc.php');
		exit;
	}

	$parent_name = $first_row['subject'];

	if (!authenticate_forum($forum_info['regular_rights'], FORUM_REPLY)) {
		echo '<p align="center">'._AC('cannot_reply_forum').'</p>';
	} else {
		echo '<p align="center"><a href="forums/view.php?fid='.$fid.SEP.'pid='.$pid.'#post" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('reply_to_thread').'</a></p>';
	}

	echo '<table border="0" cellspacing="0" cellpadding="2" width="90%" align="center" class="box2" summary="">';
	echo '<tr>';
	echo '<th class="box">'._AC('author').'</th><th class="box" colspan="2">'._AC('subject').'</th>';
	echo '</tr>';
	echo '<tr>';
	echo '<td class="row1" align="right" colspan="3"><small><b>'._AC('page').': ';
	$page_links = '';
	for ($i = 1; $i <= $num_pages; $i++) {
		if ($i == $page) {
			$page_links .= $i;
		} else {
			$page_links .= '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'pid='.$pid.SEP.'page='.$i.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$i.'</a>';
		}

		if ($i<$num_pages){
			$page_links .= ' <span class="spacer">|</span> ';
		}
	}
	echo $page_links;
	echo '</b></small></td>';
	echo '</tr>';
	
	if ($page == 1) {
		print_entry($first_row);
		$subject   = $first_row['subject'];
		if ($_GET['reply'] == $first_row['post_id']) {
			$saved_post = $first_row;
		}
		$num_per_page--;
	} else {
		$start--;
	}

	$sql	= "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=$pid AND forum_id=$fid ORDER BY date ASC LIMIT $start, $num_per_page";
	$result	= mysql_query($sql, $db);

	while ($row = mysql_fetch_array($result)) {
		print_entry($row);
		$subject   = $row['subject'];
		if ($_GET['reply'] == $row['post_id']) {
			$saved_post = $row;
		}
	}
	echo '<tr>';
	echo '<td class="row1" align="left" colspan="2"><small><b>';
	if (strpos($first_row['subscribers'], $_SESSION['member_id'].',') === false) {
		echo '<a href="forums/thread_subscribe.php?fid='.$fid.SEP.'pid='.$pid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('subscribe').'</a> - '._AC('subscribe_blurb').'';
	} else {
		echo '<a href="forums/thread_subscribe.php?fid='.$fid.SEP.'pid='.$pid.SEP.'us=1" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('unsubscribe').'</a> - '._AC('unsubscribe_blurb');
	}
	
	echo '</b></small></td>';
	echo '<td class="row1" align="right"><small><b>'._AC('page').': '.$page_links.'</b></small></td>';
	echo '</tr>';
	echo '</table>';

	$parent_id = $pid;
	$body	   = '';

	if (!$locked) {
		echo '<br />';
		require('include/new_thread.inc.php');
	} else {
		echo '<br /><p><small>'._AC('lock_no_post').'</small></p>';
	}

require(AC_INCLUDE_PATH.'footer.inc.php');
?>
Return current item: ACollab