Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.82
diff -u -r1.196.2.82 webform.module
--- webform.module	23 Feb 2011 00:46:15 -0000	1.196.2.82
+++ webform.module	23 Feb 2011 21:38:14 -0000
@@ -508,7 +508,7 @@
       'arguments' => array('node' => NULL, 'teaser' => NULL, 'page' => NULL, 'form' => NULL, 'enabled' => NULL),
     ),
     'webform_view_messages' => array(
-      'arguments' => array('node' => NULL, 'teaser' => NULL, 'page' => NULL, 'submission_count' => NULL, 'limit_exceeded' => NULL, 'allowed_roles' => NULL, 'closed' => NULL),
+      'arguments' => array('node' => NULL, 'teaser' => NULL, 'page' => NULL, 'submission_count' => NULL, 'limit_exceeded' => NULL, 'allowed_roles' => NULL, 'closed' => NULL, 'cached' => FALSE),
     ),
     'webform_form' => array(
       'arguments' => array('form' => NULL),
@@ -1264,22 +1264,27 @@
     }
   }
 
+  // Get a count of previous submissions by this user. Note that the
+  // webform_submission_access() function may disable the page cache for
+  // anonymous users if they are allowed to edit their own submissions!
+  if ($page && webform_submission_access($node, NULL, 'list')) {
+    module_load_include('inc', 'webform', 'includes/webform.submissions');
+    $submission_count = webform_get_submission_count($node->nid, $user->uid);
+  }
+
+  // Check if this page is cached or not.
+  $cached = $user->uid == 0 && (variable_get('cache', 0) || (function_exists('drupal_page_is_cacheable') && drupal_page_is_cacheable() === FALSE));
+
   // 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', 0) == 0)) {
+    if (($limit_exceeded = _webform_submission_limit_check($node)) && !$cached) {
       $enabled = FALSE;
     }
   }
 
-  // Get a count of previous submissions by this user.
-  if ($page && webform_submission_access($node, NULL, 'list')) {
-    module_load_include('inc', 'webform', 'includes/webform.submissions');
-    $submission_count = webform_get_submission_count($node->nid, $user->uid);
-  }
-
   // Check if this user has a draft for this webform.
   $is_draft = FALSE;
   if (($node->webform['allow_draft'] || $node->webform['auto_save']) && $user->uid != 0) {
@@ -1303,7 +1308,7 @@
 
   // Print out messages for the webform.
   if ($node->build_mode != NODE_BUILD_PREVIEW && !isset($node->webform_block) && !$logging_in) {
-    theme('webform_view_messages', $node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles, $closed);
+    theme('webform_view_messages', $node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles, $closed, $cached);
   }
 
   if (isset($output)) {
@@ -1353,12 +1358,17 @@
  *   A list of user roles that are allowed to submit this webform.
  * @param $closed
  *   Boolean value if submissions are closed.
+ * @param $cached
+ *   Whether the page contents are being cached. Messages that are user-specific
+ *   should not be shown when the page is cached, otherwise the message may be
+ *   shown to other users. Some messages should always be shown even if the page
+ *   is cached, such as "Submissions for this form are closed", because they
+ *   apply to all users equally.
  */
-function theme_webform_view_messages($node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles, $closed) {
+function theme_webform_view_messages($node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles, $closed, $cached) {
   global $user;
 
   $type = 'notice';
-  $cached = $user->uid == 0 && variable_get('cache', 0);
 
   if ($closed) {
     $message = t('Submissions for this form are closed.');
@@ -1910,8 +1920,10 @@
     module_load_include('inc', 'webform', 'includes/webform.submissions');
 
     if (!$finished && $limit_exceeded = _webform_submission_limit_check($node)) {
-      $error = theme('webform_view_messages', $node, 0, 1, 0, $limit_exceeded, array_keys(user_roles()), FALSE);
-      form_set_error('', $error);
+      // Assume that webform_view_messages will print out the necessary message,
+      // then stop the processing of the form with an empty form error.
+      theme('webform_view_messages', $node, 0, 1, 0, $limit_exceeded, array_keys(user_roles()), FALSE, FALSE);
+      form_set_error('', NULL);
       return;
     }
   }
@@ -3136,7 +3148,7 @@
   }
   // Drupal 6 hack to disable page cache.
   else {
-    $GLOBALS['conf']['cache'] = FALSE;
+    $GLOBALS['conf']['cache'] = CACHE_DISABLED;
   }
 }
 
