Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/php/
Upload File :
Current File : /var/www/cesa.co.za/php/Inc_calendarnew.php

<?php 
include_once('inc_db.php');	

$NumMonths = 6;

if (isset($_REQUEST["NumMonths"])) {
	if ($_REQUEST["NumMonths"]=="y2018") {
		if (date("Y")==2017) {
			$NumMonths=(13-date("m"))+12;
		} else {
			$NumMonths=13-date("m");
		}
	} else {
		$NumMonths=intval($_REQUEST["NumMonths"]);
	}
}
?>
<style>
.smallfonts {border:1px solid; border-collapse:collapse;}
.smallfonts td { font-family:Tahoma; font-size:10px; border:1px solid #CCCCCC;}
.smallfonts th { font-family:Tahoma; font-size:10px;}

@media screen {

div#tbl-container {
width: 650px;
height: 350px;
overflow: auto;
position:absolute;
left:220px;
border:2px outset;
background-color:white;
}

/*table {
table-layout: fixed;
border-collapse: collapse;
}*/

td.locked,  th.locked {
position: relative;
z-index: 10;
font-family:Tahoma; font-size:10px;
border:1px solid #CCCCCC;
border-collapse:collapse;
background-color:#CCCCCC;
}

.eventname {
		font-family: Verdana, Arial, sans-serif;
		font-size:11px;
}
}

</style>
<table border=0 cellspacing=0 cellpadding="0" width="100%">
<tr>
	<td width="50%" align="left">&nbsp;<!--<a href="http://www.cesa.co.za/public_downloads/FIDIC_INDUNA.pdf" target="_blank"><img src="http://www.cesa.co.za/images/scroller/Induna_Course_Banner.jpg"></a>-->
<form method="get" action="/scecalendar">
<input type="hidden" name="test" value="1">
	Number 
	of months to display: <select name="NumMonths">
	<option value="6"<?php if (!isset($_REQUEST["NumMonths"]) || ($_REQUEST["NumMonths"]=="6")) echo " selected"; ?>>Next 6 months</option>
	<option value="12"<?php if ($_REQUEST["NumMonths"]=="12") echo " selected"; ?>>Next 12 months</option>
	<option value="y2018"<?php if ($_REQUEST["NumMonths"]=="y2018") echo " selected"; ?>>To end of 2018</option>
	</select><br>
	Category to display: <select name="cat">
	<option value=""<?php if (!isset($_REQUEST['cat']) || empty($_REQUEST['cat'])) echo " selected"; ?>All</option>
<?php
	$catrs=mysql_query("SELECT * FROM SchoolWebCategories ORDER BY DisplayOrder");
	while ($catrow=mysql_fetch_assoc($catrs)) {
?>	
	<option value="<?php echo $catrow["WebCategoryID"]; ?>"><?php if ($_REQUEST["cat"]==$catrow["WebCategoryID"]) echo " selected"; ?>><?php echo $catrow["WebCategoryName"]; ?></option>
<?php
	}
?>	
	</select><br>
	<input type="submit" value="Update Calendar">
</form>
	</td>
<td width="50%" align="right"><a href="/php/calendarpdf.php" target="_blank"><img src="/images/icon_pdf.gif" border="0" align="absmiddle" />&nbsp;<strong>Download as a PDF (for easy printing)</strong></a></td></tr>
<!-- <tr><td width="50%"><small>Drag the edges of the box to resize the calendar</small></td>
<td width="50%">&nbsp;</td></tr> -->
</table>
?>
<table width=100% cellspacing=0 cellpadding=2 class="smallfonts" id="tbl">
<thead>
<tr><th colspan=2 class='locked'>&nbsp;</th>
<th colspan=<?php echo $NumMonths; ?> align=center class='locked'><B>MONTH</b></th></tr>
<tr>
<th class='locked'><b>TOPIC</b></th><th class='locked'><strong>CPD<br>Points</strong></th>
<?php
	$lastmonthShown = 0;
	for ($z = date("n"); $z <= (date("n")+($NumMonths-1)); $z++) {
		$usez = $z;
		if ($usez > 12) $usez = $usez-12;
		echo "<th align=center class='locked'>".date("M", strtotime(date("Y")."-".$usez."-01"))."</th>";
		$lastmonthShown = $usez;
	}
?>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM SchoolWebCategories ";
if (isset($_REQUEST["cat"]) && !empty($_REQUEST["cat"])) $sql.=" WHERE WebCategoryID=".intval($_REQUEST["cat"]);
$sql.=" ORDER BY DisplayOrder";
$catrs=mysql_query($sql);

