<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.3 www.exoops.info 2006/03 
// $Id: topten.php,v 1.2 2004/03/20 18:35:12 greyhead 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
// ------------------------------------------------------------------------- //
// Passed on      : My Downloads
// New module name: My Sections
// Version        : 1.1
// Modified by    : Faisal
// Website        : < http://www.a-xoops.com >
// Email          : info@a-xoops.com
// ------------------------------------------------------------------------- //
include_once("header.php");
include_once(XOOPS_ROOT_PATH."/header.php");
$mytree = new XoopsTree($db->prefix("mysections_cat"), "cid", "pid");
//generates top 10 charts by rating and counter for each main category
OpenTable();
echo "<b>"._MI_MYSECTIONS_NAME."</b>";
if ($rate) {
        $sort   = _RATING;
        $sortDB = "rating";
        } else {
                $sort   = _MD_COUNTER;
                $sortDB = "counter";
        }
$arr    = array();
$result = $db->query("SELECT cid, title FROM ".$db->prefix("mysections_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' cellspacing='0' cellpadding='5' class='bg3'><tr class='bg2'><td width='7%'><b>"._RANK."</b></td><td width='28%'><b>"._TITLE."</b></td><td width='40%'><b>"._CATEGORY."</b></td><td width='8%' align='center'><b>"._MD_COUNTER."</b></td><td width='9%' align='center'><b>"._RATING."</b></td><td width='8%' align='right'><b>"._VOTE."</b></td></tr>";
        $query     = "SELECT lid, cid, title, titletip, counter, rating, votes FROM ".$db->prefix("mysections_articles")." 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($did, $dcid, $dtitle, $titletip, $counter, $rating, $votes) = $db->fetchRow($result2)) {
                $rating = number_format($rating, 2);
                if ($count) {
                        $counter = "$counter";
                        } elseif ($rate) {
                                $rating = "$rating";
                                }
                $catpath = $mytree->getNicePathFromId($dcid, "title", "viewcat.php?");
                $catpath = substr($catpath, 0, -2);
                $catpath = str_replace(":", "&raquo;", $catpath);
                $thing  .= "<tr><td align='center'>$rank</td>";
                $thing  .= "<td nowrap><a href='singlefile.php?lid=$did' title='$titletip'>$dtitle</a></td>";
                $thing  .= "<td>$catpath</td>";
                $thing  .= "<td align='center'>$counter</td>";
                $thing  .= "<td align='center'>$rating</td><td align='center'>$votes</td></tr>";
                $rank++;
        }
        $thing .= "</table>";
        themecenterposts($boxtitle, $thing);
        echo "<br />";
}
CloseTable();
include_once("footer.php");
?>