#!/usr/bin/perl ###################################################################### # Programmer: Al Nguyen # # At the command prompt do "perldoc [name of this program] to see # user documentation. ###################################################################### ############################## # 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 = 1.0.2; ################################################# # Main function. Main logic of 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