Index: signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.205.2.19
diff -u -p -r1.205.2.19 signup.module
--- signup.module	3 Jun 2009 01:07:10 -0000	1.205.2.19
+++ signup.module	22 Jul 2009 18:38:07 -0000
@@ -1010,7 +1010,7 @@ function signup_content_extra_fields($ty
  *   ID (sid), or a full object of data about the signup (a complete row from
  *   the {signup_log} table.
  */
-function signup_cancel_signup($signup) {
+function signup_cancel_signup($signup, $display_message = TRUE) {
   // If we only have a numeric sid argument, load the full signup object.
   if (is_numeric($signup)) {
     $query = db_query('SELECT * FROM {signup_log} WHERE sid = %d', $signup);
@@ -1025,9 +1025,9 @@ function signup_cancel_signup($signup) {
 
   // Delete the record from the {signup_log} table.
   db_query('DELETE FROM {signup_log} WHERE sid = %d', $signup->sid);
-
-  drupal_set_message(t('Signup to !title cancelled.', array('!title' => l($node->title, "node/$node->nid"))));
-
+  if ($display_message) {
+    drupal_set_message(t('Signup to !title cancelled.', array('!title' => l($node->title, "node/$node->nid"))));
+  }
   // See if signups should be re-opened if the total dropped below the limit.
   _signup_check_limit($node, 'total');
 }
@@ -1111,7 +1111,7 @@ function signup_content_types() {
  * $signup_form['signup_form_data'] : an array of key/value pairs --
  *   key is the data category, value is the user input
  */
-function signup_sign_up_user($signup_form) {
+function signup_sign_up_user($signup_form, $display_message = TRUE) {
   $node = node_load($signup_form['nid']);
 
   // Since this is an API call, we need to validate that there are no
@@ -1169,7 +1169,7 @@ function signup_sign_up_user($signup_for
     db_query("INSERT INTO {signup_log} (uid, nid, anon_mail, signup_time, form_data) VALUES (%d, %d, '%s', %d, '%s')", $signup_form['uid'], $signup_form['nid'], $signup_anon_mail, $curtime, $signup_form_data);
     $sid = db_last_insert_id('signup_log', 'sid');
 
-    $from = variable_get('site_mail', ini_get('sendmail_from'));
+    
 
     // Get the hard-coded tokens provided by the signup module to use
     // for the confirmation and/or forwarding emails.  We need to create
@@ -1180,59 +1180,23 @@ function signup_sign_up_user($signup_for
     if (!empty($signup_anon_mail)) {
       $signup->anon_mail = $signup_anon_mail;
     }
-    $user_mail = _signup_get_email($signup);
+
     $node_type_name = node_get_types('name', $node->type);
     // If a confirmation is to be sent, compose the mail message,
     // replace the tokens with the right values, and send it.
-    if ($node->signup_send_confirmation && $user_mail) {
-      $params = array(
-        'subject' => t('Signup confirmation for !node_type: !title', array('!node_type' => $node_type_name, '!title' => $node->title)),
-        'body' => $node->signup_confirmation_email,
-        'node' => $node,
-        'signup' => $signup,
-      );
-      if (module_exists('token')) {
-        $params['body'] = token_replace($params['body'], 'node', $node);
-      }
-      $language = user_preferred_language($signup);
-      drupal_mail('signup', 'signup_confirmation_mail', $user_mail, $language, $params, $from);
+    if ($node->signup_send_confirmation && $user_mail && $display_message) {
+      signup_confirmation_mail($user, $signup, $node);
     }
 
     // If a forwarding email is to be sent, compose the mail message,
     // replace the tokens with the right values, and send it.
-    if ($node->signup_forwarding_email) {
-      $message = t('The following information was submitted as a signup for !title', array('!title' => $node->title));
-      if (_signup_get_node_scheduler($node) != 'none') {
-        $message .= "\n\r". t('Date/Time: !time', array('!time' => signup_format_date($node)));
-      }
-
-      $message .= "\n\r\n\r". t('Username: !name', array('!name' => empty($user->uid) ? variable_get('anonymous', t('Anonymous')) : $user->name));
-      if (!empty($user->uid)) {
-        // For authenticated users, just include a link to their profile page.
-        $message .= "\n\r". t('Profile page: !url', array('!url' => url('user/'. $user->uid, array('absolute' => TRUE))));
-      }
-      else {
-        // For anonymous users, their email is all we've got, so disclose it.
-        $message .= "\n\r". t('E-mail: !email', array('!email' => $user_mail));
-      }
-      if (!empty($signup->form_data)) {
-        $message .= "\n\r\n\r". theme('signup_email_token_custom_data', $signup->form_data);
-      }
-      $params = array(
-        'subject' => t('Signup confirmation for !node_type: !title', array('!node_type' => $node_type_name, '!title' => $node->title)),
-        'body' => $message,
-        'node' => $node,
-        'signup' => $signup,
-        'header' => array('From' => t('New !node_type Signup', array('!node_type' => $node_type_name)) ."<$from>"),
-      );
-      if (module_exists('token')) {
-        $params['body'] = token_replace($params['body'], 'node', $node);
-      }
-      $language = user_preferred_language($signup);
-      drupal_mail('signup', 'signup_forwarding_mail', $node->signup_forwarding_email, $language, $params, $from);
+    if ($node->signup_forwarding_email && $display_message) {
+      signup_forwarding_mail($user, $signup, $node);
     }
-
-    drupal_set_message(t('Signup to !title confirmed.', array('!title' => l($node->title, "node/$node->nid"))) . $confirmation_email . $reminder_email);
+    if ($display_message) {
+      drupal_set_message(t('Signup to !title confirmed.', array('!title' => l($node->title, "node/$node->nid"))) . $confirmation_email . $reminder_email);
+    }
+    
 
     $node->signup_total++;
     if ($node->signup_close_signup_limit) {
@@ -1244,6 +1208,71 @@ function signup_sign_up_user($signup_for
   }
 }
 
+/*
+ * Sends the signup comfirmation mail to a user is signed up for an event.
+ * @param user: The account object of the user being signed up
+ * @param signup: The signup array
+ * @node: The node object being for which the user is signed up 
+ */
+function signup_confirmation_mail($user, $signup, $node) {
+  if (empty($user->mail)) {
+    $user_mail = _signup_get_email($signup);
+  }
+  else {
+    $user_mail = $user->mail;
+  }
+  $from = variable_get('site_mail', ini_get('sendmail_from'));
+  $params = array(
+    'subject' => t('Signup confirmation for !node_type: !title', array('!node_type' => $node_type_name, '!title' => $node->title)),
+    'body' => $node->signup_confirmation_email,
+    'node' => $node,
+    'signup' => $signup,
+  );
+  if (module_exists('token')) {
+    $params['body'] = token_replace($params['body'], 'node', $node);
+  }
+  $language = user_preferred_language($signup);
+  return  drupal_mail('signup', 'signup_confirmation_mail', $user_mail, $language, $params, $from);
+}
+
+/*
+* Sends the signup comfirmation mail to a user is signed up for an event.
+ * @param user: The account object of the user being signed up
+ * @param signup: The signup array
+ * @node: The node object being for which the user is signed up
+ */
+function signup_forwarding_mail($user, $signup, $node) {
+
+  $message = t('The following information was submitted as a signup for !title', array('!title' => $node->title));
+  if (_signup_get_node_scheduler($node) != 'none') {
+    $message .= "\n\r". t('Date/Time: !time', array('!time' => signup_format_date($node)));
+  }
+
+  $message .= "\n\r\n\r". t('Username: !name', array('!name' => empty($user->uid) ? variable_get('anonymous', t('Anonymous')) : $user->name));
+  if (!empty($user->uid)) {
+    // For authenticated users, just include a link to their profile page.
+    $message .= "\n\r". t('Profile page: !url', array('!url' => url('user/'. $user->uid, array('absolute' => TRUE))));
+  }
+  else {
+    // For anonymous users, their email is all we've got, so disclose it.
+    $message .= "\n\r". t('E-mail: !email', array('!email' => $user_mail));
+  }
+  if (!empty($signup->form_data)) {
+    $message .= "\n\r\n\r". theme('signup_email_token_custom_data', $signup->form_data);
+  }
+  $params = array(
+    'subject' => t('Signup confirmation for !node_type: !title', array('!node_type' => $node_type_name, '!title' => $node->title)),
+    'body' => $message,
+    'node' => $node,
+    'signup' => $signup,
+    'header' => array('From' => t('New !node_type Signup', array('!node_type' => $node_type_name)) ."<$from>"),
+  );
+  if (module_exists('token')) {
+    $params['body'] = token_replace($params['body'], 'node', $node);
+  }
+  $language = user_preferred_language($signup);
+  return drupal_mail('signup', 'signup_forwarding_mail', $node->signup_forwarding_email, $language, $params, $from);
+}
 /**
  * Checks the signup limit for a given node, and sees if a change in
  * either the limit or total # of signups should result in a change in
