Your IP : 216.73.217.79


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

<?php
die();

error_reporting(E_NONE);
ini_set("display_errors", 0);

require("class.phpmailer.php");

$sendto = "nerave.moodley@mottmac.com";

$sendfrom = "marketing@cesa.co.za";

function GenPassword()
{
	// Password generation 
	$length = 8; // Must be a multiple of 2
	$conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
	$vocal = array("a", "e", "i", "o", "u");
	$password = "";
	srand((float)microtime() * 1000000);
	$max = $length / 2;
	for ($i = 1; $i <= $max; $i++) {
		$password .= $conso[rand(0, 19)];
		$password .= $vocal[rand(0, 4)];
	}

	return $password;
}

function CaseCorrect($str)
{
	$newstr = ucwords(strtolower($str));
	return $newstr;
}
function XMail($to, $subject, $msg, $from, $CC, $type, $sendBCC = true)
{
	global $id, $sendto;

	$mail = new PHPMailer();
	$mail->Mailer   = "mail";
	if ($type == "html") $mail->IsHTML(true);

	$mail->From     = $from;
	$mail->FromName     = $from;
	$arrto = explode(",", $to);
	for ($i = 0; $i < count($arrto); $i++) {
		if (!empty($arrto[$i])) $mail->AddAddress($arrto[$i]);
	}
	//if ($sendBCC) $mail->AddBCC($sendto);
	$mail->Subject = $subject;
	$mail->Body = $msg;

	if (!$mail->Send()) echo $mail->ErrorInfo;
}

