### Eclipse Workspace Patch 1.0
#P Ihm
Index: sites/all/modules/webform/webform.module
===================================================================
--- sites/all/modules/webform/webform.module	(revision 124)
+++ sites/all/modules/webform/webform.module	(working copy)
@@ -832,7 +832,7 @@
   module_load_include('inc', 'webform', 'includes/webform.components');
 
   // Insert the webform.
-  db_query("INSERT INTO {webform} (nid, confirmation, confirmation_format, redirect_url, teaser, allow_draft, submit_notice, submit_text, submit_limit, submit_interval, additional_validate, additional_submit) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s')", $node->nid, $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['additional_validate'], $node->webform['additional_submit']);
+  db_query("INSERT INTO {webform} (nid, confirmation, confirmation_format, redirect_url, teaser, allow_draft, submit_notice, submit_text, submit_limit, submit_interval, additional_validate, additional_submit, submit_limit_total, submit_limit_text) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', %d, '%s')", $node->nid, $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['additional_validate'], $node->webform['additional_submit'], $node->webform['submit_limit_total'], $node->webform['submit_limit_text']);
 
   // Insert the components into the database. Used with clone.module.
   if (isset($node->webform['components']) && !empty($node->webform['components'])) {
@@ -928,6 +928,8 @@
       'submit_notice' => 0,
       'submit_text' => '',
       'submit_limit' => -1,
+      'submit_limit_total' => 0,
+      'submit_limit_text' => '',
       'submit_interval' => -1,
       'additional_validate' => '',
       'additional_submit' => '',
@@ -1060,9 +1062,9 @@
   // Check if the user can add another submission.
   if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
     module_load_include('inc', 'webform', 'includes/webform.submissions');
-
-    // Disable the form if the limit is exceeded and page cache is not active.
-    if (($limit_exceeded = _webform_submission_limit_check($node)) && ($user->uid != 0 || variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED)) {
+    
+    // Disable the form if the limit is exceeded.
+    if (($limit_exceeded = _webform_submission_limit_check($node))) {
       $enabled = FALSE;
     }
   }
@@ -1175,7 +1177,10 @@
 
   // If the user has exceeded the limit of submissions, explain the limit.
   elseif ($limit_exceeded && !$cached) {
-    if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1) {
+    if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1 && $node->webform['submit_limit_text'] != "") {
+      $message = check_plain($node->webform['submit_limit_text']);
+    }
+    else if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1) {
       $message = t('You have submitted this form the maximum number of times (@count).', array('@count' => $node->webform['submit_limit']));
     }
     elseif ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] == 1) {
Index: sites/all/modules/webform/includes/webform.submissions.inc
===================================================================
--- sites/all/modules/webform/includes/webform.submissions.inc	(revision 124)
+++ sites/all/modules/webform/includes/webform.submissions.inc	(working copy)
@@ -416,16 +416,26 @@
   if ($node->webform['submit_limit'] == '-1') {
     return FALSE; // No check enabled.
   }
+  
+  $node->webform['submit_total_limit'] = TRUE; 
+  // Check if submission limiting is for total submission or per user.
+  if ($node->webform['submit_total_limit'] == TRUE) {
+    
+    // Fetch all the entries from the database
+    $num_submissions_database = db_result(db_query("SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND is_draft = 0", $node->nid));
+  } 
+  else {
+    
+    // Retrieve submission data for this IP address or username from the database.
+    $query = 'SELECT count(*) '.
+             'FROM {webform_submissions} '.
+             "WHERE (( 0 = %d AND remote_addr = '%s') OR (uid > 0 AND uid = %d)) ".
+             'AND submitted > %d AND nid = %d AND is_draft = 0';
+  
+    // Fetch all the entries from the database within the submit interval with this username and IP.
+    $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, ($node->webform['submit_interval'] != -1) ? (time() - $node->webform['submit_interval']) : $node->webform['submit_interval'], $node->nid));
+  }
 
-  // Retrieve submission data for this IP address or username from the database.
-  $query = 'SELECT count(*) '.
-           'FROM {webform_submissions} '.
-           "WHERE (( 0 = %d AND remote_addr = '%s') OR (uid > 0 AND uid = %d)) ".
-           'AND submitted > %d AND nid = %d AND is_draft = 0';
-
-  // Fetch all the entries from the database within the submit interval with this username and IP.
-  $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, ($node->webform['submit_interval'] != -1) ? (time() - $node->webform['submit_interval']) : $node->webform['submit_interval'], $node->nid));
-
   // Double check the submission history from the users machine using cookies.
   $num_submissions_cookie = 0;
   if ($user->uid == 0 && variable_get('webform_use_cookies', 0)) {
Index: sites/all/modules/webform/includes/webform.pages.inc
===================================================================
--- sites/all/modules/webform/includes/webform.pages.inc	(revision 124)
+++ sites/all/modules/webform/includes/webform.pages.inc	(working copy)
@@ -79,6 +79,22 @@
     '#parents' => array('submit_interval'),
   );
 
+  $form['submission']['submit_limit']['submit_limit_total'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Do not limit submissions per user. Limit by total submissions'),
+    '#description' => 'Default is to limit submissions per user.',
+    '#default_value' => isset($node->webform['submit_limit_total']) ? $node->webform['submit_limit_total'] : FALSE,
+    '#parents' => array('submit_limit_total'),
+  );
+
+  $form['submission']['submit_limit']['submit_limit_text'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Text to display if submission limit is exceeded'),
+    '#default_value' => isset($node->webform['submit_limit_text']) ? $node->webform['submit_limit_text'] : '',
+    '#parents' => array('submit_limit_text'),
+    '#maxlength' => 255,
+  );
+  
   /* End Edit Form */
 
   /* Start per-role submission control */
@@ -231,11 +247,16 @@
   if ($form_state['values']['enforce_limit'] == 'no') {
     $node->webform['submit_limit'] = -1;
     $node->webform['submit_interval'] = -1;
+    $node->webform['submit_limit_total'] = 0; 
   }
   else {
     $node->webform['submit_limit'] = $form_state['values']['submit_limit'];
     $node->webform['submit_interval'] = $form_state['values']['submit_interval'];
+    $node->webform['submit_limit_total'] = $form_state['values']['submit_limit_total'];
   }
+  
+  // Set limit exceeded text.
+  $node->webform['submit_limit_text'] = $form_state['values']['submit_limit_text'];
 
   // Set submit notice.
   $node->webform['submit_notice'] = $form_state['values']['submit_notice'];
Index: sites/all/modules/webform/webform.install
===================================================================
--- sites/all/modules/webform/webform.install	(revision 124)
+++ sites/all/modules/webform/webform.install	(working copy)
@@ -897,6 +897,25 @@
 }
 
 /**
+ * Add the redirect_url and submit_limit_text field.
+ */
+function webform_update_6311() {
+  $ret = array();
+
+  // Add the new submit_limit_total column.
+  if (!db_column_exists('webform', 'submit_limit_total')) {
+    db_add_field($ret, 'webform', 'submit_limit_total', array('type' => 'int', 'length' => '9', 'default' => 0));
+  }
+
+  // Add the new submit_limit_total column.
+  if (!db_column_exists('webform', 'submit_limit_text')) {
+    db_add_field($ret, 'webform', 'submit_limit_text', array('type' => 'varchar', 'length' => '255'));
+  }
+
+  return $ret;
+}
+
+/**
  * Recursively delete all files and folders in the specified filepath, then
  * delete the containing folder.
  *
