### Eclipse Workspace Patch 1.0 #P Ihm Index: sites/all/modules/webform/webform.module =================================================================== --- sites/all/modules/webform/webform.module (revision 162) +++ 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) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', %d)", $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']); // Insert the components into the database. Used with clone.module. if (isset($node->webform['components']) && !empty($node->webform['components'])) { @@ -928,6 +928,7 @@ 'submit_notice' => 0, 'submit_text' => '', 'submit_limit' => -1, + 'submit_limit_total' => 0, 'submit_interval' => -1, 'additional_validate' => '', 'additional_submit' => '', @@ -1060,10 +1061,18 @@ // 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)) { - $enabled = FALSE; + + // Check if submission limiting is for total submission or per user. + if ($node->webform['submit_limit_total']) { + // Disable the form if the limit is exceeded + if ($limit_exceeded = _webform_submission_limit_check($node)) { + $enabled = FALSE; + } + } else { + // 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)) { + $enabled = FALSE; + } } } @@ -1146,7 +1155,6 @@ */ function theme_webform_view_messages($node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles) { global $user; - $type = 'notice'; $cached = $user->uid == 0 && variable_get('cache', CACHE_DISABLED); @@ -1172,8 +1180,11 @@ $message = t('You do not have permission to view this form.'); } } - // If the user has exceeded the limit of submissions, explain the limit. + elseif ($limit_exceeded && $node->webform['submit_limit_total']) { + $message = t('This form has received the maximum number of entries.'); + $type = 'error'; + } elseif ($limit_exceeded && !$cached) { 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'])); Index: sites/all/modules/webform/includes/webform.submissions.inc =================================================================== --- sites/all/modules/webform/includes/webform.submissions.inc (revision 162) +++ sites/all/modules/webform/includes/webform.submissions.inc (working copy) @@ -416,16 +416,25 @@ if ($node->webform['submit_limit'] == '-1') { return FALSE; // No check enabled. } + + // 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 162) +++ sites/all/modules/webform/includes/webform.pages.inc (working copy) @@ -79,6 +79,14 @@ '#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'), + ); + /* End Edit Form */ /* Start per-role submission control */ @@ -231,10 +239,12 @@ 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 submit notice. Index: sites/all/modules/webform/webform.install =================================================================== --- sites/all/modules/webform/webform.install (revision 162) +++ sites/all/modules/webform/webform.install (working copy) @@ -897,6 +897,20 @@ } /** + * Add the submit_limit_total 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)); + } + + return $ret; +} + +/** * Recursively delete all files and folders in the specified filepath, then * delete the containing folder. *