<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 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");
include_once(XOOPS_ROOT_PATH."/class/xoopscomments.php");
$mytree = new XoopsTree($db->prefix("myalbum_cat"),"cid","pid");
$lid = $_GET['lid'];
if ($lid == "") { $lid = $item_id; }
if ($item_id == "") { $item_id = $lid; }
$db->query("update ".$db->prefix("myalbum_photos")." set hits=hits+1 where lid=$lid and status>0");
$q = "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.lid=$lid and l.lid=t.lid and status>0";
$result=$db->query($q);
list($lid, $cid, $ltitle, $ext, $res_x, $res_y, $status, $time, $hits, $rating, $votes, $comments, $description)=$db->fetchRow($result);
$bcoosConfig['title'] = _MI_MYALBUM_NAME." - ".$ltitle ;
include(XOOPS_ROOT_PATH."/header.php");
OpenTable();
//mainheader();
echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\"><tr><td align=\"center\">\n";
echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\" bgcolor=\"cccccc\"><tr><td width=60%>\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>";
// category navigation
$fullcountresult=$db->query("select lid from ".$db->prefix("myalbum_photos")." where cid=$cid and status>0");
while (list($id) = $db->fetchRow($fullcountresult)) {
	$ids[] = $id;
}
if ($ids[0] != $lid) {
	$prev = array_search($lid,$ids)-1;
	print "<a href='photo.php?lid=".$ids[0]."'><b>|&lt; </b></a>&nbsp;&nbsp;";
	print "<a href='photo.php?lid=".$ids[$prev]."'><b>"._MD_PREVIOUS."</b></a>&nbsp;&nbsp;";
}
$nwin = 4;
if (count($ids) > $nwin) { // window
	$pos = array_search($lid,$ids);
	if ($pos > $nwin/2) {
		if ($pos > round(count($ids) - ($nwin/2)-1) ) {
			$start = count($ids) - $nwin + 1;
		} else {
			$start = round($pos - ($nwin/2))+1;
		}
	} else {
		$start = 1;
	}
}
for($i = $start; ($i < count($ids)+1) and ($i < $start + $nwin); $i++) {
	if ($ids[$i-1] == $lid) {
		print "$i&nbsp;&nbsp;";
	} else {
		print "<a href='photo.php?lid=".$ids[$i-1]."'>$i</a>&nbsp;&nbsp;";
	}
}
if ($ids[count($ids)-1] != $lid) {
	$next = array_search($lid,$ids)+1;
	print "<a href='photo.php?lid=".$ids[$next]."'><b>"._MD_NEXT."</b></a>&nbsp;&nbsp;";
	print "<a href='photo.php?lid=".$ids[count($ids)-1]."'><b> &gt;|</b></a>";
}
echo "</td><td align='right'><a href='submit.php?cid=$cid'><b>"._MD_ADDPHOTO."</b></a></td></tr></table><br><div align=\"center\">";
echo "</div><table width=\"100%\" cellspacing=0 cellpadding=10 border=0>";
$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,"m");
$description = $myts->makeTareaData4Show($description,0);
$big = 1;
include("include/linkformat.php");
echo "</table>";
echo "</td></tr></table>\n";
// comments
//include(XOOPS_ROOT_PATH."/header.php");
// set comment mode if not set
if ( !isset($mode) || $mode == "" || ($mode != "nocomments" && $mode != "thread" && $mode != "flat") ) {
	if ( $xoopsUser ) {
		$mode = $xoopsUser->getVar("umode");
	} else {
		$mode = $bcoosConfig['com_mode'];
	}
}
// set comment order if not set
if ( !isset($order) ) {
	if ( $xoopsUser ) {
		$order = $xoopsUser->getVar("uorder");
	} else {
		$order = $bcoosConfig['com_order'];
	}
}
if ( !empty($comment_id) ){
	$photocomment = new XoopsComments($db->prefix("myalbum_comments"),$comment_id);
} else {
	$photocomment = new XoopsComments($db->prefix("myalbum_comments"));
}
$orderby = ($order == 1) ? "date DESC" : "date ASC";
if ( $mode == "flat" ) {
	$criteria = array("item_id=".$lid."");
	$commentsArray = $photocomment->getAllComments($criteria, true, $orderby);
} elseif ( $mode == "thread" ) {
	$criteria = array("item_id=".$lid."", "pid=".$photocomment->getVar("pid")."");
	$commentsArray = $photocomment->getAllComments($criteria, true, $orderby);
} else {
	$commentsArray = "";
}
OpenTable();
$photocomment->printNavBar($item_id, $mode, $order);
// Now, show comments
if ( is_array($commentsArray) && count($commentsArray) ) {
	if ( $xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid()) ){
		$adminview = 1;
	} else {
		$adminview = 0;
	}
	if ( $mode == "flat" ) {
		$photocomment->showThreadHead();
		$count = 0;
		foreach ( $commentsArray as $ele ) {
			if ( !($count % 2) ) {
				$color_num = 1;
			} else {
				$color_num = 2;
			}
			$ele->showThreadPost($order, $mode, $adminview, $color_num);
			$count++;
		}
		$photocomment->showThreadFoot();
	}
	if ( $mode == "thread" ) {
		foreach ( $commentsArray as $ele ) {
			$ele->showThreadHead();
			$ele->showThreadPost($order, $mode, $adminview);
			$ele->showThreadFoot();
			//show thread tree
			//if not in the top page, show links to parent and top comment
			if ( $ele->getVar("pid") != 0 ) {
				echo "<div style='text-align:left'>";
				echo "&nbsp;<a href='".$PHP_SELF."?item_id=".$ele->getVar("item_id")."&amp;mode=".$mode."&amp;order=".$order."'>"._TOP."</a>&nbsp;|&nbsp;";
				echo "<a href='".$PHP_SELF."?item_id=".$ele->getVar("item_id")."&amp;comment_id=".$ele->getVar("pid")."&amp;mode=".$mode."&amp;order=".$order."#".$ele->getVar("pid")."'>"._PARENT."</a>";
				echo "</div>";
			}
			echo "<br />";
			$treeArray = $ele->getCommentTree();
			if ( count($treeArray) >0 ) {
				$ele->showTreeHead();
				$count = 0;
				foreach ( $treeArray as $treeItem ) {
					if ( !($count % 2) ) {
						$color_num = 1;
					} else {
						$color_num = 2;
					}
					$treeItem->showTreeItem($order, $mode, $color_num);
					$count++;
				}
				$ele->showTreeFoot();
			}
		}
		echo "<br />";
	}
}
CloseTable();
CloseTable();
include("footer.php");
?>
