getId();
if($currentUser->isBanned()) {
echo render_info_or_json($isXHR, 'You have been banned, check your profile for more information.', 403);
return;
}
if($currentUser->isSilenced()) {
echo render_info_or_json($isXHR, 'You have been silenced, check your profile for more information.', 403);
return;
}
header(CSRF::header());
if(empty($_POST['poll']['id']) || !ctype_digit($_POST['poll']['id'])) {
echo render_info_or_json($isXHR, "Invalid request.", 400);
return;
}
$poll = forum_poll_get($_POST['poll']['id']);
if(empty($poll)) {
echo "Poll {$poll['poll_id']} doesn't exist.
";
return;
}
$topicInfo = forum_poll_get_topic($poll['poll_id']);
if(!is_null($topicInfo['topic_locked'])) {
echo "The topic associated with this poll has been locked.
";
return;
}
if(!forum_perms_check_user(
MSZ_FORUM_PERMS_GENERAL, $topicInfo['forum_id'],
$currentUserId, MSZ_FORUM_PERM_SET_READ
)) {
echo "You aren't allowed to vote on this poll.
";
return;
}
if($poll['poll_expired']) {
echo "Voting for poll {$poll['poll_id']} has closed.
";
return;
}
if(!$poll['poll_change_vote'] && forum_poll_has_voted($currentUserId, $poll['poll_id'])) {
echo "Can't change vote for {$poll['poll_id']}
";
return;
}
$answers = !empty($_POST['poll']['answers'])
&& is_array($_POST['poll']['answers'])
? $_POST['poll']['answers']
: [];
if(count($answers) > $poll['poll_max_votes']) {
echo "Too many votes for poll {$poll['poll_id']}
";
return;
}
forum_poll_vote_remove($currentUserId, $poll['poll_id']);
foreach($answers as $answerId) {
if(!is_string($answerId) || !ctype_digit($answerId)
|| !forum_poll_validate_option($poll['poll_id'], (int)$answerId)) {
echo "Vote {$answerId} was invalid for {$poll['poll_id']}
";
continue;
}
forum_poll_vote_cast($currentUserId, $poll['poll_id'], (int)$answerId);
}
url_redirect('forum-topic', ['topic' => $topicInfo['topic_id']]);