<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.3 www.bcoos.net 2006-08 GPL
//v1.2 www.exoops.info 2006/03 GPL
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
// Based on:								     //
// myPHPNUKE Web Portal System - http://myphpnuke.com/	  		     //
// PHP-NUKE Web Portal System - http://phpnuke.org/	  		     //
// Thatware - http://thatware.org/					     //
// Modified for EXOOPS by MAALBAK //
// ------------------------------------------------------------------------- //
//  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");
$cid = $_GET['cid'];
$bcoosConfig['title'] = _MI_MYALBUM_NAME." - ".$mytree->getCategoryName($cid);
include(XOOPS_ROOT_PATH."/header.php");
OpenTable();
echo "<b>"._MI_MYALBUM_NAME."</b>";
if ($_GET['show']!="") {
	$show = $_GET['show'];
} else {
	$show = $mylinks_perpage;
}
if (!isset($_GET['min'])) {
	$min = 0;
} else {
	$min = $_GET['min'];
}
if (!isset($max)) {
	$max = $min + $show;
}
if(isset($_GET['orderby'])) {
	$orderby = convertorderbyin($_GET['orderby']);
} else {
	$orderby = "date ASC";
}
echo "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td align='center'>\n";
echo "<table width='100%' cellspacing='1' cellpadding='2' border='0' class='bg3'><tr><td>\n";
$pathstring = "<a href='index.php'>"._MODIFYCATEGORY."</a>&nbsp;:&nbsp;";
$nicepath = $mytree->getNicePathFromId($cid, "title", "viewcat.php?");
$pathstring .= $nicepath;
echo "<b>".$pathstring."</b>";
echo "</td><td align='right'><a href='submit.php?cid=$cid'><b>"._MD_ADDPHOTO."</b></a></td></tr></table>";
// get child category objects
$arr=array();
$arr=$mytree->getFirstChild($cid, "title");
if ( count($arr) > 0 ) {
	echo "</td></tr>";
	echo "<tr><td align=\"left\"><h4>"._CATEGORIES."</h4></td></tr>\n";
	echo "<tr><td align=\"center\">";
	$scount = 0;
        echo "<table width=\"90%\"><tr>";
        foreach($arr as $ele){
		$title = $myts->makeTboxData4Show($ele['title']);
		$totallink = getTotalItems($ele['cid'], 1);
               	echo "<td align=\"left\"><b><a href='viewcat.php?cid=".$ele['cid']."'>".$title."</a></b>&nbsp;(".$totallink.")&nbsp;&nbsp;</td>";
               	$scount++;
               	if ($scount==4) {
               		echo "</tr><tr>";
                       	$scount = 0;
               	}
        }
        echo "</tr></table><br />\n";
	echo "<hr>";
}
$fullcountresult=$db->query("select count(*) from ".$db->prefix("myalbum_photos")." where cid=$cid and status>0");
list($numrows) = $db->fetchRow($fullcountresult);
if($numrows>0){
	$q = "select l.lid, l.title, l.ext, l.res_x, l.res_y, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description from ".$db->prefix("myalbum_photos")." l, ".$db->prefix("myalbum_text")." t where cid=$cid and l.lid=t.lid and status>0 order by $orderby";
	$result=$db->query($q,$show,$min);
	//if 2 or more items in result, show the sort menu
	if($numrows>1){
    		$orderbyTrans = convertorderbytrans($orderby);
    		echo "<br /><center>"._SORTBY."&nbsp;&nbsp;
              	"._TITLE." (<a href='viewcat.php?cid=$cid&orderby=titleA'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a><a href='viewcat.php?cid=$cid&orderby=titleD'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a>)
              	"._DATE." (<a href='viewcat.php?cid=$cid&orderby=dateA'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a><a href='viewcat.php?cid=$cid&orderby=dateD'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a>)
              "._RATING." (<a href='viewcat.php?cid=$cid&orderby=ratingA'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a><a href='viewcat.php?cid=$cid&orderby=ratingD'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a>)
              "._POPULARITY." (<a href='viewcat.php?cid=$cid&orderby=hitsA'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a><a href='viewcat.php?cid=$cid&orderby=hitsD'><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" border=\"0\" align=\"middle\" alt=\"\" /></a>)
              	";
    		echo "<b><br />";
		printf(_MD_CURSORTEDBY,$orderbyTrans);
		echo "</b></center><br /><br />";
	}
    	echo "<table width=\"100%\" cellspacing=0 cellpadding=10 border=0>";
    	while(list($lid, $ltitle, $ext, $res_x, $res_y, $status, $time, $hits, $rating, $votes, $comments, $description) = $db->fetchRow($result)) {
		$rating = number_format($rating, 2);
       	$ltitle = $myts->makeTboxData4Show($ltitle);
		$url = $myts->makeTboxData4Show($url);
		$url = urldecode($url);
		$email = $myts->makeTboxData4Show($email);
		$logourl = $myts->makeTboxData4Show($logourl);
//		$logourl = urldecode($logourl);
		$datetime = formatTimestamp($time);
		$description = $myts->makeTareaData4Show($description,0);
		include("include/linkformat.php");
   	}
	echo "</table>";
   	$orderby = convertorderbyout($orderby);
    	//Calculates how many pages exist.  Which page one should be on, etc...
    	$linkpages = ceil($numrows / $show);
    	if ($numrows % $show == 0) {
    		$linkpages = $linkpages-1;
        }
        //Page Numbering
    	if ($linkpages!=1 && $linkpages!=0) {
       		echo "<br /><br />";
        	$prev = $min - $show;
        	if ($prev>=0) {
        		echo "&nbsp;<a href='viewcat.php?cid=$cid&min=$prev&orderby=$orderby&show=$show'>";
               		echo "<b>&lt; "._MD_PREVIOUS." ]</b></a>&nbsp;";
        	}
        	$counter = 1;
        	$currentpage = ($max / $show);
        	while ( $counter<=$linkpages ) {
               		$mintemp = ($show * $counter) - $show;
               		if ($counter == $currentpage) {
				echo "<b>$counter</b>&nbsp;";
			} else {
				echo "<a href='viewcat.php?cid=$cid&min=$mintemp&orderby=$orderby&show=$show'>$counter</a>&nbsp;";
			}
               		$counter++;
        	}
        	if ( $numrows>$max ) {
        		echo "&nbsp;<a href='viewcat.php?cid=$cid&min=$max&orderby=$orderby&show=$show'>";
               		echo "<b>[ "._MD_NEXT." &gt;</b></a>";
        	}
    	}
}
echo "</td></tr></table>\n";
CloseTable();
include("footer.php");
?>
