Location: PHPKode > scripts > cDates > cdates/cDates.php
<?php
//---------------------------------------------------------------------------------------
//
// cDates
// rev. 2008-05-16
// Mark Kintigh
//
//---------------------------------------------------------------------------------------
//
// PROPERTIES
// ----------
// While there are other properties you have access to, these are the properties that you
// _SHOULD_ only make changes to.
//
// $this->cal_style()
//    * This is an assositive array containg the STYLE values for the calendar that
//      $this->drawCalendar() uses.  If there is a value in $this->cal_class() it will
//      override this setting.  The key values are:
//
//      Key      What it is for
//      -------- ------------------------------------------------------------------------
//      table    This is the style value for the table being created
//      border   This contains the border width for the table being created
//      title    This is the style value for the month / year title cell
//      dow      This is the style value for the days-of-the-week header line
//      dow_type This tells the class what type of days-of-the-week headers should be
//               displayed.  These values corrispond with the $this->dow_names() arrays,
//               which contain arrays of 7 cells.  If you wish to create a custom list,
//               do an array_push() to add your new list (the calendar function is
//               smart enough to handle the additional sub-arrays)
//      weekday  This is the style value for the cells containg the standard days of the
//               week
//      today    This is the style value for the cell containing the date passed to the
//               calendar function
//      row      This is the style value for the rows containing the day cells
//      spacer   This is the style value for the empty day cells
//      holiday  This is the style value for any holidays or events to be displayed
//
// $this->cal_class()
//    * This is an assositive array containg the CLASS values for the calendar that
//      $this->drawCalendar() uses.  If there is a non-blank value set here it will
//      override the corrisponding $this->cal_style() value.  The key values are:
//
//      Key      What it is for
//      -------- ------------------------------------------------------------------------
//      table    This is the class value for the table being created
//      title    This is the class value for the month / year title cell
//      dow      This is the class value for the days-of-the-week header line
//      weekday  This is the class value for the cells containg the standard days of the
//               week
//      today    This is the class value for the cell containing the date passed to the
//               calendar function
//      row      This is the class value for the rows containing the day cells
//      spacer   This is the class value for the empty day cells
//      holiday  This is the class value for any holidays or events to be displayed
//
// $this->dow_names()
//    * This array of arrys contains the days-of-the-week headers to display using
//      $this->drawCalendar().  There are 4 base settings (0...3); if you wish to add
//      another list of titles use the array_push() function to add another array of 7
//      values, just remember that your custom values start at 4.
//    * The base settings are:
//
//	    0 => "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
//	    1 => "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"
//      2 => "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"
//      3 => "S", "M", "T", "W", "R", "F", "S"
//
//---------------------------------------------------------------------------------------
//
// FUNCTIONS
// ---------
//
// $this->isValid([date])
//    * Validates that the given date is valid, either as a true date or a formula that
//      can return a valid date using strtotime().
//
// $this->fixDate([date])
//    * Changes a given date or date formula into a true date value or 0 if it is not
//      a valid date.
//
// $this->isHoliday([date])
//    * Returns a string that contains the text name for a holiday on the given date.  If
//      the date is invalid or there is no holiday on this date to will return a blank
//      string.
//
// $this->diff([dateA], [dateB], [difference type])
//    * Returns an integer that represents the difference between the two given dates or
//      FALSE if either date is invalid.  The number represents the differnce of dateA
//      being checked against dateB -- if dateA > dateB, returns a positive number; if
//      dateA < dateB, returns a negitive number; if dateA = dateB then it return 0.
//    * This class contains an array with a "friendly" version of the difference types
//      that are available.  Please refer to this chart for the values:
//
//         $this->difftype["x"] where "x" is....
//
//             int  assositive name
//             ---  --------------------------------------
//              1   "year", "years", or "y"
//              2   "month", "months", or "m"
//              3   "day", "days", or "d"
//              4   "hour", "hours", or "h"
//              5   "minute", "minutes", or "n"
//              6   "second", "seconds", "s"
//
//      An example of using this array would be:
//
//         $myDate->diff("last monday","now",$myDate->difftype["days"]);
//
// $this->getMonth([date])
//    * Returns the month, as a number, for the given date.  If the date is invalid it
//      returns 0.  As above, this can be a date or a strtotime() formula.
//
// $this->getDay([date])
//    * Returns the day for the given date.  If the date is invalid it returns 0.  As
//      above, this can be a date or a strtotime() formula.
//
// $this->getYear([date])
//    * Returns the 4-digit year for the given date.  If the date is invalid it
//      returns false.  As above, this can be a date or a strtotime() formula.
//
// $this->drawCalendar([date], <[include holidays] = false>,
//    <[include my events] = false>, <[table defined = false]>)
//    * This function will draw a month's calendar as a table
//
// $this->addEvent([month], [dateformula], [description])
//    * This function will attempt to add a custom event into the class.  This event
//      will occur within the given month (by number or month name), using the standard
//      conventions used in the $holiday_list arrays for the date formula (either a
//      number or a valid strtotime() translation with the %YEAR% token), with the given
//      description.  Before adding the event the function will check to see there is an
//      event already defined with these paramenters (case insensitive check).
//    * Will return TRUE if it event is added; otherwise, it returns FALSE for any test
//      failures (invalid date, duplicate, etc.).
//
// $this->delEvent([month], [dateformula], [description])
//    * This function is similar to addEvent() except that it removes an event from the
//      class.  It's parameters are exactly the same so you can have a true match.
//    * Will return TRUE if it event is removed; otherwise, it returns FALSE for any test
//      failures (invalid date, etc.).
//
// $this->delAllEvents([month])
//    * This function will reset all of the custom events for a given month (by number or
//      month name).
//    * Will return TRUE if successful; otherwise, it returns FALSE for any failures
//      (invalid month, etc.)
//
// $this->hasEvent([date])
//    * Returns a string that contains the text name for a custom event on the given date.
//      If the date is invalid or there is no event on this date to will return a blank
//      string.
//
// $this->mysql([date], [to mySQL] = true, [use leading 0] = true)
//    * Returns a reformatted date value.  It will convert a date to or from a mySQL
//      date.  If there is a problem the function returns a blank string.
//
//---------------------------------------------------------------------------------------
class cDates {
	//
	// Array containing all of the holidays in arrays
	// * The base array contains 12 arrays, 1 for each month of the year
	// * The sub-arrays contain the actual holidays for each month
	//   > The holidays are defined as "date|holiday name", where "date"
	//     can either be a day number or a valid strtotime() value (there
	//     is a possible token called "%YEAR%" to use the given date's
	//     year as part of the formula) and "holiday name" is the text
	//     to return as the name of the holiday.
	//
	var $holiday_list = array(
		1=>array(
			"1|New Year's Day"
			),
		2=>array(
			"2|Groundhog Day",
			"12|Lincoln's Birthday",
			"14|Valentine's Day",
			"22|Washington's Birthday",
			"29|Leap Year",
			"Feb %YEAR% Third Monday|President's Day"
			),
		3=>array(
			"17|St. Patricks Day"
			),
		4=>array(
			"1|April Fool's Day"
			),
		5=>array(
			"5|Cinco De Mayo",
			"May %YEAR% Second Sunday|Mother's Day",
			"May %YEAR% Third Saturday|Armed Forces Day",
			"June %YEAR% Last Monday|Memorial Day"
			),
		6=>array(
			"14|Flag Day",
			"21|Summer Solstice",
			"June %YEAR% Third Sunday|Father's Day"
			),
		7=>array(
			"4|Independence Day",
			"July %2008% Fourth Sunday|Parent's Day"
			),
		8=>array(
			),
		9=>array(
			"11|Patriot Day",
			"September %YEAR% First Monday|Labor Day"
			),
		10=>array(
			"31|Halloween",
			"October %YEAR% Second Monday|Columbus Day"
			),
		11=>array(
			"11|Veteran's Day",
			"November 2, %YEAR% Next Tuesday|Election Day",
			"November %YEAR% Fourth Thursday|Thansgiving Day"
			),
		12=>array(
			"7|National Pearl Harbor Remembrance Day",
			"21|Winter Solstice",
			"24|Christmas Eve",
			"25|Christmas Day",
			"31|New Year's Eve"
			)
	);
	//
	// Assositive array containing a "friendly" way to call the type of math
	// used in $this->diff()
	//
	var $difftype = array(
		"year"=>1,     "years"=>1,      "y"=>1,
		"month"=>2,    "months"=>2,     "m"=>2,
		"day"=>3,      "days"=>3,       "d"=>3,
		"hour"=>4,     "hours"=>4,      "h"=>4,
		"minute"=>5,   "minutes"=>5,    "n"=>5,
		"second"=>6,   "seconds"=>6,    "s"=>6
		);
	//
	// Assostive array containing the STYLE="" values used for drawing the calendar
	//
	var $cal_style = array(
		"border"=>0,
		"table"=>"border-style:none; ",
		"title"=>"border-style:none; font-weight:bold;",
		"dow"=>"border-style:inset; border-width:1px; font-size:12px; font-weight:bold; background-color:#000000; color:#FFFFFF;",
		"dow_type"=>0,
		"weekday"=>"border-style:inset; border-width:1px; font-size:12px;",
		"today"=>"border-style:inset; border-width:1px; font-size:12px; background-color:#FFFF99;",
		"row"=>"height:75px;",
		"spacer"=>"border-style:inset; border-width:1px; background-color:#EEEEEE;",
		"holiday"=>""
		);
	//
	// Assostive array containing the CLASS="" values used for drawing the calendar
	//
	var $cal_class = array(
		"table"=>"",
		"title"=>"",
		"dow"=>"",
		"weekday"=>"",
		"today"=>"",
		"row"=>"",
		"spacer"=>"",
		"holiday"=>""
		);
	//
	// Array containing the options on how the calendar displays the days of the week
	//
	var $dow_names = array(
		0=>array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday",
			"Saturday"),
		1=>array("Sun","Mon","Tue","Wed","Thr","Fri","Sat"),
		2=>array("Su","Mo","Tu","We","Th","Fr","Sa"),
		3=>array("S","M","T","W","R","F","S")
		);
	//
	// Internal array of arrays that contain custom events.
	//
	var $my_events = array(
		0=>array(), 1=>array(), 2=>array(), 3=>array(), 4=>array(), 5=>array(),
		6=>array(), 7=>array(), 8=>array(), 9=>array(), 10=>array(), 11=>array(),
		12=>array());

	//-----------------------------------------------------------------------------------
	//
	// isValid()
	//
	//-----------------------------------------------------------------------------------
	function isValid($thedate) {
		//
		// Check to see if the date is valid
		//
		if($dt = strtotime($thedate . "") === false) {
			return false;
		} else {
			return true;
		}
	}
	
	//-----------------------------------------------------------------------------------
	//
	// fixDate()
	//
	//-----------------------------------------------------------------------------------
	function fixDate($thedate) {
		//
		// Changes a given date, or date formula, into a true date value
		//
		if($dt = strtotime($thedate . "") === false) {
			return 0;
		} else {
			return strtotime($thedate . "");
		}
	}
	
	//-----------------------------------------------------------------------------------
	//
	// isHoliday()
	//
	//-----------------------------------------------------------------------------------
	function isHoliday($thedate) {
		//
		// Check to see if the given date is a holiday and, if it is, return the
		// text of the holiday; otherwise, return a blank line
		//
		$ret = "";
		//
		// If this is a valid date
		//
		if($this->isValid($thedate)) {
			//
			// Split out the date into its month, day, and year values
			//
			$m = date("m",$this->fixDate($thedate));
			$d = date("d",$this->fixDate($thedate));
			$y = date("Y",$this->fixDate($thedate));
			foreach($this->holiday_list[intval($m)] as $v) {
				list($hol, $desc) = split("\|",$v,2);
				if(intval($hol)==0) {
					//
					// The date given is a formula
					// * Replace the %YEAR% token (if exists)
					// * Strip out the actual day of the month
					//
					$thol = str_replace("%YEAR%",date("Y",$this->fixDate($thedate)),$hol);
					$hol = date("j",strtotime($thol));
				}
				//
				// Check the date verses this holiday's value
				//
				if(intval($hol)==intval($d)) {
					//
					// The passed day and this entry match, so add it
					//
					if(strlen($ret)>0) $ret .= "\n";
					$ret .= trim($desc);
				}
			}
			//
			// Check to see if this is Easter
			//
			if(strcmp(date("m/d/Y",easter_date(intval($y))),
				date("m/d/Y",strtotime($thedate . "")))==0) {
				if(strlen($ret)>0) $ret .= "\n";
				$ret .= "Easter";
			}
			//
			// Check for Ash Wed. (40 days before Easter, excluding Sundays)
			//
			$wd = date("m/d/Y",easter_date(intval($y)));
			$x = 40;
			while($x>1) {
				if(date("w",strtotime($wd))!=6) {
					//
					// Not a Sunday, so decrement the counter
					//
					$x--;
				}
				$wd = date("m/d/Y",strtotime($wd . " -1 day"));
			}
			if(strcmp($wd, date("m/d/Y",strtotime($thedate . "")))==0) {
				if(strlen($ret)>0) $ret .= "\n";
				$ret .= "Ash Wednesday";
			}

		}
		return $ret;
	}

	//-----------------------------------------------------------------------------------
	//
	// diff()
	//
	//-----------------------------------------------------------------------------------
	function diff($dateA, $dateB, $diffType) {
		//
		// Calculate the difference between two dates
		//
		if(!$this->isValid($dateA) || !$this->isValid($dateB)) {
			return false;
		}
		$ret = 0;
		//
		// Convert the given values into true date values
		//
		$date1 = $this->fixDate($dateA);
		$date2 = $this->fixDate($dateB);
		//
		// Start the calculations
		//
		switch(intval($diffType . "")) {
			case 1: //
					// difference in YEARS
					//
					$ret = floor(($date2 - $date1) / 31536000) * (-1);
					break;
			case 2: //
					// difference in MONTHS
					//
					$ret = floor(($date2-$date1)/2628000) * (-1);
					break;
			case 3: //
					// difference in DAYS
					//
					$ret = floor(($date2-$date1)/86400) * (-1);
					break;
			case 4: //
					// difference in HOURS
					//
					$ret = floor(($date2-$date1)/3600) * (-1);
					break;
			case 5: //
					// difference in MINUTES
					//
					$ret = floor(($date2-$date1)/60) * (-1);
					break;
			case 6: //
					// difference in SECONDS
					//
					$ret = ($date2-$date1) * (-1);
					break;
		}
		return $ret;
	}

	//-----------------------------------------------------------------------------------
	//
	// getMonth()
	//
	//-----------------------------------------------------------------------------------
	function getMonth($thedate) {
		if($this->isValid($thedate)) {
			return date("m",$this->fixDate($thedate));
		} else {
			return 0;
		}
	}

	//-----------------------------------------------------------------------------------
	//
	// getDay()
	//
	//-----------------------------------------------------------------------------------
	function getDay($thedate) {
		if($this->isValid($thedate)) {
			return date("d",$this->fixDate($thedate));
		} else {
			return 0;
		}
	}

	//-----------------------------------------------------------------------------------
	//
	// getYear()
	//
	//-----------------------------------------------------------------------------------
	function getYear($thedate) {
		if($this->isValid($thedate)) {
			return date("Y",$this->fixDate($thedate));
		} else {
			return false;
		}
	}

	//-----------------------------------------------------------------------------------
	//
	// drawCalendar()
	//
	//-----------------------------------------------------------------------------------
	function drawCalendar($thedate, $addholidays=false, $addmyevents=false,
		$tableready=false) {
		//
		// Pull the style or class values out of the defined properties
		// * if a style is defined, set the variable to 'style="..." '
		// * if a style class is defined, set the variable to 'class="..." '
		//
		$s_border = intval(trim($this->cal_style['border'] . "")); 
		$s_table = (strlen(trim($this->cal_style['table']))>0) ?
			"style=\"" . trim($this->cal_style['table']) . " \" " : "";
		$s_table = (strlen(trim($this->cal_class['table']))>0) ?
			"class=\"" . trim($this->cal_class['table']) . " \" " :
			$s_table;
		$s_title = (strlen(trim($this->cal_style['title']))>0) ?
			"style=\"" . trim($this->cal_style['title']) . "\" " : "";
		$s_title = (strlen(trim($this->cal_class['title']))>0) ?
			"class=\"" . trim($this->cal_class['title']) . "\" " :
			$s_title;
		$s_dow = (strlen(trim($this->cal_style['dow']))>0) ?
			"style=\"" . trim($this->cal_style['dow']) . "\" " : "";
		$s_dow = (strlen(trim($this->cal_class['dow']))>0) ?
			"class=\"" . trim($this->cal_class['dow']) . "\" " :
			$s_dow;
		if(intval(trim($this->cal_style['dow_type']. ""))>=0 &&
			intval(trim($this->cal_style['dow_type']. ""))<count($this->dow_names)) {
			$a_dow = $this->dow_names[intval($this->cal_style['dow_type'] . "")];
		} else {
			$a_dow = $this->dow_names[0];
		}
		$s_weekday = (strlen(trim($this->cal_style['weekday']))>0) ?
			"style=\"" . trim($this->cal_style['weekday']) . " \" " : "";
		$s_weekday =  (strlen(trim($this->cal_class['weekday']))>0) ?
			"class=\"" . trim($this->cal_class['weekday']) . "\" " :
			$s_weekday;
		$s_today = (strlen(trim($this->cal_style['today']))>0) ?
			"style=\"" . trim($this->cal_style['today']) . " \" " : "";
		$s_today = (strlen(trim($this->cal_class['today']))>0) ?
			"class=\"" . trim($this->cal_class['today']) . "\" " :
			$s_today;
		$s_row = (strlen(trim($this->cal_style['row']))>0) ?
			"style=\"" . trim($this->cal_style['row']) . " \" " : "";
		$s_row = (strlen(trim($this->cal_class['row']))>0) ?
			"class=\"" . trim($this->cal_class['row']) . "\" " :
			$s_row;
		$s_spacer = (strlen(trim($this->cal_style['spacer']))>0) ?
			"style=\"" . trim($this->cal_style['spacer']) . " \" " : "";
		$s_spacer = (strlen(trim($this->cal_class['spacer']))>0) ?
			"class=\"" . trim($this->cal_class['spacer']) . "\" " :
			$s_spacer;
		$s_holiday = (strlen(trim($this->cal_style['holiday']))>0) ?
			"style=\"" . trim($this->cal_style['holiday']) . "\" " : "";
		$s_holiday = (strlen(trim($this->cal_class['holiday']))>0) ?
			"class=\"" . trim($this->cal_class['holiday']) . "\" " :
			$s_holiday;
		//
		// The style / class / configs are now in local variables, now let's start
		// building the calendar
		//
		if(!$tableready) {
			//
			// The table was not pre-defined; therefore, start a new table
			//
			echo "<table border=\"$s_border\" $s_table>\n";
		}
		//
		// Write the calendar's header
		//
		$wd = strtotime(date("m/1/Y",$this->fixDate($thedate)));
		echo "\t<tr>\n\t\t<td colspan=\"7\" align=\"center\" $s_title>\n\t\t\t"
			. date("F Y",$wd)
			. "\n\t\t</td>\n\t</tr>\n";
		//
		// Write the days of the week headers
		//
		echo "\t<tr>\n";
		for($x=0;$x<7;$x++) {
			if($x==3) {
				echo "\t\t<td align=\"center\" width=\"16%\" $s_dow>"
					. $a_dow[$x] . "</td>\n";
			} else {
				echo "\t\t<td align=\"center\" width=\"14%\" $s_dow>"
					. $a_dow[$x] . "</td>\n";
			}
		}
		echo "\t</tr>\n";
		//
		// Get ready for writing the calendar itself
		//
		$mn = date("m",$wd);
		$dow = date("w", $wd);
		if($dow != 0) {
			echo "\t<tr $s_row>\n\t\t<td colspan=\"$dow\" $s_spacer>&nbsp;</td>\n";
		} else {
			echo "\t<tr $s_row>\n";
		}
		//
		// Start writing the days onto the calendar
		// ___________
		//
		// While the working date is still within this month.....
		//
		while(date("m",$wd) == $mn) {
			$temp = "";
			if(date("w",$wd)==0 && date("j",$wd)!=1) {
				//
				// If this is Sunday and NOT the first, close this row and
				// open a new row
				//
				echo "\t</tr>\n\t<tr $s_row>\n";
			}
			//
			// If this is today us the proper style, otherwise use the generic style
			//
			if(date("j",$wd)==date("j",$this->fixDate($thedate))) {
				echo "\t\t<td $s_today valign=\"top\">";
			} else {
				echo "\t\t<td $s_weekday valign=\"top\">";
			}
			//
			// Write the day number
			//
			echo "<div align=\"right\">" . date("j",$wd) . "</div>";
			//
			// If they want holidays displayed, clech for a holiday
			//
			if($addholidays) {
				$temp = trim($this->isHoliday(date("m/j/Y",$wd)));
			}
			if($addmyevents) {
				$temp2 = trim($this->hasEvent(date("m/j/Y",$wd)));
				if(strlen($temp2)>0) {
					if(strlen(trim($temp))>0) $temp .= "<br>";
					$temp .= $temp2;
				}
			}
			if(strlen(trim($temp))>0) {
				echo "<div align=\"left\" $s_holiday>$temp</div>";
			}
			echo "</td>\n";
			//
			// Convert the timg to julian, add 1 day, and reconvert it to gregorian
			//
			$wd = strtotime(jdtogregorian(gregoriantojd(
				date("m",$wd),date("j",$wd),date("Y",$wd))+1));
		}
		//
		// Check to see if this ended on a Saturday and, if not, add a spacer
		//
		$wd = strtotime(date("m/1/Y",$this->fixDate($thedate)));
		$dow = date("w",strtotime("$mn/" . date("t", $wd) . "/" . date("Y",$wd)));
		if($dow!=6) {
			echo "\t\t<td colspan=\"" . (7-$dow) . "\" $s_spacer>&nbsp;</td>\n";
		}
		echo "\t</tr>\n";
		//
		// Calendar is now done
		//
		if(!$tableready) {
			//
			// The table was not pre-defined; therefore, close the table
			//
			echo "</table>\n";
		}
	}

	//-----------------------------------------------------------------------------------
	//
	// addEvent()
	//
	//-----------------------------------------------------------------------------------
	function addEvent($month, $dateformula, $description) {
		//
		// Error checking -- valid month
		//
		if(intval($month)==0) {
			if($this->isValid("$month 1, " . date("Y",strtotime("now")))) {
				$lm = intval(date("m",strtotime("$month 1, "
					. date("Y",strtotime("now")))));
			} else {
				return false;
			}
		} else {
			$lm = intval($month . "");
		}
		if($lm<1 || $lm>12) {
			return false;
		}
		//
		// Error checking -- verify that the date / date formula is valid
		//
		if(intval(trim($dateformula))==0) {
			$temp = str_replace("%YEAR%",date("Y",strtotime("now")),
				trim($dateformula));
			if(!$this->isValid($temp)) {
				return false;
			}
		}
		//
		// Error checking -- verify there is a description
		//
		if(strlen(trim($description))<1) {
			return false;
		}
		//
		// Error check -- see if there is an event already out there with this desc.
		//
		$test = $this->my_events[$lm];
		foreach($test as $ev) {
			//
			// Do a case insensitive check of the new event's description against the
			// current event
			//
			if(strcmp(strtolower(trim($ev)),
				strtolower(trim($dateformula) . "|" . trim($description)))==0) {
				//
				// They match, so error out
				//
				return false;
			}
		}
		$temp = trim($dateformula) . "|" . trim($description);
		array_push($this->my_events[$lm],$temp);
		return true;
	}
	//-----------------------------------------------------------------------------------
	//
	// delEvent()
	//
	//-----------------------------------------------------------------------------------
	function delEvent($month, $dateformula, $description) {
		//
		// Error checking -- valid month
		//
		if(intval($month)==0) {
			if($this->isValid("$month 1, " . date("Y",strtotime("now")))) {
				$lm = intval(date("m",strtotime("$month 1, "
					. date("Y",strtotime("now")))));
			} else {
				return false;
			}
		} else {
			$lm = intval($month . "");
		}
		if($lm<1 || $lm>12) {
			return false;
		}
		//
		// Error checking -- verify that the date / date formula is valid
		//
		if(intval(trim($dateformula))==0) {
			$temp = str_replace("%YEAR%",date("Y",strtotime("now")),
				trim($dateformula));
			if(!$this->isValid($temp)) {
				return false;
			}
		}
		//
		// Error checking -- verify there is a description
		//
		if(strlen(trim($description))<1) {
			return false;
		}
		//
		// Error check -- see if there is an event already out there with this desc.
		//
		$max = count($this->my_events[$lm]);
		for($x=0; $x<$max; $x++) {
			//
			// Do a case insensitive check of the new event's description against the
			// current event
			//
			$ev = $this->my_events[$lm][$x];
			if(strcmp(strtolower(trim($ev)),
				strtolower(trim($dateformula) . "|" . trim($description)))==0) {
				//
				// They match, so kill the event
				//
				unset($this->my_events[$lm][$x]);
				return true;
			}
		}
		//
		// If we got here the deletion failed
		//
		return false;
	}

	//-----------------------------------------------------------------------------------
	//
	// delAllEvents()
	//
	//-----------------------------------------------------------------------------------
	function delAllEvents($month) {
		//
		// Error checking -- valid month
		//
		if(intval($month)==0) {
			if($this->isValid("$month 1, " . date("Y",strtotime("now")))) {
				$lm = intval(date("m",strtotime("$month 1, "
					. date("Y",strtotime("now")))));
			} else {
				return false;
			}
		} else {
			$lm = intval($month . "");
		}
		if($lm<1 || $lm>12) {
			return false;
		}
		//
		// Reset the array
		//
		$this->my_events[$lm] = array();
		if(count($this->my_events[$lm])>0) {
			return false;
		} else {
			return true;
		}
	}

	//-----------------------------------------------------------------------------------
	//
	// hasEvent()
	//
	//-----------------------------------------------------------------------------------
	function hasEvent($thedate) {
		//
		// Check to see if the given date is a holiday and, if it is, return the
		// text of the holiday; otherwise, return a blank line
		//
		$ret = "";
		//
		// If this is a valid date
		//
		if($this->isValid($thedate)) {
			//
			// Split out the date into its month, day, and year values
			//
			$m = date("m",$this->fixDate($thedate));
			$d = date("d",$this->fixDate($thedate));
			$y = date("Y",$this->fixDate($thedate));
			foreach($this->my_events[intval($m)] as $v) {
				list($hol, $desc) = split("\|",$v,2);
				if(intval($hol)==0) {
					//
					// The date given is a formula
					// * Replace the %YEAR% token (if exists)
					// * Strip out the actual day of the month
					//
					$thol = str_replace("%YEAR%",date("Y",$this->fixDate($thedate)),$hol);
					$hol = date("j",strtotime($thol));
				}
				//
				// Check the date verses this holiday's value
				//
				if(intval($hol)==intval($d)) {
					//
					// The passed day and this entry match, so add it
					//
					if(strlen($ret)>0) $ret .= "\n";
					$ret .= trim($desc);
				}
			}
		}
		return $ret;
	}

	//-----------------------------------------------------------------------------------
	//
	// mysql()
	//
	//-----------------------------------------------------------------------------------
	function mysql($ld, $tomysql=true, $leading0=true) {
		if($this->isValid($ld)) {
			if($tomysql) {
				return date("Y-m-d",strtotime(trim($ld . "")));
			} else {
				if($leading0) {
					return date("m/j/Y",strtotime(trim($ld . "")));
				} else {
					return date("n/d/Y",strtotime(trim($ld . "")));
				}
			}
		} else {
			return "";
		}
	}
}
?>
Return current item: cDates