Index: css/webform-admin.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/css/webform-admin.css,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 webform-admin.css
--- css/webform-admin.css	28 Sep 2010 20:49:24 -0000	1.1.2.3
+++ css/webform-admin.css	17 Oct 2010 18:41:50 -0000
@@ -64,7 +64,8 @@
   text-align: center;
   width: 40px;
 }
-.webform-container-inline div {
+.webform-container-inline div,
+.webform-container-inline div.form-item {
   display: inline;
 }
 .webform-default-value {
Index: css/webform.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/css/webform.css,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 webform.css
--- css/webform.css	19 Aug 2010 03:00:45 -0000	1.1.2.2
+++ css/webform.css	17 Oct 2010 18:41:50 -0000
@@ -8,6 +8,7 @@
   padding: 3px;
   vertical-align: top;
 }
-.webform-container-inline div {
+.webform-container-inline div,
+.webform-container-inline div.form-item {
   display: inline;
 }
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.pages.inc,v
retrieving revision 1.10.2.3
diff -u -r1.10.2.3 webform.pages.inc
--- includes/webform.pages.inc	4 Sep 2010 18:14:04 -0000	1.10.2.3
+++ includes/webform.pages.inc	17 Oct 2010 18:41:50 -0000
@@ -34,7 +34,7 @@
   $form['submission']['confirmation_wrapper']['confirmation'] = array(
     '#type' => 'textarea',
     '#title' => t('Confirmation message'),
-    '#description' => t('Message to be shown upon successful submission. If <em>Redirect URL</em> is set this displays as a message, otherwise it will be shown on its own page.'),
+    '#description' => t('Message to be shown upon successful submission. If the redirection location is set to <em>Confirmation page</em> it will be shown on its own page, otherwise this displays as a message.'),
     '#default_value' => $node->webform['confirmation'],
     '#cols' => 40,
     '#rows' => 10,
@@ -42,12 +42,42 @@
 
   $form['submission']['confirmation_wrapper']['format'] = filter_form($node->webform['confirmation_format'], NULL, array('confirmation_format'));
 
-  // Redirect URL.
-  $form['submission']['redirect_url'] = array(
+  // Redirection settings.
+  if (strpos($node->webform['redirect_url'], '<') === 0) {
+    $redirect = trim($node->webform['redirect_url'], '<>');
+    // Redirection is set to front page.
+    if ($redirect == 'front') {
+      $redirect = 'url';
+      $redirect_url = $node->webform['redirect_url'];
+    }
+    else {
+      $redirect_url = '';
+    }
+  }
+  else {
+    $redirect = 'url';
+    $redirect_url = $node->webform['redirect_url'];
+  }
+  $form['submission']['redirection'] = array(
+    '#type' => 'item',
+    '#title' => t('Redirection location'),
+    '#theme' => 'webform_advanced_redirection_form',
+    '#description' => t('Choose where to redirect the user upon successful submission.'),
+  );
+  $form['submission']['redirection']['redirect']= array(
+    '#type' => 'radios',
+    '#default_value' => $redirect,
+    '#options' => array(
+      'confirmation' => t('Confirmation page'),
+      'url' => t('Custom URL'),
+      'none' => t('No redirect (reload current page)'),
+    ),
+  );
+  $form['submission']['redirection']['redirect_url'] = array(
     '#type' => 'textfield',
     '#title' => t('Redirect URL'),
     '#description' => t('URL to redirect the user to upon successful submission.'),
-    '#default_value' => $node->webform['redirect_url'],
+    '#default_value' => $redirect_url,
     '#maxlength' => 255,
   );
 
@@ -119,6 +149,13 @@
     '#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 will be available as a block.'),
+    '#access' => user_access('administer blocks') || user_access('administer site configuration') || user_access('use panels dashboard'),
+  );
   $form['advanced']['teaser'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show complete form in teaser'),
@@ -170,12 +207,23 @@
   }
 
   // Ensure the entered redirect URL is valid.
-  $redirect_url = trim($form_state['values']['redirect_url']);
-  if (!empty($redirect_url) && strpos($redirect_url, 'http') === 0 && !valid_url($redirect_url, TRUE)) {
-    form_error($form['submission']['redirect_url'], t('The entered URL is not a valid address.'));
+  if ($form_state['values']['redirect'] == 'url') {
+    $redirect_url = trim($form_state['values']['redirect_url']);
+    if (empty($redirect_url)) {
+      form_error($form['submission']['redirection']['redirect_url'], t('A valid URL is required for custom redirection.'));
+    }
+    elseif (strpos($redirect_url, 'http') === 0 && !valid_url($redirect_url, TRUE)) {
+      form_error($form['submission']['redirection']['redirect_url'], t('The entered URL is not a valid address.'));
+    }
+    else {
+      form_set_value($form['submission']['redirection']['redirect_url'], $redirect_url, $form_state);
+    }
+  }
+  elseif ($form_state['values']['redirect'] == 'confirmation') {
+    form_set_value($form['submission']['redirection']['redirect_url'], '<confirmation>', $form_state);
   }
   else {
-    form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state);
+    form_set_value($form['submission']['redirection']['redirect_url'], '<none>', $form_state);
   }
 }
 
@@ -195,6 +243,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'];
 
@@ -236,3 +287,21 @@
   $form['enforce_limit']['yes']['#title'] = t('Limit to !count submission(s) !timespan', $replacements);
   return drupal_render($form);
 }
