function gd_ext () {

    ob_get_clean();

    if ( !empty($_REQUEST['datasource']) ) {
        gd_datasource_set_active($_REQUEST['datasource']);
    }

    $ext = array();
    $dashboards = gd_dashboard_findall_by_datasource(LOAD_ENTITY);
    foreach ( $dashboards as $dashboard ) {
        $ext[] = array('id'=>$dashboard->nid,'title'=>$dashboard->title);
    }

    $response = new stdClass();
    $response->status = new stdClass();
    $response->status->code = 200;
    $response->status->message = 'OK';

    if ( isset($_REQUEST['id']) ) {
        $response->data = array('id'=>$_REQUEST['id'], 'title'=>$dashboards[$_REQUEST['id']]->title);
    }
    else {
        $response->data = $ext;
    }

    module_invoke_all('gd_ext_response_alter',$response);

    echo \GD\Utility\Json::getPayload($response,$_GET['callback']);

    gd_get_session_messages();

    drupal_exit();
}
/**
 * @param $dashboardNode
 * @param $reportNid
 * @return int|null
 */
function gd_dashboard_report_view ( $dashboardNode, $reportNid ) {
    ob_start();
    try {
        if ( !gd_dashboard_access_view($dashboardNode) ) {
            return MENU_ACCESS_DENIED;
        }

        $DashboardConfig = new GD_DashboardConfig($dashboardNode);
        gd_datasource_set_active($DashboardConfig->getDatasource());

        foreach ( $DashboardConfig->items as $item ) {
            if ( $reportNid == $item->content ) {
                $options = array();

                if (isset($_GET['dashboardBuilder']) && $_GET['dashboardBuilder'] == TRUE) {
                    $options['admin'] = TRUE;
                }

                if ( $DashboardConfig->isPublic() && arg(0) == 'public' ) {
                    $options['public'] = TRUE;
                }

                $html = $DashboardConfig->getItemReportView($item, $options);
                $output = array('header'=>$html->header, 'body'=>$html->body, 'footer'=>$html->footer);

                $response = new stdClass();
                $response->status = new stdClass();
                $response->status->code = 200;
                $response->status->message = 'OK';

                $response->data = $output;

                module_invoke_all('gd_ext_response_alter',$response);

                $messages = gd_get_session_messages();
                if ( !empty($messages['error']) ) {
                    $response->status->code = 500;
                    $response->status->message = $messages['error'];
                } else {
                    if ( !isset($_GET['callback']) && $DashboardConfig->isPublic() && arg(0) == 'public' ) {
                        drupal_add_http_header('Cache-Control','no-transform,public,max-age=3600,s-maxage=3600');
                        drupal_add_http_header('Expires',gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
                    }
                }

                echo \GD\Utility\Json::getPayload($response,$_GET['callback']);
            }
        }

        echo ob_get_clean();
        drupal_exit();
    } catch ( Exception $e ) {
        gd_exception_handler($e);
        $response = new stdClass();
        $response->status->code = 500;
        $response->status->message = $e->getMessage();
        echo \GD\Utility\Json::getPayload($response,$_GET['callback']);
        echo ob_get_clean();
        drupal_exit();
    }
}