#!/usr/bin/perl $CGI=$ENV{'SCRIPT_NAME'}; sub ReadParse { local (*in) = @_ if @_; local ($i, $loc, $key, $val); if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); } @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key} .= "\0" if (defined($in{$key})); $in{$key} .= $val; } return 1;} sub Footer { print <

Table Generator was written by Matt Kruse (mkruse@saunix.sau.edu). It is free software as long as this footer is maintained in the script. Distribute and modify as you wish. Written in Perl 4.036 and tested using Netscape version 1.1. Comments and suggestions welcome.


EOF } &ReadParse; print "Content-type: text/html\n\n"; $COMMAND=$in{'COMMAND'}; # --------------------- # Output Opening Screen # --------------------- if ($COMMAND eq '') { print < Table Generator

Table

Generator

By Matt Kruse 6/29/95 -- Version 1.1


Welcome to Table Generator, an easy-to-use utility that will make basic tables quickly and easily. You must have a view that is capable of displaying HTML 3.0-compliant tables, like Netscape. Not all features of tables are supported in this program, so some manual editing may be needed if you wish to create complex tables.

Enter the dimensions of the table you wish to create:

Width:
Height:

Default alignment of cells will be:
Left Center Right

EOF &Footer; } # --------------------------------- # Create the table with input areas # --------------------------------- if ($COMMAND eq 'MAKEFORM') { #create an entry form $WIDTH=$in{'WIDTH'}; $HEIGHT=$in{'HEIGHT'}; if ($in{'DEFAULTALIGN'} eq 'LEFT') {$LEFT="CHECKED";} if ($in{'DEFAULTALIGN'} eq 'CENTER') {$CENTER="CHECKED";} if ($in{'DEFAULTALIGN'} eq 'RIGHT') {$RIGHT="CHECKED";} print < Table Entry Form

Table Entry Form

Use the entry areas below to put data into your table that you wish to create.

Use the radio buttons under the cell to change the alignment of the specific cells to Left, Center, or Right. By making a certain row or column a "Header" rather than "Data", it will be be bold by default.

The checkboxes between cells allow you to make data or header cells that span more than one column. By clicking on the checkbox between two cells, they become one cell. The data entered in the left cell is what will be entered in the larger cell, and anything in the right cell will be ignored. You may make any cell as large as you wish. For example, if you connect all the boxes, the data in the left-most cell will take up a whole row, and no other data will appear.

Border Type: Add the "Width=100%" tag to the Table.
Caption: Top Bottom Bold
(If Caption is left empty, no caption will be in the table output)

EOF #output top row headers print "\n"; print " \n"; for ($i=1;$i<=$WIDTH;$i++) { print " \n"; if ($i != $WIDTH) {print " \n";} } print "\n\n"; print "\n"; print " \n"; for ($i=1;$i<=$WIDTH;$i++) { print < Header
Data EOF if ($i != $WIDTH) {print "
\n";} } print "\n\n"; #create all entry areas for ($row=1;$row<=$HEIGHT;$row++) { print < EOF for ($col=1;$col<=$WIDTH;$col++) { print <
EOF if ($col != $WIDTH) {print <
<-> EOF } } #end of columns print "
\n"; } #end of rows print <

EOF &Footer; } # -------------------------------------- # Output the table and table source code # -------------------------------------- if ($COMMAND eq 'MAKETABLE') { $WIDTH=$in{'WIDTH'}; $HEIGHT=$in{'HEIGHT'}; $CAPTION=$in{'CAPTION'}; $CAPTIONALIGN=$in{'CAPTIONALIGN'}; $CAPTIONBOLD=$in{'CAPTIONBOLD'}; $BORDER=$in{'BORDER'}; if ($BORDER eq 'NONE') {$BORDER='';} if ($in{'WIDTH100'}) { $WIDTH100="WIDTH=100%"; } print < Table Output

Table Output

View the source of this page to see the code for this table. You can then save it to a file, or copy and paste it into the document you wish to use this with.


Sample Table:

Column $i
Row/Col Type
Header
Data
EOF if ($CAPTION) {print "\n"; } for ($row=1;$row<=$HEIGHT;$row++) { print "\n"; for ($col=1;$col<=$WIDTH;$col++) { if (($in{"ROWTYPE$row"} eq 'TH' ) || ($in{"COLTYPE$col"} eq 'TH' )) {$TYPE='TH';} else {$TYPE='TD';} $LINK="R${row}C${col-1}LINK"; if ($in{$LINK} eq '1') {next;} $COLSPAN=1; for ($i=$col;$i<=$WIDTH;$i++) { $LINK="R${row}C${i}LINK"; if ($in{$LINK} ne '1') {last;} if ($in{$LINK} eq '1') {$COLSPAN++;} } $POSITION="R${row}C${col}"; $ALIGN="${POSITION}ALIGN"; print "<${TYPE} ALIGN=$in{$ALIGN} COLSPAN=$COLSPAN>$in{$POSITION}\n"; } #end of columns print "\n"; } #end of rows print "
\n"; if ($CAPTIONBOLD) {print "";} print "$CAPTION"; if ($CAPTIONBOLD) {print "";} print "\n
\n"; print "\n"; print "

\n"; print < EOF &Footer; }