Example #1
0
 /**
  * Modify a poll
  */
 function testModifyPoll()
 {
     // Values to create it first
     $question = 'Who is the next best contender for Grudge award?';
     $id_member = 0;
     $poster_name = 'test';
     // Create the poll.
     $id_poll = createPoll($question, $id_member, $poster_name);
     // Link the poll to the topic.
     associatedPoll($this->id_topic, $id_poll);
     // Modify it. Hmm... we haz no modify function :P
     // @todo
 }
Example #2
0
/**
 * Show a poll.
 * It is possible to use this function in combination with the template
 * template_display_poll_above from Display.template.php, the only part missing
 * is the definition of the poll moderation button array (see Display.controller.php
 * for details).
 *
 * @param int|null $topicID = null
 * @param string $output_method = 'echo'
 */
function ssi_showPoll($topicID = null, $output_method = 'echo')
{
    global $txt, $user_info, $context, $scripturl;
    global $board;
    static $last_board = null;
    require_once SUBSDIR . '/Poll.subs.php';
    require_once SUBSDIR . '/Topic.subs.php';
    if ($topicID === null && isset($_REQUEST['ssi_topic'])) {
        $topicID = (int) $_REQUEST['ssi_topic'];
    } else {
        $topicID = (int) $topicID;
    }
    if (empty($topicID)) {
        return array();
    }
    // Get the topic starter information.
    $topicinfo = getTopicInfo($topicID, 'starter');
    $boards_can_poll = boardsAllowedTo('poll_view');
    // If:
    //  - is not allowed to see poll in any board,
    //  - or:
    //     - is not allowed in the specific board, and
    //     - is not an admin
    // fail
    if (empty($boards_can_poll) || !in_array($topicinfo['id_board'], $boards_can_poll) && !in_array(0, $boards_can_poll)) {
        return array();
    }
    $context['user']['started'] = $user_info['id'] == $topicinfo['id_member'] && !$user_info['is_guest'];
    $poll_id = associatedPoll($topicID);
    loadPollContext($poll_id);
    if (empty($context['poll'])) {
        return array();
    }
    // For "compatibility" sake
    // @deprecated since 1.0
    $context['poll']['allow_vote'] = $context['allow_vote'];
    $context['poll']['allow_view_results'] = $context['allow_poll_view'];
    $context['poll']['topic'] = $topicID;
    if ($output_method != 'echo') {
        return $context['poll'];
    }
    echo '
		<div class="content" id="poll_options">
			<h4 id="pollquestion">
				', $context['poll']['question'], '
			</h4>';
    if ($context['poll']['allow_vote']) {
        echo '
			<form action="', $scripturl, '?action=poll;sa=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="UTF-8">';
        // Show a warning if they are allowed more than one option.
        if ($context['poll']['allowed_warning']) {
            echo '
				<p>', $context['poll']['allowed_warning'], '</p>';
        }
        echo '
				<ul class="options">';
        // Show each option with its button - a radio likely.
        foreach ($context['poll']['options'] as $option) {
            echo '
					<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
        }
        echo '
				</ul>
				<div class="submitbutton">
					<input type="submit" value="', $txt['poll_vote'], '" class="button_submit" />
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
				</div>
			</form>';
        // Is the clock ticking?
        if (!empty($context['poll']['expire_time'])) {
            echo '
			<p><strong>', $context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on'], ':</strong> ', $context['poll']['expire_time'], '</p>';
        }
    } elseif ($context['poll']['allow_view_results']) {
        echo '
			<ul class="options">';
        // Show each option with its corresponding percentage bar.
        foreach ($context['poll']['options'] as $option) {
            echo '
				<li', $option['voted_this'] ? ' class="voted"' : '', '>', $option['option'], '
					<div class="results">';
            if ($context['allow_poll_view']) {
                echo '
						<div class="statsbar"> ', $option['bar_ndt'], '</div>
						<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
            }
            echo '
					</div>
				</li>';
        }
        echo '
			</ul>';
        if ($context['allow_poll_view']) {
            echo '
			<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
        }
        // Is the clock ticking?
        if (!empty($context['poll']['expire_time'])) {
            echo '
			<p><strong>', $context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on'], ':</strong> ', $context['poll']['expire_time'], '</p>';
        }
    } else {
        echo $txt['poll_cannot_see'];
    }
    echo '
			</div>';
}
Example #3
0
 /**
  * Remove a poll from a topic without removing the topic.
  * Must be called with a topic specified in the URL.
  * Requires poll_remove_any permission, unless it's the poll starter
  * with poll_remove_own permission.
  * Upon successful completion of action will direct user back to topic.
  * Accessed via ?action=poll;sa=remove.
  */
 public function action_remove()
 {
     global $topic, $user_info;
     // Make sure the topic is not empty.
     if (empty($topic)) {
         fatal_lang_error('no_access', false);
     }
     // Verify the session.
     checkSession('get');
     // We need to work with them polls.
     require_once SUBSDIR . '/Poll.subs.php';
     // Check permissions.
     if (!allowedTo('poll_remove_any')) {
         $pollStarters = pollStarters($topic);
         if (empty($pollStarters)) {
             fatal_lang_error('no_access', false);
         }
         list($topicStarter, $pollStarter) = $pollStarters;
         if ($topicStarter == $user_info['id'] || $pollStarter != 0 && $pollStarter == $user_info['id']) {
             isAllowedTo('poll_remove_own');
         }
     }
     // Retrieve the poll ID.
     $pollID = associatedPoll($topic);
     // Remove the poll!
     removePoll($pollID);
     // Finally set the topic poll ID back to 0!
     associatedPoll($topic, 0);
     // A mod might have logged this (social network?), so let them remove, it too
     call_integration_hook('integrate_poll_remove', array($pollID));
     // Take the moderator back to the topic.
     redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
 }