Gazelle/sections/forums/poll_mod.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
authorize();
2013-05-05 08:00:31 +00:00
if (!check_perms('forums_polls_moderate')) {
error(403,true);
}
if (!isset($_POST['topicid']) || !is_number($_POST['topicid'])) {
error(0,true);
}
2011-03-28 14:21:28 +00:00
$TopicID = $_POST['topicid'];
//Currently serves as a Featured Toggle
if (!list($Question,$Answers,$Votes,$Featured,$Closed) = $Cache->get_value('polls_'.$TopicID)) {
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT Question, Answers, Featured, Closed
FROM forums_polls
WHERE TopicID='".$TopicID."'");
2011-03-28 14:21:28 +00:00
list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
$Answers = unserialize($Answers);
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT Vote, COUNT(UserID)
FROM forums_polls_votes
2013-05-27 08:00:58 +00:00
WHERE TopicID = '$TopicID'
AND Vote != '0'
2013-05-05 08:00:31 +00:00
GROUP BY Vote");
2011-03-28 14:21:28 +00:00
$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;
}
}
}
if (isset($_POST['feature'])) {
if (!$Featured || $Featured == '0000-00-00 00:00:00') {
$Featured = sqltime();
$Cache->cache_value('polls_featured',$TopicID,0);
2013-05-05 08:00:31 +00:00
$DB->query('
UPDATE forums_polls
SET Featured=\''.sqltime().'\'
WHERE TopicID=\''.$TopicID.'\'');
2011-03-28 14:21:28 +00:00
}
}
if (isset($_POST['close'])) {
$Closed = !$Closed;
2013-05-05 08:00:31 +00:00
$DB->query('
UPDATE forums_polls
SET Closed=\''.$Closed.'\'
WHERE TopicID=\''.$TopicID.'\'');
2011-03-28 14:21:28 +00:00
}
$Cache->cache_value('polls_'.$TopicID, array($Question,$Answers,$Votes,$Featured,$Closed), 0);
header('Location: '.$_SERVER['HTTP_REFERER']);
die();