? tablemanager-599722.patch
? tablemanager-cellfix.patch
? modules/tablemanager_admin/tablemanager.admin.inc
Index: tablemanager.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tablemanager/tablemanager.module,v
retrieving revision 1.88.2.9
diff -u -p -r1.88.2.9 tablemanager.module
--- tablemanager.module	22 Aug 2009 19:13:08 -0000	1.88.2.9
+++ tablemanager.module	28 Oct 2009 01:53:05 -0000
@@ -536,7 +536,7 @@ function tablemanager_display($tid, $lis
               break;
             }
           }
-          $temp[$col + 1] = array('data' => tablemanager_process_cell($col, $a, $header[$col]));
+          $temp[$col + 1] = tablemanager_process_cell($col, $a, $header[$col]);
         }
         else {
           $temp[$col + 1] = array('data' => '');
@@ -638,7 +638,8 @@ function tablemanager_display_rows($para
             continue;
           }
         }
-        $table[$row_id][$col] = array('data' => tablemanager_process_cell($col, $cell, $full_header[$col]));
+        $cell_value = tablemanager_process_cell($col, $cell, $full_header[$col]);
+        $table[$row_id][$col] = array('data' => $cell_value['data']);
       }
     }
   }
@@ -725,11 +726,12 @@ function tablemanager_nodeadd_form() {
  */
 function tablemanager_process_cell($col, $data, $args = array()) {
   $attributes = array();
+  $temp = array();
   $path = drupal_get_path('module', 'tablemanager');
   switch ($args['type']) {
     default: // Text + Numeric
       tablemanager_attributes($data, $attributes);
-      $temp = $data;
+      $temp['data'] = $data;
       if ($attributes) {
         foreach ($attributes as $attribute) {
           foreach ($attribute as $key => $value) {
@@ -740,25 +742,25 @@ function tablemanager_process_cell($col,
       break;
     case "3": // Date
       $exp = explode('/', $data);
-      $temp = "<!-- $data -->". date(variable_get('tablemanager_date_format', 'jS F Y'), mktime(0, 0, 0, $exp['1'], $exp['2'], $exp['0']));
+      $temp['data'] = "<!-- $data -->". date(variable_get('tablemanager_date_format', 'jS F Y'), mktime(0, 0, 0, $exp['1'], $exp['2'], $exp['0']));
       break;
     case "4": // URL
       // To do - split this nicely into display name and link rather than one entry for both
-      $temp = l($data, $data);
+      $temp['data'] = l($data, $data);
       break;
     case "5": // Email
       // To do - split this nicely into display name and email rather than one entry for both
-      $temp = l($data, 'mailto:'. $data);
+      $temp['data'] = l($data, 'mailto:'. $data);
       break;
     case "6": // Bar Chart
       $temp = theme_image($path .'/misc/'. variable_get('tablemanager_bc_colour', 'red') .'-bar.png', $data, '', array('style' => 'vertical-align: middle; margin: 5px 5px 5px 0;', 'width' => $data, 'height' => '16'), FALSE);
       if (variable_get('tablemanager_bc_end', 1)) {
-        $temp = $temp . $data;
+        $temp['data'] = $temp . $data;
       }
       break;
     case "7": // Selection
       $choices = explode("\n", $args['choices']);
-      $temp = $choices[$data];
+      $temp['data'] = $choices[$data];
       break;
     case "8": // Node Reference
       break;
Index: includes/tables.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tablemanager/includes/tables.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 tables.inc
--- includes/tables.inc	22 Aug 2009 19:13:08 -0000	1.1.2.2
+++ includes/tables.inc	28 Oct 2009 01:53:06 -0000
@@ -377,7 +377,7 @@ function tablemanager_table_edit_submit(
   $form_state['storage'] = $form_state['values'];
   // organise default sort radio button
 //  if ($form_state['clicked_button']['#post']['default'] >= 0) {
-    print_r($form_state['clicked_button']['#post']);
+//    print_r($form_state['clicked_button']['#post']);
 //  }
   if (preg_match("/^delete_(\d+)$/i", $form_state['clicked_button']['#name'], $match)) {
     unset($form_state['storage']['column'][$match[1]]);
Index: modules/tablemanager_admin/tablemanager_admin.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tablemanager/modules/tablemanager_admin/Attic/tablemanager_admin.module,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 tablemanager_admin.module
--- modules/tablemanager_admin/tablemanager_admin.module	16 Apr 2008 21:48:40 -0000	1.1.2.2
+++ modules/tablemanager_admin/tablemanager_admin.module	28 Oct 2009 01:53:06 -0000
@@ -111,36 +111,144 @@ function tablemanager_admin(&$form_state
       '#value' => t('Edit'),
     );
   }
-  $header = unserialize(db_result(db_query('SELECT header FROM {tablemanager} WHERE tid = %d', variable_get('tablemanager_table', '1'))));
-  // set element 'check' to be tree so we can export it easily later
-  $form['check']['#tree'] = TRUE;
-  $fetch = db_query('SELECT id, uid, data FROM {tablemanager_data} WHERE tid = %d', variable_get('tablemanager_table', '1'));
-  while ($row = db_fetch_object($fetch)) {
-//    $form[$row->id]['weight'] = array('#type' => 'item', '#value' => $row->id);
-    $form['check'][$row->id] = array(
-      '#type' => 'checkbox',
-      '#return_value' => TRUE,
-    );
+  
+  $tid = variable_get('tablemanager_table', 1);
+  
+  $header = unserialize(db_result(db_query('SELECT header FROM {tablemanager} WHERE tid = %d', $tid)));
+
+  $sql = 'SELECT id, uid, data FROM {tablemanager_data} WHERE tid = %d';
+  $query_count = 'SELECT COUNT(id) FROM {tablemanager_data} WHERE tid = %d';
+
+  $result = pager_query($sql, 50, 0, $query_count, array($tid));
+
+  while ($row = db_fetch_object($result)) {
+    
     $current_row = unserialize($row->data);
     foreach ($current_row as $col => $data) {
-      $form['table'][$row->id][$col] = array(
+      $cell_data = tablemanager_process_cell($col, $data, $header[$col]);
+      // Separate $form subarray because $col is user input and shouldn't overwrite anything.
+      $form['data'][$row->id][$col] = array(
         '#type' => 'item',
-        '#value' => tablemanager_process_cell($col, $data, $header[$col]),
+        '#value' => $cell_data['data'],
       );
     }
+    
+    // Other per-row form elements.    
+    // Checkbox.
+    $form['check'][$row->id] = array(
+      '#type' => 'checkbox',
+      '#return_value' => TRUE,
+    );
   }
-  $form['checkbox']['select'] = array(
+  
+  // Bulk edit form elements for the bottom of the form
+  $form['bulk_edit']['select'] = array(
     '#type' => 'select',
     '#title' => t('<em>With selected</em>'),
     '#options' => array('delete' => t('Delete'), 'edit' => t('Edit')),
   );
-  $form['checkbox']['submit'] = array(
+  $form['bulk_edit']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
   );
+  
+  $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
   return $form;
 } // tablemanager_admin
 
+
+/**
+ * Theme function for Tablemanager administration screen.
+ */
+function theme_tablemanager_admin($form) {
+  drupal_add_tabledrag('tablemanager-admin', 'order', 'sibling', 'item-weight');
+
+  $tid = variable_get('tablemanager_table', 1);
+
+  // render 'Table Operations' fieldset
+  if (isset($form['ops'])) {
+    $output = drupal_render($form['ops']);
+    foreach (element_children($form['ops']) as $temp) {
+      $output .= drupal_render($form['ops'][$temp]);
+    }
+  }
+  
+  // Table actions possible on this table.
+  $table_actions = array();
+  $table_actions[] = array(
+    'title' => t('Add new table'),
+    'href' => 'node/add/table/new',
+  );
+  $table_actions[] = array(
+    'title' => t('Edit'),
+    'href' => 'admin/content/tablemanager/table_edit/table-'. $tid,
+  );
+  $table_actions[] = array(
+    'title' => t('Delete'),
+    'href' => 'admin/content/tablemanager/table_delete/table-'. $tid,
+  );
+  
+  $title = t('Viewing Table %table', array('%table' => tablemanager_fetch_name($tid)));
+  $output = $title . theme('links', $table_actions);
+
+  // build header
+  $full_header = unserialize(db_result(db_query('SELECT header FROM {tablemanager} WHERE tid = %d', $tid)));
+  // check-all entry for checkboxes
+  $header[] = theme('table_select_header_cell');
+  $header[0]['class'] = 'select-all operations';
+  foreach ($full_header as $info) {
+    $header[] = $info;
+  }
+  
+  // insert 'Operations' column (spans three columns for add, edit and delete)
+  $header[] = array('data' => t('Operations'), 'colspan' => 3, 'class' => 'operations');
+
+  // create table
+  $rows = array();
+  foreach (element_children($form['data']) as $key) {
+    $row = array();
+    $row[] = array('data' => drupal_render($form['check'][$key]), 'class' => 'operations checkboxes');
+    
+    foreach (element_children($form['data'][$key]) as $cell_key) {
+      $row[] = drupal_render($form['data'][$key][$cell_key]);
+    }
+
+    // Operation links
+    $row[] = array('data' => l(t('add'), "tablemanager/add/$key"), 'class' => 'operations add');
+    $row[] = array('data' => l(t('edit'), "tablemanager/edit/$key"), 'class' => 'operations edit');
+    $row[] = array('data' => l(t('delete'), "tablemanager/delete/$key"), 'class' => 'operations delete');
+
+    // Append the row to the master $rows array.
+    $rows[] = $row;
+  }
+
+  if (0 == count($rows)) {
+    $rows[] = array(array('data' => t('No table data available.'), 'colspan' => 3));
+  }
+
+  // add admin selection for checkboxes
+  $rows[] = array(
+    'data' => array(
+      array(
+        'data' => drupal_render($form['bulk_edit']['select']) . drupal_render($form['bulk_edit']['submit']), 
+        'colspan' => count($header) + 1,
+      ),
+    ), 
+    'class' => 'info container-inline'
+  );
+
+  // output table
+  $output .= theme('table', $header, $rows, array('id' => 'tablemanager-admin'));
+
+  // output new entry link
+  $output .= l(t('Add new entry'), 'node/add/tablemanager/table-'. $tid);
+
+  // Render remaining fields
+  $output .= drupal_render($form);
+  return $output;
+} // theme_tablemanager_admin
+
+
 /**
  * Submit function for tablemanager_admin form.
  */
@@ -191,121 +299,3 @@ function tablemanager_admin_settings() {
   return system_settings_form($form);
 } // tablemanager_admin_settings
 
-/**
- * Theme function for Tablemanager administration screen.
- */
-function theme_tablemanager_admin($form) {
-//  drupal_add_tabledrag('tablemanager-admin', 'order', 'self', 'item-weight');
-  global $pager_page_array, $pager_total_items, $pager_total;
-  $list_length = variable_get('tablemanager_defaultadmin', NULL);
-  if ($list_length == NULL || $list_length == "NULL") {
-    $list_length = db_result(db_query('SELECT COUNT(id) FROM {tablemanager_data} WHERE tid = %d', variable_get('tablemanager_table', '1')));
-    if (!$list_length) {
-      $list_length = 1;
-    }
-  }
-  // render 'Table Operations' fieldset
-  if (isset($form['ops'])) {
-    $output = drupal_render($form['ops']);
-    foreach (element_children($form['ops']) as $temp) {
-      $output .= drupal_render($form['ops'][$temp]);
-    }
-  }
-  $output .= "<table width='100%'><tr><td width='25%' align='left'><font size='+1'>Viewing Table ". variable_get('tablemanager_table', '1') .":</font></td><td width='25%' align='center'>". l(t('Edit This Table'), 'admin/content/tablemanager/table_edit/table-'. variable_get('tablemanager_table', '1')) ."<td width='25%' align='center'>". l(t('Delete This Table'), 'admin/content/tablemanager/table_delete/table-'. variable_get('tablemanager_table', '1')) ."</td>";
-  $output .= "<td width='25%' align='right'>". l(t('Create New Table'), 'node/add/table') ."</td></tr>";
-  $output .= "<tr><td colspan='4'><font size='+1'>". tablemanager_fetch_name(variable_get('tablemanager_table', '1')) ."</font></td></tr></table>";
-  $output .= "<hr>";
-
-  // build header
-  $full_header = unserialize(db_result(db_query('SELECT header FROM {tablemanager} WHERE tid = %d', variable_get('tablemanager_table', '1'))));
-  // check-all entry for checkboxes
-  $header[] = theme('table_select_header_cell');
-  $header[0]['class'] = 'select-all operations';
-  foreach ($full_header as $info) {
-    unset($temp);
-    $temp['data'] = $info['data'];
-    if (isset($info['field'])) {
-      $temp['field'] = $info['field'];
-    }
-    if (isset($info['sort'])) {
-      $temp['sort'] = $info['sort'];
-    }
-    $header[] = $temp;
-  }
-  // insert 'Operations' column (spans two columns for edit and delete)
-  $header[] = array('data' => t('Operations'), 'colspan' => '2', 'class' => 'operations');
-
-  // create table
-  foreach (element_children($form['table']) as $row) {
-    unset($rows);
-    foreach (element_children($form['table'][$row]) as $cell) {
-      // Allow for colspan
-      if ($form['table'][$row][$cell]['#value'] == "||") {
-        if ($cell > 0) {
-          $last = array_pop($rows);
-          $up1 = $last['data'];
-          $up2 = $last['colspan'] ? $last['colspan'] : '1';
-          $up2++;
-          $rows[] = array('data' => $up1, 'colspan' => $up2);
-          unset($form['table'][$row][$cell]);
-          continue;
-        }
-        else {
-          // colspan is set for first cell so just blank it
-          $form['table'][$row][$cell]['#value'] = '';
-        }
-      }
-      $rows[$cell] = array('data' => drupal_render($form['table'][$row][$cell]));
-    }
-    array_unshift($rows, array('data' => drupal_render($form['check'][$row]), 'class' => 'operations checkboxes'));
-    array_push($rows, array('data' => l(t('edit'), "tablemanager/edit/$row"), 'class' => 'operations edit'), array('data' => l(t('delete'), "tablemanager/delete/$row"), 'class' => 'operations delete'));
-//    $form[$row]['weight']['#attributes']['class'] = 'item-weight';
-//    array_push($rows, array('data' => drupal_render($form[$row]['weight'])));
-    $table[$row] = array('data' => $rows, 'class' => 'draggable');
-  }
-  if (!$table) {
-    $table[] = array(array('data' => t('No table data available.'), 'colspan' => 2));
-  }
-  else {
-    // there are results, so sort them
-    $temp = tablesort_get_order($header);
-    if ($temp['sql']) {
-      tablemanager_sort($table, ($temp['sql']), tablesort_get_sort($header));
-    }
-  }
-
-  // if results need to be paged we have to split $table (which contains ALL the results)
-  // into separate pages because we're having to avoid using 'pager' functionality
-  $count = 1;
-  $page = isset($_GET['page']) ? $_GET['page'] : '';
-  $pager_page_array = explode(',', $page);
-  $from = ($pager_page_array[variable_get('tablemanager_table', '1')] * $list_length);
-  foreach ($table as $temp) {
-    if ($count > $from && $count <= ($from + $list_length)) {
-      $build[] = $temp;
-    }
-    $count++;
-  } // end foreach
-
-  // add admin selection for checkboxes
-  $build[] = array('data' => array(array('data' => drupal_render($form['checkbox']['select']) . drupal_render($form['checkbox']['submit']), 'colspan' => count($header) + 1)), 'class' => 'info container-inline');
-
-  // output table
-  $output .= theme('table', $header, $build, array('id' => 'tablemanager-admin'));
-
-  // set global pager variables to correct values:
-  $pager_total_items[variable_get('tablemanager_table', '1')] = count($table);
-  $pager_total[variable_get('tablemanager_table', '1')] = ceil($pager_total_items[variable_get('tablemanager_table', '1')]/$list_length);
-  $pager_page_array[variable_get('tablemanager_table', '1')] = max(0, min((int)$pager_page_array[variable_get('tablemanager_table', '1')], ((int)$pager_total[variable_get('tablemanager_table', '1')]) - 1));
-
-  // output new entry link
-  $output .= l(t('Add new entry'), 'node/add/tablemanager/table-'. variable_get('tablemanager_table', '1'));
-
-  // output pager
-  $output .= theme('pager', array(), $list_length, variable_get('tablemanager_table', '1'));
-
-  // Render remaining fields
-  $output .= drupal_render($form);
-  return $output;
-} // theme_tablemanager_admin
-
