--- matrix.module.1228	2009-09-28 15:03:21.395875000 -0400
+++ matrix.module.1228.compatibility	2009-09-28 15:03:35.536500000 -0400
@@ -1,6 +1,9 @@
 <?php
 // $Id: matrix.module,v 1.2.2.8 2009/02/05 07:08:38 aaron1234nz Exp $
 
+//define('MATRIX_NUMBER', 60);
+define('MATRIX_NUMBER', 125);  // for simplexity specs,  $max_number_of_spx_features_converted = 85
+
 /**
  * Implementation of hook_field_info().
  */
@@ -16,6 +19,12 @@
 function matrix_field_settings($op, $field) {
   switch ($op) {
     case 'form':
+      $dummy = array();
+      if (!isset($field['rows'])) {
+        list($offset,$rows,$cols) = _convert_from_old_ver($field, $dummy);
+        $field['rows'] = implode("\n", $rows);
+        $field['cols'] = implode("\n", $cols);
+      }
       $form = array();
       $form['size'] = array(
         '#type' => 'textfield',
@@ -23,7 +32,7 @@
         '#title' => t('Size of textfields'),
         '#default_value' => isset($field['size']) ? $field['size'] : 15,
       );
-      
+
       $form['rows'] = array(
         '#type' => 'textarea',
         '#title' => t('Headers in Row'),
@@ -35,7 +44,7 @@
         '#required' => TRUE,
         '#default_value' => isset($field["rows"]) ? $field["rows"] : '',
         );
-      
+
      $form['cols'] = array(
        '#type' => 'textarea',
        '#title' => t("Headers in Column"),
@@ -73,12 +82,9 @@
     case 'update':
        db_query("DELETE FROM {node_field_matrix_data} WHERE vid = %d and field_name= '%s'", $node->vid, $field['field_name']);
     case 'insert':
-      $rows = trim($field['rows']);
-      $cols = trim($field['cols']);
-      $rows = explode("\n", $rows);
-      $cols = explode("\n", $cols);
-      
-      $i=0; 
+      list($offset,$rows,$cols) = _convert_from_old_ver($field, $node_field);
+
+      $i=0;
       foreach ($rows as $row) {
         if ($row) {
           $j=0;
@@ -86,7 +92,7 @@
             if ($col) {
               db_query("INSERT INTO {node_field_matrix_data} (nid, vid, field_name, row, col, value)
                         VALUES (%d, %d, '%s', %d, %d, '%s')",
-                        $node->nid, $node->vid, $field['field_name'], $i, $j, $node_field[$i][$j]
+                        $node->nid, $node->vid, $field['field_name'], $i, $j, $node_field[$i+$offset][$j+$offset]
                       );
               $j++;
             }
@@ -137,12 +143,8 @@
  * Implementation of hook_widget().
  */
 function matrix_widget($op, &$node, $field, &$node_field) {
-  if ($field['rows'] && $field['cols']) {
-    $rows = trim($field['rows']);
-    $cols = trim($field['cols']);  
-    $rows = explode("\n", $rows);
-    $cols = explode("\n", $cols);
-  }
+  list($offset,$rows,$cols) = _convert_from_old_ver($field, $node_field);
+
   switch ($op) {
     case 'form':
       $form = array();
@@ -154,16 +156,16 @@
       else {
         $label = '<label for="'. form_clean_id($field['field_name']) .'">'. t($field['widget']['label']) .'</label>';
       }
-      
+
       $form[$field['field_name']] = array(
         '#tree' => TRUE,
         '#weight' => $field['widget']['weight'],
-        '#theme' => 'matrix_table_form', 
+        '#theme' => 'matrix_table_form',
         '#value' => $label,
         '#prefix' => '<div class="form-item matrix_field">',
         '#suffix' => '</div>',
       );
-      
+
       if ($cols) {
         $header = array_merge(array(''), $cols);
       }
@@ -177,7 +179,7 @@
               $form[$field['field_name']][$i][$j] = array(
                 '#type' => 'textfield',
                 '#size' => $field['size'],
-                '#default_value' => isset($node_field[$i][$j]) ? $node_field[$i][$j] : $field['widget']['default_value'][$i][$j],
+                '#default_value' => isset($node_field[$i+$offset][$j+$offset]) ? $node_field[$i+$offset][$j+$offset] : $field['widget']['default_value'][$i+$offset][$j+$offset],
               );
               $j++;
             }
@@ -185,11 +187,11 @@
           $i++;
         }
       }
-        
+
       $form[$field['field_name']]['header'] = array('#value' => $header);
       $form[$field['field_name']]['first_col'] = array('#value' => $first_col);
       return $form;
-      
+
     case 'validate':
       if ($field['required']) {
         $i=0;
@@ -230,7 +232,7 @@
       $rows[] = $row;
     }
   }
-  
+
   drupal_render($form['header']);
   drupal_render($form['first_col']);
   $output = drupal_render($form);
@@ -240,22 +242,19 @@
 
 
 function theme_matrix_table_view($node_field, $field) {
-  $rows = trim($field['rows']);
-  $cols = trim($field['cols']);  
-  
-  $rows = explode("\n", $rows);
-  $cols = explode("\n", $cols);
+  list($offset,$rows,$cols) = _convert_from_old_ver($field, $node_field);
+
   $header = array_merge(array(''), $cols);
 
-  $i=0;  
+  $i=0;
   foreach ($rows as $row) {
     if ($row) {
       $j=0;
       $outputs = array($row);
       foreach ($cols as $col) {
         if ($col) {
-          if (!empty($node_field[$i][$j])) {
-            $outputs[] = $node_field[$i][$j];
+          if (!empty($node_field[$i+$offset][$j+$offset])) {
+            $outputs[] = $node_field[$i+$offset][$j+$offset];
           }
           else {
             $outputs[] = '-';
@@ -265,7 +264,43 @@
       }
       $i++;
     }
-    if ($outputs) $output[] = $outputs;    
-  }  
+    if ($outputs) $output[] = $outputs;
+  }
   return theme('table', $header, $output, array());
 }
+
+
+function _convert_from_old_ver(&$field, &$node_field) {
+
+  if ($field['rows'] && $field['cols']) {
+    $rows = trim($field['rows']);
+    $cols = trim($field['cols']);
+    $rows = explode("\n", $rows);
+    $cols = explode("\n", $cols);
+  }
+  else {
+    $rows = array();
+    $bail = FALSE;
+    for ($i=1; ($i<= MATRIX_NUMBER) && !$bail; $i++)
+      if (!empty($field["label_row_$i"]))
+        $rows[] = $field["label_row_$i"];
+      else
+        $bail = TRUE;
+
+    $cols = array();
+    $bail = FALSE;
+    for ($i=1; ($i<= MATRIX_NUMBER) && !$bail; $i++)
+      if (!empty($field["label_column_$i"]))
+        $cols[] = $field["label_column_$i"];
+      else
+        $bail = TRUE;
+  }
+
+  $offset = 0; // default
+  if (isset($node_field[count($rows)]))
+    $offset = 1;
+
+  return array($offset,$rows,$cols);
+
+}
+
