Index: multistep.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multistep/Attic/multistep.admin.inc,v
retrieving revision 1.1.2.4
diff -U3 -r1.1.2.4 multistep.admin.inc
--- multistep.admin.inc	23 Jul 2009 14:48:59 -0000	1.1.2.4
+++ multistep.admin.inc	31 Aug 2009 15:32:40 -0000
@@ -13,10 +13,62 @@
  */
 function multistep_admin_settings_form(&$form_state) {
   $form = array();
+  // Revisions and Publishing
+  $form['multistep']['status'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Revisioning and publishing'),
+    '#description' => t('These settings will change how multistep interacts with node revisioning and publishing.'),
+    '#weight' => -1,
+  );
+  $form['multistep']['status']['multistep_status_revisions'] = array(
+    '#type' => 'radios',
+    '#title' => t('Revisions'),
+    '#description' => t('Sets how multistep will interact with node revisioning, <em>if revisioning is enabled for the content type</em>.
+      <ul><li><strong>Any step</strong> will follow the standard revision settings
+      (i.e. new revisions will be created after each successful submission, regardless of the step).</li>
+      <li><strong>Any step, after node completion</strong> will create new revisions after each successful submission, regardless of the step, only after all steps have been submitted successfully at least once
+      (i.e. after the node is considered <em>complete</em>).</li>
+      <li><strong>Last step</strong> will create new revisions whenever you submit the last step of the form, regardless of whether the node is considered <em>complete</em> or not.
+      (i.e. it will create a new revision after the last step even if some steps were skipped).</li>
+      <li><strong>Last step, after node completion</strong> will create a new revision only when subitting the last step of the form, and only if all the steps have been successfully submitted at least once
+      (i.e. after the node is considered <em>complete</em>).</li></ul>'
+    ),
+    '#default_value' => variable_get('multistep_status_revisions', 'default'),
+    '#options' => array(
+      'default' => t('Any step (Default)'),
+      'complete' => t('Any step, after node completion'),
+      'last' => t('Last step'),
+      'last-complete' => t('Last step, after node completion'),
+    ),
+    '#weight' => -10,
+  );
+  $form['multistep']['status']['multistep_status_publishing'] = array(
+    '#type' => 'radios',
+    '#title' => t('Publishing'),
+    '#description' => t('Sets how multistep will interact with the node published status, <em>if publishing is enabled for the content type</em>.
+      <ul><li><strong>At node creation</strong> will follow the standard workflow settings
+      (i.e. the node will be published when created).</li>
+      <li><strong>At node completion</strong> will hold off publishing the node until all steps have been successfully submitted
+      (i.e. when the node is considered <em>complete</em>).</li></ul>'
+    ),
+    '#default_value' => variable_get('multistep_status_publishing', 'default'),
+    '#options' => array(
+      'default' => t('At node creation (Default)'),
+      'complete' => t('At node completion'),
+    ),
+    '#weight' => -9,
+  );
+  $form['multistep']['status']['multistep_submit_status'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 1,
+    '#access' => user_access('administer multistep'),
+    '#submit' => array('multistep_admin_settings_status_form_submit'),
+  );
   // Navigation buttons
   $form['multistep']['buttons'] = array(
     '#type' => 'fieldset',
-    '#title' => 'Navigation button labels',
+    '#title' => t('Navigation button labels'),
     '#description' => t('These settings will change the text displayed on each of the submit buttons on multistep forms.'),
     '#weight' => 0,
   );
@@ -59,7 +111,7 @@
   // Reset data
   $form['multistep']['reset'] = array(
     '#type' => 'fieldset',
-    '#title' => 'Reset data',
+    '#title' => t('Reset data'),
     '#description' => t('This form will reset all the step data for the selected content type. Use this if you just enabled multistep for a content type that already contained nodes.') . '<br /><strong>' . t('Warning! Resetting the tables for a content type that already had multistep enabled could result in the loss of the step data!') . '</strong>',
     '#weight' => 1,
   );
@@ -89,6 +141,15 @@
 }
 
 /**
+ * Saves the revision and publishing settings.
+ */
+function multistep_admin_settings_status_form_submit($form, &$form_state) {
+  variable_set('multistep_status_revisions', $form_state['values']['multistep_status_revisions']);
+  variable_set('multistep_status_publishing', $form_state['values']['multistep_status_publishing']);
+  drupal_set_message(t('Settings saved successfully.'));
+}
+
+/**
  * Validates the navigation button labels form to make sure they contain text.
  */
 function multistep_admin_settings_buttons_form_validate($form, &$form_state) {
Index: multistep.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multistep/Attic/multistep.install,v
retrieving revision 1.1.2.1.2.9
diff -U3 -r1.1.2.1.2.9 multistep.install
--- multistep.install	27 Aug 2009 02:50:49 -0000	1.1.2.1.2.9
+++ multistep.install	31 Aug 2009 15:32:40 -0000
@@ -64,6 +64,8 @@
         variable_del('multistep_extra_' . $extra_field . '_' . $content_type['type']);
       }
     }
+    variable_del('multistep_status_revisions');
+    variable_del('multistep_status_publishing');
     variable_del('multistep_button_prev');
     variable_del('multistep_button_next');
     variable_del('multistep_button_save');
