You are here

function forena_settings_validate in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 forena_ui/forena.admin.inc \forena_settings_validate()
  2. 7.4 forena.admin.inc \forena_settings_validate()

File

./forena.admin.inc, line 209

Code

function forena_settings_validate($form, &$form_state) {
  $values = $form_state['values'];
  if (!$values['forena_input_format_enabled']) {
    $form_state['values']['forena_input_format'] = 'none';
  }
  $path = $values['forena_report_repos'];
  if ($path != $values['forena_last_report_path']) {
    if (!file_exists($path)) {
      try {
        mkdir($path);
        if (file_exists($path)) {
          drupal_set_message(t('Created Report Directory %s', array(
            '%s' => $path,
          )));
        }
      } catch (Exception $e) {
        Frx::error(t('Unable to create Report Directory'), $e
          ->getMessage());
      }
    }
  }
  if (!file_exists($path)) {
    form_set_error('forena_report_repos', t('Report Directory (') . $path . t(') does not exist'));
  }
  else {
    if (!is_writable($path)) {
      form_set_error('forena_report_repos', t('Report Directory (') . $path . t(') must be writable by the web user'));
    }
  }
  if (isset($values['forena_query_data_path'])) {
    $path = $values['forena_query_data_path'];
    if ($path != $values['forena_last_query_data_path']) {
      if (!file_exists($path)) {
        try {
          mkdir($path);
          if (file_exists($path)) {
            drupal_set_message(t('Created Custom Data Block Directory %s', array(
              '%s' => $path,
            )));
          }
        } catch (Exception $e) {
          Frx::error(t('Unable to create Custom Data Block Directory'), $e
            ->getMessage());
        }
      }
    }
    if (!file_exists($path)) {
      form_set_error('forena_query_data_path', t('Custom Data Block Directory (') . $path . t(') does not exist'));
    }
    else {
      if (!is_writable($path)) {
        form_set_error('forena_query_data_path', t('Custom Data Block Directory (') . $path . t(') must be writable by the web user'));
      }
    }
  }
}