view release on metacpan or search on metacpan
CalendarMonthDB.pm view on Meta::CPAN
# 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
CalendarMonthDB.pm view on Meta::CPAN
   $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("<center><font size=+2>%s %d</font></center>",
                               Date::Calc::Month_to_Text($self->{'month'}),$self->{'year'});
   # Get the monthname now so monthname() is fast and efficient
   $self->{'monthname'} = Date::Calc::Month_to_Text($self->{'month'});
   # Initialize the (empty) cell content so the keys are representative of the month
   map { $self->{'content'}->{$_} = ''; } (1 .. Date::Calc::Days_in_Month($self->{'year'},$self->{'month'}));
   # Initialize the non-standard date buckets: weekdays, etc.
   foreach my $day ('sunday','monday','tuesday','wednesday','thursday','friday','saturday') {
CalendarMonthDB.pm view on Meta::CPAN
                                                $thiscontentcolor = $weekdaycontentcolor;
                                            }
	
	if (!$content) {
        $content = ' '; 
	}
  	$html .= "<tr><td width=\"2%\"><b>$thisday</b>";
	# Add admin links if specified in function call 
        if ($addurl) {
	        my $calid = $self->calendarid();
       		my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
                $html .= "<br><font size=\"1\"><a href=\"#\" onclick=popup(\"$addurl?date=$mdate&calid=$calid&view=list\")>[Add]</a></font>";
                }
        if ($editurl) {
        	my $calid = $self->calendarid();
        	my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
                $html .= "<br><font size=\"1\"><a href=\"#\" onclick=popup(\"$editurl?date=$mdate&calid=$calid&view=list\")>[Edit]</a></font>";
	}
	$html .= "</td><td bgcolor=\"$thisbgcolor\" bordercolor=\"$thisbordercolor\" align=\"$cellalignment\"><font color=\"$thiscontentcolor\">$content</font></td></tr>\n"; 
  	} 
   } 
   }
   $html .= '</table>';
   return $html;
}
CalendarMonthDB.pm view on Meta::CPAN
         # Get the cell content
         if (! $thisday) { # If it's a dummy cell, no content
            $thiscontent = ' '; }
         else { # A real date cell with potential content
            # Get the content
            if ($self->showdatenumbers()) { 
                $thiscontent = "<p><b>$thisday</b>";
	
		# Add admin links if specified in function call	
		if ($addurl) {
			my $calid = $self->calendarid();
                        my $mdate = $self->month().'_'.$thisday.'_'.$self->year();
                        $thiscontent .= " <font size=\"1\"><a href=\"#\" onclick=popup(\"$addurl?date=$mdate&calid=$calid&view=standard\")>[Add]</a></font>";
                }
		if ($editurl) {
                        my $calid = $self->calendarid();
                        my $mdate = $self->month().'_'.$thisday.'_'.$self->year();                        
			$thiscontent .= " <font size=\"1\"><a href=\"#\" onclick=popup(\"$editurl?date=$mdate&calid=$calid&view=standard\")>[Edit]</a></font>";
                }
		$thiscontent .= "</p>\n";
            }
            # Content for this specific date
            $thiscontent .= $self->getcontent($thisday);
            # Content for "2nd Wednesday", etc.
            $thiscontent .= $self->getcontent(int(1+($thisday/7.1)).('sunday','monday','tuesday','wednesday','thursday','friday','saturday')[$DAY]);
            # Content for "Wednesdays", etc.
CalendarMonthDB.pm view on Meta::CPAN
   my $self = shift;
   my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d\.]+$/;
   return $self->{'content'}->{$date};
}
sub getdbevent {
   my $self = shift;
   my $date = shift;
   my $month = $self->month();
   my $year = $self->year();	
   my $calendarid = $self->calendarid();
   my $dbname = $self->dbname();
   my $dbuser = $self->dbuser();
   my $dbpass = $self->dbpass();
   my $dbhost = $self->dbhost();
   $dbhost = ":host=$dbhost" if (!($dbhost eq ''));   
   my $dbclient = $self->dbclient();
   my %content;
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my($getContent)=$dbh->prepare("select eventid, eventday, eventmonth, eventyear, eventtime, eventname, eventdesc,eventlink from event where eventday= ? and eventmonth=? and eventyear=? and calendarid=? order by eventtime, eventid");
   $getContent->execute($date,$month,$year,$calendarid) || return $dbh->errstr();
   while (my($eventid,$eventday,$eventmonth,$eventyear,$eventtime,$eventname,$eventdesc,$eventlink) = $getContent->fetchrow_array()) {
	$content{$eventid}{'eventtime'} = $eventtime if $eventtime;
	$content{$eventid}{'eventday'} = $eventday if $eventday;
	$content{$eventid}{'eventmonth'} = $eventmonth if $eventmonth;
	$content{$eventid}{'eventyear'} = $eventyear if $eventyear;
	$content{$eventid}{'eventname'} = $eventname if $eventname;
	$content{$eventid}{'eventdesc'} = $eventdesc if $eventdesc;
	$content{$eventid}{'eventlink'} = $eventlink if $eventlink;
   }
   $dbh->disconnect();
   return %content;
}
sub getdbcalendar {
   my $self = shift;
   my $dbname = $self->dbname();
   my $dbuser = $self->dbuser();
   my $dbpass = $self->dbpass();
   my $dbhost = $self->dbhost();
   $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
   my $calendarid = $self->calendarid();
   my $dbclient = $self->dbclient();
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my($getCalendarInfo)=$dbh->prepare("select border,width,bgcolor,weekdaycolor,weekendcolor,todaycolor,bordercolor,weekdaybordercolor,weekendbordercolor,todaybordercolor,contentcolor,weekdaycontentcolor,weekendcontentcolor,todaycontentcolor,headerco...
   $getCalendarInfo->execute($calendarid) ||print $dbh->errstr();
   # load calendar formatting data from database and set values.
   while (my($border,$width,$bgcolor,$weekdaycolor,$weekendcolor,$todaycolor, $bordercolor,$weekdaybordercolor,$weekendbordercolor,$todaybordercolor,$contentcolor,$weekdaycontentcolor,$weekendcontentcolor,$todaycontentcolor,$headercolor,$weekdayheade...
	$self->border($border) if $border;
	$self->width($width) if $width;
	$self->bgcolor($bgcolor) if $bgcolor;
	$self->weekdaycolor($weekdaycolor) if $weekdaycolor;
	$self->weekendcolor($weekendcolor) if $weekendcolor;
	$self->todaycolor($todaycolor) if $todaycolor;
	$self->bordercolor($bordercolor) if $bordercolor;
	$self->weekdaybordercolor($weekdaybordercolor) if $weekdaybordercolor;
	$self->weekendbordercolor($weekendbordercolor) if $weekendbordercolor;
CalendarMonthDB.pm view on Meta::CPAN
	$self->headercolor($headercolor) if $headercolor;
	$self->weekdayheadercolor($weekdayheadercolor) if $weekdayheadercolor;
	$self->weekendheadercolor($weekendheadercolor) if $weekendheadercolor;
	$self->header($header) if $header;
	$self->cellalignment($cellalignment) if $cellalignment;	
}  
   $dbh->disconnect();
}
sub editdbcalendar {
   my $self = shift;
   my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
   my $dbname = $self->dbname();
   my $dbuser = $self->dbuser();
   my $dbpass = $self->dbpass();
   my $dbhost = $self->dbhost();
   $dbhost = ":host=$dbhost" if (!($dbhost eq ''));
   my $calendarid = $self->calendarid();
   if ($self1->{'border'} && !($self1->{'border'} =~ /\d+/)) {
	$self1->{'border'} =1;
   }
   my $query = "update calendar set calendarid = ?";
   $query .= ", border = '".$self1->{'border'}."'" if $self1->{'border'}; 
   $query .= ", width = '".$self1->{'width'}."'" if $self1->{'width'};    $query .= ", bgcolor = '".$self1->{'bgcolor'}."'" if $self1->{'bgcolor'};
   $query .= ", weekdaycolor = '".$self1->{'weekdaycolor'}."'" if $self1->{'weekdaycolor'};
   $query .= ", weekendcolor = '".$self1->{'weekendcolor'}."'" if $self1->{'weekendcolor'};
   $query .= ", todaycolor = '".$self1->{'todaycolor'}."'" if $self1->{'todaycolor'};
   $query .= ", bordercolor = '".$self1->{'bordercolor'}."'" if $self1->{'bordercolor'};
   $query .= ", weekdaybordercolor = '".$self1->{'weekdaybordercolor'}."'" if $self1->{'weekdaybordercolor'};
   $query .= ", weekendbordercolor = '".$self1->{'weekendbordercolor'}."'" if $self1->{'weekendbordercolor'};
   $query .= ", todaybordercolor = '".$self1->{'todaybordercolor'}."'" if $self1->{'todaybordercolor'};
   $query .= ", contentcolor = '".$self1->{'contentcolor'}."'" if $self1->{'contentcolor'};
   $query .= ", weekdaycontentcolor = '".$self1->{'weekdaycontentcolor'}."'" if $self1->{'weekdaycontentcolor'};
   $query .= ", weekendcontentcolor = '".$self1->{'weekendcontentcolor'}."'" if $self1->{'weekendcontentcolor'};
   $query .= ", todaycontentcolor = '".$self1->{'todaycontentcolor'}."'" if $self1->{'todaycontentcolor'};
   $query .= ", headercolor = '".$self1->{'headercolor'}."'" if $self1->{'headercolor'};
   $query .= ", weekdayheadercolor = '".$self1->{'weekdayheadercolor'}."'" if $self1->{'weekdayheadercolor'};
   $query .= ", weekendheadercolor = '".$self1->{'weekendheadercolor'}."'" if $self1->{'weekendheadercolor'};
   $query .= ", header = '".$self1->{'header'}."'" if $self1->{'header'};
   $query .= ", cellalignment = '".$self1->{'cellalignment'}."'" if $self1->{'cellalignment'};
   $query .= " where calendarID = ?";
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my $updateCal = $dbh->prepare($query);
   $updateCal->execute($calendarid, $calendarid) ||print $dbh->errstr();
   $dbh->disconnect();
    
   return(1);
}
sub getdbcontent {
   my $self = shift;
   my $dbname = $self->dbname();
   my $dbuser = $self->dbuser();
   my $dbpass = $self->dbpass();
   my $dbhost = $self->dbhost();
   $dbhost = ":host=$dbhost" if (!($dbhost eq ''));   
   my $calendarid = $self->calendarid();
   my $dbclient = $self->dbclient();
   my $month = $self->month();
   my $year = $self->year(); 
   my $jsDescs='';
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my($getContent)=$dbh->prepare("select eventID, eventTime, eventDay, eventName, eventDesc, eventLink from event where calendarID = ? and eventMonth = ? and eventYear = ? order by eventDay, eventTime");
 
   $getContent->execute($calendarid, $month, $year) ||print $dbh->errstr();
   while (my($eventID, $eventTime, $eventDay, $eventName, $eventDesc, $eventLink) = $getContent->fetchrow_array()) {
	$eventLink = '#' if !$eventLink;	
	$self->{'content'}->{$eventDay} .= "$eventTime:" if $eventTime;
  	$self->{'content'}->{$eventDay} .= "<a href='$eventLink' onMouseOver='popLayer($eventID)' onMouseOut='hideLayer(-50000)'>$eventName</a><br><br>"; 
   
	$jsDescs .="if (a==$eventID) desc += \"$eventDesc\";\n";
   }
   $getContent->finish(); 
   $dbh->disconnect();
CalendarMonthDB.pm view on Meta::CPAN
}
sub adddbevent {
   my $self = shift;
   my $self1 = {}; %$self1 = @_; # Load ourselves up from the args
   my $dbname = $self->dbname();
   my $dbuser = $self->dbuser();
   my $dbpass = $self->dbpass();
   my $dbhost = $self->dbhost();
   $dbhost = ":host=$dbhost" if (!($dbhost eq '')); 
   my $dbcalendar = $self->dbcalendar();
   my $month = $self->month();
   my $year = $self->year();
   my $calendarID=$self->calendarid();
   my $date = $self1->{'date'};
   my $eventname = $self1->{'eventname'};
   my $eventdesc = $self1->{'eventdesc'};
   $eventdesc =~ s/\s+/ /g;
   my $eventlink = $self1->{'eventlink'};
   my $eventtime = $self1->{'eventtime'};
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my $addContent= $dbh->prepare("insert into event (calendarid, eventday, eventmonth, eventyear, eventname, eventdesc, eventlink, eventtime) values(?, ?, ?, ?, ?, ?, ?, ?)");
   $addContent->execute($calendarID, $date, $month, $year, $eventname, $eventdesc, $eventlink, $eventtime)||print $dbh->errstr();
   $dbh->disconnect();
   return(1);
}
sub deldbevent {
my $self = shift;
my $eventid = shift;
my $dbname = $self->dbname();
my $dbuser = $self->dbuser();
my $dbpass = $self->dbpass();
CalendarMonthDB.pm view on Meta::CPAN
   $query .=  ", eventyear = '".$self1->{'eventyear'}."' " if $self1->{'eventyear'};
   $query .=  ", eventtime = '".$self1->{'eventtime'}."' " if $self1->{'eventtime'};
   $query .=  " where eventid = ?";
   my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
   my $editEvent= $dbh->prepare($query);
   $editEvent->execute($eventid, $eventid) ||print $dbh->errstr();
   $dbh->disconnect();
   return(1);
}
sub calendarid {
my $self = shift;
my $dbname = $self->dbname();
my $dbuser = $self->dbuser();
my $dbpass = $self->dbpass();
my $dbhost = $self->dbhost();
$dbhost = ":host=$dbhost" if (!($dbhost eq ''));
my $dbcalendar = $self->dbcalendar();
my $dbclient = $self->dbclient();
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname$dbhost", $dbuser, $dbpass) || return;
  
my($getCalendarID)=$dbh->prepare("select calendar.calendarID from calendar, client where calendar.name= ? and calendar.clientID=client.clientID and client.clientName= ?");
   
$getCalendarID->execute($dbcalendar, $dbclient) ||print $dbh->errstr();
my $calendarID=$getCalendarID->fetchrow_array();
   
$getCalendarID->finish();
$dbh->disconnect();
$self->{'calendarid'} = $calendarID;
return $self->{'calendarid'};
}
sub border {
   my $self = shift;
   my $newvalue = shift;
   if (defined($newvalue)) { $self->{'border'} = int($newvalue); }
   return $self->{'border'};
}
sub jsDescs {
CalendarMonthDB.pm view on Meta::CPAN
sub dbuser {
   my $self = shift;
   return $self->{'dbuser'};
}
sub dbpass {
   my $self = shift;
   return $self->{'dbpass'};
}
sub dbcalendar {
   my $self = shift;
   return $self->{'dbcalendar'};
}
sub dbclient {
   my $self = shift;
   return $self->{'dbclient'};
}
sub dbhost {
   my $self = shift;
   return $self->{'dbhost'};
CalendarMonthDB.pm view on Meta::CPAN
__END__;
#################################################################################
=head1 NAME
    HTML::CalendarMonthDB - Perl Module for Generating Persistant HTML
    Calendars
=head1 SYNOPSIS
       use HTML::CalendarMonthDB;
       $cal = new HTML::CalendarMonthDB('year'=>2001,'month'=>2, 'dbname'=>'test', 'dbuser'=>'postgres', 'dbpass'=>'', 'dbcalendar'=>'testcal', 'dbclient'=>'testClient');
       $cal->width('50%'); # non-persistant
       $cal->border(10);   # non-persistant
       $cal->header('Text at the top of the Grid'); # non-persistant
       $cal->bgcolor('pink');
       $cal->editdbcalendar('width'=>'50%', 'border'=>10, 'header'=>'Text at the top of the Grid', 'bgcolor'=>'pink'); # persistant, stored in DB.
       $cal->setcontent(14,"Don't forget to buy flowers"); # non-persistant
       $cal->addcontent(13,"Guess what's tomorrow?"); # non-persistant
       $cal->adddbevent('date'=>'14', 'eventname'=>'Don't forget to buy flowers'); # persistant, stored in db
       $cal->adddbevent('date'=>'13', 'eventname'=>'Guess what's tomorrow?', 'eventdesc'=>'A big surprise is happening tommorrow.  Click here to see more!!', 'eventlink'=>'http://www.surprise.com'); # persistant, stored in db
       print $cal->as_HTML; # print standard 7 column calendar
       print $cal->as_HTML_list; # print HTML calendar as list
=head1 DESCRIPTION
    HTML::CalendarMonthDB is a Perl module for generating, manipulating, and
    printing a HTML calendar grid for a specified month. It is intended as a
    faster and easier-to-use alternative to HTML::CalendarMonth. It is based
    on HTML::CalendarMonthSimple, but can store persistant data into a
    database, as well as adding features like per-event links, descriptions,
    and times.
    This module requires the Date::Calc module, which is available from
    CPAN.
=head1 INTERFACE METHODS
=head2 new(ARGUMENTS)
    Naturally, new() returns a newly constructed calendar object. Recognized
    arguments include 'year' and 'month', to specify which month's calendar
    will be used. If either is omitted, the current value is used. An
    important note is that the month and the year are NOT the standard C or
    Perl -- use a month in the range 1-12 and a real year, e.g. 2001. If
    this is to be a persistant calendar (you wish to store info in a
    database), there are other arguments:
    * 'dbname' (name of database to use, required if you wish to use a
    database)
    * 'dbuser' (database user, default 'nobody')
    * 'dbpass' (database user password, default '')
    * 'dbcalendar' (database calendar name, default '')
    * 'dbclient' (database calendar client name, default '')
    * 'dbhost' (database host name, default '')
       # Examples:
       # Create a calendar for this month.
       $cal = new HTML::CalendarMonthSimple(); # not persistant
       # One for a specific month/year
       $cal = new HTML::CalendarMonthSimple('month'=>2,'year'=>2000); # not persistant
       # One for "the current month" in 1997
       $cal = new HTML::CalendarMonthSimple('year'=>1997); # not persistant
   
       # One for a specific month/year, to use database specified
       $cal = new HTML::CalendarMonthSimple('month'=>2,'year'=>2000,'dbname'=>'test','dbuser'=>postgres,'dbcalendar'=>'testcal','dbclient'=>'testClient');
=head2 deldbevent (EVENTID)
    Permanently deletes record from database associated with the event id
    passed in.
=head2 adddbevent (ARGUMENTS)
    Add persistant event for date (day) specified within current month and
    year. The following are arguments:
    * 'eventname' (name of event)
    * 'eventdesc' (event description, optional)
    * 'eventlink' (event link, optional)
    * 'eventtime' (event time, optional)
=head2 addevent(DATE,STRING)
=head2 getcontent(DATE)
    These methods are used to control the content of date cells within the
    calendar grid. The DATE argument may be a numeric date or it may be a
    string describing a certain occurrence of a weekday, e.g. "3MONDAY" to
    represent "the third Monday of the month being worked with", or it may
    be the plural of a weekday name, e.g. "wednesdays" to represent all
    occurrences of the given weekday. The weekdays are case-insensitive.
       # Examples:
       # The cell for the 15th of the month will now say something.
       $cal->setcontent(15,"An Important Event!");
       # Later down the program, we want the content to be boldfaced.
       $foo = "<b>" . $cal->getcontent(15) . "</b>";
CalendarMonthDB.pm view on Meta::CPAN
       # 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:
    * 'border' (size of calendar border, integer)
    * 'width' (width of calendar, should be in pixels or %)
    * 'bgcolor' (background color of calendar)
    * 'weekdaycolor' (background color of weekday cells)
    * 'weekendcolor' (background color of weekend cells)
    * 'todaycolor' (background color of today's cell)
    * 'bordercolor' (border color of calendar)
    * 'weekdaybordercolor' (border color of weekday cells)
    * 'weekendbordercolor' (border color of weekend cells)
    * 'todaybordercolor' (border color of today's cell)
    * 'contentcolor' (color of cell content)
    * 'weekdaycontentcolor' (color of weekday cell content)
    * 'weekendcontentcolor' (color of weekend cell content)
    * 'todaycontentcolor' (color of today's cell content)
    * 'headercolor' (background color of header cell)
    * 'weekdayheadercolor' (background color of weekday header cell)
    * 'weekendheadercolor' (background color of weekend header cell)
CalendarMonthDB.pm view on Meta::CPAN
=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 <TABLE>
    declaration for the calendar. As such, this controls the thickness of
    the border around the calendar table. The default value is 5.
    If a value is not specified, the current value is returned. If a value
    is specified, the border value is changed and the new value is returned.
=head2 width([INTEGER][%])
    This sets the value of the width attribute to the <TABLE> declaration
    for the calendar. As such, this controls the horizintal width of the
    calendar.
    The width value can be either an integer (e.g. 600) or a percentage
    string (e.g. "80%"). Most web browsers take an integer to be the table's
    width in pixels and a percentage to be the table width relative to the
    screen's width. The default width is "100%".
    If a value is not specified, the current value is returned. If a value
    is specified, the border value is changed and the new value is returned.
       # Examples:
CalendarMonthDB.pm view on Meta::CPAN
    date labels in each cell (e.g. a 1 on the 1st, a 2 on the 2nd, etc.) If
    set to 0, then the date labels will not be printed. The default is 1.
    If no value is specified, the current value is returned.
    The date numbers are shown in boldface, normal size font. If you want to
    change this, consider setting showdatenumbers() to 0 and using
    setcontent()/addcontent() instead.
=head2 showweekdayheaders([1 or 0])
    If showweekdayheaders() is set to 1 (the default) then calendars
    rendered via as_HTML() will display the names of the days of the week.
    If set to 0, the days' names will not be displayed.
    If no value is specified, the current value is returned.
=head2 cellalignment([STRING])
    This sets the value of the align attribute to the <TD> 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() );
CalendarMonthDB.pm view on Meta::CPAN
    These define the colors of the cells. If a string (which should be
    either a HTML color-code like '#000000' or a color-word like 'yellow')
    is supplied as an argument, then the color is set to that specified.
    Otherwise, the current value is returned. To un-set a value, try
    assigning the null string as a value.
    The bgcolor defines the color of all cells. The weekdaycolor overrides
    the bgcolor for weekdays (Monday through Friday), the weekendcolor
    overrides the bgcolor for weekend days (Saturday and Sunday), and the
    todaycolor overrides the bgcolor for today's date. (Which may not mean a
    lot if you're looking at a calendar other than the current month.)
    The weekdayheadercolor overrides the bgcolor for the weekday headers
    that appear at the top of the calendar if showweekdayheaders() is true,
    and weekendheadercolor does the same thing for the weekend headers. The
    headercolor overrides the bgcolor for the month/year header at the top
    of the calendar.
    The colors of the cell borders may be set: bordercolor determines the
    color of the calendar grid's outside border, and is the default color of
    the inner border for individual cells. The inner bordercolor may be
    overridden for the various types of cells via weekdaybordercolor,
    weekendbordercolor, and todaybordercolor.
    Finally, the color of the cells' contents may be set with contentcolor,
    weekdaycontentcolor, weekendcontentcolor, and todaycontentcolor. The
    contentcolor is the default color of cell content, and the other methods
    override this for the appropriate days' cells.
       # Example:
       $cal->bgcolor('white');                 # Set the default cell color
       $cal->bordercolor('green');             # Set the default border color
       $cal->contentcolor('black');            # Set the default content color
       $cal->headercolor('yellow');            # Set the color of the Month+Year header
       $cal->weekdayheadercolor('orange');     # Set the color of weekdays' headers
       $cal->weekendheadercolor('pink');       # Set the color of weekends' headers
       $cal->weekendcolor('palegreen');        # Override weekends' cell color
       $cal->weekendcontentcolor('blue');      # Override weekends' content color
       $cal->todaycolor('red');                # Override today's cell color
       $cal->todaycontentcolor('yellow');      # Override today's content color
       print $cal->as_HTML;                    # Print a really ugly calendar!
=head1 BUGS, TODO, CHANGES
    No known bugs, though contributions and improvements are welcome, this
    is currently a first run.
=head1 AUTHORS, CREDITS, COPYRIGHTS
    This Perl module is freeware. It may be copied, derived, used, and
    distributed without limitation.
    HTML::CalendarMonthDB is based on HTML::CalendarMonthSimple by Gregor
IMPORTANT-README view on Meta::CPAN
*** If you wish to use the cgi admin tool included, you must have HTML::Template and URI::Escape. You can get them from CPAN.
***** If you wish to use this module with database support (for persistant calendars), you MUST create the appropriate tables in your Postgres database (more databases to follow). ***** 
-A perl script (setup_calendar.pl) has been included to help you with this task. 	-It will attempt to ask questions, then create a .sql script.  If you will be using a local database, it can also attempt to run the script for you.  The tables needed,...
	-In addition, if you plan on using the cgi scripts included for calendar administration, you will probably want to take the environament variables output and add them to your webserver config.
-Below is the database design, if you wish to add the tables manually.
##############################################################################
               List of relations
          Name           |   Type   |  Owner   
-------------------------+----------+----------
 calendar                | table    | postgres
 calendar_calendarid_seq | sequence | postgres
 client                  | table    | postgres
 client_clientid_seq     | sequence | postgres
 event                   | table    | postgres
 event_eventid_seq       | sequence | postgres
(6 rows)
                                             Table "calendar"
      Attribute      |         Type          |                          Modifier                           
---------------------+-----------------------+-------------------------------------------------------------
 calendarid          | integer               | not null default nextval('"calendar_calendarid_seq"'::text)
 clientid            | integer               | not null
 name                | character varying(64) | not null
 border              | integer               | 
 width               | character varying(8)  | 
 bgcolor             | character varying(12) | 
 weekdaycolor        | character varying(12) | 
 weekendcolor        | character varying(12) | 
 todaycolor          | character varying(12) | 
 weekdaybordercolor  | character varying(12) | 
 weekendbordercolor  | character varying(12) | 
IMPORTANT-README view on Meta::CPAN
 contentcolor        | character varying(12) | 
 weekdaycontentcolor | character varying(12) | 
 weekendcontentcolor | character varying(12) | 
 todaycontentcolor   | character varying(12) | 
 headercolor         | character varying(12) | 
 weekdayheadercolor  | character varying(12) | 
 weekendheadercolor  | character varying(12) | 
 header              | character varying(64) | 
 cellalignment       | character varying(12) | 
 bordercolor         | character varying(12) | 
Index: calendar_pkey
                                        Table "client"
 Attribute  |         Type          |                        Modifier                         
------------+-----------------------+---------------------------------------------------------
 clientid   | integer               | not null default nextval('"client_clientid_seq"'::text)
 clientname | character varying(64) | not null
Index: client_pkey
                                        Table "event"
 Attribute  |          Type          |                       Modifier                        
------------+------------------------+-------------------------------------------------------
 eventid    | integer                | not null default nextval('"event_eventid_seq"'::text)
 eventtime  | time                   | 
 calendarid | integer                | 
 eventday   | integer                | not null
 eventmonth | integer                | not null
 eventyear  | integer                | not null
 eventname  | character varying(128) | not null
 eventdesc  | text                   | 
 eventlink  | character varying(128) | 
Index: event_pkey
Sequence "calendar_calendarid_seq"
   Attribute   |  Type   
---------------+---------
 sequence_name | name
 last_value    | integer
 increment_by  | integer
 max_value     | integer
 min_value     | integer
 cache_value   | integer
 log_cnt       | integer
 is_cycled     | "char"
	C. %> perl Makefile.PL
	   if all goes well:
	   %> make
	   %> make install
*********	
2. Create postgres database tables:
	
	A. If you wish to use another database type, you will have to change the code a bit.  Sorry, I haven't had time to do this myself.
	B. Run the setup_calendar.pl script included in the distribution.  This script will ask you for database information, and will create a postgres SQL script for you to run.  If the database is local, it will attempt to run the script if you so desire...
	C. For more information about the database set up, see IMPORTANT-README.
*********
3. If you wish to use the admin tool that comes with this distribution:
	
	A. Please note that this admin tool is only set up to handle one calendar (from database), not multiple ones.  
	B. When you ran setup_calendar.pl, some environment variables were output that you should use in your webserver configuration.  If you are running apache, this should be simply a matter of cut-n-paste, restart webserver.  These environment variables...
	C. Place all files from the cgi/ directory within the distribution into an appropriate place.  They must all be in the same directory, unless you wish to change the code.
	D. HTML::Template and URI::Escape need to be installed for these cgi scripts to run.
	
	E. You may wish to modify the .tmpl files, these are basically HTML containers for the calendar admin.
	F. If you wish to publish the calendars to HTML, make sure the directory you have set in @ENV to publish to exists and that the user running your webserver has permissions to write in it.
*********
4. That's it!  This is the first, rough version.  All should work, but there may be things that should/could be done differently or better.  Please feel free to email me with comments/suggestions/questions. 
- Matt Vella the_mcv@yahoo.com
MANIFEST
Makefile.PL
CalendarMonthDB.pm
README
IMPORTANT-README
setup_calendar.pl
cgi/addcal.cgi
cgi/addcal.tmpl
cgi/caladmin.tmpl
cgi/calendar.cgi
cgi/editcal.cgi
cgi/editcal.tmpl
NAME
    HTML::CalendarMonthDB - Perl Module for Generating Persistant HTML
    Calendars
SYNOPSIS
       use HTML::CalendarMonthDB;
       $cal = new HTML::CalendarMonthDB('year'=>2001,'month'=>2, 'dbname'=>'test', 'dbuser'=>'postgres', 'dbpass'=>'', 'dbcalendar'=>'testcal', 'dbclient'=>'testClient');
       $cal->width('50%'); # non-persistant
       $cal->border(10);   # non-persistant
       $cal->header('Text at the top of the Grid'); # non-persistant
       $cal->bgcolor('pink');
       $cal->editdbcalendar('width'=>'50%', 'border'=>10, 'header'=>'Text at the top of the Grid', 'bgcolor'=>'pink'); # persistant, stored in DB.
       $cal->setcontent(14,"Don't forget to buy flowers"); # non-persistant
       $cal->addcontent(13,"Guess what's tomorrow?"); # non-persistant
       $cal->adddbevent('date'=>'14', 'eventname'=>'Don't forget to buy flowers'); # persistant, stored in db
       $cal->adddbevent('date'=>'13', 'eventname'=>'Guess what's tomorrow?', 'eventdesc'=>'A big surprise is happening tommorrow.  Click here to see more!!', 'eventlink'=>'http://www.surprise.com'); # persistant, stored in db
       print $cal->as_HTML; # print standard 7 column calendar
       print $cal->as_HTML_list; # print HTML calendar as list
DESCRIPTION
    HTML::CalendarMonthDB is a Perl module for generating, manipulating, and
    printing a HTML calendar grid for a specified month. It is intended as a
    faster and easier-to-use alternative to HTML::CalendarMonth. It is based
    on HTML::CalendarMonthSimple, but can store persistant data into a
    database, as well as adding features like per-event links, descriptions,
    and times.
        This module requires the Date::Calc module, which is available from
        CPAN.
INTERFACE METHODS
  new(ARGUMENTS)
    Naturally, new() returns a newly constructed calendar object. Recognized
    arguments include 'year' and 'month', to specify which month's calendar
    will be used. If either is omitted, the current value is used. An
    important note is that the month and the year are NOT the standard C or
    Perl -- use a month in the range 1-12 and a real year, e.g. 2001. If
    this is to be a persistant calendar (you wish to store info in a
    database), there are other arguments:
        * 'dbname' (name of database to use, required if you wish to use a
        database)
        * 'dbuser' (database user, default 'nobody')
        * 'dbpass' (database user password, default '')
        * 'dbcalendar' (database calendar name, default '')
        * 'dbclient' (database calendar client name, default '')
        * 'dbhost' (database host name, default '')
           # Examples:
           # Create a calendar for this month.
           $cal = new HTML::CalendarMonthSimple(); # not persistant
           # One for a specific month/year
           $cal = new HTML::CalendarMonthSimple('month'=>2,'year'=>2000); # not persistant
           # One for "the current month" in 1997
           $cal = new HTML::CalendarMonthSimple('year'=>1997); # not persistant
   
           # One for a specific month/year, to use database specified
           $cal = new HTML::CalendarMonthSimple('month'=>2,'year'=>2000,'dbname'=>'test','dbuser'=>postgres,'dbcalendar'=>'testcal','dbclient'=>'testClient');
  deldbevent (EVENTID)
    Permanently deletes record from database associated with the event id
    passed in.
  adddbevent (ARGUMENTS)
    Add persistant event for date (day) specified within current month and
    year. The following are arguments:
        * 'eventname' (name of event)
        * 'eventdesc' (event description, optional)
        * 'eventlink' (event link, optional)
        * 'eventtime' (event time, optional)
    =head2 addevent(DATE,STRING)
  getcontent(DATE)
    These methods are used to control the content of date cells within the
    calendar grid. The DATE argument may be a numeric date or it may be a
    string describing a certain occurrence of a weekday, e.g. "3MONDAY" to
    represent "the third Monday of the month being worked with", or it may
    be the plural of a weekday name, e.g. "wednesdays" to represent all
    occurrences of the given weekday. The weekdays are case-insensitive.
           # Examples:
           # The cell for the 15th of the month will now say something.
           $cal->setcontent(15,"An Important Event!");
           # Later down the program, we want the content to be boldfaced.
           $foo = "<b>" . $cal->getcontent(15) . "</b>";
           # 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');
  as_HTML(ARGUMENTS)
  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.)
  year()
  month()
  monthname()
    These methods simply return the year/month of the calendar. monthname()
    returns the text name of the month, e.g. "December".
  getdbcontent()
    Loads calendar event content from database.
  getdbcalendar()
    Loads calendar formatting data from database.
  editdbcalendar(ARGUMENTS)
    Edits calendar formatting attributes stored in database. Takes any or
    all of the following arguments:
        * 'border' (size of calendar border, integer)
        * 'width' (width of calendar, should be in pixels or %)
        * 'bgcolor' (background color of calendar)
        * 'weekdaycolor' (background color of weekday cells)
        * 'weekendcolor' (background color of weekend cells)
        * 'todaycolor' (background color of today's cell)
        * 'bordercolor' (border color of calendar)
        * 'weekdaybordercolor' (border color of weekday cells)
        * 'weekendbordercolor' (border color of weekend cells)
        * 'todaybordercolor' (border color of today's cell)
        * 'contentcolor' (color of cell content)
        * 'weekdaycontentcolor' (color of weekday cell content)
        * 'weekendcontentcolor' (color of weekend cell content)
        * 'todaycontentcolor' (color of today's cell content)
        * 'headercolor' (background color of header cell)
        * 'weekdayheadercolor' (background color of weekday header cell)
        * 'weekendheadercolor' (background color of weekend header cell)
  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.
  border([INTEGER])
    This specifies the value of the border attribute to the <TABLE>
    declaration for the calendar. As such, this controls the thickness of
    the border around the calendar table. The default value is 5.
        If a value is not specified, the current value is returned. If a value
        is specified, the border value is changed and the new value is returned.
  width([INTEGER][%])
    This sets the value of the width attribute to the <TABLE> declaration
    for the calendar. As such, this controls the horizintal width of the
    calendar.
        The width value can be either an integer (e.g. 600) or a percentage
        string (e.g. "80%"). Most web browsers take an integer to be the table's
        width in pixels and a percentage to be the table width relative to the
        screen's width. The default width is "100%".
        If a value is not specified, the current value is returned. If a value
        is specified, the border value is changed and the new value is returned.
           # Examples:
    date labels in each cell (e.g. a 1 on the 1st, a 2 on the 2nd, etc.) If
    set to 0, then the date labels will not be printed. The default is 1.
        If no value is specified, the current value is returned.
        The date numbers are shown in boldface, normal size font. If you want to
        change this, consider setting showdatenumbers() to 0 and using
        setcontent()/addcontent() instead.
  showweekdayheaders([1 or 0])
    If showweekdayheaders() is set to 1 (the default) then calendars
    rendered via as_HTML() will display the names of the days of the week.
    If set to 0, the days' names will not be displayed.
        If no value is specified, the current value is returned.
  cellalignment([STRING])
    This sets the value of the align attribute to the <TD> 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.
  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() );
    These define the colors of the cells. If a string (which should be
    either a HTML color-code like '#000000' or a color-word like 'yellow')
    is supplied as an argument, then the color is set to that specified.
    Otherwise, the current value is returned. To un-set a value, try
    assigning the null string as a value.
        The bgcolor defines the color of all cells. The weekdaycolor overrides
        the bgcolor for weekdays (Monday through Friday), the weekendcolor
        overrides the bgcolor for weekend days (Saturday and Sunday), and the
        todaycolor overrides the bgcolor for today's date. (Which may not mean a
        lot if you're looking at a calendar other than the current month.)
        The weekdayheadercolor overrides the bgcolor for the weekday headers
        that appear at the top of the calendar if showweekdayheaders() is true,
        and weekendheadercolor does the same thing for the weekend headers. The
        headercolor overrides the bgcolor for the month/year header at the top
        of the calendar.
        The colors of the cell borders may be set: bordercolor determines the
        color of the calendar grid's outside border, and is the default color of
        the inner border for individual cells. The inner bordercolor may be
        overridden for the various types of cells via weekdaybordercolor,
        weekendbordercolor, and todaybordercolor.
        Finally, the color of the cells' contents may be set with contentcolor,
        weekdaycontentcolor, weekendcontentcolor, and todaycontentcolor. The
        contentcolor is the default color of cell content, and the other methods
        override this for the appropriate days' cells.
           # Example:
           $cal->bgcolor('white');                 # Set the default cell color
           $cal->bordercolor('green');             # Set the default border color
           $cal->contentcolor('black');            # Set the default content color
           $cal->headercolor('yellow');            # Set the color of the Month+Year header
           $cal->weekdayheadercolor('orange');     # Set the color of weekdays' headers
           $cal->weekendheadercolor('pink');       # Set the color of weekends' headers
           $cal->weekendcolor('palegreen');        # Override weekends' cell color
           $cal->weekendcontentcolor('blue');      # Override weekends' content color
           $cal->todaycolor('red');                # Override today's cell color
           $cal->todaycontentcolor('yellow');      # Override today's content color
           print $cal->as_HTML;                    # Print a really ugly calendar!
BUGS, TODO, CHANGES
    No known bugs, though contributions and improvements are welcome, this
    is currently a first run.
AUTHORS, CREDITS, COPYRIGHTS
    This Perl module is freeware. It may be copied, derived, used, and
    distributed without limitation.
        HTML::CalendarMonthDB is based on HTML::CalendarMonthSimple by Gregor
        Mosheh <stigmata@blackangel.net>. Many additions and modifications were
cgi/addcal.cgi view on Meta::CPAN
}
sub addEvent {
	my(%param)=@_;
        my ($cal);
        my $dbname = $ENV{'DB_NAME'};
        my $dbuser = $ENV{'DB_USER'};
        my $dbpass = $ENV{'DB_PASS'};
        my $dbclient = $ENV{'DB_CLIENT'};
        my $dbcalendar = $ENV{'DB_CALENDAR'};
	my $dbhost = $ENV{'DB_HOST'};
        my($month,$day,$year) = split('_', $param{'date'});
        my($calid)=$param{'calid'};
        $cal = new HTML::CalendarMonthDB('month'=>$month, 'year'=>$year, 'dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
	$cal->adddbevent('date'=>$day, 'eventname'=>$param{'eventName'}, 'eventdesc'=>$param{'eventDesc'}, 'eventlink'=>$param{'eventLink'});
}
sub addForm {
	my(%param)=@_;
        my ($htmlOut);
	my($month,$day,$year) = split('_', $param{'date'});
	my $view = $param{'view'};
	my $template = HTML::Template->new(filename => 'addcal.tmpl');
cgi/addcal.cgi view on Meta::CPAN
	$htmlOut .= '</td></tr><tr><td>Event Name</td><td><input type="text" name="eventName"></td></tr>';
	$htmlOut .= '<tr><td>Event Description</td><td><textarea name="eventDesc" rows=8 cols=30 wrap=virtual></textarea></td></tr>';
	$htmlOut .= '<tr><td>Event Link</td><td><input type="text" name="eventLink"></td></tr>';
	$htmlOut .= '<tr><td colspan="2"><center><input type="submit" name="add" value="Add This Event"></center></td></tr>';	
	$htmlOut .= '</table><input type="hidden" name="date" value="'.$param{'date'}.'" override="1"><input type="hidden" name="calid" value="'.$param{'calid'}.'" override="1">';
	$htmlOut .= '</form>'; 	
	$template->param(
        	ADD_CAL => $htmlOut,
		BODY_INCLUDE => "onload='self.opener.window.location=\"calendar.cgi?date=1&month=$month&year=$year&view=$view\"'"
	);
	# print the template
	print $template->output;
		
}
cgi/calendar.cgi view on Meta::CPAN
}
#####################################################
sub changeCal {
	my(%param)=@_;
	my ($cal);
	my $dbname = $ENV{'DB_NAME'};
	my $dbuser = $ENV{'DB_USER'};
	my $dbpass = $ENV{'DB_PASS'};
	my $dbclient = $ENV{'DB_CLIENT'};
	my $dbcalendar = $ENV{'DB_CALENDAR'};	
	my $dbhost = $ENV{'DB_HOST'};
	
	$cal = new HTML::CalendarMonthDB('dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);		
	$cal->editdbcalendar(border=>$param{'border'}, width=>$param{'width'}, bgcolor=>$param{'bgcolor'}, weekdaycolor=>$param{'weekdaycolor'}, weekendcolor=>$param{'weekendcolor'}, todaycolor=>$param{'todaycolor'}, bordercolor=>$param{'bordercolor'}, week...
}
##############
sub getCal {
	my(%param)=@_;
	my $template = HTML::Template->new(filename => 'caladmin.tmpl');
	my $dbname = $ENV{'DB_NAME'};
	my $dbuser = $ENV{'DB_USER'};
	my $dbpass = $ENV{'DB_PASS'};
	my $dbclient = $ENV{'DB_CLIENT'};
	my $dbcalendar = $ENV{'DB_CALENDAR'};
	my $dbhost = $ENV{'DB_HOST'};
	my $htmlOut;
	my($cal,$type,$month,$year);
$htmlOut .= '<form name="calform1" method="post" action="calendar.cgi">';
$param{'view'} = '' if !$param{'view'};
$htmlOut .= '<input type="radio" name="view" value="standard"';
if (($param{'view'} eq 'standard') || !$param{'view'}) {
	$htmlOut .= ' checked onclick="document.calform1.submit()">Standard  <input type="radio" name="view" value="list" onclick="document.calform1.submit()">List View<br>';
}
else {
	$htmlOut .= ' onclick="document.calform1.submit()">Standard  <input type="radio" name="view" value="list" checked onclick="document.calform1.submit()">List View<br>';
	$type=1;
}
if (!$param{'month'}) {
	$cal = new HTML::CalendarMonthDB('dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
	$month=$cal->month();
	$year=$cal->year();
}
else {
	if ($param{'date'} eq '<<') {
		$month=$param{'lmonth'};
		$year=$param{'lyear'};
	}
	elsif ($param{'date'} eq '>>') {
		$month=$param{'nmonth'};
                $year=$param{'nyear'};
        }
	else {
		$month=$param{'month'};
		$year=$param{'year'};
	}
		 
	$cal = new HTML::CalendarMonthDB('month'=>$month, 'year'=>$year, 'dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
        }
$htmlOut .= calNav($cal->month(), $cal->year());
$htmlOut .= '</form>';
$cal->getdbcalendar();
$cal->getdbcontent();
if (!$type) {
	$htmlOut .= $cal->as_HTML(editurl=>'editcal.cgi', addurl=>'addcal.cgi');
	if ($param{'publish'}) {
		my $pubdir=$ENV{'CAL_PUB_DIR'};
		my $pubfile= '>'.$pubdir.'/'.$month."_".$year.'.txt';	
		open(FILE, $pubfile) || print "Cannot open $pubfile for writing.";
		print FILE $cal->as_HTML();	
		close(FILE);	
cgi/calendar.cgi view on Meta::CPAN
	$htmlOut .= $cal->as_HTML_list(editurl=>'editcal.cgi', addurl=>'addcal.cgi');
	if ($param{'publish'}) {
                my $pubdir=$ENV{'CAL_PUB_DIR'};
		my $pubfile= '>'.$pubdir.'/'.$month."_".$year.'.cal';
                open(FILE, $pubfile) || print "Cannot open $pubfile for writing."; 
                print FILE $cal->as_HTML_list();
		close(FILE);
        }
}
$htmlOut .= '<br><br><form name="calchange" method="post" action="calendar.cgi">';
$htmlOut .= "<input type=\"hidden\" name=\"month\" value=\"$month\" override=\"1\">";
$htmlOut .= "<input type=\"hidden\" name=\"year\" value=\"$year\" override=\"1\">";
$htmlOut .= "<input type=\"hidden\" name=\"view\" value=\"".$param{'view'}."\" override=\"1\">"; 
$htmlOut .= "<input type=\"submit\" name=\"publish\" value=\"Publish this Month\">";
$htmlOut .= '<table border="1" cellpadding="3"><tr bgcolor="red"><td colspan="2"><b><font color="ffffff" size="4"><center>Modify Calendar Attributes</center></b></font></td></tr>';
#$htmlOut .= '<tr bgcolor="ddddff"><td></td><td><input type="text" name="" value="'.$cal->().'"></td></tr>'; #template
$htmlOut .= '<tr bgcolor="ddddff"><td>Border Size</td><td><input type="text" name="border" value="'.$cal->border().'"></td></tr>';
$htmlOut .= '<tr bgcolor="ddddff"><td>Width</td><td><input type="text" name="width" value="'.$cal->width().'"></td></tr>';
cgi/editcal.cgi view on Meta::CPAN
}
sub delCal {
	my ($delid)=shift;
	my ($cal);
	my $dbname = $ENV{'DB_NAME'};
        my $dbuser = $ENV{'DB_USER'};
        my $dbpass = $ENV{'DB_PASS'};
        my $dbclient = $ENV{'DB_CLIENT'};
        my $dbcalendar = $ENV{'DB_CALENDAR'};
	my $dbhost = $ENV{'DB_HOST'};
	$cal = new HTML::CalendarMonthDB('dbname'=>$dbname, 'dbpass'=>$dbpass, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
	$cal->deldbevent($delid);
}	
sub editCal {
	my(%param)=@_;
        my ($cal, $p);
        my $dbname = $ENV{'DB_NAME'};
        my $dbuser = $ENV{'DB_USER'};
        my $dbpass = $ENV{'DB_PASS'};
        my $dbclient = $ENV{'DB_CLIENT'};
        my $dbcalendar = $ENV{'DB_CALENDAR'};
	my $dbhost = $ENV{'DB_HOST'};
        my($month,$day,$year) = split('_', $param{'date'});
        my($calid)=$param{'calid'};
        $cal = new HTML::CalendarMonthDB('month'=>$month, 'year'=>$year, 'dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
	foreach	$p (keys %param) {
		if ($p =~ /eventname/ && $param{$p}) {
			$p =~ s/eventname_//;	
			$cal->editdbevent('eventid'=>$p, 'eventday'=>$param{'eventday_'.$p}, 'eventmonth'=>$param{'eventmonth_'.$p}, 'eventyear'=>$param{'eventyear_'.$p}, 'eventname'=>$param{'eventname_'.$p}, 'eventdesc'=>$param{'eventdesc_'.$p}, 'eventlink'=>$param{'eve...
		}	
	}
}
sub editForm {
	my(%param)=@_;
        my ($htmlOut);
	my($month,$day,$year) = split('_', $param{'date'});
	my $view = $param{'view'};
	my ($cal);
	my %content;
        my $dbname = $ENV{'DB_NAME'};
        my $dbuser = $ENV{'DB_USER'};
        my $dbpass = $ENV{'DB_PASS'};
        my $dbclient = $ENV{'DB_CLIENT'};
        my $dbcalendar = $ENV{'DB_CALENDAR'};
	my $dbhost = $ENV{'DB_HOST'};
	my $template = HTML::Template->new(filename => 'editcal.tmpl');
	if ($param{'changed'} eq 1) {
		$htmlOut .='<b><font color=blue>Events modified.</font></b><br>';
	}
	elsif ($param{'changed'} eq 2) {
		$htmlOut .='<b><font color=blue>Event deleted.</font></b><br>';
	}	
	$htmlOut .= '<form name="editform" method="post"><table border="0" cellpadding="3" bgcolor="ccccff">';
	$htmlOut .= "<tr bgcolor=\"red\"><td colspan=\"2\"><center><b>Edit Events for $month/$day/$year </b><font size=1> <a href=\"addcal.cgi?date=".$param{'date'}."&calid=".$param{'calid'}."&view=$view\">[Add event for $month/$day/$year]</a></font></cente...
	$htmlOut .= '</td></tr>';
	$cal = new HTML::CalendarMonthDB('month'=>$month, 'year'=>$year, 'dbname'=>$dbname, 'dbuser'=>$dbuser, 'dbcalendar'=>$dbcalendar, 'dbclient'=>$dbclient, 'dbhost'=>$dbhost);
	%content = $cal->getdbevent($day);
	my ($c,$exist);	
	foreach $c(keys %content) {
		 $exist=1;
		 $htmlOut .= '<tr bgcolor="8888ff"><td colspan=2 align="right"><input type="submit" name="delete_'.$c.'" value="Delete Event Below"></td></tr>';
		$htmlOut .= '<tr><td>Event Name</td><td><input type="text" name="eventname_'.$c.'" value="'.$content{$c}{'eventname'}.'"></td></tr>';
		$htmlOut .= '<tr><td>Event Date</td><td><input type="text" size="2" maxlength="2" name="eventmonth_'.$c.'" value="'.$content{$c}{'eventmonth'}.'"><b>/</b><input type="text" size="2" maxlength="2" name="eventday_'.$c.'" value="'.$content{$c}{'eventd...
		$htmlOut .= '<tr><td>Event Description</td><td><textarea rows=8 cols=30 wrap=virtual name="eventdesc_'.$c.'">'.$content{$c}{'eventdesc'}.'</textarea></td></tr>';
		$htmlOut .= '<tr><td>Event Link</td><td><input type="text" name="eventlink_'.$c.'" value="'.$content{$c}{'eventlink'}.'"></td></tr>';
			
cgi/editcal.cgi view on Meta::CPAN
	}
	else {
		$htmlOut .= '<tr><td colspan="2" bgcolor="red"><center><b><input type="submit" name="edit" value="Commit Changes"></b></center></td></tr>';	
	}	
	$htmlOut .= '</table><input type="hidden" name="date" value="'.$param{'date'}.'" override="1"><input type="hidden" name="calid" value="'.$param{'calid'}.'" override="1">';
	$htmlOut .= '</form>'; 	
	$template->param(
        	EDIT_CAL => $htmlOut,
		BODY_INCLUDE => "onload='self.opener.window.location=\"calendar.cgi?date=1&month=$month&year=$year&view=$view\"'"
	);
	# print the template
	print $template->output;
		
}
setup_calendar.pl view on Meta::CPAN
use strict;
my($clientname, $dbname, $dbhost, $dbuser, $dbpass, $calname, $pubdir, $answer);
## get db info etc
$dbhost = getinput("Enter valid postgres host (leave blank for localhost): ");
$dbname = getinput("Enter valid postgres database name: ", 1);
$dbuser = getinput("Enter valid database username: ", 1);
$dbpass = getinput("Enter valid database password for user $dbuser: ");
$clientname = getinput("Enter client (person owning calendar) name: ", 1);
$calname = getinput("Enter calendar name: ", 1);
$pubdir = getinput("Enter directory to where you wish to publish static calendars: ", 1);
# make postgres setup sql script
makeSql();
# attempt to run sql script?
if (!$dbhost) {
	$answer = getinput("SQL script has been created and stored in ./calendar.sql.\nDo you wish to attempt to run this script now? <yes/no>: [yes]");
	if (($answer eq "yes") || ($answer eq "y") || !$answer) {
		runScript();
	} 
	else {
		print "*** Skipping attempt, please run this script (./calendar.sql) later in order to set up proper database tables.\n\n";
	} 
}
else {
	print "*** SQL script has been created and stored in ./calendar.sql.\nPlease run this later on the database host in order to set up the proper database tables.\n\n";
}
# print out env variables
printEnv();
exit(1);
###################################################################
sub printEnv {
setup_calendar.pl view on Meta::CPAN
	print $list."\n\n";
}
sub runScript {
	my $psql = getinput("Please enter path to psql executable: [/usr/local/pgsql/bin/psql] ");
	
	$psql = '/usr/local/pgsql/bin/psql' if !$psql;
	print "\nRunning sql setup script, output below....\n\n";
	`$psql $dbname -U $dbuser < ./calendar.sql`;	
}
sub makeSql {
	open (FILE, ">./calendar.sql") || die("\nCannot open file ./calendar.sql for writing.  Please make sure you have the proper permissions to write into this directory.\n\n");
	
	print FILE '--
-- Selected TOC Entries:
--
\connect - '.$dbuser.'
--
-- TOC Entry ID 2 (OID 18851)
--
-- Name: client_clientid_seq Type: SEQUENCE Owner: '.$dbuser.'
--
setup_calendar.pl view on Meta::CPAN
CREATE TABLE "client" (
        "clientid" integer DEFAULT nextval(\'"client_clientid_seq"\'::text) NOT NULL,
        "clientname" character varying(64) NOT NULL,
        Constraint "client_pkey" Primary Key ("clientid")
);
--
-- TOC Entry ID 4 (OID 18977)
--
-- Name: calendar_calendarid_seq Type: SEQUENCE Owner: '.$dbuser.'
--
CREATE SEQUENCE "calendar_calendarid_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
--
-- TOC Entry ID 9 (OID 18996)
--
-- Name: calendar Type: TABLE Owner: '.$dbuser.'
--
CREATE TABLE "calendar" (
        "calendarid" integer DEFAULT nextval(\'"calendar_calendarid_seq"\'::text) NOT NULL,
        "clientid" integer NOT NULL,
        "name" character varying(64) NOT NULL,
        "border" integer,
        "width" character varying(8),
        "bgcolor" character varying(12),
        "weekdaycolor" character varying(12),
        "weekendcolor" character varying(12),
        "todaycolor" character varying(12),
        "weekdaybordercolor" character varying(12),
        "weekendbordercolor" character varying(12),
setup_calendar.pl view on Meta::CPAN
        "contentcolor" character varying(12),
        "weekdaycontentcolor" character varying(12),
        "weekendcontentcolor" character varying(12),
        "todaycontentcolor" character varying(12),
        "headercolor" character varying(12),
        "weekdayheadercolor" character varying(12),
        "weekendheadercolor" character varying(12),
        "header" character varying(64),
        "cellalignment" character varying(12),
        "bordercolor" character varying(12),
        Constraint "calendar_pkey" Primary Key ("calendarid")
);
--
-- TOC Entry ID 6 (OID 19030)
--
-- Name: event_eventid_seq Type: SEQUENCE Owner: '.$dbuser.'
--
CREATE SEQUENCE "event_eventid_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
--
-- TOC Entry ID 10 (OID 19049)
--
-- Name: event Type: TABLE Owner: '.$dbuser.'
--
CREATE TABLE "event" (
        "eventid" integer DEFAULT nextval(\'"event_eventid_seq"\'::text) NOT NULL,
        "eventtime" time,
        "calendarid" integer,
        "eventday" integer NOT NULL,
        "eventmonth" integer NOT NULL,
        "eventyear" integer NOT NULL,
        "eventname" character varying(128) NOT NULL,
        "eventdesc" text,
        "eventlink" character varying(128),
        Constraint "event_pkey" Primary Key ("eventid")
);
--
setup_calendar.pl view on Meta::CPAN
-- Name: client Type: TABLE DATA Owner: '.$dbuser.'
--
COPY "client"  FROM stdin;
1	'.$clientname.'
\.
--
-- Data for TOC Entry ID 12 (OID 18996)
--
-- Name: calendar Type: TABLE DATA Owner: '.$dbuser.'
--
COPY "calendar"  FROM stdin;
1	1	'.$calname.'
\.
--
-- TOC Entry ID 3 (OID 18851)
--
-- Name: client_clientid_seq Type: SEQUENCE SET Owner:
--
SELECT setval (\'"client_clientid_seq"\', 1, \'t\');
--
-- TOC Entry ID 5 (OID 18977)
--
-- Name: calendar_calendarid_seq Type: SEQUENCE SET Owner:
--
SELECT setval (\'"calendar_calendarid_seq"\', 1, \'t\');
--
-- TOC Entry ID 7 (OID 19030)
--
-- Name: event_eventid_seq Type: SEQUENCE SET Owner:
--
SELECT setval (\'"event_eventid_seq"\', 60, \'t\');
';