You are here

function forena_admin_params_form in Forena Reports 7.2

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \forena_admin_params_form()
  2. 6 forena.admin.inc \forena_admin_params_form()
  3. 7 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_menu in ./forena.module
Implementation of hook_menu.

File

./forena.admin.inc, line 2337

Code

function forena_admin_params_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 ($desc['exists'] && $name) {
    $r = forena_get_report_editor($name);
    drupal_set_title($r->title);
    $form = array();
    $form['rpt_name'] = array(
      '#type' => 'value',
      '#value' => $name,
    );
    $links = array();
    $links[] = array(
      'href' => $desc['link'] . '/edit/params/add',
      'title' => 'Add Parameter',
    );
    $form['add_link'] = array(
      '#type' => 'markup',
      '#markup' => theme('links', array(
        'links' => $links,
        'attributes' => array(
          'class' => 'action-links',
        ),
      )),
    );
    if ($r) {
      $nodes = $r->simplexml
        ->xpath('head/frx:parameters/frx:parm');
    }
    if ($nodes) {
      $form['params'] = array(
        '#tree' => TRUE,
        '#type' => 'vertical_tabs',
      );
      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,
          '#group' => 'additional_settings',
        );
        $form['params'][$id]['id'] = array(
          '#type' => 'value',
          '#value' => $id,
        );
        $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 Type'),
          '#default_value' => $type,
          '#options' => array(
            'textfield' => 'Text',
            'radios' => 'Radios',
            'select' => 'Select',
            'selectajax' => 'Select with Refresh',
            '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;
  }
  else {
    drupal_not_found();
  }
}