Beispiel #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;
}
Beispiel #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;
}
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;
}
 $criteria = new CriteriaCompo($criteria_topic);
 $criteria->add(new Criteria('pid', 0));
 $post_handler->updateAll("pid", $topic_handler->getTopPostId($newtopic), $criteria, true);
 $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");
Beispiel #5
0
 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;
 }
Beispiel #6
0
 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;
 }
Beispiel #7
0
                $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>";
            $polls['pollQuestion'] = $polls_arr[$i]->getVar("question");
        }
        $polls['pollVoters'] = $polls_arr[$i]->getVar("voters");
        $polls['pollVotes'] = $polls_arr[$i]->getVar("votes");
        $xoopsTpl->append('polls', $polls);
        unset($polls);
    }
    include XOOPS_ROOT_PATH . "/footer.php";
} elseif (!empty($_POST['option_id'])) {
    $voted_polls = !empty($HTTP_COOKIE_VARS['voted_polls']) ? $HTTP_COOKIE_VARS['voted_polls'] : array();
    $mail_author = false;
    $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'))) {
Beispiel #8
0
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
	redirect_header("index.php",1,_AM_DBUPDATED);
	exit();
}

if ( $op == "log" ) {
	xoops_cp_header();
	echo "<h4>"._AM_POLLCONF."</h4>";
	echo "<br>View Log<br> Sorry, not yet. ;-)";
	xoops_cp_footer();
	exit();
}

if ( $op == "quickupdate" ) {
	$count = count($poll_id);
	for ( $i = 0; $i < $count; $i++ ) {
		$display[$i] = empty($display[$i]) ? 0 : 1;
		$weight[$i] = empty($weight[$i]) ? 0 : $weight[$i];
		if ( $display[$i] != $old_display[$i] || $weight[$i] != $old_weight[$i] ) {
			$poll = new XoopsPoll($poll_id[$i]);
			$poll->setVar("display", $display[$i]);
			$poll->setVar("weight", intval($weight[$i]));
			$poll->store();
		}
	}
	include_once XOOPS_ROOT_PATH.'/class/template.php';
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
	redirect_header("index.php",1,_AM_DBUPDATED);
	exit();
}
?>
Beispiel #9
0
    $op_hidden = new XoopsFormHidden("op", "restart_ok");
    $poll_form->addElement($op_hidden);
    $poll_topic_id_hidden = new XoopsFormHidden("topic_id", $topic_id);
    $poll_form->addElement($poll_topic_id_hidden);
    $poll_id_hidden = new XoopsFormHidden("poll_id", $poll->getVar("poll_id"));
    $poll_form->addElement($poll_id_hidden);
    $submit_button = new XoopsFormButton("", "poll_submit", _MD_POLL_RESTART, "submit");
    $poll_form->addElement($submit_button);
    //include XOOPS_ROOT_PATH."/header.php";
    echo "<h4>" . _MD_POLL_POLLCONF . "</h4>";
    $poll_form->display();
    //include XOOPS_ROOT_PATH."/footer.php";
    //exit();
}
if ($op == "restart_ok") {
    $poll = new XoopsPoll($poll_id);
    $end_time = empty($_POST['end_time']) ? "" : $_POST['end_time'];
    if (!empty($end_time)) {
        $timezone = is_object($xoopsUser) ? $xoopsUser->timezone() : null;
        $poll->setVar("end_time", userTimeToServerTime(strtotime($end_time), $timezone));
    } else {
        $poll->setVar("end_time", time() + 86400 * 10);
    }
    if (!empty($_POST["notify"]) && $end_time > time()) {
        // if notify, set mail status to "not mailed"
        $poll->setVar("mail_status", POLL_NOTMAILED);
    } else {
        // if not notify, set mail status to already "mailed"
        $poll->setVar("mail_status", POLL_MAILED);
    }
    if (!empty($_POST["reset"])) {
Beispiel #10
0
}
if ( !empty($_POST['forum']) ) {
	$xforum = intval($_POST['forum']);
} elseif (!empty($_GET['forum'])) {
	$xforum = intval($_GET['forum']);
}

$topic_handler =& xoops_getmodulehandler('topic', 'xforum');
$topic_obj =& $topic_handler->get($topic_id);
if (!$topic_handler->getPermission($topic_obj->getVar("forum_id"), $topic_obj->getVar('topic_status'), "vote")){
    	redirect_header("javascript:history.go(-1);", 2, _NOPERM);
}

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);