IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 26, 2006, 6:19:19 PM (20 years ago)
Author:
eugene
Message:

many changes to support the inline images and linked images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippMonitor/generate

    r8984 r9003  
    3939        # list of the table fields
    4040        if ($key eq "FIELD") {
    41             ($field, $name, $link, $extras) = split (/,\s+/, $value, 4);
     41            ($field, $name, $show, $link, $extras) = split (/,\s+/, $value, 5);
    4242            # ($field) = $field =~ m|\s*(\S+)\s*|;
    4343
    44             if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s\n", $field, $name, $link, $extras; }
     44            if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s\n", $field, $name, $show, $link, $extras; }
     45            if ($show eq "") {$show = "value";}
    4546            push @field,   $field;
    4647            push @name,    $name;
     48            push @show,    $show;
    4749            push @link,    $link;
    4850            push @extras,  $extras;
     51        }
     52
     53        # list of the table fields
     54        if ($key eq "BODY.HTML") {
     55            push @bodyhtml, $value;
     56        }
     57
     58        # list of the table fields
     59        if ($key eq "TAIL.HTML") {
     60            push @tailhtml, $value;
    4961        }
    5062
     
    6577    &check_key ("TITLE", "");
    6678    &check_key ("FILE", "");
     79   
     80    # these are used internally (not just a replacement)
     81    for ($i = 0; $i < @key; $i++) {
     82        if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
     83    }
    6784
    6885    # define query string, add to keypairs
    6986    &define_query_fields;
     87
     88    if (0) {
     89        print STDERR "show: $show[0]\n";
     90        ($a, $b, $c) = &parse_label ($show[0]);
     91        print STDERR "a: $a, b: $b, c: $c\n";
     92
     93        print STDERR "extras: $extras[0]\n";
     94        ($a, $b, $c) = &parse_label ($extras[0]);
     95        print STDERR "a: $a, b: $b, c: $c\n";
     96
     97        print STDERR "show: $show[1]\n";
     98        ($a, $b, $c) = &parse_label ($show[1]);
     99        print STDERR "a: $a, b: $b, c: $c\n";
     100
     101        print STDERR "extras: $extras[1]\n";
     102        ($a, $b, $c) = &parse_label ($extras[1]);
     103        print STDERR "a: $a, b: $b, c: $c\n";
     104        exit 0;
     105    }
    70106}
    71107
     
    102138            &write_table_restrict;
    103139        }
     140
     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;
     149        }
    104150    }
    105151    close (FILE);
    106152}
    107153
     154sub write_body_html {
     155    my ($i);
     156
     157    if (@bodyhtml == 0) { return; }
     158    printf FILE "?>\n";
     159   
     160    for ($i = 0; $i < @bodyhtml; $i++) {
     161        printf FILE "$bodyhtml[$i]\n";
     162    }
     163    printf FILE "<?\n";
     164}
     165
     166sub 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
    108178sub write_table_header {
    109179
    110180    for ($i = 0; $i < @field; $i++) {
     181        if ($show[$i] eq "none")  { next; }
    111182        printf FILE "echo \"<th class=\\\"list\\\"> $name[$i] </th>\\n\";\n";
    112183    }
     
    129200
    130201sub write_table_data {
     202    my ($i);
     203    my ($label, $value, $string);
    131204
    132205    for ($i = 0; $i < @field; $i++) {
     206        ($label, $value, $string) = &parse_label ($show[$i]);
     207
    133208        # create the link variable if this entry should be linked
    134         if ($link[$i]) {
     209        if ($label eq "none")  { next; }
     210
     211        if (($label eq "value") && !$link[$i]) {
     212            # print value without link or image
     213            if (! $value) { $value = "\$row[$i]"; }
     214            print FILE "  echo \"<td class=\\\"list\\\"> $value </td>\\n\";\n";
     215            next;
     216        }
     217
     218        if (($label eq "value") && $link[$i]) {
     219            # create the basic link variable
     220            printf FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
     221            # add extra GET data to target
     222            if ($extras[$i]) { &parse_extras ($extras[$i]); }
     223            # print the actual table cell line with the link...
     224            if (! $value) { $value = "\$row[$i]"; }
     225            printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> $value </a></td>\\n\";\n";
     226            next;
     227        }
     228
     229        if (($label eq "image") && !$link[$i]) {
     230            # print the actual table cell line with the image...
     231            printf FILE "  echo \"<td class=\\\"list\\\"><img src=\\\"$value\\\"></td>\\n\";\n";
     232            next;
     233        }
     234
     235        if (($label eq "image") && $link[$i]) {
    135236            # create the basic link
    136             printf FILE "  \$link = \"$link[$i]\" . \"?\" . \$ID['link'];\n";
    137             if ($extras[$i]) {
    138                 # examine the extras and parse the embedded fields
    139                 @extfields = split (/,/, $extras[$i]);
    140                 $N = @extfields;
    141                 if ($VERBOSE) { print STDERR "N extfields: $N\n"; }
    142                 for ($j = 0; $j < @extfields; $j++) {
    143 
    144                     # search for embedded table fields and replace with row[N]
    145                     $N = -1;
    146                     $extline = $extfields[$j];
    147                     if ($VERBOSE) { print STDERR "extfield: $extfields[$j]\n"; }
    148                     for ($k = 0; ($k < @field) && ($N == -1); $k++) {
    149                         if ($extline =~ m|\$$field[$k]|) {
    150                             $extline =~ s|\$$field[$k]||;
    151                             $N = $k;
    152                         }
    153                     }
    154                     if ($N == -1) {
    155                         # no embedded field, print verbatim
    156                         printf FILE "  \$link = \$link . \"&$extline\";\n";
    157                     } else {
    158                         # replace embedded field with row[N]
    159                         printf FILE "  \$link = \$link . \"&$extline\" . \$row[$N];\n";
    160                     }
    161                 }
    162 
    163             }
     237            printf FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
     238            # add extra php data to target
     239            if ($extras[$i]) { &parse_extras ($extras[$i]); }
    164240            # print the actual table cell line with the link...
    165             printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> \$row[$i] </a></td>\\n\";\n";
    166         } else {
    167             # or without
    168             printf FILE "  echo \"<td class=\\\"list\\\"> \$row[$i] </td>\\n\";\n";
     241            printf FILE "  echo \"<td class=\\\"list\\\"><a href=\\\"\$link\\\"> <img src=\\\"$value\\\"> </a></td>\\n\";\n";
     242            next;
    169243        }
    170244    }
     
    174248
    175249    for ($i = 0; $i < @field; $i++) {
     250        if ($show[$i] eq "none")  { next; }
    176251        printf FILE "echo \"<td class=\\\"list\\\"> <input type=\\\"text\\\" name=\\\"$field[$i]\\\"> </td>\\n\";\n";
    177252    }
     
    186261 
    187262    set_keypair ("FIELDS", $FIELDS);
     263}
     264
     265sub parse_extras {
     266    my ($extras) = $_[0];
     267    my (@extfields);
     268    my ($label, $value, $outline);
     269    my ($i);
     270
     271    # examine the extras and parse the embedded fields (comma-separated)
     272    @extfields = split (/,/, $extras);
     273    for ($i = 0; $i < @extfields; $i++) {
     274        ($label, $value, $outline) = &parse_label ($extfields[$i]);
     275        printf FILE "  \$link = \$link . \"&$outline\";\n";
     276    }
     277}
     278
     279# parse strings of the form label=value
     280# if 'value' is of the form $field, try to match with
     281# a supplied DB field, and replace with $row[$n] if found
     282sub parse_label {
     283    my ($string) = $_[0];
     284    my ($label, $value, $outline);
     285    my ($N, $i);
     286
     287    # unless we replace the value with the db row element, return the original string
     288    $outline = $string;
     289    $label = $string;
     290    $value = "";
     291
     292    # search for embedded table fields and replace with row[N]
     293    if ($VERBOSE) { print STDERR "string: $string\n"; }
     294    if ($string =~ m|\S+=\S+|) {
     295        ($label, $value) = $string =~ m|(\S+)=(\S+)|;
     296        if ($value =~ m|^\$|) {
     297          MATCH_LABEL:
     298            for ($i = 0; $i < @field; $i++) {
     299                if ($value =~ m|^\$$field[$i]|) {
     300                    $value = "\$row[$i]";
     301                    last MATCH_LABEL;
     302                }
     303            }
     304            $outline = "$label=$value";
     305        }
     306    }
     307    return ($label, $value, $outline);
    188308}
    189309
Note: See TracChangeset for help on using the changeset viewer.