You are here

function forena_layout_form in Forena Reports 6

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

Form function for the edit report form

Parameters

$form_state:

Return value

the form

2 string references to 'forena_layout_form'
forena_add_report in ./forena.module
Add a new report from scratch in forena.admin.inc
forena_layout_report in ./forena.module
Calls forena_layout_form in forena.admin.inc

File

./forena.admin.inc, line 365

Code

function forena_layout_form($form_state, $new_report = '') {
  $desc = forena_report_desc();
  $name = $desc['name'];
  $add_new_rpt;

  //determine if this is an add new report request
  if ($new_report == 'add') {
    $add_new_rpt = TRUE;
  }
  $filename = $desc['filename'];
  $format = $desc['format'];
  if ($name) {
    if ($desc['exists'] || $add_new_rpt) {

      //set the name to empty string for new reports
      if ($add_new_rpt) {
        $name = '';
      }
      $r = forena_get_report_editor($name);
      if ($add_new_rpt) {
        $title = '';
        $options = '';
        $attributes = '';
        $report_form = '';
        $hidden = '0';
        $category = '';
        $head = '';
        $body = '';
      }
      else {
        $title = (string) $r->title;
        drupal_set_title(filter_xss($r->title));

        // Need to get all option attributes
        $frx_options = $r
          ->getOptions();
        $hidden = @$frx_options['hidden'] == '1' ? 1 : 0;
        $report_form = @$frx_options['form'];
        $attributes = $r
          ->get_attributes_by_id();
        $category = $r
          ->getCategory();
        $body = $r->simplexml->body
          ->asXML();
      }
      $form = array();

      //array of xml attributes that are required to have a value
      $required = array(
        'id' => TRUE,
        'label' => TRUE,
      );

      //list of supported document formats
      $supported = forena_supported_doctypes();
      $doclist = variable_get('forena_doc_formats', array());
      $form['report_name'] = array(
        '#type' => 'value',
        '#value' => $name,
      );
      $form['save_report_name'] = array(
        '#type' => 'textfield',
        '#title' => t('Report Name'),
        '#default_value' => $name,
        '#description' => t('Enter only letters, numbers, and special characters:  - _ /
                             <br/>White space is not permitted.
                             Create a directory using the format: (directory name) / (report name). Save multiple reports to the same directory
                             by referencing the same name.'),
        '#required' => TRUE,
      );
      $form['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#default_value' => $title,
      );
      $form['category'] = array(
        '#type' => 'textfield',
        '#title' => t('Category'),
        '#default_value' => $category,
        '#autocomplete_path' => 'forena/categories/autocomplete',
        '#description' => t('The heading your report will be grouped under on the report list.'),
      );
      $form['form'] = array(
        '#type' => 'textfield',
        '#title' => t('Form'),
        '#default_value' => $report_form,
        '#description' => t('The page style of your report, such as letter or landscape. The default form is letter.'),
      );
      $form['hidden'] = array(
        '#type' => 'checkbox',
        '#title' => t('Hidden'),
        '#default_value' => $hidden,
        '#description' => t('Hide your report from showing up on the report list.'),
      );

      //begin checking doc generation options
      if ($r) {
        $nodes = $r->simplexml->head
          ->xpath('frx:docgen/frx:doc');
      }
      if ($doclist) {
        $form['docgen'] = array(
          '#tree' => TRUE,
          '#type' => 'fieldset',
          '#title' => 'Document Options',
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#description' => t('These are document transformation options. Options selected will display as links in your report view.'),
        );

        //build the options and default list
        $options = array();
        $default = array();
        foreach ($doclist as $key => $value) {
          if (is_object(forena_get_doctypes($value))) {
            $options[$value] = strtoupper($value);
            if ($r) {
              $doc = $r->simplexml->head
                ->xpath('frx:docgen/frx:doc[@type="' . $value . '"]');
            }
            if ($doc && $doclist[$value]) {
              $default[$value] = $value;
            }
          }
        }

        //display checkboxes
        $form['docgen']['docs'] = array(
          '#type' => 'checkboxes',
          '#description' => t('*If no options are selected, the system will display all of the above as available for this report.'),
          '#options' => $options,
          '#default_value' => $default,
        );
      }
      $form['attributes'] = array(
        '#type' => 'value',
        '#value' => $attributes,
      );
      $form['body'] = array(
        '#type' => 'textarea',
        '#title' => t('Body'),
        '#default_value' => $body,
        '#rows' => 25,
      );
      $form['format'] = filter_form(variable_get('forena_input_format', FILTER_FORMAT_DEFAULT));
      $form['#validate'][] = 'forena_layout_form_validate';
      $form['buttons']['save'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
        '#submit' => array(
          'forena_layout_form_submit',
        ),
      );
      if (user_access('delete report')) {
        $form['buttons']['delete'] = array(
          '#type' => 'submit',
          '#value' => 'Delete',
          '#submit' => array(
            'forena_edit_delete_submit',
          ),
        );
      }
      return $form;
    }
    else {
      drupal_not_found();
    }
  }
  else {
    drupal_not_found();
  }
}