You are here

function signup_broadcast_form_submit in Signup 5.2

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

Send an email message to all those signed up to a node.

Parameters

$form_id:

$form_values:

File

./signup.module, line 2715
The Signup module (http://drupal.org/project/signup) manages replies to nodes. In particular, it's good for event management. Signup supports sending reminder emails and automatically closing signups for nodes with a start time, via the Event…

Code

function signup_broadcast_form_submit($form_id, $form_values) {
  global $user;
  $addresses = signup_get_email_addresses($form_values['nid']);
  if (is_array($addresses)) {
    if (user_access('administer site configuration')) {
      $from = $form_values['from'];
    }
    else {
      $from = $user->mail;
    }
    $subject = $form_values['subject'];
    $node = node_load($form_values['nid']);
    foreach ($addresses as $signup) {

      // Get the hard-coded tokens provided by the signup module to use
      // for the broadcast email.  This also gives us the email to send to.
      $signup_tokens = _signup_get_email_tokens($node, $signup);
      $user_mail = $signup_tokens['%user_mail'];

      // Replace the signup-provided tokens with the right values.
      $message = strtr($form_values['message'], $signup_tokens);
      if (module_exists('token')) {

        // If the token.module is enabled, also handle any tokens it provides.
        $message = token_replace($message, 'node', $node);
      }
      drupal_mail('signup_broadcast_mail', $user_mail, $subject, $message, $from);
      watchdog('signup', t('Broadcast email for %title sent to %email.', array(
        '%title' => $node->title,
        '%email' => $user_mail,
      )), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));
    }
    if ($form_values['copy']) {
      $signup_tokens = _signup_get_email_tokens($node, $user);
      $sender_email = $signup_tokens['%user_mail'];
      $message = strtr($form_values['message'], $signup_tokens);
      if (module_exists('token')) {

        // If the token.module is enabled, also handle any tokens it provides.
        $message = token_replace($message, 'node', $node);
      }
      $final_text = theme('signup_broadcast_sender_copy', $form_values['message'], $message);
      drupal_mail('signup_broadcast_mail', $sender_email, $subject, $final_text, $from);
      watchdog('signup', t('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,
      )));
    }
  }
  drupal_set_message(t('Message sent to all users who have signed up'));
}