<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.3 www.exoops.info 2006/05
//v1.2 www.exoops.info 2006/03
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
// Modified for EXOOPS by MAALBAK //
// Based on:								     //
// myPHPNUKE Web Portal System - http://myphpnuke.com/	  		     //
// PHP-NUKE Web Portal System - http://phpnuke.org/	  		     //
// Thatware - http://thatware.org/					     //
// ------------------------------------------------------------------------- //
//  This program is free software; you can 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 should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //
include("header.php");
 // MyTextSanitizer object
include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
$mytree = new XoopsTree($db->prefix("myalbum_cat"),"cid","pid");
include(XOOPS_ROOT_PATH."/header.php");
//generates top 10 charts by rating and hits for each main category
OpenTable();
echo "<b>"._MI_MYALBUM_NAME."</b>";
if(isset($rate)){
	$sort = _RATING;
	$sortDB = "rating";
}else{
	$sort = _HITS;
	$sortDB = "hits";
}
$arr=array();
$result=$db->query("select cid, title from ".$db->prefix("myalbum_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, ext, title, hits, rating, votes from ".$db->prefix("myalbum_photos")." where status>0 and (cid=$cid";
	// get all child cat ids for a given cat id
	$arr=$mytree->getAllChildId($cid);
	$size = sizeof($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,$ext,$ltitle,$hits,$rating,$votes)=$db->fetchRow($result2)){
		$rating = number_format($rating, 2);
		if($hit){
			$hits = "<span class='fg2'>$hits</span>";
		} elseif($rate) {
			$rating = "<span class='fg2'>$rating</span>";
		}else{
		}
		$catpath = $mytree->getPathFromId($lcid, "title");
		$catpath= substr($catpath, 1);
		$catpath = str_replace("/"," <span class='fg2'>&raquo;&raquo;</span> ",$catpath);
		$thing .= "<tr><td>$rank</td>";
		$thing .= "<td><a href='photo.php?lid=$lid'><img src='".XOOPS_URL."/modules/myalbum/photos/thumbs/$lid.$ext' width='$mylinks_shotwidth' alt='$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("footer.php");
?>
