1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
NAME
HTML::CalendarMonthSimple - Perl Module for Generating HTML Calendars
SYNOPSIS
use HTML::CalendarMonthSimple;
$cal = new HTML::CalendarMonthSimple('year'=>2001,'month'=>2);
$cal->width('50%');
$cal->border(10);
$cal->header('Text at the top of the Grid');
$cal->setcontent(14,"Valentine's Day");
$cal->setdatehref(14, 'http://www.lovers.com/');
$cal->addcontent(14,"<p>Don't forget to buy flowers.");
$cal->addcontent(13,"Thirteenth day of the month");
$cal->bgcolor('pink');
print $cal->as_HTML;
DESCRIPTION
HTML::CalendarMonthSimple is a Perl module for generating, manipulating,
and printing a HTML calendar grid for a specified month. It is intended
as a faster and easier-to-use alternative to HTML::CalendarMonth.
This module requires the Date::Calc module, which is available from CPAN
if you don't already have it.
INTERFACE METHODS
new(ARGUMENTS)
Naturally, new() returns a newly constructed calendar object. Recognized
arguments are 'year' and 'month', to specify which month's calendar will
be used. If either is omitted, the current value is used. An important
note is that the month and the year are NOT the standard C or Perl --
use a month in the range 1-12 and a real year, e.g. 2001.
# Examples:
# Create a calendar for this month.
$cal = new HTML::CalendarMonthSimple();
# One for a specific month/year
$cal = new HTML::CalendarMonthSimple('month'=>2,'year=>2000);
# One for "the current date" in 1997
$cal = new HTML::CalendarMonthSimple('year'=>1997);
setcontent(DATE,STRING)
addcontent(DATE,STRING)
getcontent(DATE)
These methods are used to control the content of date cells within the
calendar grid.
# Examples:
# The cell for the 15th of the month will now say something.
$cal->setcontent(15,"An Important Event!");
# Later down the program, we want the content to be boldfaced.
$foo = "<b>" . $cal->getcontent(15) . "</b>";
$cal->setcontent(15,$foo);
# Or we could get extra spiffy:
$cal->setcontent(15,"<b>" . $cal->getcontent(15) . "</b>");
# Example:
# addcontent() does not clober existing content.
# Also, if you setcontent() to '', you've deleted the content.
$cal->setcontent(16,'');
$cal->addcontent(16,"<p>Hello World</p>");
$cal->addcontent(16,"<p>Hello Again</p>");
print $cal->getcontent(16); # Prints 2 sentences
setdatehref(DATE,URL_STRING)
getdatehref(DATE)
These methods are used to control the content of date cells within the
calendar grid.
# Example:
# The date number in the cell for the 15th of the month will
# be a link to the sourceforge website
$cal->setdatehref(15,"http://sourceforge.net/");
# Example:
# You want to add to an URL
$cal->setdatehref(15, $getdatehref(15)."projects/perl/");
as_HTML()
This method returns a string containing the HTML table for the month.
# Example:
print $cal->as_HTML();
It's okay to continue modifying the calendar after calling as_HTML(). My
guess is that you'd want to call as_HTML() again to print the
further-modified calendar, but that's your business...
year()
month()
monthname()
These methods simply return the year/month of the calendar. monthname()
returns the text name of the month, e.g. "December".
border([INTEGER])
This specifies the value of the border attribute to the <TABLE>
declaration for the calendar. As such, this controls the thickness of
the border around the calendar table. The default value is 5.
If a value is not specified, the current value is returned. If a value
is specified, the border value is changed and the new value is returned.
width([INTEGER][%])
This sets the value of the width attribute to the <TABLE> declaration
for the calendar. As such, this controls the horizintal width of the
calendar.
The width value can be either an integer (e.g. 600) or a percentage
string (e.g. "80%"). Most web browsers take an integer to be the table's
width in pixels and a percentage to be the table width relative to the
screen's width. The default width is "100%".
If a value is not specified, the current value is returned. If a value
is specified, the border value is changed and the new value is returned.
# Examples:
$cal->width(600); # absolute pixel width
$cal->width("100%"); # percentage of screen size
showdatenumbers([1 or 0])
If showdatenumbers() is set to 1, then the as_HTML() method will put
date labels in each cell (e.g. a 1 on the 1st, a 2 on the 2nd, etc.) If
set to 0, then the date labels will not be printed. The default is 1.
If no value is specified, the current value is returned.
The date numbers are shown in boldface, normal size font. If you want to
change this, consider setting showdatenumbers() to 0 and using
setcontent()/addcontent() instead.
showweekdayheaders([1 or 0])
If showweekdayheaders() is set to 1 (the default) then calendars
rendered via as_HTML() will display the names of the days of the week.
If set to 0, the days' names will not be displayed.
If no value is specified, the current value is returned.
cellalignment([STRING])
This sets the value of the align attribute to the <TD> tag for each
day's cell. This controls how text will be centered/aligned within the
cells.
Any value can be used, if you think the web browser will find it
interesting. Some useful alignments are: left, right, center, top, and
bottom,
By default, cells are aligned to the left.
header([STRING])
By default, the current month and year are displayed at the top of the
calendar grid. This is called the "header".
The header() method allows you to set the header to whatever you like.
If no new header is specified, the current header is returned.
If the header is set to an empty string, then no header will be printed
at all. (No, you won't be stuck with a big empty cell!)
# Example:
# Set the month/year header to something snazzy.
my($y,$m) = ( $cal->year() , $cal->monthname() );
$cal->header("<center><font size=+2 color=red>$m $y</font></center>\n\n");
bgcolor([STRING])
weekdaycolor([STRING])
weekendcolor([STRING])
weekdayheadercolor([STRING])
headercolor([STRING])
These define the colors of the cells. If a string (which should be a
HTML color-code like '#000000' or a color-word like 'yellow') is
supplied as an argument, then the color is set to that specified.
Otherwise, the current value is returned. To un-set a value, try
assigning the null string as a value.
The bgcolor defines the color of all cells. The weekdaycolor overrides
the bgcolor for weekdays (Monday thru\ough Friday), and the weekendcolor
overrides the bgcolor for weekend days (Saturday and Sunday). The
weekdayheadercolor overrides the bgcolor for the weekday headers that
appear at the top of the calendar if showweekdayheaders() is true. The
headercolor overrides the bgcolor for the month/year header at the top
of the calendar.
# Example:
# This sets a default cell color, and then overrides the cell colors.
# Only the weekday headers aren't overridden, so only they will show
# the default bgcolor of green.
# P.S. I don't recommend this color scheme for production use. ;)
$cal->bgcolor('green');
$cal->weekdaycolor('orange');
$cal->weekendcolor('blue');
#$cal->weekdayheadercolor('silver');
$cal->headercolor('yellow');
BUGS, TODO, CHANGES
It would be nice if the week didn't have to start on Sunday. It would
also be cool if the weekday headers could be changed (Lunes, Martes,
Miercoles,...) or suppressed. It'd be nice if the month could be
translated, as well. These features will probably make in into the next
version some time in April 2001. If anyone wants to take on any of this
work, please feel invited.
Changes in 1.01: Added VALIGN to cells, to make alignment work with
browsers better. Added showweekdayheaders(). Corrected a bug that
results in the month not fitting on the grid (e.g. March 2003). Added
getdatehref() and setdatehref(). Corrected a bug that causes a blank
week to be printed at the beginning of some months.
Changes in 1.02: Added the color methods.
AUTHORS, CREDITS, COPYRIGHTS
HTML::CalendarMonth was written and is copyrighted by Matthew P. Sisk
<sisk@mojotoad.com> and provided inspiration for the module's interface
and features. Frankly, the major inspiration was the difficulty and
unnecessary complexity of the interface. (Laziness is a virtue.)
HTML::CalendarMonthSimple was written by Gregor Mosheh
<stigmata@blackangel.net> None of Matt Sisk's code appears herein.
This would have been extremely difficult if not for Date::Calc. Many
thanks to Steffen Beyer <sb@engelschall.com> for a very fine set of
date-related functions!
Dave Fuller <dffuller@yahoo.com> added the getdatehref() and
setdatehref() methods, and pointed out the bugs that were corrected in
1.01.
Danny J. Sohier <danny@gel.ulaval.ca> provided the color functions.
This Perl module is freeware. It may be copied, derived, used, and
distributed without limitation.
|