Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.50
diff -u -p -r1.196.2.50 webform.module
--- webform.module	26 Aug 2010 11:56:37 -0000	1.196.2.50
+++ webform.module	27 Aug 2010 13:06:45 -0000
@@ -577,7 +577,8 @@ function webform_theme() {
       'file' => 'includes/webform.report.inc',
     ),
     'webform_results_submissions' => array(
-      'arguments' => array('node' => NULL, 'submissions' => NULL, 'total_count' => 0, 'pager_count' => 0),
+      'arguments' => array('element' => NULL),
+      'template' => 'templates/webform-results-submissions',
       'file' => 'includes/webform.report.inc',
     ),
     'webform_results_table_header' => array(
Index: includes/webform.report.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.report.inc,v
retrieving revision 1.16.2.7
diff -u -p -r1.16.2.7 webform.report.inc
--- includes/webform.report.inc	14 Aug 2010 21:11:42 -0000	1.16.2.7
+++ includes/webform.report.inc	27 Aug 2010 13:06:45 -0000
@@ -38,7 +38,54 @@ function webform_results_submissions($no
     $submissions = webform_get_submissions($node->nid, $header, $pager_count);
     $count = webform_get_submission_count($node->nid);
   }
-  return theme('webform_results_submissions', $node, $submissions, $count, $pager_count);
+
+  $operation_column = end($header);
+  $operation_total = $operation_column['colspan'];
+
+  $rows = array();
+  foreach ($submissions as $sid => $submission) {
+    $row = array(
+      $submission->is_draft ? t('@sid (draft)', array('@sid' => $sid)) : $sid,
+      format_date($submission->submitted, 'small'),
+    );
+    if (user_access('access all webform results') || (user_access('access own webform results') && $user->uid == $node->uid)) {
+      $row[] = theme('username', $submission);
+      $row[] = $submission->remote_addr;
+    }
+    $row[] = l(t('View'), "node/$node->nid/submission/$sid");
+    $operation_count = 1;
+    if (module_exists('print_pdf') && user_access('access PDF version')) {
+      $row[] = l(t('PDF'), "printpdf/$node->nid/submission/$sid", array('query' => drupal_get_destination()));
+      $operation_count++;
+    }
+    if (module_exists('print') && user_access('access print')) {
+      $row[] = l(t('Print'), "print/$node->nid/submission/$sid");
+      $operation_count++;
+    }
+    if ((user_access('edit own webform submissions') && $user->uid == $submission->uid) || user_access('edit all webform submissions')) {
+      $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit", array('query' => drupal_get_destination()));
+      $operation_count++;
+    }
+    if ((user_access('delete own webform submissions') && $user->uid == $submission->uid) || user_access('delete all webform submissions')) {
+      $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete", array('query' => drupal_get_destination()));
+      $operation_count++;
+    }
+    if ($operation_count < $operation_total) {
+      $row[count($row) - 1] = array('data' => $row[count($row) - 1], 'colspan' => $operation_total - $operation_count + 1);
+    }
+    $rows[] = $row;
+  }
+
+  $element['#theme'] = 'webform_results_submissions';
+  $element['#node'] = $node;
+  $element['#submissions'] = $submissions;
+  $element['#total_count'] = $count;
+  $element['#pager_count'] = $pager_count;
+  $element['#table']['#header'] = $header;
+  $element['#table']['#rows'] = $rows;
+  $element['#table']['#operation_total'] = $operation_total;
+
+  return drupal_render($element);
 }
 
 /**
@@ -109,76 +156,21 @@ function theme_webform_results_submissio
 }
 
 /**
- * Theme the submissions tab of the webform results page.
- *
- * @param $node
- *   The node whose results are being displayed.
- * @param $submissions
- *   An array of all submissions for this webform.
- * @param $total_count
- *   The total number of submissions to this webform.
- * @param $pager_count
- *   The number of results to be shown per page.
+ * Preprocess function for webform-results-submissions.tpl.php
  */
