Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.124.2.74
diff -u -r1.124.2.74 webform.module
--- webform.module	9 Jan 2009 23:47:47 -0000	1.124.2.74
+++ webform.module	10 Jan 2009 01:43:41 -0000
@@ -144,7 +144,7 @@
   $items['node/%webform_menu/webform-results'] = array(
     'title' => 'Results',
     'page callback' => 'webform_results_submissions',
-    'page arguments' => array(1),
+    'page arguments' => array(1, FALSE, '50'),
     'access callback' => 'user_access',
     'access arguments' => array('access webform results'),
     'file' => 'webform_report.inc',
@@ -154,7 +154,7 @@
   $items['node/%webform_menu/webform-results/submissions'] = array(
     'title' => 'Submissions',
     'page callback' => 'webform_results_submissions',
-    'page arguments' => array(1),
+    'page arguments' => array(1, FALSE, '50'),
     'access callback' => 'user_access',
     'access arguments' => array('access webform results'),
     'file' => 'webform_report.inc',
@@ -174,7 +174,7 @@
   $items['node/%webform_menu/webform-results/table'] = array(
     'title' => 'Table',
     'page callback' => 'webform_results_table',
-    'page arguments' => array(1),
+    'page arguments' => array(1, '50'),
     'access callback' => 'user_access',
     'access arguments' => array('access webform results'),
     'file' => 'webform_report.inc',
@@ -206,7 +206,7 @@
   $items['node/%webform_menu/submissions'] = array(
     'title' => 'Submissions',
     'page callback' => 'webform_results_submissions',
-    'page arguments' => array(1, TRUE),
+    'page arguments' => array(1, TRUE, '50'),
     'access callback' => 'webform_submission_access',
     'access arguments' => array(1, NULL, 'list'),
     'file' => 'webform_report.inc',
@@ -375,17 +375,20 @@
       'arguments' => array('form' => NULL),
     ),
     // webform_report.inc.
+    'webform_results_per_page' => array(
+      'arguments' => array('total_count' => NULL, 'pager_count' => NULL),
+    ),
     'webform_results_submissions_header' => array(
       'arguments' => array('node' => NULL),
     ),
     'webform_results_submissions' => array(
-      'arguments' => array('node' => NULL, 'submissions' => NULL),
+      'arguments' => array('node' => NULL, 'submissions' => NULL, 'total_count' => NULL, 'pager_count' => NULL),
     ),
     'webform_results_table_header' => array(
       'arguments' => array('node' => NULL),
     ),
     'webform_results_table' => array(
-      'arguments' => array('node' => NULL, 'components' => NULL, 'submissions' => NULL, 'node' => NULL),
+      'arguments' => array('node' => NULL, 'components' => NULL, 'submissions' => NULL, 'node' => NULL, 'total_count' => NULL, 'pager_count' => NULL),
     ),
   );
   // Theme functions in all components.
Index: webform.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.css,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 webform.css
--- webform.css	30 Jun 2008 00:19:36 -0000	1.4.2.1
+++ webform.css	10 Jan 2009 01:43:40 -0000
@@ -13,6 +13,10 @@
 .webform-default-value {
   color: #999;
 }
+.webform-results-per-page a.selected {
+  font-weight: bold;
+}
+
 tr.webform-add-form .tabledrag-changed {
   display: none;
 }
Index: webform_submissions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_submissions.inc,v
retrieving revision 1.6.2.19
diff -u -r1.6.2.19 webform_submissions.inc
--- webform_submissions.inc	9 Jan 2009 08:31:06 -0000	1.6.2.19
+++ webform_submissions.inc	10 Jan 2009 01:43:42 -0000
@@ -125,13 +125,31 @@
  * @return $submissions
  *   An array of submissions matching your filters.
  */
-function webform_get_submissions($nid, $header = NULL, $uid = NULL) {
+function webform_get_submissions($nid, $header = NULL, $uid = NULL, $pager_count = 0) {
+  $sids = NULL;
+  if ($pager_count) {
+    $pager_query = 'SELECT * FROM {webform_submissions} WHERE nid = %d';
+    if ($uid) {
+      $pager_query .= ' AND u.uid = %d';
+    }
+    $res = pager_query($pager_query, $pager_count, 0, NULL, $nid, $uid);
+    $sids = array();
+    while ($row = db_fetch_object($res)) {
+      $sids[] = $row->sid;
+    }
+    $sids = implode($sids, ',');
+  }
+
   $query = 'SELECT s.*, sd.cid, sd.no, sd.data, u.name, u.mail, u.status '.
            'FROM {webform_submissions} s '.
            'LEFT JOIN {webform_submitted_data} sd ON sd.sid = s.sid '.
            'LEFT JOIN {users} u ON u.uid = s.uid '.
            'WHERE sd.nid = %d';
 
+  if ($pager_count) {
+    $query .= ' AND s.sid IN (%s)';
+  }
+
   if ($uid) {
     $query .= ' AND u.uid = %d';
   }
@@ -147,7 +165,7 @@
     $query .= ' ORDER BY sid ASC, cid ASC, no ASC';
   }
 
-  $res = db_query($query, $nid, $uid);
+  $res = db_query($query, $nid, $sids, $uid);
   $submissions = array();
   $previous = array();
 
@@ -170,6 +188,24 @@
 }
 
 /**
+ * Return a count of the total number of submissions for a node.
+ *
+ * @param $nid
+ *   The node ID for which submissions are being fetched.
+ * @param $uid
+ *   Optional; the user ID to filter the submissions by.
+ * @return
+ *   An integer value of the number of submissions.
+ */
+function webform_get_submission_count($nid, $uid = NULL) {
+  $query = 'SELECT count(*) FROM {webform_submissions} WHERE nid = %d';
+  if ($uid) {
+    $query .= ' AND u.uid = %d';
+  }
+  return db_result(db_query($query, $nid, $uid));
+}
+
+/**
  * Fetch a specified submission for a webform node.
  */
 function webform_get_submission($nid, $sid, $reset = FALSE) {
Index: webform_report.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_report.inc,v
retrieving revision 1.17.2.11
diff -u -r1.17.2.11 webform_report.inc
--- webform_report.inc	9 Jan 2009 08:31:06 -0000	1.17.2.11
+++ webform_report.inc	10 Jan 2009 01:43:42 -0000
@@ -16,18 +16,69 @@
 /**
  * Retrieve lists of submissions for a given webform.
  */
-function webform_results_submissions($node, $user_filter = FALSE) {
+function webform_results_submissions($node, $user_filter, $pager_count) {
   global $user;
 
+  if (isset($_GET['results']) && is_numeric($_GET['results'])) {
+    $pager_count = $_GET['results'];
+  }
+
   $header = theme('webform_results_submissions_header', $node);
   if ($user_filter) {
     drupal_set_title(t('Submissions for %user', array('%user' => $user->name)));
-    $submissions = webform_get_submissions($node->nid, $header, $user->uid);
+    $submissions = webform_get_submissions($node->nid, $header, $user->uid, $pager_count);
+    $count = webform_get_submission_count($node->nid, $user->uid);
+  }
+  else {
+    $submissions = webform_get_submissions($node->nid, $header, NULL, $pager_count);
+    $count = webform_get_submission_count($node->nid);
+  }
+  return theme('webform_results_submissions', $node, $submissions, $count, $pager_count);
+}
+
+/**
+ * Theme the list of links for selecting the number of results per page.
+ *
+ * @param $total_count
+ *   The total number of results available.
+ * @param $pager_count
+ *   The current number of results displayed per page.
+ */
+function theme_webform_results_per_page($total_count, $pager_count) {
+  $output = '';
+
+  // Create a list of results-per-page options.
+  $counts = array(
+    '20' => '20',
+    '50' => '50',
+    '100' => '100',
+    '200' => '200',
+    '500' => '500',
+    '1000' => '1000',
+    '0' => t('All'),
+  );
+
+  $count_links = array();
+
+  foreach ($counts as $number => $text) {
+    if ($number < $total_count) {
+      $count_links[] = l($text, $_GET['q'], array('query' => 'results='. $number, 'attributes' => array('class' => $pager_count == $number ? 'selected' : '')));
+    }
+  }
+
+  $output .= '<div class="webform-results-per-page">';
+  if (count($count_links) > 1) {
+    $output .= t('Show !count results per page.', array('!count' => implode(' | ', $count_links)));
   }
   else {
-    $submissions = webform_get_submissions($node->nid, $header);
+    $output .= t('Showing all results.');
   }
-  return theme('webform_results_submissions', $node, $submissions);
+  if ($total_count > 1) {
+    $output .= ' '. t('@total results total.', array('@total' => $total_count));
+  }
+  $output .= '</div>';
+
+  return $output;
 }
 
 /**
@@ -57,10 +108,17 @@
  *   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.
  */
-function theme_webform_results_submissions($node, $submissions) {
+function theme_webform_results_submissions($node, $submissions, $total_count = 0, $pager_count = 0) {
   global $user;
-  // This header has to be generated seperately so we can add the SQL necessary
+
+  drupal_add_css(drupal_get_path('module', 'webform') .'/webform.css');
+
+  // 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);
 
@@ -89,25 +147,39 @@
     $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' => 7));
   }
 
-  $output = theme('table', $header, $rows);
+  $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;
 }
 
 /**
  * Create a table containing all submitted values for a webform node.
  */
-function webform_results_table($node) {
+function webform_results_table($node, $pager_count = 0) {
   // Load Components.
   webform_load_components();
 
+  if (isset($_GET['results']) && is_numeric($_GET['results'])) {
+    $pager_count = $_GET['results'];
+  }
+
   // Get all the submissions for the node.
   $header = theme('webform_results_table_header', $node);
-  $submissions = webform_get_submissions($node->nid, $header);
+  $submissions = webform_get_submissions($node->nid, $header, NULL, $pager_count);
+  $total_count = webform_get_submission_count($node->nid);
 
-  return theme('webform_results_table', $node, $node->webform['components'], $submissions);
+  $output = theme('webform_results_table', $node, $node->webform['components'], $submissions, $total_count, $pager_count);
+  if ($pager_count) {
+    $output .= theme('pager', NULL, $pager_count, 0);
+  }
+  return $output;
 }
 
 function theme_webform_results_table_header($node) {
@@ -128,8 +200,14 @@
  *   An associative array of the components for this webform.
  * @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.
  */
-function theme_webform_results_table($node, $components, $submissions) {
+function theme_webform_results_table($node, $components, $submissions, $total_count, $pager_count) {
+  drupal_add_css(drupal_get_path('module', 'webform') .'/webform.css');
+
   $header = array();
   $rows = array();
   $cell = array();
@@ -150,7 +228,8 @@
     foreach ($node->webform['components'] as $component) {
       $table_function = '_webform_table_data_'. $component['type'];
       if (function_exists($table_function)) {
-        $submission_output = $table_function($submission->data[$component['cid']], $component);
+        $data = isset($submission->data[$component['cid']]) ? $submission->data[$component['cid']] : NULL;
+        $submission_output = $table_function($data, $component);
         if ($submission_output !== NULL) {
           $component_headers[] = $component['name'];
           $cell[] = $submission_output;
@@ -169,7 +248,11 @@
     $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));
   }
 
-  return theme('table', $header, $rows);
+
+  $output = '';
+  $output .= theme('webform_results_per_page', $total_count, $pager_count);
+  $output .= theme('table', $header, $rows);
+  return $output;
 }
 
 /**
