--- webform_import.old.module	2010-04-27 16:30:41.000000000 -0600
+++ webform_import.module	2010-04-28 11:52:27.000000000 -0600
@@ -3,9 +3,9 @@
 
 /**
  * @file
- * This module allow delimited data files to be imported as Results in a particular Webform
+ * Allows delimited data files to be imported as results into webforms.
  *
- * This is usefull for importing results from other systems in to Webform
+ * This is useful for importing results from other systems in to Webform.
  *
  * @author John C Jemmett <jjemmett@northwind-inc.com>
  * @author Greg Bosen <gbosen@northwind-inc.com>
@@ -16,7 +16,7 @@
  */
 
 /**
- * Implements hook_help()
+ * Implements hook_help().
  */
 function webform_import_help($section = 'admin/help#webform', $arg = NULL) {
   $output = '';
@@ -32,7 +32,7 @@
         'data' => 'Create a delimited file with the data you want uploaded',
         'children' => array(
           'data' => 'Make sure that you have a single header row consisting of either the Component names or keys',
-        )
+        ),
       ),
       array(
         'data' => 'Go to node/??? > Results > Upload',
@@ -49,11 +49,11 @@
 }
 
 /**
- * Implements hook_menu()
+ * Implements hook_menu().
  */
 function webform_import_menu() {
   $items = array();
-  $items['node/%node/webform-results/upload'] = array(
+  $items['node/%webform_menu/webform-results/upload'] = array(
     'title' => 'Upload',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('webform_import_form', 1),
@@ -61,25 +61,25 @@
     'access arguments' => array('update', 1),
     'weight' => 10,
     'type' => MENU_LOCAL_TASK,
-    );
-  $items['node/%node/webform-results/upload/%'] = array(
+  );
+  $items['node/%webform_menu/webform-results/upload/%'] = array(
     'title' => 'Get Template',
     'page callback' => 'webform_import_csvtemplate',
     'page arguments' => array(1, 4),
     'access callback' => 'node_access',
     'access arguments' => array('update', 1),
     'type' => MENU_CALLBACK,
-    );
+  );
   return $items;
 }
 
 /**
- * Creates a downloadable CSV template file for corresponding to your Webform structure.
+ * Creates a downloadable CSV template file corresponding a Webform structure.
  *
  * @param $node
- *   The current webform node
+ *   The current webform node.
  * @param $type
- *   The type of delimited file template to download
+ *   The type of delimited file template to download.
  */
 function webform_import_csvtemplate($node, $type) {
   $types = _webform_import_field_key_options();
@@ -114,7 +114,7 @@
  * Client form generation function. Allows the user to upload a delimited file.
  *
  * @param $form_state
- *   The current form values of a submission, used in multipage webforms
+ *   The current form values of a submission, used in multipage webforms.
  * @param $node
  *   The current webform node.
  *
@@ -248,8 +248,7 @@
 }
 
 /**
- * Form submission function to parse the delimited file
- * and upload the data to the database.
+ * Form submission function to parse the delimited file and add to the database.
  *
  * @param $form
  *   The current form.
@@ -263,7 +262,7 @@
   global $user, $base_url;
   module_load_include('inc', 'webform', 'includes/webform.submissions');
   $sids = array();
-  //define your limits for the submission here
+  // Define your limits for the submission here.
   $limits = array(
     'extensions' => "csv tsv txt"
   );
@@ -273,7 +272,7 @@
 
   $webform = node_load(intval($form_state['values']['nid']));
 
-  // @todo: Need to check that the node is really a webform type
+  // @todo: Need to check that the node is really a webform type.
 
   $delimiter = $form_state['values']['delimiter'];
   $delimiter = $delimiter == '\t' ? "\t" : $delimiter;
@@ -300,7 +299,7 @@
         $c++;
         $data = fgetcsv($handle, 0, $delimiter);
 
-        // ignore empty rows
+        // Ignore empty rows.
         if ($data[0] === NULL) {
           continue;
         }
@@ -328,7 +327,7 @@
 
           continue 1;
         }
-        dsm($keys);
+
         $num = count($data);
         $sid = NULL;
         if ($arraylen == $num) {
@@ -342,7 +341,7 @@
             // @TODO add validation / insert for time component
             // @TODO check for mandatory columns
 
-            // checking SID input security
+            // Checking SID input security.
             if ($keys[$fields[$k]]['form_key'] === 'SID') {
               if (!is_numeric($v)) {
                 drupal_set_message(t('Invalid SID in CSV file at row: @c.  Skipping this row!', array('@c' => ($c+1))), 'warning');
@@ -353,11 +352,11 @@
               }
             }
             
-            // checking date formats
+            // Checking date formats.
             elseif (($cid = isset($cids[$k]) ? $cids[$k]:FALSE) !== FALSE) {
               // Check if it's a date value.
               if ($keys[$fields[$k]]['type'] === 'date') {
-                // checking for MM/DD/YYYY input security
+                // Checking for MM/DD/YYYY input security.
                 if ($time = strtotime($v)) {
                   $v = date("Y-m-d",$time);
                 }
@@ -367,9 +366,9 @@
                 }
               }
 
-              // checking multiselect values
+              // Checking multiselect values.
               if (isset($keys[$fields[$k]]['extra']['multiple']) && $keys[$fields[$k]]['extra']['multiple'] == 1) {
-                // explode the value into an array and associate it back to the value
+                // Explode the value into an array and associate it back to the value.
                 $v = explode(',', $v); 
               }
               $sub_array[$cid] = $v;
@@ -385,7 +384,7 @@
             'data' => webform_submission_data($webform, $sub_array),
           );
           
-          // determine if INSERT or UPDATE based on inclusion of SID
+          // Determine if INSERT or UPDATE based on inclusion of SID.
           if ($sid != NULL) {
             $submission->sid = $sid;
             $sids[] = webform_submission_update($webform, $submission);
@@ -400,10 +399,9 @@
         }
       }
       fclose($handle);
-      
-      
-      if(!file_delete($file->destination)) {
-         watchdog('webform-import', 'File could not be deleted (cleanup process). File: %file at path %path . !details', array('%file' => $file->filename, '%path' => $file->destination, '!results' => "<br />\n<pre>" . htmlentities(print_r($form_state['values'], TRUE)) . '</pre>'), WATCHDOG_ERROR);
+
+      if (!file_delete($file->destination)) {
+        watchdog('webform-import', 'File could not be deleted (cleanup process). File: %file at path %path . !details', array('%file' => $file->filename, '%path' => $file->destination, '!results' => "<br />\n<pre>" . htmlentities(print_r($form_state['values'], TRUE)) . '</pre>'), WATCHDOG_ERROR);
       }
       drupal_set_message(t("We uploaded @count sids", array( '@count' => count($sids))));
       watchdog('webform-import', 'Submission file uploaded to %title. !details', array('%title' => $node->title, '!results' => "<br />\n<pre>". htmlentities(print_r($form_state['values'], TRUE)) . '</pre>'));
@@ -418,7 +416,7 @@
 /**
  * Returns a list of value delimiters we can use.
  *
- * @return DelimiterOptions
+ * @return
  *   An array of key/value pairs for form options list.
  */
 function _webform_import_delimiter_options() {
@@ -447,19 +445,20 @@
 }
 
 /**
- * Returns a trimmed field value
+ * Returns a trimmed field value.
  *
- * @param $v
- *   field value to be trimmed
- * @return $v
- *   trimmed field value
+ * @param $value
+ *   Field value to be trimmed.
+ * @return
+ *   Trimmed field value.
  */
-function _webform_import_csvfieldtrim($v) {
-  $v = trim($v);
-  // strip off the beginning and ending quotes if necessary
-  $v = preg_replace('/^".*"$/', '', $v);
-  // remove control characters. some editors add invalid EOL chars
-  // fgetcsv does not handle unicode characters therefore we replace them manually. see http://bugs.php.net/bug.php?id=31632
-  $v = str_replace("\x00..\x1F\xfe\xff", "", $v);
-  return $v;
+function _webform_import_csvfieldtrim($value) {
+  $value = trim($value);
+  // Strip off the beginning and ending quotes if necessary.
+  $value = preg_replace('/^".*"$/', '', $value);
+  // Remove control characters. Some editors add invalid EOL chars.
+  // fgetcsv does not handle unicode characters therefore we replace them
+  // manually. See http://bugs.php.net/bug.php?id=31632.
+  $value = str_replace("\x00..\x1F\xfe\xff", "", $value);
+  return $value;
 }
