<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.8 www.exoops.info 2006/03 
// $Id: pollresults.php,v 1.7 2003/03/19 07:02:50 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
$results_page = 1;
include_once("header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopscomments.php");
include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspoll.php");
include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolloption.php");
include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolllog.php");
include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspollrenderer.php");
$item_id = (!empty($item_id)) ? intval($item_id) : 0;
$poll_id = (!empty($poll_id)) ? intval($poll_id) : 0;
if ( empty($item_id) && empty($poll_id) ) {
	redirect_header("index.php", 0);
	exit();
}
$sql = "SELECT poll_id, question FROM `".$db->prefix("xoopspoll_desc")."` WHERE poll_id=$poll_id";
$result = $db->query($sql);
list($poll_id,$poll_title) = $db->FetchRow($result);
$bcoosConfig['title'] = _MI_POLLS_NAME." : ".$poll_title;
include_once(XOOPS_ROOT_PATH."/header.php");
// set comment mode if not set
if ( !isset($mode) || $mode == "" || ($mode != 0 && $mode != "thread" && $mode != "flat") ) {
	if ( $xoopsUser ) {
		$mode = $xoopsUser->getVar("umode");
		} else {
			$mode = $bcoosConfig['com_mode'];
		}
}
if ( !empty($comment_id) ) {
	$pollcomment = new XoopsComments($db->prefix("xoopspollcomments"), $comment_id);
	} else {
		$pollcomment = new XoopsComments($db->prefix("xoopspollcomments"));
	}
$item_id = (!empty($poll_id)) ? $poll_id : $item_id;
$pollcomment->setVar("item_id", $item_id);
$parentid = $pollcomment->getVar("pid");
if ( empty($parentid) ) {
	OpenTable();
	$poll     = new XoopsPoll($item_id);
	$renderer = new XoopsPollRenderer($poll);
	echo $renderer->renderResults();
	CloseTable();
	echo "<br />";
}
//---------------------------------------------------------------------------------------//
// Comments start here
//---------------------------------------------------------------------------------------//
// set comment order if not set
if ( !isset($order) ) {
	if ( $xoopsUser ) {
		$order = $xoopsUser->getVar("uorder");
		} else {
			$order = $bcoosConfig['com_order'];
		}
}
$order = intval($order);
$orderby = ($order == 1) ? "date DESC" : "date ASC";
if ( $mode == "flat" ) {
	$criteria = array("item_id=".$item_id."");
	$commentsArray = $pollcomment->getAllComments($criteria, true, $orderby);
	} elseif ( $mode == "thread" ) {
		$criteria = array("item_id=".$item_id."", "pid=".$pollcomment->getVar("pid")."");
		$commentsArray = $pollcomment->getAllComments($criteria, true, $orderby);
		} else {
			$commentsArray = "";
		}
OpenTable();
$pollcomment->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 "&nbsp;<a href='./pollresults.php?item_id=".$ele->getVar("item_id")."&amp;mode=".$mode."&amp;order=".$order."'>"._TOP."</a>&nbsp;|&nbsp;";
				echo "<a href='./pollresults.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();
//---------------------------------------------------------------------------------------//
// Comments stop here
//---------------------------------------------------------------------------------------//
include_once(XOOPS_ROOT_PATH."/footer.php");
?>
