Location: PHPKode > scripts > Calendar Matrix > calendar-matrix/class.calendar.php
<?php
// --------------------------------------------------------------------------------
// Dozman Library - Calendar Days Generator Module 1.0
// --------------------------------------------------------------------------------
// License GNU/LGPL - Peter Ramokone - July  2005
// --------------------------------------------------------------------------------
//
//   Password Generator is a PHP library that generates  Calendar Days inside an array of each row of the calender.
//
// Description :
// 	see exmple.php
//
// Warning :
//   This library and the associated files are non commercial.
//   It should not have unexpected results. However if any damage is caused by
//   this software the author 'Peter Ramokone' can not be responsible.
//   The use of this software is at the risk of the user.
//
// --------------------------------------------------------------------------------
//  class.calendar.php ,v 1.0 2005/04/07 
class calendar_matrix
{
	var $number_of_days;	//number of days in a month
	var $day_of_month;		// day in a month
	var $month;				// the month of the calender
	var $year;				// the year of the calender
	var $weak_start_with; 	//	6 stands for sunday
	var $month_start_from;  // first day of the month
	var $full_date;			// the date and time 
	var $calendar_days=array();	// all days of the calendar, including the empty blocks of each colum
	var $final_calendar=array();// dimentional array of all the calendar days 
	function calendar_matrix()	
	{
		$this->full_date		=getdate(time());
		$this->month			=$this->full_date["mon"];
		$this->year				=$this->full_date["year"];
		$this->weak_start_with	=6;
		$this->number_of_days	=date('t');
		$this->day_of_month		=$this->full_date["mday"] ;		
	}
	function drawCalDays()
	{
		$fulldate=getdate(mktime(0, 0, 0, $this->month, 1, $this->year));
		$this->month_start_from=$fulldate["wday"];
		for($x=0;$x<$this->month_start_from;$x++){	$this->calendar_days[]=0;}		
		for($y=1;$y<=$this->number_of_days;$y++){	$this->calendar_days[]=$y;}
		return $this->drawCalendar();
	}	
	function drawCalendar()
	{		
		$colum_group=array();
		$colum_count=0;
		$dayscount=count($this->calendar_days);
		foreach($this->calendar_days as $index=>$value)
		{
			$colum_group[]=$value;
			$colum_count++;
			if($colum_count==7)
			{
				$colum_count=0;
				$this->final_calendar[]=$colum_group;
				$colum_group='';								
			}
			if($this->calendar_days[($dayscount-1)]==$value)
			{				
				$lastrowcount=count($colum_group);
				if($lastrowcount<=6)
				{
					$remaining=((7)-($lastrowcount));					
					for($z=0;$z<$remaining;$z++)
					{
						$colum_group[]=0;
					}		
					$colum_count=0;
					$this->final_calendar[]=$colum_group;
					$colum_group='';				
				}	
				else
				{
					$colum_count=0;
					$this->final_calendar[]=$colum_group;
					$colum_group='';	
				}
			}
		}		
		return $this->getCalendarArray();
	}
	function getCalendarArray()
	{
		return $this->final_calendar;
	}
	function calendar($user_year=0,$user_month=0)
	{		
		$this->year=($user_year)?$user_year:$this->year;
		$this->month=($user_month)?$user_month:$this->month;
		return $this->drawCalDays();		
	}
}
$DOZCALENDAR=new calendar_matrix();
?>
Return current item: Calendar Matrix