File Coverage

blib/lib/HTML/CalendarMonthSimple.pm
Criterion Covered Total %
statement 39 480 8.1
branch 0 238 0.0
condition 6 149 4.0
subroutine 3 62 4.8
pod 0 59 0.0
total 48 988 4.8


line stmt bran cond sub pod time code
1             # HTML::CalendarMonthSimple.pm
2             # Generate HTML calendars. An alternative to HTML::CalendarMonth
3             # Herein, the symbol $self is used to refer to the object that's being passed around.
4              
5             package HTML::CalendarMonthSimple;
6             $HTML::CalendarMonthSimple::VERSION = "1.25";
7 1     1   823 use strict;
  1         2  
  1         42  
8 1     1   881 use Date::Calc;
  1         103974  
  1         7157  
9              
10              
11             # Within the constructor is the only place where values are access directly.
12             # Methods are provided for accessing/changing values, and those methods
13             # are used even internally.
14             # Most of the constructor is assigning default values.
15             sub new {
16 1   33 1 0 55 my $class = shift; $class = ref($class) || $class;
  1         8  
17 1         2 my $self = {}; %$self = @_; # Load ourselves up from the args
  1         4  
18              
19             # figure out the current date (which may be specified as today_year, et al
20             # then figure out which year+month we're supposed to display
21             {
22 1         1 my($year,$month,$date) = Date::Calc::Today();
  1         6  
23 1   33     261 $self->{'today_year'} = $self->{'today_year'} || $year;
24 1   33     7 $self->{'today_month'} = $self->{'today_month'} || $month;
25 1   33     7 $self->{'today_date'} = $self->{'today_date'} || $date;
26 1   33     8 $self->{'month'} = $self->{'month'} || $self->{'today_month'};
27 1   33     7 $self->{'year'} = $self->{'year'} || $self->{'today_year'};
28 1         7 $self->{'monthname'} = Date::Calc::Month_to_Text($self->{'month'});
29             }
30              
31             # Some defaults
32 1         15 $self->{'border'} = 5;
33 1         4 $self->{'width'} = '100%';
34 1         3 $self->{'showdatenumbers'} = 1;
35 1         2 $self->{'showweekdayheaders'} = 1;
36 1         3 $self->{'cellalignment'} = 'left';
37 1         2 $self->{'vcellalignment'} = 'top';
38 1         2 $self->{'weekdayheadersbig'} = 1;
39 1         3 $self->{'nowrap'} = 0;
40              
41 1         4 $self->{'weekdays'} = [qw/Monday Tuesday Wednesday Thursday Friday/];
42 1         4 $self->{'sunday'} = "Sunday";
43 1         2 $self->{'saturday'} = "Saturday";
44              
45             # Set the default calendar header
46 1         6 $self->{'header'} = sprintf("
%s %d
",
47             Date::Calc::Month_to_Text($self->{'month'}),$self->{'year'});
48              
49             # Initialize the (empty) cell content so the keys are representative of the month
50 1         24 foreach my $datenumber ( 1 .. Date::Calc::Days_in_Month($self->{'year'},$self->{'month'}) ) {
51 30         89 $self->{'content'}->{$datenumber} = '';
52 30         45 $self->{'datecellclass'}->{$datenumber} = '';
53 30         49 $self->{'datecolor'}->{$datenumber} = '';
54 30         46 $self->{'datebordercolor'}->{$datenumber} = '';
55 30         43 $self->{'datecontentcolor'}->{$datenumber} = '';
56 30         58 $self->{'href'}->{$datenumber} = '';
57             }
58              
59             # All done!
60 1         4 bless $self,$class; return $self;
  1         5  
61             }
62              
63              
64             sub as_HTML {
65 0     0 0   my $self = shift;
66 0           my %params = @_;
67 0           my $html = '';
68 0           my(@days,$weeks,$WEEK,$DAY);
69              
70             # To make the grid even, pad the start of the series with 0s
71 0           @days = (1 .. Date::Calc::Days_in_Month($self->year(),$self->month() ) );
72 0 0         if ($self->weekstartsonmonday()) {
73 0           foreach (1 .. (Date::Calc::Day_of_Week($self->year(),
74             $self->month(),1) -1 )) {
75 0           unshift(@days,0);
76             }
77             }
78             else {
79 0           foreach (1 .. (Date::Calc::Day_of_Week($self->year(),
80             $self->month(),1)%7) ) {
81 0           unshift(@days,0);
82             }
83             }
84 0           $weeks = int((scalar(@days)+6)/7);
85             # And pad the end as well, to avoid "uninitialized value" warnings
86 0           foreach (scalar(@days)+1 .. $weeks*7) {
87 0           push(@days,0);
88             }
89              
90             # Define some scalars for generating the table
91 0           my $border = $self->border();
92 0           my $tablewidth = $self->width();
93 0 0 0       $tablewidth =~ m/^(\d+)(\%?)$/; my $cellwidth = (int($1/7))||'14'; if ($2) { $cellwidth .= '%'; }
  0            
  0            
  0            
94 0           my $header = $self->header();
95 0           my $cellalignment = $self->cellalignment();
96 0           my $vcellalignment = $self->vcellalignment();
97 0           my $contentfontsize = $self->contentfontsize();
98 0           my $bgcolor = $self->bgcolor();
99 0   0       my $weekdaycolor = $self->weekdaycolor() || $self->bgcolor();
100 0   0       my $weekendcolor = $self->weekendcolor() || $self->bgcolor();
101 0   0       my $todaycolor = $self->todaycolor() || $self->bgcolor();
102 0   0       my $contentcolor = $self->contentcolor() || $self->contentcolor();
103 0   0       my $weekdaycontentcolor = $self->weekdaycontentcolor() || $self->contentcolor();
104 0   0       my $weekendcontentcolor = $self->weekendcontentcolor() || $self->contentcolor();
105 0   0       my $todaycontentcolor = $self->todaycontentcolor() || $self->contentcolor();
106 0   0       my $bordercolor = $self->bordercolor() || $self->bordercolor();
107 0   0       my $weekdaybordercolor = $self->weekdaybordercolor() || $self->bordercolor();
108 0   0       my $weekendbordercolor = $self->weekendbordercolor() || $self->bordercolor();
109 0   0       my $todaybordercolor = $self->todaybordercolor() || $self->bordercolor();
110 0   0       my $weekdayheadercolor = $self->weekdayheadercolor() || $self->bgcolor();
111 0   0       my $weekendheadercolor = $self->weekendheadercolor() || $self->bgcolor();
112 0   0       my $headercontentcolor = $self->headercontentcolor() || $self->contentcolor();
113 0   0       my $weekdayheadercontentcolor = $self->weekdayheadercontentcolor() || $self->contentcolor();
114 0   0       my $weekendheadercontentcolor = $self->weekendheadercontentcolor() || $self->contentcolor();
115 0   0       my $headercolor = $self->headercolor() || $self->bgcolor();
116 0           my $cellpadding = $self->cellpadding();
117 0           my $cellspacing = $self->cellspacing();
118 0           my $sharpborders = $self->sharpborders();
119 0           my $cellheight = $self->cellheight();
120 0           my $cellclass = $self->cellclass();
121 0           my $tableclass = $self->tableclass();
122 0   0       my $weekdaycellclass = $self->weekdaycellclass() || $self->cellclass();
123 0   0       my $weekendcellclass = $self->weekendcellclass() || $self->cellclass();
124 0   0       my $todaycellclass = $self->todaycellclass() || $self->cellclass();
125 0   0       my $headerclass = $self->headerclass() || $self->cellclass();
126 0           my $nowrap = $self->nowrap();
127              
128             # Get today's date, in case there's a todaycolor()
129 0           my($todayyear,$todaymonth,$todaydate) = ($self->today_year(),$self->today_month(),$self->today_date());
130              
131             # the table declaration - sharpborders wraps the table inside a table cell
132 0 0         if ($sharpborders) {
133 0           $html .= "\n"; \n\n
134 0 0         $html .= " class=\"$tableclass\"" if defined $tableclass;
135 0 0         $html .= " width=\"$tablewidth\"" if defined $tablewidth;
136 0           $html .= " cellpadding=\"0\" cellspacing=\"0\">\n";
137 0           $html .= "
138 0           $html .= "
139 0 0         $html .= " bgcolor=\"$bordercolor\"" if defined $bordercolor;
140 0           $html .= ">";
141 0           $html .= ""; \n"; \n"; \n"; \n"; \n"; \n";
142             }
143             else {
144 0           $html .= "
145 0 0         $html .= " class=\"$tableclass\"" if defined $tableclass;
146 0 0         $html .= " border=\"$border\"" if defined $border;
147 0 0         $html .= " width=\"$tablewidth\"" if defined $tablewidth;
148 0 0         $html .= " bgcolor=\"$bgcolor\"" if defined $bgcolor;
149 0 0         $html .= " bordercolor=\"$bordercolor\"" if defined $bordercolor;
150 0 0         $html .= " cellpadding=\"$cellpadding\"" if defined $cellpadding;
151 0 0         $html .= " cellspacing=\"$cellspacing\"" if defined $cellspacing;
152 0           $html .= ">\n";
153             }
154             # the header
155 0 0         if ($header) {
156 0           $html .= "
157 0 0         $html .= " bgcolor=\"$headercolor\"" if defined $headercolor;
158 0 0         $html .= " class=\"$headerclass\"" if defined $headerclass;
159 0           $html .= ">";
160 0 0         $html .= "" if defined $headercontentcolor;
161 0           $html .= $header;
162 0 0         $html .= "" if defined $headercontentcolor;
163 0           $html .= "
164             }
165             # the names of the days of the week
166 0 0         if ($self->showweekdayheaders) {
167 0 0         my $celltype = $self->weekdayheadersbig() ? "th" : "td";
168 0           my @weekdays = $self->weekdays();
169              
170 0 0         my $saturday_html = "<$celltype"
    0          
    0          
    0          
171             . ( defined $weekendheadercolor
172             ? qq| bgcolor="$weekendheadercolor"|
173             : '' )
174             . ( defined $weekendcellclass
175             ? qq| class="$weekendcellclass"|
176             : '' )
177             . ">"
178             . ( defined $weekendheadercontentcolor
179             ? qq||
180             : '' )
181             . $self->saturday()
182             . ( defined $weekendheadercontentcolor
183             ? qq||
184             : '' )
185             . "\n";
186              
187 0 0         my $sunday_html = "<$celltype"
    0          
    0          
    0          
188             . ( defined $weekendheadercolor
189             ? qq| bgcolor="$weekendheadercolor"|
190             : '' )
191             . ( defined $weekendcellclass
192             ? qq| class="$weekendcellclass"|
193             : '' )
194             . ">"
195             . ( defined $weekendheadercontentcolor
196             ? qq||
197             : '' )
198             . $self->sunday()
199             . ( defined $weekendheadercontentcolor
200             ? qq||
201             : '' )
202             . "\n";
203            
204 0           my $weekday_html = '';
205 0           foreach (@weekdays) { # draw the weekday headers
206              
207 0 0         $weekday_html .= "<$celltype"
    0          
    0          
    0          
208             . ( defined $weekendheadercolor
209             ? qq| bgcolor="$weekdayheadercolor"|
210             : '' )
211             . ( defined $weekendcellclass
212             ? qq| class="$weekdaycellclass"|
213             : '' )
214             . ">"
215             . ( defined $weekdayheadercontentcolor
216             ? qq||
217             : '' )
218             . $_
219             . ( defined $weekdayheadercontentcolor
220             ? qq||
221             : '' )
222             . "\n";
223             }
224              
225 0           $html .= "
226 0 0         if ($self->weekstartsonmonday()) {
227 0           $html .= $weekday_html
228             . $saturday_html
229             . $sunday_html;
230             }
231             else {
232 0           $html .= $sunday_html
233             . $weekday_html
234             . $saturday_html;
235             }
236 0           $html .= "
237             }
238              
239 0           my $_saturday_index = 6;
240 0           my $_sunday_index = 0;
241 0 0         if ($self->weekstartsonmonday()) {
242 0           $_saturday_index = 5;
243 0           $_sunday_index = 6;
244             }
245             # now do each day, the actual date-content-containing cells
246 0           foreach $WEEK (0 .. ($weeks-1)) {
247 0           $html .= "
248              
249            
250 0           foreach $DAY ( 0 .. 6 ) {
251 0           my($thiscontent,$thisday,$thisbgcolor,$thisbordercolor,$thiscontentcolor,$thiscellclass);
252 0           $thisday = $days[((7*$WEEK)+$DAY)];
253              
254             # Get the cell content
255 0 0         if (! $thisday) { # If it's a dummy cell, no content
256 0           $thiscontent = ' '; }
257             else { # A real date cell with potential content
258             # Get the content
259 0 0         if ($self->showdatenumbers()) {
260 0 0         if ( $self->getdatehref( $thisday )) {
261 0           $thiscontent = "

getdatehref($thisday);

262 0           $thiscontent .= "\">$thisday

\n";
263             } else {
264 0           $thiscontent = "

$thisday

\n";
265             }
266             }
267 0           $thiscontent .= $self->{'content'}->{$thisday};
268 0   0       $thiscontent ||= ' ';
269             }
270              
271             # Get the cell's coloration and CSS class
272 0 0 0       if ($self->year == $todayyear && $self->month == $todaymonth && $thisday == $todaydate)
    0 0        
      0        
273 0   0       { $thisbgcolor = $self->datecolor($thisday) || $todaycolor;
274 0   0       $thisbordercolor = $self->datebordercolor($thisday) || $todaybordercolor;
275 0   0       $thiscontentcolor = $self->datecontentcolor($thisday) || $todaycontentcolor;
276 0   0       $thiscellclass = $self->datecellclass($thisday) || $todaycellclass;
277             }
278 0   0       elsif (($DAY == $_sunday_index) || ($DAY == $_saturday_index)) { $thisbgcolor = $self->datecolor($thisday) || $weekendcolor;
279 0   0       $thisbordercolor = $self->datebordercolor($thisday) || $weekendbordercolor;
280 0   0       $thiscontentcolor = $self->datecontentcolor($thisday) || $weekendcontentcolor;
281 0   0       $thiscellclass = $self->datecellclass($thisday) || $weekendcellclass;
282             }
283 0   0       else { $thisbgcolor = $self->datecolor($thisday) || $weekdaycolor;
284 0   0       $thisbordercolor = $self->datebordercolor($thisday) || $weekdaybordercolor;
285 0   0       $thiscontentcolor = $self->datecontentcolor($thisday) || $weekdaycontentcolor;
286 0   0       $thiscellclass = $self->datecellclass($thisday) || $weekdaycellclass;
287             }
288              
289             # Done with this cell - push it into the table
290 0           $html .= "
291 0 0         $html .= " nowrap" if $nowrap;
292 0 0         $html .= " class=\"$thiscellclass\"" if defined $thiscellclass;
293 0 0         $html .= " height=\"$cellheight\"" if defined $cellheight;
294 0 0         $html .= " width=\"$cellwidth\"" if defined $cellwidth;
295 0 0         $html .= " valign=\"$vcellalignment\"" if defined $vcellalignment;
296 0 0         $html .= " align=\"$cellalignment\"" if defined $cellalignment;
297 0 0         $html .= " bgcolor=\"$thisbgcolor\"" if defined $thisbgcolor;
298 0 0         $html .= " bordercolor=\"$thisbordercolor\"" if defined $thisbordercolor;
299 0           $html .= ">";
300 0 0 0       $html .= "
301             defined $contentfontsize);
302 0 0         $html .= " color=\"$thiscontentcolor\"" if defined $thiscontentcolor;
303 0 0         $html .= " size=\"$contentfontsize\"" if defined $contentfontsize;
304 0 0 0       $html .= ">" if (defined $thiscontentcolor ||
305             defined $contentfontsize);
306 0           $html .= $thiscontent;
307 0 0 0       $html .= "" if (defined $thiscontentcolor ||
308             defined $contentfontsize);
309 0           $html .= "
310             }
311 0           $html .= "
312             }
313 0           $html .= "
\n";
314              
315             # if sharpborders, we need to break out of the enclosing table cell
316 0 0         if ($sharpborders) {
317 0           $html .= "
\n";
318             }
319              
320 0           return $html;
321             }
322              
323              
324              
325             sub sunday {
326 0     0 0   my $self = shift;
327 0           my $newvalue = shift;
328 0 0         $self->{'sunday'} = $newvalue if defined($newvalue);
329 0           return $self->{'sunday'};
330             }
331              
332             sub saturday {
333 0     0 0   my $self = shift;
334 0           my $newvalue = shift;
335 0 0         $self->{'saturday'} = $newvalue if defined($newvalue);
336 0           return $self->{'saturday'};
337             }
338              
339             sub weekdays {
340 0     0 0   my $self = shift;
341 0           my @days = @_;
342 0 0         $self->{'weekdays'} = \@days if (scalar(@days)==5);
343 0           return @{$self->{'weekdays'}};
  0            
344             }
345              
346             sub getdatehref {
347 0     0 0   my $self = shift;
348 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
349 0           return $self->{'href'}->{$dates[0]};
350             }
351              
352             sub setdatehref {
353 0     0 0   my $self = shift;
354 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
355 0   0       my $datehref = shift || '';
356              
357 0           foreach my $date (@dates) {
358 0 0         $self->{'href'}->{$date} = $datehref if defined($self->{'href'}->{$date});
359             }
360              
361 0           return(1);
362             }
363              
364             sub weekendcolor {
365 0     0 0   my $self = shift;
366 0           my $newvalue = shift;
367 0 0         if (defined($newvalue)) { $self->{'weekendcolor'} = $newvalue; }
  0            
368 0           return $self->{'weekendcolor'};
369             }
370              
371             sub weekendheadercolor {
372 0     0 0   my $self = shift;
373 0           my $newvalue = shift;
374 0 0         if (defined($newvalue)) { $self->{'weekendheadercolor'} = $newvalue; }
  0            
375 0           return $self->{'weekendheadercolor'};
376             }
377              
378             sub weekdayheadercolor {
379 0     0 0   my $self = shift;
380 0           my $newvalue = shift;
381 0 0         if (defined($newvalue)) { $self->{'weekdayheadercolor'} = $newvalue; }
  0            
382 0           return $self->{'weekdayheadercolor'};
383             }
384              
385             sub weekdaycolor {
386 0     0 0   my $self = shift;
387 0           my $newvalue = shift;
388 0 0         if (defined($newvalue)) { $self->{'weekdaycolor'} = $newvalue; }
  0            
389 0           return $self->{'weekdaycolor'};
390             }
391              
392             sub headercolor {
393 0     0 0   my $self = shift;
394 0           my $newvalue = shift;
395 0 0         if (defined($newvalue)) { $self->{'headercolor'} = $newvalue; }
  0            
396 0           return $self->{'headercolor'};
397             }
398              
399             sub bgcolor {
400 0     0 0   my $self = shift;
401 0           my $newvalue = shift;
402 0 0         if (defined($newvalue)) { $self->{'bgcolor'} = $newvalue; }
  0            
403 0           return $self->{'bgcolor'};
404             }
405              
406             sub todaycolor {
407 0     0 0   my $self = shift;
408 0           my $newvalue = shift;
409 0 0         if (defined($newvalue)) { $self->{'todaycolor'} = $newvalue; }
  0            
410 0           return $self->{'todaycolor'};
411             }
412              
413             sub bordercolor {
414 0     0 0   my $self = shift;
415 0           my $newvalue = shift;
416 0 0         if (defined($newvalue)) { $self->{'bordercolor'} = $newvalue; }
  0            
417 0           return $self->{'bordercolor'};
418             }
419              
420             sub weekdaybordercolor {
421 0     0 0   my $self = shift;
422 0           my $newvalue = shift;
423 0 0         if (defined($newvalue)) { $self->{'weekdaybordercolor'} = $newvalue; }
  0            
424 0           return $self->{'weekdaybordercolor'};
425             }
426              
427             sub weekendbordercolor {
428 0     0 0   my $self = shift;
429 0           my $newvalue = shift;
430 0 0         if (defined($newvalue)) { $self->{'weekendbordercolor'} = $newvalue; }
  0            
431 0           return $self->{'weekendbordercolor'};
432             }
433              
434             sub todaybordercolor {
435 0     0 0   my $self = shift;
436 0           my $newvalue = shift;
437 0 0         if (defined($newvalue)) { $self->{'todaybordercolor'} = $newvalue; }
  0            
438 0           return $self->{'todaybordercolor'};
439             }
440              
441             sub contentcolor {
442 0     0 0   my $self = shift;
443 0           my $newvalue = shift;
444 0 0         if (defined($newvalue)) { $self->{'contentcolor'} = $newvalue; }
  0            
445 0           return $self->{'contentcolor'};
446             }
447              
448             sub headercontentcolor {
449 0     0 0   my $self = shift;
450 0           my $newvalue = shift;
451 0 0         if (defined($newvalue)) { $self->{'headercontentcolor'} = $newvalue; }
  0            
452 0           return $self->{'headercontentcolor'};
453             }
454              
455             sub weekdayheadercontentcolor {
456 0     0 0   my $self = shift;
457 0           my $newvalue = shift;
458 0 0         if (defined($newvalue)) { $self->{'weekdayheadercontentcolor'} = $newvalue; }
  0            
459 0           return $self->{'weekdayheadercontentcolor'};
460             }
461              
462             sub weekendheadercontentcolor {
463 0     0 0   my $self = shift;
464 0           my $newvalue = shift;
465 0 0         if (defined($newvalue)) { $self->{'weekendheadercontentcolor'} = $newvalue; }
  0            
466 0           return $self->{'weekendheadercontentcolor'};
467             }
468              
469             sub weekdaycontentcolor {
470 0     0 0   my $self = shift;
471 0           my $newvalue = shift;
472 0 0         if (defined($newvalue)) { $self->{'weekdaycontentcolor'} = $newvalue; }
  0            
473 0           return $self->{'weekdaycontentcolor'};
474             }
475              
476             sub weekendcontentcolor {
477 0     0 0   my $self = shift;
478 0           my $newvalue = shift;
479 0 0         if (defined($newvalue)) { $self->{'weekendcontentcolor'} = $newvalue; }
  0            
480 0           return $self->{'weekendcontentcolor'};
481             }
482              
483             sub todaycontentcolor {
484 0     0 0   my $self = shift;
485 0           my $newvalue = shift;
486 0 0         if (defined($newvalue)) { $self->{'todaycontentcolor'} = $newvalue; }
  0            
487 0           return $self->{'todaycontentcolor'};
488             }
489              
490             sub datecolor {
491 0     0 0   my $self = shift;
492 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
493 0           my $newvalue = shift;
494              
495 0 0         if (defined($newvalue)) {
496 0           foreach my $date (@dates) {
497 0 0         $self->{'datecolor'}->{$date} = $newvalue if defined($self->{'datecolor'}->{$date});
498             }
499             }
500              
501 0           return $self->{'datecolor'}->{$dates[0]};
502             }
503              
504             sub datebordercolor {
505 0     0 0   my $self = shift;
506 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
507 0           my $newvalue = shift;
508              
509 0 0         if (defined($newvalue)) {
510 0           foreach my $date (@dates) {
511 0 0         $self->{'datebordercolor'}->{$date} = $newvalue if defined($self->{'datebordercolor'}->{$date});
512             }
513             }
514              
515 0           return $self->{'datebordercolor'}->{$dates[0]};
516             }
517              
518             sub datecontentcolor {
519 0     0 0   my $self = shift;
520 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
521 0           my $newvalue = shift;
522              
523 0 0         if (defined($newvalue)) {
524 0           foreach my $date (@dates) {
525 0 0         $self->{'datecontentcolor'}->{$date} = $newvalue if defined($self->{'datecontentcolor'}->{$date});
526             }
527             }
528              
529 0           return $self->{'datecontentcolor'}->{$dates[0]};
530             }
531              
532             sub getcontent {
533 0     0 0   my $self = shift;
534 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
535 0           return $self->{'content'}->{$dates[0]};
536             }
537              
538             sub setcontent {
539 0     0 0   my $self = shift;
540 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
541 0   0       my $newcontent = shift || '';
542              
543 0           foreach my $date (@dates) {
544 0 0         $self->{'content'}->{$date} = $newcontent if defined($self->{'content'}->{$date});
545             }
546              
547 0           return(1);
548             }
549              
550             sub addcontent {
551 0     0 0   my $self = shift;
552 0 0         my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0            
553 0   0       my $newcontent = shift || return();
554              
555 0           foreach my $date (@dates) {
556 0 0         $self->{'content'}->{$date} .= $newcontent if defined($self->{'content'}->{$date});
557             }
558              
559 0           return(1);
560             }
561              
562             sub border {
563 0     0 0   my $self = shift;
564 0           my $newvalue = shift;
565 0 0         if (defined($newvalue)) { $self->{'border'} = int($newvalue); }
  0            
566 0           return $self->{'border'};
567             }
568              
569              
570             sub cellpadding {
571 0     0 0   my $self = shift;
572 0           my $newvalue = shift;
573 0 0         if (defined($newvalue)) { $self->{'cellpadding'} = $newvalue; }
  0            
574 0           return $self->{'cellpadding'};
575             }
576              
577             sub cellspacing {
578 0     0 0   my $self = shift;
579 0           my $newvalue = shift;
580 0 0         if (defined($newvalue)) { $self->{'cellspacing'} = $newvalue; }
  0            
581 0           return $self->{'cellspacing'};
582             }
583              
584             sub width {
585 0     0 0   my $self = shift;
586 0           my $newvalue = shift;
587 0 0         if (defined($newvalue)) { $self->{'width'} = $newvalue; }
  0            
588 0           return $self->{'width'};
589             }
590              
591             sub showdatenumbers {
592 0     0 0   my $self = shift;
593 0           my $newvalue = shift;
594 0 0         if (defined($newvalue)) { $self->{'showdatenumbers'} = $newvalue; }
  0            
595 0           return $self->{'showdatenumbers'};
596             }
597             sub showweekdayheaders {
598 0     0 0   my $self = shift;
599 0           my $newvalue = shift;
600 0 0         if (defined($newvalue)) { $self->{'showweekdayheaders'} = $newvalue; }
  0            
601 0           return $self->{'showweekdayheaders'};
602             }
603              
604             sub cellalignment {
605 0     0 0   my $self = shift;
606 0           my $newvalue = shift;
607 0 0         if (defined($newvalue)) { $self->{'cellalignment'} = $newvalue; }
  0            
608 0           return $self->{'cellalignment'};
609             }
610              
611             sub vcellalignment {
612 0     0 0   my $self = shift;
613 0           my $newvalue = shift;
614 0 0         if (defined($newvalue)) { $self->{'vcellalignment'} = $newvalue; }
  0            
615 0           return $self->{'vcellalignment'};
616             }
617              
618             sub contentfontsize {
619 0     0 0   my $self = shift;
620 0           my $newvalue = shift;
621 0 0         if (defined($newvalue)) { $self->{'contentfontsize'} = $newvalue; }
  0            
622 0           return $self->{'contentfontsize'};
623             }
624              
625             sub weekdayheadersbig {
626 0     0 0   my $self = shift;
627 0           my $newvalue = shift;
628 0 0         if (defined($newvalue)) { $self->{'weekdayheadersbig'} = $newvalue; }
  0            
629 0           return $self->{'weekdayheadersbig'};
630             }
631              
632             sub year {
633 0     0 0   my $self = shift;
634 0           return $self->{'year'};
635             }
636              
637             sub month {
638 0     0 0   my $self = shift;
639 0           return $self->{'month'};
640             }
641              
642             sub monthname {
643 0     0 0   my $self = shift;
644 0           return $self->{'monthname'};
645             }
646              
647             sub today_year {
648 0     0 0   my $self = shift;
649 0           return $self->{'today_year'};
650             }
651              
652             sub today_month {
653 0     0 0   my $self = shift;
654 0           return $self->{'today_month'};
655             }
656              
657             sub today_date {
658 0     0 0   my $self = shift;
659 0           return $self->{'today_date'};
660             }
661              
662              
663             sub header {
664 0     0 0   my $self = shift;
665 0           my $newvalue = shift;
666 0 0         if (defined($newvalue)) { $self->{'header'} = $newvalue; }
  0            
667 0           return $self->{'header'};
668             }
669              
670             sub nowrap {
671 0     0 0   my $self = shift;
672 0           my $newvalue = shift;
673 0 0         if (defined($newvalue)) { $self->{'nowrap'} = $newvalue; }
  0            
674 0           return $self->{'nowrap'};
675             }
676              
677             sub sharpborders {
678 0     0 0   my $self = shift;
679 0           my $newvalue = shift;
680 0 0         if (defined($newvalue)) { $self->{'sharpborders'} = $newvalue; }
  0            
681 0           return $self->{'sharpborders'};
682             }
683              
684             sub cellheight {
685 0     0 0   my $self = shift;
686 0           my $newvalue = shift;
687 0 0         if (defined($newvalue)) { $self->{'cellheight'} = $newvalue; }
  0            
688 0           return $self->{'cellheight'};
689             }
690              
691             sub cellclass {
692 0     0 0   my $self = shift;
693 0           my $newvalue = shift;
694 0 0         if (defined($newvalue)) { $self->{'cellclass'} = $newvalue; }
  0            
695 0           return $self->{'cellclass'};
696             }
697              
698             sub tableclass {
699 0     0 0   my $self = shift;
700 0           my $newvalue = shift;
701 0 0         if (defined($newvalue)) { $self->{'tableclass'} = $newvalue; }
  0            
702 0           return $self->{'tableclass'};
703             }
704              
705             sub weekdaycellclass {
706 0     0 0   my $self = shift;
707 0           my $newvalue = shift;
708 0 0         if (defined($newvalue)) { $self->{'weekdaycellclass'} = $newvalue; }
  0            
709 0           return $self->{'weekdaycellclass'};
710             }
711              
712             sub weekendcellclass {
713 0     0 0   my $self = shift;
714 0           my $newvalue = shift;
715 0 0         if (defined($newvalue)) { $self->{'weekendcellclass'} = $newvalue; }
  0            
716 0           return $self->{'weekendcellclass'};
717             }
718              
719             sub todaycellclass {
720 0     0 0   my $self = shift;
721 0           my $newvalue = shift;
722 0 0         if (defined($newvalue)) { $self->{'todaycellclass'} = $newvalue; }
  0            
723 0           return $self->{'todaycellclass'};
724             }
725              
726             sub datecellclass {
727 0     0 0   my $self = shift;
728 0 0 0       my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d\.]+$/;
  0            
