Location: PHPKode > scripts > Event calendar class > event-calendar-class/ClsEventCalender.cls.php
<?php
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//									[Programmer: Md. Aminul Islam] (hide@address.com)										//
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//		Class: ClsEventCalender: Used for Showing Calender and Events(With Different Color)									//
	//				[ Limitation: ]																									//
	//				[ Required Folder: None]																						//
	//==============================================================================================================================//
	//function ClsEventCalender($HostName="",$UserName="",$Password="",$DatabaseName="") [Constructor]:- 							//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	This Function Takes 4 Parameters(Optional):-																				//
	//	$HostName = Host Name (eg. "localhost")																						//
	//	$UserName = User Name (eg. "aminulsumon")																					//
	//	$Password = Password(eg. "******").																							//
	//	$DatabaseName = Database (eg."events").																						//
	//==============================================================================================================================//
	//	function SetCalenderTableInfo($CalenderTblWidth,$CalenderTblBrdrWidth=0,$CalenderTblBrdrColor="#0000FF",					//
	//							$CalenderTblHeading="Event Calender.",$CalenderCellHeight=10)										//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	This Function Takes 5 Parameter:-																							//
	//	$CalenderTblWidth = The Width of Calender Table								 												//
	//	$CalenderTblBrdrWidth = Border Width of Calender Table																		//
	//	$CalenderTblBrdrColor = Border Color of Calender Table.																		//
	//	$CalenderTblHeading = The Heading Of Calender Table (eg."Event Calender")													//
	//	$CalenderCellHeight = Height of Every Cell of Calender [Size of Event is Set by this Cell Size]														//
	//==============================================================================================================================//
	//	function SetEventTableInfo($EventTblTopPos,$EventTblLeftPos=488,$EventTblWidth=0,$EventTblHeight=0)							//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	This Function Takes 4 Parameter:-																							//
	//	$EventTblTopPos = Distance of Event Table from Top of the Page																//
	//	$EventTblLeftPos = Distance of Event Table from Left of the Page																//
	//	$EventTblWidth = Width of Event Table (Default Calender Table Width)														//
	//	$EventTblTopPos = The Position of Events Table From Top																		//
	//==============================================================================================================================//
	//	function DrawCalender()																										//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	This Function Takes 0 Parameter:-																							//
	//	This function Return One Event Calender and One Event Viewer. Click the Event and Show it in Event Viewer.
	//------------------------------------------------------------------------------------------------------------------------------//
	/*	
		Example:-
		
			//First Run the Script event_calender.sql	(Using Database Name: class_test)
			
			include("ClsEventCalender.cls.php");
			$host="localhost";
			$user="root";
			$password="";
			$database="class_test";
		
			//Define Calender Table Properties(Size,Color...)
			$CalenderTblWidth=250;
			$CalenderTblBrdrWidth=1;
			$CalenderTblBrdrColor="#0000FF";
			$CalenderTblHeading="Event Calender";
			$CalenderCellHeight=20;	//Height of Calender Cell.
			$ObjEventCal->SetCalenderTableInfo($CalenderTblWidth,$CalenderTblBrdrWidth,$CalenderTblBrdrColor,
																		$CalenderTblHeading,$CalenderCellHeight);
			
			//Define Event Table Properties(Size,Color...)
			$EventTblTopPosition=73;
			$EventTblLeftPosition=631;
			$EventTblWidth=0;	//Same Width of Calender
			$EventTblHeight=240;
			$ObjEventCal->SetEventTableInfo($EventTblTopPosition,$EventTblLeftPosition,$EventTblWidth,$EventTblHeight);
			
			//Show The Calender with Events.
			$ObjEventCal->DrawCalender();
	*/			
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//==============================================================================================================================//

	require_once("ClsConnection.cls.php");
	Class ClsEventCalender extends ClsConnection
	{
		var $CalenderTblWidth;	//Calender Table Width.
		var $CalenderTblBrdrWidth;
		var $CalenderTblBrdrColor;
		var $CalenderTblTDWidth;	//Calculated from $CalenderTblBrdrColor
		var $CalenderTblHeading;
		var $CalenderCellHeight;
		
		var $EventTblTopPos;
		var $EventTblLeftPos;
		var $EventTblWidth;
		var $EventTblHeight;
		
		function ClsEventCalender($HostName="",$UserName="",$Password="",$DatabaseName="")	//Constructor.
		{
			$this->ClsConnection();
		}
		function SetCalenderTableInfo($CalenderTblWidth,$CalenderTblBrdrWidth=0,$CalenderTblBrdrColor="#0000FF",
								$CalenderTblHeading="Event Calender.",$CalenderCellHeight=10)
		{
			//Select TD Width = $CalenderTblWidth Divide 7.If TD Width>5.0 then TD Width=6 
			$this->CalenderTblTDWidth=ceil($CalenderTblWidth/7);
			$this->CalenderTblWidth=ceil($CalenderTblWidth/7)*7;
			$this->CalenderTblBrdrWidth=$CalenderTblBrdrWidth;
			$this->CalenderTblBrdrColor=$CalenderTblBrdrColor;
			$this->CalenderTblHeading=$CalenderTblHeading;
			$this->CalenderCellHeight=$CalenderCellHeight;

			//echo "Calender Table Width: $this->CalenderTblWidth <br> Calender Table TD Width: $this->CalenderTblTDWidth <br> ";
			//echo "Event Table Width= $this->EventTblWidth <br>Event Top Position= $this->EventTblTopPos <br>";
			//echo "Calender Cell Height= $this->CalenderCellHeight";
		}
		function SetEventTableInfo($EventTblTopPos,$EventTblLeftPos=488,$EventTblWidth=0,$EventTblHeight=0)
		{
			$this->EventTblTopPos=$EventTblTopPos;	//The Distance of Event Div from Top of Page.
			$this->EventTblLeftPos=$EventTblLeftPos;
			if($EventTblWidth==0)
				$this->EventTblWidth=$this->CalenderTblWidth;	//Default Load Calender and Event Table Width are Same.
			else
				$this->EventTblWidth=$EventTblWidth;
			$this->EventTblHeight=$EventTblHeight;
		}

		function DrawCalender()
		{
			$db_event=$this->db;

			if(isset($_GET['time']))
				$time=$_GET['time'];
			else
				$time=time();
			
			$today = getdate($time); 
			$mday = $today ['mday'];
			$mon  = $today ['mon'];   
			$year  = $today ['year'];  

			$time = mktime(0, 0, 0, $mon,1,$year);

			$today = getdate($time); 
			$wday  = $today ['wday'];  
			$year  = $today ['year'];  
			$weekday = $today ['weekday'];
			$CurMonth  = $today ['month'];
			$i= -$wday;
			$CurPage=$_SERVER['PHP_SELF'];

			$time = mktime(0, 0, 0, $mon+1,0,$year);
			$lastDay=date('j',$time);

			$sql="SELECT DATE_FORMAT(EventDate,'%d') AS day,EventDate,EventId,EventTitle,EventVanue FROM events WHERE EventDate BETWEEN  '$year/$mon/01' AND '$year/$mon/31'";	
			$result=mysql_query($sql);
			$AllEvents=array();
			
			//************** Assign All Events For Current Month ************************
		
			while($row_event=mysql_fetch_object($result))
			{
				$AllEvents[intval($row_event->day)].=" <table width='100%' align='center' border='0' cellpadding='0' cellspacing='0'>	";
				$AllEvents[intval($row_event->day)].="		  <tr class='event_head'  height='20'><td width='18%'>&nbsp;Date</td><td width='2%'><strong>:</strong></td><td width='80%'>&nbsp; $row_event->EventDate </td></tr>";
				$AllEvents[intval($row_event->day)].="		  <tr class='event_col'><td>&nbsp;Title</td><td><strong>:</strong></td><td height='25' class='event_link'><a href='events_detail.php?EventId='>$row_event->EventTitle</a></td></tr>";
				$AllEvents[intval($row_event->day)].="		  <tr class='event_col'><td>&nbsp;Vanue</td><td><strong>:</strong></td><td height='25' class='event_col'>$row_event->EventVanue</td></tr>";
				$AllEvents[intval($row_event->day)].="		  <tr bgcolor='#FFFFFF'><td colspan='3' ><img src='../../s.gif' width='1' height='1'></td></tr>";
				$AllEvents[intval($row_event->day)].=" </table>";
			}
				
			echo "<style>\n";
				//Event Dates of Clender Color
				echo ".event_cls {background-color: #04ADFF;color:#FFFFDD; font-weight: bold; text-decoration: none; cursor: hand;}\n";
				//Event Head (Head of Col) Sun, Mon, Tue.....
				echo ".event_head{background-color: #99CC00;font-weight:bold;FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 11px;}\n";
				echo ".event_col{background-color:#A8E4FF;color:#000095;FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 11px;height:25px;text-decoration: none;}\n";
				echo ".event_link {TEXT-DECORATION: none; color:#0DB0FF; }\n";
				echo ".a {TEXT-DECORATION: none; color:#0DB0FF; }\n";
				echo ".Links {	font-family: Tahoma, Sylfaen; font-size: 13px; color: #FFFFFF; font-weight: bolder; Text-decoration:none; }\n";
				echo ".event_cal_heading{ font-family: 'Courier New', Courier, mono;	font-size: 18px; color: #FFFFFF; font-weight:bold; background-color: #0000FF;}";
			echo "</style>";

			//Start Drawing Calender.....
			echo "<table width='$this->CalenderTblWidth' border='$this->CalenderTblBrdrWidth' bordercolor='$this->CalenderTblBrdrColor' cellpadding='0' cellspacing='0'>\n";	//Most Outer Table
			echo "<tr><td>";
			echo "<table width='100%' border='0' align='center' cellspacing='1'>\n";
			$CalenderTblHeadingHeight=$this->CalenderCellHeight+($this->CalenderCellHeight/4);
			echo "<tr height='$CalenderTblHeadingHeight'><td align='center'  colspan='7' class='event_cal_heading'>$this->CalenderTblHeading</td></tr>";
			echo "<tr align='center' bgcolor='#7575FF' class='.Links' height='$this->CalenderCellHeight'> \n";
				echo "<td width='$this->CalenderTblTDWidth' ><b><a href='$CurPage?time=".mktime(0, 0, 0, $mon,$mday,$year-1)."' title='Previous Year' >««</a></b></td>\n";
				echo "<td width='$this->CalenderTblTDWidth'><b><a href='$CurPage?time=".mktime(0, 0, 0, $mon-1,$mday,$year)."' title='Previous Month' >«</a></b></td>\n";
				echo "<td colspan='3' class='event_col'> <b>$CurMonth $year</b></td>\n";
				echo "<td width='$this->CalenderTblTDWidth'><b><a href='$CurPage?time=".mktime(0, 0, 0, $mon+1,$mday,$year)."' title='Next Month' >»</a></b></td>\n";
				echo "<td width='$this->CalenderTblTDWidth'><b><a href='$CurPage?time=".mktime(0, 0, 0, $mon,$mday,$year+1)."' title='Next Year' >»»</a></b></td>\n";
			echo "</tr>\n";
			
			$DayCellHeight=10;
			echo "<tr class='event_col' >\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head' height='$DayCellHeight' >Sun</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Mon</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Tue</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Wed</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Thu</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Fri</td>\n";
				echo "<td align='center' width='$this->CalenderTblTDWidth' class='event_head'>Sat</td>\n";
			echo "</tr>\n";
			
			echo "<script>\n";
			foreach($AllEvents as $CurColumney => $value)
			echo "evnt$CurColumney=\"$value\"\n";

			echo "function showevent(day)\n";
			echo "{";
			echo "	evnt=eval('evnt'+day);\n";
			echo "	mydiv=document.getElementById('event');\n";
			echo "	mydiv.innerHTML=evnt\n";
			echo "}";

			echo "</script>\n";
			
			$DateCellHeight=10;
			for($CurRow=0;$CurRow<6;$CurRow++)
			{ 
				echo "<tr class='event_col'> \n";
				for($CurColumn=0;$CurColumn<7;$CurColumn++)
				{ 
					$i++;
					$cls="class='event_col'";
					if(array_key_exists($i,$AllEvents))
					$cls="class=event_cls onclick='showevent($i)'";
					echo "<td align='center' width='$this->CalenderTblTDWidth' height='$DateCellHeight' $cls>\n";
					echo ($i>0&&$i<=$lastDay)?$i:'';
					echo "</td>";
				}
				echo "</tr>" ; 
			}

			//Start Drawing Event Div..
			//$this->EventTblTopPos = Height of Event Table(Usually <div id='ShowEvents'> height.)
			//$this->EventTblHeight=240;
			//$this->EventTblLeftPos=488;
			
			$DefaultEventContent="<br><br><br><br><br><h4><p align='center'>Md. Aminul Islam.</p></h4>";
			echo " <tr > <td colspan=8 >\n";
			echo " <div id='ShowEvents' class='event_col' style='position:absolute; width:$this->EventTblWidth; height:$this->EventTblHeight; z-index:1; left:$this->EventTblLeftPos; top:$this->EventTblTopPos; border-width:3px;' >
				 	<table width='100%' border='0' cellpadding='0' cellspacing='0'>
					<tr><td class='event_cal_heading' align='center' height='30'>Current Event</td></tr>
					<tr><td bgcolor='#FFFFFF'><img src='../../s.gif' width='1' height='1'></td></tr></table>";
			echo " <div id='event' style='position:absolute; width:$this->EventTblWidth; height:242px; z-index:1; left: 0px; top: 31px; overflow: auto; border-width:3px; valign='middle''>
					$DefaultEventContent<p align='center'>bGlobal Sourcing</p></div></td></tr></table>\n";
			echo "</td></tr></table>\n";	//Closing Outer Table.
		}
	}
?>
Return current item: Event calendar class