Index: webform.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v retrieving revision 1.196.2.16 diff -u -r1.196.2.16 webform.module --- webform.module 3 Apr 2010 04:03:39 -0000 1.196.2.16 +++ webform.module 3 Apr 2010 19:50:49 -0000 @@ -851,7 +851,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) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d, %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']); + db_query("INSERT INTO {webform} (nid, confirmation, confirmation_format, redirect_url, teaser, allow_draft, submit_notice, submit_text, submit_limit, submit_interval) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%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']); // Insert the components into the database. Used with clone.module. if (isset($node->webform['components']) && !empty($node->webform['components'])) { @@ -1195,10 +1195,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'] == '' && $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) { + elseif ($node->webform['submit_interval'] == '' && $node->webform['submit_limit'] == 1) { $message = t('You have already submitted this form.'); } else { @@ -1773,11 +1773,13 @@ $form_state['values']['details']['is_new'] = TRUE; // Set a cookie including the server's submission time. - // The cookie expires in the length of the interval plus a day to compensate for different timezones. + // The cookie expires in the length of the interval plus a day to compensate + // for different timezones. if (variable_get('webform_use_cookies', 0)) { $cookie_name = 'webform-' . $node->nid; - $time = time(); - setcookie($cookie_name . '[' . $time . ']', $time, $time + $node->webform['submit_interval'] + 86400); + $time = $submission->submitted; + $next_allowed_time = _webform_submission_interval_timestamp($node); + setcookie($cookie_name . '[' . $time . ']', $time, $next_allowed_time + 86400); } // Save session information about this submission for anonymous users, Index: webform.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.install,v retrieving revision 1.40.2.8 diff -u -r1.40.2.8 webform.install --- webform.install 27 Mar 2010 21:55:30 -0000 1.40.2.8 +++ webform.install 3 Apr 2010 19:50:48 -0000 @@ -71,10 +71,9 @@ 'default' => -1, ), 'submit_interval' => array( - 'description' => 'The amount of time in seconds that must pass before a user can submit another submission within the set limit.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => -1, + 'description' => 'The amount of time that must pass before a user can submit another submission within the set limit.', + 'type' => 'varchar', + 'length' => 32, ), ), 'primary key' => array('nid'), @@ -1150,6 +1149,26 @@ } /** + * Convert the submission interval to a string instead of an an integer. + */ +function webform_update_6316() { + $ret = array(); + db_change_field($ret, 'webform', 'submit_interval', 'submit_interval', array('type' => 'varchar', 'length' => 32)); + $intervals = array( + '-1' => '', + '3600' => 'hour', + '86400' => 'day', + '604800' => 'week', + ); + + foreach ($intervals as $seconds => $interval) { + $ret[] = update_sql("UPDATE {webform} SET submit_interval = '$interval' WHERE submit_interval = '$seconds'"); + } + + return $ret; +} + +/** * Recursively delete all files and folders in the specified filepath, then * delete the containing folder. * Index: includes/webform.pages.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.pages.inc,v retrieving revision 1.10.2.1 diff -u -r1.10.2.1 webform.pages.inc --- includes/webform.pages.inc 27 Mar 2010 18:21:06 -0000 1.10.2.1 +++ includes/webform.pages.inc 3 Apr 2010 19:50:49 -0000 @@ -70,10 +70,11 @@ $form['submission']['submit_limit']['submit_interval'] = array( '#type' => 'select', '#options' => array( - '-1' => t('ever'), - '3600' => t('every hour'), - '86400' => t('every day'), - '604800' => t('every week'), + '' => t('ever'), + 'hour' => t('every hour'), + 'day' => t('every day'), + 'week' => t('every week'), + 'month' => t('every month'), ), '#default_value' => $node->webform['submit_interval'], '#parents' => array('submit_interval'), @@ -200,7 +201,7 @@ // Set the submit limit to -1 if set to unlimited. if ($form_state['values']['enforce_limit'] == 'no') { $node->webform['submit_limit'] = -1; - $node->webform['submit_interval'] = -1; + $node->webform['submit_interval'] = ''; } else { $node->webform['submit_limit'] = $form_state['values']['submit_limit']; Index: includes/webform.submissions.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.submissions.inc,v retrieving revision 1.18.2.5 diff -u -r1.18.2.5 webform.submissions.inc --- includes/webform.submissions.inc 26 Mar 2010 00:50:35 -0000 1.18.2.5 +++ includes/webform.submissions.inc 3 Apr 2010 19:50:49 -0000 @@ -408,6 +408,29 @@ } /** + * Get the timestamp representing the next allowed time for a user submission. + */ +function _webform_submission_interval_timestamp($node) { + switch ($node->webform['submit_interval']) { + case '': + return 0; + case 'hour': + return time() - 3600; + case 'day': + return gmmktime(00, 00, 00, gmdate('n'), gmdate('j'), gmdate('Y')); + case 'week': + // Adjust day of the week according to the site settings. + $day_of_week = gmdate('w') - variable_get('date_first_day', 0); + if ($day_of_week < 0) { + $day_of_week = $day_of_week + 7; + } + return gmmktime(00, 00, 00, gmdate('n'), gmdate('j') - $day_of_week, gmdate('Y')); + case 'month': + return gmmktime(00, 00, 00, gmdate('n') - 1, gmdate('j'), gmdate('Y')); + } +} + +/** * Check if the current user has exceeded the limit on this form. * * @param $node @@ -429,8 +452,8 @@ "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)); + $submitted_timestamp = _webform_submission_interval_timestamp($node); + $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, $submitted_timestamp, $node->nid)); // Double check the submission history from the users machine using cookies. $num_submissions_cookie = 0; @@ -439,9 +462,10 @@ if (isset($_COOKIE[$cookie_name]) && is_array($_COOKIE[$cookie_name])) { foreach ($_COOKIE[$cookie_name] as $key => $timestamp) { - if ($node->webform['submit_interval'] != -1 && $timestamp <= time() - $node->webform['submit_interval']) { + if ($timestamp <= $submitted_timestamp) { // Remove the cookie if past the required time interval. setcookie($cookie_name . '[' . $key . ']', '', 0); + unset($_COOKIE[$cookie_name][$key]); } } // Count the number of submissions recorded in cookies.