### Eclipse Workspace Patch 1.0
#P webform
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal/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	2 Sep 2010 17:08:53 -0000
@@ -14,6 +14,7 @@
   $form = array();
 
   drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css');
+  drupal_add_js(drupal_get_path('module', 'webform') . '/js/webform-admin.js', 'module', 'header', FALSE, TRUE, FALSE);
 
   $form['nid'] = array(
     '#type' => 'value',
@@ -40,11 +41,20 @@
 
   $form['submission']['confirmation_wrapper']['format'] = filter_form($node->webform['confirmation_format'], NULL, array('confirmation_format'));
 
-  // Redirect URL.
-  $form['submission']['redirect_url'] = array(
+  // Redirection settings.
+  $form['submission']['redirection'] = array(
+    '#type' => 'item',
+    '#title' => t('Redirection'),
+    '#theme' => 'webform_advanced_redirection_form',
+    '#description' => t('If enabled the user will be redirected to the confirmation page or the given URL (optional). Enabled by default, uncheck to reload the current page.'),
+  );
+  $form['submission']['redirection']['redirect']= array(
+    '#type' => 'checkbox',
+    '#title' => t('Redirect to confirmation page or custom URL'),
+    '#default_value' => $node->webform['redirect'],
+  );
+  $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'],
     '#maxlength' => 255,
   );
@@ -117,6 +127,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'),
@@ -170,10 +186,10 @@
   // 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.'));
+    form_error($form['submission']['redirection']['redirect_url'], t('The entered URL is not a valid address.'));
   }
   else {
-    form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state);
+    form_set_value($form['submission']['redirection']['redirect_url'], $redirect_url, $form_state);
   }
 }
 
@@ -187,12 +203,16 @@
   $node->webform['confirmation'] = $form_state['values']['confirmation'];
   $node->webform['confirmation_format'] = $form_state['values']['confirmation_format'];
 
-  // Save the redirect URL
+  // Save redirection.
+  $node->webform['redirect'] = $form_state['values']['redirect'];
   $node->webform['redirect_url'] = $form_state['values']['redirect_url'];
 
   // 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'];
 
@@ -234,3 +254,14 @@
   $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) {
+  $form['redirect_url']['#attributes']['class'] = 'webform-set-active';
+  $form['redirect']['#prefix'] = '<div class="webform-container-inline">';
+  $form['redirect']['#suffix'] = '</div>';
+  $form['redirect']['#title'] = $form['redirect']['#title'] . ': ' . drupal_render($form['redirect_url']);
+  return drupal_render($form);
+}
Index: js/webform-admin.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/webform/js/webform-admin.js,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 webform-admin.js
--- js/webform-admin.js	30 Aug 2010 20:22:15 -0000	1.1.2.3
+++ js/webform-admin.js	2 Sep 2010 17:08:53 -0000
@@ -13,6 +13,8 @@
   Drupal.webform.updateTemplate(context);
   // Enhance the normal tableselect.js file to support indentations.
   Drupal.webform.tableSelectIndentation(context);
+  // Disable redirect URL textfield when redirection is disabled.
+  Drupal.webform.disableRedirectUrl(context);
 }
 
 Drupal.webform = Drupal.webform || {};
@@ -98,3 +100,20 @@
   });
 }
 
+Drupal.webform.disableRedirectUrl = function(context) {
+  var redirectUrl = $("#edit-redirect-url");
+  var redirectOption = $("#edit-redirect");
+
+  var toogleRedirectUrlStatus = function () {
+    if (redirectOption.attr("checked")) {
+      redirectUrl.removeAttr("disabled");
+      return;
+    }
+    redirectUrl.val("");
+    redirectUrl.attr("disabled", "disabled");
+  }
+
+  $(function() { toogleRedirectUrlStatus(); }); 
+  redirectOption.change(toogleRedirectUrlStatus);
+
+}
Index: webform.install
===================================================================
RCS file: /cvs/drupal/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	2 Sep 2010 17:08:51 -0000
@@ -33,11 +33,25 @@
         'not null' => TRUE,
         'default' => 0,
       ),
+      'redirect' => array(
+        'description' => 'Boolean value for whether redirect the user after succesfull submission.',
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 1,
+      ),
       'redirect_url' => array(
         'description' => 'The URL a user is redirected to after submitting a form.',
         '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 +388,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 +1226,16 @@
 }
 
 /**
+ * Add field for block feature and redirection setting.
+ */
+function webform_update_6320() {
+  $ret = array();
+  db_add_field($ret, 'webform', 'redirect', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));
+  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: webform.module
===================================================================
RCS file: /cvs/drupal/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	2 Sep 2010 17:08:52 -0000
@@ -495,6 +495,10 @@
       'template' => 'templates/webform-form',
       'pattern' => 'webform_form_[0-9]+',
     ),
+    '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',
@@ -853,7 +857,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 +900,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);
@@ -988,8 +994,10 @@
   return array(
     'confirmation' => '',
     'confirmation_format' => FILTER_FORMAT_DEFAULT,
+    'redirect' => 1,
     'redirect_url' => '',
     'teaser' => 0,
+    'block' => 0,
     'allow_draft' => 0,
     'submit_notice' => 0,
     'submit_text' => '',
@@ -1326,6 +1334,136 @@
 }
 
 /**
+ * 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;
+  }
+}
+
+/**
+ * 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['client-block-'. $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[$delta]) ? $webform_blocks[$delta] : array();
+  $settings += array(
+    'display' => 'form',
+  );
+  // Get the node id from delta.
+  $nid = drupal_substr($delta, strrpos($delta, '-')+1);
+  // The webform node to display in the block.
+  $node = node_load($nid);
+  // 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;
+  // 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[$delta]) ? $webform_blocks[$delta] : array();
+  $settings += array(
+    'display' => 'form',
+  );
+  // Allow the user to choose if the teaser should be displayed in the block.
+  $form = array();
+  $form[$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.'),
+  );
+  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[$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.
@@ -1368,7 +1506,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 +2004,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');
@@ -2032,6 +2170,9 @@
   // Remove the domain name from the redirect.
   $redirect_url = preg_replace('/^' . preg_quote($GLOBALS['base_url'], '/') . '\//', '', $redirect_url);
 
+  // Get redirection setting.
+  $redirect = ($node->webform['redirect'] == 0) ? NULL : TRUE;
+
   // Check confirmation and redirect_url fields.
   $message = NULL;
   $external_url = FALSE;
@@ -2043,25 +2184,27 @@
     $redirect = NULL;
     $message = t('Submission updated.');
   }
-  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);
+  elseif ($redirect) {
+    if (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)) {
+  // If reloading current page or redirecting and we have a confirmation message, show it as a message.
+  elseif ((!$redirect || (!$external_url && !empty($redirect_url))) && !empty($confirmation)) {
     drupal_set_message(check_markup($confirmation, $node->webform['confirmation_format'], FALSE));
   }
 
