diff -durN webform.orig/includes/webform.pages.inc webform/includes/webform.pages.inc --- webform.orig/includes/webform.pages.inc 2010-03-27 13:21:06.000000000 -0500 +++ webform/includes/webform.pages.inc 2010-04-26 11:31:15.000000000 -0500 @@ -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']; diff -durN webform.orig/includes/webform.submissions.inc webform/includes/webform.submissions.inc --- webform.orig/includes/webform.submissions.inc 2010-03-25 19:50:35.000000000 -0500 +++ webform/includes/webform.submissions.inc 2010-04-26 11:32:30.000000000 -0500 @@ -408,6 +408,41 @@ } /** + * Get the timestamp representing the next allowed time for a user submission. + */ +function _webform_submission_interval_timestamp($node) { + // Get default timezone using code borrowed from drupal 7 function. + global $user; + if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) { + $tz = $user->timezone; + } + else { + // Default to timezone setting from date_default_timezone_set(), php.ini or failover to UTC + $tz = variable_get('date_default_timezone', @date_default_timezone_get()); + } + // Set the timezone used for the following operations. + date_default_timezone_set($tz); + // Calculate our submission limit expiration based on current time values. + switch ($node->webform['submit_interval']) { + case '': + return 0; + case 'hour': + return time() - 3600; + case 'day': + return mktime(00, 00, 00, date('n'), date('j'), date('Y')); + case 'week': + // Adjust day of the week according to the site settings. + $day_of_week = date('w') - variable_get('date_first_day', 0); + if ($day_of_week < 0) { + $day_of_week = $day_of_week + 7; + } + return mktime(00, 00, 00, date('n'), date('j') - $day_of_week, date('Y')); + case 'month': + return mktime(00, 00, 00, date('n') - 1, date('j'), date('Y')); + } +} + +/** * Check if the current user has exceeded the limit on this form. * * @param $node @@ -429,8 +464,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 +474,9 @@ 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. diff -durN webform.orig/webform.install webform/webform.install --- webform.orig/webform.install 2010-04-09 21:20:38.000000000 -0500 +++ webform/webform.install 2010-04-26 11:52:53.000000000 -0500 @@ -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'), @@ -1148,10 +1147,39 @@ return $ret; } +/** This entry is nullified due to reversion + * between 3.0-beta4 and 3.0-beta5. + */ +function webform_update_6316() { + $ret = array(); + $ret[] = array('success' => TRUE, 'query' => t('Null update no changes have been made.')); + return $ret; +} + +/** + * Convert the submission interval to a string instead of an an integer. + */ +function webform_update_6317() { + $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; +} + /** * Remove the Webform Debug variable. */ -function webform_update_6316() { +function webform_update_6318() { $ret = array(); variable_del('webform_debug'); $ret[] = array('success' => TRUE, 'query' => t('Removed the webform_debug variable which is no longer used.')); diff -durN webform.orig/webform.module webform/webform.module --- webform.orig/webform.module 2010-04-11 01:13:51.000000000 -0500 +++ webform/webform.module 2010-04-26 11:33:41.000000000 -0500 @@ -852,7 +852,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'])) { @@ -885,7 +885,7 @@ } // Update the webform entry. - db_query("UPDATE {webform} SET confirmation = '%s', confirmation_format = %d, redirect_url = '%s', teaser = %d, allow_draft = %d, submit_notice = %d, submit_text = '%s', submit_limit = %d, submit_interval = %d where nid = %d", $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->nid); + db_query("UPDATE {webform} SET confirmation = '%s', confirmation_format = %d, redirect_url = '%s', teaser = %d, allow_draft = %d, submit_notice = %d, submit_text = '%s', submit_limit = %d, submit_interval = '%s' where nid = %d", $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->nid); // Compare the webform components and don't do anything if it's not needed. $original = node_load($node->nid); @@ -987,7 +987,7 @@ 'submit_notice' => 0, 'submit_text' => '', 'submit_limit' => -1, - 'submit_interval' => -1, + 'submit_interval' => '', 'roles' => array(1, 2), 'emails' => array(), ); @@ -1235,10 +1235,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 { @@ -1816,11 +1816,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,