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"]);
	}
}

// Check if this is for PDF generation
$isPDF = isset($_REQUEST["pdf"]) && $_REQUEST["pdf"] == "1";
?>
<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;
			text-align: center;
		}

		.eventname {
			font-family: Verdana, Arial, sans-serif;
			font-size: 11px;
		}
	}
</style>
<?php if (!$isPDF): ?>
<table border=0 cellspacing=0 cellpadding="0" width="100%">
	<tr>
		<td width="50%" align="left">&nbsp;
			<!--<a href="https://www.cesa.co.za/public_downloads/FIDIC_INDUNA.pdf" target="_blank"><img 
				src="https://www.cesa.co.za/images/scroller/Induna_Course_Banner.jpg"></a>-->
			<form method="get" action="/scecalendar">
				<input type="hidden" name="test" value="1">
				<table border="0">
					<tr>
						<td valign="middle">
							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 categories</option>
								<?php
								$catrs = mysql_query("SELECT * FROM SchoolWebCategories WHERE DisplayOrder>0 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></td>
						<td valign="middle">&nbsp;&nbsp;<input type="submit" value="Update Calendar"></td>
					</tr>
				</table>
			</form>
		</td>
		<td width="50%" align="right">
			<a href="/php/calendarpdf.php?NumMonths=<?php echo $_REQUEST["NumMonths"]; ?>" target="_blank"><img
					src="/images/icon_pdf.gif" border="0" align="absmiddle" />&nbsp;<strong>Download as a PDF</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>
<?php endif; ?>
<table width=100% cellspacing=0 cellpadding=2 class="smallfonts" id="tbl">
	<thead>
		<tr>
			<th colspan=<?php echo $NumMonths + 2; ?> align=center class='locked' bgcolor="#325eab">
				<B style="color:white">Training Schedule, <?php echo date("M Y"); ?> -
					<?php echo date("M Y", strtotime("+ " . ($NumMonths - 1) . " months", strtotime(date("Y-m") . "-01"))); ?></b>
			</th>
		</tr>
		<tr>
			<th class='locked' bgcolor="#325eab" align=center><b style="color:white">Course</b></th>
			<th class='locked' bgcolor="#325eab" align=center><strong style="color:white">CPD</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' bgcolor='#325eab'><b style='color:white'>" . date("M", strtotime(date("Y") . "-" . $usez . "-01")) . "</b></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($conn) . " " . $sql);

			if (mysql_num_rows($queryresult) > 0) {
		?>
				<tr>
					<td colspan="<?php echo $NumMonths + 2; ?>" align="left" bgcolor="#6ba9d5" style="color:#325eab">
						<b><?php echo $catrow["WebCategoryName"]; ?></b>
					</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>&nbsp;</td>";
								}
								for ($z = 1; $z <= $lastmonthShown; $z++) {
									$sThisRow .= "<td>&nbsp;</td>";
								}
							} else {
								for ($z = $iLastMonth + 1; $z <= $lastmonthShown; $z++) {
									$sThisRow .= "<td>&nbsp;</td>";
								}
							}
							$sThisRow .= "</tr>
";

							$sThisRow = str_replace("EVENTIDHERE", $lasteventid, $sThisRow);
							echo $sThisRow;
						}
						$sThisRow = "<tr><td width=280>";
						if (!$isPDF) {
							$sThisRow .= "<a href='/sce/school-course?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;";
						} else {
							$sThisRow .= "<span class='eventname'>";
							$sThisRow .= $sEventInfo;
							$sThisRow .= "</span>";
						}
						$sThisRow .= "</td><td align=center>" . $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>&nbsp;</td>";
							}
							for ($z = 1; $z < $smonth; $z++) {
								$sThisRow .= "<td>&nbsp;</td>";
							}
						} else {
							for ($z = $iLastMonth + 1; $z < $smonth; $z++) {
								$sThisRow .= "<td>&nbsp;</td>";
							}
						}

						if ($emonth > $smonth) {
							$sThisRow .= "<td nowrap colspan=" . ($emonth - $smonth) . " align=center>";
						} else {
							$sThisRow .= "<td nowrap align=center>";
						}
					} else {
						$sThisRow .= "<hr>";
					}
					
					if (!$isPDF) {
						$sThisRow .= "<a href='/sce/school-event?id=" . $eventid . "'>" . $sday;
						if (strtotime($enddate) > strtotime($startdate)) {
							$sThisRow .= "-" . $eday;
						}
						$sThisRow .= " " . date("M", strtotime(date("Y") . "-" . $smonth . "-01"));
						$sThisRow .= "<br><small>" . $city . "</small></a><br>";
						if ($row["Cancelled"] == 0) {
							$sThisRow .= "<a href='/sce/school-event-registration?id=" . $eventid . "'><u><i>Register&nbsp;Now</i></u></a>";
						} else {
							$sThisRow .= "Cancelled";
						}
					} else {
						$sThisRow .= $sday;
						if (strtotime($enddate) > strtotime($startdate)) {
							$sThisRow .= "-" . $eday;
						}
						$sThisRow .= " " . date("M", strtotime(date("Y") . "-" . $smonth . "-01"));
						$sThisRow .= "<br><small>" . $city . "</small><br>";
						if ($row["Cancelled"] == 0) {
							$sThisRow .= "<i>Register&nbsp;Now</i>";
						} 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>&nbsp;</td>";
					}
					$sThisRow .= "</tr>
";

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