<!-- SophiaKnows -->

PHP: AUTOCALENDAR
Rev 3: December 2004

<?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>&nbsp;</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>&nbsp;</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.="&lt;</a> &nbsp;";
   $headercontrols.=strtoupper(date("F",mktime ( 0, 0, 0, $m, 1, $y )))." $y";
   $headercontrols.="&nbsp; <a href=".ReturnNextLink($m,$y).">";
   $headercontrols.="&gt;</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));
?>


<style type="text/css">
a.vcr {
   border-color:#fff;
   border-style:solid;
   border-width:2px;
   background:#99c;
   font-size:15px;
   color:#fff;
   text-decoration:none;
   padding:0 5px 0 5px;
   }

body {
   background:#ddd;
   }
div.canvasLabel {
   font-size:18px;
   text-align:center;
   margin:0 0 5px 0;
   }
table.calendar {
   width:550px;
   background:#fff;
   }   
td.hotDate,td.dateSquare {
   vertical-align:top;
   height:60px;
   font-size:16px;
   }
td.dateSquare {
   background:#eee;
   }
td.hotDate {
   background:#cdf;
   }
td.weekdaySquare {
   background:#eef;
   height:20px;
   font-size:14px;
   font-weight:bold;
   }

</style>

< CODEBASE | TOP^ | MAINPAGE >

Text & Design By Tony Pisarra
© SophiaKnows 1998-2004