Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.124.2.95
diff -u -r1.124.2.95 webform.module
--- webform.module	27 Feb 2009 22:35:15 -0000	1.124.2.95
+++ webform.module	23 Mar 2009 15:59:24 -0000
@@ -199,6 +199,14 @@
     'weight' => 8,
     'type' => MENU_LOCAL_TASK,
   );
+  $items['node/%webform_menu/migrate'] = array(
+    'title' => 'Import/Export',
+    'page callback' => 'webform_settings_migrate_page',
+    'page arguments' => array(1),
+    'access arguments' => 'use PHP for additional processing',
+    'weight' => 2,
+    'type' => MENU_LOCAL_TASK,
+  );
 
   // Node submissions.
   $items['node/%webform_menu/submissions'] = array(
@@ -2302,6 +2310,127 @@
 }
 
 /**
+ * Display the form for importing or exporting webform settings.
+ *
+ * @param $node
+ *   The node containing the webform.
+ *
+ * @return
+ *   The rendered form.
+ */
+function webform_settings_migrate_page($node) {
+  $output = drupal_get_form('webform_settings_import', $node);
+  $output .= drupal_get_form('webform_settings_export', $node);
+  return $output;
+}
+
+/**
+ * The form for exporting webform settings.
+ *
+ * @param $node
+ *   The node with the webform settings to be exported.
+ *
+ * @return
+ *   A Form API array.
+ */
+function webform_settings_export($node) {
+  $form = array();
+  $form['webform_settings_export'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Webform Export'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['webform_settings_export']['settings'] = array(
+    '#type' => 'textarea',
+    '#description' => t('Copy the contents of this field into an import field on another Webform.'),
+    '#value' => var_export($node->webform, TRUE) . ';',
+  );
+  return $form;
+}
+
+/**
+ * The form for importing webform settings.
+ *
+ * @param $form_state
+ *   The current state of the form.
+ *
+ * @param $node
+ *   The node with the webform settings to be imported into.
+ *
+ * @return
+ *   A Form API array.
+ */
+function webform_settings_import($form_state, $node) {
+  $form = array();
+  $form['webform_settings_import'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Webform Import'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  if (empty($node->webform['components'])) {
+    $form['webform_settings_import']['settings'] = array(
+      '#type' => 'textarea',
+      '#description' => t('Copy the contents of an export from another Webform.'),
+    );
+    $form['node'] = array(
+      '#type' => 'hidden',
+      '#value' => $node,
+    );
+    $form['webform_settings_import']['import'] = array(
+      '#type' => 'submit',
+      '#value' => t('Import webform components'),
+    );
+  }
+  else {
+    $form['webform_settings_import']['disabled'] = array(
+      '#prefix' => '<p>',
+      '#suffix' => '</p>',
+      '#value' => t('This Webform has components assigned to it. To import a Webform, remove all components from this form.')
+    );
+  }
+  return $form;
+}
+
+/**
+ * Submit handler for importing Webform settings.
+ *
+ * @param $form_id
+ *   The form ID of the import form.
+ *
+ * @param $form_values
+ *   The values submitted by the user to the form.
+ */
+function webform_settings_import_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
+  eval('$webform = ' . $form_values['settings']);
+  $node = $form_values['node'];
+  array_walk_recursive($webform, 'update_nid', $node->nid);
+  $node->webform = $webform;
+  node_save($node);
+  drupal_set_message(t('Successfully imported the Webform settings.'));
+}
+
+/**
+ * Find all 'nid' keys in an array and update them to the specified node ID.
+ * This is used for updating a node ID when importing from another site.
+ *
+ * @param &$item
+ *   The array with 'nid' keys to update.
+ *
+ * @param $key
+ *   The current key in the array.
+ *
+ * @param $nid
+ *   The node ID to change the 'nid' key to.
+ */
+function _webform_export_update_nid(&$item, $key, $nid) {
+  if ($key == 'nid') {
+    $item[$key] = $nid;
+  }
+}
+/**
  * Given a set of components, determine which one are appropriate for a
  * particular use, such as an email address or subject.
  *
