#!/usr/bin/perl ############################################ ## ## ## WebCal (Addition Script) ## ## by Darryl Burgdorf ## ## (e-mail burgdorf@awsd.com) ## ## ## ## version: 1.21 ## ## last modified: 1/4/00 ## ## copyright (c) 2000 ## ## ## ## latest version is available from ## ## http://awsd.com/scripts/ ## ## ## ############################################ require "webcal.config.pl"; # NOTHING BELOW THIS LINE NEEDS TO BE ALTERED! 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; } unless (-w "$DataDirPath") { $DataDirPath = ""; } if ($INPUT{'Add'}) { &Add; } else { &Display; } sub Display { &Header("Add Calendar Entry"); print "

Add New Calendar Entry:

\n"; print "
\n"; $datafiles = (keys %editfiles); if ($datafiles > 1) { print "

Data File to Edit: \n"; } else { foreach $key (keys %editfiles) { print "\n"; } } print "

Input the date of the event below."; print "
Use a year designation of "x" "; print "for an annual (every year) event."; print "
Two-digit year entries will be understood "; print "
to lie between 1950 and 2049 A.D.
\n"; print "

Month: "; print "Date: "; print " "; print "Year: "; print "\n"; if ($AllowMultiDate) { print "

If you wish an event to appear "; print "on a series of dates,
"; print "enter the ending date below.
\n"; print "

End Month: "; print " "; print "End Date: "; print " "; print "End Year: "; print "\n"; print "

Instead of specifying a straight series "; print "of dates above,
you may specify a certain day "; print "(e.g., "Second Tuesday")
of each of a "; print "series of months.
"; print "

Day: "; print " \n"; print " "; print "

First Month: "; print " "; print "Year: "; print " "; print "Last Month: "; print " "; print "Year: "; print "\n"; } print "

Input a brief description (or title) "; print "of the event below.
You may also include a URL "; print "(Web page address)
if you wish to link to "; print "a page with more detailed information.
\n"; if ($AllowHTML) { print "
(HTML tags may be included in the event "; print "description.
However, if you use them, "; print "please include any URL in the "; print "description
instead of inputting it in the "; print "separate URL box. Thanks!)
\n"; } print "

Event: "; print "\n"; print "

URL (optional): "; print "\n"; if ($DataDirPath && $DataDirURL) { print "

If you have no URL, but want "; print "to include more information, enter it "; print "here.
A document will be created "; print "for you, to which the entry will "; print "link.
\n"; if ($AllowHTML) { print "
(Again, you are welcome "; print "to include HTML tags here.)\n"; } print "

Detailed Information:\n"; print "
\n"; } print "

\n"; print "

\n"; &Footer; exit; } sub Add { unless ((($INPUT{'RangeNumber'} && $INPUT{'RangeDay'} && $INPUT{'FirstMonth'} && $INPUT{'LastMonth'}) || ($INPUT{'StartMonth'} && $INPUT{'StartDate'})) && $INPUT{'Add'} && $INPUT{'datafile'}) { &Header("Incomplete Submission"); print "

Incomplete Submission!

\n"; print "

You didn't include enough information!\n"; print "

(Use your browser's "; print ""Back" button
or just reload "; print "this page to try again!)
\n"; &Footer; exit; } $INPUT{'Add'} =~ s/|//g; $INPUT{'Add'} =~ s/\n//g; if ($AllowHTML) { $INPUT{'Add'} =~ s///g; } else { $INPUT{'Add'} =~ s/<([^>])*>//g; $INPUT{'Add'} =~ s///g; } $INPUT{'URL'} =~ s/\s//g; unless ($INPUT{'URL'} =~ /\*|(\.\.)|(^\.)|(\/\/\.)/ || $INPUT{'URL'} !~ /.*\:\/\/.*\..*/) { $URL = "$INPUT{'URL'}"; } if ($INPUT{'FullText'} && !($URL)) { $time = time; $URL = "$DataDirURL/$time.html"; } if ($INPUT{'RangeNumber'} && $INPUT{'RangeDay'} && $INPUT{'FirstMonth'} && $INPUT{'LastMonth'}) { $Year = $INPUT{'FirstYear'}; $Date = 1; $Month = int($INPUT{'FirstMonth'}); if ($Year =~ /\D/) { $Year = 0; } elsif ($Year < 50) { $Year += 2000; } elsif ($Year < 100) { $Year += 1900; } $EndYear = $INPUT{'LastYear'}; $EndDate = 1; $EndMonth = int($INPUT{'LastMonth'})+1; if ($EndMonth == 13) { $EndMonth = 1; $EndYear += 1; } if ($EndYear =~ /\D/) { $EndYear = 0; } elsif ($EndYear < 50) { $EndYear += 2000; } elsif ($EndYear < 100) { $EndYear += 1900; } if (($Year < 1601) || ($Year > 2899) || ($EndYear < 1601) || ($EndYear > 2899)) { &Error_OutOfRange; } &PerpCal($Month,$Date,$Year); $StartDay = $perp_days; &PerpCal($EndMonth,$EndDate,$EndYear); $EndDay = $perp_days-1; if (($EndDay <= $StartDay) || (($EndDay-$StartDay)>3700)) { &Header("Invalid Date Range"); print "

Invalid Date Range!

\n"; print "

Either your start date comes "; print "after your end date,
or the range specified "; print "is too wide.
"; print "("Once a month" entries can span "; print "up to 10 years.)\n"; print "

