Index: trunk/ippMonitor/generate
===================================================================
--- trunk/ippMonitor/generate	(revision 8984)
+++ trunk/ippMonitor/generate	(revision 9003)
@@ -39,12 +39,24 @@
 	# list of the table fields
  	if ($key eq "FIELD") {
-	    ($field, $name, $link, $extras) = split (/,\s+/, $value, 4);
+	    ($field, $name, $show, $link, $extras) = split (/,\s+/, $value, 5);
 	    # ($field) = $field =~ m|\s*(\S+)\s*|;
 
-	    if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s\n", $field, $name, $link, $extras; }
+	    if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s\n", $field, $name, $show, $link, $extras; }
+	    if ($show eq "") {$show = "value";}
 	    push @field,   $field;
 	    push @name,    $name;
+	    push @show,    $show;
 	    push @link,    $link;
 	    push @extras,  $extras;
+	}
+
+	# list of the table fields
+ 	if ($key eq "BODY.HTML") {
+	    push @bodyhtml, $value;
+	}
+
+	# list of the table fields
+ 	if ($key eq "TAIL.HTML") {
+	    push @tailhtml, $value;
 	}
 
@@ -65,7 +77,31 @@
     &check_key ("TITLE", "");
     &check_key ("FILE", "");
+    
+    # these are used internally (not just a replacement)
+    for ($i = 0; $i < @key; $i++) {
+	if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
+    }
 
     # define query string, add to keypairs
     &define_query_fields;
+
+    if (0) {
+	print STDERR "show: $show[0]\n";
+	($a, $b, $c) = &parse_label ($show[0]);
+	print STDERR "a: $a, b: $b, c: $c\n";
+
+	print STDERR "extras: $extras[0]\n";
+	($a, $b, $c) = &parse_label ($extras[0]);
+	print STDERR "a: $a, b: $b, c: $c\n";
+
+	print STDERR "show: $show[1]\n";
+	($a, $b, $c) = &parse_label ($show[1]);
+	print STDERR "a: $a, b: $b, c: $c\n";
+
+	print STDERR "extras: $extras[1]\n";
+	($a, $b, $c) = &parse_label ($extras[1]);
+	print STDERR "a: $a, b: $b, c: $c\n";
+	exit 0;
+    }
 }
 
@@ -102,11 +138,46 @@
 	    &write_table_restrict;
 	}
+
+	# fill in body HTML
+	if ($line =~ m|// \*\* BODY HTML \*\*|) {
+	    &write_body_html;
+	}
+
+	# fill in tail HTML
+	if ($line =~ m|// \*\* TAIL HTML \*\*|) {
+	    &write_tail_html;
+	}
     }
     close (FILE);
 }
 
