recalc.php 1.36 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 admin recalculation 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
require_once QA_INCLUDE_DIR . 'app/users.php';
Scott committed
23 24


Scott committed
25 26 27 28 29
if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
	if (!qa_check_form_security_code('admin/recalc', qa_post_text('code'))) {
		$state = '';
		$message = qa_lang('misc/form_security_reload');
	} else {
30
		$recalc = new \Q2A\Recalc\RecalcMain(qa_post_text('state'));
Scott committed
31
		$stoptime = time() + 3;
Scott committed
32

33
		while ($recalc->performStep() && time() < $stoptime) {
34 35
			// wait
		}
Scott committed
36

37 38
		$message = $recalc->getMessage();
		$state = $recalc->getState();
Scott committed
39
	}
Scott committed
40 41 42 43
} else {
	$state = '';
	$message = qa_lang('admin/no_privileges');
}
Scott committed
44

pupi1985 committed
45 46 47 48
$response = array(
	'state' => $state,
	'message' => qa_html($message),
);
Scott committed
49

pupi1985 committed
50
echo json_encode($response);