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; }
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; }
){ @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"; } if ( $xforumtopic->getVar('topic_haspoll') && $topic_handler->getPermission($viewtopic_forum, $xforumtopic->getVar('topic_status'), "vote") ){ $xoopsTpl->assign('topic_poll', 1); $poll = new XoopsPoll($xforumtopic->getVar('poll_id')); $renderer = new XoopsPollRenderer($poll); $uid = is_object($xoopsUser)?$xoopsUser->getVar("uid"):0; if ( XoopsPollLog::hasVoted($xforumtopic->getVar('poll_id'), $_SERVER['REMOTE_ADDR'], $uid) ) { $renderer->assignResults($xoopsTpl); //pollresults($xforumtopic->getVar('poll_id')); $xoopsTpl->assign('topic_pollresult', 1); setcookie("xf_polls[".$xforumtopic->getVar("poll_id")."]", 1); } else { $renderer->assignForm($xoopsTpl); $xoopsTpl->assign('lang_vote' , _PL_VOTE); $xoopsTpl->assign('lang_results' , _PL_RESULTS); //pollview($xforumtopic->getVar('poll_id')); setcookie("xf_polls[".$xforumtopic->getVar("poll_id")."]", 1); } } if ($topic_handler->getPermission($viewtopic_forum, $xforumtopic->getVar('topic_status'), "addpoll") ){ if(!$xforumtopic->getVar('topic_haspoll')){
$poll = new XoopsPoll($poll_id); if (!$poll->hasExpired()) { if ($poll->isAllowedToVote()) { if (empty($voted_polls[$poll_id])) { if ($xoopsUser) { if (XoopsPollLog::hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $xoopsUser->getVar("uid"))) { setcookie("voted_polls[{$poll_id}]", 1, 0); $msg = _PL_ALREADYVOTED; } else { $poll->vote($_POST['option_id'], xoops_getenv('REMOTE_ADDR'), $xoopsUser->getVar("uid")); $poll->updateCount(); setcookie("voted_polls[{$poll_id}]", 1, 0); $msg = _PL_THANKSFORVOTE; } } else { if (XoopsPollLog::hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'))) { setcookie("voted_polls[{$poll_id}]", 1, 0); $msg = _PL_ALREADYVOTED; } else { $poll->vote($_POST['option_id'], xoops_getenv('REMOTE_ADDR')); $poll->updateCount(); setcookie("voted_polls[{$poll_id}]", 1, 0); $msg = _PL_THANKSFORVOTE; } } } else { $msg = _PL_ALREADYVOTED; } } else { $msg = _PL_MUSTLOGIN; }
if ( !empty($_POST['option_id']) ) { $mail_author = false; $poll = new XoopsPoll($poll_id); if ( is_object($xoopsUser) ) { if ( XoopsPollLog::hasVoted($poll_id, $_SERVER['REMOTE_ADDR'], $xoopsUser->getVar("uid")) ) { $msg = _PL_ALREADYVOTED; setcookie("xf_polls[$poll_id]", 1); } else { $poll->vote($_POST['option_id'], '', $xoopsUser->getVar("uid")); $poll->updateCount(); $msg = _PL_THANKSFORVOTE; setcookie("xf_polls[$poll_id]", 1); } } else { if ( XoopsPollLog::hasVoted($poll_id, $_SERVER['REMOTE_ADDR']) ) { $msg = _PL_ALREADYVOTED; setcookie("xf_polls[$poll_id]", 1); } else { $poll->vote($_POST['option_id'], $_SERVER['REMOTE_ADDR']); $poll->updateCount(); $msg = _PL_THANKSFORVOTE; setcookie("xf_polls[$poll_id]", 1); } } redirect_header("viewtopic.php?topic_id=$topic_id&forum=$xforum&poll_id=$poll_id&pollresult=1", 1, $msg); exit(); } redirect_header("viewtopic.php?topic_id=$topic_id&forum=$xforum", 1, "You must choose an option !!");
/////////////////////////////// // show Poll if ($topic_handler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), "vote") && $viewtopic_forum->getVar('allow_polls') == 1 && $forumdata['topic_haspoll']) { $xoopsTpl->assign('topic_poll', 1); $poll = new XoopsPoll($forumdata['poll_id']); if (is_object($xoopsUser)) { if (XoopsPollLog::hasVoted($forumdata['poll_id'], $_SERVER['REMOTE_ADDR'], $xoopsUser->getVar("uid"))) { pollresults($forumdata['poll_id']); $xoopsTpl->assign('topic_pollresult', 1); setcookie("bb_polls[{$forumdata['poll_id']}]", 1); } else { pollview($forumdata['poll_id']); setcookie("bb_polls[{$forumdata['poll_id']}]", 1); } } else { if (XoopsPollLog::hasVoted($forumdata['poll_id'], $_SERVER['REMOTE_ADDR'])) { pollresults($forumdata['poll_id']); $xoopsTpl->assign('topic_pollresult', 1); setcookie("bb_polls[{$forumdata['poll_id']}]", 1); } else { pollview($forumdata['poll_id']); setcookie("bb_polls[{$forumdata['poll_id']}]", 1); } } } if ($topic_handler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), "addpoll") && $viewtopic_forum->getVar('allow_polls') == 1) { if (!$forumdata['topic_haspoll']) { if (is_object($xoopsUser) && $xoopsUser->getVar("uid") == $forumtopic->getVar("topic_poster")) { $t_poll = newbb_displayImage($forumImage['t_poll'], _MD_ADDPOLL); $xoopsTpl->assign('forum_addpoll', "<a href=\"polls.php?op=add&forum=" . $forumdata['forum_id'] . "&topic_id=" . $topic_id . "\">" . $t_poll . "</a> "); }
function assignResults(&$tpl) { if (!$this->poll->hasExpired()) { $end_text = sprintf(_PL_ENDSAT, formatTimestamp($this->poll->getVar("end_time"), "m")); } else { $end_text = sprintf(_PL_ENDEDAT, formatTimestamp($this->poll->getVar("end_time"), "m")); } $options_arr =& XoopsPollOption::getAllByPollId($this->poll->getVar("poll_id")); $total = $this->poll->getVar("votes"); $i = 0; foreach ($options_arr as $option) { if ($total > 0) { $percent = 100 * $option->getVar("option_count") / $total; } else { $percent = 0; } $options[$i]['text'] = $option->getVar("option_text"); if ($percent > 0) { $width = intval($percent) * 2; $options[$i]['image'] = "<img src='" . XOOPS_URL . "/modules/xoopspoll/images/colorbars/" . $option->getVar("option_color", "E") . "' height='14' width='" . $width . "' align='middle' alt='" . intval($percent) . " %' />"; } $options[$i]['percent'] = sprintf(" %d %% (%d)", $percent, $option->getVar("option_count")); $options[$i]['total'] = $option->getVar("option_count"); $i++; } global $xoopsUser; $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; if (!$this->poll->hasExpired() && !XoopsPollLog::hasVoted($this->poll->getVar('poll_id'), xoops_getenv('REMOTE_ADDR'), $uid)) { $vote = "<a href='" . XOOPS_URL . "/modules/xoopspoll/index.php?poll_id=" . $this->poll->getVar("poll_id") . "'>" . _PL_VOTE . "</a>"; } else { $vote = null; } $tpl->assign('poll', array('question' => $this->poll->getVar("question"), 'end_text' => $end_text, 'totalVotes' => sprintf(_PL_TOTALVOTES, $total), 'totalVoters' => sprintf(_PL_TOTALVOTERS, $this->poll->getVar("voters")), 'vote' => $vote, 'options' => $options, 'description' => $this->poll->getVar("description"))); }