IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2006, 12:30:54 PM (20 years ago)
Author:
eugene
Message:

adding inline images, php, html, more restricts, * fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippMonitor/generate

    r9003 r9008  
    99$template = $ARGV[1];
    1010$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
    1116
    1217&parse_schema;
     
    3136        ($key, $value) = split (" ", $line, 2);
    3237       
    33         # strip white space from the following
    34         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*$|; }
    3641
    3742        &set_keypair ($key, $value);
     
    5257
    5358        # list of the table fields
    54         if ($key eq "BODY.HTML") {
    55             push @bodyhtml, $value;
     59        if ($key eq "HEAD") {
     60            push @headcode, $value;
    5661        }
    5762
    5863        # list of the table fields
    59         if ($key eq "TAIL.HTML") {
    60             push @tailhtml, $value;
     64        if ($key eq "TAIL") {
     65            push @tailcode, $value;
    6166        }
    6267
    6368        # list of the table restrictions
    64         if ($key eq "RESTRICT") {
     69        # replace this with a flexible where statement?
     70        if ($key eq "WHERE") {
    6571            ($field) = split (/,\s+/, $value, 1);
    66             # ($field) = $field =~ m|\s*(\S+)\s*|;
    67 
    6872            if ($VERBOSE) { printf "%-20s\n", $field; }
    69             push @restrict,   $field;
     73            push @where,   $field;
    7074        }
    7175    }
     
    8387    }
    8488
    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);
    8793
    8894    if (0) {
     
    139145        }
    140146
    141         # fill in body HTML
    142         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);
    149155        }
    150156    }
     
    152158}
    153159
    154 sub write_body_html {
    155     my ($i);
    156 
    157     if (@bodyhtml == 0) { return; }
    158     printf FILE "?>\n";
     160sub write_inline_code {
     161    my (@code) = @_;
     162    my ($i, $code, $type);
    159163   
    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)
    178176sub write_table_header {
    179177
     
    184182}
    185183
     184# generate a WHERE test for each field (field != *)
    186185sub write_table_restrict {
    187186
    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";
    198194    }
    199195}
    200196
    201197sub write_table_data {
    202     my ($i);
     198    my ($i, $Nrow);
    203199    my ($label, $value, $string);
    204200
    205201    for ($i = 0; $i < @field; $i++) {
    206202        ($label, $value, $string) = &parse_label ($show[$i]);
     203        $Nrow = $count[$i];
    207204
    208205        # create the link variable if this entry should be linked
     
    211208        if (($label eq "value") && !$link[$i]) {
    212209            # print value without link or image
    213             if (! $value) { $value = "\$row[$i]"; }
     210            if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
    214211            print FILE "  echo \"<td class=\\\"list\\\"> $value </td>\\n\";\n";
    215212            next;
     
    222219            if ($extras[$i]) { &parse_extras ($extras[$i]); }
    223220            # print the actual table cell line with the link...
    224             if (! $value) { $value = "\$row[$i]"; }
     221            if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
    225222            printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> $value </a></td>\\n\";\n";
    226223            next;
     
    246243
    247244sub write_table_query {
    248 
     245    my ($i);
    249246    for ($i = 0; $i < @field; $i++) {
    250247        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> &nbsp; </td>\\n\";\n";
     251        } else {
     252            printf FILE "write_query_row ('$field[$i]');\n";
     253        }
     254    }
     255}
     256
     257sub 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    }
    262267    set_keypair ("FIELDS", $FIELDS);
     268}
     269
     270sub 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
     287sub 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);
    263299}
    264300
     
    283319    my ($string) = $_[0];
    284320    my ($label, $value, $outline);
    285     my ($N, $i);
     321    my ($Nrow, $i);
    286322
    287323    # unless we replace the value with the db row element, return the original string
     
    297333          MATCH_LABEL:
    298334            for ($i = 0; $i < @field; $i++) {
     335                if ($field[$i] eq "*") { next; }
    299336                if ($value =~ m|^\$$field[$i]|) {
    300                     $value = "\$row[$i]";
     337                    $Nrow = $count[$i];
     338                    $value = "\$row[$Nrow]";
    301339                    last MATCH_LABEL;
    302340                }
Note: See TracChangeset for help on using the changeset viewer.