<?php
// $Id: topten.php,v 1.1 2004/07/11 10:28:23 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once("../../mainfile.php");

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_discussions($order, $title) {
global $db, $myts, $xoopsConfig, $xoopsUser;

$uid   = $xoopsUser ? $xoopsUser->uid() : 0;

include_once('../../header.php');
OpenTable();
echo "<div align='left'><h4>10 ".sprintf(_MD_NEWBB_TOP, $title)."</h4></div>";

$fsql = "
	SELECT
	f.forum_id AS fid,
	f.forum_name AS fname
	FROM ".$db->prefix("bb_forums")." f
	LEFT JOIN ".$db->prefix("bb_forum_access")." a ON a.user_id IN($uid)
	WHERE ((f.forum_type = 0) OR (a.forum_id = f.forum_id))
	GROUP BY f.forum_id
	ORDER BY f.forum_name DESC";

$fquery = $db->query($fsql);

while (list($fid, $fname) = $db->fetch_row($fquery) ) {
	$fname = $myts->makeTboxData4Show($fname);

$sql = "
	SELECT
	t.topic_poster AS userid,
	t.topic_id AS topicid,
	t.topic_title AS title,
	t.topic_time AS time,
	t.topic_views AS views,
	t.topic_replies AS replies
	FROM ".$db->prefix("bb_topics")." t
	WHERE t.forum_id = $fid
	ORDER BY t.$order DESC";

$content  .= '
	<table border="0" cellpadding="0" cellspacing="0" valign="top" width="100%" class="bg2"><tr>
	<td>
	<table width="100%" border="0" cellpadding="4" cellspacing="1"><tr>
	<td colspan="4" align="left" class="bg1"><b>'.$fname.'</b></td>
	</tr><tr>
	<td align="left"><b>'._MD_TOPIC.'</b></td>
	<td align="center"><b>'._MD_REPLIES.'</b></td>
	<td align="center"><b>'._MD_VIEWS.'</b></td>
	<td align="right"><b>'._MD_POSTER.'</b></td></tr>';

	$query = $db->query($sql, 10, 0);
	while ( list($userid, $topicid, $title, $time, $views, $replies) = $db->fetch_row($query) ) {
		$title = $myts->makeTboxData4Show($title);
		$time  = formatTimestamp($time, "m");
		if ( strlen($title) > 100 ) {
			$title = substr($title, 0, 100)."..";
		}

		$content .= '
			<tr class="bg1">
			<td align="left"><a href="'.XOOPS_URL.'/modules/newbb/viewtopic.php?topic_id='.$topicid.'&amp;forum='.$fid.'">'.$title.'</a></td>
			<td align="center" width="1%" nowrap>'.$replies.'</td>
			<td align="center" width="1%" nowrap>'.$views.'</td>
			<td align="right" width="1%" nowrap>';

		$poster = new XoopsUser($userid);
		!$poster->uname() ? $postername = $xoopsConfig['anonymous'] : $postername = $poster->uname();
		$postername = $myts->makeTboxData4Show($postername);
		if ( strlen($postername) > 30 ) {
		$postername = substr($postername, 0, 30)."..";
		}

		$content .= '<b>'.$postername.'</b><br />'.$time.'</td>';
	} // END WHILE

	$content .= '
		</tr></table></td>
		</tr><tr class="bg4">
		<td align="right">
		<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;<b>
		<a href="'.XOOPS_URL.'/modules/newbb/viewforum.php?forum='.$fid.'">'._MD_NEWBB_VSTFRM.'</a></b>
		</td></tr>
		</table>';

$content .= '<br /><br />';
} // END LIST FORUMS

echo $content;
CloseTable();
include_once('../../footer.php');
}

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
switch($HTTP_GET_VARS['op']) {

case "1":
	show_discussions("topic_views", _MD_NEWBB_MVIEWED);
	break;

case "2":
	show_discussions("topic_replies", _MD_NEWBB_MACTIVE);
	break;

default:
	show_discussions("topic_time", _MD_NEWBB_MRECENT);
	break;
}
?>