Index: multistep.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multistep/multistep.module,v
retrieving revision 1.1.2.2.2.21
diff -U3 -r1.1.2.2.2.21 multistep.module
--- multistep.module	28 Aug 2009 14:13:03 -0000	1.1.2.2.2.21
+++ multistep.module	31 Aug 2009 15:32:40 -0000
@@ -225,9 +225,9 @@
   );
   $form['multistep']['multistep_settings']['multistep_buttons'] = array(
     '#type' => 'checkbox',
-    '#title' => t('Hide standard buttons'),
+    '#title' => t('Hide Preview button'),
     '#default_value' => variable_get('multistep_buttons_' . $type, 0),
-    '#description' => t('Marking this option removes the Preview and Delete buttons from the form.'),
+    '#description' => t('Marking this option removes the Preview button from the form.'),
   );
   $form['multistep']['multistep_settings']['multistep_default'] = array(
     '#type' => 'radios',
@@ -375,19 +375,20 @@
   $form['buttons']['all'] = array(
     '#type' => 'item',
     '#value' => l('View ' . ($step == 0 ? 'multistep' : 'entire') . ' form', arg(0) . '/' . arg(1) . '/' . arg(2) . ($step == 0 ? '/1' : '/0')),
-    '#weight' => 14,
+    '#weight' => 16,
     '#access' => user_access('toggle multistep'),
   );
   // Remove extra buttons if not wanted.
   if (variable_get('multistep_buttons_' . $type, 0) == 1) {
-    unset($form['buttons']['delete']);
     unset($form['buttons']['preview']);
-    if (module_exists('uc_product') && uc_product_is_product_form($form)) {
-      unset($form['buttons']['save_continue']);
-    }
+  }
+  if (module_exists('uc_product') && uc_product_is_product_form($form)) {
+    unset($form['buttons']['save_continue']);
   }
   // This is removed in favor of the custom ones above
   unset($form['buttons']['submit']);
+  // Will decide whether the form is ready for revisioning or publishing.
+  $form['#validate'][] = 'multistep_validate';
 }
 
 /**
@@ -419,6 +420,22 @@
 }
 
 /**
+ * Set proper revisioning and publishing.
+ */
+function multistep_validate($form, &$form_state) {
+  if ($form['revision_information']['revision']['#value']) {
+    $complete = _multistep_is_complete($form_state['values']['nid']);
+    $last = $form_state['clicked_button']['#parents'][0] == 'done' ? TRUE : FALSE;
+    $form_state['values']['revision'] = _multistep_revisioning($complete, $last);
+  }
+  if (array_search('status', variable_get('node_options_' . $form_state['values']['type'], array())) !== FALSE) {
+    $step = _multistep_get_current_step($form_state['values']['type']);
+    $complete = _multistep_will_complete($form_state['values']['nid'], $step);
+    $form_state['values']['status'] = _multistep_publishing($complete);
+  }
+}
+
+/**
  * Submit the form and redirect to the next appropriate step.
  */
 function multistep_submit($form, &$form_state, $action) {
@@ -429,6 +446,7 @@
   $nid = $form_state['nid'];
   // Update the multistep table.
   _multistep_update_status($nid, 'submitted', $step);
+  // Set next step.
   switch($action) {
     case 'save':
       $goto_step = $step;
@@ -460,6 +478,50 @@
 }
 
 /**
+ * Set proper revisioning settings.
+ */
+function _multistep_revisioning($complete, $last) {
+  switch (variable_get('multistep_status_revisions', 'default')) {
+    case 'default':
+      return 1;
+      break;
+    case 'complete':
+      if ($complete) {
+        return 1;
+      }
+      break;
+    case 'last':
+      if ($last) {
+        return 1;
+      }
+      break;
+    case 'last-complete':
+      if ($last && $complete) {
+        return 1;
+      }
+      break;
+  }
+  return 0;
+}
+
+/**
+ * Set proper publishing settings.
+ */
+function _multistep_publishing($complete) {
+  switch (variable_get('multistep_status_publishing', 'default')) {
+    case 'default':
+      return 1;
+      break;
+    case 'complete':
+      if ($complete) {
+        return 1;
+      }
+      break;
+  }
+  return 0;
+}
+
+/**
  * Get all possible steps as an array.
  */
 function _multistep_get_steps($form_type) {
@@ -569,6 +631,50 @@
 }
 
 /**
+ * Get status of all steps in a specific node and decide whether the form is complete or no.
+ */
+function _multistep_is_complete($nid) {
+  $type = node_load($nid)->type;
+  $steps = variable_get('multistep_steps_' . $type, 0);
+  // Verify if there's at least one step that's not complete.
+  for ($step = 1; $step <= $steps; $step++) {
+    if (_multistep_get_status($nid, $step) != 'submitted') {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
+
+/**
+ * Decide whether the current submission process will bring the form to completion status, or if it's complete already.
+ */
+function _multistep_will_complete($nid, $current_step) {
+  if (_multistep_is_complete($nid)) {
+    return TRUE;
+  }
+  $type = node_load($nid)->type;
+  $steps = variable_get('multistep_steps_' . $type, 0);
+  $unsubmitted = array();
+  // Verify which steps are not complete.
+  for ($step = 1; $step <= $steps; $step++) {
+    if (_multistep_get_status($nid, $step) != 'submitted') {
+      $unsubmitted[$step] = $step;
+    }
+  }
+  if (count($unsubmitted) == 0) {
+    // If it's complete, submitting the current step will keep it complete.
+    return TRUE;
+  }
+  elseif (count($unsubmitted) == 1 && $unsubmitted[$current_step] == $current_step) {
+    // If the current step is the only one left, submitting it will complete the form.
+    return TRUE;
+  }
+  else {
+    return FALSE;
+  }
+}
+
+/**
  * Implementation of hook_theme(). 
  */
 function multistep_theme() {