while ($catrow=mysql_fetch_assoc($catrs)) {

	$sql = "SELECT SchoolEvents.EventID, SchoolEvents.EventName, SchoolEvents.City,	SchoolEvents.CostPerPerson, 
	SchoolEvents.AccredNum, SchoolEvents.CPD, SchoolEvents.Cancelled, SchoolEvents.Venue, 
	CourseVenues.CourseVenueCity, MIN(EventSchedules.ScheduleDate) AS StartDate, 
	MAX(EventSchedules.ScheduleDate) AS EndDate
	FROM (SchoolEvents LEFT JOIN CourseVenues ON SchoolEvents.Venue = CourseVenues.CourseVenueName)
	LEFT JOIN EventSchedules ON SchoolEvents.EventID=EventSchedules.EventID
	WHERE Cancelled=0 AND WebCategory=".$catrow["WebCategoryID"]."
	GROUP BY SchoolEvents.EventID, SchoolEvents.EventName, SchoolEvents.City, SchoolEvents.CostPerPerson, 
	SchoolEvents.AccredNum, SchoolEvents.CPD, SchoolEvents.Cancelled, SchoolEvents.Venue, 
	CourseVenues.CourseVenueCity
	HAVING StartDate >= '".date("Y-m")."-01'
	AND StartDate < '".date("Y-m", strtotime("+ ".$NumMonths." months", strtotime(date("Y-m")."-01")))."-01'
	ORDER BY EventName, Cancelled, AccredNum, CPD, StartDate";

	$queryresult = mysql_query($sql) or die(mysql_error()." ".$sql);
	
	if (mysql_num_rows($queryresult) > 0) {
?>
<tr><td colspan="<?php echo $NumMonths+2; ?>" align="center"><?php echo $catrow["WebCategoryName"]; ?></td></tr>
<?php
	$i=1;
	$sLastEvent = "";
	$iLastMonth = date("n")-1;
	$sThisRow = "";
	while ($row = mysql_fetch_array($queryresult)) {
		$eventid = $row["EventID"];
		$city = $row["City"];
		if (empty($city)) $city = $row["CourseVenueCity"];
		if (empty($city)) $city = $row["Venue"];
		$startdate = $row["StartDate"];
		$enddate = $row["EndDate"];
		$sday = date("d", strtotime($startdate));
		$syear = date("Y", strtotime($startdate));
		$smonth = date("m", strtotime($startdate));
		$eday = date("d", strtotime($enddate));
		$eyear = date("Y", strtotime($enddate));
		$emonth = date("m", strtotime($enddate));
		
		$sEventInfo = $row["EventName"];
		$sCPD=$row["CPD"];
		if ($row["Cancelled"] == 1) $sEventInfo .= " - CANCELLED";
		if (!empty($row["AccredNum"])) $sEventInfo .= " (".$row["AccredNum"].")";
		//$sEventInfo .= "<br>";
		//if (!empty($row["CPD"])) $sEventInfo .= $row["CPD"]." CPD point(s)";

		if ($sLastEvent != $sEventInfo) {
			if (!empty($sLastEvent)) {
				if ($iLastMonth > 0) $sThisRow .= "</td>";
				if ($iLastMonth > $lastmonthShown) {
					for ($z= $iLastMonth+1; $z <= 12; $z++) {
						$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
					}
					for ($z= 1; $z <= $lastmonthShown; $z++) {
						$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
					}
				} else {
					for ($z=$iLastMonth+1; $z <= $lastmonthShown; $z++) {
						$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
					}
				}
				$sThisRow .= "</tr>
";

				$sThisRow = str_replace("EVENTIDHERE", $lasteventid, $sThisRow);
				echo $sThisRow;

			}
			$sThisRow = "<tr><td width=280>";
			$sThisRow .= "<a href='/node/110?id=EVENTIDHERE'><span class='eventname'>";
			$sThisRow .= $sEventInfo;
			$sThisRow .= "</span><br>";
			$sThisRow .= "More&nbsp;Info</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			$sThisRow .= "</td><td>".$sCPD."</td>";
			$iLastMonth = date("n")-1;
			$sLastEvent = $sEventInfo;

			if (($i % 10) == 0) {
	?>
	<tr>
	<td class='locked'>&nbsp;</td><td class='locked'>&nbsp;</td>
	<?php
		$lastmonthShown = 0;
		for ($z = date("n"); $z <= (date("n")+($NumMonths-1)); $z++) {
			$usez = $z;
			if ($usez > 12) $usez = $usez-12;
			echo "<td align=center class='locked'><b>".date("M", strtotime(date("Y")."-".$usez."-01"))."</b></td>";
			$lastmonthShown = $usez;
		}
	?>
	</tr>
	<?php			
			}
	
			$i++;
		}
		if ($smonth != $iLastMonth) {
			// starting in a new month
			if ($iLastMonth > 0) echo "</td>";
			// fill in the months before this
			if ($iLastMonth > $smonth) {
				for ($z= $iLastMonth+1; $z <= 12; $z++) {
					$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
				}
				for ($z= 1; $z < $smonth; $z++) {
					$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
				}
			} else {
				for ($z=$iLastMonth+1; $z < $smonth; $z++) {
					$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
				}
			}
			
			if ($emonth > $smonth) {
				$sThisRow .= "<td nowrap colspan=".($emonth-$smonth)." align=center>";
			} else {
				$sThisRow .= "<td nowrap align=center>";
			}
		} else {
			$sThisRow .= "<hr>";
		}
		$sThisRow .= "<a href='/node/111?id=".$eventid."'>".$sday;
		if (strtotime($enddate) > strtotime($startdate)) {
			$sThisRow .= "-".$eday;
		}
		$sThisRow .= "<br><small>".$city."</small></a><br>";
		if ($row["Cancelled"] == 0) {
			$sThisRow .= "<a href='/node/112?id=".$eventid."'><u><i>Register&nbsp;Now</i></u></a>";
		} else {
			$sThisRow .= "Cancelled";
		}
		// $sThisRow .= "</td>"."\r\n";

		$iLastMonth = $smonth;
		if ($iLastMonth > 12) $iLastMonth = 1;
		$lasteventid = $eventid;
	}

	if (!empty($sLastEvent)) {
		if ($iLastMonth > 0) $sThisRow .= "</td>";
		for ($z=$iLastMonth+1; $z <= $lastmonthShown; $z++) {
			$sThisRow .= "<td><img src='/images/spacer.gif' width=30'></td>";
		}
		$sThisRow .= "</tr>
";

		$sThisRow = str_replace("EVENTIDHERE", $lasteventid, $sThisRow);
		echo $sThisRow;
		
	}
	
	}
}
?>
</tbody>
</table>