You are here

function signup_send_broadcast in Signup 6

Same name and namespace in other branches
  1. 6.2 includes/broadcast.inc \signup_send_broadcast()
  2. 7 includes/broadcast.inc \signup_send_broadcast()

Send an email message to users who have signed up to a node.

Parameters

$nid: Node ID of the signup node to send a broadcast about.

$subject: The subject of the broadcast message to send.

$body: The body of the broadcast message to send.

$from: The from address to use when sending the broadcast message.

$copy: Optional boolean indicating if the current user should get a copy.

$signups: Optional array of signup objects to send the broadcast to. Each object in the array should at least contain the following fields:

  • "sid": The unique signup ID
  • "mail" or "anon_mail": E-mail address to send to depending on if it's an authenticated or anonymous signup.
  • "name": Username of an authenticated signup.
  • "form_data": The optional custom signup form data for this signup.
  • "language": The user's prefered language (if known).

See also

signup_get_signup()

_signup_get_email()

_signup_get_email_tokens()

1 call to signup_send_broadcast()
signup_broadcast_form_submit in includes/broadcast.inc
Submit callback for the signup broadcast form.

File

includes/broadcast.inc, line 135
Code related to sending signup broadcast messages.

Code

function signup_send_broadcast($nid, $subject, $body, $from, $copy = FALSE, $signups = array()) {
  global $user;
  $send_all = FALSE;

  // If the parameter isn't defined, grab all users who signed up to the node.
  if (empty($signups)) {
    $signups = signup_get_signups($nid);
    $send_all = TRUE;
  }

  // Make sure that signup_get_signups() returned something for this node.
  if (!empty($signups)) {
    $node = node_load($nid);
    foreach ($signups as $signup) {
      $user_mail = _signup_get_email($signup);
      $params = array(
        'subject' => $subject,
        'body' => $body,
        'node' => $node,
        'signup' => $signup,
      );
      if (module_exists('token')) {
        $params['body'] = token_replace_multiple($params['body'], array(
          'node' => $node,
          'signup' => $signup,
          'global' => NULL,
        ));
      }
      $language = user_preferred_language($signup);
      drupal_mail('signup', 'signup_broadcast_mail', $user_mail, $language, $params, $from);
      watchdog('signup', 'Broadcast email for %title sent to %email.', array(
        '%title' => $node->title,
        '%email' => $user_mail,
      ), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));
    }
    if ($copy) {
      $sender_email = _signup_get_email($user);
      $signup_tokens = _signup_get_email_tokens($node, $user);
      $message = strtr($body, $signup_tokens);
      if (module_exists('token')) {

        // If the token.module is enabled, also handle any tokens it provides.
        $message = token_replace_multiple($message, array(
          'node' => $node,
          'signup' => $signup,
          'global' => NULL,
        ));
      }
      $final_text = theme('signup_broadcast_sender_copy', $body, $message);
      $params = array(
        'subject' => $subject,
        'body' => $final_text,
        'ignore_tokens' => TRUE,
      );
      $language = user_preferred_language($user);
      drupal_mail('signup', 'signup_broadcast_mail', $sender_email, $language, $params, $from);
      watchdog('signup', 'Broadcast email copy for %title sent to %email.', array(
        '%title' => $node->title,
        '%email' => $sender_email,
      ), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));
      drupal_set_message(t('Sent a copy of this message to %email', array(
        '%email' => $sender_email,
      )));
    }
  }
  if ($send_all) {
    drupal_set_message(t('Message sent to all users who have signed up'));
  }
  else {
    drupal_set_message(t('Message sent to selected users who have signed up'));
  }
}