# HTML::CalendarMonthDB.pm # Generate persistant or non-persistant HTML calendars. # An alternative to HTML::CalendarMonth and HTML::CalendarMonthSimple # Herein, the symbol $self is used to refer to the object that's being passed around. package HTML::CalendarMonthDB; my $VERSION = "1.0"; use strict; use Date::Calc; # Within the constructor is the only place where values are access directly. # Methods are provided for accessing/changing values, and those methods # are used even internally. # Most of the constructor is assigning default values. sub new { my $class = shift; $class = ref($class) || $class; my $self = {}; %$self = @_; # Load ourselves up from the args # Set the month and year to either args or today ($self->{'month'}) || ($self->{'month'} = (Date::Calc::Today)[1]); ($self->{'year'}) || ($self->{'year'} = (Date::Calc::Today)[0]); # Some defaults $self->{'border'} = 5; $self->{'width'} = '100%'; $self->{'showdatenumbers'} = 1; $self->{'showweekdayheaders'} = 1; $self->{'cellalignment'} = 'left'; $self->{'bgcolor'} = 'ffffff'; if ($self->{'dbname'}) { use DBI; # det defaults ($self->{'dbuser'}) || ($self->{'dbuser'} = 'nobody'); ($self->{'dbpass'}) || ($self->{'dbpass'} = ''); ($self->{'dbcalendar'}) || ($self->{'dbcalendar'} = ''); ($self->{'dbclient'}) || ($self->{'dbclient'} = ''); ($self->{'dbhost'}) || ($self->{'dbhost'} = ''); } # Set the default calendar header $self->{'header'} = sprintf("
$header | |
$thisday";
# Add admin links if specified in function call
if ($addurl) {
my $calid = $self->calendarid();
my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
$html .= " [Add]"; } if ($editurl) { my $calid = $self->calendarid(); my $mdate = $self->month().'_'.$thisday.'_'.$self->year(); $html .= " [Edit]"; } $html .= " | $content |
$header | ||||||
Sunday | \nMonday | \nTuesday | \nWednesday | \nThursday | \nFriday | \nSaturday | \n
---|---|---|---|---|---|---|
Sunday | \nMonday | \nTuesday | \nWednesday | \nThursday | \nFriday | \nSaturday | \n
$thiscontent | \n"; } $html .= "
Hello World
"); $cal->addcontent(16,"Hello Again
"); print $cal->getcontent(16); # Prints 2 sentences # Padded and decimal numbers may be used, as well: $cal->setcontent(3.14159,'Third of the month'); $cal->addcontent('00003.0000','Still the third'); $cal->getcontent('3'); # Gets the 2 sentences # The second Sunday of May is some holiday or another... $cal->addcontent('2sunday','Some Special Day') if ($cal->month() == 5); # So is the third wednesday of this month $cal->setcontent('3WedNEsDaY','Third Wednesday!'); # What's scheduled for the second Friday? $cal->getcontent('2FRIDAY'); # Every Wednesday and Friday of this month... $cal->addcontent('wednesdays','Every Wednesday!'); $cal->getcontent('Fridays'); =head2 as_HTML(ARGUMENTS) =head2 as_HTML_list(ARGUMENTS) These methods return a string containing the HTML calendar for the month. as_HTML() returns a standard 7 column table, while as_HTML_list() returns a two-column list format calendar. Examples: print $cal->as_HTML(); print $cal->as_HTML_list('editurl'=>'editcal.cgi', 'addurl'=>'addcal.cgi'); Two optional arguments may be passed, in order to ease the integration of adminitrative front-ends: 'editurl' (Will add a [edit] link in each day's cell to specified url like so- http://editurl?date=month_day_year&calid=calendarid.) 'addurl' (Will add a [add] link in each day's cell to specified url like so- http://addurl?date=month_day_year&calid=calendarid.) =head2 year() =head2 month() =head2 monthname() These methods simply return the year/month of the calendar. monthname() returns the text name of the month, e.g. "December". =head2 getdbcontent() Loads calendar event content from database. =head2 getdbcalendar() Loads calendar formatting data from database. =head2 editdbcalendar(ARGUMENTS) Edits calendar formatting attributes stored in database. Takes any or all of the following arguments: =over 4 =item * 'border' size of calendar border, integer =item * 'width' width of calendar, should be in pixels or % =item * 'bgcolor' background color of calendar =item * 'weekdaycolor' background color of weekday cells =item * 'weekendcolor' background color of weekend cells =item * 'todaycolor' background color of today's cell =item * 'bordercolor' border color of calendar =item * 'weekdaybordercolor' border color of weekday cells =item * 'weekendbordercolor' border color of weekend cells =item * 'todaybordercolor' border color of today's cell =item * 'contentcolor' color of cell content =item * 'weekdaycontentcolor' color of weekday cell content =item * 'weekendcontentcolor' color of weekend cell content =item * 'todaycontentcolor' color of today's cell content =item * 'headercolor' background color of header cell =item * 'weekdayheadercolor' background color of weekday header cell =item * 'weekendheadercolor' background color of weekend header cell =item * 'header' header text, defaults to 'Month Year' if not specified or '' =item * 'cellalignment' alignment of text within cells, defaults to left, other valid values include right, center =back =head2 editdbevent(ARGUMENTS) Edits specific event attributes in database. Arguments: =over 4 =item * 'eventid' id of specific event, required =item * 'eventname' name of event =item * 'eventdesc' event description =item * 'eventlink' event link =item * 'eventtime' event time =back =head2 getdbevent(DATE) Takes an argument of the date(day) and returns a hash of event id's and their attributes for the specified day in this form: hash{eventid}{eventattribute} Useful as a function to be used in admin tools. =head2 border([INTEGER]) This specifies the value of the border attribute to the 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.
=head2 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(" |