You are here

function constant_contact_save_user in Constant Contact 5

Same name and namespace in other branches
  1. 6 constant_contact.module \constant_contact_save_user()

Store list in user-data, or session for anon users

Parameters

string $list is the friendly name of the list:

boolean $subscribe indicates whether we are adding or removing:

Return value

boolean success status

3 calls to constant_contact_save_user()
constant_contact_block_form_submit in ./constant_contact.module
Implementation of hook_form_submit() process the join mailing list block
constant_contact_import_submit in ./constant_contact.module
Implementation of hook_form_submit() process import users
constant_contact_unsubscribe_confirm_submit in ./constant_contact.module
Implementation of hook_form_submit() process confirm unsubscribe

File

./constant_contact.module, line 457

Code

function constant_contact_save_user(&$user, $list, $subscribe = TRUE) {

  // save in session for anon users, and when the user logs out
  $_SESSION['constant_contact_lists'] = isset($user->constant_contact_lists) ? $user->constant_contact_lists : array();
  $_SESSION['constant_contact_lists'][$list] = $subscribe;
  if (empty($user->uid)) {
    return TRUE;
  }
  $data = array();
  $data['constant_contact_lists'] = isset($user->constant_contact_lists) ? $user->constant_contact_lists : array();
  $data['constant_contact_lists'][$list] = $subscribe;
  $u = user_save($user, $data);
  if (!empty($u)) {
    $user = $u;
    return TRUE;
  }
  else {
    drupal_set_message(t('Error storing subscribtion information.'), 'error');
    return FALSE;
  }
}