You are here

function multiple_email_user in Multiple E-mail Addresses 6

Same name and namespace in other branches
  1. 5 multiple_email.module \multiple_email_user()

Implementation of hook_user().

Parameters

string $op:

array $edit:

object $account:

string $category:

Return value

mixed

File

./multiple_email.module, line 190
multiple_email module file

Code

function multiple_email_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'categories':
      return array(
        array(
          'name' => 'email-addresses',
          'title' => 'E-mail addresses',
          'weight' => 100,
        ),
      );
    case 'form':
      if ($category == 'email-addresses') {
        $form = array();
        return $form;
      }
      break;
    case 'insert':

      // add the new e-mail address into the Multiple E-mails section.
      $eid = multiple_email_register_email($account->uid, $account->mail, TRUE);
      break;
    case 'delete':

      // delete Multiple E-mails from the deleting user.
      db_query("DELETE FROM {multiple_email} WHERE uid = %d", $account->uid);
      break;
    case 'validate':
      if (!empty($edit['mail'])) {
        $mail = multiple_email_find_address($edit['mail']);

        // If this is an email
        if (!empty($mail) && empty($mail->primary_address) && (empty($account->uid) || $account->uid != $mail->uid)) {
          form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array(
            '%email' => $edit['mail'],
            '@password' => url('user/password'),
          )));
        }
      }
      break;
    case 'after_update':
      if (!empty($edit['mail'])) {
        $object = multiple_email_find_address($edit['mail']);

        // add this to multiple email
        if (empty($object)) {

          // If an administer is making a change or user doesn't have
          // multiple emails permission, mark as confirmed.
          $confirmed = user_access('adminster users') || !user_access('use multiple emails', $account);

          // confirm if action done by administer
          $eid = multiple_email_register_email($account->uid, $edit['mail'], $confirmed);
          if (empty($confirmed) && !empty($eid)) {
            multiple_email_send_confirmation($account, $edit['mail']);
          }
        }
      }
      break;
  }
}