Exemplo n.º 1
0
/**
 * 
 * Закрыть/Открыть голосование
 * 
 * @param integer $thread_id   id треда
 */
function BlogsPoll_Close($thread_id)
{
    global $DB;
    require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/blogs.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/users.php";
    session_start();
    $uid = intval($_SESSION['uid']);
    $user = new users();
    $ban_where = $user->GetField($uid, $error, "ban_where");
    if ($ban_where == 1) {
        $objResponse->alert('Вам закрыт доступ в блоги');
        return $objResponse;
    }
    $thread_id = intval($thread_id);
    $objResponse = new xajaxResponse();
    $msg = $DB->row("\n\t\tSELECT bm.fromuser_id, bp.question, bp.multiple, bb.thread_id AS blocked\n\t\tFROM blogs_msgs AS bm \n\t\tLEFT JOIN blogs_poll AS bp ON bp.thread_id = bm.thread_id\n\t\tLEFT JOIN blogs_blocked AS bb ON bb.thread_id = bm.thread_id \n\t\tWHERE bm.thread_id = ? AND bm.reply_to IS NULL\n\t", $thread_id);
    if ($msg['question'] && (!$msg['blocked'] && $uid == $msg['fromuser_id'] || hasPermissions('blogs'))) {
        $blog = new blogs();
        $poll = $blog->Poll_Answers($thread_id);
        if ($blog->Poll_Close($thread_id)) {
            BlogsPoll_ShowClosed($thread_id, $objResponse, $poll);
        } else {
            if ($blog->Poll_Voted($uid, $thread_id)) {
                BlogsPoll_ShowResult($thread_id, $objResponse, $poll, 1);
            } else {
                $radio = $msg['multiple'] == 't' ? 0 : 1;
                BlogsPoll_ShowPoll($thread_id, $objResponse, $poll, $radio);
            }
        }
    }
    return $objResponse;
}