Index: css/webform-admin.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/css/webform-admin.css,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 webform-admin.css --- css/webform-admin.css 19 Aug 2010 03:00:45 -0000 1.1.2.2 +++ css/webform-admin.css 4 Sep 2010 17:45:27 -0000 @@ -60,7 +60,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 4 Sep 2010 17:45:27 -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: 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 4 Sep 2010 17:45:27 -0000 @@ -495,10 +495,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', @@ -557,6 +553,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), @@ -853,7 +858,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 +901,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 +995,9 @@ return array( 'confirmation' => '', 'confirmation_format' => FILTER_FORMAT_DEFAULT, - 'redirect_url' => '', + 'redirect_url' => '', 'teaser' => 0, + 'block' => 0, 'allow_draft' => 0, 'submit_notice' => 0, 'submit_text' => '', @@ -1142,6 +1150,7 @@ return; } + $info = array(); $submission = array(); $submission_count = 0; $enabled = TRUE; @@ -1208,7 +1217,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); } @@ -1326,6 +1335,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. @@ -1368,7 +1517,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 +2015,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'); @@ -2034,34 +2183,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 == '') { + $redirect = NULL; + } + elseif ($redirect_url == '') { + $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 != '') && !empty($confirmation)) { drupal_set_message(check_markup($confirmation, $node->webform['confirmation_format'], FALSE)); } 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 4 Sep 2010 17:45:26 -0000 @@ -37,6 +37,14 @@ 'description' => 'The URL a user is redirected to after submitting a form.', 'type' => 'varchar', 'length' => 255, + 'default' => '', + ), + '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'; @@ -1211,6 +1220,17 @@ } /** + * Add field for block feature and redirection setting. + */ +function webform_update_6320() { + $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' => '')); + update_sql("UPDATE {webform} SET redirect_url = '' WHERE redirect_url = ''"); + 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 4 Sep 2010 17:45:27 -0000 @@ -13,7 +13,9 @@ function webform_configure_form(&$form_state, $node) { $form = array(); - drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css'); + // Add CSS and JS. Don't preprocess because these files are used rarely. + drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE); + drupal_add_js(drupal_get_path('module', 'webform') . '/js/webform-admin.js', 'module', 'header', FALSE, TRUE, FALSE); $form['nid'] = array( '#type' => 'value', @@ -32,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 Redirect URL 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 Confirmation page it will be shown on its own page, otherwise this displays as a message.'), '#default_value' => $node->webform['confirmation'], '#cols' => 40, '#rows' => 10, @@ -40,12 +42,35 @@ $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'], '<>'); + $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' => ('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, ); @@ -117,6 +142,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 will be available as a block.'), + ); $form['advanced']['teaser'] = array( '#type' => 'checkbox', '#title' => t('Show complete form in teaser'), @@ -168,12 +199,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'], '', $form_state); } else { - form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state); + form_set_value($form['submission']['redirection']['redirect_url'], '', $form_state); } } @@ -193,6 +235,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']; @@ -234,3 +279,20 @@ $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. + unset($form['redirect_url']['#title'], $form['redirect_url']['#description']); + + // Add prefix and suffix to display Redirect URL field inline. + $form['redirect']['url']['#prefix'] = '
'; + $form['redirect']['url']['#suffix'] = '
'; + $form['redirect']['url']['#title'] = $form['redirect']['url']['#title'] . ': ' . drupal_render($form['redirect_url']); + return drupal_render($form); +}