Esempio n. 1
0
function b_xoopspoll_show()
{
    $block = array();
    $polls =& XoopsPoll::getAll(array('display=1'), true, 'weight ASC, end_time DESC');
    $count = count($polls);
    $block['lang_vote'] = _PL_VOTE;
    $block['lang_results'] = _PL_RESULTS;
    for ($i = 0; $i < $count; $i++) {
        $options_arr =& XoopsPollOption::getAllByPollId($polls[$i]->getVar('poll_id'));
        $option_type = 'radio';
        $option_name = 'option_id';
        if ($polls[$i]->getVar('multiple') == 1) {
            $option_type = 'checkbox';
            $option_name .= '[]';
        }
        foreach ($options_arr as $option) {
            $options[] = array('id' => $option->getVar('option_id'), 'text' => $option->getVar('option_text'));
        }
        $poll = array('id' => $polls[$i]->getVar('poll_id'), 'question' => $polls[$i]->getVar('question'), 'option_type' => $option_type, 'option_name' => $option_name, 'options' => $options);
        $block['polls'][] =& $poll;
        unset($options);
        unset($poll);
    }
    return $block;
}
Esempio n. 2
0
function b_xoopspoll_show()
{
	//echo "a";
	global $xoopsUser;
	$block = array();
	$polls =& XoopsPoll::getAll(array('display=1'), true, 'weight ASC, end_time DESC');
	$count = count($polls);
	$block['lang_vote'] = _PL_VOTE;
	$block['lang_results'] = _PL_RESULTS;
	$block['lang_expires'] = _PL_WILLEXPIRE;
	$block['lang_expired'] = _PL_HASEXPIRED;

	for ($i = 0; $i < $count; $i++) {
		$options_arr =& XoopsPollOption::getAllByPollId($polls[$i]->getVar('poll_id'));
		$option_type = 'radio';
		$option_name = 'option_id';
		if ($polls[$i]->getVar('multiple') == 1) {
			$option_type = 'checkbox';
			$option_name .= '[]';
		}
				
		$totalVotes=$polls[$i]->getVar('votes');
		$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
		if ( XoopsPollLog::hasVoted($polls[$i]->getVar('poll_id'), xoops_getenv('REMOTE_ADDR'),$uid)){
			$hasVoted=1;
		}else{
			$hasVoted=0;
		}

		foreach ($options_arr as $option) {
			$percent = intval(100 * $option->getVar("option_count") / $totalVotes).'%';
			$options[] = array('id' => $option->getVar('option_id'), 'text' => $option->getVar('option_text'), 'count' => $option->getVar('option_count'), 'percent'=>$percent, 'color'=>$option->getVar('option_color'));
		}
		$poll = array('id' => $polls[$i]->getVar('poll_id'), 'question' => $polls[$i]->getVar('question'), 'option_type' => $option_type, 'option_name' => $option_name, 'options' => $options,'has_expired'=>$polls[$i]->hasExpired(), 'votes' => $polls[$i]->getVar('votes'), 'has_voted'=>$hasVoted, 'end_time'=>formatTimeStamp($polls[$i]->getVar('end_time'), "m"));
		$block['polls'][] =& $poll;
		unset($options);
		unset($poll);
	}
    return $block;
}
Esempio n. 3
0
function b_xoopspoll_show()
{
    global $xoopsUser;
    $block = array();
    $polls =& XoopsPoll::getAll(array('display=1'), true, 'weight ASC, end_time DESC');
    $count = count($polls);
    $block['lang_vote'] = _PL_VOTE;
    $block['lang_results'] = _PL_RESULTS;
    $block['lang_expires'] = _PL_WILLEXPIRE;
    $block['lang_expired'] = _PL_HASEXPIRED;
    $block['lang_comments'] = _PL_COMMENTS;
    $block['lang_comment'] = _PL_COMMENT;
    $block['url'] = "http" . (!empty($_SERVER['HTTPS']) ? "s" : "") . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    for ($i = 0; $i < $count; $i++) {
        $options_arr =& XoopsPollOption::getAllByPollId($polls[$i]->getVar('poll_id'));
        $option_type = 'radio';
        $option_name = 'option_id';
        if ($polls[$i]->getVar('multiple') == 1) {
            $option_type = 'checkbox';
            $option_name .= '[]';
        }
        $totalVotes = $polls[$i]->getVar('votes');
        $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
        if (XoopsPollLog::hasVoted($polls[$i]->getVar('poll_id'), xoops_getenv('REMOTE_ADDR'), $uid)) {
            $hasVoted = 1;
        } else {
            $hasVoted = 0;
        }
        foreach ($options_arr as $option) {
            $percent = intval(100 * $option->getVar("option_count") / $totalVotes) . '%';
            $options[] = array('id' => $option->getVar('option_id'), 'text' => $option->getVar('option_text'), 'count' => $option->getVar('option_count'), 'percent' => $percent, 'color' => $option->getVar('option_color'));
        }
        $poll = array('id' => $polls[$i]->getVar('poll_id'), 'question' => $polls[$i]->getVar('question'), 'option_type' => $option_type, 'option_name' => $option_name, 'options' => $options, 'has_expired' => $polls[$i]->hasExpired(), 'votes' => $polls[$i]->getVar('votes'), 'has_voted' => $hasVoted, 'totalVotes' => sprintf(_PL_TOTALVOTES, $totalVotes), 'comments' => XoopsPoll::getcomments($polls[$i]->getVar('poll_id')), 'end_time' => formatTimeStamp($polls[$i]->getVar('end_time'), "m"), 'comment_mode' => XoopsPollLog::commentMode());
        $block['polls'][] =& $poll;
        unset($options);
        unset($poll);
    }
    return $block;
}
Esempio n. 4
0
}
$url = $_POST['url'];
if (empty($poll_id)) {
    $xoopsOption['template_main'] = 'xoopspoll_index.html';
    include XOOPS_ROOT_PATH . "/header.php";
    $limit = !empty($_GET['limit']) ? intval($_GET['limit']) : 50;
    $start = !empty($_GET['start']) ? intval($_GET['start']) : 0;
    $xoopsTpl->assign('lang_pollslist', _PL_POLLSLIST);
    $xoopsTpl->assign('lang_pollquestion', _PL_POLLQUESTION);
    $xoopsTpl->assign('lang_pollvoters', _PL_VOTERS);
    $xoopsTpl->assign('lang_votes', _PL_VOTES);
    $xoopsTpl->assign('lang_expiration', _PL_EXPIRATION);
    $xoopsTpl->assign('lang_results', _PL_RESULTS);
    $xoopsTpl->assign('lang_mustlogin', _PL_MUSTLOGIN);
    // add 1 to $limit to know whether there are more polls
    $polls_arr =& XoopsPoll::getAll(array(), true, "weight ASC, end_time DESC", $limit + 1, $start);
    $polls_count = count($polls_arr);
    $max = $polls_count > $limit ? $limit : $polls_count;
    for ($i = 0; $i < $max; $i++) {
        $polls = array();
        $polls['pollId'] = $polls_arr[$i]->getVar("poll_id");
        if ($polls_arr[$i]->getVar("end_time") > time()) {
            $polls['pollEnd'] = formatTimestamp($polls_arr[$i]->getVar("end_time"), "m");
            $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
            if (XoopsPollLog::hasVoted($polls_arr[$i]->getVar('poll_id'), xoops_getenv('REMOTE_ADDR'), $uid)) {
                $polls['pollQuestion'] = $polls_arr[$i]->getVar("question");
            } else {
                $polls['pollQuestion'] = "<a href='index.php?poll_id=" . $polls_arr[$i]->getVar("poll_id") . "'>" . $polls_arr[$i]->getVar("question") . "</a>";
            }
        } else {
            $polls['pollEnd'] = "<span style='color:#ff0000;'>" . _PL_EXPIRED . "</span>";