Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/Blocks/Block_minicalendar.php
<?php
/*
*****************************************************************

 Block_minicalendar.php
 
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version:                  LSP 2.0 "Enigma 2"
Software by:                         Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by:       Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at:    http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it 
under the terms of the provided license as published by Lunabyte Systems.

This program is distributed in the hope that it is and will be useful,                  
but WITHOUT ANY WARRANTIES; without even any implied warranty of           
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        

See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/

if (!defined('ENIGMA'))
	die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');

// minicalendar & support functions
function Block_minicalendar ()
{
	global $sourcedir, $scripturl, $modSettings;

	$today = date("d");
	$month = date("m");
	$year = date("Y");
	$datecode = date("Ymd");

	$first = mktime(0,0,0, $month,1,$year);
	$mon_yr = date("F Y", $first); 

	$wd = date("w",$first);
	$lastday = date("d", mktime(0,0,0,$month+1,0,$year));
	$cur =- $wd+0;

	require_once $sourcedir . '/Calendar.php';

	// make date strings YYYY-MM-DD for the calendar
	$dates['first']	= date("Y-m-d",mktime(0,0,0,$month,0,$year));
	$dates['last']	= date("Y-m-d",mktime(0,0,0,$month+1,0,$year));

	// build arrays of all birthdays, events, holidays this month and add a link to the calendar
	$thismonth['events']	= calendarEventArray($dates['first'], $dates['last']);
	$thismonth['birthday']	= calendarBirthdayArray($dates['first'], $dates['last']);
	$thismonth['holiday']	= calendarHolidayArray($dates['first'], $dates['last']);

	echo '
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="blockcalweek">
	<caption class="blockcal">', $mon_yr, '</caption>
	<tr>
		<th class="blockcalweek" width="15%">S</th>
		<th class="blockcalweek" width="15%">M</th>
		<th class="blockcalweek" width="15%">T</th>
		<th class="blockcalweek" width="15%">W</th>
		<th class="blockcalweek" width="15%">T</th>
		<th class="blockcalweek" width="15%">F</th>
		<th class="blockcalweek" width="15%">S</th>
	</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="blockcal">
	<tr>';

	for ($week=0; $week<6; $week++)
	{
		if ($cur>$lastday)
			continue;

		if ($week>0)
			echo '
	</tr><tr>';

		for ($day=0;$day<7;$day++)
		{
			$cur++;
			if (($cur>0) || ($cur<$lastday))
			{
				echo '
		<td width="15%" class="', ($cur==$today) ? 'blockcaltoday' : (($cur<$today) ? 'blockcalpast' : 'blockcal'), '">';
			}

			if (($cur<=0) || ($cur>$lastday)){} // just skiping this cell!!
			else
			{
				echo minitoday($cur, $thismonth) ? '<a href="' . $scripturl . '?action=calendar" title="'.buildtitle($cur, $thismonth).'">' : '';
				echo ($cur==$today) ? '<b>' . $cur . '</b>' : $cur;
				echo minitoday($cur, $thismonth) ? '</a>' : '';
			}
			echo '</td>';
		}
	}

echo '
	</tr>
</table>';
	unset($thismonth, $dates);
}

function minitoday ($day, $thismonth)
{
	if (array_key_exists($day, $thismonth['holiday']))	return 1;
	if (array_key_exists($day, $thismonth['events']))	return 1;
	if (array_key_exists($day, $thismonth['birthday']))	return 1;

	return 0;
}

function buildtitle($cur, $thismonth)
{
	$return = 'Events: ' . @count($thismonth['events'][$cur]) . '
';
	$return .= 'Holidays: ' . @count($thismonth['holiday'][$cur]) . '
';
	$return .= 'Birthdays: ' . @count($thismonth['birthday'][$cur]);

	return $return;
}
// end minicalendar functions
?>
Return current item: Enigma