Ejemplo 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;
}
Ejemplo 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;
}
Ejemplo 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;
}
Ejemplo n.º 4
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");
 }
 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>";
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 7
0
 function vote($option_id, $ip, $user_id = null)
 {
     if (!empty($option_id)) {
         if (is_array($option_id)) {
             foreach ($option_id as $vote) {
                 $option = new XoopsPollOption($vote);
                 if ($this->getVar("poll_id") == $option->getVar("poll_id")) {
                     $log = new XoopsPollLog();
                     $log->setVar("poll_id", $this->getVar("poll_id"));
                     $log->setVar("option_id", $vote);
                     $log->setVar("ip", $ip);
                     if (isset($user_id)) {
                         $log->setVar("user_id", $user_id);
                     }
                     if (!$log->store()) {
                     } else {
                         $option->updateCount();
                     }
                 }
             }
         } else {
             $option = new XoopsPollOption($option_id);
             if ($this->getVar("poll_id") == $option->getVar("poll_id")) {
                 $log = new XoopsPollLog();
                 $log->setVar("poll_id", $this->getVar("poll_id"));
                 $log->setVar("option_id", $option_id);
                 $log->setVar("ip", $ip);
                 if (isset($user_id)) {
                     $log->setVar("user_id", $user_id);
                 }
                 $log->store();
                 $option->updateCount();
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 8
0
	echo "<h4>"._AM_POLLCONF."</h4>";
	$poll_form->display();
	xoops_cp_footer();
	exit();
}

if ( $op == "savemore" ) {
    if (!$GLOBALS['xoopsSecurity']->check()) {
        redirect_header('index.php', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
    }
	$poll = new XoopsPoll($poll_id);
	$i = 0;
	foreach ( $option_text as $optxt ) {
		$optxt = trim($optxt);
		if ( $optxt != "" ) {
			$option = new XoopsPollOption();
			$option->setVar("option_text", $optxt);
			$option->setVar("poll_id", $poll->getVar("poll_id"));
			$option->setVar("option_color", $option_color[$i]);
			$option->store();
		}
		$i++;
	}
	include_once XOOPS_ROOT_PATH.'/class/template.php';
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
	redirect_header("index.php",1,_AM_DBUPDATED);
	exit();
}

if ( $op == "delete" ) {
	xoops_cp_header();
Ejemplo n.º 9
0
    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));
    }
Ejemplo n.º 10
0
 echo "<a href='" . $sorthref . "option_id&amp;orderdir=ASC'><img src=" . $arrow_up . "></a>";
 echo "<a href='" . $sorthref . "option_id&amp;orderdir=DESC'><img src=" . $arrow_down . "></a>&nbsp;" . _AM_OPTIONID . "</td>";
 echo "<td nowrap>";
 echo "<a href='" . $sorthref . "ip&amp;orderdir=ASC'><img src=" . $arrow_up . "></a>";
 echo "<a href='" . $sorthref . "ip&amp;orderdir=DESC'><img src=" . $arrow_down . "></a>&nbsp;" . _AM_IP . "</td>";
 echo "<td nowrap>";
 echo "<a href='" . $sorthref . "user_id&amp;orderdir=ASC'><img src=" . $arrow_up . "></a>";
 echo "<a href='" . $sorthref . "user_id&amp;orderdir=DESC'><img src=" . $arrow_down . "></a>&nbsp;" . _AM_VOTER . "</td>";
 echo "<td nowrap>";
 echo "<a href='" . $sorthref . "time&amp;orderdir=ASC'><img src=" . $arrow_up . "></a>";
 echo "<a href='" . $sorthref . "time&amp;orderdir=DESC'><img src=" . $arrow_down . "></a>&nbsp;" . _AM_VOTETIME . "</td>";
 //		echo "<td nowrap>&nbsp;</td>";
 echo "</tr>";
 $max = $logs_count > $limit ? $limit : $logs_count;
 for ($i = 0; $i < $max; $i++) {
     $option = new XoopsPollOption($logs_arr[$i]->getVar("option_id"));
     echo "<tr class='bg1'>";
     echo "<td align='center'>" . $logs_arr[$i]->getVar("log_id") . "</td>";
     echo "<td>" . $option->getVar('option_text') . "</td>";
     if ($xoopsModuleConfig['lookuphost'] == 1) {
         $remote_ip = gethostbyaddr_with_cache($logs_arr[$i]->getVar("ip"));
     } else {
         $remote_ip = $logs_arr[$i]->getVar("ip");
     }
     echo "<td align='center'>" . $remote_ip . "</td>";
     if ($logs_arr[$i]->getVar("user_id") != 0) {
         $user = new XoopsUser($logs_arr[$i]->getVar("user_id"));
         $uname = $user->getVar('uname');
         echo "<td align='center'><a href=" . XOOPS_URL . "/userinfo.php?uid=" . $user->getVar("uid") . ">" . $uname . "</a></td>";
     } else {
         $uname = $xoopsConfig['anonymous'];