You are here

function forena_admin_params_form in Forena Reports 6

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \forena_admin_params_form()
  2. 7 forena.admin.inc \forena_admin_params_form()
  3. 7.2 forena.admin.inc \forena_admin_params_form()
  4. 7.3 forena.admin.inc \forena_admin_params_form()
1 string reference to 'forena_admin_params_form'
forena_admin_params in ./forena.module
Calls forena_admin_params_form in forena.admin.inc edit and save param values.

File

./forena.admin.inc, line 1248

Code

function forena_admin_params_form($form_state) {
  $desc = forena_report_desc();
  $name = $desc['name'];
  $filename = $desc['filename'];
  $format = $desc['format'];
  if ($desc['exists'] || !$name) {
    $r = forena_get_report_editor($name);
    drupal_set_title($r->title);
    $form = array();
    $form['rpt_name'] = array(
      '#type' => 'value',
      '#value' => $name,
    );
    if ($r) {
      $nodes = $r->simplexml
        ->xpath('head/frx:parameters/frx:parm');
    }
    if ($nodes) {
      $form['params'] = array(
        '#tree' => TRUE,
      );
      foreach ($nodes as $node) {
        $attrs = $node
          ->attributes();
        $id = (string) $attrs['id'];
        $label = (string) $attrs['label'];
        $value = (string) $attrs['value'] ? (string) $attrs['value'] : (string) $node;
        $require = (string) $attrs['require'];
        $data_source = (string) $attrs['data_source'];
        $data_field = (string) $attrs['data_field'];
        $desc = (string) $attrs['desc'];
        $type = (string) $attrs['type'];

        //make a subtree for each param
        $form['params'][$id] = array(
          '#tree' => TRUE,
          '#type' => 'fieldset',
          '#title' => $label ? $label : $id,
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form['params'][$id]['id'] = array(
          '#type' => 'textfield',
          '#title' => t('id'),
          '#default_value' => $id,
          '#required' => TRUE,
          '#description' => t('The name of the parameter to be filtered against.'),
        );
        $form['params'][$id]['label'] = array(
          '#type' => 'textfield',
          '#title' => t('label'),
          '#default_value' => $label,
          '#required' => FALSE,
          '#description' => t('A descriptive name of the parameter to be displayed on a form.'),
        );
        $form['params'][$id]['require'] = array(
          '#type' => 'radios',
          '#title' => t('require'),
          '#default_value' => $require ? $require : "0",
          '#options' => array(
            "1" => t('Yes'),
            "0" => t('No'),
          ),
          '#description' => t('Requires a value for this parameter to display the report. If there is not a default value, the user will be prompted to enter a value.'),
        );
        $form['params'][$id]['value'] = array(
          '#type' => 'textfield',
          '#title' => 'default value',
          '#default_value' => $value,
          '#description' => t('The value of the parameter for the initial view of the report.'),
        );
        $form['params'][$id]['desc'] = array(
          '#type' => 'textfield',
          '#title' => t('description'),
          '#default_value' => $desc,
          '#description' => t('Enter a helpful description about this parameter. This will display on the form when the user is prompted to enter a parameter.'),
        );
        $form['params'][$id]['data_source'] = array(
          '#type' => 'textfield',
          '#title' => t('Data Source'),
          '#default_value' => $data_source,
          '#autocomplete_path' => 'forena/data_block/autocomplete',
          '#description' => t('Data block to be used for list of values'),
        );
        $form['params'][$id]['data_field'] = array(
          '#type' => 'textfield',
          '#title' => t('Data Field'),
          '#default_value' => $data_field,
          '#description' => t('Column in data block to be used for ID'),
        );
        $form['params'][$id]['type'] = array(
          '#type' => 'select',
          '#title' => t('Input Control'),
          '#default_value' => $type,
          '#options' => array(
            'textfield' => 'Text Input',
            'radios' => 'Radios',
            'select' => 'Select',
            'multiselect' => 'Multi-Select',
            'checkboxes' => 'Checkboxes',
          ),
          '#description' => t('Enter a helpful description about this parameter. This will display on the form when the user is prompted to enter a parameter.'),
        );
        $form['params'][$id]['delete_ind'] = array(
          '#type' => 'checkbox',
          '#title' => 'Remove this parameter',
          '#description' => t('Check to remove this parameter, then save'),
        );
      }
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
      );
      return $form;
    }
  }
}