<?php
// www.bcoos.net 2006-09 1.0.2 GPL
// $Id: xoopspoll.php,v 1.8 2003/07/15 00:15:21 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
// ------------------------------------------------------------------------- //
function b_xoopspoll_show() {
global $_COOKIE, $xoopsUser;
	include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspoll.php");
	include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolllog.php");
	include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspolloption.php");
	include_once(XOOPS_ROOT_PATH."/modules/xoopspoll/class/xoopspollrenderer.php");
	$block            = array();
	$block['title']   = _MB_POLLS_TITLE1;
	$block['content'] = '';
	$polls =& XoopsPoll::getAll(array("display=1"), true, "weight ASC, end_time DESC");
	foreach ($polls as $poll) {
		$renderer = new XoopsPollRenderer($poll);
		$expired  = intval($poll->getVar('end_time') < time());
		$already  = isset($_COOKIE["voted_polls"][$poll->getVar("poll_id")]);
		if ( $expired || $already) {
			$block['content'] .= $renderer->renderResults();
			} else {
				$uid = $xoopsUser ? $xoopsUser->getVar("uid") : 0;
				if ( XoopsPollLog::hasVoted($poll->getVar("poll_id"), _REMOTE_ADDR, $uid) ) {
					$block['content'] .= $renderer->renderResults();
					} else {
						$block['content'] .= $renderer->renderForm();
					}
			}
	}
return $block;
}
?>
