Changeset 9008 for trunk/ippMonitor/generate
- Timestamp:
- Sep 27, 2006, 12:30:54 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippMonitor/generate (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippMonitor/generate
r9003 r9008 9 9 $template = $ARGV[1]; 10 10 $output = $ARGV[2]; 11 12 # global variables: 13 # @key, @value : paired list of keys and values 14 # @field, @name, @show, @link, @extras : properties of each table column 15 # @headcode, @tailcode : additional HTML or PHP code before or after table 11 16 12 17 &parse_schema; … … 31 36 ($key, $value) = split (" ", $line, 2); 32 37 33 # strip white space from the following34 if ($key eq "TABLE") { ($value) = $value =~ m| \s*(\S+)\s*|; }35 if ($key eq "TYPE") { ($value) = $value =~ m| \s*(\S+)\s*|; }38 # strip leading and trailing white space from the following 39 if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; } 40 if ($key eq "TYPE") { ($value) = $value =~ m|^\s*(.+)\s*$|; } 36 41 37 42 &set_keypair ($key, $value); … … 52 57 53 58 # list of the table fields 54 if ($key eq " BODY.HTML") {55 push @ bodyhtml, $value;59 if ($key eq "HEAD") { 60 push @headcode, $value; 56 61 } 57 62 58 63 # list of the table fields 59 if ($key eq "TAIL .HTML") {60 push @tail html, $value;64 if ($key eq "TAIL") { 65 push @tailcode, $value; 61 66 } 62 67 63 68 # list of the table restrictions 64 if ($key eq "RESTRICT") { 69 # replace this with a flexible where statement? 70 if ($key eq "WHERE") { 65 71 ($field) = split (/,\s+/, $value, 1); 66 # ($field) = $field =~ m|\s*(\S+)\s*|;67 68 72 if ($VERBOSE) { printf "%-20s\n", $field; } 69 push @ restrict, $field;73 push @where, $field; 70 74 } 71 75 } … … 83 87 } 84 88 85 # define query string, add to keypairs 86 &define_query_fields; 89 # define FIELDS and WHERE strings, add to keypairs 90 &define_fields_count; 91 &define_fields_string (@field); 92 &define_where_string (@where); 87 93 88 94 if (0) { … … 139 145 } 140 146 141 # fill in body HTML142 if ($line =~ m|// \*\* BODY HTML\*\*|) {143 &write_ body_html;144 } 145 146 # fill in tail HTML 147 if ($line =~ m|// \*\* TAIL HTML\*\*|) {148 &write_ tail_html;147 # fill in head HTML or PHP code 148 if ($line =~ m|// \*\* HEAD CODE \*\*|) { 149 &write_inline_code (@headcode); 150 } 151 152 # fill in tail HTML or PHP code 153 if ($line =~ m|// \*\* TAIL CODE \*\*|) { 154 &write_inline_code (@tailcode); 149 155 } 150 156 } … … 152 158 } 153 159 154 sub write_body_html { 155 my ($i); 156 157 if (@bodyhtml == 0) { return; } 158 printf FILE "?>\n"; 160 sub write_inline_code { 161 my (@code) = @_; 162 my ($i, $code, $type); 159 163 160 for ($i = 0; $i < @bodyhtml; $i++) { 161 printf FILE "$bodyhtml[$i]\n"; 162 } 163 printf FILE "<?\n"; 164 } 165 166 sub write_tail_html { 167 my ($i); 168 169 if (@tailhtml == 0) { return; } 170 printf FILE "?>\n"; 171 172 for ($i = 0; $i < @tailhtml; $i++) { 173 printf FILE "$tailhtml[$i]\n"; 174 } 175 printf FILE "<?\n"; 176 } 177 164 for ($i = 0; $i < @code; $i++) { 165 ($type, $line) = split (" ", $code[$i], 2); 166 if ($type eq "PHP") { 167 printf FILE "$line\n"; 168 } 169 if ($type eq "HTML") { 170 printf FILE "?> $line <?\n"; 171 } 172 } 173 } 174 175 # generate a table header cell (<th> </th>) for each field (show != none) 178 176 sub write_table_header { 179 177 … … 184 182 } 185 183 184 # generate a WHERE test for each field (field != *) 186 185 sub write_table_restrict { 187 186 188 for ($i = 0; $i < @restrict; $i++) { 189 $value = $restrict[$i]; 190 printf FILE "\$value = \$_GET['$value'];\n"; 191 printf FILE "if (\$value) {\n"; 192 printf FILE " if (\$WHERE) {\n"; 193 printf FILE " \$WHERE = \$WHERE . \" AND $value = '\$value'\";\n"; 194 printf FILE " } else {\n"; 195 printf FILE " \$WHERE = \"$value = '\$value'\";\n"; 196 printf FILE " }\n"; 197 printf FILE "}\n"; 187 if ($WHERE) { 188 printf FILE "\$WHERE = \"$WHERE\";\n"; 189 } 190 for ($i = 0; $i < @field; $i++) { 191 $value = $field[$i]; 192 if ($value eq "*") { next; } 193 printf FILE "\$WHERE = check_restrict ('$value', \$WHERE);\n"; 198 194 } 199 195 } 200 196 201 197 sub write_table_data { 202 my ($i );198 my ($i, $Nrow); 203 199 my ($label, $value, $string); 204 200 205 201 for ($i = 0; $i < @field; $i++) { 206 202 ($label, $value, $string) = &parse_label ($show[$i]); 203 $Nrow = $count[$i]; 207 204 208 205 # create the link variable if this entry should be linked … … 211 208 if (($label eq "value") && !$link[$i]) { 212 209 # print value without link or image 213 if (! $value ) { $value = "\$row[$i]"; }210 if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; } 214 211 print FILE " echo \"<td class=\\\"list\\\"> $value </td>\\n\";\n"; 215 212 next; … … 222 219 if ($extras[$i]) { &parse_extras ($extras[$i]); } 223 220 # print the actual table cell line with the link... 224 if (! $value ) { $value = "\$row[$i]"; }221 if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; } 225 222 printf FILE " echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> $value </a></td>\\n\";\n"; 226 223 next; … … 246 243 247 244 sub write_table_query { 248 245 my ($i); 249 246 for ($i = 0; $i < @field; $i++) { 250 247 if ($show[$i] eq "none") { next; } 251 printf FILE "echo \"<td class=\\\"list\\\"> <input type=\\\"text\\\" name=\\\"$field[$i]\\\"> </td>\\n\";\n"; 252 } 253 } 254 255 sub define_query_fields { 256 257 $FIELDS = "$field[0]"; 258 for ($i = 1; $i < @field; $i++) { 259 $FIELDS = "$FIELDS,$field[$i]"; 260 } 261 248 if ($field[$i] eq "*") { 249 # * fields create an empty cell 250 printf FILE "echo \"<td> </td>\\n\";\n"; 251 } else { 252 printf FILE "write_query_row ('$field[$i]');\n"; 253 } 254 } 255 } 256 257 sub define_fields_string { 258 my (@array) = @_; 259 my ($i, $FIELDS); 260 261 $FIELDS = "$array[0]"; 262 for ($i = 1; $i < @array; $i++) { 263 # skip * fields (not a valid query element 264 if ($array[$i] eq "*") { next; } 265 $FIELDS = "$FIELDS,$array[$i]"; 266 } 262 267 set_keypair ("FIELDS", $FIELDS); 268 } 269 270 sub define_fields_count { 271 my ($i, $Nrow); 272 273 @count = (); 274 275 $Nrow = 0; 276 for ($i = 0; $i < @field; $i++) { 277 # skip * fields (not a valid query element 278 if ($field[$i] eq "*") { 279 $count[$i] = -1; 280 } else { 281 $count[$i] = $Nrow; 282 $Nrow ++; 283 } 284 } 285 } 286 287 sub define_where_string { 288 my (@array) = @_; 289 my ($i, $FIELDS); 290 291 if (@array == 0) { return; } 292 293 $WHERE = "$array[0]"; 294 for ($i = 1; $i < @array; $i++) { 295 $WHERE = "$WHERE AND $array[$i]"; 296 } 297 298 set_keypair ("WHERE", $WHERE); 263 299 } 264 300 … … 283 319 my ($string) = $_[0]; 284 320 my ($label, $value, $outline); 285 my ($N , $i);321 my ($Nrow, $i); 286 322 287 323 # unless we replace the value with the db row element, return the original string … … 297 333 MATCH_LABEL: 298 334 for ($i = 0; $i < @field; $i++) { 335 if ($field[$i] eq "*") { next; } 299 336 if ($value =~ m|^\$$field[$i]|) { 300 $value = "\$row[$i]"; 337 $Nrow = $count[$i]; 338 $value = "\$row[$Nrow]"; 301 339 last MATCH_LABEL; 302 340 }
Note:
See TracChangeset
for help on using the changeset viewer.
