You are here

function forena_data_block_form in Forena Reports 7.3

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \forena_data_block_form()
  2. 6 forena.admin.inc \forena_data_block_form()
  3. 7 forena.admin.inc \forena_data_block_form()
  4. 7.2 forena.admin.inc \forena_data_block_form()

A form to preview and add data blocks to an existing report

Parameters

$formid String representation fo form:

$form_state Array of block type:

Return value

unknown_type

1 string reference to 'forena_data_block_form'
forena_menu in ./forena.module
Implementation of hook_menu.

File

./forena.admin.inc, line 1770

Code

function forena_data_block_form($formid, &$form_state, $report_name) {
  $desc = Frx::Menu()
    ->parseURL($report_name);
  if (!$desc['exists']) {
    drupal_not_found();
    exit;
  }
  $name = $desc['name'];
  $filename = $desc['filename'];
  $format = isset($desc['format']) ? $desc['format'] : '';
  $r = forena_get_report_editor($name);
  drupal_set_title($r->title);
  $form = array();
  $title = (string) $r->title;
  $template_array = FrxReportGenerator::instance()
    ->supported_templates();
  @($default_template = $form_state['storage']['template']);
  @($params = $form_state['storage']['parameters']);
  @($param_values = $form_state['storage']['param_values']);
  $form = array();
  $form['report_name'] = array(
    '#type' => 'value',
    '#value' => $name,
  );
  $links = array();
  $links[] = array(
    'href' => $desc['link'] . '/edit/data/add',
    'title' => 'Add Data',
  );
  $form['add_link'] = array(
    '#type' => 'markup',
    '#markup' => theme('links', array(
      'links' => $links,
      'attributes' => array(
        'class' => 'action-links',
      ),
    )),
  );

  //The default submit handler

  //If someone presses enter, this handler will execute
  $form['default_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'forena_data_block_form_submit',
    ),
    '#prefix' => '<div style="visibility:hidden;float:right">',
    '#suffix' => '</div>',
  );

  //find the datablocks in the existing report
  $data_block_array = array();
  if ($r) {
    $r
      ->get_attributes_by_id();
  }
  $body = $r->simplexml->body;
  $path = '//*[@frx:block]';
  $form['blocks'] = array(
    '#tree' => TRUE,
    '#type' => 'vertical_tabs',
  );
  if ($body) {
    foreach ($body
      ->xpath($path) as $node) {
      $attrs = $node
        ->attributes(FRX_NS);
      $id = (string) $node['id'];
      $block = (string) $attrs['block'];
      $parameters = (string) $attrs['parameters'];
      $block_info = Frx::RepoMan()
        ->loadBlock($block);
      $access = @$block_info['access'];
      $data_block_array[$id] = $block . ": <i>" . ' security "' . $access . '"</i>';
      $ctl = array(
        '#type' => 'fieldset',
        '#title' => $id,
        '#group' => 'additional_settings',
      );
      $ctl['id'] = array(
        '#type' => 'value',
        '#value' => $id,
      );
      $ctl['block'] = array(
        '#type' => 'textfield',
        '#autocomplete_path' => 'forena/data_block/autocomplete',
        '#title' => 'Data Block',
        '#default_value' => $block,
        '#required' => TRUE,
        '#description' => t('The data block to be used as the source for the data in the report.'),
      );
      $ctl['access'] = array(
        '#type' => 'item',
        '#markup' => $access,
        '#title' => t('Security'),
      );
      $ctl['parameters'] = array(
        '#type' => 'textfield',
        '#title' => t('Parameters'),
        '#default_value' => $parameters,
        '#description' => t('Leave blank to use the current data context as parameters.  In a simple report this will be the parameters of the report.
          In master detail reports, this will be the report of the containing data block. Parameters should be specified in the form of a url string.'),
      );
      $ctl['delete'] = array(
        '#type' => 'checkbox',
        '#title' => 'Confirm delete',
        '#description' => t('Check this box to remove this data from the report.'),
      );
      $ctl['delete_submit'] = array(
        '#type' => 'submit',
        '#value' => 'Delete',
        '#submit' => array(
          'forena_data_block_delete',
        ),
      );
      $form['blocks'][] = $ctl;
    }
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );
  return $form;
}