1: #!/usr/bin/perl
2:
3: # I wanted something VERY SIMPLE for generating an
4: # HTML calendar. I didn't want to wade through the interface
5: # for HTML::Calendar::Simple, or worry about Entities.
6:
7: # This script looks at the time, backtracks to the first of
8: # the month, and then prints out an HTML calendar for this
9: # month. You can manipulate the month being printed by fiddling
10: # with the $now variable and you can put information into the
11: # calendar easily where commented.
12:
13: # Oakbox Productions - Richard Still (oakbox)
14:
15: use strict;
16:
17: my $message; # variable to hold output
18:
19: my $now = time;
20:
21: my @wday = localtime($now);
22:
23: my %dayrev = ( "0" => "Sun",
24: "1" => "Mon",
25: "2" => "Tue",
26: "3" => "Wed",
27: "4" => "Thu",
28: "5" => "Fri",
29: "6" => "Sat");
30:
31: my %monrev = ( "0" => "Jan",
32: "1" => "Feb",
33: "2" => "Mar",
34: "3" => "Apr",
35: "4" => "May",
36: "5" => "Jun",
37: "6" => "Jul",
38: "7" => "Aug",
39: "8" => "Sep",
40: "9" => "Oct",
41: "10" => "Nov",
42: "11" => "Dec");
43:
44:
45: use Time::Local;
46:
47: $message.=qq(<span class="big"> $monrev{$wday[4]} </span>
48: <br> <table border="1" cellspacing="0" cellpadding"3" width="100%">
49: <tr bgcolor="#679cd3" class="big">
50: <td align="center"> $dayrev{0} </td>
51: <td align="center"> $dayrev{1} </td>
52: <td align="center"> $dayrev{2} </td>
53: <td align="center"> $dayrev{3} </td>
54: <td align="center"> $dayrev{4} </td>
55: <td align="center"> $dayrev{5} </td>
56: <td align="center"> $dayrev{6} </td>
57: </tr>);
58:
59: # I have to move the start date a little bit to get Sunday
60: # over to the first position
61:
62: my $fday = timelocal(0,0,0,1,$wday[4],$wday[5]);
63: my @ltime = localtime($fday);
64: if($ltime[6] ne "0"){
65: $message.=qq(<tr>);
66:
67: foreach my $cl (0...($ltime[6] - 1)){
68: $message.=qq(<td> </td> );
69: }
70: }else{
71:
72: $message.=qq(<tr>);
73:
74: }
75:
76: my $endm;
77:
78: foreach my $daycount (1...31){
79: my $thisday;
80: eval { $thisday = timelocal(0,0,0,$daycount,$wday[4],$wday[5]); };
81: if( $@ ){ next; }
82: my @ltime = localtime($thisday);
83: $endm = $ltime[6]; # signal to next section about what day we ended on
84:
85: my $color = qq();
86:
87: ## This is where you want to put stuff INTO your calendar
88: ## but that's optional :)
89:
90: $message.=qq(<td $color> $daycount<p> </td>\n);
91:
92: if($ltime[6] eq "6"){ $message.=qq(</tr><tr>\n); }
93: }
94:
95: # close up the table by filling in any missing days
96:
97: if($endm ne "6"){
98: foreach my $cl (($endm+1)...6){
99: $message.=qq(<td> </td> );
100: }
101: }
102: $message.=qq(</tr></table>);
103:
104:
105: # little html out template
106:
107: my $html_frame=qq(<html>
108: <head>
109: <style type="text/css">
110: <!--
111: td, body, p { font-family: Arial, Helvetica, sans-serif; font-size: 12px}
112: .big { font-family: Arial, Helvetica, sans-serif; font-size: 14px}
113: -->
114: </style>
115: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
116: </head>
117:
118: <body bgcolor="#FFFFFF" text="#000000">
119: <p>$message</p>
120: </body>
121: </html>);
122:
123: print "Content-type: text/html\n\n";
124: print "$html_frame";
125:
126: exit;