diff -urN webform.orig/includes/webform.pages.inc webform/includes/webform.pages.inc --- webform.orig/includes/webform.pages.inc 2010-02-11 16:05:27.000000000 -0600 +++ webform/includes/webform.pages.inc 2010-03-18 18:05:36.000000000 -0500 @@ -74,6 +74,8 @@ '3600' => t('every hour'), '86400' => t('every day'), '604800' => t('every week'), + '-2' => t('per calendar day'), + '-3' => t('per calendar week'), ), '#default_value' => $node->webform['submit_interval'], '#parents' => array('submit_interval'), diff -urN webform.orig/includes/webform.submissions.inc webform/includes/webform.submissions.inc --- webform.orig/includes/webform.submissions.inc 2010-03-01 10:29:51.000000000 -0600 +++ webform/includes/webform.submissions.inc 2010-03-24 15:12:05.000000000 -0500 @@ -422,9 +422,26 @@ '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)); + // Check for calendar based options and adjust query parameters accordingly. + switch ($node->webform['submit_interval']) { + case '-2': + // Fetch all the entries from the database within the current calendar day with this username and IP. + $basetime = mktime(00, 00, 00, date('n'), date('j'), date('Y')); + $range = 86400; + $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, $basetime, $node->nid)); + break; + + case '-3': + // Fetch all the entries from the database within the current calendar week (starting sunday) with this username and IP. + $basetime = mktime(00, 00, 00, date('n'), date('j') - date('w'), date('Y')); + $range = 604800; + $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, $basetime, $node->nid)); + break; + + default: + // 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; @@ -433,9 +450,21 @@ 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']) { - // Remove the cookie if past the required time interval. - setcookie($cookie_name .'['. $key .']', '', 0); + switch ($node->webform['submit_interval']) { + case '-2': + case '-3': + if($timestamp <= $basetime + $range) { + // Remove the cookie if it is not within todays range. + setcookie($cookie_name .'['. $key .']', '', 0); + } + break; + + default: + if ($node->webform['submit_interval'] != -1 && $timestamp <= time() - $node->webform['submit_interval']) { + // Remove the cookie if past the required time interval. + setcookie($cookie_name .'['. $key .']', '', 0); + } + break; } } // Count the number of submissions recorded in cookies. diff -urN webform.orig/webform.module webform/webform.module --- webform.orig/webform.module 2010-02-28 19:59:12.000000000 -0600 +++ webform/webform.module 2010-03-24 08:13:39.000000000 -0500 @@ -1752,7 +1752,28 @@ 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); + // Check for special case negative options and adjust cookie settings accordingly. + switch ($node->webform['submit_interval']) { + case '-1': + // Just add 86400 for traditional 'day' setting. + setcookie($cookie_name .'['. $time .']', $time, $time + 86400); + break; + + case '-2': + // Calculate midnight today plus one day. + setcookie($cookie_name .'['. $time .']', $time, $time + mktime(00, 00, 00, date('n'), date('j'), date('Y')) + 86400); + break; + + case '-3': + // Calculate midnight on sunday of this week plus one day. + setcookie($cookie_name .'['. $time .']', $time, $time + mktime(00, 00, 00, date('n'), date('j') - date('w'), date('Y')) + 86400); + break; + + default: + // Default to historical behavior based on static time frames. + $basetime = + setcookie($cookie_name .'['. $time .']', $time, $time + $node->webform['submit_interval'] + 86400); + } } // Save session information about this submission for anonymous users, @@ -1857,7 +1878,7 @@ 'submission' => $submission, ); drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']); - + // Debugging output for email. if (variable_get('webform_debug', 0) >= 2) { drupal_set_message('E-mail Headers:
'. check_plain(print_r($headers[$cid], TRUE)) .'To: '. check_plain($address) .'
'. check_plain($email['message']) .''); @@ -1897,7 +1918,7 @@ elseif (valid_url($redirect_url, TRUE)) { $redirect = $redirect_url; $external_url = TRUE; - } + } elseif ($redirect_url && strpos($redirect_url, 'http') !== 0) { $parts = parse_url($redirect_url); $query = $parts['query'] ? ($parts['query'] . '&sid=' . $sid) : ('sid=' . $sid);