You are here

function biblio_import_form in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 includes/biblio.import.export.inc \biblio_import_form()
  2. 7 includes/biblio.import.export.inc \biblio_import_form()
  3. 7.2 includes/biblio.import.export.inc \biblio_import_form()

Return a form used to import files into biblio.

Return value

An array which will be used by the form builder to build the import form

2 string references to 'biblio_import_form'
biblio_import_form_validate in ./biblio.import.export.inc
Implementation of hook_validate() for the biblio_import_form.
biblio_menu in ./biblio.module
Implementation of hook_menu().

File

./biblio.import.export.inc, line 58
Functions that are used to import and export biblio data.

Code

function biblio_import_form() {
  global $user;
  if (biblio_access('import')) {

    // && !user_access('administer nodes')) {
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['biblio_import_file'] = array(
      '#type' => 'file',
      '#title' => t('Import file'),
      '#default_value' => '',
      '#size' => 60,
    );
    $import_formats = array(
      'none' => t('Select type'),
      'bib' => t('BibTex'),
      'tagged' => t('EndNote Tagged'),
      'xml' => t('EndNote 7 XML (and previous versions)'),
      'xml8' => t('EndNote 8 XML (and newer versions)'),
      'marc' => t('MARC'),
      'ris' => t('RIS'),
    );
    if (module_exists('biblio_pm')) {
      $import_formats['pubmed'] = t('PubMed ID List');
      $import_formats['pubmed_xml'] = t('PubMed XML');
    }
    $form['filetype'] = array(
      '#type' => 'select',
      '#title' => t('File Type'),
      '#default_value' => 0,
      '#options' => $import_formats,
    );
    $form['batch_process'] = array(
      '#type' => 'checkbox',
      '#title' => t('Batch Process'),
      '#default_value' => 1,
      '#description' => t('You should use batch processing if your import file contains more than about 20 records, or if you are experiencing script timeouts during import'),
    );
    $form['userid'] = _biblio_admin_build_user_select($user->uid);

    // Get the vocabularies  attached to the biblio node type ...
    $vocabularies = module_invoke('taxonomy', 'get_vocabularies', 'biblio');

    // ... and print a form to select the terms in each of them
    $form['import_taxonomy'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Taxonomy Settings'),
      '#description' => t('Typically you don\'t have to do anything here, however if you wish, you may select terms to be assigned to imported records. This effectively adds a keyword to all entries being imported.'),
    );
    if (count($vocabularies)) {
      if (variable_get('biblio_keyword_freetagging', 0)) {
        $freetag_vocab = $vocabularies[variable_get('biblio_keyword_vocabulary', 0)];
        unset($vocabularies[variable_get('biblio_keyword_vocabulary', 0)]);
        $msg = t('<b>NOTE:</b> Keyword "free tagging" is turned on, consequently all incomming keywords will be added to the <b>@name</b> vocabulary as specified in the "Keyword" section of the !url page.', array(
          '@name' => $freetag_vocab->name,
          '!url' => l(t('admin/settings/biblio'), 'admin/settings/biblio'),
        ));
      }
      else {
        $msg = t('<b>NOTE:</b> Keyword "free tagging" is turned off, consequently keywords will <b>NOT</b> be added to the vocabulary as specified in the Taxonomy section of the !url page.', array(
          '!url' => l(t('admin/settings/biblio'), 'admin/settings/biblio'),
        ));
      }
      $i = 0;
      foreach ($vocabularies as $vocabulary) {
        $form['import_taxonomy']['vocabulary' . $i] = module_invoke('taxonomy', 'form', $vocabulary->vid, 0);
        $form['import_taxonomy']['vocabulary' . $i]['#weight'] = $vocabulary->weight;
        $form['import_taxonomy']['vocabulary' . $i++]['#description'] = t("Select taxonomy term to be assigned to imported entries");
      }
      $form['import_taxonomy']['copy_to_biblio'] = array(
        '#type' => 'checkbox',
        '#title' => t('Copy these terms to the biblio keyword database'),
        '#return_value' => 1,
        '#default_value' => variable_get('biblio_copy_taxo_terms_to_keywords', 0),
        '#description' => t('If this option is selected, the selected taxonomy terms will be copied to the @biblio_title keyword database and be displayed as keywords (as well as taxonomy terms) for this entry.', array(
          '@biblio_title' => variable_get('biblio_base_title', 'Biblio'),
        )),
      );
    }
    else {
      if (module_exists('taxonomy')) {
        $vocab_msg = t('There are currently no vocabularies assigned to the biblio node type, please go the the !url page to fix this', array(
          '!url' => l(t('admin/content/taxonomy'), 'admin/content/taxonomy'),
        ));
      }
      else {
        $vocab_msg = '<div class="admin-dependencies">' . t('Depends on') . ': ' . t('Taxonomy') . ' (<span class="admin-disabled">' . t('disabled') . '</span>)</div>';
      }
      $form['import_taxonomy']['vocabulary_message'] = array(
        '#value' => '<p><div>' . $vocab_msg . '</div></p>',
      );
    }
    $form['import_taxonomy']['freetagging_information'] = array(
      '#value' => '<p><div>' . $msg . '</div></p>',
    );
    $form['button'] = array(
      '#type' => 'submit',
      '#value' => t('Import'),
    );
    return $form;
  }
  else {
    drupal_set_message("You are not authorized to access the biblio import page", 'error');
    print theme('page', '');
  }
}