| Current Path : /var/www/cesa.co.za/php/ |
| Current File : /var/www/cesa.co.za/php/relayteams.php |
<?php
die();
error_reporting(E_NONE);
ini_set("display_errors", 0);
require("class.phpmailer.php");
$sendto = "julia@xe.co.za";
$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 ((double)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 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"]);
$cid = intval($_REQUEST["cid"]);
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>·</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"]==2)) {
$bFormErrors = false;
if (!$bFormErrors) {
$bShowForm=false;
?>
<p><b>Thank you for registering your team members.</b></p>
<?php
$sql="SELECT * FROM RelayEvents WHERE RelayEvents.EventID=".$id." ORDER BY DisplayOrder";
$recRE=mysql_query($sql);
while ($rowRE=mysql_fetch_assoc($recRE)) {
mysql_query("DELETE FROM RelayTeams WHERE RelayCompanyID=".$cid." AND RelayEventID=".$rowRE["RelayEventID"]);
for ($j=0; $j<$rowRE["NumParticipants"]*5; $j++) {
if (!empty($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_ParticipantName"]) || !empty($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_IDNumber"])) {
$sql="INSERT INTO RelayTeams (EventID, RelayCompanyID, RelayEventID, ParticipantName, IDNumber, Gender, Age, Indemnity, DateCreated) VALUES (".$id.", ".$cid.", ".$rowRE["RelayEventID"].", '".addslashes($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_ParticipantName"])."', '".addslashes($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_IDNumber"])."', '".addslashes($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_Gender"])."', '".addslashes($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_Age"])."', '".addslashes($_POST["RE_".$rowRE["RelayEventID"]."_".$j."_Indemnity"])."', '".date("Y-m-d H:i:s")."')";
mysql_query($sql);
}
}
}
}
}
if ($bShowForm) {
?>
<h1 align="center"><?php echo $row["EventName"]; ?></h1>
<h2>Team Member Registration</h2>
<?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>";
}
$sql="SELECT * FROM RelayCompanies WHERE RelayCompanyID=".$cid;
$recC=mysql_query($sql);
if ($rowC=mysql_fetch_assoc($recC)) {
?>
<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 $rowC["CompanyName"]; ?></td>
</tr>
<tr>
<td valign=top bgcolor="#EFEFEF"><p>Branch:</p></td>
<td width="72%" valign=top><?php echo $rowC["Branch"]; ?></td>
</tr>
</table>
<p><b>TEAM ENTRIES</b></p>
<?php
if (!isset($_REQUEST["ProcessForm"])) {
?>
<form name="form1" method="post" action="/node/626">
<input type="hidden" name="ProcessForm" value="1">
<input type="hidden" name="id" value="<? echo $id; ?>">
<input type="hidden" name="cid" value="<? echo $cid; ?>">
<p><b>Please confirm your team numbers:</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></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
$sql="SELECT NumTeams FROM RelayCompanyEvents WHERE RelayCompanyID=".$cid." AND RelayEventID=".$rowRE["RelayEventID"];
$recNT=mysql_query($sql);
if ($rowNT=mysql_fetch_assoc($recNT)) echo $rowNT["NumTeams"];
?>"></td></tr>
<?php
}
?>
</table>
<div align="center">
<p>
<input type="submit" name="Submit" value="Continue" style="background-color:red;color:white;font-style:bold;width:150px;height:50px">
</p>
<p> </p>
</div>
</form>
<?php
} else {
?>
<form name="form1" method="post" action="/node/626">
<input type="hidden" name="ProcessForm" value="2">
<input type="hidden" name="id" value="<? echo $id; ?>">
<input type="hidden" name="cid" value="<? echo $cid; ?>">
<p><b>Indemnity: </b><br>The participant acknowledges that the activity in which he/she participates by its very nature carries inherent risks which could cause him/her to sustain bodily injury and/or suffer damages, and waives any claim so arising against the organisers or its members or employees.<br>
The participant makes use of the event facilities at entirely his/her own risk and agrees that the organisers will not be held liable and/or responsible for any loss, injury, damages, death, and/or compensation of whatsoever nature and howsoever arising as a result thereof, irrespective of whether negligence or gross negligence exists on the part of the organisers or any member or employee, and the participant does hereby waive any claim it may have against the organiser as a result thereof.<br>
The Participant hereby warrants that he/she is medically fit so as to participate in activities of this nature, it not being the responsibility of the Organiser to have the Participant undergo any medical examination, the onus being on the Participant to do so. The Organiser shall not be obliged to call upon the Participant to provide a medical certificate. The Organiser, its members or employees, shall not be liable for any claim or injury or loss or damages arising from or in connection with the agreement.<br>
Persons accepting this indemnity as the parent and/or guardian of a minor hereby agree to such minor being bound by the aforegoing waiver and indemnity. I/We , the undersigned, have read and fully understood the above indemnity. </p>
<?php
$sql="SELECT RelayEvents.* FROM RelayEvents WHERE RelayEvents.EventID=".$id." ORDER BY DisplayOrder";
$recRE=mysql_query($sql);
while ($rowRE=mysql_fetch_assoc($recRE)) {
$k=0;
//$iNumTeams=$rowRE["MaxTeams"];
//if (empty($iNumTeams)) $iNumTeams=5;
$iNumTeams=intval($_REQUEST["RE_".$rowRE["RelayEventID"]]);
mysql_query("DELETE FROM RelayCompanyEvents WHERE EventID=".$id." AND RelayCompanyID=".$cid." AND RelayEventID=".$rowRE["RelayEventID"]);
mysql_query("INSERT INTO RelayCompanyEvents (EventID, RelayCompanyID, RelayEventID, NumTeams) VALUES (".$id.", ".$cid.", ".$rowRE["RelayEventID"].", ".$iNumTeams.")");
for ($i=0; $i<$iNumTeams; $i++) {
$sql="SELECT * FROM RelayTeams WHERE RelayCompanyID=".$cid." AND RelayEventID=".$rowRE["RelayEventID"]." ORDER BY RelayTeamID";
$recRT=mysql_query($sql);
?>
<p><b><?php echo $rowRE["EventName"]; ?>: TEAM NO <?php echo $i+1; ?></b></p>
<table width=760 border=1 cellpadding=2 cellspacing=0>
<tr><td bgcolor="#EFEFEF"><b>Running Order</b></td>
<td bgcolor="#EFEFEF"><b>Participant Name</b></td>
<td bgcolor="#EFEFEF"><b>ID Number</b></td>
<td bgcolor="#EFEFEF"><b>Gender</b></td>
<td bgcolor="#EFEFEF"><b>Age</b></td>
<td bgcolor="#EFEFEF"><b>Indemnity</b></td>
</tr>
<?php
for ($j=0; $j<$rowRE["NumParticipants"]; $j++) {
$RT_ParticipantName="";
$RT_IDNumber="";
$RT_Gender="";
$RT_Age="";
$RT_Indemnity="";
if ($rowRT=mysql_fetch_assoc($recRT)) extract($rowRT, EXTR_PREFIX_ALL, "RT");
?>
<tr>
<td><?php echo $j+1; ?></td>
<td><input type="text" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>ParticipantName" value="<?php echo $RT_ParticipantName; ?>"></td>
<td><input type="text" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>IDNumber" value="<?php echo $RT_IDNumber; ?>"></td>
<td><input type="radio" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>Gender" value="M"<?php if ($RT_Gender=="M") echo " checked"; ?>> M<br>
<input type="radio" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>Gender" value="F"<?php if ($RT_Gender=="F") echo " checked"; ?>> F</td>
<td><input type="text" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>Age" size="4" value="<?php echo $RT_Age; ?>"></td>
<td><input type="checkbox" name="<?php echo "RE_".$rowRE["RelayEventID"]."_".$k."_"; ?>Indemnity" value="1"<?php if ($RT_Indemnity==1) echo " checked"; ?>> Accepted</td>
</tr>
<?php
$k++;
}
?>
</table>
<?php
}
}
?>
<div align="center">
<p>
<input type="submit" name="Submit" value="Save and Submit" style="background-color:red;color:white;font-style:bold;width:150px;height:50px">
</p>
<p> </p>
</div>
</form>
<?php
}
}
}
}
} else {
echo "Event not found.";
}
?>
</table>