<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.8 www.bcoos.net 2006-08 GPL
//v1.7 www.exoops.info 2006/03 
// $Id: index.php,v 1.6 2003/02/28 06:02:59 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Based on:
// phpBB: http://www.phpBB.com
// License type: GPL
// ------------------------------------------------------------------------- //
include_once("header.php");
$bcoosConfig['title'] .= " - "._MI_NEWBB_NAME;
$myts->setType("admin");
$sql = "
	SELECT c.* FROM
	".$db->prefix("bb_categories")." c,
	".$db->prefix("bb_forums")." f
	WHERE
	f.cat_id=c.cat_id
	GROUP BY
	c.cat_id, c.cat_title, c.cat_order
	ORDER BY
	c.cat_order";
if (!$result = $db->query($sql)) {
	redirect_header("../../index.php", 2, _MD_COULDNOTQUERY);
	exit();
}
$total_categories = $db->getRowsNum($result);
if ($bcoosConfig['startpage'] == "newbb") {
	$xoopsOption['show_rblock'] = 1;
	include_once(XOOPS_ROOT_PATH."/header.php");
	make_cblock();
	echo "<br />";
	} else {
		$xoopsOption['show_rblock'] = 0;
		include_once(XOOPS_ROOT_PATH."/header.php");
	}
OpenTable();
?>
<table cellpadding="2" cellspacing="0" border="0" width="<?php echo $bbWidth?>"  align="center"><tr>
<td colspan="2">
<b><?php printf(_MD_WELCOME, $bcoosConfig['title']);?></b><br />
<?php echo _MD_TOSTART;?><hr />
</td>
</tr><tr valign="bottom">
<td><?php echo _MD_TOTALTOPICSC;?><b><?php echo get_total_topics();?></b> | <?php echo _MD_TOTALPOSTSC;?><b><?php echo get_total_posts("0", "all");?></b></td>
<td align="right">
<?php
	$currenttime = formatTimestamp(time(), "m");
	printf(_MD_TIMENOW, $currenttime);
	echo "<br />";
	$yourlastvisit = formatTimestamp($last_visit, "m");
	printf(_MD_LASTVISIT, $yourlastvisit)
