Exemple #1
0
 private function create_ajax_request()
 {
     $ajax = new Ajax_Request();
     $path = $this->path . '/editor/map-creator.php';
     $ajax->send($path);
 }
Exemple #2
0
 /**
  * Handle an Ajax Request
  * @param Ajax_Request $request
  * @return Json_Response or Json_Exception if the invoked class or method
  *  is not found or not callable or if the invokation is not allowed or
  *  throws an exception
  */
 public function handle(Ajax_Request $request)
 {
     try {
         if (isset($this->register[$request->getClass()])) {
             if (in_array($request->getMethod(), $this->register[$request->getClass()]['methods']) || is_null($this->register[$request->getClass()]['methods'])) {
                 if (!$this->register[$request->getClass()]['object']->isMethodInvokationAllowed($request)) {
                     throw new Exception('Remote method invokation not allowed : ' . $request->__toString());
                 }
                 if (is_callable(array($this->register[$request->getClass()]['object'], $request->getMethod()))) {
                     $response = call_user_func(array($this->register[$request->getClass()]['object'], $request->getMethod()), $request);
                     return new Json_Response(array('class' => $request->getClass(), 'method' => $request->getMethod(), 'parameters' => $request->getParameters(), 'response' => $response));
                 } else {
                     throw new Exception("Method not callable {$request->getMethod()} in class {$request->getClass()}");
                 }
             } else {
                 throw new Exception("Method not found {$request->getMethod()} in class {$request->getClass()}");
             }
         } else {
             throw new Exception("Class not found {$request->getClass()}");
         }
     } catch (Exception $e) {
         return new Json_Exception($e);
     }
 }
Exemple #3
0
 *  1. Register Ajax remote service in module functions.php
 *      Claroline::ajaxServiceBroker()->register( .... );
 *  2. Execute AJAX requests on get_path('url').'/claroline/backends/ajaxbroker.php'
 *
 * @version     $Revision: 14132 $
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 * @author      Claroline Team <*****@*****.**>
 * @author      Frederic Minne <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html
 *              GNU GENERAL PUBLIC LICENSE version 2 or later
 * @package     kernel.utils.ajax
 * @since       Claroline 1.10
 */
try {
    require_once dirname(__FILE__) . '/../inc/claro_init_global.inc.php';
    if (!get_conf('ajaxRemoteServiceBrokerEnabled', false)) {
        $response = new Json_Error("Ajax Remote Service is not available (you can allow it in the " . "claroline configuration advanced settings)");
    } else {
        $moduleLabel = Claro_UserInput::getInstance()->get('moduleLabel', false);
        if ($moduleLabel) {
            Ajax_Remote_Module_Service::registerModuleServiceInstance($moduleLabel);
        }
        $ajaxRequest = Ajax_Request::getRequest(Claro_UserInput::getInstance());
        $response = Claroline::ajaxServiceBroker()->handle($ajaxRequest);
    }
} catch (Exception $e) {
    $response = new Json_Exception($e);
}
header('Content-type: application/json; charset=utf-8');
echo $response->toJson();
exit;