You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
![]()
13 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* Ajax controller. Dispatch request and perform required action.
|
||
|
*
|
||
|
*
|
||
|
* Usage:
|
||
|
*
|
||
|
* $controller = AjaxController::instance();
|
||
|
* $controller->run();
|
||
|
*
|
||
|
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
|
||
|
* @license /license.txt
|
||
|
*/
|
||
|
class AjaxController extends \Controller
|
||
|
{
|
||
|
|
||
|
function forbidden()
|
||
|
{
|
||
|
$this->response(false, get_lang('YourAreNotAuthorized'));
|
||
|
}
|
||
|
|
||
|
public function unknown()
|
||
|
{
|
||
|
$this->response(false, get_lang('UnknownAction'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Action exists but implementation is missing.
|
||
|
*/
|
||
|
public function missing()
|
||
|
{
|
||
|
$this->response(false, get_lang('NoImplementation'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Display a standard json responce.
|
||
|
*
|
||
|
* @param bool $success
|
||
|
* @param string $message
|
||
|
* @param object $data
|
||
|
*/
|
||
|
public function response($success = false, $message = '', $data = null)
|
||
|
{
|
||
|
$message = trim($message);
|
||
|
$response = (object) array();
|
||
|
$response->success = $success;
|
||
|
if ($message) {
|
||
|
$response->message = Display::return_message($message, $success ? 'normal' : 'error');
|
||
|
} else {
|
||
|
$response->message = '';
|
||
|
}
|
||
|
$response->data = $data;
|
||
|
$this->render_json($response);
|
||
|
}
|
||
|
|
||
|
}
|