You are here

function forena_query_editor in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 forena_query/forena_query.inc \forena_query_editor()
  2. 7.4 forena_query.inc \forena_query_editor()

Basic SQL Editor form hook implementation

_state

Parameters

unknown $form:

string $block_name:

Return value

multitype:NULL

1 string reference to 'forena_query_editor'
forena_query_menu in ./forena_query.module
Implementation of hook_menu

File

./forena_query.inc, line 81

Code

function forena_query_editor($form, &$form_state, $block_name = '') {
  static $first = TRUE;
  if ($first) {
    drupal_add_library('system', 'ui.autocomplete');
    $m_path = drupal_get_path('module', 'forena_query');
    drupal_add_js("{$m_path}/forena_query.js");
    drupal_add_css("{$m_path}/forena_query.css");
    @(list($repos, $name) = explode('.', $block_name));
    drupal_add_js(array(
      'forenaSQLEditor' => array(
        'repos' => $repos,
      ),
    ), 'setting');
    $first = FALSE;
  }
  $o = Frx::BlockEditor($block_name);
  $block = $o->block;
  if (!isset($form_state['storage'])) {
    $form_state['storage']['block_name'] = $block_name;
    $form_state['storage']['parameters'] = array();
    $form_state['storage']['block'] = $block;
  }
  drupal_set_title(str_replace('.', '/', $block_name));
  $block = $form_state['storage']['block'];
  $builder = isset($block['builder']) ? $block['builder'] : 'FrxQueryBuilder';
  $builders = $o
    ->builderList();
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['builder'] = array(
    '#type' => 'select',
    '#title' => t('Template'),
    '#options' => $builders,
    '#access' => FALSE,
    '#default_value' => $builder,
  );
  $form['advanced']['access'] = array(
    '#title' => t('Data Security'),
    '#description' => t('Value depends on the security for the data block,
            but for drupal data, this is a right as defined by the module provided.  '),
    '#type' => 'textfield',
    '#access' => user_access('forena data security'),
    '#default_value' => @$block['access'],
  );
  $form['config'] = $o
    ->configForm($builder, $block);
  $form['config']['#tree'] = 'true';
  $form['config']['#prefix'] = "<div id='query-builder-config'>\n";
  $form['config']['#suffix'] = '</div>';
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
    '#validate' => array(
      'forena_query_editor_validate',
    ),
    '#submit' => array(
      'forena_query_editor_update',
      'forena_query_save_block',
    ),
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#submit' => array(
      'forena_query_close',
    ),
    '#limit_validation_errors' => array(),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Test Changes'),
    '#submit' => array(
      'forena_query_editor_update',
      'forena_query_preview',
    ),
    '#ajax' => array(
      'callback' => 'forena_query_preview_ajax',
      'wrapper' => 'forena-query-preview',
    ),
  );
  $tokens = $o
    ->tokens();
  $form['preview'] = array(
    '#prefix' => '<div id="forena-query-preview">',
    '#suffix' => '</div>',
  );
  if ($tokens) {
    $form['preview']['parameters'] = array(
      '#title' => 'Parameters',
      '#type' => 'fieldset',
      '#tree' => TRUE,
    );
    foreach ($tokens as $name) {
      $ctl = array(
        '#type' => 'textfield',
        '#title' => check_plain($name),
      );
      $form['preview']['parameters'][$name] = $ctl;
    }
  }
  $form['preview']['report'] = @$form_state['storage']['preview'];
  return $form;
}