Index: trunk/ippMonitor/raw/ipp.php
===================================================================
--- trunk/ippMonitor/raw/ipp.php	(revision 18143)
+++ trunk/ippMonitor/raw/ipp.php	(revision 18193)
@@ -315,4 +315,9 @@
     $sortKey = "&sort=" . $_POST['sort'];
   }
+  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
+    $sortKey = "&rsort=" . $_GET['rsort']; 
+  } else {
+    $sortKey = "&rsort=" . $_POST['rsort'];
+  }
 
   if ($rowStart > 0) {
@@ -410,4 +415,14 @@
   if ($value != "") {
     $where = $where . " ORDER BY $value";
+    return $where;
+  }
+  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
+    $value = $_GET['rsort']; 
+  } else {
+    $value = $_POST['rsort'];
+  }
+  if ($value != "") {
+    $where = $where . " ORDER BY $value DESC";
+    return $where;
   }
   return $where;
@@ -432,5 +447,5 @@
 }
 
-// for numerical fields, test for both 'min' and 'max' values
+// for numerical fields, test for both 'min' and plain values
 function button_restrict_min ($key, $line) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
@@ -470,7 +485,50 @@
 }
 
-function write_table_header ($class, $name, $value, $buttonLink, $ID, $file) {
-
-  $link = "$file" . "?" . $ID['link'] . "&sort=$value";
+function write_header_cell ($class, $name) {
+
+  echo "<th class=\"$class\">$name</th>\n";
+}
+
+// write a table cell with the up and down sort arrows
+function write_sort_cell ($class, $value, $buttonLink, $ID, $file) {
+  
+  echo "<td class=\"$class\">";
+
+  // base link
+  $baselink = "$file" . "?" . $ID['link'];
+  if ($buttonLink != "") {
+    $baselink = $baselink . "&$buttonLink";
+  }
+
+  if ($_SERVER[REQUEST_METHOD] == 'GET') { 
+    $up   = $_GET['sort']; 
+    $down = $_GET['rsort']; 
+  } else {
+    $up   = $_POST['sort']; 
+    $down = $_POST['rsort']; 
+  }
+
+  // up button link
+  $link = "$baselink" . "&sort=$value";
+  if ($up == $value) {
+    echo "<a href=\"$link\"><img src=\"up.png\"></a>";
+  } else {
+    echo "<a href=\"$link\"><img src=\"left.png\"></a>";
+  }
+
+  // down button link
+  $link = "$baselink" . "&rsort=$value";
+  if ($down == $value) {
+    echo "<a href=\"$link\"><img src=\"down.png\"></a>";
+  } else {
+    echo "<a href=\"$link\"><img src=\"right.png\"></a>";
+  }
+
+  echo "</td>\n";
+}
+
+function write_write_sort_down ($class, $name, $value, $buttonLink, $ID, $file) {
+
+  $link = "$file" . "?" . $ID['link'] . "&rsort=$value";
   if ($buttonLink != "") {
     $link = $link . "&$buttonLink";
@@ -483,4 +541,6 @@
 function write_query_row ($key, $width, $mode) {
   $htmlkey = preg_replace ('|\.|', '_', $key);
+
+  // optional bits by mode
   if ($mode == 'min') {
     $htmlkey = $htmlkey . "_min";
@@ -494,13 +554,27 @@
     $value = $_POST[$htmlkey];
   }
-  // XXX need to modify $key (should it be htmlkey here?)
+
+  // full table element includes optionally the <= or >= words
+  echo "<td class=\"list\"> <input type=\"text\" name=\"$htmlkey\" size=\"$width\"";
   if ($value != "") { 
-    echo "<td class=\"list\"> <input type=\"text\" name=\"$htmlkey\" size=\"$width\" value=\"$value\"> </td>\n";
-  } else {
-    echo "<td class=\"list\"> <input type=\"text\" name=\"$htmlkey\" size=\"$width\"> </td>\n";
-  }
+    echo "value=\"$value\">";
+  } 
+  echo "</td>\n";
 }
 
 function write_table_cell ($class, $format, $link, $value) {
+
+  if ($format == '%T') {
+    $format = '%s';
+  }
+  if ($format == '%t') {
+    $format = '%s';
+    if ($value == 0) { 
+      $value = 'N'; 
+    } else {
+      $value = 'Y';
+    }
+  }
+
   $myValue = sprintf ($format, $value);
   if ($myValue == "") { $myValue = "&nbsp;"; }
