You are here

function constant_contact_import_submit in Constant Contact 5

Same name and namespace in other branches
  1. 6.3 admin.import.inc \constant_contact_import_submit()
  2. 6 constant_contact.module \constant_contact_import_submit()
  3. 7.3 admin.import.inc \constant_contact_import_submit()

Implementation of hook_form_submit() process import users

File

./constant_contact.module, line 412

Code

function constant_contact_import_submit($form_id, $values) {
  $lists = constant_contact_get_lists();
  $rs = db_query("SELECT * FROM {users}");
  $fail_count = $success_count = 0;
  require_once 'ConstantContact.php';
  $constant_contact = new ConstantContact();
  $constant_contact
    ->setUsername(variable_get('constant_contact_username', ''));
  $constant_contact
    ->setPassword(variable_get('constant_contact_password', ''));
  $constant_contact
    ->setCategory($values['list']);
  while ($user = db_fetch_object($rs)) {
    if (empty($user->uid)) {
      continue;
    }
    $data = array(
      'Custom_field_1' => $user->name,
      'Custom_field_2' => $user->uid,
      'Custom_field_3' => date('r'),
    );
    if ($constant_contact
      ->add($user->mail, $data)) {
      constant_contact_save_user($user, $values['list']);
      $success_count++;
    }
    else {
      $fail_count++;
    }
  }
  if ($success_count) {
    drupal_set_message(t('!sc users sucessfully imported.', array(
      '!sc' => $success_count,
    )));
  }
  if ($fail_count) {
    drupal_set_message(t('!sc users failed to be imported.', array(
      '!sc' => $fail_count,
    )), 'error');
  }
}