Location: PHPKode > projects > ACollab > forums/forum.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: forum.php 426 2005-03-07 14:28:06Z shozubq $

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

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

$fid = intval($_GET['fid']);

if ($fid == 0) {
	Header('Location: index.php');
	exit;
}

$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/';

require(AC_INCLUDE_PATH.'header.inc.php');
if (authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {
	print_popup_help('help_admin_forum_options');
}
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 (authenticate_forum($forum_info['regular_rights'], FORUM_START)) {
	echo '<p align="center"><a href="forums/new_thread.php?fid='.$fid.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'._AC('start_thread').'</a></p>';
} else {
	echo '<p align="center">'._AC('cannot_start_thread').'</p>';
}


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

if ($_GET['col']) {
	$col = addslashes($_GET['col']);
} else {
	$col = 'last_comment';
	$_GET['order'] = 'desc';
}
if ($_GET['order']) {
	$order = addslashes($_GET['order']);
} else {
	$order = 'asc';
}
${'highlight_'.$col} = ' u';

$sql	= "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id=$fid";
$result	= mysql_query($sql, $db);
$num_threads = mysql_fetch_array($result);
$num_threads = $num_threads['cnt'];

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

$sql	= "SELECT * FROM ".TABLE_PREFIX."forums_threads WHERE parent_id=0 AND forum_id=$fid ORDER BY sticky DESC,  $col $order LIMIT $start,$num_per_page";
$result	= mysql_query($sql, $db);

if ($row = mysql_fetch_array($result)) {
	echo '<table cellspacing="0" cellpadding="2" border="0" bgcolor="white" width="99%" align="center" summary="" class="box2">';
	echo '<tr>';
	echo '<th scope="col" class="box" align="left"><small><a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=subject'.SEP.'order=asc" class="nav';
	echo $highlight_subject.'" title="'._AC('topic_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_subject.'\'">'._AC('topic').'</a> ';
		if (($col == 'subject') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=subject'.SEP.'order=desc"><img src="images/desc.gif" height="7" width="11" alt="'._AC('topic_desc').'" border="0" class="img4" /></a>';
		} else if (($col == 'subject') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=subject'.SEP.'order=asc"><img src="images/asc.gif" height="7" width="11" alt="'._AC('topic_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	echo '<th scope="col" class="box" align="left" nowrap="nowrap"><small><a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=num_comments'.SEP.'order=asc" class="nav';
	echo $highlight_num_comments.'" title="'._AC('replies_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_num_comments.'\'">'._AC('replies').'</a> ';
		if (($col == 'num_comments') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=num_comments'.SEP.'order=desc"><img src="images/desc.gif" height="7" width="11" alt="'._AC('replies_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'num_comments') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=num_comments'.SEP.'order=asc"><img src="images/asc.gif" height="7" width="11" alt="'._AC('replies_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	echo '<th scope="col" class="box" align="left" nowrap="nowrap"><small><a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=login'.SEP.'order=asc" class="nav';
	echo $highlight_login.'" title="'._AC('start_by_asc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_login.'\'">'._AC('started_by').'</a> ';
		if (($col == 'login') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=login'.SEP.'order=desc"><img src="images/desc.gif" height="7" width="11" alt="'._AC('started_by_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'login') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=login'.SEP.'order=asc"><img src="images/asc.gif" height="7" width="11" alt="'._AC('started_by_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	echo '<th scope="col" class="box" align="left" nowrap="nowrap"><small><a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=last_comment'.SEP.'order=desc" class="nav';
	echo $highlight_last_comment.'" title="'._AC('last_post_desc').'" onfocus="this.className=\'highlight\'" onblur="this.className=\'nav'.$highlight_last_comment.'\'">'._AC('last_post').'</a> ';
		if (($col == 'last_comment') && ($order == 'asc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=last_comment'.SEP.'order=desc"><img src="images/desc.gif" height="7" width="11" alt="'._AC('last_post_desc').'" border="0"  class="img4" /></a>';
		} else if (($col == 'last_comment') && ($order == 'desc')) {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'col=last_comment'.SEP.'order=asc"><img src="images/asc.gif" height="7" width="11" alt="'._AC('last_post_asc').'" border="0"  class="img4" /></a>';
		} else {
			echo '<img src="images/clr.gif" height="7" width="11" alt="" />';
		}
	echo '</small></th>';

	$colspan = 4;
	if (authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {
		echo '<th class="box">&nbsp;</th>';
		$colspan++;
	}
	echo '</tr>';
	echo '<tr>';
	echo '<td class="row1" colspan="'.$colspan.'" align="right"><small><b>'._AC('page').': ';

	for ($i=1; $i<=$num_pages; $i++) {
		if ($i == $page) {
			echo $i;
		} else {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'page='.$i.SEP.'col='.$col.SEP.'order='.$order.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$i.'</a>';
		}

		if ($i<$num_pages){
			echo ' <span class="spacer">|</span> ';
		}
	}
	
	echo '</b></small></td>';
	echo '</tr>';

	$current_thread = $row['thread_id'];
	do {
		$counter++;
		/* crop the subject, if needed */
		if (strlen($row['subject']) > 28) {
			$row['subject'] = substr($row['subject'], 0, 25).'...';
		}
		echo '<tr>';
		echo '<td class="row'.(($counter-1)%2).'" width="60%"><small>';
	
		if ($row['num_comments'] > 10) {
			echo '<i style="color: red; font-weight: bold; font-size: .7em;" title="'.$_template['hot_thread'].'">'._AC('hot').'</i> ';
		}

		if ($row['locked'] != 0) {
			echo '<img src="images/topic_lock.gif" alt="'.$_template['thread_locked'].'" class="img7" title="'._AC('thread_locked').'"/> ';
		}
		
		if ($row['sticky'] != 0) {
			echo '<img src="images/forum/topic_stick.gif" alt="'.$_template['sticky_thread'].'" class="img7"  title="'._AC('sticky_thread').'"/> ';
		}
		
		if ($row['locked'] != 1) {
			echo '<a href="forums/view.php?fid='.$fid.SEP.'pid='.$row['post_id'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$row['subject'].'</a>';

			if ($row['locked'] == 2) {
				echo ' <i class="spacer">('._AC('post_lock').')</i>';
			}
		} else {
			echo $row['subject'].' <i class="spacer">('._AC('read_lock').')</i>';
		}

		/* print page numbers */
		$num_pages_2 = ceil(($row['num_comments']+1)/$num_per_page);

		if ($num_pages_2 > 1) {
			echo ' ( Page: ';
			for ($i=2; $i<=$num_pages_2; $i++) {
				echo '<a href="forums/view.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'page='.$i.SEP.'col='.$col.SEP.'order='.$order.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$i.'</a>';

				if ($i<$num_pages_2){
					echo ' | ';
				}
			}
			echo ' )';
		}

		if (strpos($row['subscribers'], $_SESSION['member_id'].',') !== false) {
			echo  ' <br /><small><a href="forums/thread_subscribe.php?us=1'.SEP.'pid='.$row['post_id'].SEP.'fid='.$fid.SEP.'t=1">('._AC('unsubscribe').')</a></small>';
		} else {
			echo  ' <br /><small><a href="forums/thread_subscribe.php?pid='.$row['post_id'].SEP.'fid='.$fid.SEP.'t=1">('._AC('subscribe').')</a></small>';
		}
		
		echo '</small></td>';

		echo '<td class="row'.(($counter-1)%2).'" width="10%" align="center"><small>'.$row['num_comments'].'</small></td>';

		echo '<td class="row'.(($counter-1)%2).'" width="10%"><small><a href="profile.php?id='.$row['member_id'].'">'.$row['login'].'</a></small></td>';

		echo '<td class="row'.(($counter-1)%2).'" width="20%" align="right" nowrap="nowrap"><small>';

		echo AT_date(_AC('forum_date_format'), $row['last_comment'], AT_DATE_MYSQL_DATETIME);
		echo '</small></td>';

		if (authenticate(USER_GROUP_ADMIN, USER_RETURN_CHECK)) {
			echo '<td class="row'.(($counter-1)%2).'" nowrap="nowrap">';
			echo ' <a href="forums/stick.php?fid='.$fid.SEP.'pid='.$row['post_id'].'"><img src="images/forum/sticky.gif" border="0" alt="'._AC('sticky_thread').'" title="'._AC('sticky_thread').'"  class="img6" /></a> ';
			
			if ($row['locked'] != 0) {
				echo '<a href="forums/lock_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].SEP.'unlock='.$row['locked'].'"><img src="images/unlock.gif" border="0" alt="'._AC('unlock_thread').'"  title="'._AC('unlock_thread').'" class="img6" /></a>';
			} else {
				echo '<a href="forums/lock_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].'"><img src="images/forum/lock.gif" border="0" alt="'._AC('lock_thread').'"  title="'._AC('lock_thread').'" class="img6" /></a>';
			}
			echo ' <a href="forums/delete_thread.php?fid='.$fid.SEP.'pid='.$row['post_id'].'"><img src="images/forum/icon_delete.gif" border="0" alt="'._AC('delete_thread').'"  title="'._AC('delete_thread').'" class="img6" /></a>';
			
			echo '</td>';
		}
		echo '</tr>';
	} while ($row = mysql_fetch_array($result));

	echo '<tr>';
	echo '<td class="row1" colspan="'.$colspan.'" align="right"><small><b>'._AC('page').': ';

	for ($i=1; $i<=$num_pages; $i++) {
		if ($i == $page) {
			echo $i;
		} else {
			echo '<a href="'.$_SERVER['PHP_SELF'].'?fid='.$fid.SEP.'page='.$i.'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$i.'</a>';
		}

		if ($i<$num_pages){
			echo ' <span class="spacer">|</span> ';
		}
	}
	
	echo '</b></small></td>';
	echo '</tr>';
	echo '</table>';

	echo '<p><small>'._AC('use_col_headings').'</small></p>';

} else {
	echo '<p>'._AC('no_threads_found').'</p>';
}

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