diff --git a/includes/webform.pages.inc b/includes/webform.pages.inc index def36342..2a148ac0 100644 --- a/includes/webform.pages.inc +++ b/includes/webform.pages.inc @@ -50,6 +50,34 @@ function webform_configure_form($form, &$form_state, $node) { '#parents' => array('confirmation'), ); + $form['submission']['time_limit'] = array( + '#type' => 'checkbox', + '#title' => t('Enable time limit on a submission'), + '#description' => t('Time limited anonymous submission access.'), + '#default_value' => !empty($node->webform['time_limit_duration']), + ); + $time_limit_options = array( + '900' => t('15 minutes'), + '1800' => t('30 minutes'), + '3600' => t('1 hour'), + '14400' => t('4 hours'), + '43200' => t('12 hours'), + '86400' => t('1 day'), + '604800' => t('1 week'), + ); + $form['submission']['time_limit_duration'] = array( + '#type' => 'select', + '#title' => t('Time limit duration'), + '#options' => $time_limit_options, + '#default_value' => $node->webform['time_limit_duration'], + '#parents' => array('time_limit_duration'), + '#states' => array( + 'visible' => array( + ':input[name="time_limit"]' => array('checked' => TRUE), + ), + ), + ); + // Redirection settings. if (strpos($node->webform['redirect_url'], '<') === 0) { $redirect = trim($node->webform['redirect_url'], '<>'); @@ -444,6 +472,9 @@ function webform_configure_form_submit($form, &$form_state) { // Save the redirect URL. $node->webform['redirect_url'] = $form_state['values']['redirect_url']; + // Save the time limit duration. + $node->webform['time_limit_duration'] = ($form_state['values']['time_limit']) ? $form_state['values']['time_limit_duration'] : 0; + // Overall form status. $node->webform['status'] = $form_state['values']['status']; diff --git a/webform.install b/webform.install index e137831e..26be84c5 100644 --- a/webform.install +++ b/webform.install @@ -198,6 +198,12 @@ function webform_schema() { 'type' => 'text', 'not null' => TRUE, ), + 'time_limit_duration' => array( + 'description' => 'Integer value that contains the duration of access to a submission in seconds.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('nid'), ); @@ -2359,3 +2365,20 @@ function webform_update_7430() { return t('Webform emails may now be disabled.'); } + +/** + * Add column for time limit duration setting. + */ +function webform_update_7431() { + if (!db_field_exists('webform', 'time_limit_duration')) { + db_add_field('webform', 'time_limit_duration', + array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ) + ); + } + + return t('Webform time limit has been set up.'); +} diff --git a/webform.module b/webform.module index 2cbb6e72..991dfff4 100644 --- a/webform.module +++ b/webform.module @@ -640,6 +640,13 @@ function webform_submission_access($node, $submission, $op = 'view', $account = $_SESSION['webform_submission'][$submission->sid] = $node->nid; } + // Adjust token access if time_limit_duration has been set. + if ($token_access && $node->webform['time_limit_duration']) { + if (REQUEST_TIME > $node->webform['time_limit_duration'] + $submission->submitted) { + $token_access = FALSE; + } + } + $general_access = $access_all || $access_own_submission || $access_node_submissions || $token_access; // Disable the page cache for anonymous users in this access callback, @@ -1739,6 +1746,7 @@ function webform_node_defaults() { 'next_serial' => 1, 'submit_limit' => '-1', 'submit_interval' => '-1', + 'time_limit_duration' => 0, 'total_submit_limit' => '-1', 'total_submit_interval' => '-1', 'progressbar_page_number' => in_array('progressbar_page_number', $progress_bar_defaults) ? '1' : '0',