#!/usr/local/bin/perl print "Content-type: text/html\n\n"; use lib "/home/scsfac/downeyt/public/scripts"; use CGILib; use DB_File; my %query = get_query(); use constant DB_PATH => "/home/scsfac/downeyt/notes/"; my @monthArr = qw(January February March April May June July August September October November December); my %monthArr = qw(january 0 ffebruary 1 march 2 april 3 may 4 june 5 july 6 august 7 september 8 october 9 november 10 december 11); my %selected; $selected{$query{class}} = "selected"; $selected{$query{month}} = "selected"; $selected{$query{day}} = "selected"; $selected{$query{year}} = "selected"; print < Show Class Notes
Class: Month: Day:
 
HTML ; $showClass = $defaultClass; if ($query{class}) { $showClass = $query{class}; } if ($showClass) { print_cal($showClass); } print <
HTML ; print_comment(); print <
HTML ; sub print_comment { if ($query{class}) { print "
"; my %hash; my $db = tie %hash, "DB_File", DB_PATH."$query{class}.db", O_RDWR or die "Could not open notes.db: $!"; my $fd = $db->fd; open DBM, "+<&$fd" or die "Could not dup DBM: $!"; flock DBM, LOCK_EX; undef $db; ($course, $section, $semester, $year) = split "[.]",$query{class}; print "

$course Section $section $semester $year, $query{month} $query{day}

\n"; my $key = "$query{month}.$query{day}"; if (exists($hash{$key})) { ($heading,$content) = split ("$;",$hash{$key}); print "

$heading

\n"; print "
$content
\n"; } else { print "

No notes for this date

\n"; } untie %hash; } } sub print_cal { ($courseName) = @_; chomp $courseName; my %hash = (); my $db = tie %hash, "DB_File", DB_PATH."$courseName.db", O_CREAT | O_RDWR or die "Could not open DB_PATH.$courseName.db: $!"; my $fd = $db->fd; open DBM, "+<&$fd" or die "Could not dup DBM: $!"; flock DBM, LOCK_EX; undef $db; %calMonth=(); foreach $date (sort sort_by_month_day keys %hash) { ($month, $day) = split(/\./,$date); $calMonth{$month} .= ":$day"; } print "\n"; print "\n"; $align = 0; foreach $month (sort sort_by_month keys %calMonth) { print "\n"; @day = split (/:/,$calMonth{$month}); shift @day; sort {$a <=> $b} @day; $pos = 0; foreach (@day) { if ($pos%2 == 0) { print ""; } $pos++; if ($align) { print "\n"; $align =0; $pos++; } print "\n"; if ($pos%2 == 0) { print ""; } } $align = ($pos%2 != 0); } print "
$courseName
$month
 \n"; print ""; print "$_
"; } sub sort_by_month_day { my ($montha, $daya) = split(/\./,$a); my ($monthb, $dayb) = split(/\./,$b); $montha cmp $monthb || $daya <=> $dayb; } sub sort_by_month { $monthArr{lc $a} <=> $monthArr{lc $b}; }