Index: includes/webform.submissions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.submissions.inc,v
retrieving revision 1.20
diff -u -r1.20 webform.submissions.inc
--- includes/webform.submissions.inc	8 Mar 2010 01:04:42 -0000	1.20
+++ includes/webform.submissions.inc	10 Mar 2010 03:58:49 -0000
@@ -132,7 +132,7 @@
   // Iterate through all components and let each do cleanup if necessary.
   foreach ($node->webform['components'] as $cid => $component) {
     if (isset($submission->data[$cid])) {
-      webform_component_invoke($component['type'], 'delete', $component, $submission->data[$cid]);
+      webform_component_invoke($component['type'], 'delete', $component, $submission->data[$cid]['value']);
     }
   }
 
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.pages.inc,v
retrieving revision 1.11
diff -u -r1.11 webform.pages.inc
--- includes/webform.pages.inc	8 Mar 2010 01:04:42 -0000	1.11
+++ includes/webform.pages.inc	10 Mar 2010 03:58:49 -0000
@@ -11,7 +11,13 @@
  * Main configuration form for editing a webform node.
  */
 function webform_configure_form($form, &$form_state, $node) {
-  $form = array();
+  $path = drupal_get_path('module', 'webform');
+  $form = array(
+    '#attached' =>  array(
+      'css' => array($path . '/webform.css' => array('preprocess' => FALSE, 'weight' => CSS_DEFAULT + 1)),
+      'js' => array($path . '/webform.js' => array('preprocess' => FALSE)),
+    ),
+  );
 
   $form['nid'] = array(
     '#type' => 'value',
@@ -35,7 +41,7 @@
     '#cols' => 40,
     '#rows' => 10,
     '#text_format' => $node->webform['confirmation_format'],
-    '#parents' => array('confirmation_format'),
+    '#parents' => array('confirmation'),
   );
 
   // Redirect URL.
@@ -257,16 +263,18 @@
  */
 function theme_webform_advanced_submit_limit_form($variables) {
   $form = $variables['form'];
-  $form['submit_limit']['#attributes']['class'] = 'webform-set-active';
-  $form['submit_interval']['#attributes']['class'] = 'webform-set-active';
+  $form['submit_limit']['#attributes']['class'] = array('webform-set-active');
+  $form['submit_interval']['#attributes']['class'] = array('webform-set-active');
+
   $replacements = array(
     '!count' => drupal_render($form['submit_limit']),
     '!timespan' => drupal_render($form['submit_interval']),
   );
-  $form['enforce_limit']['no']['#prefix'] = '<div class="container-inline">';
-  $form['enforce_limit']['no']['#suffix'] = '</div>';
-  $form['enforce_limit']['yes']['#prefix'] = '<div class="container-inline">';
-  $form['enforce_limit']['yes']['#suffix'] = '</div>';
-  $form['enforce_limit']['yes']['#title'] = t('Limit to !count submission(s) !timespan', $replacements);
-  return drupal_render($form);
+
+  $form['enforce_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
+  $form['enforce_limit']['yes']['#title'] = NULL;
+  $form['enforce_limit']['yes']['#inline_element'] = t('Limit to !count submission(s) !timespan', $replacements);
+  $form['enforce_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
+
+  return drupal_render_children($form);
 }
Index: includes/webform.components.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.components.inc,v
retrieving revision 1.27
diff -u -r1.27 webform.components.inc
--- includes/webform.components.inc	8 Mar 2010 01:04:42 -0000	1.27
+++ includes/webform.components.inc	10 Mar 2010 03:58:48 -0000
@@ -653,7 +653,7 @@
       'form_key' => $component['form_key'],
       'name' => $component['name'],
       'type' => $component['type'],
-      'value' => $component['value'],
+      'value' => (string) $component['value'],
       'extra' => serialize($component['extra']),
       'mandatory' => $component['mandatory'],
       'weight' => $component['weight'],
@@ -712,7 +712,7 @@
     $submissions = webform_get_submissions($node->nid);
     foreach ($submissions as $submission) {
       if (isset($submission->data[$component['cid']])) {
-        webform_component_invoke($component['type'], 'delete', $component, $submission->data[$component['cid']]);
+        webform_component_invoke($component['type'], 'delete', $component, $submission->data[$component['cid']]['value']);
       }
     }
   }
@@ -728,7 +728,7 @@
     ->execute();
 
   // Delete all elements under this element.
-  $result = db_select('webform_component')
+  $result = db_delete('webform_component')
     ->condition('nid', $node->nid)
     ->condition('cid', $component['cid'])
     ->execute();
Index: includes/webform.emails.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.emails.inc,v
retrieving revision 1.11
diff -u -r1.11 webform.emails.inc
--- includes/webform.emails.inc	8 Mar 2010 01:04:42 -0000	1.11
+++ includes/webform.emails.inc	10 Mar 2010 03:58:48 -0000
@@ -35,13 +35,13 @@
     }
 
     $form['emails'][$eid]['email'] = array(
-      '#value' => implode('<br />', $email_addresses),
+      '#markup' => implode('<br />', $email_addresses),
     );
     $form['emails'][$eid]['subject'] = array(
-      '#value' => check_plain(webform_format_email_subject($email['subject'], $node)),
+      '#markup' => check_plain(webform_format_email_subject($email['subject'], $node)),
     );
     $form['emails'][$eid]['from'] = array(
-      '#value' => check_plain(webform_format_email_address($email['from_address'], $email['from_name'], $node, NULL, FALSE)),
+      '#markup' => check_plain(webform_format_email_address($email['from_address'], $email['from_name'], $node, NULL, FALSE)),
     );
   }
 
