You are here

function forena_fields_form in Forena Reports 7.2

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

Parameters

$form_state:

Return value

a form to edit the fields of the report

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

File

./forena.admin.inc, line 1448

Code

function forena_fields_form($formid, $form_state, $report_name) {
  $desc = forena_report_desc($report_name);
  if (!$desc['exists']) {
    drupal_not_found();
    exit;
  }
  $name = $desc['name'];
  $filename = $desc['filename'];
  @($format = $desc['format']);
  if ($name) {
    if (file_exists($filename)) {
      $r = forena_get_report_editor($name);
      drupal_set_title($r->title);
      $regexp = FRX_TOKEN_EXP;
      $match = array(
        "{",
        "}",
      );

      /*search the body, looking for {}*/
      $body = $r->simplexml->body
        ->asXML();
      $head = $r->simplexml->head;
      $fields = array();
      preg_match_all($regexp, $body, $out);
      foreach ($out as $key => $value) {
        foreach ($value as $el) {
          $clean_element = str_replace($match, "", $el);
          $fields[$clean_element] = $clean_element;
        }
      }
      $form = array();
      $form['report_name'] = array(
        '#type' => 'value',
        '#value' => $name,
      );
      $form['fields'] = array(
        '#tree' => TRUE,
        '#type' => 'vertical_tabs',
      );

      /*Now check the fields in the body against the xml*/
      $i = 0;
      foreach ($fields as $field) {
        $i++;
        $field_ids[$i] = $field;
        $form['fields'][$i] = array(
          '#tree' => TRUE,
          '#type' => 'fieldset',
          '#title' => $field,
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#group' => 'additional_settings',
        );
        $path = 'frx:fields/frx:field[@id="' . $field . '"]';
        $node = $head
          ->xpath($path);
        $attr = array();
        $default = '';
        if ($node) {
          $attr = $node[0];
          $default = (string) $node[0];
        }
        $form['fields'][$i]['id'] = array(
          '#type' => 'value',
          '#value' => $field,
        );
        $form['fields'][$i]['format'] = array(
          '#type' => 'textfield',
          '#title' => t('format'),
          '#default_value' => @$attr['format'],
          '#size' => 30,
          '#autocomplete_path' => 'forena/fields/format/autocomplete',
          '#description' => t('Format a date and time field by entering the name of a supported format function. Enter a "*" to see all available formats.'),
        );
        $form['fields'][$i]['format-string'] = array(
          '#type' => 'textfield',
          '#title' => t('format-string'),
          '#default_value' => @$attr['format-string'],
          '#size' => 30,
          '#description' => t('The display type of your format.'),
        );
        $form['fields'][$i]['link'] = array(
          '#type' => 'textfield',
          '#title' => t('link'),
          '#default_value' => @$attr['link'],
          '#size' => 100,
          '#maxlength' => 256,
          '#description' => t('Create a link that incorporates this field, e.g "profile/{field_name}" will create a link to this field_name\'s profile. *Note the field must be wrapped in {}.'),
        );
        $form['fields'][$i]['rel'] = array(
          '#type' => 'textfield',
          '#title' => t('rel'),
          '#description' => t('Relationship attribute to apply to the link.'),
          '#size' => 100,
          '#maxlength' => 256,
          '#default_value' => @$attr['rel'],
        );
        $form['fields'][$i]['class'] = array(
          '#type' => 'textfield',
          '#title' => t('class'),
          '#description' => t('Class applied to be applied to the link.'),
          '#size' => 100,
          '#maxlength' => 256,
          '#default_value' => @$attr['class'],
        );
        $form['fields'][$i]['target'] = array(
          '#type' => 'textfield',
          '#title' => t('target'),
          '#default_value' => @$attr['target'],
          '#size' => 30,
          '#description' => t('Link target eg. _BLANK,  Targets that begin with "popup" will be opened in a new window using javascript.'),
        );
        $form['fields'][$i]['default'] = array(
          '#type' => 'textfield',
          '#title' => t('default value'),
          '#default_value' => $default,
          '#size' => 30,
          '#description' => t('The value to be displayed in the report when no value exists.'),
        );
      }
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
      );
      return $form;
    }
    else {
      drupal_not_found();
    }
  }
  else {
    drupal_not_found();
  }
}