Index: includes/tablesort.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v
retrieving revision 1.17
diff -u -r1.17 tablesort.inc
--- includes/tablesort.inc	30 Mar 2004 21:01:19 -0000	1.17
+++ includes/tablesort.inc	23 May 2004 01:06:56 -0000
@@ -5,12 +5,10 @@
   static $ts;
 
   if (empty($ts)) {
-    $ts['order'] = tablesort_get_order($header);
-    $ts['order_sql'] = tablesort_get_order_sql($header, $ts['order']);
+    $ts = tablesort_get_order($header);
     $ts['sort'] = tablesort_get_sort($header);
     $ts['query_string'] = tablesort_get_querystring();
   }
-
   return $ts;
 }
 
@@ -22,7 +20,9 @@
 
 function tablesort_sql($header) {
   $ts = tablesort_init($header);
-  return " ORDER BY ". $ts['order_sql']. " ". strtoupper($ts['sort']);
+  $sql = check_query($ts['sql']);
+  $sort = strtoupper(check_query($ts['sort']));
+  return " ORDER BY $sql $sort";
 }
 
 function tablesort($cell, $header) {
@@ -30,21 +30,20 @@
   $title = t("sort by %s", array("%s" => $cell['data']));
 
   // special formatting for the currently sorted column header
-  if ($cell['data'] == $ts['order']) {
+  if ($cell['data'] == $ts['name']) {
     $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
-    $cell['class'] = 'cell-highlight';
+    $cell['class'] = 'active';
     $image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
     $title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
-  } else {
+  }
+  else {
     // If the user clicks a different header, we want to sort ascending initially.
     $ts['sort'] = "asc";
   }
 
   $cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
 
-  unset($cell['field']);
-  unset($cell['sort']);
-
+  unset($cell['field'], $cell['sort']);
   return $cell;
 }
 
@@ -59,15 +58,17 @@
 }
 
 function tablesort_get_order($headers) {
+  $i = 0;
   $order = $_GET['order'];
   foreach ($headers as $header) {
     if ($order == $header['data']) {
-      return $header['data'];
+      return array('name' => $header['data'], 'index' => $i, 'sql' => $header['field']);
     }
 
     if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
-      $default = $header['data'];
+      $default = array('name' => $header['data'], 'index' => $i, 'sql' => $header['field']);
     }
+    $i++;
   }
 
   if ($default) {
@@ -76,15 +77,7 @@
   else {
     // The first column specified is initial 'order by' field unless otherwise specified
     $first = reset($headers);
-    return $first['data'];
-  }
-}
-
-function tablesort_get_order_sql($header, $order) {
-  foreach ($header as $cell) {
-    if ($cell['data'] == $order) {
-      return $cell['field'];
-    }
+    return array('name' => $first['data'], 'index' => 0, 'sql' => $first['field']);
   }
 }
 
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.192
diff -u -r1.192 theme.inc
--- includes/theme.inc	24 Apr 2004 15:39:31 -0000	1.192
+++ includes/theme.inc	24 May 2004 12:51:16 -0000
@@ -333,6 +333,7 @@
   */
 
   if (is_array($rows)) {
+    $i = 0;
     foreach ($rows as $number => $row) {
       if ($number % 2 == 1) {
         $output .= " <tr class=\"light\">";
@@ -342,9 +343,23 @@
       }
 
       foreach ($row as $cell) {
+        // highlight the currently sorted column. only applies to tables with headers.
+        if (is_array($header)) {
+          $ts = tablesort_init($header);
+          if ($i === $ts['index']) {
+            if (is_array($cell)) {
+              $cell['class'] .= ' active';
+            }
+            else {
+              $cell = array('data' => $cell, 'class' => 'active');
+            }
+          }
+        }
         $output .= _theme_table_cell($cell, 0);
+        $i++;
       }
       $output .= " </tr>\n";
+      $i=0;
     }
   }
 
