#!/usr/bin/perl -w
# use strict;
use diagnostics;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
# constants
@months = ("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
"December");
# globals
%events = (); # Create has to keep events sorted by date
$q = new CGI; # Create an instance of CGI
sub PrintMonth{
my $mo = shift();
my $yr = shift();
print "
\n";
print "\n";
print "\t\n";
print "\t\t| ";
if ($mo > 1){
printf "",$q->url(),$mo-1,$yr;
print "<";
}else{
printf "",$q->url(),$yr-1;
print "< ";
}
print " | \n";
print "\t\t $months[$mo-1] $yr | \n";
print "\t\t ";
if ($mo < 12){
printf "",$q->url(),$mo+1,$yr;
print ">";
}else{
printf "",$q->url(),$yr+1;
print "> ";
}
print " | \n\t
\n";
my @cal = `cal $mo $yr`;
shift(@cal);
while(@cal){
print "\t\n";
$line = shift(@cal);
foreach $i (0..6) {
unless (length($line) - $i*3 < 2){
$day = substr($line,$i*3,2);
$idxday = $day; # Build hash index from date
$idxday =~ tr/ /0/;
$idxday = $mo.$idxday.$yr;
print "\t\t| ";
if (exists($events{$idxday})){
print "";
print "$day";
}else{
print $day;
}
print " | \n";
}
}
print "\t
\n";
}
print "\n";
print "
\n";
}
# Read events file:
sub ReadFile{
my $fname = shift();
open(EVENTS,$fname) or die "can't open events file";
while (){
chop;
my ($date,$url) = split('\^');
$events{$date+0}=$url; #get rid of the eventual 0
}
}
# Send an appropriate MIME header
print $q->header(-type => "text/html");
# Send some content
print $q->start_html(-title => "Calendar Script",
-bgcolor => "#3d663d");
ReadFile('events.txt');
my ($yr,$mo) = (0,0); #get rid of stupid perl warning
if($q->param()){
($mo,$yr) = ($q->param('mo'),$yr = $q->param('yr'));
}else{
@dateinfo = localtime;
($mo,$yr) = ($dateinfo[4]+1,$dateinfo[5]+1900);
}
PrintMonth($mo,$yr);
print $q->end_html;