<?php
/***************************************************************
 * PHP FUNCTIONS
 *
 **************************************************************/

 //Global Variables
 $lastEvent = '0101';
 $eventCount = 0;
 $context = '/hog';

 $PAGE_TITLE = '';
 $PAGE_DESCRIP = 'The House of Glory is a parish of The Redeemed Christian Church of God, and is located in Baltimore, Maryland. It is a place where christians in the area can come together in communal worship, and hear the unadulterated word of God, while fellowshiping with other believers.';

 $images_array = array();

 function setImagesArray()
 {
	global $images_array, $context;
 	$imgdir = $_SERVER['DOCUMENT_ROOT'].$context. "/images";
 	if (empty($images_array))
 	{
 		$images_array = scandir($imgdir, 1);
 		array_pop($images_array);
		array_pop($images_array);
 	}
 }

function getRandomImage()
{
	global 	$images_array;

	$count = count($images_array);
	$index = rand(0,$count);
	$img_url = $dir. './images/'. $images_array[$index];
	return $img_url;
}

	function setPageTitle($pageTitle)
	{
	 	global $PAGE_TITLE;
	 	$PAGE_TITLE= $pageTitle;
	}

	function pageTitleHeader()
	{
		global $PAGE_TITLE;
		//$PAGE_TITLE = pageTitle;
		$str =  '<div class="headerbox"><h1>';
		//$str .= $pageTitle;
		$str .= $PAGE_TITLE;
		$str .= '</h1></div><br/>';

		//echo $str;
		return $str;
	}

	function getPageTitle()
	{
	 	global $PAGE_TITLE;
		$str;

	 	if ($PAGE_TITLE != '')
	 	 $str = $PAGE_TITLE . ' - ';

	 	return $str;
	}

	function setPageDescription($descrip)
	{
		global $PAGE_DESCRIP;
		if($descrip != '')
		{
			$PAGE_DESCRIP = $descrip;
		}
	}

	function printPageDescription()
	{
		global $PAGE_DESCRIP;
		echo '<meta name="description" content="'
				.$PAGE_DESCRIP.'">';
	}

 	function getCurrentYear()
 	{
 		$currentDate = getdate();
 		$currentYear = $currentDate['year'];
 		return $currentYear;
 	}


	function todayIs()
	{
		$currentDate = getdate();
		echo $currentDate['weekday']." ". $currentDate['month']." ".$currentDate['mday'].", ".$currentDate['year'];
	}


	/*
	 * Parses the $month and $day into an  'mmdd' format
	 */
	function dateMMDD($month, $day)
	{
		if ($month < 10)
		{
			$month = '0'. $month;
		}

		if ($day < 10)
		{
			$day = '0'. $day;
		}

		return $month.$day;
	}

	function dateMMDDYYY($year, $month, $day)
	{

		return dateMMDD($month, $day).$year;
	}

	function dateNumbers($month, $day, $year)
	{
		$year = 10000 * $year;
		$month = 100 * $month;
		return $year + $month + $day;
	}

	//deal with my menu highlights
	//highlighted item is previous event that has passed ($prevMonthDigit, $prevDay)
	function highlightEvents($event, $eventDate, $prevMonthDigit, $prevDayDigit, $prevYearDigit)
	{
		global $lastEvent, $eventCount;

		$currentDate = getdate();
		$currentMonth = $currentDate['mon'];
		$currentDay = $currentDate['mday'];
		$currentYear = $currentDate['year'];

		$currentDateNumber = dateNumbers($currentMonth, $currentDay, $currentYear);
	//echo "current: " . $currentDateNumber;
		$eventDateNumber = dateNumbers($prevMonthDigit, $prevDayDigit, $prevYearDigit);
	//echo "event: " . $eventDateNumber;

		$timeElapsed = $currentDateNumber - $eventDateNumber;

		if ($eventCount <=13 && ( $timeElapsed < 400) )
		{
			//past events
			if ( $currentDateNumber > $eventDateNumber )
			{
				echo "<IMG  src=\"images/a_sep.gif\"width=10 height=10>" .
					"<span style=\"color:#C0C0C0;\">" .
					"<b>&nbsp;&nbsp;" . $event . "</b>" .
					"&nbsp;&nbsp;<span style=\"color:#C0C0C0;\">[" . $eventDate."]</span><br>" .
					"</span>";
					$lastEvent= eventDateNumber;
			}
			//next event
			else if ($lastEvent < $eventDateNumber )
			{
				//highlight coming event
				echo "<IMG  src=\"images/a_sep.gif\"width=10 height=10>" .
					"<span style=\"background-color:#FFFF33;\">" .
					"<b>&nbsp;&nbsp;" . $event . "</b>" .
					"&nbsp;&nbsp;<span style=\"color:red;\">[" . $eventDate ."]</span><br>" .
					"</span>";
				$lastEvent= '20991231'; //long future date
			}
			//future events
			else
			{
				echo "<IMG  src=\"images/a_sep.gif\"width=10 height=10>" .
				"<b>&nbsp;&nbsp;" . $event . "</b>" .
				"&nbsp;&nbsp;<span style=\"color:red;\">[" . $eventDate."]</span><br>";
			}
			$eventCount++;
		}
	}

	//deal with my menu highlights
	//highlighted item is previous event that has passed ($prevMonthDigit, $prevDay)
	function oldhighlightEvents($event, $month, $day, $prevMonthDigit, $prevDay)
	{
		$currentDate = getdate();
		$currentMonth = $currentDate['mon'];
		$currentDay = $currentDate['mday'];

		if (dateMMDD($currentMonth, $currentDay) > dateMMDD($prevMonthDigit, $prevDay) )
		{
			echo "<IMG  src=\"images/a_sep.gif\"width=10 height=10>" .
			"<span style=\"background-color:#FFFF99;\">" .
				"<b>&nbsp;&nbsp;" . $event . "</b>" .
				"&nbsp;&nbsp;<span style=\"color:red;\">[" . $month . " " . $day ."]</span><br>" .
			"</span>";
		}
		else
		{
			echo "<IMG  src=\"images/a_sep.gif\"width=10 height=10>" .
			"<b>&nbsp;&nbsp;" . $event . "</b>" .
			"&nbsp;&nbsp;<span style=\"color:red;\">[" . $month . " " . $day ."]</span><br>";
		}
	}

	//converts the month digit to the month name
	function toMonthName($monthDigit)
	{
		switch ($monthDigit)
		{
			case '1': $month = 'January';
			case '2': $month = 'February';
			case '3': $month = 'March';
			case '4': $month = 'April';
			case '5': $month = 'May';
			case '6': $month = 'June';
			case '7': $month = 'July';
			case '8': $month = 'August';
			case '9': $month = 'September';
			case '10': $month = 'October';
			case '11': $month = 'November';
			case '12': $month = 'December';
		}
		return $month;
	}

	//converts the month digit to the month name
	function toMonthDigit($month)
	{
		switch ($month)
		{
			case 'January': $monthDigit = '0';
			case 'February': $monthDigit = '1';
			case 'March': $monthDigit = '2';
			case 'April': $monthDigit = '3';
			case 'May': $monthDigit = '4';
			case 'June': $monthDigit = '5';
			case 'July': $monthDigit = '6';
			case 'August': $monthDigit = '7';
			case 'September': $monthDigit = '8';
			case 'October': $monthDigit = '9';
			case 'November': $monthDigit = '10';
			case 'December': $monthDigit = '11';
		}
		return $monthDigit;
	}