@@ -133,17 +133,13 @@
   // Add a default value to the custom e-mail textfield.
   $form['email_custom']['#value'] = t('email@example.com');
   $form['email_custom']['#attributes']['class'] = array('webform-set-active', 'webform-default-value');
-  $form['email_option']['custom']['#title'] = $form['email_option']['custom']['#title'] . ': ' . drupal_render($form['email_custom']);
+  $form['email_option']['custom']['#theme_wrappers'] = array('webform_inline_radio');
+  $form['email_option']['custom']['#inline_element'] = drupal_render($form['email_custom']);
 
   // Render the component value.
   $form['email_component']['#attributes']['class'] = array('webform-set-active');
-  $form['email_option']['component']['#title'] = $form['email_option']['component']['#title'] . ': ' . drupal_render($form['email_component']);
-
-  // For spacing consistency, every option is wrapped in container-inline.
-  foreach (element_children($form['email_option']) as $option) {
-    $form['email_option'][$option]['#prefix'] = '<div class="container-inline">';
-    $form['email_option'][$option]['#suffix'] = '</div>';
-  }
+  $form['email_option']['component']['#theme_wrappers'] = array('webform_inline_radio');
+  $form['email_option']['component']['#inline_element'] = drupal_render($form['email_component']);
 
   return drupal_render_children($form);
 }
@@ -158,7 +154,7 @@
   else {
     $email = $form_state['values']['email_component'];
   }
