#!/usr/local/bin/perl #File:calendar4.pl use CGI; $CAL='/usr/bin/cal'; $query = new CGI; print $query->header; # We use the path information to distinguish between calls # to the script to: # (1) create the frameset # (2) create the query form # (3) create the query response $path_info = $query->path_info; # If no path information is provided, then we create # a top-to-bottom frame set if (!$path_info) { &print_frameset($query); exit 0; } # If we get here, then we're either going to be creating the fill-out # form or the calendar. The path information tells us which it's to be. # In either case, we need to retrieve the current year from the query. unless ($query->param('year')) { # if date is missing, then fill it in chop($year=`/bin/date +%Y`); $query->param(-name=>'year',-value=>$year); } print $query->start_html('Calendar'); &print_query($query) if $path_info=~/query/; &print_response($query) if $path_info=~/response/; print $query->end_html; exit 0; # ------------------- PRINT THE FRAMESET ------------------- sub print_frameset { my($query) = @_; my($name) = $query->script_name; print <Calendar 5 END ; } # ------------------- CREATE THE FILL-OUT FORM ------------------- sub print_query { my($query) = @_; my(@years)=(1990..2010); print "

Settings

\n"; my($name) = $query->script_name; print # start the form $query->start_form(-action=>"$name/response", -target=>"response"), # Print the popup menu for the year. "YEAR: ",$query->popup_menu(-name=>'year', -values=>\@years), # Print the checkbox for Julian calendar. $query->checkbox(-name=>'julian'), # Submit button $query->submit(-label=>'Make Calendar'); # end the form print $query->end_form; } # ------------------- PRINT THE CALENDAR ------------------- sub print_response { my($query) = @_; my($year) = $query->param('year'); unless ($year=~/^\d{4}$/) { print "ERROR: Year '$year' must be exactly four digits.\n"; return; } my($extra_switches) = '-j' if $query->param('julian'); my($calendar_text); chop($calendar_text=`$CAL $extra_switches $year`); print <Calendar for Year $year
$calendar_text

Welcome Page END ; }