<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.3 www.bcoos.net 2006-08 GPL
//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");
$bcoosConfig['title'] .= " - "._MI_MYALBUM_NAME;
if($bcoosConfig['startpage'] == "myalbum"){
	$xoopsOption['show_rblock'] =1;
	include(XOOPS_ROOT_PATH."/header.php");
	make_cblock();
	echo "<br />";
}else{
	$xoopsOption['show_rblock'] =0;
	include(XOOPS_ROOT_PATH."/header.php");
}
$result=$db->query("SELECT cid, title, imgurl FROM ".$db->prefix("myalbum_cat")." WHERE pid = 0 ORDER BY title") or die("Error");
OpenTable();
echo "<b>"._MI_MYALBUM_NAME."</b>";
echo "<center><table border=0 cellspacing=5 cellpadding=0 width=\"90%\"><tr>";
$count = 0;
while($myrow = $db->fetchArray($result)) {
	$title = $myts->makeTboxData4Show($myrow['title']);
    	echo "<td valign=\"top\" align=\"right\">";
    	if ($myrow['imgurl'] && $myrow['imgurl'] != "http://"){
		$imgurl = $myts->makeTboxData4Edit($myrow['imgurl']);
		echo "<a href=\"".XOOPS_URL."/modules/myalbum/viewcat.php?cid=".$myrow['cid']."\"><img src=\"".$imgurl."\" height=\"50\" border=\"0\"></a>";
    	} else {
		echo "";
    	}
	$totallink = getTotalItems($myrow['cid'], 1);
    	echo "</td><td valign=\"top\" width=\"40%\"><a href=\"".XOOPS_URL."/modules/myalbum/viewcat.php?cid=".$myrow['cid']."\"><b>$title</b></a>&nbsp;($totallink)<br>";
	// get child category objects
	$arr=array();
	$arr=$mytree->getFirstChild($myrow['cid'], "title");
	$space = 0;
	$chcount = 0;
	foreach($arr as $ele){
		$chtitle=$myts->makeTboxData4Show($ele['title']);
		if ($chcount>5){
			echo "...";
			break;
		}
		if ($space>0) {
        		echo ", ";
        	}
        	echo "<a href=\"".XOOPS_URL."/modules/myalbum/viewcat.php?cid=".$ele['cid']."\">".$chtitle."</a>";
        	$space++;
		$chcount++;
	}
    	if ($count<1) {
        	echo "</td>";
    	}
    	$count++;
    	if ($count==2) {
        	echo "</td></tr><tr>";
        	$count = 0;
    	}
}
echo "</td></tr></table>";
list($numrows)=$db->fetchRow($db->query("select count(*) from ".$db->prefix("myalbum_photos")." where status>0"));
echo "<br /><br />";
printf(_MD_THEREARE,$numrows);
echo "</center>";
CloseTable();
echo "<br />";
OpenTable();
echo "<div align=\"left\"><h4>";
printf(_LATESTLISTINGS,$mylinks_newlinks);
echo "</h4><br><br>";
showNew();
echo "</div>";
CloseTable();
include(XOOPS_ROOT_PATH."/modules/myalbum/footer.php");
// Shows the Latest Listings on the front page
function showNew(){
	global $myts, $db, $bcoosConfig, $xoopsModule;
	global $mylinks_shotwidth, $mylinks_newlinks, $mylinks_useshots;
	$result = $db->query("SELECT l.lid, l.cid, 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 l.status>0 and l.lid=t.lid ORDER BY date DESC",$mylinks_newlinks,0);
	echo "<table width=\"100%\" cellspacing=0 cellpadding=10 border=0><tr><td width=\"110\" align=\"center\">";
    	while(list($lid, $cid, $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);
		$email = $myts->makeTboxData4Show($email);
		$logourl = $myts->makeTboxData4Show($logourl);
#		$logourl = urldecode($logourl);
		$datetime = formatTimestamp($time,"m");
		$description = $myts->makeTareaData4Show($description,0);
		include(XOOPS_ROOT_PATH."/modules/myalbum/include/linkformat.php");
    	}
	echo "</table>";
}
?>
