Index: components/hidden.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/hidden.inc,v
retrieving revision 1.16
diff -u -r1.16 hidden.inc
--- components/hidden.inc	10 Jan 2010 07:03:27 -0000	1.16
+++ components/hidden.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module hidden component.
+ * Webform module hidden component.
  */
 
 /**
- * Create a default hidden component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_hidden() {
   return array(
@@ -22,42 +22,31 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_hidden($currfield) {
-  $edit_fields = array();
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_hidden($component) {
+  $form = array();
+  $form['value'] = array(
     '#type' => 'textarea',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') . theme('webform_token_help'),
     '#cols' => 60,
     '#rows' => 5,
     '#weight' => 0,
   );
-  $edit_fields['advanced']['mandatory'] = array(
+  $form['advanced']['mandatory'] = array(
     '#type' => 'hidden',
     '#value' => 1,
   );
-  $edit_fields['extra']['description'] = array(); // Hide the description box.
-  return $edit_fields;
+  $form['extra']['description'] = array(); // Hide the description box.
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_hidden($component, $filter = TRUE) {
+function _webform_render_hidden($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#type'          => 'hidden',
     '#title'         => $component['name'],
@@ -65,40 +54,31 @@
     '#weight'        => $component['weight'],
   );
 
+  if (isset($value[0])) {
+    $form_item['#default_value'] = $value[0];
+  }
+
   return $form_item;
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_hidden($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_hidden($component);
+function _webform_display_hidden($component, $value) {
+  $form_item = _webform_render_hidden($component, $value);
   // Only allow administrators that can view or edit all submissions to view or edit hidden fields.
   if (user_access('edit all webform submissions') || user_access('access all webform results')) {
     unset($form_item['#value']);
-    $form_item['#default_value'] = $data['value']['0'];
+    $form_item['#default_value'] = $value[0];
     $form_item['#type'] = 'textfield';
     $form_item['#title'] = t('@name (hidden)', array('@name' => $component['name']));
-    if (!$enabled) {
-      $form_item['#attributes']['readonly'] = 'readonly';
-    }
+    $form_item['#disabled'] = TRUE;
   }
   return $form_item;
 }
 
 /**
- * Module specific instance of hook_form_builder_preview_alter().
+ * Implementation of _webform_form_builder_preview_alter_component().
  *
  * Make hidden fields visible while editing.
  */
