Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.74
diff -u -p -r1.196.2.74 webform.module
--- webform.module	6 Jan 2011 18:34:59 -0000	1.196.2.74
+++ webform.module	26 Jan 2011 23:54:47 -0000
@@ -332,6 +332,17 @@ function webform_menu() {
     'file' => 'includes/webform.submissions.inc',
     'type' => MENU_LOCAL_TASK,
   );
+  $items['node/%webform_menu/submission/%webform_menu_submission/resend'] = array(
+    'title' => 'Resend',
+    'load arguments' => array(1),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('webform_submission_resend', 1, 3),
+    'access callback' => 'webform_submission_access',
+    'access arguments' => array(1, 3, 'resend'),
+    'weight' => 3,
+    'file' => 'includes/webform.submissions.inc',
+    'type' => MENU_LOCAL_TASK,
+  );
 
   return $items;
 }
@@ -422,6 +433,8 @@ function webform_submission_access($node
   switch ($op) {
     case 'view':
       return $module_access || $general_access;
+    case 'resend':
+      return $module_access || $general_access;
     case 'edit':
       return $module_access || ($general_access && (user_access('edit all webform submissions', $account) || (user_access('edit own webform submissions', $account) && $account->uid == $submission->uid)));
     case 'delete':
@@ -628,6 +641,10 @@ function webform_theme() {
       'template' => 'templates/webform-submission-navigation',
       'file' => 'includes/webform.submissions.inc',
     ),
+    'webform_submission_resend' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'includes/webform.submissions.inc',
+    ),
   );
 
   // Theme functions in all components.
