Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.52
diff -u -r1.196.2.52 webform.module
--- webform.module	30 Aug 2010 20:22:15 -0000	1.196.2.52
+++ webform.module	31 Aug 2010 23:28:33 -0000
@@ -853,7 +853,8 @@
   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']);
+  $node->webform['nid'] = $node->nid;
+  drupal_write_record('webform', $node->webform);
 
   // Insert the components into the database. Used with clone.module.
   if (isset($node->webform['components']) && !empty($node->webform['components'])) {
@@ -895,7 +896,8 @@
   }
 
   // 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);
+  $node->webform['nid'] = $node->nid;
+  drupal_write_record('webform', $node->webform, array('nid'));
 
   // Compare the webform components and don't do anything if it's not needed.
   $original = node_load($node->nid);
@@ -990,6 +992,7 @@
     'confirmation_format' => FILTER_FORMAT_DEFAULT,
     'redirect_url' => '',
     'teaser' => 0,
+    'block' => 0,
     'allow_draft' => 0,
     'submit_notice' => 0,
     'submit_text' => '',
@@ -1326,6 +1329,148 @@
 }
 
 /**
+ * Implementation of hook_block().
+ */
+function webform_block($op = 'list', $delta = 0, $edit = array()) {
+  // The result will be FALSE if this is not a webform node block.
+  if ($op != 'list' && !db_result(db_query("SELECT block FROM {webform} WHERE nid = %d", $delta))) {
+    return;
+  }
+
+  switch ($op) {
+    case 'list':
+      return webform_block_info();
+    case 'view':
+      return webform_block_view($delta);
+    case 'configure':
+      return webform_block_configure($delta);
+    case 'save':
+      webform_block_save($delta, $edit);
+      break;
+  }
+}
+
+/**
+ * Define all webform blocks.
+ */
+function webform_block_info() {
+  $blocks = array();
+  $webform_node_types = webform_variable_get('webform_node_types');
+  if (!empty($webform_node_types)) {
+    $placeholders = db_placeholders($webform_node_types);
+    $result = db_query("SELECT n.title, n.nid FROM {webform} w LEFT JOIN {node} n ON w.nid = n.nid WHERE w.block = 1 AND n.type IN ($placeholders) AND n.status = 1", $webform_node_types);
+    while ($data = db_fetch_object($result)) {
+      $blocks[$data->nid] = array(
+        'info' => t('Webform: !title', array('!title' => $data->title)),
+        'cache' => BLOCK_NO_CACHE,
+      );
+    }
+  }
+  return $blocks;
+}
+
+/**
+ * Generates the contents of the webform blocks.
+ *
+ * @param $delta
+ *   The unique identifier for the block.
+ */
+function webform_block_view($delta = '') {
+  // Load the block-specific configuration settings.
+  $webform_blocks = variable_get('webform_blocks', array());
+  $settings = isset($webform_blocks['block_'. $delta]) ? $webform_blocks['block_'. $delta] : array();
+  $settings += array(
+    'display' => 'form',
+    'redirect' => 'default',
+  );
+  // The webform node to display in the block.
+  $node = node_load($delta);
+  // This is a webform node block.
+  $node->webform_block = TRUE;
+  // Use the node title for the block title, but don't print the title in the block content.
+  $subject = $node->title;
+  if ($settings['redirect'] == 'none') {
+    $node->webform['redirect_url'] = $_GET['q'];
+  }
+  // Check if the teaser should be displayed in the block.
+  if ($settings['display'] == 'form') {
+    webform_node_view($node, FALSE, TRUE, FALSE);
+    $content = $node->content['webform']['#value'];
+  }
+  else {
+    $teaser = ($settings['display'] == 'teaser') ? TRUE : FALSE;
+    $content = node_view($node, $teaser, TRUE, FALSE);
+  }
+  // Create the block.
+  $block = array(
+    'subject' => $subject,
+    'content' => $content,
+  );
+  return $block;
+}
+
+/**
+ * Define a configuration form for a webform block.
+ *
+ * @param $delta
+ *   The unique identifier for the block.
+ */
+function webform_block_configure($delta = '') {
+  // Load the block-specific configuration settings.
+  $webform_blocks = variable_get('webform_blocks', array());
+  $settings = isset($webform_blocks['block_'. $delta]) ? $webform_blocks['block_'. $delta] : array();
+  $settings += array(
+    'display' => 'form',
+    'redirect' => 'default',
+  );
+  // Allow the user to choose if the teaser should be displayed in the block.
+  $form = array();
+  $form['block_'. $delta]['display'] = array(
+    '#type' => 'radios',
+    '#title' => t('Display settings'),
+    '#default_value' => $settings['display'],
+    '#options' => array(
+      'form' => t('Form only'),
+      'full' => t('Full node'),
+      'teaser' => t('Teaser'),
+    ),
+    '#description' => t('Choose how to display the webform node in the block.'),
+  );
+  $form['block_'. $delta]['redirect'] = array(
+    '#type' => 'radios',
+    '#title' => t('Redirect settings'),
+    '#default_value' => $settings['redirect'],
+    '#options' => array(
+      'default' => t('Default, use the webform redirect configuration'),
+      'none' => t('No redirect, keep on the same page'),
+    ),
+    '#description' => t('Choose where to redirect the user to after successful submission.'),
+  );
+  return $form;
+}
+
+/**
+ * Save the configuration options from webform_block_configure().
+ *
+ * @param $delta
+ *   The unique identifier for the block.
+ * @param array $edit
+ *   The submitted form data from the configuration form.
+ */
+function webform_block_save($delta = '', $edit = array()) {
+  // Load the previously defined block-specific configuration settings.
+  $settings = variable_get('webform_blocks', array());
+  // Build the settings array.
+  $new_settings['block_'. $delta] = array(
+    'display' => $edit['display'],
+    'redirect' => $edit['redirect']
+  );
+  // We store settings for multiple blocks in just one variable
+  // so we merge the existing settings with the new ones before save.
+  variable_set('webform_blocks', array_merge($settings, $new_settings));
+}
+
+/**
  * Client form generation function. If this is displaying an existing
  * submission, pass in the $submission variable with the contents of the
  * submission to be displayed.
@@ -1368,7 +1513,7 @@
 
   // Set the form action to the node ID in case this is being displayed on the
   // teaser, subsequent pages should be on the node page directly.
-  if (empty($submission)) {
+  if (!isset($node->webform_block) && empty($submission)) {
     $form['#action'] = url('node/' . $node->nid);
   }
 
@@ -1866,7 +2011,7 @@
     return;
   }
 
-  $node = node_load($form_state['values']['details']['nid']);
+  $node = $form['#node'];
 
   // Check if user is submitting as a draft.
   $is_draft = $form_state['values']['op'] == t('Save Draft');
Index: webform.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.install,v
retrieving revision 1.40.2.17
diff -u -r1.40.2.17 webform.install
--- webform.install	30 Aug 2010 20:22:15 -0000	1.40.2.17
+++ webform.install	31 Aug 2010 23:28:31 -0000
@@ -38,6 +38,13 @@
         'type' => 'varchar',
         'length' => 255,
       ),
+      'block' => array(
+         'description' => 'Boolean value for whether this form be available as a block.',
+         'type' => 'int',
+         'size' => 'tiny',
+         'not null' => TRUE,
+         'default' => 0,
+      ),
       'teaser' => array(
         'description' => 'Boolean value for whether the entire form should be displayed on the teaser.',
         'type' => 'int',
@@ -374,6 +381,7 @@
   variable_del('webform_default_format');
   variable_del('webform_format_override');
   variable_del('webform_csv_delimiter');
+  variable_del('webform_blocks');
 
   $component_list = array();
   $path = drupal_get_path('module', 'webform') . '/components';
@@ -1211,6 +1219,15 @@
 }
 
 /**
+ * Add field for block feature.
+ */
+function webform_update_6320() {
+  $ret = array();
+  db_add_field($ret, 'webform', 'block', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  return $ret;
+}
+
+/**
  * Recursively delete all files and folders in the specified filepath, then
  * delete the containing folder.
  *
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.pages.inc,v
retrieving revision 1.10.2.2
diff -u -r1.10.2.2 webform.pages.inc
--- includes/webform.pages.inc	19 Aug 2010 03:00:45 -0000	1.10.2.2
+++ includes/webform.pages.inc	31 Aug 2010 23:28:33 -0000
@@ -117,6 +117,12 @@
     '#collapsed' => TRUE,
     '#weight' => -1,
   );
+  $form['advanced']['block'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Available as block'),
+    '#default_value' => $node->webform['block'],
+    '#description' => t('If enabled this webform node will be available as a block.'),
+  );
   $form['advanced']['teaser'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show complete form in teaser'),
@@ -193,6 +199,9 @@
   // Save roles.
   $node->webform['roles'] = array_keys(array_filter($form_state['values']['roles']));
 
+  // Set the block option.
+  $node->webform['block'] = $form_state['values']['block'];
+
   // Set the Show complete form in teaser setting.
   $node->webform['teaser'] = $form_state['values']['teaser'];
 
