Index: includes/webform.pages.inc
===================================================================
--- includes/webform.pages.inc	(revision 626)
+++ includes/webform.pages.inc	(working copy)
@@ -1,6 +1,6 @@
 <?php
 // $Id: webform.pages.inc,v 1.10.2.1 2010/03/27 18:21:06 quicksketch Exp $
-
+require_once ('./'. drupal_get_path('module', 'webform') ."/components/date.inc");
 /**
  * @file
  *
@@ -11,6 +11,7 @@
  * Main configuration form for editing a webform node.
  */
 function webform_configure_form(&$form_state, $node) {
+  $format = webform_date_format('short');
   $form = array();
 
   $form['nid'] = array(
@@ -78,7 +79,26 @@
     '#default_value' => $node->webform['submit_interval'],
     '#parents' => array('submit_interval'),
   );
-
+  
+  $form['submission']['start_date'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Submission Start Date'),
+    '#default_value' => strtotime($node->webform['start_date']) ? date($format, strtotime($node->webform['start_date'])) : '',
+    '#description' => t('Begin date for submissions - the form will display "Submissions for this form are closed." previous to the date entered, so leave blank for it to be immediately visible.'). '<br />' . t('Accepts any date in any <a href="http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html">GNU Date Input Format</a>. Strings such as today, +2 months, and Dec 9 2004 are all valid.'),
+    '#parents' => array('start_date'),
+    '#size' => 60,
+    '#maxlength' => 127,
+  );
+  
+  $form['submission']['end_date'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Submission End Date'),
+    '#default_value' => strtotime($node->webform['end_date']) ? date($format, strtotime($node->webform['end_date'])) : '',
+    '#description' => t('End date for submissions - the form will display "Submissions for this form are closed." after the date entered, so leave blank for no expiration.'). '<br />' . t('Accepts any date in any <a href="http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html">GNU Date Input Format</a>. Strings such as today, +2 months, and Dec 9 2004 are all valid.'),
+    '#parents' => array('end_date'),
+    '#size' => 60,
+    '#maxlength' => 127,
+  );
   /* End Edit Form */
 
   /* Start per-role submission control */
@@ -173,12 +193,28 @@
   else {
     form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state);
   }
+  
+  
+  if (!empty($form_state['values']['start_date']) && strtotime($form_state['values']['start_date']) === false) {
+    form_error($form['submission']['start_date'], t('Please enter a valid start date.'));
+  }
+  
+  if (!empty($form_state['values']['end_date']) && strtotime($form_state['values']['end_date']) === false) {
+    form_error($form['submission']['end_date'], t('Please enter a valid end date.'));
+  }
+  
+  if (!empty($form_state['values']['start_date']) && !empty($form_state['values']['end_date']) && (strtotime($form_state['values']['end_date']) < strtotime($form_state['values']['start_date']))) {
+    form_error($form['submission']['start_date'], t('Start date cannot be after end date - please alter one or the other.'));
+  }
 }
 
 /**
  * Submit handler for webform_configure_form().
  */
 function webform_configure_form_submit($form, &$form_state) {
+$current_tz = date_default_timezone_get();
+date_default_timezone_set('UTC');
+
   $node = node_load($form_state['values']['nid']);
 
   // Save the confirmation.
@@ -206,6 +242,18 @@
     $node->webform['submit_limit'] = $form_state['values']['submit_limit'];
     $node->webform['submit_interval'] = $form_state['values']['submit_interval'];
   }
+  
+  if (!empty($form_state['values']['start_date'])) {
+    $node->webform['start_date'] = date('Y/m/d', strtotime($form_state['values']['start_date']));
+  } else {
+    $node->webform['start_date'] = '';
+  }
+  
+  if (!empty($form_state['values']['end_date'])) {
+    $node->webform['end_date'] = date('Y/m/d', strtotime($form_state['values']['end_date']));
+  } else {
+    $node->webform['end_date'] = '';
+  }
 
   // Set submit notice.
   $node->webform['submit_notice'] = $form_state['values']['submit_notice'];
@@ -234,4 +282,4 @@
   $form['enforce_limit']['yes']['#suffix'] = '</div>';
   $form['enforce_limit']['yes']['#title'] = t('Limit to !count submission(s) !timespan', $replacements);
   return drupal_render($form);
-}
+}
\ No newline at end of file
Index: webform.install
===================================================================
--- webform.install	(revision 626)
+++ webform.install	(working copy)
@@ -1,5 +1,5 @@
 <?php
-// $Id: webform.install,v 1.40.2.11 2010/06/17 23:59:04 quicksketch Exp $
+// $Id: webform.install,v 1.40.2.9 2010/04/10 02:20:38 quicksketch Exp $
 
 /**
  * @file
@@ -1169,6 +1169,29 @@
 }
 
 /**
+ * Add fields for scheduling open/close of form submissions
+ */
+function webform_update_6318() {
+  $ret = array();
+
+  // Safety check to prevent re-adding existing column.
+  if (db_column_exists('webform', 'start_date')) {
+    return $ret;
+  }
+  // Safety check to prevent re-adding existing column.
+  if (db_column_exists('webform', 'end_date')) {
+    return $ret;
+  }
+
+  // Add the new start & end date columns.
+  db_add_field($ret, 'webform', 'start_date', array('type' => 'varchar', 'length' => 255, 'default' => 'NULL'));
+  db_add_field($ret, 'webform', 'end_date', array('type' => 'varchar', 'length' => 255, 'default' => 'NULL'));
+
+  return $ret;
+}
+
+
+/**
  * Recursively delete all files and folders in the specified filepath, then
  * delete the containing folder.
  *
Index: webform.module
===================================================================
--- webform.module	(revision 626)
+++ webform.module	(working copy)
@@ -856,7 +856,7 @@
   module_load_include('inc', 'webform', 'includes/webform.emails');
 
   // 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, start_date, end_date) 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['start_date'], $node->webform['end_date']);
 
   // Insert the components into the database. Used with clone.module.
   if (isset($node->webform['components']) && !empty($node->webform['components'])) {
@@ -898,7 +898,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 = %d, start_date = '%s', end_date = '%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->webform['start_date'], $node->webform['end_date'], $node->nid);
 
   // Compare the webform components and don't do anything if it's not needed.
   $original = node_load($node->nid);
@@ -1147,20 +1147,29 @@
     $logging_in = TRUE;
   }
 
-  // Check if the user's role can submit this webform.
-  if (variable_get('webform_submission_access_control', 1)) {
-    $allowed_roles = array();
-    foreach ($node->webform['roles'] as $rid) {
-      $allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
+    // make sure that the form isn't expired (having an end date previous to today) or not yet active (begin date after today)
+    $start = strtotime($node->webform['start_date']); //false if unset
+    $end = strtotime($node->webform['end_date']);
+    $now = strtotime("now");
+    if(($start && $start > $now) || ($end && $end < $now)){
+        $allowed_roles = array();
+        $enabled = FALSE;
+    } else {
+      // Check if the user's role can submit this webform.
+      if (variable_get('webform_submission_access_control', 1)) {
+        $allowed_roles = array();
+        foreach ($node->webform['roles'] as $rid) {
+          $allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
+        }
+        if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
+          $enabled = FALSE;
+        }
+      }
+      else {
+        // If not using Webform submission access control, allow for all roles.
+        $allowed_roles = array_keys(user_roles());
+      }
     }
-    if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
-      $enabled = FALSE;
-    }
-  }
-  else {
-    // If not using Webform submission access control, allow for all roles.
-    $allowed_roles = array_keys(user_roles());
-  }
 
   // Check if the user can add another submission.
   if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
