/**
 * Function responsible for displaying the results of a poll.
 *
 * @param int $poll_id
 * @return string
 */
function poll_results($poll_id = 0)
{
    global $db;
    $output = "";
    $poll_id = (int) $poll_id;
    if ($poll_id) {
        $query = "SELECT `poll_question` FROM `poll_questions` WHERE `poll_id` = " . $db->qstr($poll_id);
        $poll_question = $db->GetRow($query);
        if ($poll_question) {
            $answers = array();
            $winner = 0;
            $highest = 0;
            $total_votes = poll_responses($poll_id);
            $query = "SELECT `answer_id`, `answer_text`, `answer_order` FROM `poll_answers` WHERE `poll_id`=" . $db->qstr($poll_id) . " ORDER BY `answer_order` ASC";
            $poll_answers = $db->GetAll($query);
            if ($poll_answers) {
                foreach ($poll_answers as $poll_answer) {
                    if (trim($poll_answer["answer_text"]) != "") {
                        $answers[$poll_answer["answer_order"]]["answer_id"] = $poll_answer["answer_id"];
                        $answers[$poll_answer["answer_order"]]["answer_text"] = $poll_answer["answer_text"];
                        $answers[$poll_answer["answer_order"]]["votes"] = poll_answer_responses($poll_id, $poll_answer["answer_id"]);
                        if ($answers[$poll_answer["answer_order"]]["votes"] > $highest) {
                            $winner = $answers[$poll_answer["answer_order"]]["answer_id"];
                            $highest = $answers[$poll_answer["answer_order"]]["votes"];
                        }
                    }
                }
            }
            $output .= "<div class=\"poll\">\n";
            $output .= "    <div class=\"poll-question\">" . html_encode($poll_question["poll_question"]) . "</div>\n";
            foreach ($answers as $answer) {
                $percent = round($answer["votes"] / ($total_votes + 0.0001) * 100);
                $output .= html_encode($answer["answer_text"]);
                $output .= "<div class=\"poll-response row-fluid\">\n";
                $output .= "    <div class=\"span10\">\n";
                $output .= "        <div class=\"progress\">\n";
                $output .= "            <div class=\"bar\" style=\"width: " . (!$percent ? "1" : $percent) . "%\"></div>";
                $output .= "        </div>\n";
                $output .= "    </div>\n";
                $output .= "    <div class=\"span2\">\n";
                $output .= $percent . "%\n";
                $output .= "    </div>\n";
                $output .= "</div>\n";
            }
            $output .= "    <div class=\"poll-votes\">\n";
            $output .= "        <strong>Total Votes:</strong> " . $total_votes . "\n";
            $output .= "    </div>\n";
            $output .= "</div>\n";
        }
    }
    return $output;
}
示例#2
0
			<tr>
				<td></td>
				<td colspan="3" style="padding-top: 10px">
					<input type="submit" class="btn btn-danger" name="delete_polls" value="Delete Selected" />
					<input type="submit" class="btn btn-warning" name="expire_polls" value="Expire Selected" />
				</td>
			</tr>
		</tfoot>
		<?php 
        }
        ?>
		<tbody>
			<?php 
        foreach ($results as $result) {
            $expired = false;
            $responses = poll_responses($result["poll_id"]);
            if (!$responses) {
                $url = ENTRADA_URL . "/admin/polls?section=edit&amp;id=" . $result["poll_id"];
            } else {
                $url = "javascript: SeeResults('" . $result["poll_id"] . "')";
            }
            if (($poll_until = (int) $result["poll_until"]) && $poll_until < time()) {
                $expired = true;
            }
            echo "<tr id=\"poll-" . $result["poll_id"] . "\" class=\"poll" . ($expired ? " na" : "") . "\">\n";
            echo "\t<td class=\"modified\"><input type=\"checkbox\" name=\"delete[]\" value=\"" . $result["poll_id"] . "\" /></td>\n";
            echo "\t<td class=\"general\">" . ($url ? "<a href=\"" . $url . "\" title=\"Edit Poll: " . (isset($POLL_TARGETS[$result["poll_target"]]) ? str_replace("&nbsp;", "", $POLL_TARGETS[$result["poll_target"]]) : $result["poll_target"]) . "\">" : "") . (isset($POLL_TARGETS[$result["poll_target"]]) ? str_replace("&nbsp;", "", $POLL_TARGETS[$result["poll_target"]]) : $result["poll_target"]) . ($url ? "</a>" : "") . "</td>\n";
            echo "\t<td class=\"title\">" . ($url ? "<a href=\"" . $url . "\" title=\"Edit Poll: " . html_encode($result["poll_question"]) . "\">" : "") . html_encode($result["poll_question"]) . ($url ? "</a>" : "") . "</td>\n";
            echo "\t<td class=\"responses\">" . $responses . "</td>\n";
            echo "</tr>\n";
        }
示例#3
0
    exit;
} elseif (!isset($_SESSION["isAuthorized"]) || !$_SESSION["isAuthorized"]) {
    header("Location: " . ENTRADA_URL);
    exit;
} elseif (!$ENTRADA_ACL->amIAllowed('poll', 'update', false)) {
    $ONLOAD[] = "setTimeout('window.location=\\'" . ENTRADA_URL . "/admin/" . $MODULE . "\\'', 15000);";
    $ERROR++;
    $ERRORSTR[] = "Your account does not have the permissions required to use this feature of this module.<br /><br />If you believe you are receiving this message in error please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.";
    echo display_error();
    application_log("error", "Group [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["group"] . "] and role [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["role"] . "] does not have access to this module [" . $MODULE . "]");
} else {
    if ($POLL_ID) {
        $query = "SELECT * FROM `poll_questions` WHERE `poll_id`=" . $db->qstr($POLL_ID);
        $result = $db->GetRow($query);
        if ($result) {
            if (!poll_responses($POLL_ID)) {
                $PROCESSED_ANSWERS = array();
                $BREADCRUMB[] = array("url" => "", "title" => "Editing Poll");
                echo "<h1>Editing Poll</h1>\n";
                // Error Checking
                switch ($STEP) {
                    case 2:
                        if (isset($_POST["poll_target"]) && ($poll_target = clean_input($_POST["poll_target"], "alphanumeric"))) {
                            $PROCESSED["poll_target"] = $poll_target;
                        } else {
                            $ERROR++;
                            $ERRORSTR[] = "You must select a valid target audience from the select box.";
                        }
                        if (isset($_POST["poll_question"]) && ($poll_question = clean_input($_POST["poll_question"], array("trim")))) {
                            $PROCESSED["poll_question"] = $poll_question;
                        } else {