/** past usage for old
<?php highlightEvents("7-day Fast", 'Jan', '2-8', 5, 31); ?>
<?php highlightEvents("28-day Fast", 'Feb', '1-28', 1, 8); ?>
<?php highlightEvents("Gethsemane Summit", 'Feb', '15-17', 1, 8); ?>
<?php highlightEvents("Maximum Impact Simulcast", 'Apr', '18', 2, 17); ?>
<?php highlightEvents("Peniel Encounter", 'Apr', '25-27', 4, 18); ?>
<?php highlightEvents("RCCGNA Convention", 'Jun', '18-22', 4, 27); ?>
<?php highlightEvents("Family Empowerment", 'Jul', '11-13', 6, 22); ?>
<?php highlightEvents("Glory Cloud", 'Aug', '17-24', 7, 13); ?>
<?php highlightEvents("Picnic", 'Sep', '6', 8, 24); ?>
<?php highlightEvents("DOZ Annual Conf", 'Sep', '20', 9, 6); ?>
<?php highlightEvents("Retreat", 'Sep 28', '- Oct 4', 9, 20); ?>
<?php highlightEvents("RCCGNA Workers Rally", 'Oct', '8', 10, 4); ?>
<?php highlightEvents("Festival of Life", 'Oct', '10', 10, 8); ?>
<?php highlightEvents("RCCGNA Ministers' Conf.", 'Oct', '16-18', 10, 10); ?>
**/





?>