You are here

function user_import_form_field_match in User Import 7.3

Same name and namespace in other branches
  1. 8 user_import.admin.inc \user_import_form_field_match()
  2. 5.2 user_import.module \user_import_form_field_match()
  3. 5 user_import.module \user_import_form_field_match()
  4. 6.4 user_import.admin.inc \user_import_form_field_match()
  5. 6.2 user_import.admin.inc \user_import_form_field_match()
  6. 7 user_import.admin.inc \user_import_form_field_match()
  7. 7.2 user_import.admin.inc \user_import_form_field_match()
1 call to user_import_form_field_match()
user_import_edit in ./user_import.admin.inc

File

./user_import.admin.inc, line 967
Provide administration configuration pages to import users.

Code

function user_import_form_field_match(&$form, $import) {
  $delimiter = isset($import['options']['delimiter']) && !empty($import['options']['delimiter']) ? $import['options']['delimiter'] : ',';
  $encoding = isset($import['options']['encoding']) && !empty($import['options']['encoding']) ? $import['options']['encoding'] : 'UTF-8';
  $collapsed = empty($import['name']) ? FALSE : TRUE;
  $handle = _user_import_file_open($form['filepath']['#value'], $form['filename']['#value']);
  $data_row = _user_import_file_row($form['filename']['#value'], $handle, $delimiter, $encoding);
  $fieldmatch_description_parts = array(
    '<strong>' . t('Drupal fields') . ':</strong> ' . t("Match columns in CSV file to drupal user fields, leave as '----' to ignore the column."),
    '<strong>' . t('Username') . ':</strong> ' . t("If username is selected for multiple fields, the username will be built in the order selected. Otherwise, the username will be randomly generated."),
    '<strong>' . t('Abbreviate') . ':</strong> ' . t("Use the first letter of a field in uppercase for the Username, e.g. 'john' -> 'J'."),
  );
  $fieldmatch_description = theme('item_list', array(
    'items' => $fieldmatch_description_parts,
  ));
  $form['field_match'] = array(
    '#type' => 'fieldset',
    '#title' => t('Field Match'),
    '#description' => $fieldmatch_description,
    '#weight' => -90,
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#tree' => TRUE,
  );

  // add default and email address options
  $user_fields[0] = '-------------';
  $additional_user_fields = module_invoke_all('user_import_form_field_match');
  foreach ($additional_user_fields as $type => $type_options) {
    if (is_array($type_options)) {
      foreach ($type_options as $field_id => $label) {
        $user_fields["{$type}-{$field_id}"] = $label;
      }
    }
  }
  asort($user_fields);
  $row = 0;
  $sort = array(
    t('--'),
    1,
    2,
    3,
    4,
  );
  if (empty($data_row)) {
    return;
  }
  foreach ($data_row as $data_cell) {
    $form['field_match'][$row] = array(
      '#tree' => TRUE,
    );
    $form['field_match'][$row]['csv'] = array(
      '#markup' => check_plain(drupal_substr($data_cell, 0, 40)),
    );
    $form['field_match'][$row]['field_match'] = array(
      '#type' => 'select',
      '#default_value' => isset($import['field_match'][$row]['field_match']) ? $import['field_match'][$row]['field_match'] : $user_fields[0],
      '#options' => $user_fields,
    );
    $form['field_match'][$row]['username'] = array(
      '#type' => 'select',
      '#default_value' => isset($import['field_match'][$row]['username']) ? $import['field_match'][$row]['username'] : $sort[0],
      '#options' => $sort,
    );
    $form['field_match'][$row]['abbreviate'] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($import['field_match'][$row]['abbreviate']) ? $import['field_match'][$row]['abbreviate'] : NULL,
    );
    $row++;
  }
  return;
}