Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/members/inc/
Upload File :
Current File : /var/www/cesa.co.za/members/inc/calendar.inc

<?
// list of names for days and months
$days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// number of days in each month
$totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

// set up some variables to identify the month, date and year to display
if(!$currYear) { $currYear = gmdate ("Y", time()+7200); }
if(!$currMonth) { $currMonth = gmdate ("n", time()+7200); }
if(!$currDay) { $currDay = gmdate ("j", time()+7200); }

// if leap year, modify $totaldays array appropriately
if (date("L", mktime(0,0,0,$currMonth,1,$currYear)))
	{
	$totalDays[2] = 29;	
	}

// set up variables to display previous and next months correctly

// defaults for previous month
$prevMonth = $currMonth-1;
$prevYear = $currYear;

// if January, decrement year and set month to December
if ($prevMonth < 1)
	{
	$prevMonth=12;
	$prevYear--;
	}	

// defaults for next month
$nextMonth = $currMonth+1;
$nextYear = $currYear;

// if December, increment year and set month to January
if ($nextMonth > 12)
	{
	$nextMonth=1;
	$nextYear++;
	}	

// get down to displaying the calendar
// find out which day the first of the month falls on
$firstDayOfMonth = date("w", mktime(0,0,0,$currMonth,1,$currYear));

$detect = strrpos($PHP_SELF,"/");
	if ($detect > 1) {
		$inc= "../inc/conf.inc";		
	} else {
		$inc = "inc/conf.inc";
	}
include($inc);

// open a connection to the database 
$connection = mysql_connect($server, $user, $pass);

// formulate the SQL query - same as above
$query = "SELECT DISTINCT date from calendar where (userid='$loginid' OR userid='saace_evt') AND date >= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-01' and date <= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-" . $totalDays[$currMonth] . "'";

// run the query on the database
$result = mysql_db_query($db,$query ,$connection);

$x=0;
$dateList=array();
if(mysql_num_rows($result) > 0)
{
	while($row =  mysql_fetch_array($result))
	{
	$dates = explode("-", $row["date"]);
	$dateList[$x] = $dates[2];
	$x++;
	}
}
// close connection
mysql_close($connection);
?>
<!-- month display -->
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td class="calendartexthead"><a class="calendartexthead" href="<? echo $PHP_SELF; ?>?currMonth=<? echo $prevMonth; ?>&currYear=<? echo $prevYear; ?>&currDay=<? echo $currDay; ?>">&lt;&lt;</a></td>
<td class="calendartexthead" colspan="5" align="CENTER"><? echo $months[$currMonth] . " " . $currYear; ?></td>
<td class="calendartexthead"><a class="calendartexthead" href="<? echo $PHP_SELF; ?>?currMonth=<? echo $nextMonth; ?>&currYear=<? echo $nextYear; ?>&currDay=<? echo $currDay; ?>">&gt;&gt;</a></td>
</tr>
<!-- day names -->
<tr>
<?
for ($x=0; $x<7; $x++)
{ 
echo "<td class=\"calendartextplain\">" . substr($days[$x],0,3) . "</td>"; 
}
?>
</tr>

<!-- start displaying dates -->
<tr>
<?
// display blank spaces until the first day of the month
for ($x=1; $x<=$firstDayOfMonth; $x++)
{
// this comes in handy to find the end of each 7-day block
$rowCount++;
echo "<td class=\"calendartext\"></td>\n";
}

// counter to track the current date
$dayCount=1;
while ($dayCount <= $totalDays[$currMonth])
{
	// use this to find out when the 7-day block is complete and display a new row
	if ($rowCount % 7 == 0)
	{
	echo "</tr>\n<tr>\n";
	}

// if today, display in different colour

// print date
if ($dayCount == date("j") && $currYear == date("Y") && $currMonth == date("n"))
{
echo "<td class=\"calendartext\" align=center bgcolor=#FFFFCC width=\"21\"><a href=/calendar.php4?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $dayCount . ">" . $dayCount. "</a>";

}
else
{
echo "<td class=\"calendartext\" align=center bgcolor=#EEEEEE width=\"21\"><a href=/calendar.php4?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $dayCount . ">" . $dayCount . "</a>";
}
for ($y=0; $y<sizeof($dateList); $y++)
{
//echo $dateList[$y];
	if ($dateList[$y] == $dayCount)
	{
	echo "+";
	}
}


echo "</td>\n";
// increment counters
$dayCount++;
$rowCount++;
}
?>
</tr>

<tr>
<td class="calendartextplain" align=right colspan=7>
<!--<a href="<? echo $HTTP_ENV_VARS["REDIRECT_URL"]."?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $currDay ?>">this month</a>-->
</td>
</tr>
<form method="get" action="<?php echo $PHP_SELF; ?>">
<tr><td colspan="3" class="calendartextplain" align="right">
<select name="currMonth" class="calendartextplain">
<?php
for ($i=1; $i <= 12; $i++) {
	if ($i == $currMonth) {
		echo "<option value=\"$i\" selected>".$months[$i];
	} else {
		echo "<option value=\"$i\">".$months[$i];
	}
}
?>
</select>
</td><td colspan="3" class="calendartextplain" align="right">
<select name="currYear" class="calendartextplain">
<?php
	$yearb4 = $currYear-2;
	$lastyear = $currYear-1;
	$nextyear = $currYear+1;
	$yearafter = $currYear+2;
	echo "<option value=\"$yearb4\">$yearb4";
	echo "<option value=\"$lastyear\">$lastyear";
	echo "<option value=\"$currYear\" selected>$currYear";
	echo "<option value=\"$nextyear\">$nextyear";
	echo "<option value=\"$yearafter\">$yearafter";
?>
</select>
</td><td class="calendartextplain" align="right">
<input type="submit" value="go" class="calendartextplain"></td></tr>
</form>
</td></tr>
</table>