<?php

require dirname(dirname(__FILE__)) . '/includes/bootstrap.php';
if (isset($_POST['action'])) {
    if ($_POST['action'] == 'thumb-up' || $_POST['action'] == 'thumb-down') {
        if (!buckys_check_user_acl(USER_ACL_REGISTERED)) {
            $data = ['status' => 'error', 'message' => MSG_PLEASE_LOGIN_TO_CAST_VOTE];
        } else {
            if (!$_POST['objectID'] || !$_POST['objectIDHash'] || !$_POST['objectType'] || !buckys_check_id_encrypted($_POST['objectID'], $_POST['objectIDHash'])) {
                $data = ['status' => 'error', 'message' => MSG_INVALID_REQUEST];
            } else {
                if ($_POST['objectType'] == 'topic') {
                    $result = BuckysForumTopic::voteTopic($TNB_GLOBALS['user']['userID'], $_POST['objectID'], $_POST['action'] == 'thumb-up' ? 1 : -1);
                } else {
                    $result = BuckysForumReply::voteReply($TNB_GLOBALS['user']['userID'], $_POST['objectID'], $_POST['action'] == 'thumb-up' ? 1 : -1);
                }
                if (is_int($result)) {
                    $data = ['status' => 'success', 'message' => MSG_THANKS_YOUR_VOTE, 'votes' => ($result > 0 ? "+" : "") . $result];
                } else {
                    $data = ['status' => 'error', 'message' => $result];
                }
            }
        }
        render_result_xml($data);
        exit;
    }
} else {
    if (isset($_GET['action']) && $_GET['action'] == 'delete') {
        //Delete this topic
        $userID = buckys_is_logged_in();
        $topicID = isset($_GET['id']) ? get_secure_integer($_GET['id']) : null;