729 0           my $newvalue = shift;
730 0 0         if (defined($newvalue)) { $self->{'datecellclass'}->{$date} = $newvalue; }
  0            
731 0           return $self->{'datecellclass'}->{$date};
732             }
733              
734             sub headerclass {
735 0     0 0   my $self = shift;
736 0           my $newvalue = shift;
737 0 0         if (defined($newvalue)) { $self->{'headerclass'} = $newvalue; }
  0            
738 0           return $self->{'headerclass'};
739             }
740              
741             sub weekstartsonmonday {
742 0     0 0   my $self = shift;
743 0           my $newvalue = shift;
744 0 0         if (defined($newvalue)) { $self->{'weekstartsonmonday'} = $newvalue; }
  0            
745 0 0         return $self->{'weekstartsonmonday'} ? 1 : 0;
746             }
747              
748              
749             ### the following methods are internal-use-only methods
750              
751             # _date_string_to_numeric() takes a date string (e.g. 5, 'wednesdays', or '3friday')
752             # and returns the corresponding numeric date. For numerics, this sounds meaningless,
753             # but for the strings it's useful to have this all in one place.
754             # If it's a plural weekday (e.g. 'sundays') then an array of numeric dates is returned.
755             sub _date_string_to_numeric {
756 0     0     my $self = shift;
757 0   0       my $date = shift || return ();
758              
759 0           my($which,$weekday);
760 0 0         if ($date =~ m/^\d\.*\d*$/) { # first and easiest, simple numerics
    0          
    0          
761 0           return int($date);
762             }
763             elsif (($which,$weekday) = ($date =~ m/^(\d)([a-zA-Z]+)$/)) {
764 0           my($y,$m,$d) = Date::Calc::Nth_Weekday_of_Month_Year($self->year(),$self->month(),Date::Calc::Decode_Day_of_Week($weekday),$which);
765 0           return $d;
766             }
767             elsif (($weekday) = ($date =~ m/^(\w+)s$/i)) {
768 0           $weekday = Date::Calc::Decode_Day_of_Week($weekday); # now it's the numeric weekday
769 0           my @dates;
770 0           foreach my $which (1..5) {
771 0           my $thisdate = Date::Calc::Nth_Weekday_of_Month_Year($self->year(),$self->month(),$weekday,$which);
772 0 0         push(@dates,$thisdate) if $thisdate;
773             }
774 0           return @dates;
775             }
776             }
777              
778              
779              
780             __END__;