$app->render(400, array('error' => true, 'msg' => 'Not JSON'));
        }
    });
    $app->delete('/:id', function ($id) use($app) {
        $session = new Session($id);
        $session->delete();
        Notify(ADMIN_TOPIC, array('action' => 'delete', 'session' => $id));
        $app->render(200, array());
    });
    $app->put('/:id/:index', function ($id, $index) use($app) {
        $session = new Session($id);
        $result = json_decode($app->request->getBody(), true);
        if (false != $result) {
            $index = $session->saveResult($result, $index);
            $result['id'] = $index;
            Notify(ADMIN_TOPIC, array('action' => 'result', 'session' => $session->getInfo(), 'result' => $result));
            $app->render(200, array());
        } else {
            $app->render(400, array('error' => true, 'msg' => 'Not JSON'));
        }
    });
    $app->options('/:param+', function ($param) use($app) {
        $app->render(200, array());
    });
});
$app->group('/references', function () use($app) {
    $app->get('/', function () use($app) {
        $references = array();
        if ($dh = opendir(REFERENCE_DIR)) {
            while (($file = readdir($dh)) !== false) {
                if (Reference::isValidResults($file)) {