You are here

function forena_data_select_block_submit in Forena Reports 7.2

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \forena_data_select_block_submit()
  2. 7.3 forena.admin.inc \forena_data_select_block_submit()
1 string reference to 'forena_data_select_block_submit'
forena_add_data_block_form in ./forena.admin.inc

File

./forena.admin.inc, line 1888

Code

function forena_data_select_block_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
  $values = $form_state['values'];
  $name = $values['report_name'];
  $data_block = $form_state['storage']['data_block'] = $values['data_block'];
  $params = $form_state['storage']['params'] = isset($values['params']) ? $values['params'] : array();
  $where_clause = $form_state['storage']['where_clause'] = $values['where_clause'];
  $parameters = $form_state['storage']['parm_data'] = $values['parameters'];
  $parms = isset($values['parms']) ? $values['parms'] : array();
  $xml = '';
  $block_info = '';
  if ($data_block) {

    //get xml from data block

    //check for and store parameters
    $block_info = FrxReportGenerator::instance()
      ->load_block($data_block, $where_clause);
    if ($block_info) {

      //if there were not any parameters passed. Use the report parameters
      if (!$parms) {
        $r = FrxReportGenerator::instance()
          ->get_report($values['report_name']);
        $rpt_params = $r->parameters;
        if ($rpt_params) {
          foreach ($block_info['tokens'] as $index => $id) {
            $parms[$id] = (string) @$rpt_params[$id];
          }
        }
      }
      drupal_alter('forena_parameters', $name, $parms);

      //now invoke the data provider with the correct params
      FrxData::instance()
        ->push($parms, 'parm');
      $form_state['storage']['parms'] = $params;
      $xml = FrxReportGenerator::instance()
        ->invoke_data_provider($data_block, $parms, $where_clause);
      if ($xml) {
        $form_state['storage']['step'] = 'select_template';
        $form_state['storage']['xml'] = $xml
          ->asXML();
        $form_state['storage']['parms'] = $parms;
      }
      else {
        $form_state['storage']['parameters'] = @$block_info['tokens'];
      }

      //create xml from template object
    }
  }
}