<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: topten.php,v 1.1 2003/08/31 12:16:29 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once("header.php");
include_once(XOOPS_ROOT_PATH."/header.php");
$mytree = new XoopsTree($db->prefix("mylinks_cat"), "cid", "pid");
//generates top 10 charts by rating and hits for each main category
OpenTable();
mainheader();
if (isset($rate)) {
	$sort   = _RATING;
	$sortDB = "rating";
	} else {
		$sort   = _HITS;
		$sortDB = "hits";
	}
$arr    = array();
$result = $db->query("SELECT cid, title from ".$db->prefix("mylinks_cat")." WHERE pid=0");
while (list($cid, $ctitle) = $db->fetchRow($result)) {
	$boxtitle  = "<big>";
	$boxtitle .= sprintf(_TOP10, $ctitle);
	$boxtitle .= " (".$sort.")</big>";
	$thing     = "<table width='100%' border='0'><tr><td width='7%' class='bg3'><b>"._RANK."</b></td><td width='28%' class='bg3'><b>"._TITLE."</b></td><td width='40%' class='bg3'><b>"._CATEGORY."</b></td><td width='8%' class='bg3' align='center'><b>"._HITS."</b></td><td width='9%' class='bg3' align='center'><b>"._RATING."</b></td><td width='8%' class='bg3' align='right'><b>"._VOTE."</b></td></tr>";
	$query     = "SELECT lid, cid, title, hits, rating, votes FROM ".$db->prefix("mylinks_links")." where status>0 and (cid=$cid";
	// get all child cat ids for a given cat id
	$arr  = $mytree->getAllChildId($cid);
	$size = count($arr);
	for ($i=0; $i<$size; $i++) {
		$query .= " or cid=".$arr[$i]."";
	}
	$query  .= ") order by ".$sortDB." DESC";
	$result2 = $db->query($query, 10, 0);
	$rank    = 1;
	while (list($lid, $lcid, $ltitle, $hits, $rating, $votes) = $db->fetchRow($result2)) {
		$rating = number_format($rating, 2);
		if ($hit) {
			$hits = "$hits";
			} elseif ($rate) {
				$rating = "$rating";
			}
		$catpath = $mytree->getNicePathFromId($lcid, "title", "viewcat.php?");
		$catpath = substr($catpath, 0, -2);
		$catpath = str_replace(":", "&raquo;", $catpath);
		$thing  .= "<tr><td>$rank</td>";
		$thing  .= "<td><a href='singlelink.php?lid=$lid'>$ltitle</a></td>";
		$thing  .= "<td>$catpath</td>";
		$thing  .= "<td align='center'>$hits</td>";
		$thing  .= "<td align='center'>$rating</td><td align='right'>$votes</td></tr>";
		$rank++;
	}
	$thing .= "</table>";
	themecenterposts($boxtitle, $thing);
	echo "<br />";
}
CloseTable();
include_once("footer.php");
?>
