qa-ajax-vote.php 2.18 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-ajax-vote.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Server-side response to Ajax voting requests


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	require_once QA_INCLUDE_DIR.'qa-app-users.php';
	require_once QA_INCLUDE_DIR.'qa-app-cookies.php';
	require_once QA_INCLUDE_DIR.'qa-app-votes.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';
	require_once QA_INCLUDE_DIR.'qa-app-options.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
Scott Vivian committed
33

Gideon Greenspan committed
34 35 36

	$postid=qa_post_text('postid');
	$vote=qa_post_text('vote');
Gideon Greenspan committed
37
	$code=qa_post_text('code');
Scott Vivian committed
38

Gideon Greenspan committed
39 40 41
	$userid=qa_get_logged_in_userid();
	$cookieid=qa_cookie_get();

Gideon Greenspan committed
42 43
	if (!qa_check_form_security_code('vote', $code))
		$voteerror=qa_lang_html('misc/form_security_reload');
Scott Vivian committed
44

Gideon Greenspan committed
45 46 47 48
	else {
		$post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
		$voteerror=qa_vote_error_html($post, $vote, $userid, qa_request());
	}
Scott Vivian committed
49

Gideon Greenspan committed
50 51
	if ($voteerror===false) {
		qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote);
Scott Vivian committed
52

Gideon Greenspan committed
53
		$post=qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
Scott Vivian committed
54

Gideon Greenspan committed
55
		$fields=qa_post_html_fields($post, $userid, $cookieid, array(), null, array(
Gideon Greenspan committed
56
			'voteview' => qa_get_vote_view($post, true), // behave as if on question page since the vote succeeded
Gideon Greenspan committed
57
		));
Scott Vivian committed
58

Gideon Greenspan committed
59 60 61 62 63 64 65
		$themeclass=qa_load_theme_class(qa_get_site_theme(), 'voting', null, null);

		echo "QA_AJAX_RESPONSE\n1\n";
		$themeclass->voting_inner_html($fields);

	} else
		echo "QA_AJAX_RESPONSE\n0\n".$voteerror;
Scott Vivian committed
66

Gideon Greenspan committed
67 68 69 70

/*
	Omit PHP closing tag to help avoid accidental output
*/