Esempio n. 1
0
Session::start();
\Xily\Bean::$BEAN_DIRS[] = LIB_DIR . 'beans';
$pluginEvents = array('menu' => array('clocking', 'clockings', 'offtime', 'transaction', 'transactions'));
function registerPluginEvents($pluginEvents)
{
    foreach ($pluginEvents as $entity => $events) {
        foreach ($events as $event) {
            PluginPeer::registerEvent($entity, $event);
        }
    }
}
try {
    registerPluginEvents($pluginEvents);
    $userAuthenticated = APIFactory::getAuthenticator()->authUser(true, true, isset($_REQUEST['autologin']) && $_REQUEST['autologin'] == true);
    $user = APIFactory::getAuthenticator()->getUser();
    PluginPeer::setAuthenticatedUser($user);
    if (isset($_REQUEST['do'])) {
        /* PERFORM THE API CALL
        		-------------------------------------------------------------------- */
        $api = null;
        try {
            $apiName = array_key_exists('api', $_REQUEST) ? strtolower($_REQUEST['api']) : API_DEFAULT;
            $api = APIFactory::get($apiName);
            $api->run();
        } catch (Exception $e) {
            if ($e instanceof APIPermissionDeniedException and !empty($_REQUEST['inline'])) {
                HTTP::forwardTo($_SERVER['SCRIPT_NAME'] . '?view=login' . '&return=' . urlencode($_SERVER['REQUEST_URI']) . '&' . Form::getTokenName() . '=' . urlencode(Form::getToken('loginreturn')));
            } else {
                header('Content-Type: application/json; charset=utf-8');
                if ($api instanceof API) {
                    $res = $api->exceptionToResult($e);