of the code. No hooks for graphics yet. I may take some time to do this.
class tableCalendar {
# Create an html calendar for a month.
# Interface:
# $calendar = new tableCalendar;
#
# Set necessary variables:
# $calendar->setDay($day); # Integer
# $calendar->setMonth($month); # Integer
# $calendar->setYear($year); # Integer
# $calendar->setFrameTarget($target_string); # String
# $calendar->setHrefString($href_string); # String
#
# $calendar->printCal(); # This'll print your table for you.
var $selectedDay, $selectedMonth, $selectedYear;
var $days;
var $frametarget, $href;
var $DEBUGGING_SET = 0;
function setDay ($day) {
$this->selectedDay = $day;
}
function setMonth ($month) {
$this->selectedMonth = $month;
}
function setYear ($year) {
$this->selectedYear = $year;
}
function setFrameTarget($target_string) {
$this->frametarget = "target = \"$target_string\"";
}
function setHref($href_string) {
$this->href = $href_string;
}
function setAndCheckDefaults () {
if (!$this->selectedDay ) {
$this->selectedDay = date( 'd');
}
if (!$this->selectedMonth) {
$this->selectedMonth = date( 'm');
}
if (!$this->selectedYear) {
$this->selectedYear = date( 'Y');
}
$this->days = array(0=> 'Sun',1=> 'Mon',2=> 'Tue',3=> 'Wed',
4=> 'Thu',5=> 'Fri',6=> 'Sat');
}
function printCal () {
$monthOrig;
$monthTest;
$monthName;
$firstday;
$dayRow;
$lastday = 31;
$this->setAndCheckDefaults(); # make sure we do the right thing(s)
# Find out the first day of the week!
$firstday = date( 'w',mktime(0,0,0,$this->selectedMonth,1,$this->selectedYear));
# have to perform a loop to test from 31 backwards,
# to see what the last day of the month is
$lastday = 31;
do {
$monthOrig = date( 'm',mktime(0,0,0,$this->selectedMonth,1,$this->selectedYear));
$monthTest = date( 'm',mktime(0,0,0,$this->selectedMonth,$lastday,$this->selectedYear));
if ($monthTest != $monthOrig) { $lastday -= 1; };
} while ($monthTest != $monthOrig);
$monthName = date( 'F',mktime(0,0,0,$this->selectedMonth,1,$this->selectedYear));
if($this->DEBUGGING_SET != 0) {
print( "first day of the first week of $selectedMonth $selectedYear is $firstday (from 0 to 6)
\n");
print( "The last day of $selectedMonth $selectedYear is $lastday\n
");
}
$this->printTable($monthName, $firstday, $lastday);
}
function printHref($day) {
$href = '';
if($this->href) {
print( "href?month=$this->selectedMonth&day=$day&year=$this->selectedYear\" $this-
>frametarget>$day");
}
}
function printTable ($monthName, $firstDay, $lastDay) {
$dayRow = 0;
$day = 0;
$targetString;
$adjustedDay;
print( "
");
print( "$monthName $this->selectedYear ");
print( "\n");
# Print days along the top.
for($i=0; $i<=6; $i++) {
print( "".$this->days[$i]. " \n");
}
print( " \n");
print( "\n");
while($dayRow < $firstDay) {
print( " ");
$dayRow += 1;
}
while($day < $lastDay) {
if(($dayRow % 7) == 0) {
print( " \n\n");
}
$adjustedDay = $day+1;
print( "");
$this->printHref($adjustedDay);
print( " ");
$day += 1;
$dayRow += 1;
}
print( "\n \n
\n");
}
}
?>