-function theme_webform_results_submissions($node, $submissions, $total_count = 0, $pager_count = 0) {
-  global $user;
+function template_preprocess_webform_results_submissions(&$vars) {
+  $vars['node'] = $vars['element']['#node'];
+  $vars['submissions'] = $vars['element']['#submissions'];
 
-  drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE);
+  $vars['table']['header'] = $vars['element']['#table']['#header'];
+  $vars['table']['rows'] = $vars['element']['#table']['#rows'];
+  $vars['table']['operation_total'] = $vars['element']['#table']['#operation_total'];
 
-  // This header has to be generated separately so we can add the SQL necessary
-  // to sort the results.
-  $header = theme('webform_results_submissions_header', $node);
-  $operation_column = end($header);
-  $operation_total = $operation_column['colspan'];
+  $vars['total_count'] = $vars['element']['#total_count'];
+  $vars['pager_count'] = $vars['element']['#pager_count'];
+  $vars['is_submissions'] = (arg(2) == 'submissions')? 1 : 0;
 
-  $rows = array();
-  foreach ($submissions as $sid => $submission) {
-    $row = array(
-      $submission->is_draft ? t('@sid (draft)', array('@sid' => $sid)) : $sid,
-      format_date($submission->submitted, 'small'),
-    );
-    if (user_access('access all webform results') || (user_access('access own webform results') && $user->uid == $node->uid)) {
-      $row[] = theme('username', $submission);
-      $row[] = $submission->remote_addr;
-    }
-    $row[] = l(t('View'), "node/$node->nid/submission/$sid");
-    $operation_count = 1;
-    if (module_exists('print_pdf') && user_access('access PDF version')) {
-      $row[] = l(t('PDF'), "printpdf/$node->nid/submission/$sid", array('query' => drupal_get_destination()));
-      $operation_count++;
-    }
-    if (module_exists('print') && user_access('access print')) {
-      $row[] = l(t('Print'), "print/$node->nid/submission/$sid");
-      $operation_count++;
-    }
-    if ((user_access('edit own webform submissions') && $user->uid == $submission->uid) || user_access('edit all webform submissions')) {
-      $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit", array('query' => drupal_get_destination()));
-      $operation_count++;
-    }
-    if ((user_access('delete own webform submissions') && $user->uid == $submission->uid) || user_access('delete all webform submissions')) {
-      $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete", array('query' => drupal_get_destination()));
-      $operation_count++;
-    }
-    if ($operation_count < $operation_total) {
-      $row[count($row) - 1] = array('data' => $row[count($row) - 1], 'colspan' => $operation_total - $operation_count + 1);
-    }
-    $rows[] = $row;
-  }
-
-  if (count($rows) == 0) {
-    $rows[] = array(array('data' => t('There are no submissions for this form. <a href="!url">View this form</a>.', array('!url' => url('node/' . $node->nid))), 'colspan' => 4 + $operation_total));
-  }
-
-  $output = '';
-  $output .= theme('webform_results_per_page', $total_count, $pager_count);
-  $output .= theme('table', $header, $rows);
-  if (arg(2) == 'submissions') {
-    $output .= theme('links', array('webform' => array('title' => t('Go back to the form'), 'href' => 'node/' . $node->nid)));
-  }
-  if ($pager_count) {
-    $output .= theme('pager', NULL, $pager_count, 0);
-  }
-  return $output;
+  unset($vars['element']);
 }
 
 /**
Index: templates/webform-results-submissions.tpl.php
===================================================================
RCS file: templates/webform-results-submissions.tpl.php
diff -N templates/webform-results-submissions.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ templates/webform-results-submissions.tpl.php	27 Aug 2010 13:06:45 -0000
@@ -0,0 +1,37 @@
+<?php
+// $Id:
+
+/**
+ * @file
+ * Result submissions page.
+ *
+ * Available variables:
+ * - $node: The node object for this webform.
+ * - $submission: The Webform submission array.
+ * - $total_count: The total number of submissions to this webform.
+ * - $pager_count: The number of results to be shown per page.
+ * - is_submissions: The user is viewing the node/NID/submissions page.
+ * - $table: The table[] array consists of three keys:
+ * - $table['header']: Table header.
+ * - $table['rows']: Table rows.
+ * - $table['operation_total']: Maximum number of operations in the operation column.
+ */
+drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE);
+?>
+
+<?php print theme('webform_results_per_page', $total_count, $pager_count); ?>
+
+<?php if (count($table['rows'])):
+  print theme('table', $table['header'], $table['rows']);
+else:
+  print t('There are no submissions for this form. <a href="!url">View this form</a>.', array('!url' => url('node/'. $node->nid)));
+endif; ?>
+
+
+<?php if ($is_submissions):
+  print theme('links', array('webform' => array('title' => t('Go back to the form'), 'href' => 'node/'. $node->nid)));
+endif; ?>
+
+<?php if ($pager_count):
+  print theme('pager', NULL, $pager_count, 0);
+endif; ?>
