You are here

function regcode_admin_import in Registration codes 6

Same name and namespace in other branches
  1. 5.3 regcode_admin.inc.php \regcode_admin_import()

Return the form associated with the registration code import admin page

Return value

The import form array

1 string reference to 'regcode_admin_import'
regcode_menu in ./regcode.module
Implementation of hook_menu().

File

./regcode.admin.php, line 243
Functions and pages needed for the administration interface for the regcode module.

Code

function regcode_admin_import() {

  // 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>';
  $action_text .= '<li>' . t('<strong>Clean</strong>: Erases <strong>all</strong> existing codes before importing new codes.') . '</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
  module_load_include('regcode.api', 'regcode', 'php');
  $fieldorder_text .= '<ul>';
  $fields = regcode_get_fields();
  foreach ($fields as $field => $value) {
    if ($value['#exposed'] === TRUE) {
      $fieldorder_text .= sprintf('<li><strong>%s</strong>: %s</li>', $field, $value['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_action'] = array(
    '#type' => 'select',
    '#title' => t("Action"),
    '#default_value' => variable_get('regcode_import_action', 'skip'),
    '#options' => array(
      'skip' => t('Skip'),
      'overwrite' => t('Overwrite'),
      'clean' => t('Clean'),
    ),
    '#description' => $action_text,
  );
  $form['regcode_import_delimiter'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => t("Field delimiter"),
    '#description' => t('Character used as delimiter in csv import of registration codes'),
    '#default_value' => variable_get('regcode_import_delimiter', ','),
  );
  $form['regcode_import_enclosure'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => t("Text enclosure"),
    '#default_value' => variable_get('regcode_import_enclosure', '"'),
    '#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_import_fieldorder', 'code'),
    '#description' => $fieldorder_text,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  return $form;
}