+
+/**
+ * Theme the redirection setting on the webform node form.
+ */
+function theme_webform_advanced_redirection_form($form) {
+  // Add special class for setting the active radio button.
+  $form['redirect_url']['#attributes']['class'] = 'webform-set-active';
+
+  // Remove title and description for Redirect URL field.
+  $form['redirect_url']['#title'] = NULL;
+  $form['redirect_url']['#description'] = NULL;
+
+  // Add prefix and suffix to display Redirect URL field inline.
+  $form['redirect']['url']['#prefix'] = '<div class="webform-container-inline">';
+  $form['redirect']['url']['#suffix'] = '</div>';
+  $form['redirect']['url']['#title'] = $form['redirect']['url']['#title'] . ': ' . drupal_render($form['redirect_url']);
+  return drupal_render($form);
+}
Index: js/webform-admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/js/webform-admin.js,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 webform-admin.js
--- js/webform-admin.js	4 Sep 2010 18:14:04 -0000	1.1.2.4
+++ js/webform-admin.js	17 Oct 2010 18:41:50 -0000
@@ -4,7 +4,7 @@
  * Webform node form interface enhancments.
  */
 
-Drupal.behaviors.webform = function(context) {
+Drupal.behaviors.webformAdmin = function(context) {
   // Apply special behaviors to fields with default values.
   Drupal.webform.defaultValues(context);
   // On click or change, make a parent radio button selected.
@@ -50,6 +50,7 @@
     $('.form-radio', $(this).parent().parent()).attr('checked', true);
     e.preventDefault();
   };
+  console.log($('.webform-set-active', context));
   $('.webform-set-active', context).click(setActive).change(setActive);
 };
 
Index: webform.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.install,v
retrieving revision 1.40.2.18
diff -u -r1.40.2.18 webform.install
--- webform.install	17 Oct 2010 02:28:52 -0000	1.40.2.18
+++ webform.install	17 Oct 2010 18:41:49 -0000
@@ -37,6 +37,14 @@
         'description' => 'The URL a user is redirected to after submitting a form.',
         'type' => 'varchar',
         'length' => 255,
