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; }
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; }
if ( !$poll->hasExpired() ) { $expire_text = new XoopsFormText(_AM_EXPIRATION."<br /><small>"._AM_FORMAT."<br />".sprintf(_AM_CURRENTTIME, formatTimestamp(time(), "Y-m-d H:i:s"))."</small>", "end_time", 20, 19, $date); $poll_form->addElement($expire_text); } else { $restart_label = new XoopsFormLabel(_AM_EXPIRATION, sprintf(_AM_EXPIREDAT, $date)."<br /><a href='index.php?op=restart&poll_id=".$poll->getVar("poll_id")."'>"._AM_RESTART."</a>"); $poll_form->addElement($restart_label); } $disp_yn = new XoopsFormRadioYN(_AM_DISPLAYBLOCK, "display", $poll->getVar("display")); $poll_form->addElement($disp_yn); $weight_text = new XoopsFormText(_AM_DISPLAYORDER, "weight", 6, 5, $poll->getVar("weight")); $poll_form->addElement($weight_text); $multi_yn = new XoopsFormRadioYN(_AM_ALLOWMULTI, "multiple", $poll->getVar("multiple")); $poll_form->addElement($multi_yn); $anonymous_yn = new XoopsFormRadioYN(_AM_ALLOWANONYMOUS, "anonymous", $poll->getVar("anonymous")); $poll_form->addElement($anonymous_yn); $options_arr =& XoopsPollOption::getAllByPollId($poll->getVar("poll_id")); $notify_value = 1; if ( $poll->getVar("mail_status") != 0 ) { $notify_value = 0; } $notify_yn = new XoopsFormRadioYN(_AM_NOTIFY, "notify", $notify_value); $poll_form->addElement($notify_yn); $option_tray = new XoopsFormElementTray(_AM_POLLOPTIONS, ""); $barcolor_array =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/modules/xoopspoll/images/colorbars/"); $i = 0; foreach($options_arr as $option){ $option_text = new XoopsFormText("", "option_text[]", 50, 255, $option->getVar("option_text")); $option_tray->addElement($option_text); $option_id_hidden = new XoopsFormHidden("option_id[]", $option->getVar("option_id")); $option_tray->addElement($option_id_hidden); $color_select = new XoopsFormSelect("", "option_color[".$i."]", $option->getVar("option_color"));
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++; } if ( !$this->poll->hasExpired() ) { $vote = "<a href='".XOOPS_URL."/modules/xoopspoll/index.php?poll_id=".$this->poll->getVar("poll_id")."'>"._PL_VOTE."</a>"; } $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)); }