You are here

function forena_admin_params_form in Forena Reports 7.3

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.2 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 2159

Code

function forena_admin_params_form($formid, $form_state, $report_name) {
  $desc = Frx::Menu()
    ->parseURL($report_name);
  if (!$desc['exists']) {
    drupal_not_found();
    exit;
  }
  $name = $desc['name'];
  $filename = $desc['filename'];
  $format = @$desc['format'];
  if ($desc['exists'] && $name) {

    // Set up basic control types.
    $control_types = array(
      'textfield' => 'Text',
      'hidden' => 'Hidden',
      'radios' => 'Radios',
      'checkbox' => 'Checkbox',
      'checkboxes' => 'Checkboxes',
      'select' => 'Select',
      'selectajax' => 'Select with Refresh',
      'multiselect' => 'Multi-Select',
      'multiselectajax' => 'Multi-select With Refresh',
    );

    // Supported module specific control types.
    if (module_exists('date_api')) {
      $control_types['date_select'] = 'Date Select';
    }
    if (module_exists('date_popup')) {
      $control_types['date_popup'] = 'Date Popup';
    }

    //Construct report editor
    $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'];
        $label_field = @(string) $attrs['label_field'];
        $class = @(string) $attrs['class'];
        $desc = @(string) $attrs['desc'];
        $type = @(string) $attrs['type'];
        $options = @(string) $attrs['options'];

        //make a subtree for each param
        $form['params'][$id] = array(
          '#tree' => TRUE,
          '#type' => 'fieldset',
          '#title' => $label ? $label . ' (' . $id . ')' : $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]['type'] = array(
          '#type' => 'select',
          '#title' => t('Input Control Type'),
          '#default_value' => $type,
          '#options' => $control_types,
          '#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 select, multiselect, and checkboxes types'),
        );
        $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 data of select boxes and radio buttons. '),
        );
        $form['params'][$id]['label_field'] = array(
          '#type' => 'textfield',
          '#title' => t('Label Field'),
          '#default_value' => $label_field,
          '#description' => t('Column in data block to be used for the label for selet boxes and radio buttons.'),
        );
        $form['params'][$id]['options'] = array(
          '#type' => 'textfield',
          '#title' => t('Options'),
          '#default_value' => $options,
          '#description' => t('Used to configure the control type above options depend on the control type above.'),
        );
        $form['params'][$id]['class'] = array(
          '#type' => 'textfield',
          '#title' => t('Class'),
          '#description' => t('Specify the html class you wish to apply to this parameter'),
          '#default_value' => $class,
        );
        $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();
  }
}