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; }
$post_handler->updateAll("topic_id", $newtopic, $criteria_topic, true); $topic_views = $topic_obj->getVar("topic_views") + $newtopic_obj->getVar("topic_views"); $criteria_newtopic = new Criteria("topic_id", $newtopic); $topic_handler->updateAll("topic_views", $topic_views, $criteria_newtopic, true); $topic_handler->synchronization($newtopic); $poll_id = $topic_handler->get($tid, "poll_id"); if ($poll_id > 0) { if (is_dir(XOOPS_ROOT_PATH . "/modules/xoopspoll/")) { 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"; $poll = new XoopsPoll($poll_id); if ($poll->delete() != false) { XoopsPollOption::deleteByPollId($poll->getVar("poll_id")); XoopsPollLog::deleteByPollId($poll->getVar("poll_id")); xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id')); } } } $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $xoopsDB->prefix("bb_topics"), $tid); $result = $xoopsDB->queryF($sql); $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $xoopsDB->prefix("bb_votedata"), $tid); $result = $xoopsDB->queryF($sql); $sql = sprintf("UPDATE %s SET forum_topics = forum_topics-1 WHERE forum_id = %u", $xoopsDB->prefix("bb_forums"), $forum); $result = $xoopsDB->queryF($sql); $topic_obj->loadFilters("delete"); $newtopic_obj->loadFilters("update"); } echo $action[$mode]['msg'] . "<p><a href='viewtopic.php?topic_id={$newtopic}'>" . _MD_VIEWTHETOPIC . "</a></p>" . "<p><a href='viewforum.php?forum={$forum}'>" . _MD_RETURNTOTHEFORUM . "</a></p>" . "<p><a href='index.php'>" . _MD_RETURNFORUMINDEX . "</a></p>"; } elseif ('move' == $mode) {
function emptyTopic(&$post) { global $xoopsModule, $xoopsConfig; if (!is_object($post) || !$post->isTopic()) { return false; } $sql = sprintf("UPDATE %s SET post_text='[--DELETED--]', post_edit='' WHERE post_id = %u", $this->db->prefix("bb_posts_text"), $post->getVar('post_id')); if (!($result = $this->db->queryF($sql))) { newbb_message("Could not remove post text: " . $sql); return false; } $post->deleteAttachment(); $sql = sprintf("UPDATE %s SET uid=0, attachment='', attachsig=0 WHERE post_id = %u", $this->db->prefix("bb_posts"), $post->getVar('post_id')); if (!($result = $this->db->queryF($sql))) { newbb_message("Could not remove post : " . $sql); return false; } $sql = sprintf("UPDATE %s SET topic_poster=0, topic_haspoll=0 WHERE topic_id = %u", $this->db->prefix("bb_topics"), $post->getVar('topic_id')); if (!($result = $this->db->queryF($sql))) { newbb_message("Could not update topic: " . $sql); return false; } if ($post->getVar('uid')) { $sql = sprintf("UPDATE %s SET posts=posts-1 WHERE uid = %u", $this->db->prefix("users"), $post->getVar('uid')); if (!($result = $this->db->queryF($sql))) { newbb_message("Could not update user posts: " . $sql); } } $topic_handler =& xoops_getmodulehandler('topic', 'newbb'); $poll_id =& $topic_handler->get($post->getVar('topic_id'), "poll_id"); if ($poll_id > 0) { if (is_dir(XOOPS_ROOT_PATH . "/modules/xoopspoll/")) { 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"; $poll = new XoopsPoll($poll_id); if ($poll->delete() != false) { XoopsPollOption::deleteByPollId($poll->getVar("poll_id")); XoopsPollLog::deleteByPollId($poll->getVar("poll_id")); xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id')); } } } $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->db->prefix("bb_votedata"), $post->getVar('topic_id')); if (!($result = $this->db->queryF($sql))) { newbb_message("Could not delete votedata: " . $sql); } return true; }
function _delete(&$post, $force = false) { global $xoopsModule; if (!is_object($post) || $post->getVar('post_id') == 0) { return false; } /* Set active post as deleted */ if ($post->getVar("approved") > 0 && empty($force)) { $sql = "UPDATE " . $this->db->prefix("bb_posts") . " SET approved = -1 WHERE post_id = " . $post->getVar("post_id"); if (!($result = $this->db->queryF($sql))) { } /* delete pending post directly */ } else { $sql = sprintf("DELETE FROM %s WHERE post_id = %u", $this->db->prefix("bb_posts"), $post->getVar('post_id')); if (!($result = $this->db->queryF($sql))) { $post->setErrors("delte post error: " . $sql); return false; } $post->deleteAttachment(); $sql = sprintf("DELETE FROM %s WHERE post_id = %u", $this->db->prefix("bb_posts_text"), $post->getVar('post_id')); if (!($result = $this->db->queryF($sql))) { $post->setErrors("Could not remove post text: " . $sql); return false; } } if ($post->isTopic()) { $topic_handler =& xoops_getmodulehandler('topic', 'newbb'); $topic_obj =& $topic_handler->get($post->getVar('topic_id')); if (is_object($topic_obj) && $topic_obj->getVar("approved") > 0 && empty($force)) { $topiccount_toupdate = 1; $topic_obj->setVar("approved", -1); $topic_handler->insert($topic_obj); xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); } else { if (is_object($topic_obj)) { if ($topic_obj->getVar("approved") > 0) { xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); } $poll_id = $topic_obj->getVar("poll_id"); if ($poll_id > 0) { if (is_dir(XOOPS_ROOT_PATH . "/modules/xoopspoll/")) { 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"; $poll = new XoopsPoll($poll_id); if ($poll->delete() != false) { XoopsPollOption::deleteByPollId($poll->getVar("poll_id")); XoopsPollLog::deleteByPollId($poll->getVar("poll_id")); xoops_comment_delete($xoopsModule->getVar('mid'), $poll->getVar('poll_id')); } } } } $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->db->prefix("bb_topics"), $post->getVar('topic_id')); if (!($result = $this->db->queryF($sql))) { //xoops_error($this->db->error()); } $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->db->prefix("bb_votedata"), $post->getVar('topic_id')); if (!($result = $this->db->queryF($sql))) { //xoops_error($this->db->error()); } } } else { $sql = "UPDATE " . $this->db->prefix("bb_topics") . " t\r\n \t\t\t\tLEFT JOIN " . $this->db->prefix("bb_posts") . " p ON p.topic_id = t.topic_id\r\n \t\t\t\tSET t.topic_last_post_id = p.post_id\r\n \t\t\t\tWHERE t.topic_last_post_id = " . $post->getVar('post_id') . "\r\n \t\t\t\t\t\tAND p.post_id = (SELECT MAX(post_id) FROM " . $this->db->prefix("bb_posts") . " WHERE topic_id=t.topic_id)"; if (!($result = $this->db->queryF($sql))) { } } $postcount_toupdate = $post->getVar("approved"); if ($postcount_toupdate > 0) { // Update user stats if ($post->getVar('uid') > 0) { $member_handler =& xoops_gethandler('member'); $poster =& $member_handler->getUser($post->getVar('uid')); if (is_object($poster) && $post->getVar('uid') == $poster->getVar("uid")) { $poster->setVar('posts', $poster->getVar('posts') - 1); $res = $member_handler->insertUser($poster, true); unset($poster); } } $sql = "UPDATE " . $this->db->prefix("bb_posts") . " SET pid = " . $post->getVar('pid') . " WHERE pid=" . $post->getVar('post_id'); if (!($result = $this->db->queryF($sql))) { //xoops_error($this->db->error()); } } return true; }
){ @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; }
function updateCount() { $votes = XoopsPollLog::getTotalVotesByPollId($this->getVar("poll_id")); $voters = XoopsPollLog::getTotalVotersByPollId($this->getVar("poll_id")); $sql = "UPDATE " . $this->db->prefix("xoopspoll_desc") . " SET votes={$votes}, voters={$voters} WHERE poll_id=" . $this->getVar("poll_id") . ""; $this->db->query($sql); }
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 !!");
function updateCount() { $votes = XoopsPollLog::getTotalVotesByOptionId($this->getVar("option_id")); $sql = "UPDATE " . $this->db->prefix("xoopspoll_option") . " SET option_count={$votes} WHERE option_id=" . $this->getVar("option_id") . ""; $this->db->query($sql); }
/////////////////////////////// // 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"))); }
echo "<tr class='bg3'>"; echo "<td nowrap>" . _AM_POLLQUESTION . "</td><td nowrap>" . _AM_POLLDESC . "</td>"; echo "<td nowrap>" . _AM_VOTERS . "</td><td nowrap>" . _AM_VOTES . "</td>"; echo "<td nowrap>" . _AM_EXPIRATION . "</td>"; echo "</tr>"; echo "<tr class='bg1'>"; echo "<td>" . $poll->getVar('question') . "</td><td>" . $poll->getVar('description') . "</td>"; echo "<td align='center'>" . $poll->getVar('voters') . "</td><td align='center'>" . $poll->getVar('votes') . "</td>"; echo "<td>" . formatTimestamp($poll->getVar('end_time'), "l") . "</td>"; echo "</tr>"; echo "</table>"; echo "</td></tr>"; echo "</table>"; echo "<br>"; // show logs $logs_arr =& XoopsPollLog::getAllByPollId($poll_id, $orderby . " " . $orderdir); $logs_count = count($logs_arr); $arrow_up = XOOPS_URL . "/modules/xoopspoll/images/up.gif"; $arrow_down = XOOPS_URL . "/modules/xoopspoll/images/down.gif"; $sorthref = "index.php?op=log&poll_id=" . $poll_id . "&orderby="; if (is_array($logs_arr) && $logs_count > 0) { echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"; echo "<tr><td class='bg2'>"; echo "<table width='100%' border='0' cellpadding='4' cellspacing='1'>"; echo "<tr class='bg3'>"; echo "<td nowrap>"; echo "<a href='" . $sorthref . "log_id&orderdir=ASC'><img src=" . $arrow_up . "></a>"; echo "<a href='" . $sorthref . "log_id&orderdir=DESC'><img src=" . $arrow_down . "></a> " . _AM_LOGID . "</td>"; echo "<td nowrap>"; echo "<a href='" . $sorthref . "option_id&orderdir=ASC'><img src=" . $arrow_up . "></a>"; echo "<a href='" . $sorthref . "option_id&orderdir=DESC'><img src=" . $arrow_down . "></a> " . _AM_OPTIONID . "</td>";