You are here

function _birthdays_send_user_message in Birthdays 6

Same name and namespace in other branches
  1. 5 birthdays.module \_birthdays_send_user_message()

Send all birthdays on this day a message

@todo re-introduce the postcard module to make it fun

1 call to _birthdays_send_user_message()
birthdays_cron in ./birthdays.module
Implementation of hook_cron().

File

./birthdays.mail.inc, line 89
This file contains the files necessary to e-mail the administrator his periodical listings and/or the users on their birthday.

Code

function _birthdays_send_user_message() {
  global $_birthdays_field;

  // If messaging is enabled
  if (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) != BIRTHDAYS_USER_MAIL_NO) {

    // Get all users having their birthday today
    $accounts = birthdays_get_todays_birthdays();
    foreach ($accounts as $uid) {

      // Load user
      $account = user_load(array(
        'uid' => $uid,
      ));

      // If user and/or administrator allows sending messages
      if (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) == BIRTHDAYS_USER_MAIL_YES || variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) == BIRTHDAYS_USER_MAIL_USER && $account->{$_birthdays_field->name}['birthdays_user_send_mail'] == BIRTHDAYS_USER_MAIL_USER_YES) {
        $to = $account->name . ' <' . $account->mail . '>';
        $params['account'] = $account;

        // Send mail
        drupal_mail('birthdays', 'user_message', $to, user_preferred_language($account), $params);

        // Log actions
        watchdog('Birthdays', 'Sent @name a birthday e-mail.', array(
          '@name' => $account->name,
        ), WATCHDOG_NOTICE, '&#160;');
      }
    }
  }
}