#!/usr/bin/perl -w # interests.pl # produce several HTML tables: # 1.) all BRBC members # 2.) membership types # 3.) member interest by category # 4.) grand prix series # author: gregory c. wilcox # date: 3/14/2003 # note: use double quote with escape characters, such as \n # use single quote with HTML tags that contain single quotes, such as HREF #paths to csv data files # $path_to_csv="/www"; use warnings; use strict; use Text::ParseWords; use CGI::Carp qw(fatalsToBrowser); sub member; my $headingp = 1; # is this line the heading? my $email = 5; # email column of table my $category = 0; # category to build table for my $head; # table heading my $file = "members.csv"; # database name my $members = 0; # number of members my $data = 1; # database field comparison value -- normally 1 my $line; # one line of the database my @fields; # fields in one line my $input; # input value my @inputs; # all input values my $types; # string of all membership types to match my $typenames = ""; # list of the names for each type my $debug = 0; # set to 1 for debugging # column headings of member database my @heading = ( "Last Name", "First Name", "City", "State", "Types: ", "Email Address", "Occupation", "Road Rides", "Adopt-a-Lane", "Mountain Bike", "Trail Maintenance", "Direct Road Rides", "Advocacy", "Direct Mountain Rides", "Volunteer", "Assault on the Carolinas", "WesTrek??", "Hilly Hellacious Volunteer", "Tobacco Free for Life", "The Beat Goes On", "YMCA Tour de Leaves", ); # HTML header my @header = ( "Content-type: text/html\n", # must have two carriage returns '
', '© Blue Ridge Bicycle Club Inc. 2003', '', ); # main program begins here my $query = $ENV{'QUERY_STRING'}; # print 'Query string=', $query, "\n"; unless ( $query ) { $query = "19&G"; } split_query($query); $category = int($inputs[0]); $types = $inputs[1]; # for category 'type', use type data if ($category == 4) { $data = $types; make_typenames($types); } # double duty for types: A = all members; G = Grand Prix if ($types =~ /A/) { $head = "All Members"; } elsif ($types =~ /G/) { $head = "Grand Prix Series"; } else { $head = $heading[$category].$typenames; } open(FILE, $file) or die "can't open $file: $!"; output_strings(@header); print '
Number of members: $members \n";
output_strings(@footer);
close(FILE);
# end of main program
# output strings
sub output_strings
{
foreach (@_) { print; print "\n"; }
}
# make a list of type names
sub make_typenames
{
$typenames .= "Individual " if $types =~ /I/;
$typenames .= "Family " if $types =~ /F/;
$typenames .= "Relative " if $types =~ /R/;
}
# split the query into input values
# input 0 = category
# input 1 = types
# no keys used here
sub split_query
{
my $index = 0;
foreach $input (split("&",$query))
{
if ($debug) { print "Input($index) = [$input]
\n"; }
$inputs[$index++] = $input;
}
}
# output one entry in the table
sub entry
{
my $i = shift;
my $str = $fields[$i];
# print $heading[$i], ' = "', $str, "\"\n";
print '