<?php
// $Id: xoopspoll.php,v 1.1 2004/07/11 10:29:10 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// 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 $HTTP_COOKIE_VARS, $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($HTTP_COOKIE_VARS["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;
}
?>
