Here is the Calendar class. It may run out to the right a bit.
<?php
/*
##################################################
#
# Filename..........: $RCSfile: Calendar.php,v $
# Original Author...: Anthony L. Awtrey
# Version...........: $Revision: 0.1 $
# Last Modified By..: $Author: aawtrey $
# Last Modified.....: $Date: 2006/09/21 09:34:00 $
#
# Copyright 2006 Anthony Awtrey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
*/
/*
* This table generates HTML calendars
*/
class Calendar {
var $year = "";
var $month = "";
var $appt = array( );
/*
* Constructor
*/
function __construct($year='',$month='')
{
if ( $year != '' ) {
$this->year = $year;
} else {
$this->year = gmdate("Y", gmmktime(NULL));
}
if ( $year != '' ) {
$this->month = $month;
} else {
$this->month = gmdate("m", gmmktime(NULL));
}
}
function __destruct()
{
}
function _get_last_dom($year,$month)
{
return gmdate("d",gmmktime(0,0,0,intval($month+1),0,intval($year)));
}
function _get_first_dow($year,$month)
{
$fdow = gmdate('w',gmmktime (0,0,0,intval($month),1,intval($year)));
if ( $fdow == 0 ) { $fdow = 7; }
return $fdow;
}
function _get_month_name($month)
{
return gmdate("M",gmmktime(0,0,0,intval($month),1,intval($this->year)));
}
function _render_month($year,$month)
{
$mon = $this->_get_month_name($month);
$days = $this->_get_last_dom($year,$month);
$fdow = $this->_get_first_dow($year,$month);
require_once('Table.php');
$t = new Table();
$t->set_title($mon.' '.$year);
$t->add_headers(array('M', 'T', 'W', 'T', 'F', 'S', 'S'));
$day = 1;
while ( $day <= $days ) {
for ( $i=1; $i<8; $i++) {
if (
( ( $day == 1 ) && ( $fdow == $i ) ) ||
( ( $day > 1 ) && ( $day <= $days ) )
)
{
if ( $this->get_appt($year,$month,$day) != '' ) {
$t->add_cell( '<a href="'.$this->get_appt($year,$month,$day).'">'.$day.'</a>' );
} else {
$t->add_cell( $day );
}
$day++;
} else {
$t->add_cell( ' ' );
}
}
$t->add_row();
}
return( $t->render() );
}
function _render_year($year)
{
$month = 1;
for ( $c=1; $c<5; $c++ ) {
for ( $r=1; $r<4; $r++ ) {
$result .= $this->_render_month($year,$month);
$month++;
}
}
return( "<div class="calendar">n".$result."</div>n");
}
function get_appt($year,$month,$day)
{
return( $this->appt[ gmmktime(0,0,0,intval($month),intval($day),intval($year)) ] );
}
function set_appt($year,$month,$day,$url)
{
$this->appt[ gmmktime(0,0,0,intval($month),intval($day),intval($year)) ] = $url;
return(true);
}
function render($year='',$month='')
{
if ( $year != '' && $year >= 0 && $year <= 9999 && $month == '' ) {
return($this->_render_year($year));
} elseif ( $year != '' && $year >= 0 && $year <= 9999 && $month != '' && $month >= 1 && $month <= 12 ) {
return($this->_render_month($year,$month));
} else {
return($this->_render_year($this->year));
}
}
}
?>