You are here

function _advuser_receive_notification_by_role in Advanced User 7.3

Same name and namespace in other branches
  1. 6.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 274
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($subject, $types);
  $body = token_replace($body, $types);
  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();
      foreach ($result as $row) {
        $accounts[] = $row;
      }
    }
    foreach ($accounts as $account) {
      drupal_mail('advuser', 'advanced-user-mail', $account->mail, user_preferred_language($account), array(
        'subject' => $subject,
        'body' => array(
          $body,
        ),
      ), $from, TRUE);
    }
  }
}