Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: 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.

In reply to HTML::CalendarMonthSimple cookbook recipe by boo_radley

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (3)
    As of 2020-09-20 00:52 GMT
    Find Nodes?
      Voting Booth?
      If at first I donít succeed, I Ö

      Results (117 votes). Check out past polls.