You are here

function biblio_import_form in Bibliography Module 6.2

Same name and namespace in other branches
  1. 6 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()

Defines a form used to import files into biblio.

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

File

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

Code

function biblio_import_form(&$form_state) {
  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(s)'),
      '#description' => t('If you are using FireFox 3.6 or newer, you may select multiple files for import (they must all be of the same type).'),
      '#name' => 'biblio_import_mult[]',
      '#attributes' => array(
        'multiple' => '',
      ),
      '#default_value' => '',
      '#size' => 60,
    );
    $form['filetype'] = array(
      '#type' => 'select',
      '#title' => t('File Type'),
      '#default_value' => 0,
      '#options' => array(
        '0' => t('Select type'),
      ),
    );
    $other_options = module_invoke_all('biblio_import_options');
    $form['filetype']['#options'] = array_merge($form['filetype']['#options'], $other_options);
    asort($form['filetype']['#options']);
    $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', '');
  }
}