Index: trunk/ippMonitor/generate
===================================================================
--- trunk/ippMonitor/generate	(revision 13264)
+++ trunk/ippMonitor/generate	(revision 13566)
@@ -59,4 +59,8 @@
 	}
 
+	if ($key eq "FILE") {
+	    $myFile = $value;
+	}
+
 	# list of the table fields
  	if ($key eq "HEAD") {
@@ -69,7 +73,13 @@
 	}
 
-	# the IMAGE commands sets up a reference name
+	# the ARGS commands defines arguments to FIELDS commands
 	if ($key eq "ARGS") {
 	    push @linkargs, $value;
+	}
+
+	# the TD_CLASS command sets up an alternate TD class
+	if ($key eq "TD_CLASS") {
+	    $tdClass = $value;
+	    # print STDERR "found TD_CLASS\n";
 	}
 
@@ -151,4 +161,9 @@
 	}
 
+	# fill in TD_CLASS test
+	if ($line =~ m|// \*\* TD CLASS \*\*|) {
+	    &write_td_class;
+	}
+
 	# fill in table data
 	if ($line =~ m|// \*\* TABLE DATA \*\*|) {
@@ -164,4 +179,9 @@
 	if ($line =~ m|// \*\* TABLE RESTRICTIONS \*\*|) {
 	    &write_table_restrict;
+	}
+
+	# fill in table restricts
+	if ($line =~ m|// \*\* BUTTON RESTRICTIONS \*\*|) {
+	    &write_button_restrict;
 	}
 
@@ -200,6 +220,23 @@
     for ($i = 0; $i < @field; $i++) {
 	if ($show[$i] eq "none")  { next; }
-	printf FILE "echo \"<th class=\\\"list\\\"> $name[$i] </th>\\n\";\n";
-    }
+	# printf FILE "echo \"<th class=\\\"list\\\"> $name[$i] </th>\\n\";\n";
+	printf FILE "write_table_header (\"list\", \"$name[$i]\", \"$field[$i]\", \$buttonLink, \$ID, '$myFile');\n";
+    }
+}
+
+sub write_td_class {
+    my ($field, $testline);
+
+    if ($tdClass eq "") { return; }
+    # print STDERR "write TD CLASS: $tdClass...\n";
+
+    # TD_CLASS class field expression
+    ($class, $field, $testline) = split (" ", $tdClass, 3);
+
+    $field = &parse_fieldname ($field);
+
+    printf FILE "  if ($field $testline) {\n";
+    printf FILE "    \$class = \"$class\";\n";
+    printf FILE "  }\n";
 }
 
@@ -208,5 +245,5 @@
 
     if ($WHERE) {
-	printf FILE "\$WHERE = \"$WHERE\";\n";
+	printf FILE "\$WHERE = \"WHERE $WHERE\";\n";
     }	
     for ($i = 0; $i < @field; $i++) {
@@ -215,4 +252,15 @@
 	printf FILE "\$WHERE = check_restrict ('$value', \$WHERE);\n";
     }
+    printf FILE "\$WHERE = check_ordering (\$WHERE);\n";
+}
+
+# generate a button link entry for each field (field != *)
+sub write_button_restrict {
+
+    for ($i = 0; $i < @field; $i++) {
+	$value = $field[$i];
+	if ($value eq "*") { next; }
+	printf FILE "\$buttonLink = button_restrict ('$value', \$buttonLink);\n";
+    }
 }
 
@@ -228,19 +276,17 @@
 	if ($label eq "none")  { next; }
 
-	if (($label eq "value") && !$link[$i]) { 
-	    # print value without link or image
-	    if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
-	    print FILE "  echo \"<td class=\\\"list\\\"> $value </td>\\n\";\n";
-	    next;
-	}
-
-	if (($label eq "value") && $link[$i]) {
+	if ($label eq "value") {
 	    # create the basic link variable
-	    printf FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
-	    # add extra GET data to target
-	    if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
+	    if ($link[$i]) {
+		printf FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
+		# add extra GET data to target
+		if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
+		$myLink = "\$link";
+	    } else {
+		$myLink = "\"\"";
+	    }
 	    # print the actual table cell line with the link...
 	    if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
-	    printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> $value </a></td>\\n\";\n";
+	    printf FILE "  write_table_cell (\$class, $myLink, $value);\n";
 	    next;
 	}
@@ -248,5 +294,5 @@
 	if (($label eq "image") && !$link[$i]) {
 	    # print the actual table cell line with the image...
-	    printf FILE "  echo \"<td class=\\\"list\\\"><img src=\\\"$image{$value}\\\"></td>\\n\";\n";
+	    printf FILE "  echo \"<td class=\\\"\$class\\\"><img src=\\\"$image{$value}\\\"></td>\\n\";\n";
 	    next;
 	}
@@ -258,5 +304,5 @@
 	    if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); } 
 	    # print the actual table cell line with the link...
-	    printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
+	    printf FILE "  echo \"<td class=\\\"\$class\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
 	    next;
 	}
@@ -401,4 +447,6 @@
     my ($i);
     
+    # print STDERR "variable: $variable\n";
+
     unless ($variable =~ m|^\$|) {
 	return $variable;
@@ -407,8 +455,8 @@
     $fieldname = substr ($variable, 1);
 
-    print STDERR "fieldname: $fieldname\n";
-
-    for ($i = 0; $i < @field; $i++) {
-	print STDERR "$i: $field[$i] : $fieldname\n";
+    # print STDERR "fieldname: $fieldname\n";
+
+    for ($i = 0; $i < @field; $i++) {
+	# print STDERR "$i: $field[$i] : $fieldname\n";
 
 	if ($field[$i] eq "*") { next; }
@@ -420,5 +468,5 @@
 	$value = "\$row[$Nrow]";
 
-	print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
+	# print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
 	return $value;
     }
