Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

HTML::CalendarMonthSimple cookbook recipe

by boo_radley (Parson)
on Oct 23, 2001 at 20:51 UTC ( #120838=perltutorial: print w/replies, xml ) Need Help??


You want to display data online in a monthly view.


Make use of HTML::CalendarMonthSimple to provide a programmatic interface to the contents of an HTML calendar month.
#! c:/perl/bin/perl.exe use strict; use CGI qw (header); use CGI::Carp qw(fatalsToBrowser); use DBI; use HTML::CalendarMonthSimple; my $myyear=2001; my $mymonth=10; # month to pull data on # # set up database connectivity & retrieve records # the dbi method selectall_arrayref was added in DBI v1.15. # my $dbi=DBI->connect("DBI:mysql:host=myhost:user=nobody") || die ("no +dbi",DBI->errstr); $dbi->do ("use mydatabase") || die DBI->errstr; my @items = @{$dbi->selectall_arrayref ( "SELECT title, dayofmonth(date), detail FROM table WHERE month (date) = $mymonth AND year (date) = $myyear order by dayofmonth(date)")}; # # set up the calendar & populate information # my $cal = new HTML::CalendarMonthSimple('year'=>$myyear,'month'=>$mymo +nth); $cal->width('100%'); $cal->border(2); $cal->header('Monthly data'); $cal->bgcolor('whitesmoke'); # # populate calendar with data # foreach my $row (@items) { $cal->addcontent($$row[1], "<b>$$row[0]</b> <br /> <i>$$row[2]</i> +"); } print header; print $cal->as_HTML;


This short example provides the barest methods for inputting data into an HTML::CalendarMonthSimple object, and the displaying that calendar.
The new method takes 2 optional arguments, year and month. If either is missing, the current month or year will be used. This can be useful if you want a calendar of the current month in a previous year.
Example :  my $cal = new HTML::CalendarMonthSimple ('year'=>1990); will make a calendar for October 1990.

content is added to each day via the setcontent and addcontent methods; setcontent replaces any existing data, and addcontent appends to the day's data. Example : $cal->setcontent(31,"Halloween!"); puts "Halloween" into the 31st day of the calendar.
Example : $cal->addcontent(31,"<br>Buy lots of candy for the kids"); appends a second line to the same date.
In addition to specifying the exact day, references like "2FRIDAY" can be used to place information in certain cells when the date value may not be known (think paydays, for example).

In addition to the methods listed above, there are a large host of methods which control the layout & presentation of the calendar; colors, fonts and html attributes can be configured easily, and calendar layout can be manipulated as well.
There are some things which could be done better -- this module is not warning-safe due to concatenation of undef'd strings in a few places, and the HTML produced is not in strict compliance with HTML 3 standards, causing tidy to produce warnings. I feel that these are not insurmountable problems though, and have found that working with HTML::CalendarMonthSimple has been a rewarding and speedy way to present data over the web.

update I've patched the source code to prevent the warnings from occuring and as a side effect, this will emit smaller html. I've contacted the module's owner about the patches.

update (20Nov01) The patches I submitted have been integrated into the module, so it should be warning safe now.

Replies are listed 'Best First'.
Re: HTML::CalendarMonthSimple cookbook recipe
by larsen (Parson) on Oct 23, 2001 at 21:40 UTC
      It would be nice if you could show an example of the output it generates.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://120838]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-03-23 20:20 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.