#!/usr/local/bin/perl # File: calendar3.pl $CAL = '/usr/bin/cal'; @years=(1990..2010); %query = &get_query; # # Set the year to the query, otherwise the current year if ($query{'year'}) { $year = $query{'year'}; } else { chop($year=`date +%Y`); } # Print the header and the top of the document print <Calendar

Calendar for $year

END ; # ------------------- CREATE THE FILL-OUT FORM ------------------- # Print the popup menu for the year. print '
',"\n"; print "YEAR: \n"; # Print the checkbox for Julian calendar. $checked = 'CHECKED' if $query{'julian'}; print qq/Julian\n/; # Submit button print '

'; print "


\n"; # ------------------- PRINT THE CALENDAR ------------------- unless ($year=~/^\d{4}$/) { print "ERRORYear must be exactly four digits\n"; exit 0; } $extra_switches = '-j' if $query{'julian'}; chop($calendar_text=`$CAL $extra_switches $year`); print < $calendar_text
Welcome Page END ; # ------------------ QUERY PARSING ROUTINE HERE ------------ sub get_query { local($query_string); local(@lines); local($method)=$ENV{'REQUEST_METHOD'}; # If method is GET fetch the query from # the environment. if ($method eq 'GET') { $query_string = $ENV{'QUERY_STRING'}; # If the method is POST, fetch the query from standard in } elsif ($method eq 'POST') { read(STDIN,$query_string,$ENV{'CONTENT_LENGTH'}); } # No data. Return an empty array. return () unless $query_string; # We now have the query string. # Call parse_params() to split it into key/value pairs return &parse_params($query_string); } sub parse_params { local($tosplit) = @_; local(@pairs) = split('&',$tosplit); local($param,$value,%parameters); foreach (@pairs) { ($param,$value) = split('='); $param = &unescape($param); $value = &unescape($value); if ($parameters{$param}) { $parameters{$param} .= "$;$value"; } else { $parameters{$param} = $value; } } return %parameters; } sub unescape { local($todecode) = @_; $todecode =~ tr/+/ /; # pluses become spaces $todecode =~ s/%([0-9A-Fa-f]{2})/pack("c",hex($1))/ge; return $todecode; }