<?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 
// $Id: article.php,v 1.1 2003/08/31 12:16:29 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once("./header.php");
include_once(XOOPS_ROOT_PATH . "/class/xoopscomments.php");
//include_once("./class/class.newsstory.php");
include_once("./cache/config.php");
$item_id = (!empty($item_id)) ? intval($item_id) : 0;
$lid = $item_id;
//$lid = (!empty($lid)) ? intval($lid) : 0;
if ( empty($item_id) ) {
	redirect_header("index.php", 2, _NW_NOSTORY);
	exit();
}
// set comment mode if not set
$mode = $_GET['mode'];
if ( ($mode != "0") && ($mode != "thread") && ($mode != "flat") ) {
	if ($xoopsUser) {
		$mode = $xoopsUser->getVar("umode");
		} else {
			$mode = $bcoosConfig['com_mode'];
		}
}
// set comment order if not set
$order = $_GET['order'];
if ( ($order != "0") && ($order != "1") ) {
	if ( $xoopsUser ) {
		$order = $xoopsUser->getVar("uorder");
		} else {
			$order = $bcoosConfig['com_order'];
		}
}
$mytree = new XoopsTree($db->prefix("mylinks_cat"), "cid", "pid");
$result = $db->query("SELECT cid, title, imgurl FROM ".$db->prefix("mylinks_cat")." WHERE pid=0 ORDER BY title") or die("Error");
if ( !empty($comment_id) ) {
	$artcomment = new XoopsComments($db->prefix("mylinks_comments"), $comment_id);
	} else {
		$artcomment = new XoopsComments($db->prefix("mylinks_comments"));
	}
$item_id = $lid;
$artcomment->setVar("item_id", $item_id);
	$sql = "SELECT lid, cid, title,	url, email, logourl, status, date, hits, rating, votes,	comments, description
	FROM ".$db->prefix("mylinks_links")." WHERE lid=".$lid."";
	$result = $db->query($sql);
	list($lid, $cid, $ltitle, $url, $email, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $db->fetchRow($result);
	$bcoosConfig['title'] .= " - ".$ltitle;
	include_once(XOOPS_ROOT_PATH."/header.php");
	$rating      = number_format($rating, 2);
	$ltitle      = $myts->makeTboxData4Show($ltitle);
	$url         = $myts->makeTboxData4Show($url);
	$email       = $myts->makeTboxData4Show($email);
	$logourl     = $myts->makeTboxData4Show($logourl);
	$datetime    = formatTimestamp($time, "s");
	$description = $myts->makeTareaData4Show($description, 1, 1, 1);
	include("include/linkformat.php");
	
$orderby = ($order == 1) ? "date DESC" : "date ASC";
if ( $mode == "flat" ) {
	$criteria = array("item_id=".$item_id."");
	$commentsArray = $artcomment->getAllComments($criteria, true, $orderby);
	} elseif ( $mode=="thread" ) {
		$criteria = array("item_id=".$item_id."", "pid=".$artcomment->getVar("pid")."");
		$commentsArray = $artcomment->getAllComments($criteria, true, $orderby);
		} else {
			$commentsArray = "";
		}
include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
// print navbar
$artcomment->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" ) {
		$count = 0;
		foreach($commentsArray as $ele) {
			if ( !($count % 2) ) {
				$color_num = 1;
				} else {
					$color_num = 2;
				}
			$ele->showThreadPost($order, $mode, $adminview, $color_num);
			$count++;
		}
	}
	if ( $mode=="thread" ) {
		foreach($commentsArray as $ele) {
			$ele->showThreadPost($order, $mode, $adminview);
			//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 "<a href='./link.php?item_id=".$ele->getVar("item_id")."&amp;mode=".$mode."&amp;order=".$order."'>"._TOP."</a> | ";
				echo "<a href='./link.php?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();
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
