#!/usr/bin/perl ############################################ ## ## ## WebCal ## ## by Darryl Burgdorf ## ## (e-mail burgdorf@awsd.com) ## ## ## ## version: 1.11 ## ## last modified: 1/30/98 ## ## copyright (c) 1998 ## ## ## ## latest version is available from ## ## http://awsd.com/scripts/ ## ## ## ############################################ # COPYRIGHT NOTICE: # # Copyright 1998 Darryl C. Burgdorf. All Rights Reserved. # # This program is being distributed as shareware. It may be used and # modified by anyone, so long as this copyright notice and the header # above remain intact, but any usage should be registered. (See the # program documentation for registration information.) By using this # program you agree to indemnify Darryl C. Burgdorf from any liability. # # Selling the code for this program without prior written consent is # expressly forbidden. Obtain permission before redistributing this # program over the Internet or in any other medium. In all cases # copyright and header must remain intact. # VERSION HISTORY: # # 1.12 08/09/99 Modified for D0 by D. Casey # 1.11 01/30/98 Corrected small problem with some versions of Perl 5 # 1.10 01/29/98 FIRST SHAREWARE RELEASE # Moved configuration variables to separate file # Added configurable table colors # Added "Small Table" option (with or without text) # Stripped "empty" entries from text listing # Allowed for "Monday-Sunday" weeks # Allowed for two-digit year entry (1900s) # Allowed for "date range" entries # Added option to allow HTML in calendar data entries # Limited basic event entries to 80 characters # Added optional "data dir" for more extensive entries # Allowed disabling of user choice of style # Fixed bug that made some entries "undeletable" # 1.00 01/05/98 Initial "public" release require "/www-d0/home/WWW/docs/atwork/general/d0webcal.old/d0webcal.config.pl"; # NOTHING BELOW THIS LINE NEEDS TO BE ALTERED! $DefaultUsed = 0; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $INPUT{$name} = $value; } if (($INPUT{'Year'} < 1601) || ($INPUT{'Year'} > 2899)) { &Header("Date Out of Range!"); print "

Date Out of Range!

\n"; print "

The date you provided is out of range."; print "
It must be between 1601 and 2899 A.D.

\n"; &Footer; exit; } open (DATA,$datafile); @data = ; close (DATA); foreach $line (@data) { if ($line =~ /\n$/) { chop ($line); } ($date,$textstyle,$textcolor,$textsize,$cellColor,$desc,$URL) = split (/\|/, $line); ($dateyear,$datemonth,$dateday) = $date =~ m#(\d\d\d\d)(\d\d)(\d\d)#o; if ((int($dateyear) == int($INPUT{'Year'})) || (int($dateyear) < 1)) { if (int($datemonth) == int($INPUT{'Month'})) { $BgColor_Cell{int($dateday)} = $cellColor; $textdesc = $desc; $textdesc =~ s/<([^>]|\n)*>//g; $Table{int($dateday)} .= "<$textstyle>

"; $SmallTable{int($dateday)} .= ""; if ($URL) { $Table{int($dateday)} .= ""; $Table{int($dateday)} .= "$desc"; $SmallTable{int($dateday)} .= "
"; $SmallTable{int($dateday)} .= "$desc
"; $Text{int($dateday)} .= " "; $Text{int($dateday)} .= ""; $Text{int($dateday)} .= "$textdesc\n"; } else { $Table{int($dateday)} .= "$desc"; $SmallTable{int($dateday)} .= "
$desc"; $Text{int($dateday)} .= " "; $Text{int($dateday)} .= "$textdesc\n"; } } } $SmallTable{int($dateday)} =~ s/^
//; $Text{int($dateday)} =~ s/^ //; } &PerpetualCalendar(int($INPUT{'Month'}),1,int($INPUT{'Year'})); $xmonth = @months[int($INPUT{'Month'})-1]; $heading = "$xmonth $INPUT{'Year'}"; &Header("$heading"); if ($INPUT{'Type'} eq "Text") { print "

$heading

\n"; print "

\n";
	foreach $key (1..$perp_eom) {
		$weekday = ($key+$perp_dow)-(int(($key+$perp_dow)/7)*7);
		if ($weekday < 1) { $weekday = 7; }
		if ($Text{$key}) {
			if ($key < 10) { print "0"; }
			print "$key ";
			$xshortmonth = @shortmonths[$INPUT{'Month'}-1];
			print "$xshortmonth ";
			print "$INPUT{'Year'} ";
			$xshortday = @shortdays[$weekday-1];
			print "($xshortday)   ";
			print "$Text{$key}";
		}
		if (($weekday == 7) && !($key == $perp_eom)) {
			print "\n                    ---------------\n\n";
		}
	}
	print "

\n"; } elsif ($INPUT{'Type'} eq "Table") { print "

\n"; print "\n"; print "\n"; foreach $key (1..7) { print ""; } print "\n\n"; if ($perp_dow > 0) { print ""; } foreach $key (1..$perp_eom) { print ""; $weekday = ($key+$perp_dow)-(int(($key+$perp_dow)/7)*7); if (($weekday == 0) && !($key == $perp_eom)) { print "\n\n"; } } if ($weekday > 0) { $leftover = 7-$weekday; print ""; } print "
"; print ""; print "

