You are here

function _advuser_receive_notification_by_role in Advanced User 6.3

Same name and namespace in other branches
  1. 7.3 advuser.module \_advuser_receive_notification_by_role()

@private Notify account registrations and modifications for the given users of a role.

Parameters

string $op:

object $account:

1 call to _advuser_receive_notification_by_role()
advuser_user in ./advuser.module
hook_user implementation

File

./advuser.module, line 338
Advanced user module allows you to select users based on an advanced set of filtering and apply actions to block, unblock, delete or email the selected users.

Code

function _advuser_receive_notification_by_role($op, $account) {
  static $accounts = array();
  $from = variable_get("site_mail", ini_get("sendmail_from"));
  switch ($op) {
    case 'insert':
      $notify = variable_get('advuser_new_notify', FALSE) && !user_access('administer users');
      $body = variable_get('advuser_new_mail', t(ADVUSER_DEFAULT_NEW_MAIL));
      $subject = variable_get('advuser_new_subject', t(ADVUSER_DEFAULT_NEW_SUBJECT));
      break;
    case 'update':
      $notify = variable_get('advuser_modify_notify', FALSE) && !user_access('administer users');
      $body = variable_get('advuser_modify_mail', t(ADVUSER_DEFAULT_NEW_MAIL));
      $subject = variable_get('advuser_modify_subject', t(ADVUSER_DEFAULT_NEW_SUBJECT));
      break;
  }
  $types = array(
    'user' => $account,
  );
  $subject = token_replace_multiple($subject, $types, ADVUSER_TOKEN_PREFIX, ADVUSER_TOKEN_SUFFIX);
  $body = token_replace_multiple($body, $types, ADVUSER_TOKEN_PREFIX, ADVUSER_TOKEN_SUFFIX);
  unset($types);
  if ($notify) {
    if (variable_get('advuser_log_notifications', FALSE)) {
      watchdog('advuser', "Sending notification mail: from='{$from}' subj='{$subject}' body='{$body}'");
    }
    if (empty($accounts)) {
      $result = _advuser_dbquery_users_to_notify();
      while ($row = db_fetch_object($result)) {
        $accounts[] = $row;
      }
    }
    foreach ($accounts as $account) {
      drupal_mail('advuser', 'advanced-user-mail', $account->mail, user_preferred_language($account), array(
        'subject' => $subject,
        'body' => $body,
      ), $from, TRUE);
    }
  }
}