(Use your browser's "; print ""Back" button
or just reload "; print "this page to try again!)
\n"; &Footer; exit; } } else { $Year = $INPUT{'StartYear'}; $Date = int($INPUT{'StartDate'}); $Month = int($INPUT{'StartMonth'}); if (($Year == 0) && ($Year =~ /\D/)) { $Year = 0; $NewEntry = "0000"; } elsif ($Year < 0) { $Year = 1; } elsif ($Year < 50) { $Year += 2000; $NewEntry = $Year; } elsif ($Year < 100) { $Year += 1900; $NewEntry = $Year; } else { $NewEntry = $Year; } if (($Year != 0) && (($Year < 1601) || ($Year > 2899))) { &Error_OutOfRange; } if ($Month < 10) { $NewEntry .= "0"; } $NewEntry .= "$Month"; if ($Date < 10) { $NewEntry .= "0"; } $NewEntry .= "$Date|$INPUT{'Add'}|$URL\n"; if ($INPUT{'EndMonth'} && $INPUT{'EndDate'} && ($Year > 0)) { $EndYear = $INPUT{'EndYear'}; $EndDate = int($INPUT{'EndDate'}); $EndMonth = int($INPUT{'EndMonth'}); if ($EndYear =~ /\D/) { $EndYear = 0; } elsif ($EndYear < 50) { $EndYear += 2000; } elsif ($EndYear < 100) { $EndYear += 1900; } if (($EndYear < 1601) || ($EndYear > 2899)) { &Error_OutOfRange; } &PerpCal($Month,$Date,$Year); $StartDay = $perp_days; &PerpCal($EndMonth,$EndDate,$EndYear); $EndDay = $perp_days; if (($EndDay <= $StartDay) || (($EndDay-$StartDay)>92)) { &Header("Invalid Date Range"); print "

Invalid Date Range!

\n"; print "

Either your start date comes "; print "after your end date,
or the range specified "; print "is too wide.
"; print "(Daily entries can span "; print "up to three months.)\n"; print "

(Use your browser's "; print ""Back" button
or just reload "; print "this page to try again!)
\n"; &Footer; exit; } } } if ($EndDay > 0) { foreach $date ($StartDay..$EndDay) { &PerpCalRev($date); if ($perp_day == 1) { for $key (0..6) { $dow[$key] = 0; } } $perp_dow = $date - (int($date/7)*7); if ($perp_dow == 7) { $perp_dow = 0; } if ($MonSunWeek) { $perp_dow -= 1; if ($perp_dow == -1) { $perp_dow = 6; } } $dow[$perp_dow] += 1; if ($INPUT{'RangeNumber'} && $INPUT{'RangeDay'}) { next unless (($INPUT{'RangeNumber'} == 5) || ($INPUT{'RangeNumber'} == $dow[$perp_dow])); next unless ($INPUT{'RangeDay'} == ($perp_dow+1)); if ($DateSet) { $DateSet .= "
"; } $DateSet .= "$perp_day "; $DateSet .= "$shortmonths[$perp_mon-1] $perp_year"; } $NextEntry = $perp_year; if ($perp_mon < 10) { $NextEntry .= "0"; } $NextEntry .= "$perp_mon"; if ($perp_day < 10) { $NextEntry .= "0"; } $NextEntry .= "$perp_day|$INPUT{'Add'}|$URL\n"; &AddEntry($NextEntry); } } else { &AddEntry($NewEntry); } if ($INPUT{'FullText'}) { if ($AllowHTML) { $INPUT{'FullText'} =~ s// /g; } else { $INPUT{'FullText'} =~ s/<([^>]|\n)*>/ /g; $INPUT{'FullText'} =~ s/\&/\&\;/g; $INPUT{'FullText'} =~ s/"/\"\;/g; $INPUT{'FullText'} =~ s//\>\;/g; } $INPUT{'FullText'} =~ s/\cM\n*/\n/g; $INPUT{'FullText'} =~ s/\n/
/g; $INPUT{'FullText'} =~ s/
\s\s\s+/

/g; $INPUT{'FullText'} =~ s/
\t/

/g; $INPUT{'FullText'} =~ s/\s+/ /g; $INPUT{'FullText'} =~ s/
\s/
/g; $INPUT{'FullText'} =~ s/\s
/
/g; $INPUT{'FullText'} =~ s/

/

/g; $INPUT{'FullText'} =~ s/


/

/g; $INPUT{'FullText'} =~ s/\s+/ /g; $INPUT{'FullText'} =~ s/^\s+//g; $INPUT{'FullText'} =~ s/\s+$//g; $INPUT{'FullText'} =~ s/

/\n

/g; $INPUT{'FullText'} =~ s/
/\n
/g; $INPUT{'FullText'} =~ s/

\n//g; $INPUT{'FullText'} =~ s/
\n//g; open (DATA,">$DataDirPath/$time.html"); print DATA ""; print DATA "$INPUT{'Add'}\n"; print DATA "\n"; if ($DataDir_header) { open (HEADER,"$DataDir_header"); @header =

; close (HEADER); foreach $line (@header) { print DATA"$line"; } } print DATA "

$INPUT{'Add'}

\n"; print DATA "

"; if ($DateSet) { print DATA "$DateSet"; } else { print DATA "$Date $shortmonths[$Month-1] "; if ($Year == 0) { print DATA "Annually"; } else { print DATA "$Year"; } if ($EndDay) { print DATA " - $EndDate "; print DATA "$shortmonths[$EndMonth-1] $EndYear"; } } print DATA "\n"; print DATA "

$INPUT{'FullText'}\n"; if ($DataDir_footer) { open (FOOTER,"$DataDir_footer"); @footer =