PHP Code:
<?php
class calendarMonth()
{
// m - month; i.e. "01" to "12"
// M - month, textual, 3 letters; e.g. "Jan"
// F - month, textual, long; e.g. "January"
// Y - year, 4 digits; e.g. "1999"
// D - day of the week, textual, 3 letters; e.g. "Fri"
// d - day of the month, 2 digits with leading zeros; i.e. "01" to "31"
// l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"
// L - boolean for whether it is a leap year; i.e. "0" or "1"
var $firstCell = 0;
var $thisDayDate = date("d");
var $thisMonth;
var $nextMonth;
var $prevMonth;
var $thisYear;
var $nextYear;
var $prevYear;
var $monthTable = '';
var $firstDay;
var $thisMonthName;
var $newRow = 0;
var $dayCellHeight;
var $titleCellHeight;
var $tableWidth;
var $colWidth;
var $tableBorder;
var $tableBorder;
var $cellPadding;
var $cellSpacing;
var $cellBorder;
var $tableBGColor;
var $cellBGColor;
var $borderColor;
var $monthDaysArray = array("January" => 31,
"February" => 28,
"March" => 31,
"April" => 30,
"May" => 31,
"June" => 30,
"July" => 31,
"August" => 31,
"September" => 30,
"October" => 31,
"November" => 30,
"December" => 31);
var $dayNumberArray = array("Sat" => 0,
"Sun" => 1,
"Mon" => 2,
"Tue" => 3,
"Wed" => 4,
"Thu" => 5,
"Fri" => 6);
var $weekDayArray = array("Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
function calendarMonth( $argsArray )
{
//$argsArray = func_get_args();
define('DAYSPERWEEK', 7);
$this->thisMonth = isset($argsArray['month']) ? $argsArray['month'] : date("m");
$this->nextMonth = $thisMonth + 1;
$this->prevMonth = $thisMonth - 1;
$this->thisYear = isset($argsArray['year']) ? $argsArray['year'] : date("Y");
$this->nextYear = $thisYear + 1;
$this->prevYear = $thisYear - 1;
$this->firstDay = date("D", mktime(0, 0, 1, $thisMonth, 1, $thisYear));
$this->thisMonthName = date("F", mktime(0, 0, 1, $thisMonth, 1, $thisYear));
$this->newRow = 0;
$this->dayCellHeight = isset($argsArray['dateCellHeight']) ? $argsArray['dateCellHeight'] : 60;
$this->titleCellHeight = isset($argsArray['colHeadCellHeight']) ? $argsArray['colHeadCellHeight'] : 18;
$this->tableWidth = isset($argsArray['tableWidth']) ? $argsArray['tableWidth'] : 750;
$this->colWidth = $tableWidth / DAYSPERWEEK;
$this->tableBorder = isset($argsArray['tableBorder']) ? $argsArray['tableBorder'] : 4;
$this->cellPadding = isset($argsArray['cellPadding']) ? $argsArray['cellPadding'] : 5;
$this->cellSpacing = isset($argsArray['cellSpacing']) ? $argsArray['cellSpacing'] : 0;
$this->cellBorder = isset($argsArray['cellBorder']) ? $argsArray['cellBorder'] : 1;
$this->tableBGColor = isset($argsArray['tableBGColor']) ? $argsArray['tableBGColor'] : "#00FFFF";
$this->cellBGColor = isset($argsArray['cellBGColor']) ? $argsArray['cellBGColor'] : "#0099FF";
$this->borderColor = isset($argsArray['borderColor']) ? $argsArray['borderColor'] : "#000000";
if(date("L", mktime(0, 0, 0, 1, 1, $nextYear)))
{
$this->monthDaysArray["February"] = 29;
} // End test for leap year
} // End calendarMonth constructor
function setMonth( $month )
{
$this->thisMonth = $month;
$this->nextMonth = $thisMonth + 1;
$this->prevMonth = $thisMonth - 1;
}
function setYear( $year )
{
$this->thisYear = $year;
$this->nextYear = $thisYear + 1;
$this->prevYear = $thisYear - 1;
}
function setDayCellHeight( $color )
{
$this->dayCellColor = $color;
}
function setTitleCellHeight( $height )
{
$this->titleCellHeight = $height;
}
function setTableWidth( $width )
{
$this->tableWidth = $width;
}
function setTableBorder( $border )
{
$this->tableBorder = $border;
}
function setCellPadding( $padding )
{
$this->cellPadding = $padding;
}
function setCellSpacing( $spacing )
{
$this->cellSpacing = $spacing;
}
function setCellBorder( $border )
{
$this->cellBorder = $border;
}
function setTableBGColor( $color )
{
$this->tableBGColor = $color;
}
function setCellBGColor( $color )
{
$this->cellBGColor = $color;
}
function setBorderColor( $color )
{
$this->borderColor = $color;
}
function showArgs()
{ }
function buildMonth( $month, $year )
{
if( isset( $month ))
$this->setMonth( $month );
if( isset( $year ))
$this->setYear( $year );
$this->monthTable = '<table width="'.$tableWidth.'" border="'.$tableBorder.'" cellpadding="'.$cellPadding.'" bordercolor="'.$borderColor.'" bgcolor="'.$tableBGColor.'" summary="Month display">
<tr bgcolor="'.$cellBGColor.'">
<td align="center">
';
if($nextMonth + 1 > 12)
{
$nextMonth = 1;
$nextYear += 1;
}
else
{
$nextMonth += 1;
}
if($prevMonth < 1)
{
$prevMonth = 12;
$prevYear -= 1;
}
if($prevMonth >= date("m") || $prevYear > date("Y"))
{
$this->monthTable .= '<a href="'.$PHP_SELF.'?nextMonth='.$prevMonth.'&year='.$prevYear.'"><<</a>';
}
else
{
$this->monthTable .= ' ';
}
$this->monthTable .= ' <td align="center">
'.$thisMonthName.'
</td>
<td align="center">
<a href="'.$PHP_SELF.'?nextMonth='.$nextMonth.'&year='.$nextYear.'">>></a>
</td>
<td colspan="4" align="center">
</td>
</tr>
';
for($i = 0; $i < DAYSPERWEEK; $i++)
{
$this->monthTable .= '<td height="'.$titleCellHeight.'" width="'.$colWidth.'">
<div align="center">'.$weekDayArray[$i].'</div>
</td>
';
}
$this->monthTable .= '</tr>';
$firstCell = $dayNumberArray[$firstDay];
++$firstCell;
$this->monthTable .= '<tr valign="top">';
for($blanks = 1; $blanks < $firstCell; $blanks++)
{
$this->monthTable .= '<td>
</td>
';
++$newRow;
}
for($cell = 0; $cell < $monthDaysArray[$thisMonthName]; $cell++)
{
$monthdayNumberArray = $cell + 1;
$this->monthTable .= '<td align="left" height="'.$dayCellHeight.'">
';
if($thisDayDate == $monthdayNumberArray)
{
$this->monthTable .= '<span class="todaysDate">'.$monthdayNumberArray.'</span>';
}
else
{
$this->monthTable .= $monthdayNumberArray;
}
$this->monthTable .= '</td>
';
++$newRow;
if($newRow == 7)
{
$this->monthTable .= '</tr>
<tr valign="top">
';
$newRow = 0;
}
}
$this->monthTable .=' </tr>
</table>
';
return $this->monthTable;
} // End buildMonth function
} // End class calendarMonth
?>
Bookmarks