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