You are here

function forena_layout_form_submit in Forena Reports 7

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

builds a string of the xml document, submits it to forena_save_report.

1 string reference to 'forena_layout_form_submit'
forena_layout_form in ./forena.admin.inc
Form function for the edit report form

File

./forena.admin.inc, line 597

Code

function forena_layout_form_submit($form, &$form_state) {
  $nodes = array();
  $values = $form_state['values'];
  $report_name = $values['save_report_name'];
  $r = forena_get_report_editor($report_name);

  // Title and category
  $r
    ->setTitle($values['title']);
  $r
    ->setCategory($values['category']);

  // Form options
  $options = array(
    'hidden' => $values['hidden'],
    'form' => $values['form'],
  );
  $r
    ->setOptions($options);

  // Doc gen settings.
  if (isset($form['docgen'])) {
    $docgen = array();
    if ($selected == array_filter($values['docgen']['docs'])) {
      foreach ($selected as $key => $value) {
        if ($value) {
          $docgen[] = array(
            'type' => $key,
          );
        }
      }
    }
    $r
      ->setDocgen($docgen);
  }

  // Body
  $r
    ->setBody($values['body']['value']);

  // If there are no frx attributes in the body then replace them with the old values.
  $frx_nodes = $r->simplexml
    ->xpath('body//*[@frx:block]');
  if (!$frx_nodes) {
    $r
      ->save_attributes_by_id($values['attributes']);
  }

  //determine redirection.
  $report_path = forena_report_path();
  $filename = $report_path . '/' . $report_name . '.frx';
  if (!file_exists($filename)) {
    $new_rpt = TRUE;
  }
  else {
    $new_rpt = FALSE;
  }
  if (forena_save_report($report_name, $r
    ->asXML(), TRUE) == 1) {
    drupal_set_message(t('Your report, %s has been saved.', array(
      '%s' => $report_name,
    )));

    //if this is a new report then redirect to data blocks
    if ($new_rpt) {
      $form_state['redirect'] = 'reports/' . str_replace('/', '.', $report_name) . '/data';
    }
    else {
      $form_state['redirect'] = 'reports/' . str_replace('/', '.', $report_name) . '/layout';
    }
  }
}