You are here

function forena_add_report_form in Forena Reports 8

Same name and namespace in other branches
  1. 6.2 forena.admin.inc \forena_add_report_form()
  2. 7.5 forena.report.inc \forena_add_report_form()
  3. 7.2 forena.admin.inc \forena_add_report_form()
  4. 7.3 forena.admin.inc \forena_add_report_form()
  5. 7.4 forena.report.inc \forena_add_report_form()
1 call to forena_add_report_form()
forena_data_quick_report_form in forena_ui/forena.data.inc
Create a report quickly from a data block

File

./forena.report.inc, line 6

Code

function forena_add_report_form($formid, $form_state, $report_name = '') {
  $name = '';
  $filename = '';
  $format = '';
  if ($report_name) {
    $desc = Frx::Menu()
      ->parseURL($report_name);
    $name = $desc['name'];
    $filename = $desc['filename'];
    $format = @$desc['format'];
  }
  $form = array();
  $language = \Drupal::languageManager()
    ->getCurrentLanguage();

  //determine if this is an add new report request
  $r = Frx::Editor($name);
  $title = (string) $r->title;
  if (\Drupal::moduleHandler()
    ->moduleExists('locale')) {
    @(list($tlang, $tsave_name) = explode('/', $name, 2));

    // FInd out if the starting name of the report is an installed language.
    if (array_key_exists($tlang, locale_translatable_language_list())) {
      $lang = $tlang;
      $save_name = $tsave_name;
    }
    else {
      $lang = 'en';
    }
  }

  // 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();

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

  //list of supported document formats
  $doclist = \Drupal::config('forena.settings')
    ->get('forena_doc_formats');
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $title,
    '#required' => TRUE,
  );
  $form['report_name'] = array(
    '#type' => 'forena_machine_name',
    '#title' => t('Report 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,
    '#machine_name' => array(
      'source' => array(
        'report_name',
      ),
      'label' => 'Report_name',
    ),
  );
  $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['hidden'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hidden'),
    '#default_value' => $hidden,
    '#description' => t('Hide your report from showing up on the report list.'),
  );
  $form['clone_report_name'] = array(
    '#title' => t('Create from report'),
    '#type' => 'textfield',
    '#autocomplete_path' => 'forena/reports/autocomplete',
    '#default_value' => $name,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#validate' => array(
      'forena_validate_report_name',
    ),
    '#submit' => array(
      'forena_create_report_submit',
    ),
    '#value' => 'Create',
  );
  return $form;
}