Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Problem

You want to display data online in a monthly view.

Solution

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;

Discussion

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.


In reply to HTML::CalendarMonthSimple cookbook recipe by boo_radley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-29 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found