@@ -2090,116 +2107,7 @@ function webform_client_form_submit($for
   // Check if this form is sending an email.
   if (!$is_draft && !$form_state['values']['details']['finished']) {
     $submission = webform_get_submission($node->nid, $sid, TRUE);
-
-    // Create a themed message for mailing.
-    foreach ($node->webform['emails'] as $eid => $email) {
-      // Pass through the theme layer if using the default template.
-      if ($email['template'] == 'default') {
-        $email['message'] = theme(array('webform_mail_' . $node->nid, 'webform_mail', 'webform_mail_message'), $node, $submission, $email);
-      }
-      else {
-        $email['message'] = $email['template'];
-      }
-
-      // Replace tokens in the message.
-      $email['html'] = ($email['html'] && module_exists('mimemail'));
-      $email['message'] = _webform_filter_values($email['message'], $node, $submission, $email, FALSE, TRUE);
-
-      // Build the e-mail headers.
-      $email['headers'] = theme(array('webform_mail_headers_' . $node->nid, 'webform_mail_headers'), $node, $submission, $email);
-
-      // Assemble the FROM string.
-      if (isset($email['headers']['From'])) {
-        // If a header From is already set, don't override it.
-        $email['from'] = $email['headers']['From'];
-        unset($email['headers']['From']);
-      }
-      else {
-        $email['from'] = webform_format_email_address($email['from_address'], $email['from_name'], $node, $submission);
-      }
-
-      // Update the subject if set in the themed headers.
-      if (isset($email['headers']['Subject'])) {
-        $email['subject'] = $email['headers']['Subject'];
-        unset($email['headers']['Subject']);
-      }
-      else {
-        $email['subject'] = webform_format_email_subject($email['subject'], $node, $submission);
-      }
-
-      // Update the to e-mail if set in the themed headers.
-      if (isset($email['headers']['To'])) {
-        $email['email'] = $email['headers']['To'];
-        unset($email['headers']['To']);
-      }
-
-      // Generate the list of addresses that this e-mail will be sent to.
-      $addresses = array_filter(explode(',', $email['email']));
-      $addresses_final = array();
-      foreach ($addresses as $address) {
-        $address = trim($address);
-
-        // After filtering e-mail addresses with component values, a single value
-        // might contain multiple addresses (such as from checkboxes or selects).
-        $address = webform_format_email_address($address, NULL, $node, $submission, TRUE, FALSE, 'short');
-
-        if (is_array($address)) {
-          foreach ($address as $new_address) {
-            $new_address = trim($new_address);
-            if (valid_email_address($new_address)) {
-              $addresses_final[] = $new_address;
-            }
-          }
-        }
-        elseif (valid_email_address($address)) {
-          $addresses_final[] = $address;
-        }
-      }
-
-      // Mail the webform results.
-      foreach ($addresses_final as $address) {
-        // Verify that this submission is not attempting to send any spam hacks.
-        if (_webform_submission_spam_check($address, $email['subject'], $email['from'], $email['headers'])) {
-          watchdog('webform', 'Possible spam attempt from @remote_addr' . "<br />\n" . nl2br(htmlentities($email['message'])), array('@remote_add' => ip_address()));
-          drupal_set_message(t('Illegal information. Data not submitted.'), 'error');
-          return FALSE;
-        }
-
-        $language = $user->uid ? user_preferred_language($user) : language_default();
-        $mail_params = array(
-          'message' => $email['message'],
-          'subject' => $email['subject'],
-          'headers' => $email['headers'],
-          'node' => $node,
-          'submission' => $submission,
-        );
-
-        if (module_exists('mimemail')) {
-          // Load attachments for the e-mail.
-          $attachments = array();
-          if ($email['attachments']) {
-            webform_component_include('file');
-            foreach ($node->webform['components'] as $component) {
-              if (webform_component_feature($component['type'], 'attachment') && !empty($submission->data[$component['cid']]['value'][0])) {
-                $file = webform_get_file($submission->data[$component['cid']]['value'][0]);
-                if ($file) {
-                  $file->list = 1; // Needed to include in attachments.
-                  $attachments[] = $file;
-                }
-              }
-            }
-          }
-
-          // Send the e-mail via MIME mail.
-          mimemail($email['from'], $address, $email['subject'], $email['message'], !$email['html'], $email['headers'], $email['html'] ? NULL : $email['message'], $attachments, 'webform');
-        }
-        else {
-          // Normal Drupal mailer.
-          drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
-        }
-      }
-
-    }
+    webform_send_mail($node, $submission);
   }
 
   // Strip out empty tags added by WYSIWYG editors if needed.
@@ -2247,6 +2155,136 @@ function webform_client_form_submit($for
   $form_state['redirect'] = $redirect;
 }
 
+function webform_send_mail($node = NULL, $submission = NULL, $emails = NULL, $resend = FALSE) {
+  // Ensure we have all appropriate variables to send email(s)
+  if (!$node || !$submission) {
+    return FALSE;
+  }
+  if (!$emails && isset($node->webform['emails'])) {
+    $emails = $node->webform['emails'];
+    if (!$emails || empty($emails)) {
+      return FALSE;
+    }
+  }
+  $send_count = 0;
+  // Create a themed message for mailing.
+  foreach ($emails as $eid => $email) {
+    // Pass through the theme layer if using the default template.
+    if ($email['template'] == 'default') {
+      $email['message'] = theme(array('webform_mail_' . $node->nid, 'webform_mail', 'webform_mail_message'), $node, $submission, $email);
+    }
+    else {
+      $email['message'] = $email['template'];
+    }
+
+    // Replace tokens in the message.
+    $email['html'] = ($email['html'] && module_exists('mimemail'));
+    $email['message'] = _webform_filter_values($email['message'], $node, $submission, $email, FALSE, TRUE);
+
+    // Build the e-mail headers.
+    $email['headers'] = theme(array('webform_mail_headers_' . $node->nid, 'webform_mail_headers'), $node, $submission, $email);
+
+    // Assemble the FROM string.
+    if (isset($email['headers']['From'])) {
+      // If a header From is already set, don't override it.
+      $email['from'] = $email['headers']['From'];
+      unset($email['headers']['From']);
+    }
+    else {
+      $email['from'] = webform_format_email_address($email['from_address'], $email['from_name'], $node, $submission);
+    }
+
+    // Update the subject if set in the themed headers.
+    if (isset($email['headers']['Subject'])) {
+      $email['subject'] = $email['headers']['Subject'];
+      unset($email['headers']['Subject']);
+    }
+    else {
+      $email['subject'] = webform_format_email_subject($email['subject'], $node, $submission);
+    }
+
+    // Update the to e-mail if set in the themed headers.
+    if (isset($email['headers']['To'])) {
+      $email['email'] = $email['headers']['To'];
+      unset($email['headers']['To']);
+    }
+
+    // Generate the list of addresses that this e-mail will be sent to.
+    $addresses = array_filter(explode(',', $email['email']));
+    $addresses_final = array();
+    foreach ($addresses as $address) {
+      $address = trim($address);
+
+      // After filtering e-mail addresses with component values, a single value
+      // might contain multiple addresses (such as from checkboxes or selects).
+      $address = webform_format_email_address($address, NULL, $node, $submission, TRUE, FALSE, 'short');
+
+      if (is_array($address)) {
+        foreach ($address as $new_address) {
+          $new_address = trim($new_address);
+          if (valid_email_address($new_address)) {
+            $addresses_final[] = $new_address;
+          }
+        }
+      }
+      elseif (valid_email_address($address)) {
+        $addresses_final[] = $address;
+      }
+    }
+    
+    // Mail the webform results.
+    foreach ($addresses_final as $address) {
+      // Verify that this submission is not attempting to send any spam hacks.
+      if (_webform_submission_spam_check($address, $email['subject'], $email['from'], $email['headers'])) {
+        watchdog('webform', 'Possible spam attempt from @remote_addr' . "<br />\n" . nl2br(htmlentities($email['message'])), array('@remote_add' => ip_address()));
+        drupal_set_message(t('Illegal information. Data not submitted.'), 'error');
+        return FALSE;
+      }
+
+      $language = $user->uid ? user_preferred_language($user) : language_default();
+      $mail_params = array(
+        'message' => $email['message'],
+        'subject' => $email['subject'],
+        'headers' => $email['headers'],
+        'node' => $node,
+        'submission' => $submission,
+      );
+
+      if (module_exists('mimemail')) {
+        // Load attachments for the e-mail.
+        $attachments = array();
+        if ($email['attachments']) {
+          webform_component_include('file');
+          foreach ($node->webform['components'] as $component) {
+            if (webform_component_feature($component['type'], 'attachment') && !empty($submission->data[$component['cid']]['value'][0])) {
+              $file = webform_get_file($submission->data[$component['cid']]['value'][0]);
+              if ($file) {
+                $file->list = 1; // Needed to include in attachments.
+                $attachments[] = $file;
+              }
+            }
+          }
+        }
+        // Send the e-mail via MIME mail.
+        $message = mimemail($email['from'], $address, $email['subject'], $email['message'], !$email['html'], $email['headers'], $email['html'] ? NULL : $email['message'], $attachments, 'webform');
+        if ($message) {
+          $send_count++;
+        }
+      }
+      else {
+        // Normal Drupal mailer.
+        $message = drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
+        if ($message['result']) {
+          $send_count++;
+        }
+      }
+    }
+  }
+  if ($send_count > 0 && $resend) {
+    drupal_set_message(t('Successfully re-sent submission #%sid to %send_count.', array('%sid' => $submission->sid, '%send_count' => format_plural($send_count, '1 recipient', '@count recipients'))));
+  }
+}
+
 /**
  * Post processes the submission tree with any updates from components.
  *
@@ -2587,7 +2625,8 @@ function _webform_filter_values($string,
         $display_element['#id'] = form_clean_id('edit-' . implode('-', $display_element['#parents']));
       }
       $replacements['email'][$format]['%email[' . $form_key . ']'] = drupal_render($display_element);
-      $replacements['email'][$format]['%value[' . $form_key . ']'] = isset($display_element['#children']) ? $display_element['#children'] : '';
+      // Use the #value if there is no #children, needed for hidden elements
+      $replacements['email'][$format]['%value[' . $form_key . ']'] = (isset($display_element['#children']) ? $display_element['#children'] : (isset($display_element['#value']) ? $display_element['#value'] : ''));
     }
 
     // Submission edit URL.
Index: includes/webform.report.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.report.inc,v
retrieving revision 1.16.2.10
diff -u -p -r1.16.2.10 webform.report.inc
--- includes/webform.report.inc	29 Sep 2010 18:38:19 -0000	1.16.2.10
+++ includes/webform.report.inc	26 Jan 2011 23:54:47 -0000
@@ -54,8 +54,10 @@ function webform_results_submissions($no
     }
     $row[] = l(t('View'), "node/$node->nid/submission/$sid");
     $operation_count = 1;
+    // No need to call this multiple times, just reference this in a variable.
+    $destination = drupal_get_destination();
     if (module_exists('print_pdf') && user_access('access PDF version')) {
-      $row[] = l(t('PDF'), "printpdf/$node->nid/submission/$sid", array('query' => drupal_get_destination()));
+      $row[] = l(t('PDF'), "printpdf/$node->nid/submission/$sid", array('query' => $destination));
       $operation_count++;
     }
     if (module_exists('print') && user_access('access print')) {
@@ -63,11 +65,15 @@ function webform_results_submissions($no
       $operation_count++;
     }
     if (webform_submission_access($node, $submission, 'edit', $user)) {
-      $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit", array('query' => drupal_get_destination()));
+      $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit", array('query' => $destination));
       $operation_count++;
     }
     if (webform_submission_access($node, $submission, 'delete', $user)) {
-      $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete", array('query' => drupal_get_destination()));
+      $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete", array('query' => $destination));
+      $operation_count++;
+    }
+    if (webform_submission_access($node, $submission, 'resend', $user)) {
+      $row[] = l(t('Resend'), "node/$node->nid/submission/$sid/resend", array('query' => $destination));
       $operation_count++;
     }
     if ($operation_count < $operation_total) {
Index: includes/webform.submissions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.submissions.inc,v
retrieving revision 1.18.2.14
diff -u -p -r1.18.2.14 webform.submissions.inc
--- includes/webform.submissions.inc	5 Jan 2011 23:46:02 -0000	1.18.2.14
+++ includes/webform.submissions.inc	26 Jan 2011 23:54:47 -0000
@@ -218,6 +218,93 @@ function webform_submission_page($node, 
   return theme('webform_submission_page', $node, $submission, $output, $navigation, $information);
 }
 
+function webform_submission_resend($form_state, $node, $submission) {
+  global $firebug;
+  // module_load_include('inc', 'webform', 'includes/webform.components');
+  // Render the admin UI breadcrumb.
+  webform_set_breadcrumb($node);
+  $form = array(
+    '#tree' => TRUE,
+    '#node' => $node,
+    'components' => array(),
+  );
+  
+  $form['#node'] = $node;
+  $form['#submission'] = $submission;
+
+  foreach ($node->webform['emails'] as $eid => $email) {
+    $email_addresses = array_filter(explode(',', check_plain($email['email'])));
+    foreach ($email_addresses as $key => $email_address) {
+      $email_addresses[$key] = webform_format_email_address($email_address, NULL, $node, NULL, FALSE);
+    }
+    $form['resend'][$eid] = array(
+      '#type' => 'checkbox',
+      '#default_value' => TRUE,
+    );
+    $form['emails'][$eid]['email'] = array(
+      '#value' => implode('<br />', $email_addresses),
+    );
+    $form['emails'][$eid]['subject'] = array(
+      '#value' => check_plain(webform_format_email_subject($email['subject'], $node, $submission)),
+    );
+    $form['emails'][$eid]['from'] = array(
+      '#value' => check_plain(webform_format_email_address($email['from_address'], $email['from_name'], $node, $submission, FALSE)),
+    );
+    $form['buttons']['resend'] = array(
+      '#type' => 'submit',
+      '#value' => 'Resend',
+    );
+  }
+  return $form;
+}
+
+function webform_submission_resend_validate($form, &$form_state) {
+  if (!isset($form['#post']['resend'])) {
+    form_set_error('emails', t('You must select at least one email address to resend submission.'));
+  }
+}
+
+function webform_submission_resend_submit($form, &$form_state) {
+  $emails = array();
+  foreach ($form['#post']['resend'] as $eid => $checked) {
+    $emails[] = $form['#node']->webform['emails'][$eid];
+  }
+  if (!empty($emails)) {
+    webform_send_mail($form['#node'], $form['#submission'], $emails, TRUE);
+  }
+}
+
+/**
+ * Theme the node components form. Use a table to organize the components.
+ *
+ * @param $form
+ *   The form array.
+ * @return
+ *   Formatted HTML form, ready for display.
+ */
+function theme_webform_submission_resend($form) {
+  $header = array('',t('E-mail to'), t('Subject'), t('From'));
+  $rows = array();
+  if (!empty($form['emails'])) {
+    foreach (element_children($form['emails']) as $eid) {
+      // Add each component to a table row.
+      $rows[] = array(
+        drupal_render($form['resend'][$eid]),
+        drupal_render($form['emails'][$eid]['email']),
+        drupal_render($form['emails'][$eid]['subject']),
+        drupal_render($form['emails'][$eid]['from']),
+      );
+    }
+  }
+  else {
+    $rows[] = array(array('data' => t('This webform is currently not setup to send emails.'), 'colspan' => 5));
+  }
+  $output = '';
+  $output .= theme('table', $header, $rows, array('id' => 'webform-emails'));
+  $output .= drupal_render($form);
+  return $output;
+}
+
 /**
  * Print a Webform submission for display on a page or in an e-mail.
  */
