function tripal_get_importer_form_validate

3.x tripal.importer.inc tripal_get_importer_form_validate($form, &$form_state)

Validate function for the tripal_get_importer_form form().

File

tripal/includes/tripal.importer.inc, line 112

Code

function tripal_get_importer_form_validate($form, &$form_state) {

  $class = $form_state['values']['importer_class'];
  tripal_load_include_importer_class($class);

  $file_local = NULL;
  $file_upload = NULL;
  $file_remote = NULL;
  $file_existing = NULL;

  // Get the form values for the file.
  if (array_key_exists('file_local', $class::$methods) and $class::$methods['file_local'] == TRUE) {
    $file_local = trim($form_state['values']['file_local']);
    // If the file is local make sure it exists on the local filesystem.
    if ($file_local) {
      // check to see if the file is located local to Drupal
      $file_local = trim($file_local);
      $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $file_local;
      if (!file_exists($dfile)) {
        // if not local to Drupal, the file must be someplace else, just use
        // the full path provided
        $dfile = $file_local;
      }
      if (!file_exists($dfile)) {
        form_set_error('file_local', t("Cannot find the file on the system. Check that the file exists or that the web server has permissions to read the file."));
      }
    }
  }
  if (array_key_exists('file_upload', $class::$methods) and $class::$methods['file_upload'] == TRUE) {
    $file_upload = trim($form_state['values']['file_upload']);
    if (array_key_exists('file_upload_existing', $form_state['values']) and $form_state['values']['file_upload_existing']) {
      $file_existing = $form_state['values']['file_upload_existing'];
    }
  }
  if (array_key_exists('file_remote', $class::$methods) and $class::$methods['file_remote'] == TRUE) {
    $file_remote = trim($form_state['values']['file_remote']);
  }

  // The user must provide at least an uploaded file or a local file path.
  if ($class::$file_required == TRUE and !$file_upload and !$file_local and !$file_remote and !$file_existing) {
    form_set_error('file_local', t("You must provide a file."));
  }

  // Now allow the loader to do validation of it's form additions.
  $importer = new $class();
  $importer->formValidate($form, $form_state);
}