$heading

"; print ""; $xday = @days[$key-1]; print "$xday
"; print "

 

"; } else { print "$bgcolor_normal\">"; } if (($INPUT{'Year'} == $year) && ($INPUT{'Month'} == $month) && ($key == $mday)) { print ""; print "

$key"; } else { print ""; print "

$key"; } #print "
($perp_sofar/$perp_togo)"; $perp_sofar++; $perp_togo -= 1; print "
"; if ($Table{$key}) { # # DPC # # print ""; print "$Table{$key}"; # print ""; } else { print "

 "; } print "

"; print "

 

\n"; } else { if ($SmallTableText) { print "

"; print "
\n"; print "

\n"; foreach $key (1..$perp_eom) { next unless ($SmallTable{$key}); print ""; print ""; $color = $BgColor_Cell{int($key)}; print ""; print ""; } print "
"; print ""; $xshortmonth = @shortmonths[$INPUT{'Month'}-1]; print "$key $xshortmonth "; print "$INPUT{'Year'} "; $weekday = ($key+$perp_dow)-(int(($key+$perp_dow)/7)*7); if ($weekday < 1) { $weekday = 7; } $xshortday = @shortdays[$weekday-1]; print "($xshortday):"; print "
"; print ""; print "$SmallTable{$key}

"; print "
\n"; } print "

\n"; print "\n"; print "\n"; foreach $key (1..7) { print ""; } print "\n\n"; if ($perp_dow > 0) { print ""; } foreach $key (1..$perp_eom) { print ""; $weekday = ($key+$perp_dow)-(int(($key+$perp_dow)/7)*7); if (($weekday == 0) && !($key == $perp_eom)) { print "\n\n"; } } if ($weekday > 0) { $leftover = 7-$weekday; print ""; } print "
"; print ""; print "$heading
"; print ""; $xshortday = @shortdays[$key-1]; print "$xshortday
"; print "

 

"; } else { print "$bgcolor_normal\">"; } if (($INPUT{'Year'} == $year) && ($INPUT{'Month'} == $month) && ($key == $mday)) { print ""; print "

$key"; } else { print ""; print "

$key"; } print "

"; print "

 

\n"; } print "

\n"; $LastYear = int($INPUT{'Year'}); $LastMonth = int($INPUT{'Month'})-1; if ($LastMonth == 0) { $LastMonth = 12; $LastYear -= 1; } print "\n"; $NextYear = int($INPUT{'Year'}); $NextMonth = int($INPUT{'Month'})+1; if ($NextMonth == 13) { $NextMonth = 1; $NextYear += 1; } print "\n"; print "
"; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print ""; print ""; print "

\n"; &Footer; exit; sub PerpetualCalendar { # This perpetual calendar routine provides accurate day/date # correspondences for dates from 1601 to 2899 A.D. It is based on # the Gregorian calendar, so be aware that early correspondences # may not always be historically accurate. The Gregorian calendar # was adopted by the Italian states, Portugal and Spain in 1582, # and by the Catholic German states in 1583. However, it was not # adopted by the Protestant German states until 1699, by England # and its colonies until 1752, by Sweden until 1753, by Japan # until 1873, by China until 1912, by the Soviet Union until 1918, # and by Greece until 1923. ($perp_mon,$perp_day,$perp_year) = @_; %day_counts = (1,0,2,31,3,59,4,90,5,120,6,151,7,181, 8,212,9,243,10,273,11,304,12,334); $perp_days = (($perp_year-1601)*365)+(int(($perp_year-1601)/4)); $perp_days += $day_counts{$perp_mon}; $perp_days += $perp_day; $perp_sofar = $day_counts{$perp_mon}; $perp_sofar += $perp_day; $perp_togo = 365-$perp_sofar; if (int(($perp_year-1600)/4) eq (($perp_year-1600)/4)) { $perp_togo++; if ($perp_mon > 2) { $perp_days++; $perp_sofar++; $perp_togo -= 1; } } foreach $key (1700,1800,1900,2100,2200,2300,2500,2600,2700) { if ((($perp_year == $key) && ($perp_mon > 2)) || ($perp_year > $key)) { $perp_days -= 1; } } $perp_dow = $perp_days - (int($perp_days/7)*7); if ($perp_dow == 7) { $perp_dow = 0; } if ($MonSunWeek) { $perp_dow -= 1; if ($perp_dow == -1) { $perp_dow = 6; } } $perp_eom = 31; if (($perp_mon == 4) || ($perp_mon == 6) || ($perp_mon == 9) || ($perp_mon == 11)) { $perp_eom = 30; } if (($perp_mon == 2)) { $perp_eom = 28; } if ((int(($perp_year-1600)/4) eq (($perp_year-1600)/4)) && ($perp_mon == 2)) { $perp_eom = 29; } foreach $key (1700,1800,1900,2100,2200,2300,2500,2600,2700) { if ($perp_year == $key) { if ($perp_mon == 1) { $perp_togo -= 1; } elsif ($perp_mon == 2) { $perp_togo -= 1; $perp_eom = 28; } else { $perp_sofar -= 1; } } } }