;?>
</td>
</tr></table>
<table border="0" width="<?php echo $bbWidth?>" cellpadding="0" cellspacing="0" align="center" valign="top"><tr>
<td class="bg2">
<table border="0" cellpadding="4" cellspacing="1" width="100%"><tr class="bg3" align="center">
<td>&nbsp;</td>
<td nowrap="nowrap" align="left"><b><?php echo _MD_FORUM;?></b></td>
<td nowrap="nowrap"><b><?php echo _MD_TOPICS;?></b></td>
<td nowrap="nowrap"><b><?php echo _MD_POSTS;?></b></td>
<td nowrap="nowrap"><b><?php echo _MD_LASTPOST;?></b></td>
<td nowrap="nowrap"><b><?php echo _MD_MODERATOR;?></b></td>
</tr>
<?php
if ($total_categories) {
	if (!isset($viewcat) || $viewcat == "") { $viewcat = -1; } elseif (!is_int($viewcat)) { $viewcat = -1;}
	while ($cat_row = $db->fetchArray($result)) {
		$categories[] = $cat_row;
	}
	$limit_forums = "";
	if ($viewcat != -1) {
		$limit_forums = "WHERE f.cat_id = $viewcat";
	}
	$sql = "
		SELECT f.*, u.uname, u.uid, p.topic_id, p.post_time, p.subject, p.icon
		FROM ".$db->prefix("bb_forums")." f
		LEFT JOIN ".$db->prefix("bb_posts")." p
		ON p.post_id = f.forum_last_post_id
		LEFT JOIN ".$db->prefix("users")." u
		ON u.uid = p.uid $limit_forums
		ORDER BY f.cat_id, f.forum_name";
	if (!$f_res = $db->query($sql)) {
		die("Error <br />$sql");
	}
	while ($forum_data = $db->fetchArray($f_res)) {
		$forum_row[] = $forum_data;
	}
	for ($i=0; $i<$total_categories; $i++) {
		if ($viewcat != -1) {
			if ($categories[$i]['cat_id'] != $viewcat) {
				$title = $myts->makeTboxData4Show($categories[$i]['cat_title']);
				echo "
				<tr align='left' valign='top'>
				<td colspan='6' class='bg4'>
				<b><a href='./index.php?viewcat=".$categories[$i]['cat_id']."'>$title</a></b>
				</td></tr>";
				continue;
			}
		}
$title = $myts->makeTboxData4Show($categories[$i]['cat_title']);
echo "
<tr align='left' valign='top'>
<td colspan='6' class='bg4'>
<a href='./index.php?viewcat=".$categories[$i]['cat_id']."'><b>$title</b></a>
</td></tr>";
@reset($forum_row);
$size = count($forum_row);
for ($x=0; $x<$size; $x++) {
	unset($last_post);
	if ($forum_row[$x]['cat_id'] == $categories[$i]['cat_id']) {
	if ($forum_row[$x]['forum_type'] == 1) {
		if (!$xoopsUser) {
			continue;
			} elseif (!$xoopsUser->isAdmin($xoopsModule->mid()) && !check_priv_forum_auth($xoopsUser->uid(), $forum_row[$x]['forum_id'], 0)) {
				continue;
			}
	}
	if ($forum_row[$x]['post_time']) {
		$forum_row[$x]['subject'] = $myts->makeTboxData4Show($forum_row[$x]['subject']);
		
	$timenow = formatTimestamp(time(), "s");
	$timepost = formatTimestamp($forum_row[$x]['post_time'], "s");
	if ( $timenow == $timepost) { $last_post  = formatTimestamp($forum_row[$x]['post_time'], "t");
	} else { $last_post  = formatTimestamp($forum_row[$x]['post_time'], "m"); }
	echo "&nbsp;&nbsp;<br />";
		
		$last_post .= "<a href='".XOOPS_URL."/modules/newbb/viewtopic.php?post_id=".$forum_row[$x]['forum_last_post_id']."&amp;topic_id=".$forum_row[$x]['topic_id']."&amp;forum=".$forum_row[$x]['forum_id']."#".$forum_row[$x]['forum_last_post_id']."'>";
		if ($forum_row[$x]['icon']) {
			$last_post .= "<img src='".XOOPS_URL."/images/subject/".$forum_row[$x]['icon']."' border='0' alt='' />";
			} else {
				$last_post .= "<img src='".XOOPS_URL."/images/subject/icon1.gif' border='0' alt='' />";
			}
		$last_post .= "</a><br />"._MD_BY."&nbsp;";
		if ($forum_row[$x]['uid'] != 0 && $forum_row[$x]['uname']) {
			$last_post .= "<a href='".XOOPS_URL."/userinfo.php?uid=".$forum_row[$x]['uid']."'>" . $myts->makeTboxData4Show($forum_row[$x]['uname'])."</a>";
			} else {
				$last_post .= $bcoosConfig['anonymous'];
			}
	}
	$last_post_datetime = $forum_row[$x]['post_time'];
	if (empty($last_post)) {
		$last_post = _MD_NOPOSTS;
	}
	echo "<tr align='left' valign='top'>";
	if ( ( ($last_post_datetime > $last_visit) && ($last_post != _MD_NOPOSTS)  ) &&
		!isset($_COOKIE['bbtopic_time'][$forum_row[$x]['topic_id']]) ) {
		echo "<td class='bg3' align='center' valign='middle' width='5%'><img src='".$bbImage['newposts']."' alt='' /></td>";
		} else {
			echo "<td class='bg3' align='center' valign='middle' width='5%'><img src='".$bbImage['folder']."' alt='' /></td>";
		}
	$name         = $myts->makeTboxData4Show($forum_row[$x]['forum_name']);
	$total_posts  = $forum_row[$x]["forum_posts"];
	$total_topics = $forum_row[$x]["forum_topics"];
	$myts->setType('admin');
	$desc         = $myts->makeTareaData4Show($forum_row[$x]['forum_desc'], 1, 1, 1);
	$forum_link   = XOOPS_URL."/modules/newbb/viewforum.php?forum=".$forum_row[$x]["forum_id"];
	if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
		$admin_link = "<a href='admin/admin_forums.php?mode=editforum&forum=".$forum_row[$x]["forum_id"]."'><img src='".$bbImage['editicon']."' alt='"._EDIT."' border='0'></a>";
	}
	echo "
	<td class='bg1' onmouseover='this.className=\"bg3\"; this.style.cursor=\"hand\";' onmouseout='this.className=\"bg1\";' onclick='window.location.href=\"$forum_link\";'>
	$admin_link <a href='$forum_link'><b>$name</b></a>
	<br />$desc</td>
	<td class='bg3' width='5%' align='center' valign='middle'>$total_topics</td>
	<td class='bg1' width='5%' align='center' valign='middle'>$total_posts</td>
	<td class='bg3' width='15%' align='center' valign='middle' onmouseover='this.className=\"bg1\";' onmouseout='this.className=\"bg3\";'>$last_post</td>
	<td class='bg1' width='5%' align='center' valign='middle' onmouseover='this.className=\"bg3\";' onmouseout='this.className=\"bg1\";'>";
	list_moderators($forum_row[$x]['forum_id']);
	echo "</td></tr>";
			}
		}
	}
}
?>
</table></td></tr></table>
<form name="search" action="search.php" method="post">
<table align="center" border="0" width="<?php echo $bbWidth;?>"><tr>
<td valign="middle">
<img src="<?php echo $bbImage['newposts'];?>" alt="" /> = <?php echo _MD_NEWPOSTS;?>.
<br /><img src="<?php echo $bbImage['folder'];?>" alt="" /> = <?php echo _MD_NONEWPOSTS;?>.
</td>
<td align="right" valign="bottom">
<b><?php echo _SEARCH;?></b> <input type="text" class="text" name="term"  size="20">
<input type="hidden" name="forum" value="all">
<input type="hidden" name="sortby" value="p.post_time desc">
<input type="hidden" name="searchboth" value="both">
<input type="hidden" name="submit" value="<?php echo _SEARCH;?>">
<br />[ <a href="<?php echo XOOPS_URL;?>/modules/newbb/search.php"><?php echo _MD_ADVSEARCH;?></a> ]
</td>
</tr></table></form>
<?php
CloseTable();
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
