You are here

function forena_report_data_block_form in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 forena.report.inc \forena_report_data_block_form()
  2. 7.4 forena.report.inc \forena_report_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_report_data_block_form'
forena_menu in ./forena.module
Implementation of hook_menu.

File

./forena.report.inc, line 598

Code

function forena_report_data_block_form($formid, &$form_state, $report_name, $action, $block_name, $id = '') {
  $config = array();
  $r = Frx::Editor($report_name);

  // List of templates
  $templates = $r
    ->templateOptions();
  if (!isset($form_state['storage'])) {
    $form_state['storage']['id'] = $id;
    $parms = $_GET;
    unset($parms['q']);
    $form_state['storage']['parms'] = $parms;
  }
  $id = isset($form_state['storage']['id']) ? $form_state['storage']['id'] : $id;
  $template_class = isset($form_state['values']['template_class']) ? $form_state['values']['template_class'] : 'FrxTable';
  if (isset($form_state['values']['config'])) {
    $config = array_merge($form_state['storage']['config'], $form_state['values']['config']);
  }
  elseif ($id && $action != 'add-data') {
    $template_class = $r
      ->scrapeBlockConfig($id, $config);
  }
  $form_state['storage']['config'] = $config;

  //The default submit handler

  //If someone presses enter, this handler will execute
  $form['action'] = array(
    '#type' => 'value',
    '#value' => $action,
  );
  $form['add'] = array(
    '#type' => 'submit',
    '#value' => 'Add',
    '#submit' => array(
      'forena_report_add_template_submit',
    ),
    '#access' => $action == 'add-data',
  );
  $form['update'] = array(
    '#type' => 'submit',
    '#value' => 'Update',
    '#submit' => array(
      'forena_report_edit_template_submit',
    ),
    '#access' => $action == 'edit-data',
  );
  $form['prepend'] = array(
    '#type' => 'submit',
    '#value' => 'Insert',
    '#submit' => array(
      'forena_report_prepend_template_submit',
    ),
    '#access' => $action == 'prepend-data',
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => 'Cancel',
    '#submit' => array(
      'forena_update_cancel',
    ),
  );
  $form['report_name'] = array(
    '#type' => 'value',
    '#value' => $report_name,
  );
  $form['block_name'] = array(
    '#type' => 'value',
    '#value' => $block_name,
  );
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $id,
  );
  $form['template_class'] = array(
    '#type' => 'select',
    '#title' => t('Template'),
    '#options' => $templates,
    '#default_value' => $template_class,
    '#ajax' => array(
      'callback' => 'forena_template_callback',
      'wrapper' => 'forena-template-wrapper',
    ),
  );
  $form['template']['#prefix'] = '<div id="forena-template-wrapper">';
  $form['template']['#suffix'] = '</div>';
  $form['template']['config'] = array(
    '#type' => 'fieldset',
    '#title' => 'Settings',
    '#collapsible' => TRUE,
    "#tree" => TRUE,
  );

  // Generate Data block with preview
  $parms = $form_state['storage']['parms'];
  $r = Frx::Editor('__report_block_preview__');
  $r
    ->setEditorParms($parms);
  $r
    ->addBlock($block_name, $template_class, $config);
  $form['template']['config'] = array_merge($form['template']['config'], $r
    ->templateConfigForm($template_class, $config));
  $r
    ->update();
  $preview = $r
    ->preview($parms);
  $form['template']['preview_button'] = array(
    '#type' => 'button',
    '#value' => t('Preview'),
  );
  if (!$preview['#has_data']) {
    $path = "reports/{$report_name}/edit/preview-data/{$action}/{$block_name}";
    if ($id) {
      $path .= "/{$id}";
    }
    $options = array();
    if ($parms) {
      $options['query'] = Frx::parms();
    }
    drupal_goto("{$path}", $options);
  }
  $form['template']['preview']['content'] = $preview['content'];
  $r
    ->cancel();
  return $form;
}