<?php
/* --------------------------------- */
/* SOPHIAKNOWS: PHP LIBRARY */
/* --------------------------------- */
/* AUTOCALENDAR */
/* --------------------------------- */
/* Created: 2003-01-01 */
/* Issued: 2003-01-01 */
/* Modified: 2004-12-30 */
/* Component: PHP RANDOM IMAGE */
/* Copyright (c) 2003-2004 */
/* Tony Pisarra, SophiaKnows */
/* --------------------------------- */
/* --------------------------------- */
$year=(($year)?$year:date("Y"));
$month=(($month)?$month:date("m"));
function Make_Calendar($y,$m) {
$the_first_day=date("w",mktime ( 0, 0, 0, $m, 1, $y ));
$the_max=(date("t",mktime ( 0, 0, 0, $m, 1, $y ))+1);
$endpoint=(($the_first_day>6)?43:36);
if($the_first_day>4 && $the_max>30){$endpoint=43;}
$calendarhash.=ReturnHeaderControls($y,$m);
$calendarhash.=ReturnDaysRow();
$calendarhash.="<tr>";
for ($i=0; $i < 7; $i++) {
if ($i < $the_first_day ) { $calendarhash.="<td> </td>"; }
if ($i == $the_first_day) {
$calendarhash.="<td>1</td>";
if ($i == 6) { $calendarhash.="\n</tr>\n<tr>\n"; }
}
}
$date_count = 2;
for ($l=($the_first_day + 2); $l < $endpoint; $l++) {
if ($date_count < $the_max) {
$calendarhash.="<td>$date_count</td>";
}
if ($date_count >= $the_max) {
$calendarhash.="<td> </td>";
}
if ($l % 7 == 0) {
$calendarhash.=(($date_count<$the_max)?"\n</tr>\n<tr>\n":"");
}
$date_count++;
}
$calendarhash.="\n</tr>\n</table>";
return $calendarhash;
}
// MONTH YEAR BACK/NEXT
function ReturnHeaderControls($y,$m) {
$headercontrols.="<a href=".ReturnBackLink($m,$y).">";
$headercontrols.="<</a> ";
$headercontrols.=strtoupper(date("F",mktime ( 0, 0, 0, $m, 1, $y )))." $y";
$headercontrols.=" <a href=".ReturnNextLink($m,$y).">";
$headercontrols.="></a></div>\n";
$headercontrols.="<table cellpadding=2 cellspacing=2 class=calendar>\n";
return $headercontrols;
}
// WEEKDAYS ROW
function ReturnDaysRow() {
$days = array("S","M","T","W","T","F","S");
$daysRow="<tr>\n";
for ($c=0; $c < 7; $c++) {
$daysRow.="<td align=center class=weekdaySquare>".$days[$c]."</td>";
}
$daysRow.="</tr>\n";
return $daysRow;
}
// BACK MONTH LINK
function ReturnBackLink($xMon,$xYear) {
$xYear=(($xMon>1)?$xYear:$xYear-1);
$xMon=(($xMon>1)?$xMon-1 : 12);
$xString="?month=$xMon&year=$xYear";
return $xString;
}
// NEXT MONTH LINK
function ReturnNextLink($xMon,$xYear) {
$xYear=(($xMon<12)?$xYear:$xYear+1);
$xMon=(($xMon<12)?$xMon+1 : 1);
$xString="?month=$xMon&year=$xYear";
return $xString;
}
?>
<title>Calendar</title>
<body>
<center>
<?php
echo(Make_Calendar($year,$month));
?>