-  $form_state['redirect'] = array('node/' . $form['#node']->nid . '/webform/emails/new', array('option' => $form_state['values']['email_option'], 'email' => trim($email)));
+  $form_state['redirect'] = array('node/' . $form['#node']->nid . '/webform/emails/new', array('query' => array('option' => $form_state['values']['email_option'], 'email' => trim($email))));
 }
 
 /**
@@ -171,7 +167,7 @@
     '#attached' =>  array(
       'css' => array($path . '/webform.css' => array('preprocess' => FALSE, 'weight' => CSS_DEFAULT + 1)),
       'js' => array($path . '/webform.js' => array('preprocess' => FALSE)),
-    )
+    ),
   );
   $form['node'] = array(
     '#type' => 'value',
@@ -215,10 +211,10 @@
       '#description' => $description,
     );
     if (!empty($default_value)) {
-      $form[$field . '_option']['#options']['default'] = $default_value;
+      $form[$field . '_option']['#options']['default'] = t('Default: %value', array('%value' => $default_value));
     }
-    $form[$field . '_option']['#options']['custom'] = 'custom';
-    $form[$field . '_option']['#options']['component'] = 'component';
+    $form[$field . '_option']['#options']['custom'] = t('Custom');
+    $form[$field . '_option']['#options']['component'] = t('Component');
 
     $form[$field . '_custom'] = array(
       '#type' => 'textfield',
@@ -312,18 +308,13 @@
 
   // Loop through fields, rendering them into radio button options.
   foreach (array('email', 'subject', 'from_address', 'from_name') as $field) {
-    foreach (array('custom' => t('Custom'), 'component' => t('Component')) as $option => $title) {
+    foreach (array('custom', 'component') as $option) {
       $form[$field . '_' . $option]['#attributes']['class'] = array('webform-set-active');
-      $form[$field . '_option'][$option]['#title'] = $title . ': ' . drupal_render($form[$field . '_' . $option]);
+      $form[$field . '_option'][$option]['#theme_wrappers'] = array('webform_inline_radio');
+      $form[$field . '_option'][$option]['#inline_element'] = drupal_render($form[$field . '_' . $option]);
     }
-    // For spacing consistency, every option is wrapped in container-inline.
-    foreach (element_children($form[$field . '_option']) as $option) {
-      $form[$field . '_option'][$option]['#prefix'] = '<div class="container-inline">';
-      $form[$field . '_option'][$option]['#suffix'] = '</div>';
-    }
-    // Wrap the default option in a placeholder tag..
     if (isset($form[$field . '_option']['#options']['default'])) {
-      $form[$field . '_option']['default']['#title'] = t('Default') . ': ' . drupal_placeholder(array('text' => $form[$field . '_option']['default']['#title']));
+      $form[$field . '_option']['default']['#theme_wrappers'] = array('webform_inline_radio');
     }
   }
 
@@ -338,12 +329,16 @@
     '#children' => $details,
     '#collapsible' => FALSE,
     '#parents' => array('details'),
+    '#groups' => array('details' => array()),
     '#attributes' => array(),
   );
 
   $form['template']['template']['#description'] .= drupal_render($form['template']['components']);
 
-  return drupal_render_children($form);
+  // Re-sort the elements since we added the details fieldset.
+  $form['#sorted'] = FALSE;
+  $children = element_children($form, TRUE);
+  return drupal_render_children($form, $children);
 }
 
 /**
@@ -472,12 +467,12 @@
   // TODO: This is not race-condition safe. Switch to using transactions?
   if (!isset($email['eid'])) {
     $next_id_query = db_select('webform_emails')->condition('nid', $email['nid']);
-    $email->addExpression('MAX(cid) + 1', 'eid');
-    $component['eid'] = $next_id_query->execute()->fetchField();
+    $next_id_query->addExpression('MAX(eid) + 1', 'eid');
+    $email['eid'] = $next_id_query->execute()->fetchField();
   }
 
   $email['excluded_components'] = implode(',', $email['excluded_components']);
-  $success = drupal_write_record($email);
+  $success = drupal_write_record('webform_emails', $email);
 
   return $success ? $email['eid'] : FALSE;
 }
@@ -491,7 +486,7 @@
  */
 function webform_email_update($email) {
   $email['excluded_components'] = implode(',', $email['excluded_components']);
-  return drupal_write_record($email);
+  return drupal_write_record('webform_emails', $email, 'eid');
 }
 
 /**
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.198
diff -u -r1.198 webform.module
--- webform.module	8 Mar 2010 01:04:42 -0000	1.198
+++ webform.module	10 Mar 2010 03:58:47 -0000
@@ -453,19 +453,19 @@
   if (module_exists('form_builder') && strpos($_GET['q'], 'admin/build/form-builder') !== FALSE) {
     module_load_include('inc', 'webform', 'includes/webform.form_builder');
   }
+}
 
-  // Use the administrative theme if set to use on content editing pages.
-  // See system_init().
-  if (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(2) == 'webform' || arg(2) == 'webform-results')) {
-    global $custom_theme;
-    $custom_theme = variable_get('admin_theme', '0');
-    drupal_add_css(drupal_get_path('module', 'system') . '/admin.css', 'module');
-
-    // Support for Admin module (1.x).
-    if (function_exists('_admin_init_theme')) {
-      _admin_init_theme();
-    }
-  }
+/**
+ * Implementation of hook_admin_paths().
+ */
+function webform_admin_paths() {
+  return array(
+    'node/*/webform' => TRUE,
+    'node/*/webform/*' => TRUE,
+    'node/*/webform-results' => TRUE,
+    'node/*/webform-results/*' => TRUE,
+    'node/*/submission/*' => TRUE,
+  );
 }
 
 /**
@@ -531,6 +531,9 @@
     'webform_element_text' => array(
       'render element' => 'element',
     ),
+    'webform_inline_radio' => array(
+      'render element' => 'element',
+    ),
     'webform_mail_message' => array(
       'variables' => array('node' => NULL, 'submission' => NULL, 'cid' => NULL),
       'template' => 'templates/webform-mail',
@@ -2160,6 +2163,48 @@
 }
 
 /**
+ * Theme a radio button and another element together.
+ *
+ * This is used in the e-mail configuration to show a radio button and a text
+ * field or select list on the same line.
+ */
+function theme_webform_inline_radio($variables) {
+  $element = $variables['element'];
+
+  // Add element's #type and #name as class to aid with JS/CSS selectors.
+  $class = array('form-item');
+  if (!empty($element['#type'])) {
+    $class[] = 'form-type-' . strtr($element['#type'], '_', '-');
+  }
+  if (!empty($element['#name'])) {
+    $class[] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
+  }
+
+  // Add container-inline to all elements.
+  $class[] = 'container-inline';
+  if (isset($element['#inline_element'])) {
+    $variables['element']['#title'] = $variables['element']['#title'] . ': ';
+  }
+
+  $output = '<div class="' . implode(' ', $class) . '">' . "\n";
+  $output .= ' ' . $element['#children'];
+  if (!empty($element['#title'])) {
+    $output .= ' ' . theme('form_element_label', $variables) . "\n";
+  }
+  if (isset($element['#inline_element'])) {
+    $output .= ' ' . $element['#inline_element'] . "\n";
+  }
+
+  if (!empty($element['#description'])) {
+    $output .= ' <div class="description">' . $element['#description'] . "</div>\n";
+  }
+
+  $output .= "</div>\n";
+
+  return $output;
+}
+
+/**
  * Theme the headers when sending an email from webform.
  *
  * @param $node
Index: components/file.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/file.inc,v
retrieving revision 1.19
diff -u -r1.19 file.inc
--- components/file.inc	8 Mar 2010 01:04:42 -0000	1.19
+++ components/file.inc	10 Mar 2010 03:58:48 -0000
@@ -129,7 +129,7 @@
       '#default_value' => $component['extra']['savelocation'],
       '#description' => '<div style="display: block">' . t('Webform uploads are always saved in the site files directory. You may optionally specify a subfolder to store your files.') . '</div>',
       '#weight' => 3,
-      '#element_validate' => array('_webform_edit_file_check_directory', '_webform_edit_file_validate'),
+      '#element_validate' => array('_webform_edit_file_check_directory'),
       '#after_build' => array('_webform_edit_file_check_directory'),
     );
     $form['display']['width'] = array(
@@ -151,12 +151,9 @@
  * Ensure that the destination directory exists and is writable.
  */
 function _webform_edit_file_check_directory($element) {
-  $base_dir = file_directory_path() . '/webform';
-  $base_success = file_check_directory($base_dir, FILE_CREATE_DIRECTORY);
-
-  $destination_dir = $base_dir . '/' . $element['#value'];
-  $destination_success = file_check_directory($destination_dir, FILE_CREATE_DIRECTORY);
-  if (!$base_success || !$destination_success) {
+  $destination_dir = file_build_uri('webform/' . $element['#value']);
+  $destination_success = file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
+  if (!$destination_success) {
     form_set_error('savelocation', t('The save directory %directory could not be created. Check that the webform files directory is writtable.', array('%directory' => $destination_dir)));
   }
   return $element;
@@ -194,18 +191,16 @@
 function theme_webform_edit_file($variables) {
   $form = $variables['form'];
 
-  // Add a little javascript to check all the items in one type.
+  // Add a little JavaScript to check all the items in one type.
   $javascript = '
-    <script type="text/javascript">
-      function check_category_boxes() {
-        var checkValue = !document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[1]).checked;
-        for(var i=1; i < arguments.length; i++) {
-          document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[i]).checked = checkValue;
-        }
+    function check_category_boxes() {
+      var checkValue = !document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[1]).checked;
+      for(var i=1; i < arguments.length; i++) {
+        document.getElementById("edit-extra-filtering-types-"+arguments[0]+"-"+arguments[i]).checked = checkValue;
       }
-  </script>
+    }
  ';
-  drupal_add_html_head($javascript);
+  drupal_add_js($javascript, 'inline');
 
   // Format the components into a table.
   $per_row = 6;
@@ -218,7 +213,7 @@
       $row[] = $form['validation']['filtering']['types'][$filtergroup]['#title'];
       $row[] = '&nbsp;';
       // Convert the checkboxes into individual form-items.
-      $checkboxes = expand_checkboxes($form['validation']['filtering']['types'][$filtergroup]);
+      $checkboxes = form_process_checkboxes($form['validation']['filtering']['types'][$filtergroup]);
       // Render the checkboxes in two rows.
       $checkcount = 0;
       $jsboxes = '';
@@ -274,7 +269,7 @@
     '#rows' => $rows
   );
 