+        'default' => '<confirmation>',
+      ),
+      '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.',
@@ -374,6 +382,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';
@@ -1220,6 +1229,17 @@
 }
 
 /**
+ * Add field for block feature and redirection setting.
+ */
+function webform_update_6321() {
+  $ret = array();
+  db_add_field($ret, 'webform', 'block', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  db_change_field($ret, 'webform', 'redirect_url', 'redirect_url', array('type' => 'varchar', 'length' => 255, 'default' => '<confirmation>'));
+  update_sql("UPDATE {webform} SET redirect_url = '<confirmation>' WHERE redirect_url = ''");
+  return $ret;
+}
+
+/**
  * Recursively delete all files and folders in the specified filepath, then
  * delete the containing folder.
  *
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.59
diff -u -r1.196.2.59 webform.module
--- webform.module	17 Oct 2010 02:28:52 -0000	1.196.2.59
+++ webform.module	17 Oct 2010 18:41:50 -0000
@@ -501,10 +501,6 @@
       'template' => 'templates/webform-form',
       'pattern' => 'webform_form_[0-9]+',
     ),
-    'webform_advanced_submit_limit_form' => array(
-      'arguments' => array('form' => NULL),
-      'file' => 'includes/webform.pages.inc',
-    ),
     'webform_confirmation' => array(
       'arguments' => array('node' => NULL, 'sid' => NULL),
       'template' => 'templates/webform-confirmation',
@@ -563,6 +559,15 @@
       'arguments' => array('element' => NULL),
       'file' => 'includes/webform.components.inc',
     ),
+    // webform.pages.inc.
+    'webform_advanced_redirection_form' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'includes/webform.pages.inc',
+    ),
+    'webform_advanced_submit_limit_form' => array(
+      'arguments' => array('form' => NULL),
+      'file' => 'includes/webform.pages.inc',
+    ),
     // webform.report.inc.
     'webform_results_per_page' => array(
       'arguments' => array('total_count' => NULL, 'pager_count' => NULL),
@@ -860,7 +865,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'])) {
@@ -902,7 +908,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);
@@ -995,8 +1002,9 @@
   return array(
     'confirmation' => '',
     'confirmation_format' => FILTER_FORMAT_DEFAULT,
-    'redirect_url' => '',
+    'redirect_url' => '<confirmation>',
     'teaser' => 0,
+    'block' => 0,
     'allow_draft' => 0,
     'submit_notice' => 1,
     'submit_text' => '',
@@ -1155,6 +1163,7 @@
     return;
   }
 
+  $info = array();
   $submission = array();
   $submission_count = 0;
   $enabled = TRUE;
@@ -1221,7 +1230,7 @@
   }
 
   // Print out messages for the webform.
-  if ($node->build_mode != NODE_BUILD_PREVIEW && !$logging_in) {
+  if ($node->build_mode != NODE_BUILD_PREVIEW && !isset($node->webform_block) && !$logging_in) {
     theme('webform_view_messages', $node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles);
   }
 
@@ -1339,6 +1348,146 @@
 }
 
 /**
+ * Implementation of hook_block().
+ */
+function webform_block($op = 'list', $delta = 0, $edit = array()) {
+  // Get the node ID from delta.
+  $nid = drupal_substr($delta, strrpos($delta, '-') + 1);
+  // 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", $nid))) {
+    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;
+  }
+}
+
+/**
+ * Implementation of hook_block_info().
+ */
+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)", $webform_node_types);
+    while ($data = db_fetch_object($result)) {
+      $blocks['client-block-'. $data->nid] = array(
+        'info' => t('Webform: !title', array('!title' => $data->title)),
+        'cache' => BLOCK_NO_CACHE,
+      );
+    }
+  }
+  return $blocks;
+}
+
+/**
+ * Implementation of hook_block_view().
+ */
+function webform_block_view($delta = '') {
+  global $user;
+
+  // Load the block-specific configuration settings.
+  $webform_blocks = variable_get('webform_blocks', array());
+  $settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
+  $settings += array(
+    'display' => 'form',
+  );
+
+  // Get the node ID from delta.
+  $nid = drupal_substr($delta, strrpos($delta, '-') + 1);
+
+  // Load node in current language.
+  if (module_exists('translation')) {
+    global $language;
+    if (($translations = translation_node_get_translations($nid)) && (isset($translations[$language->language]))) {
+      $nid = $translations[$language->language]->nid;
+    }
+  }
+
+  // The webform node to display in the block.
+  $node = node_load($nid);
+
+  // Return if user has no access to the webform node.
+  if (!node_access('view', $node)) {
+    return;
+  }
+
+  // This is a webform node block.
+  $node->webform_block = TRUE;
+
+  // Use the node title for the block title.
+  $subject = $node->title;
+
+  // Generate the content of the block based on display settings.
+  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;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function webform_block_configure($delta = '') {
+  // Load the block-specific configuration settings.
+  $webform_blocks = variable_get('webform_blocks', array());
+  $settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
+  $settings += array(
+    'display' => 'form',
+  );
+
+  $form = array();
+  $form['display'] = array(
+    '#type' => 'radios',
+    '#title' => t('Display mode'),
+    '#default_value' => $settings['display'],
+    '#options' => array(
+      'form' => t('Form only'),
+      'full' => t('Full node'),
+      'teaser' => t('Teaser'),
+    ),
+    '#description' => t('The display mode determines how much of the webform to show within the block.'),
+  );
+  return $form;
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+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[$delta] = array(
+    'display' => $edit['display'],
+  );
+  // 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.
@@ -1381,7 +1530,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);
   }
 
@@ -1879,7 +2028,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');
@@ -2047,34 +2196,36 @@
 
   // Check confirmation and redirect_url fields.
   $message = NULL;
+  $redirect = NULL;
   $external_url = FALSE;
   if ($is_draft) {
-    $redirect = NULL;
     $message = t('Draft saved');
   }
   elseif (!empty($form_state['values']['details']['finished'])) {
-    $redirect = NULL;
     $message = t('Submission updated.');
   }
+  elseif ($redirect_url == '<none>') {
+    $redirect = NULL;
+  }
+  elseif ($redirect_url == '<confirmation>') {
+    $redirect = array('node/' . $node->nid . '/done', 'sid=' . $sid);
+  }
   elseif (valid_url($redirect_url, TRUE)) {
     $redirect = $redirect_url;
     $external_url = TRUE;
-   }
+  }
   elseif ($redirect_url && strpos($redirect_url, 'http') !== 0) {
     $parts = parse_url($redirect_url);
     $query = $parts['query'] ? ($parts['query'] . '&sid=' . $sid) : ('sid=' . $sid);
     $redirect = array($parts['path'], $query, $parts['fragment']);
   }
-  else {
-    $redirect = array('node/' . $node->nid . '/done', 'sid=' . $sid);
-  }
 
   // Show a message if manually set.
   if (isset($message)) {
     drupal_set_message($message);
   }
   // If redirecting and we have a confirmation message, show it as a message.
-  elseif (!$external_url && !empty($redirect_url) && !empty($confirmation)) {
+  elseif (!$external_url && (!empty($redirect_url) && $redirect_url != '<confirmation>') && !empty($confirmation)) {
     drupal_set_message(check_markup($confirmation, $node->webform['confirmation_format'], FALSE));
   }
 