?>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<SCRIPT LANGUAGE="JavaScript">
	function IsEmpty(aTextField) {
		if ((aTextField.value.length == 0) || (aTextField.value == null)) {
			return true;
		} else {
			return false;
		}
	}

	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 7;

	function isInteger(s) {
		var i;
		for (i = 0; i < s.length; i++) {
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}

	function stripCharsInBag(s, bag) {
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++) {
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	function checkInternationalPhone(strPhone) {
		s = stripCharsInBag(strPhone, validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}

	function ValidateForm() {
		var Phone = document.frmSample.txtPhone

		if ((Phone.value == null) || (Phone.value == "")) {
			alert("Please Enter your Phone Number")
			Phone.focus()
			return false
		}
		if (checkInternationalPhone(Phone.value) == false) {
			alert("Please Enter a Valid Phone Number")
			Phone.value = ""
			Phone.focus()
			return false
		}
		return true
	}

	function formCheck(objForm) {
		bOK = true;

		if (IsEmpty(objForm.CompanyName)) {
			bOK = false;
			alert('Please fill in your company name.');
		} else if (IsEmpty(objForm.ContactPerson1)) {
			bOK = false;
			alert('Please fill in a contact person.');
		} else if (IsEmpty(objForm.EmailAddress1)) {
			bOK = false;
			alert('Please fill in the email address.');
		}
		return bOK;
	}
</script>
<?php
//$id = intval($_REQUEST["id"]);

include('inc_db.php');
$db = mysql_connect($loghost, $logid, $logpwd);

mysql_select_db($dbname, $db);

$sql = "SELECT * FROM MarketingEvents WHERE EventID=" . $id;

$queryresult = mysql_query($sql) or die(mysql_error());

if ($row = mysql_fetch_array($queryresult)) {

	// check the dates
	$StartDatePlusTime = date("Y-m-d", strtotime($row["StartDate"])) . " " . date("H:i", strtotime($row["StartTime"]));
	$ScheduleDates .= "<b>&middot;</b>" . date("D j F Y", strtotime($row["StartDate"])) . " at " . $row["StartTime"] . "<BR><br>";
	if (strtotime($StartDatePlusTime) < time()) $bEventInPast = true;

	if ($bEventInPast || ($row["Cancelled"] == 1)) {
		//if (1==1) {
		// No space left
		echo "<b><center>Registrations have now closed for this event.</center></b>";
	} else {

		$bShowForm = true;
		if (isset($_POST["ProcessForm"]) && ($_POST["ProcessForm"] == 1)) {

			$EventID = $_POST["EventID"];
			$bFormErrors = false;
			if (!reCaptcha($_POST["g-recaptcha-response"])) {
				$bFormErrors = true;
				$sError[] = "You could not be verified as not being a robot, please tick the reCaptcha verification option at the bottom of the form.";
			} else {

				if (empty($_POST["CompanyName"])) {
					$bFormErrors = true;
					$sError[] = "Your company name is required.";
				}
				if (empty($ContactPerson1)) {
					$bFormErrors = true;
					$sError[] = "A contact person is required.";
				}
				if (empty($ContactPerson1)) {
					$bFormErrors = true;
					$sError[] = "An email address is required.";
				}
			}

			if (!$bFormErrors) {
				$bShowForm = false;
				$iTotalCost = 0;
?>
				<p><b>Please confirm your details below and submit your registration.</b></p>
				<form name="form1" method="post" action="/node/625" id="submitform">
					<input type="hidden" name="ProcessForm" value="2" id="ProcessForm">
					<input type="hidden" name="EventID" value="<? echo $id; ?>">
					<input type="hidden" name="id" value="<? echo $id; ?>">
					<input type="hidden" name="CompanyName" value="<?php echo addslashes($_POST["CompanyName"]); ?>">
					<input type="hidden" name="Branch" value="<?php echo addslashes($_POST["Branch"]); ?>">
					<input type="hidden" name="Address" value="<?php echo addslashes($_POST["Address"]); ?>">
					<input type="hidden" name="TelephoneNumber" value="<?php echo addslashes($_POST["TelephoneNumber"]); ?>">
					<input type="hidden" name="VATNumber" value="<?php echo addslashes($_POST["VATNumber"]); ?>">
					<input type="hidden" name="ContactPerson1" value="<?php echo addslashes($_POST["ContactPerson1"]); ?>">
					<input type="hidden" name="EmailAddress1" value="<?php echo addslashes($_POST["EmailAddress1"]); ?>">
					<input type="hidden" name="ContactPerson2" value="<?php echo addslashes($_POST["ContactPerson2"]); ?>">
					<input type="hidden" name="EmailAddress2" value="<?php echo addslashes($_POST["EmailAddress2"]); ?>">

					<table width=760 border=1 cellpadding=2 cellspacing=0>
						<tr>
							<td width="28%" valign=top bgcolor="#EFEFEF">
								<p><strong>Company Name:</strong></p>
							</td>
							<td width="72%" valign=top><?php echo stripslashes($_POST["CompanyName"] . ""); ?></td>
						</tr>
					</table>
					<p><b>ENTRY SUMMARY</b></p>
					<table width=760 border=1 cellpadding=2 cellspacing=0>
						<tr>
							<td bgcolor="#EFEFEF"><b>Event</b></td>
							<td bgcolor="#EFEFEF"><b>Num Participants</b></td>
							<td bgcolor="#EFEFEF"><b>Cost Per Team</b></td>
							<td bgcolor="#EFEFEF"><b>Num Teams Entered</b></td>
							<td bgcolor="#EFEFEF"><b>Total Cost</b></td>
						</tr>
						<?php
						$sql = "SELECT * FROM RelayEvents WHERE EventID=" . $id . " ORDER BY DisplayOrder";
						$recRE = mysql_query($sql);
						while ($rowRE = mysql_fetch_assoc($recRE)) {
							if (!empty($_POST["RE_" . $rowRE["RelayEventID"]]))
						?>
							<tr>
								<td><?php echo $rowRE["EventName"]; ?></td>
								<td><?php echo $rowRE["NumParticipants"]; ?><?php if (!empty($rowRE["MaxTeams"])) echo " (max " . $rowRE["MaxTeams"] . " teams)"; ?></td>
								<td>R<?php echo $rowRE["Cost"]; ?></td>
								<td><?php echo $_POST["RE_" . $rowRE["RelayEventID"]]; ?>
									<input type="hidden" name="RE_<?php echo $rowRE["RelayEventID"]; ?>" value="<?php echo $_POST["RE_" . $rowRE["RelayEventID"]]; ?>">
								</td>
								<td><b>R<?php $iCost = intval($_POST["RE_" . $rowRE["RelayEventID"]]) * $rowRE["Cost"];
										$iTotalCost += $iCost;
										echo $iCost; ?></b></td>
							</tr>
						<?php

						}
						?>
					</table>
					<p><b>EQUIPMENT HIRE</b></p>
					<table width=760 border=1 cellpadding=2 cellspacing=0>
						<tr>
							<td bgcolor="#EFEFEF"><b>Description</b></td>
							<td bgcolor="#EFEFEF"><b>Cost Each</b></td>
							<td bgcolor="#EFEFEF"><b>Number Required</b></td>
							<td bgcolor="#EFEFEF"><b>Total Cost</b></td>
						</tr>
						<?php
						$sql = "SELECT * FROM RelayOther WHERE EventID=" . $id . " ORDER BY DisplayOrder";
						$recRE = mysql_query($sql);
						while ($rowRE = mysql_fetch_assoc($recRE)) {
							if (!empty($_POST["RO_" . $rowRE["RelayOtherID"]]))
						?>
							<tr>
								<td><?php echo $rowRE["OtherName"]; ?></td>
								<td>R<?php echo $rowRE["Cost"]; ?></td>
								<td><?php echo $_POST["RO_" . $rowRE["RelayOtherID"]]; ?><input type="hidden" name="RO_<?php echo $rowRE["RelayOtherID"]; ?>" size="4" value="<?php echo $_POST["RO_" . $rowRE["RelayOtherID"]]; ?>"></td>
								<td><b>R<?php $iCost = intval($_POST["RO_" . $rowRE["RelayOtherID"]]) * $rowRE["Cost"];
										$iTotalCost += $iCost;
										echo $iCost; ?></b></td>
							</tr>
						<?php

						}
						?>
					</table>
					<table width=760 border=1 cellpadding=2 cellspacing=0>
						<tr>
							<td colspan="2" align=right>
								<p><b>TOTAL COST: R <?php echo $iTotalCost; ?></b></p>
							</td>
						</tr>
						<tr>
							<td><input type="button" name="Cancel" value="Go Back and Make Changes" style="background-color:gray;color:white;font-style:bold;width:250px;height:50px" onclick="document.getElementById('ProcessForm').value=''; document.getElementById('submitform').submit();"></td>
							<td>
								<input type="submit" name="Submit" value="Confirm and Register" style="background-color:red;color:white;font-style:bold;width:150px;height:50px">
							</td>
						</tr>
					</table>
				</form>
			<?php
			}
		}
		if (isset($_POST["ProcessForm"]) && ($_POST["ProcessForm"] == 2)) {
			$bShowForm = false;
			$iTotalCost = 0;

			$EventID = $_POST["EventID"];
			// Save all the form fields
			foreach ($_POST as $FieldName => $FieldValue) {
				$sql = "INSERT INTO EventFormFields (EventID, FirstName, LastName, FieldName, FieldValue, DateCreated) VALUES ('" . $EventID . "', '" . $FirstName . "', '" . $Surname . "', '" . $FieldName . "', '" . $FieldValue . "', '" . date("Y-m-d H:i") . "')";
				$queryresult = mysql_query($sql);
			}

			$msg = "<table border=1>";

			$sql = "INSERT INTO RelayCompanies (EventID, CompanyName, Branch, Address, TelephoneNumber, VATNumber, ContactPerson1, EmailAddress1, ContactPerson2, EmailAddress2, DateCreated) VALUES (" . $EventID . ", '" . addslashes($_POST["CompanyName"]) . "', '" . addslashes($_POST["Branch"]) . "', '" . addslashes($_POST["Address"]) . "', '" . addslashes($_POST["TelephoneNumber"]) . "',  '" . addslashes($_POST["VATNumber"]) . "', '" . addslashes($_POST["ContactPerson1"]) . "', '" . addslashes($_POST["EmailAddress1"]) . "', '" . addslashes($_POST["ContactPerson2"]) . "', '" . addslashes($_POST["EmailAddress2"]) . "', '" . date("Y-m-d H:i:s") . "')";
			mysql_query($sql);
			$CompanyID = mysql_insert_id();
			$msg .= "<tr><td><b>Company Name:</b></td><td>" . $_POST["CompanyName"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Branch:</b></td><td>" . $_POST["Branch"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Address:</b></td><td>" . $_POST["Address"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Telephone Number:</b></td><td>" . $_POST["TelephoneNumber"] . "</td></tr>
			";
			$msg .= "<tr><td><b>VAT Number:</b></td><td>" . $_POST["VATNumber"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Contact Person 1:</b></td><td>" . $_POST["ContactPerson1"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Email Address 1:</b></td><td>" . $_POST["EmailAddress1"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Contact Person 2:</b></td><td>" . $_POST["ContactPerson2"] . "</td></tr>
			";
			$msg .= "<tr><td><b>Email Address 2:</b></td><td>" . $_POST["EmailAddress2"] . "</td></tr></table>
			";
			$msg .= "<p>EVENTS</p>
			<table border=1>";
			$sql = "SELECT * FROM RelayEvents WHERE EventID=" . $EventID . " ORDER BY DisplayOrder";
			$recRE = mysql_query($sql);
			while ($rowRE = mysql_fetch_assoc($recRE)) {
				if (!empty($_POST["RE_" . $rowRE["RelayEventID"]])) {
					$sql = "INSERT INTO RelayCompanyEvents (EventID, RelayCompanyID, RelayEventID, NumTeams) VALUES (" . $EventID . ", " . $CompanyID . ", " . $rowRE["RelayEventID"] . ", " . $_POST["RE_" . $rowRE["RelayEventID"]] . ")";
					mysql_query($sql);
					$msg .= "<tr><td><b>" . $rowRE["EventName"] . "</b></td><td>" . $_POST["RE_" . $rowRE["RelayEventID"]] . " teams</td></tr>
					 ";
					$iCost = intval($_POST["RE_" . $rowRE["RelayEventID"]]) * $rowRE["Cost"];
					$iTotalCost += $iCost;
				}
			}
			$msg .= "</table><p>EQUIPMENT</p>
			<table border=1>";
			$sql = "SELECT * FROM RelayOther WHERE EventID=" . $EventID . " ORDER BY DisplayOrder";
			$recRE = mysql_query($sql);
			while ($rowRE = mysql_fetch_assoc($recRE)) {
				if (!empty($_POST["RO_" . $rowRE["RelayOtherID"]])) {
					$sql = "INSERT INTO RelayCompanyOther (EventID, RelayCompanyID, RelayOtherID, NumRequired) VALUES (" . $EventID . ", " . $CompanyID . ", " . $rowRE["RelayOtherID"] . ", " . $_POST["RO_" . $rowRE["RelayOtherID"]] . ")";
					mysql_query($sql);
					$msg .= "<tr><td><b>" . $rowRE["OtherName"] . "</b></td><td>" . $_POST["RO_" . $rowRE["RelayOtherID"]] . " ordered</td></tr>
					 ";
					$iCost = intval($_POST["RO_" . $rowRE["RelayOtherID"]]) * $rowRE["Cost"];
					$iTotalCost += $iCost;
				}
			}
			$msg .= "</table>";
			$msg .= "<p align=center><b>TOTAL COST: R " . $iTotalCost . "</b></p>";
			XMail($_POST["EmailAddress1"] . "," . $_POST["EmailAddress2"], "CESA KZN Relay Registration", "<p><b>Thank you for your registration.</b></p><p>To register your teams members, please proceed to: <a href='https://www.cesa.co.za/regteam?id=" . $EventID . "&cid=" . $CompanyID . "'>https://www.cesa.co.za/regteam?id=" . $EventID . "&cid=" . $CompanyID . "</a></p>" . $msg, $sendfrom, "", "html");
			XMail($sendto, "CESA KZN Relay Registration", "<p><b>The following registration has been received:</b></p>" . $msg, $sendfrom, "", "html");
			?>
			<p><b>Thank you for your registration!</b></p>
			<p>You can continue to register your team members now, or come back later to do so.</p>
			<p><a href="/node/626?id=<?php echo $EventID; ?>&cid=<?php echo $CompanyID; ?>"><b>Register my teams now</b></a></p>
			<p>To register teams at a later date, please save the following URL to return to:<br><b><a href="/node/626?id=<?php echo $EventID; ?>&cid=<?php echo $CompanyID; ?>">https://www.cesa.co.za/regteam?id=<?php echo $EventID; ?>&cid=<?php echo $CompanyID; ?></a></b><br>This URL has also been emailed to the contact person's email provided in your registration.</p>
		<?php

		}

		if ($bShowForm) {
		?>
			<h1 align="center"><?php echo $row["EventName"]; ?></h1><br>
			<?php
			if ($bFormErrors) {
				echo "<p><font color=red><b>The following errors occurred:</b></font><br>" . join("<br>", $sError) . "<br><b>Please correct the errors and submit again. Thank you!</b></p>";
			}

			if (!empty($row["ExternalLink"])) echo "<p align=center><b style='font-size:14px'><a href='" . $row["ExternalLink"] . "' target='_blank'>Click here for more information about this event</a></b></p>";
			?>
			<p align=center style='text-align:center'><b>Please fill in the form below to register for this event.</b></p>
			<form name="form1" method="post" action="/node/625" onSubmit="return formCheck(this)">
				<input type="hidden" name="ProcessForm" value="1">
				<input type="hidden" name="EventID" value="<? echo $id; ?>">
				<input type="hidden" name="id" value="<? echo $id; ?>">
				<table width=760 border=1 cellpadding=2 cellspacing=0>
					<tr>
						<td width="28%" valign=top bgcolor="#EFEFEF">
							<p><strong>Company Name:</strong></p>
						</td>
						<td width="72%" valign=top><input name="CompanyName" id="CompanyName" type="text" size="45" value="<?php echo stripslashes($_POST["CompanyName"] . ""); ?>"></td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Branch:</p>
						</td>
						<td valign=top><input name="Branch" type="text" size="45" value="<?php echo stripslashes($_POST["Branch"] . ""); ?>"></td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Address:</p>
						</td>
						<td valign=top><textarea name="Address"><?php echo stripslashes($_POST["Address"] . ""); ?></textarea> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Telephone Number:</p>
						</td>
						<td valign=top><input name="TelephoneNumber" type="text" size="45" value="<?php echo stripslashes($_POST["TelephoneNumber"] . ""); ?>"> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>VAT Number:</p>
						</td>
						<td valign=top><input name="VATNumber" type="text" size="45" value="<?php echo stripslashes($_POST["VATNumber"] . ""); ?>"> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Contact Person 1:</p>
						</td>
						<td valign=top><input name="ContactPerson1" type="text" size="45" value="<?php echo stripslashes($_POST["ContactPerson1"] . ""); ?>"> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Email Address 1:</p>
						</td>
						<td valign=top><input name="EmailAddress1" type="text" size="45" value="<?php echo stripslashes($_POST["EmailAddress1"] . ""); ?>"> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Contact Person 2:</p>
						</td>
						<td valign=top><input name="ContactPerson2" type="text" size="45" value="<?php echo stripslashes($_POST["ContactPerson2"] . ""); ?>"> </td>
					</tr>
					<tr>
						<td valign=top bgcolor="#EFEFEF">
							<p>Email Address 2:</p>
						</td>
						<td valign=top><input name="EmailAddress2" type="text" size="45" value="<?php echo stripslashes($_POST["EmailAddress2"] . ""); ?>"> </td>
					</tr>
				</table>
				<p><b>ENTRY SUMMARY</b></p>
				<p>Please fill in the number of teams you would like to enter in each category below.</p>
				<table width=760 border=1 cellpadding=2 cellspacing=0>
					<tr>
						<td bgcolor="#EFEFEF"><b>Event</b></td>
						<td bgcolor="#EFEFEF"><b>Num Participants</b></td>
						<td bgcolor="#EFEFEF"><b>Cost Per Team</b></td>
						<td bgcolor="#EFEFEF"><b>Num Teams Entered</b></td>
					</tr>
					<?php
					$sql = "SELECT * FROM RelayEvents WHERE EventID=" . $id . " ORDER BY DisplayOrder";
					$recRE = mysql_query($sql);
					while ($rowRE = mysql_fetch_assoc($recRE)) {
					?>
						<tr>
							<td><?php echo $rowRE["EventName"]; ?></td>
							<td><?php echo $rowRE["NumParticipants"]; ?><?php if (!empty($rowRE["MaxTeams"])) echo " (max " . $rowRE["MaxTeams"] . " teams)"; ?></td>
							<td>R<?php echo $rowRE["Cost"]; ?></td>
							<td><input type="text" name="RE_<?php echo $rowRE["RelayEventID"]; ?>" max="<?php echo $rowRE["MaxTeams"]; ?>" size="4" value="<?php echo $_POST["RE_" . $rowRE["RelayEventID"]]; ?>"></td>
						</tr>
					<?php

					}
					?>
				</table>
				<p><b>EQUIPMENT HIRE</b></p>
				<table width=760 border=1 cellpadding=2 cellspacing=0>
					<tr>
						<td bgcolor="#EFEFEF"><b>Description</b></td>
						<td bgcolor="#EFEFEF"><b>Cost Each</b></td>
						<td bgcolor="#EFEFEF"><b>Number Required</b></td>
					</tr>
					<?php
					$sql = "SELECT * FROM RelayOther WHERE EventID=" . $id . " ORDER BY DisplayOrder";
					$recRE = mysql_query($sql);
					while ($rowRE = mysql_fetch_assoc($recRE)) {
					?>
						<tr>
							<td><?php echo $rowRE["OtherName"]; ?></td>
							<td>R<?php echo $rowRE["Cost"]; ?></td>
							<td><input type="text" name="RO_<?php echo $rowRE["RelayOtherID"]; ?>" size="4" value="<?php echo $_POST["RO_" . $rowRE["RelayOtherID"]]; ?>"></td>
						</tr>
					<?php

					}
					?>
				</table>

				<div align="center">
					<div class="g-recaptcha" data-sitekey="6LcoIWUrAAAAAKBLHpjS7GyroBey9G6yhilbpyNa"></div>
					<p>
						<input type="submit" name="Submit" value="Continue" style="background-color:red;color:white;font-style:bold;width:150px;height:50px">
					</p>

					<p>&nbsp; </p>
				</div>
			</form>
<?php
		}
	}
} else {
	echo "Event not found.";
}
?>
</table>