2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
|
|
|
|
if(!isset($_POST['topicid']) || !is_number($_POST['topicid'])) { error(0,true); }
|
|
|
|
$TopicID = $_POST['topicid'];
|
|
|
|
|
|
|
|
if (!empty($_POST['large'])) {
|
|
|
|
$Size = 750;
|
|
|
|
} else {
|
|
|
|
$Size = 140;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$ThreadInfo = $Cache->get_value('thread_'.$TopicID.'_info')) {
|
|
|
|
$DB->query("SELECT
|
|
|
|
t.Title,
|
|
|
|
t.ForumID,
|
|
|
|
t.IsLocked,
|
|
|
|
t.IsSticky,
|
|
|
|
COUNT(fp.id) AS Posts,
|
|
|
|
t.LastPostAuthorID,
|
|
|
|
ISNULL(p.TopicID) AS NoPoll
|
|
|
|
FROM forums_topics AS t
|
|
|
|
JOIN forums_posts AS fp ON fp.TopicID = t.ID
|
|
|
|
LEFT JOIN forums_polls AS p ON p.TopicID=t.ID
|
|
|
|
WHERE t.ID = '$TopicID'
|
|
|
|
GROUP BY fp.TopicID");
|
|
|
|
if($DB->record_count()==0) { die(); }
|
|
|
|
$ThreadInfo = $DB->next_record(MYSQLI_ASSOC);
|
|
|
|
if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
|
|
|
|
$Cache->cache_value('thread_'.$TopicID.'_info', $ThreadInfo, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ForumID = $ThreadInfo['ForumID'];
|
|
|
|
|
|
|
|
if (!list($Question,$Answers,$Votes,$Featured,$Closed) = $Cache->get_value('polls_'.$TopicID)) {
|
|
|
|
$DB->query("SELECT Question, Answers, Featured, Closed FROM forums_polls WHERE TopicID='".$TopicID."'");
|
|
|
|
list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
|
|
|
|
$Answers = unserialize($Answers);
|
|
|
|
$DB->query("SELECT Vote, COUNT(UserID) FROM forums_polls_votes WHERE TopicID='$TopicID' AND Vote <> '0' GROUP BY Vote");
|
|
|
|
$VoteArray = $DB->to_array(false, MYSQLI_NUM);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$Votes = array();
|
|
|
|
foreach ($VoteArray as $VoteSet) {
|
2013-02-22 08:00:24 +00:00
|
|
|
list($Key,$Value) = $VoteSet;
|
2011-03-28 14:21:28 +00:00
|
|
|
$Votes[$Key] = $Value;
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
for ($i = 1, $il = count($Answers); $i <= $il; ++$i) {
|
|
|
|
if (!isset($Votes[$i])) {
|
|
|
|
$Votes[$i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$Cache->cache_value('polls_'.$TopicID, array($Question,$Answers,$Votes,$Featured,$Closed), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($Closed) {
|
|
|
|
error(403,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($Votes)) {
|
|
|
|
$TotalVotes = array_sum($Votes);
|
|
|
|
$MaxVotes = max($Votes);
|
|
|
|
} else {
|
|
|
|
$TotalVotes = 0;
|
|
|
|
$MaxVotes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($_POST['vote']) || !is_number($_POST['vote'])) {
|
|
|
|
?>
|
|
|
|
<span class="error">Please select an option.</span><br />
|
2013-01-15 08:00:37 +00:00
|
|
|
<form class="vote_form" name="poll" id="poll" action="">
|
2012-09-19 08:00:35 +00:00
|
|
|
<input type="hidden" name="action" value="poll" />
|
2011-03-28 14:21:28 +00:00
|
|
|
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
|
2012-09-19 08:00:35 +00:00
|
|
|
<input type="hidden" name="large" value="<?=display_str($_POST['large'])?>" />
|
2011-03-28 14:21:28 +00:00
|
|
|
<input type="hidden" name="topicid" value="<?=$TopicID?>" />
|
|
|
|
<? for ($i = 1, $il = count($Answers); $i <= $il; $i++) { ?>
|
|
|
|
<input type="radio" name="vote" id="answer_<?=$i?>" value="<?=$i?>" />
|
|
|
|
<label for="answer_<?=$i?>"><?=display_str($Answers[$i])?></label><br />
|
|
|
|
<? } ?>
|
|
|
|
<br /><input type="radio" name="vote" id="answer_0" value="0" /> <label for="answer_0">Blank - Show the results!</label><br /><br />
|
2012-09-15 08:00:25 +00:00
|
|
|
<input type="button" onclick="ajax.post('index.php','poll',function(response){$('#poll_container').raw().innerHTML = response});" value="Vote" />
|
2011-03-28 14:21:28 +00:00
|
|
|
</form>
|
|
|
|
<?
|
|
|
|
} else {
|
|
|
|
authorize();
|
|
|
|
$Vote = $_POST['vote'];
|
|
|
|
if (!isset($Answers[$Vote]) && $Vote != 0) { error(0,true); }
|
|
|
|
|
|
|
|
//Add our vote
|
|
|
|
$DB->query('INSERT IGNORE INTO forums_polls_votes (TopicID, UserID, Vote) VALUES ('.$TopicID.','.$LoggedUser['ID'].','.$Vote.')');
|
|
|
|
if ($DB->affected_rows() == 1 && $Vote != 0) {
|
|
|
|
$Cache->begin_transaction('polls_'.$TopicID);
|
|
|
|
$Cache->update_row(2, array($Vote => '+1'));
|
|
|
|
$Cache->commit_transaction(0);
|
|
|
|
$Votes[$Vote]++;
|
|
|
|
$TotalVotes++;
|
|
|
|
$MaxVotes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Vote != 0) {
|
|
|
|
$Answers[$Vote] = '=> '.$Answers[$Vote];
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
<ul class="poll nobullet">
|
|
|
|
<?
|
|
|
|
if($ForumID != STAFF_FORUM) {
|
|
|
|
for ($i = 1, $il = count($Answers); $i <= $il; $i++) {
|
|
|
|
if (!empty($Votes[$i]) && $TotalVotes > 0) {
|
|
|
|
$Ratio = $Votes[$i]/$MaxVotes;
|
|
|
|
$Percent = $Votes[$i]/$TotalVotes;
|
|
|
|
} else {
|
|
|
|
$Ratio=0;
|
|
|
|
$Percent=0;
|
2013-02-22 08:00:24 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<li><?=display_str($Answers[$i])?> (<?=number_format($Percent*100,2)?>%)</li>
|
|
|
|
<li class="graph">
|
|
|
|
<span class="left_poll"></span>
|
|
|
|
<span class="center_poll" style="width:<?=round($Ratio*$Size)?>px;"></span>
|
|
|
|
<span class="right_poll"></span>
|
|
|
|
</li>
|
|
|
|
<? }
|
|
|
|
} else {
|
|
|
|
//Staff forum, output voters, not percentages
|
2013-02-22 08:00:24 +00:00
|
|
|
$DB->query("SELECT GROUP_CONCAT(um.Username SEPARATOR ', '),
|
|
|
|
fpv.Vote
|
|
|
|
FROM users_main AS um
|
2011-03-28 14:21:28 +00:00
|
|
|
JOIN forums_polls_votes AS fpv ON um.ID = fpv.UserID
|
|
|
|
WHERE TopicID = ".$TopicID."
|
|
|
|
GROUP BY fpv.Vote");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$StaffVotes = $DB->to_array();
|
|
|
|
foreach($StaffVotes as $StaffVote) {
|
|
|
|
list($StaffString, $StaffVoted) = $StaffVote;
|
|
|
|
?>
|
|
|
|
<li><a href="forums.php?action=change_vote&threadid=<?=$TopicID?>&auth=<?=$LoggedUser['AuthKey']?>&vote=<?=(int) $StaffVoted?>"><?=display_str(empty($Answers[$StaffVoted]) ? "Blank" : $Answers[$StaffVoted])?></a> - <?=$StaffString?></li>
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</ul>
|
|
|
|
<br /><strong>Votes:</strong> <?=number_format($TotalVotes)?>
|
|
|
|
<?
|
|
|
|
}
|