-  $output = drupal_render($form);
+  $output = drupal_render_children($form);
 
   // Prefix the upload location field with the default path for webform.
   $output = str_replace('Upload Directory: </label>', 'Upload Directory: </label>' . file_directory_path() . '/webform/', $output);
@@ -339,7 +334,7 @@
   // Add information about the existing file, if any.
   $value = $element['_fid']['#value'] ? $element['_fid']['#value'] : $element['_old']['#value'];
   if ($value && ($file = webform_get_file($value))) {
-    $element['#suffix'] = ' ' . l(t('Download !filename', array('!filename' => webform_file_name($file->filepath))), webform_file_url($file->filepath)) . (isset($element['#suffix']) ? $element['#suffix'] : '');
+    $element['#suffix'] = ' ' . l(t('Download !filename', array('!filename' => webform_file_name($file->uri))), webform_file_url($file->uri)) . (isset($element['#suffix']) ? $element['#suffix'] : '');
     $element['#description'] = t('Uploading a new file will replace the current file.');
   }
 
@@ -348,7 +343,7 @@
     $element[$element['#webform_form_key']]['#required'] = TRUE;
   }
 
-  return drupal_render($element);
+  return drupal_render_children($element);
 }
 
 /**
@@ -435,8 +430,8 @@
 
   // Save the file to a temporary location.
   if (!$file_error) {
-    $upload_dir = file_directory_path() . '/webform/' . $component['extra']['savelocation'];
-    if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
+    $upload_dir = file_build_uri('webform/' . $component['extra']['savelocation']);
+    if (file_prepare_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
       $file = file_save_upload($form_key, array(), $upload_dir);
       if ($file) {
         // Set the hidden field value.
@@ -503,7 +498,7 @@
   $element = $variables['element'];
 
   $file = $element['#value'];
-  $url = !empty($file) ? webform_file_url($file->filepath) : t('no upload');
+  $url = !empty($file) ? webform_file_url($file->uri) : t('no upload');
   return !empty($file) ? ($element['#format'] == 'text' ? $url : l($file->filename, $url)) : ' ';
 }
 
@@ -513,8 +508,7 @@
 function _webform_delete_file($component, $value) {
   // Delete an individual submission file.
   if (isset($value[0]) && ($file = webform_get_file($value[0]))) {
-    unlink($file->filepath);
-    db_query("DELETE FROM {files} WHERE fid = '%d'", $file->fid);
+    file_delete($file);
   }
 }
 
@@ -558,7 +552,7 @@
   $output = '';
   $file = webform_get_file($value[0]);
   if (!empty($file->fid)) {
-    $output = '<a href="' . webform_file_url($file->filepath) . '">' . webform_file_name($file->filepath) . '</a>';
+    $output = '<a href="' . webform_file_url($file->uri) . '">' . webform_file_name($file->uri) . '</a>';
     $output .= ' (' . (int) ($file->filesize/1024) . ' KB)';
   }
   return $output;
@@ -581,7 +575,7 @@
  */
 function _webform_csv_data_file($component, $export_options, $value) {
   $file = webform_get_file($value[0]);
-  return empty($file->filename) ? array('', '') : array(webform_file_url($file->filepath), (int) ($file->filesize/1024));
+  return empty($file->filename) ? array('', '') : array(webform_file_url($file->uri), (int) ($file->filesize/1024));
 }
 
 /**
@@ -598,28 +592,18 @@
 /**
  * Helper function to create proper URLs for uploaded file.
  */
-function webform_file_url($filepath) {
-  if (!empty($filepath)) {
-    $info = pathinfo($filepath);
-    $file_url = file_create_url($info['dirname'] . '/' . rawurlencode($info['basename']));
+function webform_file_url($uri) {
+  if (!empty($uri)) {
+    $file_url = file_create_url($uri);
   }
   return isset($file_url) ? $file_url : '';
 }
 
 /**
  * Helper function to load a file from the database.
+ *
+ * @todo We can remove this entirely now the Drupal 7 has native file loading.
  */
 function webform_get_file($fid) {
-  static $files;
-
-  if (!isset($files[$fid])) {
-    if (empty($fid)) {
-      $files[$fid] = FALSE;
-    }
-    else {
-      $files[$fid] = db_fetch_object(db_query("SELECT * FROM {files} WHERE fid = %d", $fid));
-    }
-  }
-
-  return $files[$fid];
+  return file_load($fid);
 }
\ No newline at end of file