+sub write_body_html {
+    my ($i);
+
+    if (@bodyhtml == 0) { return; }
+    printf FILE "?>\n";
+    
+    for ($i = 0; $i < @bodyhtml; $i++) {
+	printf FILE "$bodyhtml[$i]\n";
+    }
+    printf FILE "<?\n";
+}
+
+sub write_tail_html {
+    my ($i);
+
+    if (@tailhtml == 0) { return; }
+    printf FILE "?>\n";
+    
+    for ($i = 0; $i < @tailhtml; $i++) {
+	printf FILE "$tailhtml[$i]\n";
+    }
+    printf FILE "<?\n";
+}
+
 sub write_table_header {
 
     for ($i = 0; $i < @field; $i++) {
+	if ($show[$i] eq "none")  { next; }
 	printf FILE "echo \"<th class=\\\"list\\\"> $name[$i] </th>\\n\";\n";
     }
@@ -129,42 +200,45 @@
 
 sub write_table_data {
+    my ($i);
+    my ($label, $value, $string);
 
     for ($i = 0; $i < @field; $i++) {
+	($label, $value, $string) = &parse_label ($show[$i]);
+
 	# create the link variable if this entry should be linked
-	if ($link[$i]) {
+	if ($label eq "none")  { next; }
+
+	if (($label eq "value") && !$link[$i]) { 
+	    # print value without link or image
+	    if (! $value) { $value = "\$row[$i]"; }
+	    print FILE "  echo \"<td class=\\\"list\\\"> $value </td>\\n\";\n";
+	    next;
+	}
+
+	if (($label eq "value") && $link[$i]) {
+	    # 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 ($extras[$i]); } 
+	    # print the actual table cell line with the link...
+	    if (! $value) { $value = "\$row[$i]"; }
+	    printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> $value </a></td>\\n\";\n";
+	    next;
+	}
+
+	if (($label eq "image") && !$link[$i]) {
+	    # print the actual table cell line with the image...
+	    printf FILE "  echo \"<td class=\\\"list\\\"><img src=\\\"$value\\\"></td>\\n\";\n";
+	    next;
+	}
+
+	if (($label eq "image") && $link[$i]) {
 	    # create the basic link 
-	    printf FILE "  \$link = \"$link[$i]\" . \"?\" . \$ID['link'];\n";
-	    if ($extras[$i]) {
-		# examine the extras and parse the embedded fields
-		@extfields = split (/,/, $extras[$i]);
-		$N = @extfields;
-		if ($VERBOSE) { print STDERR "N extfields: $N\n"; }
-		for ($j = 0; $j < @extfields; $j++) {
-
-		    # search for embedded table fields and replace with row[N]
-		    $N = -1;
-		    $extline = $extfields[$j];
-		    if ($VERBOSE) { print STDERR "extfield: $extfields[$j]\n"; }
-		    for ($k = 0; ($k < @field) && ($N == -1); $k++) {
-			if ($extline =~ m|\$$field[$k]|) {
-			    $extline =~ s|\$$field[$k]||;
-			    $N = $k;
-			}
-		    }
-		    if ($N == -1) {
-			# no embedded field, print verbatim
-			printf FILE "  \$link = \$link . \"&$extline\";\n";
-		    } else {
-			# replace embedded field with row[N]
-			printf FILE "  \$link = \$link . \"&$extline\" . \$row[$N];\n";
-		    }
-		}
-
-	    } 
+	    printf FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
+	    # add extra php data to target
+	    if ($extras[$i]) { &parse_extras ($extras[$i]); } 
 	    # print the actual table cell line with the link...
-	    printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> \$row[$i] </a></td>\\n\";\n";
-	} else {
-	    # or without
-	    printf FILE "  echo \"<td class=\\\"list\\\"> \$row[$i] </td>\\n\";\n";
+	    printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> <img src=\\\"$value\\\"> </a></td>\\n\";\n";
+	    next;
 	}
     }
@@ -174,4 +248,5 @@
 
     for ($i = 0; $i < @field; $i++) {
+	if ($show[$i] eq "none")  { next; }
 	printf FILE "echo \"<td class=\\\"list\\\"> <input type=\\\"text\\\" name=\\\"$field[$i]\\\"> </td>\\n\";\n";
     }
@@ -186,4 +261,49 @@
  
     set_keypair ("FIELDS", $FIELDS);
+}
+
+sub parse_extras {
+    my ($extras) = $_[0];
+    my (@extfields);
+    my ($label, $value, $outline);
+    my ($i);
+
+    # examine the extras and parse the embedded fields (comma-separated)
+    @extfields = split (/,/, $extras);
+    for ($i = 0; $i < @extfields; $i++) {
+	($label, $value, $outline) = &parse_label ($extfields[$i]);
+	printf FILE "  \$link = \$link . \"&$outline\";\n";
+    }
+}
+
+# parse strings of the form label=value
+# if 'value' is of the form $field, try to match with 
+# a supplied DB field, and replace with $row[$n] if found
+sub parse_label {
+    my ($string) = $_[0];
+    my ($label, $value, $outline);
+    my ($N, $i);
+
+    # unless we replace the value with the db row element, return the original string
+    $outline = $string;
+    $label = $string;
+    $value = "";
+
+    # search for embedded table fields and replace with row[N]
+    if ($VERBOSE) { print STDERR "string: $string\n"; }
+    if ($string =~ m|\S+=\S+|) {
+	($label, $value) = $string =~ m|(\S+)=(\S+)|;
+	if ($value =~ m|^\$|) {
+	  MATCH_LABEL:
+	    for ($i = 0; $i < @field; $i++) {
+		if ($value =~ m|^\$$field[$i]|) {
+		    $value = "\$row[$i]";
+		    last MATCH_LABEL;
+		}
+	    }
+	    $outline = "$label=$value";
+	} 
+    }
+    return ($label, $value, $outline);
 }
 
