You are here

function regcode_ie_admin_import in Registration codes 7

Same name and namespace in other branches
  1. 6.2 regcode_ie/regcode_ie.module \regcode_ie_admin_import()
  2. 7.2 regcode_ie/regcode_ie.module \regcode_ie_admin_import()

Import registration codes form.

1 string reference to 'regcode_ie_admin_import'
regcode_ie_menu in regcode_ie/regcode_ie.module
Implements hook_menu().

File

regcode_ie/regcode_ie.module, line 40
Import and export functionality for regcode module.

Code

function regcode_ie_admin_import($form, $form_state) {

  // Build the descriptions.
  $action_text = '<p>' . t('Action to perform when importing the data.') . '</p>';
  $action_text .= '<ul><li>' . t('<strong>Skip</strong>: Add new codes skipping those which already exists.') . '</li>';
  $action_text .= '<li>' . t('<strong>Overwrite</strong>: Add new codes overwriting those which already exist.') . '</li></ul>';
  $fieldorder_text = '<p>' . t('Comma separated list mapping regcode fields to CSV fields, e.g. "IGNORE, code, rid, info".') . '</p>';
  $fieldorder_text .= '<p>' . t('If you leave this field blank, the titles from the first row will be used.') . '</p>';

  // Add all of the available fields.
  $fieldorder_text .= '<ul>';
  $fields = regcode_get_fields();
  foreach ($fields as $key => $field) {
    $fieldorder_text .= sprintf('<li><strong>%s</strong>: %s</li>', $key, $field['description']);
  }
  $fieldorder_text .= '</ul>';

  // Build the form.
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['regcode_import_file'] = array(
    '#type' => 'file',
    '#title' => t('File'),
    '#description' => t('File upload with data to add/import (plaintext list or CSV format).'),
  );
  $form['regcode_import_tags'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Tags'),
    '#options' => regcode_get_vocab_terms(),
    '#description' => t('You may assign tags to the imported codes.'),
    '#default_value' => isset($form_state['values']['regcode_import_tags']) ? $form_state['values']['regcode_import_tags'] : array(),
  );
  $form['regcode_import_action'] = array(
    '#type' => 'select',
    '#title' => t('Action'),
    '#options' => array(
      REGCODE_MODE_SKIP => t('Skip'),
      REGCODE_MODE_REPLACE => t('Overwrite'),
    ),
    '#required' => TRUE,
    '#description' => $action_text,
    '#default_value' => isset($form_state['values']['regcode_import_action']) ? $form_state['values']['regcode_import_action'] : '',
  );
  $form['regcode_import_delimiter'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => t("Field delimiter"),
    '#required' => TRUE,
    '#description' => t('Character used as delimiter in csv import of registration codes.'),
    '#default_value' => variable_get('regcode_ie_delimiter', ','),
  );
  $form['regcode_import_enclosure'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => t("Text enclosure"),
    '#default_value' => variable_get('regcode_ie_enclosure', '"'),
    '#required' => TRUE,
    '#description' => t('Character used as enclosure around text content fields on CSV import.'),
  );
  $form['regcode_import_fieldorder'] = array(
    '#type' => 'textfield',
    '#title' => t("Field order"),
    '#default_value' => variable_get('regcode_ie_fieldorder', 'code'),
    '#required' => TRUE,
    '#description' => $fieldorder_text,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  return $form;
}