Index: volunteer.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/volunteer/volunteer.module,v
retrieving revision 1.58
diff -u -r1.58 volunteer.module
--- volunteer.module	16 May 2006 20:22:37 -0000	1.58
+++ volunteer.module	17 May 2006 04:00:22 -0000
@@ -561,6 +561,7 @@
 
 function volunteer_volunteer_form($nid, &$edit) {
   // TODO: convert to validate/submit model for better radability
+  // webchick: another form that can't be converted as it's generated from CiviCRM.
   global $user;
   //why factor this? Because the HTML 1.0 designers did not
   //care about I18n...
@@ -621,17 +622,6 @@
     );
 
     return drupal_get_form('volunteer_form_form', $form);
-
-/*    // We do not use Forms API here, because CiviCRM
-    // ouputs HTML for the form
-    $output .= '<form action="'. $url. '" method="post">';
-    $output .= ;
-    $output .= '<input type="submit" value="'. t('Volunteer') .'"/>';
-    $output .= '</form>';
-
-    return $output;
-*/
-
   }
 }
 
@@ -881,8 +871,6 @@
     if (strtolower(get_class($contact)) != 'crm_contact_bao_contact') {
       continue;
     }
-    // TODO @ killes: This does not populate 'first name', 'last name', etc. properly.
-    // Can I refer to $contact['contact_type_object'] directly?
     $contact_data = volunteer_get_properties($contact, $header);
     if (!$single) {
       switch ($volunteer->stage) {
@@ -1188,6 +1176,10 @@
   $contact = _volunteer_array_mergedown($contact);
   $new_contact = array();
   foreach ($properties as $key => $value) {
+    // Adjust e-mail field
+    if ($key == 'email-1') {
+      $key = 'email';
+    }
     if (isset($contact[$key])) {
       $new_contact[$key] = $contact[$key];
     }
@@ -1260,22 +1252,41 @@
 }
 
 // from php.net
-// Note: Originally this was split into two functions, however this caused
-// infinite looping under PHP 5.1. I've now done a straight copy/paste from
-// http://ca3.php.net/manual/en/function.array-walk-recursive.php#48181
 function _volunteer_array_mergedown() {
-  global $outarray;
-  $outarray = array();
-  function array_walk_recphp4(&$val,$key) {
-    global $outarray;
-    if (is_array($val)) array_walk($val,'array_walk_recphp4');
-    else {
-      $outarray[$key] = $val;
+   global $outarray;
+   $outarray = array();
+   $params = func_get_args();
+   foreach ($params as $subarr) {
+       array_walk_recphp4($subarr, '');
+   }
+   return $outarray;
+} 
+
+function array_walk_recphp4(&$val,$key) {
+   global $outarray;
+
+   $val = _volunteer_object2array($val);
+   if (is_array($val)) array_walk($val,'array_walk_recphp4');
+   else {
+       $outarray[$key] = $val;
+   }
+}
+
+/**
+ * Forward-port of Drupal 4.6's object2array function
+ *
+ * Why? Because casting $val to an array in array_walk_recphp4
+ * causes a segfault.
+ */
+function _volunteer_object2array($object) {
+  if (is_object($object)) {
+    foreach ($object as $key => $value) {
+      $array[$key] = $value;
     }
   }
-  $params = func_get_args();
-  foreach ($params as $subarr) {
-    array_walk_recphp4($subarr, '');
+  else {
+    $array = $object;
   }
-  return $outarray;
+
+  return $array;
 }