@@ -109,7 +89,7 @@
 }
 
 /**
- * Module specific instance of hook_form_builder_types().
+ * Implementation of _webform_form_builder_types_component().
  */
 function _webform_form_builder_types_hidden() {
   $fields = array();
@@ -131,7 +111,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_hidden($section) {
   switch ($section) {
@@ -141,18 +121,7 @@
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_hidden($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -182,29 +151,14 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
- */
-function _webform_table_data_hidden($data) {
-  return check_plain(empty($data['value']['0']) ? '' : $data['value']['0']);
+ * Implementation of _webform_csv_data_component().
+ */
+function _webform_table_data_hidden($component, $value) {
+  return check_plain(empty($value[0]) ? '' : $value[0]);
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_data_component().
  */
 function _webform_csv_headers_hidden($component) {
   $header = array();
@@ -215,15 +169,8 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_hidden($data) {
-  return empty($data['value']['0']) ? '' : $data['value']['0'];
+function _webform_csv_data_hidden($component, $value) {
+  return empty($value[0]) ? '' : $value[0];
 }
Index: components/textarea.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/textarea.inc,v
retrieving revision 1.15
diff -u -r1.15 textarea.inc
--- components/textarea.inc	20 Jun 2009 23:04:58 -0000	1.15
+++ components/textarea.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module textarea component.
+ * Webform module textarea component.
  */
 
 /**
- * Create a default textarea component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_textarea() {
   return array(
@@ -30,68 +30,57 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_textarea($currfield) {
-  $edit_fields = array();
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_textarea($component) {
+  $form = array();
+  $form['value'] = array(
     '#type' => 'textarea',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') . theme('webform_token_help'),
     '#cols' => 60,
     '#rows' => 5,
     '#weight' => 0,
   );
-  $edit_fields['extra']['cols'] = array(
+  $form['extra']['cols'] = array(
     '#type' => 'textfield',
     '#title' => t('Width'),
-    '#default_value' => $currfield['extra']['cols'],
+    '#default_value' => $component['extra']['cols'],
     '#description' => t('Width of the textfield.') .' '. t('Leaving blank will use the default size.'),
     '#size' => 5,
     '#maxlength' => 10,
   );
-  $edit_fields['extra']['rows'] = array(
+  $form['extra']['rows'] = array(
     '#type' => 'textfield',
     '#title' => t('Height'),
-    '#default_value' => $currfield['extra']['rows'],
+    '#default_value' => $component['extra']['rows'],
     '#description' => t('Height of the textfield.') .' '. t('Leaving blank will use the default size.'),
     '#size' => 5,
     '#maxlength' => 10,
   );
-  $edit_fields['extra']['resizable'] = array(
+  $form['extra']['resizable'] = array(
     '#type' => 'checkbox',
     '#title' => t('Resizable'),
     '#description' => t('Make this field resizable by the user.'),
     '#weight' => 2,
-    '#default_value' => $currfield['extra']['resizable'],
+    '#default_value' => $component['extra']['resizable'],
   );
-  $edit_fields['extra']['disabled'] = array(
+  $form['extra']['disabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Disabled'),
     '#return_value' => 1,
     '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
     '#weight' => 3,
-    '#default_value' => $currfield['extra']['disabled'],
+    '#default_value' => $component['extra']['disabled'],
   );
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_textarea($component, $filter = TRUE) {
+function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#type'          => 'textarea',
     '#title'         => $component['name'],
@@ -111,34 +100,25 @@
     $form_item['#attributes']['readonly'] = 'readonly';
   }
 
+  if (isset($value)) {
+    $form_item['#default_value'] = $value[0];
+  }
+
   return $form_item;
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
- */
-function _webform_submission_display_textarea($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_textarea($component);
-  $form_item['#default_value'] = $data['value']['0'];
-  if (!$enabled) {
-    $form_item['#attributes']['readonly'] = 'readonly';
-  }
+ * Implementation of _webform_display_component().
+ */
+function _webform_display_textarea($component, $value) {
+  $form_item = _webform_render_textarea($component, $value);
+  $form_item['#default_value'] = $value[0];
+  $form_item['#attributes']['readonly'] = 'readonly';
   return $form_item;
 }
 
 /**
- * Module specific instance of hook_form_builder_types().
+ * Implementation of _webform_form_builder_types_component().
  */
 function _webform_form_builder_types_textarea() {
   $fields = array();
@@ -165,7 +145,7 @@
 }
 
 /**
- * Convert a FAPI form element into settings savable in a component.
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_textarea(&$component, $form_element) {
   $component['extra']['description'] = $form_element['#description'];
@@ -176,7 +156,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_textarea($section) {
   switch ($section) {
@@ -186,18 +166,7 @@
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_textarea($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -226,29 +195,14 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
- */
-function _webform_table_data_textarea($data) {
-  return empty($data['value']['0']) ? '' : check_plain($data['value']['0']);
+ * Implementation of _webform_table_data_component().
+ */
+function _webform_table_data_textarea($component, $value) {
+  return empty($value[0]) ? '' : check_plain($value[0]);
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_textarea($component) {
   $header = array();
@@ -259,15 +213,8 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_textarea($data) {
-  return empty($data['value']['0']) ? '' : $data['value']['0'];
+function _webform_csv_data_textarea($component, $value) {
+  return empty($value[0]) ? '' : $value[0];
 }
Index: components/file.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/file.inc,v
retrieving revision 1.5
diff -u -r1.5 file.inc
--- components/file.inc	7 May 2009 22:38:14 -0000	1.5
+++ components/file.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module file component.
+ * Webform module file component.
  */
 
 /**
- * Create a default file component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_file() {
   return array(
@@ -32,17 +32,12 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this component.
- * Use care naming the form items, as this correlates directly to the database schema.
- * The component "Name" and "Description" fields are added to every component type and
- * are not necessary to specify here (although they may be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page
+ * Implementation of _webform_edit_component().
  */
-function _webform_edit_file($currfield) {
-    $edit_fields = array();
-    $edit_fields['#theme'] = 'webform_edit_file';
-    $edit_fields['extra']['filtering'] = array(
+function _webform_edit_file($component) {
+    $form = array();
+    $form['#theme'] = 'webform_edit_file';
+    $form['extra']['filtering'] = array(
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => FALSE,
@@ -52,10 +47,10 @@
     );
 
     // Find the list of all currently valid extensions.
-    $current_types = isset($currfield['extra']['filtering']['types']) ? $currfield['extra']['filtering']['types'] : array();
+    $current_types = isset($component['extra']['filtering']['types']) ? $component['extra']['filtering']['types'] : array();
 
     $types = array('gif', 'jpg', 'png');
-    $edit_fields['extra']['filtering']['types']['webimages'] = array(
+    $form['extra']['filtering']['types']['webimages'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Web Images'),
       '#options' => drupal_map_assoc($types),
@@ -63,7 +58,7 @@
     );
 
     $types = array('bmp', 'eps', 'tif', 'pict', 'psd');
-    $edit_fields['extra']['filtering']['types']['desktopimages'] = array(
+    $form['extra']['filtering']['types']['desktopimages'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Desktop Images'),
       '#options' => drupal_map_assoc($types),
@@ -71,7 +66,7 @@
     );
 
     $types = array('txt', 'rtf', 'html', 'odf', 'pdf', 'doc', 'ppt', 'xls', 'xml');
-    $edit_fields['extra']['filtering']['types']['documents'] = array(
+    $form['extra']['filtering']['types']['documents'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Documents'),
       '#options' => drupal_map_assoc($types),
@@ -79,7 +74,7 @@
     );
 
     $types = array('avi', 'mov', 'mp3', 'ogg', 'wav');
-    $edit_fields['extra']['filtering']['types']['media'] = array(
+    $form['extra']['filtering']['types']['media'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Media'),
       '#options' => drupal_map_assoc($types),
@@ -87,53 +82,58 @@
     );
 
     $types = array('bz2', 'dmg', 'gz', 'jar', 'rar', 'sit', 'tar', 'zip');
-    $edit_fields['extra']['filtering']['types']['archives'] = array(
+    $form['extra']['filtering']['types']['archives'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Archives'),
       '#options' => drupal_map_assoc($types),
       '#default_value' => array_intersect($current_types, $types),
     );
 
-    $edit_fields['extra']['filtering']['addextensions'] = array(
+    $form['extra']['filtering']['addextensions'] = array(
       '#type' => 'textfield',
       '#title' => t('Additional Extensions'),
-      '#default_value' => $currfield['extra']['filtering']['addextensions'],
+      '#default_value' => $component['extra']['filtering']['addextensions'],
       '#description' => t('Enter a list of additional file extensions for this upload field, seperated by commas.<br /> Entered extensions will be appended to checked items above.'),
       '#size' => 60,
       '#weight' => 3,
-      '#default_value' => $currfield['extra']['filtering']['addextensions'],
+      '#default_value' => $component['extra']['filtering']['addextensions'],
     );
 
-    $edit_fields['extra']['filtering']['size'] = array(
+    $form['extra']['filtering']['size'] = array(
       '#type' => 'textfield',
       '#title' => t('Max Upload Size'),
-      '#default_value' => $currfield['extra']['filtering']['size'],
+      '#default_value' => $component['extra']['filtering']['size'],
       '#description' => t('Enter the max file size a user may upload (in KB).'),
       '#size' => 10,
       '#weight' => 3,
-      '#default_value' => $currfield['extra']['filtering']['size'],
+      '#default_value' => $component['extra']['filtering']['size'],
     );
-    $edit_fields['extra']['savelocation'] = array(
+    $form['extra']['savelocation'] = array(
       '#type' => 'textfield',
       '#title' => t('Upload Directory'),
-      '#default_value' => $currfield['extra']['savelocation'],
+      '#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'),
       '#after_build' => array('_webform_edit_file_check_directory'),
     );
-    $edit_fields['extra']['width'] = array(
+    $form['extra']['width'] = array(
       '#type' => 'textfield',
       '#title' => t('Width'),
-      '#default_value' => $currfield['extra']['width'],
+      '#default_value' => $component['extra']['width'],
       '#description' => t('Width of the file field.') .' '. t('Leaving blank will use the default size.'),
       '#size' => 5,
       '#maxlength' => 10,
       '#weight' => 4,
     );
-    return $edit_fields;
+    return $form;
 }
 
+/**
+ * A Form API after build function.
+ *
+ * Ensure that the destination directory exists and is writable.
+ */
 function _webform_edit_file_check_directory($form_element) {
   $base_dir = file_directory_path() .'/webform';
   $base_success = file_check_directory($base_dir, FILE_CREATE_DIRECTORY);
@@ -147,6 +147,8 @@
 }
 
 /**
+ * A Form API element validate function.
+ *
  * Change the submitted values of the component so that all filtering extensions
  * are saved as a single array.
  */
@@ -261,14 +263,9 @@
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_file($component) {
+function _webform_render_file($component, $value = NULL) {
   $form_item[$component['form_key']] = array(
     '#type'          => $component['type'],
     '#title'         => $component['name'],
@@ -292,6 +289,19 @@
     '#value' => $component['form_key'],
     '#tree' => TRUE,
   );
+
+  if (isset($value)) {
+    $file_data = unserialize($value[0]);
+    if (isset($file_data['filename'])) {
+      $form_item['#suffix'] = ' <a href="'. webform_file_url($file_data['filepath']) .'">Download '. $file_data['filename'] .'</a>'. $form_item['#suffix'];
+      $form_item['#description'] = t('Uploading a new file will replace the current file.');
+      $form_item['existing'] = array(
+        '#type' => 'value',
+        '#value' => $file_data,
+      );
+    }
+  }
+
   // Change the 'width' option to the correct 'size' option.
   if ($component['extra']['width'] > 0) {
     $form_item[$component['form_key']]['#size'] = $component['extra']['width'];
@@ -300,15 +310,25 @@
   return $form_item;
 }
 
+/**
+ * A Form API element validate function.
+ *
+ * Fix Drupal core's handling of required file fields.
+ */
 function _webform_required_file($form_element, $form_state) {
   $component = $form_element['#webform_component'];
   $form_key = $component['form_key'];
 
   if (empty($_FILES['files']['name'][$form_key]) && $component['mandatory']) {
-    form_set_error($form_key, t('%field field is required.', array('%field' => $component['name'])));
+    form_error($form_element, t('%field field is required.', array('%field' => $component['name'])));
   }
 }
 
+/**
+ * A Form API element validate function.
+ *
+ * Ensure that the uploaded file matches the specified file types.
+ */
 function _webform_validate_file($form_element, &$form_state) {
   $component = $form_element['#webform_component'];
   $form_key = $component['form_key'];
@@ -347,30 +367,22 @@
 }
 
 /**
- * Perform additional server-side processing on the submitted data, such as
- * managing an uploaded file.
- * @param $data
- *   The POST data associated with the component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   Nothing.
+ * Implementation of _webform_submit_component().
  */
-function _webform_submit_file(&$data, $component) {
+function _webform_submit_file($component, $value) {
   $upload_dir = file_directory_path() .'/webform/'. $component['extra']['savelocation'];
-  if (!empty($_FILES['files']['name'][$data['new']])) {
+  if (!empty($_FILES['files']['name'][$value['new']])) {
     if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
-      $file_saved = file_save_upload($data['new'], array(), $upload_dir);
+      $file_saved = file_save_upload($value['new'], array(), $upload_dir);
       if (!$file_saved) {
         drupal_set_message(t('The uploaded file %filename was unable to be saved. The destination directory may not be writable.', array('%filename' => $file_saved['filename'])), 'error');
       }
       else {
         file_set_status($file_saved, FILE_STATUS_PERMANENT);
-        if (isset($data['existing']['filepath'])) {
-          file_delete($data['existing']['filepath']);
+        if (isset($value['existing']['filepath'])) {
+          file_delete($value['existing']['filepath']);
         }
-        $data = serialize((array)$file_saved);
+        $value = serialize((array) $file_saved);
       }
     }
     else {
@@ -378,84 +390,57 @@
     }
   }
   else {
-    $data = serialize(array());
+    $value = serialize(array());
   }
+
+  return $value;
 }
 
 /**
  * Format the output of emailed data for this component
  *
- * @param mixed $data
+ * @param $component
+ *   A Webform component array.
+ * @param $data
  *   A string or array of the submitted data.
- * @param array $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
  * @return
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_file($data, $component) {
-  $file = is_string($data) ? unserialize($data) : $data;
+function theme_webform_mail_file($component, $value) {
+  $file = is_string($value) ? unserialize($value) : $value;
   $output = $component['name'] .': '. (!empty($file['filepath']) ? webform_file_url($file['filepath']) : '') ."\n";
   return $output;
 }
-
 /**
- * Display the result of a file submission. The output of this function will be
- * displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_file($data, $component, $enabled = FALSE) {
-  $filedata = unserialize($data['value'][0]);
-  $form_item = _webform_render_file($component);
-  if (!$enabled) {
-    $form_item['#type'] = 'textfield';
-    $form_item['#tree'] = TRUE;
-    $form_item['#attributes']['readonly'] = 'readonly';
-    $form_item['#default_value'] = empty($filedata['filepath']) ? $filedata['error'] : $filedata['filepath'];
-  }
-  if (!empty($filedata['filename'])) {
-    $form_item['#suffix'] = ' <a href="'. webform_file_url($filedata['filepath']) .'">Download '. $filedata['filename'] .'</a>'. $form_item['#suffix'];
-    if ($enabled) {
-      $form_item['#description'] = t('Uploading a new file will replace the current file.');
-      $form_item['existing'] = array(
-        '#type' => 'value',
-        '#value' => $filedata,
-      );
-    }
-  }
+function _webform_display_file($component, $value) {
+  $file_data = unserialize($value[0]);
+  $form_item = _webform_render_file($component, $value);
+  $form_item['#type'] = 'textfield';
+  $form_item['#tree'] = TRUE;
+  $form_item['#attributes']['readonly'] = 'readonly';
+  $form_item['#default_value'] = empty($file_data['filepath']) ? '' : $file_data['filepath'];
+
   return $form_item;
 }
 
 /**
- * Delete operation for file components or submissions.
- *
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
+ * Implementation of _webform_delete_component().
  */
-function _webform_delete_file($data, $component) {
+function _webform_delete_file($component, $value) {
   // Delete an individual submission file.
-  $filedata = unserialize($data['value']['0']);
-  if (isset($filedata['filepath']) && is_file($filedata['filepath'])) {
-    unlink($filedata['filepath']);
-    db_query("DELETE FROM {files} WHERE filepath = '%s'", $filedata['filepath']);
+  if (isset($value[0])) {
+    $file_data = unserialize($value[0]);
+    if (isset($file_data['filepath']) && is_file($file_data['filepath'])) {
+      unlink($file_data['filepath']);
+      db_query("DELETE FROM {files} WHERE filepath = '%s'", $file_data['filepath']);
+    }
   }
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_file($section) {
   switch ($section) {
@@ -465,7 +450,7 @@
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_file() {
   return array(
@@ -473,24 +458,13 @@
       'arguments' => array('form' => NULL),
     ),
     'webform_mail_file' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_file($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -505,10 +479,10 @@
 
   $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids));
   while ($data = db_fetch_array($result)) {
-    $filedata = unserialize($data['data']);
-    if (isset($filedata['filesize'])) {
+    $file_data = unserialize($data['data']);
+    if (isset($file_data['filesize'])) {
       $nonblanks++;
-      $sizetotal += $filedata['filesize'];
+      $sizetotal += $file_data['filesize'];
     }
     $submissions++;
   }
@@ -520,38 +494,24 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_file($data) {
+function _webform_table_data_file($component, $value) {
   $output = '';
-  $filedata = unserialize($data['value']['0']);
-  if (!empty($filedata['filename'])) {
-    $output = '<a href="'. base_path() . $filedata['filepath'] .'">'. $filedata['filename'] .'</a>';
-    $output .= ' ('. (int)($filedata['filesize']/1024) .' KB)';
+  $file_data = unserialize($value[0]);
+  if (!empty($file_data['filename'])) {
+    $output = '<a href="'. base_path() . $file_data['filepath'] .'">'. $file_data['filename'] .'</a>';
+    $output .= ' ('. (int)($file_data['filesize']/1024) .' KB)';
   }
-  elseif (!empty($filedata['error'])) {
-    $output = $filedata['error'];
+  elseif (!empty($file_data['error'])) {
+    $output = $file_data['error'];
   }
   return $output;
 }
 
 
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_file($component) {
   $header = array();
@@ -563,19 +523,13 @@
 }
 
 /**
- * Return the result of a file submission. The output of this function will be
- * displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_file($data) {
-  $filedata = unserialize($data['value']['0']);
-  return empty($filedata['filename']) ? array('', '') : array($filedata['filename'], (int)($filedata['filesize']/1024));
+function _webform_csv_data_file($component, $value) {
+  $file_data = unserialize($value[0]);
+  return empty($file_data['filename']) ? array('', '') : array($file_data['filename'], (int) ($file_data['filesize']/1024));
 }
+
 /**
  * Helper function to create proper URLs for uploaded file.
  */
Index: components/pagebreak.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/pagebreak.inc,v
retrieving revision 1.4
diff -u -r1.4 pagebreak.inc
--- components/pagebreak.inc	7 May 2009 22:38:14 -0000	1.4
+++ components/pagebreak.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module page break component.
+ * Webform module page break component.
  */
 
 /**
- * Create a default pagebreak component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_pagebreak() {
   return array(
@@ -20,15 +20,9 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
+ * Implementation of _webform_edit_component().
  */
-function _webform_edit_pagebreak($currfield) {
+function _webform_edit_pagebreak($component) {
   drupal_set_message(t('Use caution when combining the pagebreak and file components. File components will not be submitted unless they are after the last pagebreak in the form.'), 'warning');
 
   $form = array();
@@ -51,7 +45,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_pagebreak($section) {
   switch ($section) {
@@ -60,25 +54,28 @@
   }
 }
 
-function _webform_render_pagebreak($component) {
-  $form = array();
+/**
+ * Implementation of _webform_render_component().
+ */
+function _webform_render_pagebreak($component, $value = NULL, $filter = TRUE) {
+  $form_item = array();
   // Render page breaks as hidden elements so that they can be displayed in
   // emails as separators.
-  $form = array(
+  $form_item = array(
     '#type' => 'hidden',
     '#value' => $component['name'],
     '#weight' => $component['weight'],
   );
-  return $form;
+  return $form_item;
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_pagebreak() {
   return array(
     'webform_mail_pagebreak' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
@@ -86,14 +83,13 @@
 /**
  * Format the output of e-mailed data for this component.
  *
- * @param $data
- *   A string or array of the submitted data.
  * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
+ *   A Webform component array.
+ * @param $value
+ *   A string or array of the submitted data.
  * @return
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_pagebreak($data, $component) {
+function theme_webform_mail_pagebreak($component, $value) {
   return "\n-- ". $component['name'] ." --\n";
 }
Index: components/time.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/time.inc,v
retrieving revision 1.18
diff -u -r1.18 time.inc
--- components/time.inc	6 Nov 2009 00:45:29 -0000	1.18
+++ components/time.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module time component.
+ * Webform module time component.
  */
 
 /**
- * Create a default time component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_time() {
   return array(
@@ -28,55 +28,49 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this component.
- * Use care naming the form items, as this correlates directly to the database schema.
- * The component "Name" and "Description" fields are added to every component type and
- * are not necessary to specify here (although they may be overridden if desired).
- * @return An array of form items to be displayed on the edit component page
- */
-function _webform_edit_time($currfield) {
-  $edit_fields = array();
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_time($component) {
+  $form = array();
+  $form['value'] = array(
     '#type' => 'textfield',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') .'<br />'. t('Accepts a time in any <a href="http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html">GNU Date Input Format</a>. Strings such as now, +2 hours, and 10:30pm are all valid.'),
     '#size' => 60,
     '#maxlength' => 127,
     '#weight' => 0,
     '#element_validate' => array('webform_validate_time_string'),
   );
-  $edit_fields['extra']['timezone'] = array(
+  $form['extra']['timezone'] = array(
     '#type' => 'radios',
     '#title' => t('Timezone'),
-    '#default_value' => empty($currfield['extra']['timezone']) ? 'site' : $currfield['extra']['timezone'],
+    '#default_value' => empty($component['extra']['timezone']) ? 'site' : $component['extra']['timezone'],
     '#description' => t('Adjust the time according to a specific timezone. Website timezone is defined in the <a href="!settings">Site Settings</a> and is the default.', array('!settings' => url('admin/settings/date-time'))),
     '#options' => array('site' => 'Website Timezone', 'user' => 'User Timezone', 'gmt' => 'GMT'),
     '#weight' => 0,
   );
-$edit_fields['extra']['check_daylight_savings'] = array(
-  '#type' => 'checkbox',
-  '#title' => t('Observe Daylight Savings'),
-  '#default_value' => $currfield['extra']['check_daylight_savings'],
-  '#checked_value' => 1,
-  '#description' => t('Automatically adjust the time during daylight savings.'),
-  '#weight' => 1,
-);
-  $edit_fields['extra']['hourformat'] = array(
+  $form['extra']['check_daylight_savings'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Observe Daylight Savings'),
+    '#default_value' => $component['extra']['check_daylight_savings'],
+    '#checked_value' => 1,
+    '#description' => t('Automatically adjust the time during daylight savings.'),
+    '#weight' => 1,
+  );
+  $form['extra']['hourformat'] = array(
     '#type' => 'radios',
     '#title' => t('Time Format'),
-    '#default_value' => isset($currfield['extra']['hourformat']) ? $currfield['extra']['hourformat'] : '12-hour',
+    '#default_value' => isset($component['extra']['hourformat']) ? $component['extra']['hourformat'] : '12-hour',
     '#description' => t('Format the display of the time in 12 or 24 hours.'),
     '#options' => array('12-hour' => '12-hour (am/pm)', '24-hour' => '24-hour'),
     '#weight' => 2,
   );
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component
- * @param $component An array of information describing the component, directly correlating to the webform_component database schema
- * @return An array of a form item to be displayed on the client-side webform
+ * Implementation of _webform_render_component().
  */
 function _webform_render_time($component) {
   if (drupal_strlen($component['value']) > 0) {
@@ -118,6 +112,11 @@
     $minute = gmdate('i', $timestamp);
     $am_pm = gmdate('a', $timestamp);
   }
+  else {
+    $hour = '';
+    $minute = '';
+    $am_pm = 'am';
+  }
 
   // Generate the choices for drop-down selects.
   $hours[''] = t('hour');
@@ -158,6 +157,22 @@
     );
   }
 
+  if (isset($value)) {
+    $form_item['minute']['#default_value'] = $value[1];
+  
+    // Match the hourly data to the hour format.
+    if ($value[1]) {
+      $timestamp = strtotime($value[0] .':'. $value[1] . (isset($value[2]) ? $value[2] : ''));
+      if ($component['extra']['hourformat'] == '24-hour') {
+        $form_item['hour']['#default_value'] = date('H', $timestamp);
+      }
+      else {
+        $form_item['hour']['#default_value'] = date('g', $timestamp);
+        $form_item['ampm']['#default_value'] = $value[2];
+      }
+    }
+  }
+
   return $form_item;
 }
 
@@ -174,75 +189,63 @@
   }
 
   // Check for a valid time.
-  if ($form_item['hour']['#value'] !== '' || $form_item['minute']['#value'] !== '' || (isset($form_item['ampm']) && $form_item['ampm']['#value'] !== '')) {
+  if ($form_item['hour']['#value'] !== '' || $form_item['minute']['#value'] !== '') {
     if (!is_numeric($form_item['hour']['#value']) || !is_numeric($form_item['minute']['#value']) || (isset($form_item['ampm']) && $form_item['ampm']['#value'] === '')) {
-      form_set_error($form_key, t('Entered %name is not a valid time.', array('%name' => $name)));
+      form_error($form_key, t('Entered %name is not a valid time.', array('%name' => $name)));
       return;
     }
   }
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_time($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_time($component);
-  $form_item['minute']['#default_value'] = $data['value']['1'];
-  $form_item['minute']['#disabled'] = !$enabled;
-  $form_item['hour']['#disabled'] = !$enabled;
-  $form_item['ampm']['#disabled'] = !$enabled;
+function _webform_display_time($component, $value) {
+  $form_item = _webform_render_time($component, $value);
+  $form_item['minute']['#default_value'] = $value[1];
+  $form_item['minute']['#disabled'] = TRUE;
+  $form_item['hour']['#disabled'] = TRUE;
+  $form_item['ampm']['#disabled'] = TRUE;
 
   // Match the hourly data to the hour format.
-  if ($data['value']['1']) {
-    $timestamp = strtotime($data['value']['0'] .':'. $data['value']['1'] . (isset($data['value']['2']) ? $data['value']['2'] : ''));
+  if ($value[1]) {
+    $timestamp = strtotime($value[0] .':'. $value[1] . (isset($value[2]) ? $value[2] : ''));
     if ($component['extra']['hourformat'] == '24-hour') {
       $form_item['hour']['#default_value'] = date('H', $timestamp);
     }
     else {
       $form_item['hour']['#default_value'] = date('g', $timestamp);
-      $form_item['ampm']['#default_value'] = $data['value']['2'];
+      $form_item['ampm']['#default_value'] = $value[2];
     }
   }
   return $form_item;
 }
 
 /**
- * Format the output of emailed data for this component
+ * Format the output of e-mailed data for this component
  *
+ * @param $component
+ *   A Webform component array.
  * @param $data
  *   A string or array of the submitted data
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
  * @return
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_time($data, $component) {
+function theme_webform_mail_time($component, $value) {
   $output = $component['name'] .':';
-  if ($data['hour'] && $data['minute']) {
+  if ($value['hour'] && $value['minute']) {
     if ($component['extra']['hourformat'] == '24-hour') {
-      $output .= ' '. $data['hour'] .':'. $data['minute'];
+      $output .= ' '. $value['hour'] .':'. $value['minute'];
     }
     else {
-      $output .= ' '. $data['hour'] .':'. $data['minute'] .' '. $data['ampm'];
+      $output .= ' '. $value['hour'] .':'. $value['minute'] .' '. $value['ampm'];
     }
   }
   return $output;
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_time($section) {
   switch ($section) {
@@ -252,7 +255,7 @@
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_time() {
   return array(
@@ -260,24 +263,13 @@
       'arguments' => array('element' => NULL),
     ),
     'webform_mail_time' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_time($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -326,17 +318,11 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_time($data, $component) {
-  if (drupal_strlen($data['value']['0']) > 0 && drupal_strlen($data['value']['1']) > 0) {
-    $timestamp = strtotime($data['value']['0'] .':'. $data['value']['1'] . $data['value']['2']);
+function _webform_table_data_time($component, $value) {
+  if (drupal_strlen($value[0]) > 0 && drupal_strlen($value[1]) > 0) {
+    $timestamp = strtotime($value[0] .':'. $value[1] . $value[2]);
     if ($component['extra']['hourformat'] == '24-hour') {
       return check_plain(date('H:i', $timestamp));
     }
@@ -349,17 +335,8 @@
   }
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_time($component) {
   $header = array();
@@ -370,18 +347,11 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_time($data, $component) {
-  if (drupal_strlen($data['value']['0']) > 0 && drupal_strlen($data['value']['1']) > 0) {
-    $timestamp = strtotime($data['value']['0'] .':'. $data['value']['1'] . $data['value']['2']);
+function _webform_csv_data_time($component, $value) {
+  if (drupal_strlen($value[0]) > 0 && drupal_strlen($value[1]) > 0) {
+    $timestamp = strtotime($value[0] .':'. $value[1] . $value[2]);
     if ($component['extra']['hourformat'] == '24-hour') {
       return date('H:i', $timestamp);
     }
Index: components/date.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/date.inc,v
retrieving revision 1.18
diff -u -r1.18 date.inc
--- components/date.inc	6 Nov 2009 00:51:47 -0000	1.18
+++ components/date.inc	11 Jan 2010 08:29:10 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module date component.
+ * Webform module date component.
  */
 
 /**
- * Create a default date component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_date() {
   return array(
@@ -29,80 +29,69 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_date($currfield) {
-  $edit_fields = array();
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_date($component) {
+  $form = array();
+  $form['value'] = array(
     '#type' => 'textfield',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') .'<br />'. t('Accepts any date in any <a href="http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html">GNU Date Input Format</a>. Strings such as today, +2 months, and Dec 9 2004 are all valid.'),
     '#size' => 60,
     '#maxlength' => 127,
     '#weight' => 0,
   );
-  $edit_fields['extra']['timezone'] = array(
+  $form['extra']['timezone'] = array(
     '#type' => 'radios',
     '#title' => t('Timezone'),
-    '#default_value' => empty($currfield['extra']['timezone']) ? 'site' : $currfield['extra']['timezone'],
+    '#default_value' => empty($component['extra']['timezone']) ? 'site' : $component['extra']['timezone'],
     '#description' => t('Adjust the date according to a specific timezone. Website timezone is defined in the <a href="!settings">Site Settings</a> and is the default.', array('!settings' => url('admin/settings/date-time'))),
     '#options' => array('site' => t('Website timezone'), 'user' => t('User timezone'), 'gmt' => t('GMT')),
     '#weight' => 1,
   );
-  $edit_fields['extra']['check_daylight_savings'] = array(
+  $form['extra']['check_daylight_savings'] = array(
     '#type' => 'checkbox',
     '#title' => t('Observe Daylight Savings'),
-    '#default_value' => $currfield['extra']['check_daylight_savings'],
+    '#default_value' => $component['extra']['check_daylight_savings'],
     '#checked_value' => 1,
     '#description' => t('Automatically adjust the time during daylight savings.'),
     '#weight' => 2,
   );
 
-  $edit_fields['extra']['year_start'] = array(
+  $form['extra']['year_start'] = array(
     '#type' => 'textfield',
     '#title' => t('Start year'),
-    '#default_value' => empty($currfield['extra']['year_start']) ? '1900' : $currfield['extra']['year_start'],
+    '#default_value' => empty($component['extra']['year_start']) ? '1900' : $component['extra']['year_start'],
     '#description' => t('The first year that is allowed to be entered.'),
     '#size' => 10,
     '#maxlength' => 4,
     '#weight' => 3,
   );
-  $edit_fields['extra']['year_end'] = array(
+  $form['extra']['year_end'] = array(
     '#type' => 'textfield',
     '#title' => t('End year'),
-    '#default_value' => empty($currfield['extra']['year_end']) ? '2050' : $currfield['extra']['year_end'],
+    '#default_value' => empty($component['extra']['year_end']) ? '2050' : $component['extra']['year_end'],
     '#description' => t('The last year that is allowed to be entered.'),
     '#size' => 10,
     '#maxlength' => 4,
     '#weight' => 4,
   );
-  $edit_fields['extra']['year_textfield'] = array(
+  $form['extra']['year_textfield'] = array(
     '#type' => 'checkbox',
     '#title' => t('Use a textfield for year'),
-    '#default_value' => $currfield['extra']['year_textfield'],
+    '#default_value' => $component['extra']['year_textfield'],
     '#description' => t('If checked, the generated date field will use a textfield for the year. Otherwise it will use a select list.'),
     '#weight' => 5,
   );
 
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_date($component) {
+function _webform_render_date($component, $value = NULL) {
   $form_item = array(
     '#title' => $component['name'],
     '#weight' => $component['weight'],
@@ -115,9 +104,19 @@
     '#process' => array('webform_expand_date'),
     '#element_validate' => array('webform_validate_date'),
   );
+
+  if (isset($value)) {
+    $form_item['month']['#default_value'] = $value[0];
+    $form_item['day']['#default_value'] = $value[1];
+    $form_item['year']['#default_value'] = $value[2];
+  }
+
   return $form_item;
 }
 
+/**
+ * Form API #process function for Webform date fields.
+ */
 function webform_expand_date($element) {
   $component = $element['#webform_component'];
 
@@ -241,61 +240,33 @@
 }
 
 /**
- * Convert internationalized Date formats into the US order expected by Webform.
- *
- * @param $data
- *   The POST data associated with the component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   Nothing.
+ * Implementation of _webform_submit_component().
  */
-function _webform_submit_date(&$data, $component) {
+function _webform_submit_date($component, $value) {
   // Webform stores dates in month/day/year rows.
   // Ensure consistency when using international date formats.
-  $data = array($data['month'], $data['day'], $data['year']);
+  return array($value['month'], $value['day'], $value['year']);
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
- */
-function _webform_submission_display_date($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_date($component);
-  $form_item['month']['#default_value'] = $data['value']['0'];
-  $form_item['day']['#default_value'] = $data['value']['1'];
-  $form_item['year']['#default_value'] = $data['value']['2'];
-
-  $form_item['#disabled'] = !$enabled;
+ * Implementation of _webform_display_component().
+ */
+function _webform_display_date($component, $value) {
+  $form_item = _webform_render_date($component, $value);
+  $form_item['month']['#default_value'] = $value[0];
+  $form_item['day']['#default_value'] = $value[1];
+  $form_item['year']['#default_value'] = $value[2];
+  $form_item['#disabled'] = TRUE;
   return $form_item;
 }
 
 /**
- * Format the output of emailed data for this component
- *
- * @param $data
- *   A string or array of the submitted data
- * @param $component
- *   An array of information describing the component,
- * directly correlating to the webform_component database schema.
- * @return string
- *   Textual output to be included in the email.
+ * Format the output of e-mailed data for this component.
  */
-function theme_webform_mail_date($data, $component) {
+function theme_webform_mail_date($component, $value) {
   $output = $component['name'] .':';
-  if ($data[0] && $data[1]) {
-    $timestamp = strtotime($data[0] .'/'. $data[1] .'/'. $data[2]);
+  if ($value[0] && $value[1]) {
+    $timestamp = strtotime($value[0] .'/'. $value[1] .'/'. $value[2]);
     $format = webform_date_format('medium');
     $output .= ' '. format_date($timestamp, 'custom', $format);
   }
@@ -304,7 +275,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_date($section) {
   switch ($section) {
@@ -314,7 +285,7 @@
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_date() {
   return array(
@@ -322,24 +293,13 @@
       'arguments' => array('element' => NULL),
     ),
     'webform_mail_date' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_date($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -383,42 +343,26 @@
   }
 
   // Display stats.
-  // TODO: display date statistics in javascript tabs.
   $nonblanks = count($timestamps);
-  $rows[0] = array( t('Left Blank'), ($submissions - $nonblanks));
-  $rows[1] = array( t('User entered value'), $nonblanks);
+  $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
+  $rows[1] = array(t('User entered value'), $nonblanks);
   return $rows;
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
- */
-function _webform_table_data_date($data) {
-  if (drupal_strlen($data['value']['0']) > 0 && drupal_strlen($data['value']['1']) > 0 && drupal_strlen($data['value']['2']) > 0) {
-    return check_plain($data['value']['0'] .'/'. $data['value']['1'] .'/'. $data['value']['2']);
+ * Implementation of _webform_table_data_component().
+ */
+function _webform_table_data_date($component, $value) {
+  if (drupal_strlen($value[0]) > 0 && drupal_strlen($value[1]) > 0 && drupal_strlen($value[2]) > 0) {
+    return check_plain($value[0] .'/'. $value[1] .'/'. $value[2]);
   }
   else {
     return '';
   }
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_date($component) {
   $header = array();
@@ -429,18 +373,11 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
- */
-function _webform_csv_data_date($data) {
-  if (drupal_strlen($data['value']['0']) > 0 && drupal_strlen($data['value']['1']) > 0 && drupal_strlen($data['value']['2']) > 0) {
-    $timestamp = strtotime($data['value']['0'] .'/'. $data['value']['1'] .'/'. $data['value']['2']);
+ * Implementation of _webform_csv_data_component().
+ */
+function _webform_csv_data_date($component, $value) {
+  if (drupal_strlen($value[0]) > 0 && drupal_strlen($value[1]) > 0 && drupal_strlen($value[2]) > 0) {
+    $timestamp = strtotime($value[0] .'/'. $value[1] .'/'. $value[2]);
     $format = webform_date_format('short');
     return date($format, $timestamp);
   }
Index: components/fieldset.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/fieldset.inc,v
retrieving revision 1.6
diff -u -r1.6 fieldset.inc
--- components/fieldset.inc	20 Jun 2009 23:04:58 -0000	1.6
+++ components/fieldset.inc	11 Jan 2010 08:29:10 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module fieldset component.
+ * Webform module fieldset component.
  */
 
 /**
- * Create a default fieldset component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_fieldset() {
   return array(
@@ -24,43 +24,32 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_fieldset($currfield) {
-  $edit_fields = array();
-  $edit_fields['extra']['collapsible'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_fieldset($component) {
+  $form = array();
+  $form['extra']['collapsible'] = array(
     '#type' => 'checkbox',
     '#title' => t('Collapsible'),
-    '#default_value' => $currfield['extra']['collapsible'],
+    '#default_value' => $component['extra']['collapsible'],
     '#description' => t('If this fieldset is collapsible, the user may open or close the fieldset.'),
     '#weight' => 0,
   );
-  $edit_fields['extra']['collapsed'] = array(
+  $form['extra']['collapsed'] = array(
     '#type' => 'checkbox',
     '#title' => t('Collapsed by Default'),
-    '#default_value' => $currfield['extra']['collapsed'],
+    '#default_value' => $component['extra']['collapsed'],
     '#description' => t('Collapsible fieldsets are "open" by default. Select this option to default the fieldset to "closed."'),
     '#weight' => 3,
   );
-  $edit_fields['advanced']['mandatory'] = array();
-  return $edit_fields;
+  $form['advanced']['mandatory'] = array();
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_fieldset($component, $filter = TRUE) {
+function _webform_render_fieldset($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#type'          => $component['type'],
     '#title'         => htmlspecialchars($component['name'], ENT_QUOTES),
@@ -75,24 +64,15 @@
 }
 
 /**
- * Display the result of a fieldset submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_fieldset($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_fieldset($component);
+function _webform_display_fieldset($component, $value) {
+  $form_item = _webform_render_fieldset($component, $value);
   return $form_item;
 }
 
 /**
- * Module specific instance of hook_form_builder_types().
+ * Implementation of _webform_form_builder_types_component().
  */
 function _webform_form_builder_types_fieldset() {
   $fields = array();
@@ -118,7 +98,7 @@
 }
 
 /**
- * Module specific instance of hook_form_builder_save().
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_fieldset(&$component, $form_element) {
   $component['extra']['collapsible'] = isset($form_element['#collapsible']) ? $form_element['#collapsible'] : NULL;
@@ -127,7 +107,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_fieldset($section) {
   switch ($section) {
Index: components/markup.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/markup.inc,v
retrieving revision 1.7
diff -u -r1.7 markup.inc
--- components/markup.inc	20 Jun 2009 23:04:58 -0000	1.7
+++ components/markup.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module markup component.
+ * Webform module markup component.
  */
 
 /**
- * Create a default markup component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_markup() {
   return array(
@@ -23,42 +23,31 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_markup($currfield) {
-  $edit_fields = array();
-  $edit_fields['advanced']['mandatory'] = array(); // Do not render the mandatory checkbox.
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_markup($component) {
+  $form = array();
+  $form['advanced']['mandatory'] = array(); // Do not render the mandatory checkbox.
+  $form['value'] = array(
     '#type' => 'textarea',
     '#title' => t('Value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('Markup allows you to enter custom HTML or PHP logic into your form.') . theme('webform_token_help'),
     '#weight' => -1,
   );
   // Add the filter form.
-  $edit_fields['extra']['format'] = filter_form($currfield['extra']['format'], 0, array('extra', 'format'));
+  $form['extra']['format'] = filter_form($component['extra']['format'], 0, array('extra', 'format'));
 
   // No description for markup.
-  $edit_fields['extra']['description'] = array();
+  $form['extra']['description'] = array();
 
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_markup($component, $filter) {
+function _webform_render_markup($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#type'   => 'markup',
     '#title'  => $component['name'],
@@ -76,24 +65,14 @@
 }
 
 /**
- * Display the markup  in the results. The output of this function will be
- * displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_markup($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_markup($component);
-  return $form_item;
+function _webform_display_markup($component, $value) {
+  return _webform_render_markup($component, $value);
 }
 
 /**
- * Convert a FAPI form element into settings savable in a component.
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_markup(&$component, $form_element) {
   $component['extra']['format'] = $form_element['#input_format'];
@@ -142,7 +121,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_markup($section) {
   switch ($section) {
Index: components/grid.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/grid.inc,v
retrieving revision 1.5
diff -u -r1.5 grid.inc
--- components/grid.inc	6 Nov 2009 00:42:18 -0000	1.5
+++ components/grid.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module grid component.
+ * Webform module grid component.
  */
 
 /**
- * Create a default grid component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_grid() {
   return array(
@@ -28,68 +28,61 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this component.
- * Use care naming the form items, as this correlates directly to the database schema.
- * The component "Name" and "Description" fields are added to every component type and
- * are not necessary to specify here (although they may be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page
+ * Implementation of _webform_edit_component().
  */
-function _webform_edit_grid($currfield) {
-  $edit_fields = array();
-  $edit_fields['extra']['options'] = array(
+function _webform_edit_grid($component) {
+  $form = array();
+  $form['extra']['options'] = array(
     '#type' => 'textarea',
     '#title' => t('Options'),
-    '#default_value' => $currfield['extra']['options'],
+    '#default_value' => $component['extra']['options'],
     '#description' => t('Options to select across the top. One option per line. Key-value pairs may be entered seperated by pipes. i.e. safe_key|Some readable option') . theme('webform_token_help'),
     '#cols' => 60,
     '#rows' => 5,
     '#weight' => -3,
     '#required' => TRUE,
   );
-  $edit_fields['extra']['questions'] = array(
+  $form['extra']['questions'] = array(
     '#type' => 'textarea',
     '#title' => t('Questions'),
-    '#default_value' => $currfield['extra']['questions'],
+    '#default_value' => $component['extra']['questions'],
     '#description' => t('Questions list down the left side. One question per line.') . theme('webform_token_help'),
     '#cols' => 60,
     '#rows' => 5,
     '#weight' => -2,
     '#required' => TRUE,
   );
-  $edit_fields['extra']['optrand'] = array(
+  $form['extra']['optrand'] = array(
     '#type' => 'checkbox',
     '#title' => t('Randomize Options'),
-    '#default_value' => $currfield['extra']['optrand'],
+    '#default_value' => $component['extra']['optrand'],
     '#description' => t('Randomizes the order of options on the top when they are displayed in the form.'),
   );
-  $edit_fields['extra']['qrand'] = array(
+  $form['extra']['qrand'] = array(
     '#type' => 'checkbox',
     '#title' => t('Randomize Questions'),
-    '#default_value' => $currfield['extra']['qrand'],
+    '#default_value' => $component['extra']['qrand'],
     '#description' => t('Randomize the order of the questions on the side when they are displayed in the form.'),
   );
-  return $edit_fields;
-}
-
-function _webform_edit_validate_grid($form_values) {
-  // Currently no validation for selects.
-  return TRUE;
+  return $form;
 }
 
-function _webform_render_grid($component, $random = TRUE) {
+/**
+ * Implementation of _webform_render_component().
+ */
+function _webform_render_grid($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#title' => $component['name'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
     '#theme' => 'webform_grid',
-    '#description'   => _webform_filter_descriptions($component['extra']['description']),
+    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
   );
 
   $questions = _webform_grid_options($component['extra']['questions']);
   $options = _webform_grid_options($component['extra']['options']);
 
-  if ($component['extra']['optrand'] && $random) {
+  if ($component['extra']['optrand']) {
     // This maneuver shuffles the array keys, then uses them as
     // the basis for ordering the options.
     $aux = array();
@@ -101,7 +94,7 @@
     }
     $options = $aux;
   }
-  if ($component['extra']['qrand'] && $random) {
+  if ($component['extra']['qrand']) {
     $aux = array();
     $keys = array_keys($questions);
     shuffle($keys);
@@ -125,46 +118,31 @@
     }
   }
 
+  if (isset($value)) {
+    $cid = 0;
+    foreach (element_children($form_item) as $key) {
+      $form_item[$key]['#default_value'] = $value[$cid++];
+    }
+  }
+
   return $form_item;
 }
 
 /**
- * Display the result of a grid submission. The output of this function will be
- * displayed under the "results" tab then "submissions"
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_grid($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_grid($component, FALSE);
-  $cid = 0;
+function _webform_display_grid($component, $value) {
+  $form_item = _webform_render_grid($component, $value);
   foreach (element_children($form_item) as $key) {
-    $form_item[$key]['#default_value'] = $data['value'][$cid++];
-    $form_item[$key]['#disabled'] = !$enabled;
+    $form_item[$key]['#disabled'] = TRUE;
   }
   return $form_item;
 }
 
 /**
- * Translates the submitted 'safe' form values back into their un-edited
- * original form.
- *
- * @param $data
- *   The POST data associated with the component
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @return
- *   Nothing
+ * Implementation of _webform_submit_component().
  */
-function _webform_submit_grid(&$data, $component) {
+function _webform_submit_grid($component, $value) {
   $options = drupal_map_assoc(array_flip(_webform_grid_options($component['extra']['options'])));
 
   // Questions are a bit more tricky, since quotes were removed from them in
@@ -175,51 +153,49 @@
     $questions[$safe_question] = $question;
   }
 
-  if (is_array($data)) {
-    foreach ($data as $key => $value) {
-      if ($value !== '') {
-        $data[$key] = $options[$value];
+  if (is_array($value)) {
+    foreach ($value as $key => $option_value) {
+      if ($option_value !== '') {
+        $value[$key] = $options[$option_value];
       }
     }
   }
-  elseif ($data !== '') {
-    $data = $options[$data];
+  elseif ($value !== '') {
+    $value = $options[$value];
   }
 
   // Put the form in the original option order before saving.
   // Return the final data with the quotes back in place.
-  $ordered_data = array();
+  $ordered_value = array();
   foreach ($questions as $safe_question => $question) {
-    if (isset($data[$safe_question])) {
-      $ordered_data[$question] = $data[$safe_question];
+    if (isset($value[$safe_question])) {
+      $ordered_value[$question] = $value[$safe_question];
     }
   }
 
-  $data = $ordered_data;
+  return $ordered_value;
 }
 /**
- * Format the output of emailed data for this component.
+ * Format the output of e-mailed data for this component.
  *
- * @param $data
- *   A string or array of the submitted data.
  * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
+ *   A Webform component array.
+ * @param $value
+ *   A string or array of the submitted data.
  * @return
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_grid($data, $component) {
+function theme_webform_mail_grid($component, $value) {
   $questions = _webform_grid_options($component['extra']['questions']);
   $output = $component['name'] .":\n";
   foreach ($questions as $key => $question) {
-    $output .= '  - '. $question .':'. ($data[$question] == '' ? '' : ' '. $data[$question]) ."\n";
+    $output .= '  - '. $question .':'. ($value[$question] == '' ? '' : ' '. $value[$question]) ."\n";
   }
   return $output;
 }
 
 /**
- * function _webform_help_select
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_grid($section) {
   switch ($section) {
@@ -229,7 +205,7 @@
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_help_grid().
  */
 function _webform_theme_grid() {
   return array(
@@ -237,25 +213,13 @@
       'arguments' => array('grid_element' => NULL),
     ),
     'webform_mail_grid' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- *
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_grid($component, $sids = array()) {
   // Generate the list of options and questions.
@@ -300,39 +264,27 @@
 }
 
 /**
- * function _webform_table_data_select
- * Return the result of this component's submission for display in a table. The output of this function will be displayed under the "results" tab then "table"
- * @param $data An array of information containing the submission result, directly correlating to the webform_submitted_data database schema
- * @returns Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_grid($data, $component) {
+function _webform_table_data_grid($component, $value) {
   $questions = array_values(_webform_grid_options($component['extra']['questions']));
   $output = '';
   // Set the value as a single string.
-  if (is_array($data['value'])) {
-    foreach ($data['value'] as $item => $value) {
+  if (is_array($value)) {
+    foreach ($value as $item => $value) {
       if ($value !== '') {
         $output .= $questions[$item] .': '. check_plain($value) .'<br />';
       }
     }
   }
   else {
-    $output = check_plain(!isset($data['value']['0']) ? '' : $data['value']['0']);
+    $output = check_plain(!isset($value[0]) ? '' : $value[0]);
   }
   return $output;
 }
 
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under
- * the "results" tab then "download".
- *
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_grid($component) {
   $header = array();
@@ -355,26 +307,18 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- *
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_grid($data, $component) {
+function _webform_csv_data_grid($component, $value) {
   $questions = array_keys(_webform_grid_options($component['extra']['questions']));
   $return = array();
   foreach ($questions as $key => $question) {
-    $return[] = isset($data['value'][$key]) ? $data['value'][$key] : '';
+    $return[] = isset($value[$key]) ? $value[$key] : '';
   }
   return $return;
 }
 
-function theme_webform_grid(&$grid_element) {
+function theme_webform_grid($grid_element) {
   $rows = array();
   $header = array('');
   $first = TRUE;
@@ -405,8 +349,7 @@
 }
 
 /**
- * Utility function to split user-entered values from new-line separated
- * text into an array of options.
+ * Utility function to convert user-entered values into grid options.
  */
 function _webform_grid_options($text) {
   $options = array();
Index: components/select.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/select.inc,v
retrieving revision 1.26
diff -u -r1.26 select.inc
--- components/select.inc	6 Nov 2009 00:49:35 -0000	1.26
+++ components/select.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module multiple select component.
+ * Webform module multiple select component.
  */
 
 /**
- * Create a default select component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_select() {
   return array(
@@ -28,20 +28,14 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
+ * Implementation of _webform_edit_component().
  */
-function _webform_edit_select($currfield) {
-  $edit_fields = array();
-  $edit_fields['extra']['items'] = array(
+function _webform_edit_select($component) {
+  $form = array();
+  $form['extra']['items'] = array(
     '#type' => 'textarea',
     '#title' => t('Options'),
-    '#default_value' => $currfield['extra']['items'],
+    '#default_value' => $component['extra']['items'],
     '#description' => t('A list of selectable options. One option per line. Key-value pairs may be entered seperated by pipes, such as "safe_key|Some readable option". Option groups for lists and menus may be specified with &lt;Group Name&gt;. &lt;&gt; can be used to insert items at the root of the menu after specifying a group.') . theme('webform_token_help'),
     '#cols' => 60,
     '#rows' => 5,
@@ -49,31 +43,31 @@
     '#required' => TRUE,
     '#element_validate' => array('_webform_edit_validate_select'),
   );
-  $edit_fields['value'] = array(
+  $form['value'] = array(
     '#type' => 'textfield',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field. For multiple selects use commas to separate multiple defaults.') . theme('webform_token_help'),
     '#size' => 60,
     '#maxlength' => 256,
     '#weight' => 0,
   );
-  $edit_fields['extra']['multiple'] = array(
+  $form['extra']['multiple'] = array(
     '#type' => 'checkbox',
     '#title' => t('Multiple'),
     '#return_value' => 'Y',
-    '#default_value' => $currfield['extra']['multiple'],
+    '#default_value' => $component['extra']['multiple'],
     '#description' => t('Check this option if the user should be allowed to choose multiple values.'),
   );
-  $edit_fields['extra']['aslist'] = array(
+  $form['extra']['aslist'] = array(
     '#type' => 'checkbox',
     '#title' => t('Listbox'),
     '#return_value' => 'Y',
-    '#default_value' => $currfield['extra']['aslist'],
+    '#default_value' => $component['extra']['aslist'],
     '#description' => t('Check this option if you want the select component to be of listbox type instead of radiobuttons or checkboxes.'),
   );
 
-  return $edit_fields;
+  return $form;
 }
 
 /**
@@ -122,17 +116,9 @@
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $filter
- *   Whether or not to filter the descriptions and values within this component.
- *   Values need to be unfiltered to be edited in Form Builder.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_select($component, $filter = TRUE) {
+function _webform_render_select($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#title'         => $component['name'],
     '#required'      => $component['mandatory'],
@@ -154,7 +140,23 @@
   $form_item['#options'] = $options;
 
   // Set the default value.
-  if ($default_value != '') {
+  if (isset($value)) {
+    if ($component['extra']['multiple'] === 'Y') {
+      // Set the value as an array.
+      $form_item['#default_value'] = array();
+      foreach ((array) $value as $key => $option_value) {
+        $form_item['#default_value'][] = $option_value;
+      }
+    }
+    else {
+      // Set the value as a single string.
+      $form_item['#default_value'] = '';
+      foreach ((array) $value as $option_value) {
+        $form_item['#default_value'] = $option_value;
+      }
+    }
+  }
+  elseif ($default_value != '') {
     // Convert default value to a list if necessary.
     if ($component['extra']['multiple'] === 'Y') {
       $varray = array_filter(explode(',', $default_value));
@@ -212,68 +214,52 @@
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_select($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_select($component);
+function _webform_display_select($component, $value) {
+  $form_item = _webform_render_select($component, $value);
   if ($component['extra']['multiple'] === 'Y') {
     // Set the value as an array.
     $form_item['#default_value'] = array();
-    foreach ((array)$data['value'] as $key => $value) {
+    foreach ((array) $value as $key => $value) {
       $form_item['#default_value'][] = $value;
     }
   }
   else {
     // Set the value as a single string.
     $form_item['#default_value'] = '';
-    foreach ((array)$data['value'] as $value) {
+    foreach ((array) $value as $value) {
       $form_item['#default_value'] = $value;
     }
   }
-  $form_item['#disabled'] = !$enabled;
+  $form_item['#disabled'] = TRUE;
   return $form_item;
 }
 
-
 /**
- * Convert FAPI 0/1 values into something saveable.
+ * Implementation of _webform_submit_component().
  *
- * @param $data
- *   The POST data associated with the component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   Nothing.
+ * Convert FAPI 0/1 values into something saveable.
  */
-function _webform_submit_select(&$data, $component) {
+function _webform_submit_select($component, $value) {
   $options = drupal_map_assoc(array_flip(_webform_select_options($component['extra']['items'], TRUE)));
 
-  if (is_array($data)) {
-    foreach ($data as $key => $value) {
-      if ($value != '') {
-        $data[$key] = $options[$key];
+  if (is_array($value)) {
+    foreach ($value as $key => $option_value) {
+      if ($option_value != '') {
+        $value[$key] = $options[$key];
       }
       // Checkboxes submit a value of 0 when not checked.
-      elseif ($value == 0 && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') {
-        unset($data[$key]);
+      elseif ($option_value == 0 && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') {
+        unset($value[$key]);
       }
       else {
-        unset($data[$key]);
+        unset($value[$key]);
       }
     }
   }
+
+  return $value;
 }
 
 /**
@@ -358,13 +344,13 @@
 }
 
 /**
- * Convert a FAPI form element into settings savable in a component.
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_select(&$component, $form_element) {
   $options = '';
 
-  foreach ($form_element['#options'] as $key => $value) {
-    $options .= $key .'|'. $value ."\n";
+  foreach ($form_element['#options'] as $key => $option_value) {
+    $options .= $key .'|'. $option_value ."\n";
   }
 
   $component['extra']['items'] = $options;
@@ -374,17 +360,16 @@
 }
 
 /**
- * Format the output of emailed data for this component.
+ * Format the output of e-mailed data for this component.
  *
- * @param $data
- *   A string or array of the submitted data.
  * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
+ *   A Webform component array.
+ * @param $value
+ *   A string or array of the submitted data.
  * @return
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_select($data, $component) {
+function theme_webform_mail_select($component, $value) {
   // Convert submitted 'safe' values to un-edited, original form.
   $options = _webform_select_options($component['extra']['items'], TRUE);
 
@@ -392,24 +377,24 @@
   $output = '';
   if ($component['extra']['multiple']) {
     $output .= $component['name'] .":\n";
-    foreach ((array)$data as $value) {
-      if ($value) {
-        if ($options[$value]) {
-          $output .= '    - '. $options[$value] ."\n";
+    foreach ((array) $value as $option_value) {
+      if ($option_value) {
+        if ($options[$option_value]) {
+          $output .= '    - '. $options[$option_value] ."\n";
         }
       }
     }
   }
   else {
-    if ($data !== '' && $options[$data]) {
-      $output .= $component['name'] .": ". $options[$data] ."\n";
+    if ($value !== '' && $options[$value]) {
+      $output .= $component['name'] .": ". $options[$value] ."\n";
     }
   }
   return $output;
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_select($section) {
   switch ($section) {
@@ -419,29 +404,18 @@
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_select() {
   return array(
     'webform_mail_select' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_select($component, $sids = array()) {
   $options = _webform_select_options($component['extra']['items'], TRUE);
@@ -469,41 +443,26 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_select($data) {
+function _webform_table_data_select($component, $value) {
   $output = '';
   // Set the value as a single string.
-  if (is_array($data['value'])) {
-    foreach ($data['value'] as $value) {
-      if ($value !== '0') {
-        $output .= check_plain($value) .'<br />';
+  if (is_array($value)) {
+    foreach ($value as $option_value) {
+      if ($option_value !== '0') {
+        $output .= check_plain($option_value) .'<br />';
       }
     }
   }
   else {
-    $output .= check_plain(empty($data['value']['0']) ? '' : $data['value']['0']);
+    $output .= check_plain(empty($value[0]) ? '' : $value[0]);
   }
   return $output;
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_select($component) {
   $headers = array(
@@ -536,24 +495,16 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_select($data, $component) {
-  $value = _webform_filter_values($component['value'], NULL, NULL, FALSE);
+function _webform_csv_data_select($component, $value) {
+  $component_values = _webform_filter_values($component['value'], NULL, NULL, FALSE);
   $options = _webform_select_options($component['extra']['items'], TRUE);
   $return = array();
 
   if ($component['extra']['multiple']) {
     foreach ($options as $key => $item) {
-      
-      if (in_array($key, (array)$data['value']) === TRUE) {
+      if (in_array($key, (array) $component_values) === TRUE) {
         $return[] = 'X';
       }
       else {
@@ -562,7 +513,7 @@
     }
   }
   else {
-    $return = $data['value'][0];
+    $return = $value[0];
   }
   return $return;
 }
Index: components/textfield.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/textfield.inc,v
retrieving revision 1.15
diff -u -r1.15 textfield.inc
--- components/textfield.inc	15 Oct 2009 01:29:57 -0000	1.15
+++ components/textfield.inc	11 Jan 2010 08:29:11 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module textfield component.
+ * Webform module textfield component.
  */
 
 /**
- * Create a default textfield component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_textfield() {
   return array(
@@ -31,81 +31,70 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
- */
-function _webform_edit_textfield($currfield) {
-  $edit_fields = array();
-  $edit_fields['value'] = array(
+ * Implementation of _webform_edit_component().
+ */
+function _webform_edit_textfield($component) {
+  $form = array();
+  $form['value'] = array(
     '#type' => 'textfield',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') . theme('webform_token_help'),
     '#size' => 60,
     '#maxlength' => 127,
     '#weight' => 0,
   );
-  $edit_fields['extra']['width'] = array(
+  $form['extra']['width'] = array(
     '#type' => 'textfield',
     '#title' => t('Width'),
-    '#default_value' => $currfield['extra']['width'],
+    '#default_value' => $component['extra']['width'],
     '#description' => t('Width of the textfield.') .' '. t('Leaving blank will use the default size.'),
     '#size' => 5,
     '#maxlength' => 10,
     '#weight' => 0,
   );
-  $edit_fields['extra']['maxlength'] = array(
+  $form['extra']['maxlength'] = array(
     '#type' => 'textfield',
     '#title' => t('Maxlength'),
-    '#default_value' => $currfield['extra']['maxlength'],
+    '#default_value' => $component['extra']['maxlength'],
     '#description' => t('Maxlength of the textfield.'),
     '#size' => 5,
     '#maxlength' => 10,
     '#weight' => 0,
   );
-  $edit_fields['extra']['field_prefix'] = array(
+  $form['extra']['field_prefix'] = array(
     '#type' => 'textfield',
     '#title' => t('Label placed to the left of the textfield'),
-    '#default_value' => $currfield['extra']['field_prefix'],
+    '#default_value' => $component['extra']['field_prefix'],
     '#description' => t('Examples: $, #, -.'),
     '#size' => 20,
     '#maxlength' => 127,
     '#weight' => 1.1,
   );
-  $edit_fields['extra']['field_suffix'] = array(
+  $form['extra']['field_suffix'] = array(
     '#type' => 'textfield',
     '#title' => t('Label placed to the right of the textfield'),
-    '#default_value' => $currfield['extra']['field_suffix'],
+    '#default_value' => $component['extra']['field_suffix'],
     '#description' => t('Examples: lb, kg, %.'),
     '#size' => 20,
     '#maxlength' => 127,
     '#weight' => 1.2,
   );
-  $edit_fields['extra']['disabled'] = array(
+  $form['extra']['disabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Disabled'),
     '#return_value' => 1,
     '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
     '#weight' => 3,
-    '#default_value' => $currfield['extra']['disabled'],
+    '#default_value' => $component['extra']['disabled'],
   );
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_textfield($component, $filter = TRUE) {
+function _webform_render_textfield($component, $value = NULL, $filter = TRUE) {
   $form_item = array(
     '#type'          => $component['type'],
     '#title'         => $component['name'],
@@ -132,34 +121,25 @@
     $form_item['#maxlength'] = $component['extra']['maxlength'];
   }
 
+  if (isset($value)) {
+    $form_item['#default_value'] = $value[0];
+  }
+
   return $form_item;
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_textfield($data, $component, $enabled = FALSE) {
+function _webform_display_textfield($component, $value) {
   $form_item = _webform_render_textfield($component);
-  $form_item['#default_value'] = $data['value']['0'];
-  if (!$enabled) {
-    $form_item['#attributes']['readonly'] = 'readonly';
-  }
+  $form_item['#default_value'] = $value[0];
+  $form_item['#attributes']['readonly'] = 'readonly';
   return $form_item;
 }
 
 /**
- * Convert a FAPI form element into settings savable in a component.
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_textfield(&$component, $form_element) {
   $component['extra']['width'] = isset($form_element['#size']) ? $form_element['#size'] : NULL;
@@ -171,7 +151,7 @@
 }
 
 /**
- * Module specific instance of hook_form_builder_types().
+ * Implementation of _webform_form_builder_types_component().
  */
 function _webform_form_builder_types_textfield() {
   $fields = array();
@@ -198,35 +178,33 @@
 }
 
 /**
- * Format the output of emailed data for this component
+ * Format the output of e-mailed data for this component
  *
- * @param $data
- *   A string or array of the submitted data
  * @param $component
- *   An array of information describing the component,
- *   directly correlating to the webform_component database schema.
- *
+ *   A Webform component array.
+ * @param $value
+ *   A string or array of the submitted data
  * @return string
  *   Textual output to be included in the email.
  */
-function theme_webform_mail_textfield($data, $component) {
-  $value = $data == '' ? '' : ' '. $component['extra']['field_prefix'] . $data . $component['extra']['field_suffix'];
+function theme_webform_mail_textfield($component, $value) {
+  $value = $value == '' ? '' : ' '. $component['extra']['field_prefix'] . $value . $component['extra']['field_suffix'];
   return $component['name'] .':'. $value;
 }
 
 /**
- * Module specific instance of hook_theme().
+ * Implementation of _webform_theme_component().
  */
 function _webform_theme_textfield() {
   return array(
     'webform_mail_textfield' => array(
-      'arguments' => array('data' => NULL, 'component' => NULL),
+      'arguments' => array('component' => NULL, 'value' => NULL),
     ),
   );
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_textfield($section) {
   switch ($section) {
@@ -236,18 +214,7 @@
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_textfield($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -276,29 +243,14 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_textfield($data) {
-  return check_plain(empty($data['value']['0']) ? '' : $data['value']['0']);
+function _webform_table_data_textfield($component, $value) {
+  return check_plain(empty($value[0]) ? '' : $value[0]);
 }
 
-
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_textfield($component) {
   $header = array();
@@ -309,15 +261,8 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_textfield($data) {
-  return !isset($data['value']['0']) ? '' : $data['value']['0'];
+function _webform_csv_data_textfield($component, $value) {
+  return !isset($value[0]) ? '' : $value[0];
 }
Index: components/email.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/email.inc,v
retrieving revision 1.22
diff -u -r1.22 email.inc
--- components/email.inc	20 Jun 2009 23:04:58 -0000	1.22
+++ components/email.inc	11 Jan 2010 08:29:10 -0000
@@ -3,11 +3,11 @@
 
 /**
  * @file
- *   Webform module email component.
+ * Webform module email component.
  */
 
 /**
- * Create a default email component.
+ * Implementation of _webform_defaults_component().
  */
 function _webform_defaults_email() {
   return array(
@@ -28,56 +28,50 @@
 }
 
 /**
- * Create a set of form items to be displayed on the form for editing this
- * component. Use care naming the form items, as this correlates directly to the
- * database schema. The component "Name" and "Description" fields are added to
- * every component type and are not necessary to specify here (although they may
- * be overridden if desired).
- * @return
- *   An array of form items to be displayed on the edit component page.
+ * Implementation of _webform_edit_component().
  */
-function _webform_edit_email($currfield) {
-  $edit_fields['value'] = array(
+function _webform_edit_email($component) {
+  $form['value'] = array(
     '#type' => 'textfield',
     '#title' => t('Default value'),
-    '#default_value' => $currfield['value'],
+    '#default_value' => $component['value'],
     '#description' => t('The default value of the field.') . theme('webform_token_help'),
     '#size' => 60,
     '#maxlength' => 127,
     '#weight' => 0,
-    '#attributes' => ($currfield['value'] == '%useremail' && count(form_get_errors()) == 0) ? array('disabled' => TRUE) : array(),
+    '#attributes' => ($component['value'] == '%useremail' && count(form_get_errors()) == 0) ? array('disabled' => TRUE) : array(),
     '#id' => 'email-value',
   );
-  $edit_fields['user_email'] = array(
+  $form['user_email'] = array(
     '#type' => 'checkbox',
     '#title' => t('User email as default'),
-    '#default_value' => $currfield['value'] == '%useremail' ? 1 : 0,
+    '#default_value' => $component['value'] == '%useremail' ? 1 : 0,
     '#description' => t('Set the default value of this field to the user email, if he/she is logged in.'),
     '#attributes' => array('onclick' => 'getElementById("email-value").value = (this.checked ? "%useremail" : ""); getElementById("email-value").disabled = this.checked;'),
     '#weight' => 0,
     '#element_validate' => array('_webform_edit_email_validate'),
   );
-  $edit_fields['extra']['width'] = array(
+  $form['extra']['width'] = array(
     '#type' => 'textfield',
     '#title' => t('Width'),
-    '#default_value' => $currfield['extra']['width'],
+    '#default_value' => $component['extra']['width'],
     '#description' => t('Width of the textfield.') .' '. t('Leaving blank will use the default size.'),
     '#size' => 5,
     '#maxlength' => 10,
   );
-  $edit_fields['extra']['disabled'] = array(
+  $form['extra']['disabled'] = array(
     '#type' => 'checkbox',
     '#title' => t('Disabled'),
     '#return_value' => 1,
     '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'),
     '#weight' => 3,
-    '#default_value' => $currfield['extra']['disabled'],
+    '#default_value' => $component['extra']['disabled'],
   );
-  return $edit_fields;
+  return $form;
 }
 
 /**
- * Validation function for the email edit form.
+ * Element validation function for the email edit form.
  */
 function _webform_edit_email_validate($element, &$form_state) {
   if ($form_state['values']['user_email']) {
@@ -86,14 +80,9 @@
 }
 
 /**
- * Build a form item array containing all the properties of this component.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of a form item to be displayed on the client-side webform.
+ * Implementation of _webform_render_component().
  */
-function _webform_render_email($component) {
+function _webform_render_email($component, $value = NULL) {
   global $user;
   $form_item = array(
     '#type'          => 'textfield',
@@ -110,6 +99,10 @@
     '#form_builder'  => array('element_type' => 'email'),
   );
 
+  if (isset($value)) {
+    $form_item['#default_value'] = $value[0];
+  }
+
   if ($component['extra']['disabled']) {
     $form_item['#attributes']['readonly'] = 'readonly';
   }
@@ -123,8 +116,9 @@
 }
 
 /**
- * A Drupal Forms API Validation function. Validates the entered values from
+ * A Drupal Form API Validation function. Validates the entered values from
  * email components on the client-side form.
+ *
  * @param $form_element
  *   The e-mail form element.
  * @param $form_state
@@ -140,30 +134,17 @@
 }
 
 /**
- * Display the result of a textfield submission. The output of this function
- * will be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @param $enabled
- *   If enabled, the value may be changed. Otherwise it will set to readonly.
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_display_component().
  */
-function _webform_submission_display_email($data, $component, $enabled = FALSE) {
-  $form_item = _webform_render_email($component);
-  $form_item['#default_value'] = $data['value']['0'];
-  if (!$enabled) {
-    $form_item['#attributes']['readonly'] = 'readonly';
-  }
+function _webform_display_email($component, $value) {
+  $form_item = _webform_render_email($component, $value);
+  $form_item['#default_value'] = $value[0];
+  $form_item['#attributes']['readonly'] = 'readonly';
   return $form_item;
 }
 
 /**
- * Convert a FAPI form element into settings savable in a component.
+ * Implementation of _webform_form_builder_save_component().
  */
 function _webform_form_builder_save_email(&$component, $form_element) {
   $component['extra']['width'] = isset($form_element['#size']) ? $form_element['#size'] : NULL;
@@ -172,7 +153,7 @@
 }
 
 /**
- * Module specific instance of hook_form_builder_types().
+ * Implementation of _webform_form_builder_types_component().
  */
 function _webform_form_builder_types_email() {
   $fields = array();
@@ -198,7 +179,7 @@
 }
 
 /**
- * Module specific instance of hook_help().
+ * Implementation of _webform_help_component().
  */
 function _webform_help_email($section) {
   switch ($section) {
@@ -208,18 +189,7 @@
 }
 
 /**
- * Calculate and returns statistics about results for this component from all
- * submission to this webform. The output of this function will be displayed
- * under the "results" tab then "analysis".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema
- * @param $sids
- *   An optional array of submission IDs (sid). If supplied, the analysis will be limited
- *   to these sids.
- * @return
- *   An array of data rows, each containing a statistic for this component's
- *   submissions.
+ * Implementation of _webform_analysis_rows_component().
  */
 function _webform_analysis_rows_email($component, $sids = array()) {
   $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
@@ -248,29 +218,15 @@
 }
 
 /**
- * Return the result of this component's submission for display in a table. The
- * output of this function will be displayed under the "results" tab then "table".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema
- * @return
- *   Textual output formatted for human reading.
+ * Implementation of _webform_table_data_component().
  */
-function _webform_table_data_email($data) {
-  return check_plain(empty($data['value']['0']) ? '' : $data['value']['0']);
+function _webform_table_data_email($component, $value) {
+  return check_plain(empty($value[0]) ? '' : $value[0]);
 }
 
 
 /**
- * Return the header information for this component to be displayed in a comma
- * seperated value file. The output of this function will be displayed under the
- * "results" tab then "download".
- * @param $component
- *   An array of information describing the component, directly correlating to
- *   the webform_component database schema.
- * @return
- *   An array of data to be displayed in the first three rows of a CSV file, not
- *   including either prefixed or trailing commas.
+ * Implementation of _webform_csv_headers_component().
  */
 function _webform_csv_headers_email($component) {
   $header = array();
@@ -281,15 +237,8 @@
 }
 
 /**
- * Return the result of a textfield submission. The output of this function will
- * be displayed under the "results" tab then "submissions".
- * @param $data
- *   An array of information containing the submission result, directly
- *   correlating to the webform_submitted_data database schema.
- * @return
- *   Textual output formatted for CSV, not including either prefixed or trailing
- *   commas.
+ * Implementation of _webform_csv_data_component().
  */
-function _webform_csv_data_email($data) {
-  return empty($data['value']['0']) ? '' : $data['value']['0'];
+function _webform_csv_data_email($component, $value) {
+  return empty($value[0]) ? '' : $value[0];
 }
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.150
diff -u -r1.150 webform.module
--- webform.module	11 Jan 2010 01:13:35 -0000	1.150
+++ webform.module	11 Jan 2010 08:29:10 -0000
@@ -705,6 +705,7 @@
       'confirmation' => '',
       'confirmation_format' => FILTER_FORMAT_DEFAULT,
       'teaser' => 0,
+      'allow_draft' => 0,
       'submit_notice' => 0,
       'submit_text' => '',
       'submit_limit' => -1,
@@ -813,7 +814,7 @@
   global $user;
   // If a teaser, do not display the form.
   if ($teaser && !$node->webform['teaser']) {
-    $node->content['teaser'] = array('#value' => check_markup($node->teaser, $node->format, FALSE));
+    return;
   }
 
   $submission = array();
@@ -1386,41 +1387,31 @@
   // Load with submission information if necessary.
   if (!$enabled) {
     // This component is display only.
-    $display_function = '_webform_submission_display_'. $component['type'];
+    $display_function = '_webform_display_'. $component['type'];
     if (function_exists($display_function)) {
-      $parent_fieldset[$component['form_key']] = $display_function(empty($submission->data[$cid]) ? NULL : $submission->data[$cid], $component, $enabled);
+      $parent_fieldset[$component['form_key']] = $display_function($component, (empty($submission->data[$cid]['value']) ? NULL : $submission->data[$cid]['value']));
     }
   }
   elseif ($component['page_num'] == $page_num) {
     // Add this user-defined field to the form (with all the values that are always available).
-    if (isset($submission->data)) {
-      $display_function = '_webform_submission_display_'. $component['type'];
-      if (function_exists($display_function)) {
-        $data = isset($submission->data[$cid]) ? $submission->data[$cid] : NULL;
-        $parent_fieldset[$component['form_key']] = $display_function($data, $component, $enabled);
-      }
-    }
-    else {
-      $render_function = '_webform_render_'. $component['type'];
-      if (function_exists($render_function)) {
-        // Call the component render function.
-        $parent_fieldset[$component['form_key']] = $render_function($component, $filter);
-
-        // Set a value if one already exists in the form state.
-        if (isset($component_value)) {
-          if (is_array($component_value)) {
-            foreach ($component_value as $key => $value) {
-              $parent_fieldset[$component['form_key']][$key]['#default_value'] = $value;
-            }
-          }
-          else {
-            $parent_fieldset[$component['form_key']]['#default_value'] = $component_value;
+    $render_function = '_webform_render_'. $component['type'];
+    if (function_exists($render_function)) {
+      // Call the component render function.
+      $data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL;
+      $parent_fieldset[$component['form_key']] = $render_function($component, $data, $filter);
+
+      // Override the value if one already exists in the form state.
+      if (isset($component_value)) {
+        $parent_fieldset[$component['form_key']]['#default_value'] = $component_value;
+        if (is_array($component_value)) {
+          foreach ($component_value as $key => $value) {
+            $parent_fieldset[$component['form_key']][$key]['#default_value'] = $value;
           }
         }
       }
-      else {
-        drupal_set_message(t('The webform component @type is not able to be displayed', array('@type' => $component['type'])));
-      }
+    }
+    else {
+      drupal_set_message(t('The webform component @type is not able to be displayed', array('@type' => $component['type'])));
     }
   }
 
@@ -1812,7 +1803,7 @@
         $submit_function = '_webform_submit_'. $component['type'];
         if (function_exists($submit_function) && (!isset($types) || in_array($component['type'], $types))) {
           // Call the component process submission function.
-          $submit_function($form_values[$component['form_key']], $component);
+          $form_values[$component['form_key']] = $submit_function($component, $form_values[$component['form_key']]);
         }
       }
     }
Index: includes/webform.submissions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.submissions.inc,v
retrieving revision 1.3
diff -u -r1.3 webform.submissions.inc
--- includes/webform.submissions.inc	11 Jan 2010 01:13:35 -0000	1.3
+++ includes/webform.submissions.inc	11 Jan 2010 08:29:12 -0000
@@ -84,7 +84,7 @@
   foreach ($node->webform['components'] as $cid => $component) {
     $delete_function = '_webform_delete_'. $component['type'];
     if (function_exists($delete_function) && isset($submission->data[$cid])) {
-      $delete_function($submission->data[$cid], $component);
+      $delete_function($component, $submission->data[$cid]);
     }
   }
 
Index: includes/webform.components.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.components.inc,v
retrieving revision 1.8
diff -u -r1.8 webform.components.inc
--- includes/webform.components.inc	10 Jan 2010 00:39:05 -0000	1.8
+++ includes/webform.components.inc	11 Jan 2010 08:29:12 -0000
@@ -139,7 +139,7 @@
   $form['add']['weight'] = array(
     '#type' => 'weight',
     '#delta' => count($node->webform['components']) > 10 ? count($node->webform['components']) : 10,
-    '#default_value' => (isset($_GET['cid']) && isset($node->webform['components'][$_GET['cid']])) ? $node->webform['components'][$_GET['cid']]['weight'] + 1 : count($node->webform['components']),
+    '#default_value' => (isset($_GET['cid']) && isset($node->webform['components'][$_GET['cid']])) ? $node->webform['components'][$_GET['cid']]['weight'] + 1: count($node->webform['components']),
   );
 
   $form['add']['add'] = array(
@@ -303,7 +303,7 @@
   }
   elseif (isset($_POST['op']) && $_POST['op'] == t('Add')) {
     $component = $form_state['values']['add'];
-    $form_state['redirect'] = array('node/'. $node->nid .'/webform/components/new/'. $component['type'], drupal_get_destination() . '&name='. urlencode($component['name']) .'&mandatory='. $component['mandatory'] .'&email='. $component['email'] .'&pid='. $component['pid'] .'&weight='. $component['weight']);
+    $form_state['redirect'] = array('node/'. $node->nid .'/webform/components/new/'. $component['type'], 'name='. urlencode($component['name']) .'&mandatory='. $component['mandatory'] .'&email='. $component['email'] .'&pid='. $component['pid'] .'&weight='. $component['weight']);
   }
   else {
     drupal_set_message(t('The component positions and mandatory values have been updated.'));
@@ -484,7 +484,7 @@
   $edit_function = '_webform_edit_'. $component['type'];
   $additional_form_elements = array();
   if (function_exists($edit_function)) {
-    $additional_form_elements = $edit_function($component); // Call the component render function.
+    $additional_form_elements = $edit_function($component);
   }
   else {
     drupal_set_message(t('The webform component of type @type does not have an edit function defined.', array('@type' => $component['type'])));
@@ -507,7 +507,7 @@
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
-    '#weight' => 5,
+    '#weight' => 20,
   );
 
   return $form;
@@ -643,7 +643,7 @@
     $submissions = webform_get_submissions($node->nid);
     foreach ($submissions as $submission) {
       if (isset($submission->data[$component['cid']])) {
-        $delete_function($submission->data[$component['cid']], $component);
+        $delete_function($component, $submission->data[$component['cid']]);
       }
     }
   }
Index: includes/webform.report.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.report.inc,v
retrieving revision 1.5
diff -u -r1.5 webform.report.inc
--- includes/webform.report.inc	11 Jan 2010 01:13:35 -0000	1.5
+++ includes/webform.report.inc	11 Jan 2010 08:29:12 -0000
@@ -231,8 +231,8 @@
     foreach ($node->webform['components'] as $component) {
       $table_function = '_webform_table_data_'. $component['type'];
       if (function_exists($table_function)) {
-        $data = isset($submission->data[$component['cid']]) ? $submission->data[$component['cid']] : NULL;
-        $submission_output = $table_function($data, $component);
+        $data = isset($submission->data[$component['cid']]['value']) ? $submission->data[$component['cid']]['value'] : NULL;
+        $submission_output = $table_function($component, $data);
         if ($submission_output !== NULL) {
           $component_headers[] = $component['name'];
           $cell[] = $submission_output;
@@ -435,8 +435,8 @@
       $csv_data_function = '_webform_csv_data_'. $component['type'];
       if (function_exists($csv_data_function)) {
         // Let each component add its data.
-        $raw_data = isset($submission->data[$cid]) ? $submission->data[$cid] : NULL;
-        $data = $csv_data_function($raw_data, $component);
+        $raw_data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL;
+        $data = $csv_data_function($component, $raw_data);
         if (is_array($data)) {
           $row = array_merge($row, array_values($data));
         }
Index: webform_hooks.php
===================================================================
RCS file: webform_hooks.php
diff -N webform_hooks.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ webform_hooks.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,424 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Sample hooks demonstrating usage in Webform.
+ */
+
+/**
+ * @defgroup webform_component Sample Webform Component
+ * @{
+ * Note that while these sample functions contain the word "hook", they are
+ * not actual hooks, but instead samples of how Webform integrates with its
+ * own built-in components. Additional components should not be written using
+ * this method unless they will be integrated with Webform core. Use
+ * the public API hooks for making your own components.
+ *
+ * @see webform_components
+ */
+
+/**
+ * Specify the default properties of a component.
+ *
+ * @return
+ *   An array defining the default structure of a component.
+ */
+function _webform_defaults_component() {
+  return array(
+    'name' => '',
+    'form_key' => NULL,
+    'email' => 1,
+    'mandatory' => 0,
+    'pid' => 0,
+    'weight' => 0,
+    'extra' => array(
+      'options' => '',
+      'questions' => '',
+      'optrand' => 0,
+      'qrand' => 0,
+      'description' => '',
+    ),
+  );
+}
+
+/**
+ * Generate the form for editing a component.
+ *
+ * Create a set of form elements to be displayed on the form for editing this
+ * component. Use care naming the form items, as this correlates directly to the
+ * database schema. The component "Name" and "Description" fields are added to
+ * every component type and are not necessary to specify here (although they
+ * may be overridden if desired).
+ *
+ * @param $component
+ *   A Webform component array.
+ * @return
+ *   An array of form items to be displayed on the edit component page
+ */
+function _webform_edit_component($component) {
+  $form = array();
+
+  // Disabling the description if not wanted.
+  $form['description'] = array();
+
+  // Most options are stored in the "extra" array, which stores any settings
+  // unique to a particular component type.
+  $form['extra']['options'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Options'),
+    '#default_value' => $component['extra']['options'],
+    '#description' => t('Key-value pairs may be entered separated by pipes. i.e. safe_key|Some readable option') . theme('webform_token_help'),
+    '#cols' => 60,
+    '#rows' => 5,
+    '#weight' => -3,
+    '#required' => TRUE,
+  );
+  return $form;
+}
+
+/**
+ * Validate the configuration form of _webform_edit_component().
+ *
+ * @param $form
+ *   The complete form array for editing a component.
+ * @param $form_state
+ *   The form state array containing the submitted values.
+ */
+function _webform_edit_validate_component($form, $form_state) {
+  $rows = explode('\n', $form['extra']['options']);
+  if (count($rows) < 2) {
+    form_error($form['extra']['options'], t('At least 2 options must be provided.'));
+  }
+}
+
+/**
+ * Define the component to structure to hook_form_builder_types().
+ */
+function _webform_form_builder_types_email() {
+  $fields = array();
+
+  $fields['email'] = array(
+    'title' => t('E-mail'),
+    'properties' => array(
+      'title',
+      'description',
+      'default_value',
+      'required',
+      'size',
+      'key',
+    ),
+    'default' => array(
+      '#title' => t('New e-mail'),
+      '#type' => 'textfield',
+      '#form_builder' => array('element_type' => 'email'),
+    ),
+  );
+
+  return $fields;
+}
+
+/**
+ * Convert a FAPI form element into settings savable in a component.
+ *
+ * @param $component
+ *   The Webform component to be saved.
+ * @param $form_element
+ *   The form element as edited by the user through Form Builder.
+ */
+function _webform_form_builder_save_component(&$component, $form_element) {
+  $component['extra']['width'] = isset($form_element['#size']) ? $form_element['#size'] : NULL;
+  $component['extra']['description'] = isset($form_element['#description']) ? $form_element['#description'] : NULL;
+  $component['extra']['disabled'] = isset($form_element['#disabled']) ? $form_element['#disabled'] : FALSE;
+}
+
+/**
+ * Module specific instance of hook_form_builder_preview_alter().
+ */
+function _webform_form_builder_preview_alter_hidden(&$form_element) {
+  // Make hidden fields visible while editing.
+  $form_element['#field_suffix'] = '(' . t('hidden') . ')';
+  $form_element['#autocomplete_path'] = NULL; // Needed to avoid notices.
+  $form_element['#type'] = 'textfield';
+}
+
+/**
+ * Render a Webform component to be part of a form.
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $value
+ *   If editing an existing submission or resuming a draft, this will contain
+ *   an array of values to be shown instead of the default in the component
+ *   configuration. This value will always be an array, keyed numerically for
+ *   each value saved in this field.
+ */
+function _webform_render_component($component, $value = NULL) {
+  $form_item = array(
+    '#type' => 'textfield',
+    '#title' => $component['name'],
+    '#required' => $component['mandatory'],
+    '#weight' => $component['weight'],
+    '#description'   => _webform_filter_descriptions($component['extra']['description']),
+    '#default_value' => $component['value'],
+    '#prefix' => '<div class="webform-component-'. $component['type'] .'" id="webform-component-'. $component['form_key'] .'">',
+    '#suffix' => '</div>',
+  );
+
+  if (isset($value)) {
+    $form_item['#default_value'] = $value[0];
+  }
+
+  return $form_item;
+}
+
+/**
+ * Display the result of a submission for a component.
+ * 
+ * The output of this function will be displayed under the "Results" tab then
+ * "Submissions". This should output the saved data in some reasonable manner.
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $value
+ *   An array of information containing the submission result, directly
+ *   correlating to the webform_submitted_data database table schema.
+ * @return
+ *   Textual output formatted for human reading.
+ */
+function _webform_display_component($component, $value, $enabled = FALSE) {
+  $form_item = _webform_render_component($component, FALSE);
+  $cid = 0;
+  foreach (element_children($form_item) as $key) {
+    $form_item[$key]['#default_value'] = $value[$cid++];
+    $form_item[$key]['#disabled'] = !$enabled;
+  }
+  return $form_item;
+}
+
+/**
+ * A hook for changing the input values before saving to the database.
+ *
+ * Note that Webform will save the result of this function directly into the
+ * database.
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $value
+ *   The POST data associated with the user input.
+ * @return
+ *   An array of values to be saved into the database. Note that this should be
+ *   a numerically keyed array.
+ */
+function _webform_submit_component($component, $value) {
+  // Clean up a phone number into 123-456-7890 format.
+  if ($component['extra']['phone_number']) {
+    $matches = array();
+    $number = preg_replace('[^0-9]', $value[0]);
+    if (strlen($number) == 7) {
+      $number = substr($number, 0, 3) . '-' . substr($number, 3, 4);
+    }
+    else {
+      $number = substr($number, 0, 3) . '-' . substr($number, 3, 3) . '-' . substr($number, 6, 4);
+    }
+  }
+
+  $value[0] = $number;
+  return $value;
+}
+
+/**
+ * Delete operation for a component or submission.
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $data
+ *   An array of information containing the submission result, directly
+ *   correlating to the webform_submitted_data database schema.
+ */
+function _webform_delete_component($component, $value) {
+  // Delete corresponding files when a submission is deleted.
+  $filedata = unserialize($value['0']);
+  if (isset($filedata['filepath']) && is_file($filedata['filepath'])) {
+    unlink($filedata['filepath']);
+    db_query("DELETE FROM {files} WHERE filepath = '%s'", $filedata['filepath']);
+  }
+}
+
+/**
+ * Module specific instance of hook_help().
+ *
+ * This allows each Webform component to add information into hook_help().
+ */
+function _webform_help_component($section) {
+  switch ($section) {
+    case 'admin/settings/webform#grid_description':
+      return t('Allows creation of grid questions, denoted by radio buttons.');
+  }
+}
+
+/**
+ * Module specific instance of hook_theme().
+ *
+ * This allows each Webform component to add information into hook_theme().
+ */
+function _webform_theme_component() {
+  return array(
+    'webform_grid' => array(
+      'arguments' => array('grid_element' => NULL),
+    ),
+    'webform_mail_grid' => array(
+      'arguments' => array('component' => NULL, 'value' => NULL),
+    ),
+  );
+}
+
+/**
+ * Calculate and returns statistics about results for this component.
+ * 
+ * This takes into account all submissions to this webform. The output of this
+ * function will be displayed under the "Results" tab then "Analysis".
+ *
+ * @param $component
+ *   An array of information describing the component, directly correlating to
+ *   the webform_component database schema.
+ * @param $sids
+ *   An optional array of submission IDs (sid). If supplied, the analysis will
+ *   be limited to these sids.
+ * @return
+ *   An array of data rows, each containing a statistic for this component's
+ *   submissions.
+ */
+function _webform_analysis_rows_component($component, $sids = array()) {
+  // Generate the list of options and questions.
+  $options = _webform_component_options($component['extra']['options']);
+  $questions = array_values(_webform_component_options($component['extra']['questions']));
+
+  // Generate a lookup table of results.
+  $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
+  $sidfilter = count($sids) ? " AND sid in (".implode(",", $placeholders).")" : "";
+  $query = 'SELECT no, data, count(data) as datacount '.
+    ' FROM {webform_submitted_data} '.
+    ' WHERE nid = %d '.
+    ' AND cid = %d '.
+    " AND data != '' ". $sidfilter .
+    ' GROUP BY no, data';
+  $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids));
+  $counts = array();
+  while ($data = db_fetch_object($result)) {
+    $counts[$data->no][$data->data] = $data->datacount;
+  }
+
+  // Create an entire table to be put into the returned row.
+  $rows = array();
+  $header = array('');
+
+  // Add options as a header row.
+  foreach ($options as $option) {
+    $header[] = $option;
+  }
+
+  // Add questions as each row.
+  foreach ($questions as $qkey => $question) {
+    $row = array($question);
+    foreach ($options as $okey => $option) {
+      $row[] = !empty($counts[$qkey][$okey]) ? $counts[$qkey][$okey] : 0;
+    }
+    $rows[] = $row;
+  }
+  $output = theme('table', $header, $rows, array('class' => 'webform-grid'));
+
+  return array(array(array('data' => $output, 'colspan' => 2)));
+}
+
+/**
+ * Return the result of a component value for display in a table.
+ *
+ * The output of this function will be displayed under the "Results" tab then
+ * "Table".
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $value
+ *   An array of information containing the submission result, directly
+ *   correlating to the webform_submitted_data database schema.
+ * @return
+ *   Textual output formatted for human reading.
+ */
+function _webform_table_data_component($component, $value) {
+  $questions = array_values(_webform_component_options($component['extra']['questions']));
+  $output = '';
+  // Set the value as a single string.
+  if (is_array($value)) {
+    foreach ($value as $item => $value) {
+      if ($value !== '') {
+        $output .= $questions[$item] .': '. check_plain($value) .'<br />';
+      }
+    }
+  }
+  else {
+    $output = check_plain(!isset($value['0']) ? '' : $value['0']);
+  }
+  return $output;
+}
+
+/**
+ * Return the header for this component to be displayed in a CSV file.
+ *
+ * The output of this function will be displayed under the "Results" tab then
+ * "Download".
+ *
+ * @param $component
+ *   A Webform component array.
+ * @return
+ *   An array of data to be displayed in the first three rows of a CSV file, not
+ *   including either prefixed or trailing commas.
+ */
+function _webform_csv_headers_component($component) {
+  $header = array();
+  $header[0] = array('');
+  $header[1] = array($component['name']);
+  $items = _webform_component_options($component['extra']['questions']);
+  $count = 0;
+  foreach ($items as $key => $item) {
+    // Empty column per sub-field in main header.
+    if ($count != 0) {
+      $header[0][] = '';
+      $header[1][] = '';
+    }
+    // The value for this option.
+    $header[2][] = $item;
+    $count++;
+  }
+
+  return $header;
+}
+
+/**
+ * Format the submitted data of a component for CSV downloading.
+ *
+ * The output of this function will be displayed under the "Results" tab then
+ * "Download".
+ *
+ * @param $component
+ *   A Webform component array.
+ * @param $value
+ *   An array of information containing the submission result, directly
+ *   correlating to the webform_submitted_data database schema.
+ * @return
+ *   An array of items to be added to the CSV file. Each value within the array
+ *   will be another column within the file. This function is called once for
+ *   every row of data.
+ */
+function _webform_csv_data_component($component, $value) {
+  $questions = array_keys(_webform_select_options($component['extra']['questions']));
+  $return = array();
+  foreach ($questions as $key => $question) {
+    $return[] = isset($value[$key]) ? $value[$key] : '';
+  }
+  return $return;
+}
+
+/**
+ * @}
+ */
