Return to Snippet

Revision: 3880
at September 27, 2007 13:02 by others


Initial Code
<?php
	/************************************************************
	*	PHP Calendar by Scott Richardson, ScanOnline June 2002 	*
	*	[email protected]								*
	************************************************************/

	//date sent to calendar
	if( !isset($_REQUEST["CurrentMonth"]) ) {
		$WorkDate = date("m/d/Y");
	}
	else{
		$WorkDate = $_REQUEST['CurrentMonth'];
	}
	$PrevMonth = date("m/d/Y", strtotime($WorkDate . "-1 month"));
	$NextMonth = date("m/d/Y", strtotime($WorkDate . "+1 month"));

	//page that called the calendar
	if( !isset($_REQUEST["ParentPage"]) ) {
		$ParentPage = "";
	}
	else{
		$ParentPage = $_REQUEST["ParentPage"];
	}

	$Today = date("j",strtotime($WorkDate));
	$DaysThisMonth = DaysInMonth(date("m/d/Y",strtotime($WorkDate)));
	$DaysLastMonth = DaysInMonth(date("m/d/Y", strtotime ($PrevMonth)));
	$InThisMonth = 0;
	$CurrentDate = GetStartingPoint($DaysLastMonth);

	//Head
	echo "<html><head></head>";

	//Body
	echo "<body topmargin='100' leftmargin='100' marginheight='100' marginwidth='100'>";


	echo "<table bgcolor='B0C4DE' height='100%' width='100%' border='1'><tr>";
	echo "<td colspan='7' height='8%' align='center' >";

	echo "<table height='100%' width='100%' border='0'><tr>";
	echo "<td align='left'><b><font size='2'><a href='http://localhost/calendar/cal.php?CurrentMonth=".$PrevMonth."&ParentPage=".$ParentPage."'>Mês<br>Anterior</a></font></b></td>";
	echo "<td align='center'>";
	echo "<font size='5'><b>".date("F Y",strtotime($WorkDate))."</b></font><br><a href='http://localhost/calendar/cal.php?CurrentMonth=".date("m/d/Y")."&ParentPage=".$ParentPage."'>Data de Hoje</a></td>";
	echo "<td align='right'><b><font size='2'><a href='http://localhost/calendar/cal.php?CurrentMonth=".$NextMonth."&ParentPage=".$ParentPage."'>Próximo<br>Mês</a></font></b></td></tr></table>";

	echo "</td></tr>";
	echo "<td height='8%' align='center' valign='top' width='15%' bgcolor='B0C4DE'><font size='4'><b>Su</b></font></td>";
	echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Mo</b></font></td>";
	echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Tu</b></font></td>";
	echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>We</b></font></td>";
	echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Th</b></font></td>";
	echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Fr</b></font></td>";
	echo "<td align='center' valign='top' width='15%' bgcolor='B0C4DE'><font size='4'><b>Sa</b></font></td></tr>";

	for($x=1;$x<7;$x++){
		echo "<tr>";
		for($i=1;$i<8;$i++){
			echo "<td align='left' valign='top' height='14%' ";

			if($InThisMonth==0){
				echo "bgcolor='#D3D3D3'>";
				echo $CurrentDate++;
			}
			else{
				if( $CurrentDate == date("j") && date("n",strtotime($WorkDate)) == date("n") && date("y",strtotime($WorkDate)) == date("y") ){
					echo "bgcolor='FFFACD'>";
				}
				else{
					echo "bgcolor='#FFFFFF'>";
				}

				if( $ParentPage ){
					echo "<a href='".$ParentPage."?CalendarDate=".GetThisDate($CurrentDate)."'>".$CurrentDate++."</a>";
				}
				else{
					echo $CurrentDate++;
				}
			}

			echo "</td>";

			if( $InThisMonth == 0 && $CurrentDate > $DaysLastMonth ){
				$CurrentDate = 1;
				$InThisMonth = 1;
			}
			elseif($InThisMonth == 1 && $CurrentDate > $DaysThisMonth ){
				$CurrentDate = 1;
				$InThisMonth = 0;
			}

		}
		echo "</tr>";
	}

	echo "</table></body></html>";


	function DaysInMonth($dt) {
		return date("t",strtotime($dt));
	}

	function GetStartingPoint($DLM){
		$today = getdate(strtotime($GLOBALS['WorkDate']));
		$mday = $today['mday'];
		$mday-=1;
		$FirstOfMonth = date("m/d/Y",strtotime($GLOBALS['WorkDate'] . "-" . $mday . " days"));

		switch(date("l",strtotime($FirstOfMonth))){
		case "Sunday":
			$CD = 1;
			$GLOBALS["InThisMonth"] = 1;
			break;

		case "Monday":
			$CD = $DLM;
			break;

		case "Tuesday":
			$CD = $DLM-1;
			break;

		case "Wednesday":
			$CD = $DLM-2;
			break;

		case "Thursday":
			$CD = $DLM-3;
			break;

		case "Friday":
			$CD = $DLM-4;
			break;

		case "Saturday":
			$CD = $DLM-5;
		}

		return $CD;
	}

	function GetThisDate($SelectedDay){
		$today = getdate(strtotime($GLOBALS['WorkDate']));
		$mon = $today['mon'];
		$myear = $today['year'];
		return date("m/d/Y", strtotime($mon."/".$SelectedDay."/".$myear));
	}
?>

Initial URL


Initial Description


Initial Title
codigo calendar

Initial Tags


Initial Language
PHP