#!/usr/bin/perl ######################################## ##### ##### Ryan's HTML Calendar Maker ##### ##### version 1.0 ##### copyright 2001 ##### ######################################## ################################################ ####################Variables#################### # # $dayoftheweek - The start day. # 0 : Sunday # -1 : Monday # -2 : Tuesday # -3 : Wednesday # -4 : Thursday # -5 : Friday # -6 : Saturday # # $daysinmonth - Number of days in a particular # month. # # $numofweeks - Number of weeks for the # given month. # # $spacing - A number used in determining # the spacing of the entries. # Calculated. # # $monthname - The name of the given month. # # $year - The given year. # ################################################# use CGI; $query = new CGI; print $query->header( ); $chosenmonth = $query->param("month"); $year = $query->param("year"); unless ($chosenmonth >= 1 && $chosenmonth <= 12) { die "Invalid entry.\n"; } $chosenmonth--; @dates = (["January",31],["February",28],["March",31],["April",30],["May",31], ["June",30],["July",31],["August",31],["September",30],["October",31], ["November",30],["December",31]); $monthname = $dates[$chosenmonth][0]; $daysinmonth = $dates[$chosenmonth][1]; unless ($year >= 1500 && $year <= 3999) { die "Invalid entry.\n"; } ############################## # testing for a leap year ############################## if ($chosenmonth == 1) { $daysinmonth = ($year % 400 == 0) ? 29 : ($year % 100 == 0) ? 28 : ($year % 4 == 0) ? 29 : 28; } ################################################### # Calculating the start day using the Claus method ################################################### $dayoftheweek = claus(1,$chosenmonth + 1,$year); # the 1 makes it the 1st day $dayoftheweek = 0 - $dayoftheweek; # the + 1 corrects the earlier subtraction ##################################### # Calculating the number of weeks ##################################### if($dayoftheweek == -6 && ($daysinmonth == 31 || $daysinmonth == 30)) { $numofweeks = 6; } elsif($dayoftheweek == -5 && $daysinmonth == 31) { $numofweeks = 6; } elsif($dayoftheweek == 0 && $daysinmonth == 28) { $numofweeks = 4; } else { $numofweeks = 5; } ######### # Spacer ######### $spacing = 2 * (10 - $numofweeks); ######### # Opener ######### print "
"; print " " x 18; print "" . uc($monthname) . " " . $year . ""; print " " x 18; print " |
Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday |
";
print " " x $spacing; print " $dayoftheweek"; print ""; } else { print " | "; } print " | \n"; } print "