#!/usr/bin/perl -Tw use strict; use CGI; # Set PATH to cal ######################### $ENV{'PATH'} = '/usr/bin'; # The directory to store entries for dates ######################### my $date_dir = "dates/"; my $cgi = new CGI; my $cal_prog = '/usr/bin/cal'; # A style sheet ######################### my $cal_style= <<"EOT"; EOT # Colors for the backgrounds ########################## my $month_bg_color='#ff0000'; my $week_bg_color='#0000ff'; my $date_bg_color='#e0e0e0'; my $year = 2000; my $num_of_months = 12; # The number of months shown per row ########################## my $months_per_row = 3; print $cgi->header(), $cgi->start_html( -title=>'Calendar', -BGCOLOR=>'#ffffff', -style=>{-code=>$cal_style} ); print $cgi->h1('Calendar for the year '. $year); print ''; # A table for all months ############################ my $row_count = 1; for(;$row_count <= $num_of_months ; $row_count++){ open(CAL,"$cal_prog -m $row_count $year |") || die "Cannot open CAL: $!\n"; my @month = ; close(CAL); print ''; if($row_count % $months_per_row == 0){ print ''; } } print '
'; my $month_name = splice(@month,0,1); $month_name =~ s/^\s+(\w+) \d+$/$1/g; my $days = splice(@month,0,1); # A table for each of the months ################################### print '', '', ''; # Mo Tu We Th Fr Sa Su ############################### my @day_names = split(" ",$days); foreach(@day_names){ print ''; } # Start spitting out the dates ############################### foreach(@month){ s/[^\d] /\-\- /g; s/ (\d)( |\n)/0$1$2/g; print ''; my @dates = split(/ /g, $_); foreach(@dates){ unless(/^--/){ s/\n$//; chomp($month_name); my $date_file = $date_dir . $month_name . $_; my @date_stats = stat($date_file); # Check for entries per date, if any highlight it ################################################# if( -e $date_file && $date_stats[7] > 0){ print ''; } else{ print ''; } } print ''; } print '
', $cgi->h3($month_name), '
',$_,'
',$_; } else{ print '',$_; } print ' --
'; print '
'; print $cgi->end_html;