diff --git a/includes/webform.submissions.inc b/includes/webform.submissions.inc index 7db8f7b..0ab2645 100644 --- a/includes/webform.submissions.inc +++ b/includes/webform.submissions.inc @@ -790,12 +790,26 @@ function _webform_submission_spam_check($to, $subject, $from, $headers = array() * * @param $node * The webform node to be checked. + * @param $account + * Optional parameter. Specify the account you want to check the limit + * against. + * * @return * Boolean TRUE if the user has exceeded their limit. FALSE otherwise. */ -function _webform_submission_user_limit_check($node) { +function webform_submission_user_limit_check($node, $account = NULL) { global $user; + if (!isset($account)) { + $account = $user; + } + + // We can only check access for anonymous users through their cookies. + if ($user->uid !== 0 && $account->uid === 0) { + watchdog('webform', 'Unable to check anonymous user submission limit when logged in as user @uid.', array('@uid' => $user->uid), WATCHDOG_WARNING); + return FALSE; + } + // Check if submission limiting is enabled. if ($node->webform['submit_limit'] == '-1') { return FALSE; // No check enabled. @@ -810,8 +824,8 @@ function _webform_submission_user_limit_check($node) { $query->condition('submitted', REQUEST_TIME - $node->webform['submit_interval'], '>'); } - if ($user->uid) { - $query->condition('uid', $user->uid); + if ($account->uid) { + $query->condition('uid', $account->uid); } else { $query->condition('remote_addr', ip_address()); @@ -822,7 +836,7 @@ function _webform_submission_user_limit_check($node) { // 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)) { + if ($account->uid === 0 && variable_get('webform_use_cookies', 0)) { $cookie_name = 'webform-' . $node->nid; if (isset($_COOKIE[$cookie_name]) && is_array($_COOKIE[$cookie_name])) { @@ -858,7 +872,7 @@ function _webform_submission_user_limit_check($node) { * @return * Boolean TRUE if the form has exceeded it's limit. FALSE otherwise. */ -function _webform_submission_total_limit_check($node) { +function webform_submission_total_limit_check($node) { // Check if submission limiting is enabled. if ($node->webform['total_submit_limit'] == '-1') { diff --git a/webform.module b/webform.module index 4e24b74..f93067f 100644 --- a/webform.module +++ b/webform.module @@ -1598,7 +1598,7 @@ function webform_node_view($node, $view_mode) { module_load_include('inc', 'webform', 'includes/webform.submissions'); // Disable the form if the limit is exceeded and page cache is not active. - if (($user_limit_exceeded = _webform_submission_user_limit_check($node)) && !$cached) { + if (($user_limit_exceeded = webform_submission_user_limit_check($node)) && !$cached) { $enabled = FALSE; } } @@ -1609,7 +1609,7 @@ function webform_node_view($node, $view_mode) { module_load_include('inc', 'webform', 'includes/webform.submissions'); // Disable the form if the limit is exceeded and page cache is not active. - if (($total_limit_exceeded = _webform_submission_total_limit_check($node)) && !$cached) { + if (($total_limit_exceeded = webform_submission_total_limit_check($node)) && !$cached) { $enabled = FALSE; } } @@ -2408,7 +2408,7 @@ function webform_client_form_validate($form, &$form_state) { module_load_include('inc', 'webform', 'includes/webform.submissions'); // Check if the total number of entries was reached before the user submitted // the form. - if (!$finished && $total_limit_exceeded = _webform_submission_total_limit_check($node)) { + if (!$finished && $total_limit_exceeded = webform_submission_total_limit_check($node)) { // Show the user the limit has exceeded. theme('webform_view_messages', array('node' => $node, 'teaser' => 0, 'page' => 1, 'submission_count' => 0, 'total_limit_exceeded' => $total_limit_exceeded, 'allowed_roles' => array_keys(user_roles()), 'closed' => FALSE, 'cached' => FALSE)); form_set_error('', NULL); @@ -2422,7 +2422,7 @@ function webform_client_form_validate($form, &$form_state) { if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled. module_load_include('inc', 'webform', 'includes/webform.submissions'); - if (!$finished && $user_limit_exceeded = _webform_submission_user_limit_check($node)) { + if (!$finished && $user_limit_exceeded = webform_submission_user_limit_check($node)) { // 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', array('node' => $node, 'teaser' => 0, 'page' => 1, 'submission_count' => 0, 'user_limit_exceeded' => $user_limit_exceeded, 'allowed_roles' => array_keys(user_roles()), 'closed' => FALSE, 'cached' => FALSE));