>Hi: > >Anyone have a link, or source, for a calendar cgi? A friend of mine has one >he can provide, but it only runs on linux/unix. > I put this code together about two and a half or three years ago. I think I could do it more efficiently if I were to do it today. Nevertheless, it seems to work. David Seay http://www.mastercall.com/g-s/ #!/perl5 use Time::Local; # $htmlTableFormat = "yes"; $htmlTableFormat = "no"; $calendarYear = 100; $monthsToPrint = 12; $startMonth = "January"; $specialDateList = "4/1 - David's Birthday\n7/24 - Debby's Birthday\n"; &specialDateList; &processCalendars; exit(); # ------------------------------------------------------- # -------------------- SUB ROUTINES -------------------- # ------------------------------------------------------- sub specialDateList { @specialDates = split(/\n/,$specialDateList); $b=0; foreach $specialDate (@specialDates) { ($bDate[$b], $bWho[$b]) = split(/ - /, $specialDate); ($bMonth[$b], $bDay[$b]) = split(/\//, $bDate[$b]); ++$b; } $specialDateMonths = @specialDates; $specialDateNames = ""; } sub processCalendars { if ($htmlTableFormat =~ "y") { print "<HTML><HEAD><TITLE>Calendar</TITLE></HEAD><BODY BGCOLOR=\"\#FFFFFF\"><CENTER>"; } $startMonth=index("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", substr($startMonth,0,3)) / 4 + 1; # change to month number $monthsPrinted=0; for ($m = $startMonth;$monthsPrinted<$monthsToPrint;$m++) { $mm = $m; ++$monthsPrinted; while () { if($mm > 12) { $mm -= 12; if($mm == 1) { ++$calendarYear; } } else { last; } } $calendarDate = "$mm/01/$calendarYear"; &createMonthCalendar; } if ($htmlTableFormat =~ "y") { if ($specialDateNames) { print "<HR>"; print "<TABLE BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\" ALIGN=\"CENTER\">\n"; print "<TR><TD ALIGN=\"CENTER\">\n"; print "<FONT SIZE=\"+1\"><B> SPECIAL DATES </B></FONT>\n"; print "</TD></TR><TR><TD ALIGN=\"CENTER\">\n"; print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\" ALIGN=\"CENTER\">\n"; print "$specialDateNames\n"; print "</TABLE>\n"; print "</TD></TR></TABLE>\n"; } print "<BR><A HREF=\"http://www.mastercall.com/calendar.htm\">Calendar Creator</A>\n"; print "</CENTER></BODY></HTML>"; } } sub createMonthCalendar { &firstDayOfMonth; &dateTime; &checkForSpecialDateMonth; &printCalendar; } sub checkForSpecialDateMonth { $monthsSpecialDates = ""; @monthsSpecialDates = ""; for ($b=0;$b<$specialDateMonths;$b++) { if($monthNumber == $bMonth[$b]) { $monthsSpecialDates[$bDay[$b]] = $bWho[$b] } } } sub firstDayOfMonth { if ($calendarDate =~ m|^(\d+)/(\d+)/(\d+)$|) { ($month, $day, $year) = ($1, $2, $3); $month -= 1; if ($year > 1900) { $year -= 1900 } $chosenSecs = timelocal (0,0,0, $day, $month, $year); # in Time::Local $xxx = localtime($chosenSecs); $xxx =~s/ / /g; ($firstDay, $mon, $dayMon, $militaryTime, $yr) =split (/ /,$xxx); } else { print " [Error in date format] "; exit(1); } } sub dateTime { $monthNumber=index("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", $mon) / 4 + 1; # MONTH NUMBER @months=("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $month = $months[$monthNumber - 1]; if($yr % 4 == 0) { # ADJUST FEBRUARY'S DAYS FOR LEAP YEAR $monthDays=substr("31 29 31 30 31 30 31 31 30 31 30 31",$monthNumber * 3 - 3,2); } else { $monthDays=substr("31 28 31 30 31 30 31 31 30 31 30 31",$monthNumber * 3 - 3,2); } @days=("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); } sub printCalendar { $heading = "$month $yr"; if ($htmlTableFormat =~ "y") { # PRINT HEADING AND THE DAYS (NAMES) OF THE WEEK print "<A name=\"$month $yr\"></A>\n"; print "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"0\">\n"; print "<tr><th COLSPAN=\"7\" BGCOLOR=\"\#FFFF00\"><FONT SIZE=\"+1\" COLOR=\"\#0000FF\"><B>$heading</B></FONT></th></tr>\n"; print "<tr><th ALIGN=Center>Sun</th><th ALIGN=Center>Mon</th><th ALIGN=Center>Tue</th><th ALIGN=Center>Wed</th><th ALIGN=Center>Thu</th><th ALIGN=Center>Fri</th><th ALIGN=Center>Sat</th></tr>\n"; print "<tr>"; } else { # ----- CENTER HEADING ----- # $indentNum=(28-length($heading))/2; if((28-length($heading)) % 2 eq 0) { $indentNum -= 1 } $indentSpaces=substr(" ",0,$indentNum); # -------------------------- # print "$indentSpaces $month $yr\n"; print " Sun Mon Tue Wed Thu Fri Sat\n"; } $daysInWk=0; for ($dd=0;$dd<=6;$dd++) { # FILL OUT THE BLANK DAYS OF THE FIRST WEEK OF THE MONTH if($days[$dd] =~ /$firstDay/) { last; } else { if ($htmlTableFormat =~ "y") { print "<td> </td>\n" } else { print" " } ++$daysInWk; } } for ($dd = 1;$dd <= $monthDays;$dd++) { # PRINT THE DAYS (NUMBERS) OF THE MONTH if ($htmlTableFormat =~ "y") { if ($monthsSpecialDates[$dd]) { # SPECIALDATE MATCH print"<td BGCOLOR=\"\#00FFFF\" ALIGN=Center>"; print"<A href=\"\#$monthsSpecialDates[$dd]\">$dd</A></td>\n"; $specialDateNames .= "<TR><TD VALIGN=Top ALIGN=Right><A name=\"$monthsSpecialDates[$dd]\"></A>"; $specialDateNames .= "<A href=\"\#$month $yr\">$month $dd</A> \-</TD>"; $specialDateNames .= "<TD>$monthsSpecialDates[$dd]</TD></TR>\n"; } else { print"<td ALIGN=Center>$dd</td>\n"; } } else { if($dd<10) { print" $dd" } else { print" $dd" } } ++$daysInWk; if($daysInWk > 6 && $dd != $monthDays) { if ($htmlTableFormat =~ "y") { print "</tr>\n<tr>" } else { print"\n" } $daysInWk=0; } } if ($htmlTableFormat =~ "y") { # FILL OUT THE BLANK DAYS OF THE LAST WEEK OF THE MONTH if ($daysInWk < 7) { for ($dd = $daysInWk;$dd<7;$dd++) { print "<td> </td>\n"; } } print "</tr>\n</table><BR>"; } print"\n\n\n"; } ==== Want to unsubscribe from this list? ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org