Index: webform.install =================================================================== --- webform.install (revision 13791) +++ webform.install (working copy) @@ -81,6 +81,12 @@ 'type' => 'text', 'not null' => TRUE, ), + 'allow_draft' => array ( + 'description' => t('Can this form be saved as a draft?'), + 'type' => 'tinyint', + 'not null' => TRUE, + 'default' => '0', + ), ), 'primary key' => array('nid'), ); @@ -216,6 +222,12 @@ 'type' => 'varchar', 'length' => 128, ), + 'is_draft' => array ( + 'description' => t('Is this a draft of the submission?'), + 'type' => 'tinyint', + 'not null' => TRUE, + 'default' => '0', + ), ), 'unique keys' => array( 'sid_nid' => array('sid', 'nid'), @@ -1016,6 +1028,24 @@ } /** + * Add the ability to save as draft. + */ +function webform_update_6206() { + $ret = array(); + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $ret[] = update_sql("ALTER TABLE {webform_submissions} ADD is_draft tinyint not null default '0'"); + $ret[] = update_sql("ALTER TABLE {webform} ADD allow_draft tinyint not null default '0'"); + break; + case 'pgsql': + $ret[] = update_sql("ALTER TABLE {webform_submissions} ADD is_draft smallint not null default '0'"); + $ret[] = update_sql("ALTER TABLE {webform} ADD allow_draft smallint not null default '0'"); + break; + } + +} +/** * Recursively delete all files and folders in the specified filepath, then * delete the containing folder. * Index: webform.module =================================================================== --- webform.module (revision 13791) +++ webform.module (working copy) @@ -87,6 +87,17 @@ ); // Node page tabs. + + $items['node/%webform_menu/draftsaved']= array( + 'title' => t('Draft saved'), + 'load arguments' => array(1), + 'page callback' => '_webform_draft_confirmation', + 'page arguments' => array(1, 3), + 'access callback' => 'webform_submission_access', + 'access arguments' => array(1, 3, 'view'), + 'type' => MENU_CALLBACK, + ); + $items['node/%webform_menu/done'] = array( 'title' => 'Webform confirmation', 'page callback' => '_webform_confirmation', @@ -214,7 +225,7 @@ 'title' => 'Webform submission', 'load arguments' => array(1), 'page callback' => 'webform_client_form_load', - 'page arguments' => array(1, 3, FALSE, FALSE), + 'page arguments' => array(1, 3, FALSE, FALSE, FALSE), 'access callback' => 'webform_submission_access', 'access arguments' => array(1, 3, 'view'), 'type' => MENU_CALLBACK, @@ -223,7 +234,7 @@ 'title' => 'View', 'load arguments' => array(1), 'page callback' => 'webform_client_form_load', - 'page arguments' => array(1, 3, FALSE, FALSE), + 'page arguments' => array(1, 3, FALSE, FALSE, FALSE), 'access callback' => 'webform_submission_access', 'access arguments' => array(1, 3, 'view'), 'weight' => 0, @@ -233,7 +244,7 @@ 'title' => 'Edit', 'load arguments' => array(1), 'page callback' => 'webform_client_form_load', - 'page arguments' => array(1, 3, TRUE, FALSE), + 'page arguments' => array(1, 3, TRUE, FALSE, FALSE), 'access callback' => 'webform_submission_access', 'access arguments' => array(1, 3, 'edit'), 'weight' => 1, @@ -481,7 +492,7 @@ } // Insert the Webform. - db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit']); + db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit, allow_draft) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit'], $node->webform['allow_draft']); // Insert the components into the database. Used with clone.module. if (isset($node->webform['components']) && !empty($node->webform['components'])) { @@ -843,6 +854,14 @@ '#default_value' => $node->webform['submit_text'], '#description' => t('By default the submit button on this form will have the label Submit. Enter a new title here to override the default.'), ); + + // Allow save draft + $form['webform']['advanced']['allow_draft'] = array( + '#type' => 'checkbox', + '#title' => t('Allow users to save a draft'), + '#default_value' => $node->webform['allow_draft'], + ); + if (user_access('use PHP for additional processing')) { $form['webform']['advanced']['additional_validate'] = array( '#type' => 'textarea', @@ -1108,11 +1127,22 @@ // Get a count of previous submissions by this user. if ($user->uid && (user_access('access own webform submissions') || user_access('access webform results') || user_access('access webform submissions'))) { - $submission_count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND uid = %d', $node->nid, $user->uid)); + $submission_count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND uid = %d AND is_draft = false', $node->nid, $user->uid)); } + // Check if this user has a draft for this webform. + $is_draft = FALSE; + if ($node->webform['allow_draft'] && $user->uid != 0) { + // Draft found - display form with draft data for further editing. + if ($_draft_sid = _webform_fetch_draft_sid($node->nid, $user->uid)) { + include_once(drupal_get_path('module', 'webform') ."/webform_submissions.inc"); + $submission = webform_get_submission($node->nid, $_draft_sid); + $enabled = TRUE; + $is_draft = TRUE; + } + } // Render the form and generate the output. - $form = drupal_get_form('webform_client_form_'. $node->nid, $node, $submission, $enabled, $preview); + $form = drupal_get_form('webform_client_form_'. $node->nid, $node, $submission, $enabled, $preview, $is_draft); $output = theme('webform_view', $node, $teaser, $page, $form, $enabled); // Remove the surrounding