vote.php 2.01 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	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.

	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
*/

Scott committed
22 23 24 25 26 27
require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/cookies.php';
require_once QA_INCLUDE_DIR . 'app/votes.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
Scott committed
28 29


Scott committed
30 31 32
$postid = qa_post_text('postid');
$vote = qa_post_text('vote');
$code = qa_post_text('code');
Scott committed
33

Scott committed
34 35
$userid = qa_get_logged_in_userid();
$cookieid = qa_cookie_get();
Scott committed
36

37
if (!qa_check_form_security_code('vote', $code)) {
Scott committed
38
	$voteerror = qa_lang_html('misc/form_security_reload');
39
} else {
Scott committed
40 41 42
	$post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
	$voteerror = qa_vote_error_html($post, $vote, $userid, qa_request());
}
Scott committed
43

Scott committed
44 45
if ($voteerror === false) {
	qa_vote_set($post, $userid, qa_get_logged_in_handle(), $cookieid, $vote);
Scott committed
46

Scott committed
47
	$post = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $postid));
Scott committed
48

Scott committed
49 50 51
	$fields = qa_post_html_fields($post, $userid, $cookieid, array(), null, array(
		'voteview' => qa_get_vote_view($post, true), // behave as if on question page since the vote succeeded
	));
Scott committed
52

Scott committed
53 54
	$themeclass = qa_load_theme_class(qa_get_site_theme(), 'voting', null, null);
	$themeclass->initialize();
Scott committed
55

Scott committed
56 57
	echo "QA_AJAX_RESPONSE\n1\n";
	$themeclass->voting_inner_html($fields);
Scott committed
58

Scott committed
59
	return;
Scott committed
60

Scott committed
61
}
Scott committed
62

Scott committed
63
echo "QA_AJAX_RESPONSE\n0\n" . $voteerror;