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);
$Votes = array();
foreach ($VoteArray as $VoteSet) {
list($Key,$Value) = $VoteSet;
$Votes[$Key] = $Value;
}
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'])) {
?>
Please select an option.