PHP Classes

File: BaseCalendar.inc

Recommend this page to a friend!
  Classes of William J Sanders   BaseCalendar   BaseCalendar.inc   Download  
File: BaseCalendar.inc
Role: ???
Content type: text/plain
Description: BaseCalendar Class
Class: BaseCalendar
Author: By
Last change:
Date: 21 years ago
Size: 4,619 bytes
 

Contents

Class file image Download
<?php // // To display the calendars, type // include_once("BaseCalendar.inc"); // $newCal = new BaseCalendar(); // class BaseCalendar { var $numYear = ""; var $textMonth = ""; var $thisMonthTimestamp = ""; var $numMonth = ""; var $nextMonthTimestamp = ""; var $numNextMonth = ""; var $textNextMonth = ""; var $yearNextMonth = ""; var $followingMonthTimestamp = ""; var $numFollowingMonth = ""; var $calWidth = "100px"; var $calBGColor = "#f7e4bf"; var $calTextColor = "#000000"; // constructor function, sets current date as default function BaseCalendar($YYYY=false, $Mmm=false, $calWid=false, $calBGC=false, $calTC=false) { $this->numYear = ($YYYY) ? $YYYY : date("Y"); $this->textMonth = ($Mmm) ? $Mmm : date("M"); $this->thisMonthTimestamp = strtotime("1 $this->textMonth $this->numYear"); $this->numMonth = date("n",$this->thisMonthTimestamp); $this->nextMonthTimestamp = strtotime("next month",$this->thisMonthTimestamp); $this->numNextMonth = date("n",$this->nextMonthTimestamp); $this->textNextMonth = date("M",$this->nextMonthTimestamp); $this->yearNextMonth = date("Y",$this->nextMonthTimestamp); $this->followingMonthTimestamp = strtotime("+2 month",$this->thisMonthTimestamp); $this->numFollowingMonth = date("n",$this->followingMonthTimestamp); $this->calWidth = ($calWid) ? $calWid : $this->calWidth; $this->calBGColor = ($calBGC) ? $calBGC : $this->calBGColor; $this->calTextColor = ($calTC) ? $calTC : $this->calTextColor; echo("<table padding=0 cellpadding=0 style=\"border:1px solid black; float:left; background-color:".$this->calBGColor."; color:".$this->calTextColor."\">\n"); echo("<tr valign=\"top\"><td>"); $this->displayMonth(); echo("</td><td style=\"border-left:1px solid black\">"); $this->displayNextMonth(); echo("</td></tr></table>\n"); } function displayMonth() { $daysInMonth = date("t",$this->thisMonthTimestamp); $dayMonthStarts = date("w",$this->thisMonthTimestamp); $dayNextMonthStarts = date("w",$this->nextMonthTimestamp); $today = date("n/j"); echo "<table style=\"padding:0; color:#6D4F16; font-size:x-small; line-height:1em; width:".$this->calWidth."\">\n"; echo "<tr><th colspan=\"7\" style=\"text-align:center\">".$this->textMonth."&nbsp;&nbsp;".$this->numYear."</th></tr>\n"; echo "<tr><th>Su</th><th>Mo</th><th>Tu</th><th>We</th> <th>Th</th><th>Fr</th><th>Sa</th></tr>\n"; echo "<tr style=\"text-align:center\">\n"; for ($i=0; $i<$dayMonthStarts; $i++) {echo "<td>&nbsp;</td>\n";} for ($i=1; $i<=$daysInMonth; $i++) { if ($today==date("n/j",strtotime("$i $this->textMonth $this->numYear"))) { echo "<td style=\"background-color:#f7c86d; text-align:center; color:black\">$i</td>"; } else echo "<td style=\"text-align:center\">$i</td>\n"; if (date("w",strtotime("$i $this->textMonth $this->numYear"))==6 && $i<$daysInMonth) { echo "</tr><tr style=\"text-align:center\">\n"; } else if (date("w",strtotime("$i $this->textMonth $this->numYear"))==6 && $i==$daysInMonth) { echo "</tr>\n"; } else if ($i==$daysInMonth) { for ($h=$dayNextMonthStarts; $h<7; $h++) { echo "<td>&nbsp;</td>\n"; } echo "</tr>\n"; } } echo "</table>\n"; } function displayNextMonth() { $daysInNextMonth = date("t",$this->nextMonthTimestamp); $dayNextMonthStarts = date("w",$this->nextMonthTimestamp); $dayFollowingMonthStarts = date("w",$this->followingMonthTimestamp); echo "<table style=\"padding:0; color:#6D4F16; font-size:x-small; line-height:1em; width:".$this->calWidth."\">\n"; echo "<tr><th colspan=\"7\" style=\"text-align:center\">".$this->textNextMonth."&nbsp;&nbsp;".$this->yearNextMonth."</th></tr>\n"; echo "<tr><th>Su</th><th>Mo</th><th>Tu</th><th>We</th> <th>Th</th><th>Fr</th><th>Sa</th></tr>\n"; echo "<tr style=\"text-align:center\">\n"; for ($i=0; $i<$dayNextMonthStarts; $i++) {echo "<td>&nbsp;</td>\n";} for ($i=1; $i<=$daysInNextMonth; $i++) { echo "<td style=\"text-align:center\">$i</td>\n"; if (date("w",strtotime("$i $this->textNextMonth $this->yearNextMonth"))==6 && $i<$daysInNextMonth) { echo "</tr><tr style=\"text-align:center\">\n"; } else if (date("w",strtotime("$i $this->textNextMonth $this->yearNextMonth"))==6 && $i==$daysInNextMonth) { echo "</tr>\n"; } else if ($i==$daysInNextMonth) { for ($h=$dayFollowingMonthStarts; $h<7; $h++) { echo "<td>&nbsp;</td>\n"; } echo "</tr>\n"; } } echo "</table>\n"; } // end of class } ?>