#!/usr/bin/perl ############################################################################# # # Developer: Al Nguyen # # Description: This program displays a calendar that allows a user # to select a date. The selected date is written to a session cookie # where other programs can access it. The date is in the # format: yyyy-mm-dd. The program should be launched within a # javascript pop-up window. It should be called with the query string # parameters: calendar.pl?dtype=begin&appID=onlineCatalog. The dtype # parameter should be 'begin' or 'end' depending on whether it's a # beginning date to a range or the end date. The appID param can be # any alpha-numeric string identifying the application that will read # the cookie. This parameter allows more than one application to use the # program during a browser session. # ############################################################################# ############################## # Include these libraries. ############################## use strict; use CGI; $CGI::POST_MAX = 1024 * 100; #100K max post $CGI::DISABLE_UPLOADS = 1; use CGI::Carp qw( fatalsToBrowser ); use Data::Dumper; my $VERSION = 0.1; ################################################# # Main function. Point of entry for program. ################################################# main(); sub main { my %form = form2hash(); $form{dtype} = untaint( $form{dtype}, 'begin|end', qq(Invalid date type parameter) ); $form{appID} = untaint( $form{appID}, '\w+', qq(Invalid appID parameter) ) if ! $form{curMonth}; $form{date} = untaint( $form{date}, '\d\d\d\d-\d\d-\d\d', qq(Invalid date parameter) ) if $form{date}; $form{curMonth} = untaint( $form{curMonth}, '\d+', qq(Invalid month parameter) ) if $form{curMonth}; $form{year} = untaint( $form{year}, '\d\d\d\d', qq(Invalid year parameter) ) if $form{year}; my $q = new CGI; if ( ! $q->param('date') ) { ( $q->param('dtype') eq 'begin' ) ? showCalendar( 'begin', 0, $form{curMonth}, $form{appID}, $form{year} ) : showCalendar( 'end', 0, $form{curMonth}, $form{appID}, $form{year} ); } date2cookie( $form{date}, $form{dtype}, $form{appID} ); confDateSelected( $form{date} ); } ########################################################### # Write the date selected to a session cookie. ########################################################### sub date2cookie { my( $date, $type, $appID ) = @_; my $q = new CGI; my $name = ( $type eq 'begin' ) ? "beginDate-$appID" : "endDate-$appID"; my $c = $q->cookie( -name => $name, -value => $date, ); print $q->header( -cookie => $c ); return( 1 ); } ###################################################################### # Read the date cookie to confirm that it was set properly. # This function is useful for debugging. ###################################################################### sub readDateCookie { my( $cookieName ) = @_; my $q = new CGI; my $c = $q->cookie( $cookieName ); return( $c ); } ########################################################### # Show a calendar displaying the current month. ########################################################### sub showCalendar { my( $type, $dont_send_type_flag, $current_month, $appID, $year ) = @_; my( $curYear, $curMonth, $curDay ) = get_system_date(); my $current_date = "$curYear-$curMonth-$curDay"; $current_month = $curMonth if ! $current_month; $current_month =~ s/^0//; $curDay =~ s/^0//; my $whichYear = { '2005' => \&getCalendar2005, '2004' => \&getCalendar2004, '2003' => \&getCalendar2003, }; $year = $curYear if ! $year; my $show4year = $whichYear->{ $year }; my $calendar = $show4year->( $current_month, $type, $appID, $year ); print "Content-type: text/html\n\n" if ! $dont_send_type_flag; my @lines = split( /\n/, $calendar ); foreach ( @lines ) { $_ =~ s/\
$data_as_string