<?php
	
	include('initialize.php');
	include('MemberManager.php');
	
	$memberManager = new MemberManager($databaseConnection);
	
	$ERROR_STRING = "";
	$ERROR_CODE = 0;
	$SUBMITTED = 0;
	
	$year = $websiteInfo['currentSeason'];
	$allowSignups = $websiteInfo['allowSignups'];
	
	if (@$_REQUEST['submitted'] == "true")
	{
		$childFirstName = @$_REQUEST['childFirstName'];
		$childLastName = @$_REQUEST['childLastName'];
		$parentFirstName = @$_REQUEST['parentFirstName'];
		$parentLastName = @$_REQUEST['parentLastName'];
		$street = @$_REQUEST['street'];
		$city = @$_REQUEST['city'];
		$state = @$_REQUEST['state'];
		$zipcode = @$_REQUEST['zipcode'];
		$phoneNumber = @$_REQUEST['phoneNumber'];
		$email = @$_REQUEST['email'];
		$school = @$_REQUEST['school'];
		$grade = @$_REQUEST['grade'];
		$chaperone = @$_REQUEST['chaperone'];
		
		if ($childFirstName == null) { $ERROR_STRING = "You need to supply a child's first name"; $ERROR_CODE = 1; }
		else if ($childLastName == null) { $ERROR_STRING = "You need to supply a child's last name"; $ERROR_CODE = 2; }
		else if ($parentFirstName == null) { $ERROR_STRING = "You need to supply a parent's first name"; $ERROR_CODE = 3; }
		else if ($parentLastName == null) { $ERROR_STRING = "You need to supply a parent's last name"; $ERROR_CODE = 4; }
		else if ($street == null) { $ERROR_STRING = "You need to supply an street"; $ERROR_CODE = 5; }
		else if ($city == null) { $ERROR_STRING = "You need to supply an city"; $ERROR_CODE = 6; }
		else if ($state == null) { $ERROR_STRING = "You need to supply an state"; $ERROR_CODE = 7; }
		else if ($zipcode == null) { $ERROR_STRING = "You need to supply an zipcode"; $ERROR_CODE = 8; }
		else if ($phoneNumber == null) { $ERROR_STRING = "You need to supply a phone number"; $ERROR_CODE = 9; }
		else if ($email == null)  { $ERROR_STRING = "You need to supply an email address"; $ERROR_CODE = 10;}
		
		if($chaperone != null)
			$chaperone= 1;
		else
		 	$chaperone = 0;
		 	
		if ($ERROR_CODE == 0)
		{
			$result = $memberManager->createMember($childFirstName, $childLastName, $parentFirstName, $parentLastName, $street, $city, $state, $zipcode, $phoneNumber, $email, $school, $grade, $chaperone, $year);
			$result = 1;
			if (! $result)
			{
				$ERROR_CODE = 11;
				$ERROR_STRING = "Unable to add $childFirstName $childLastName as a member to the Sandown Ski Club database for season $year";
			}
			else
			{
				$SUBMITTED = 1;
			}
			
		}
	}
?>


<?php include('header.php'); ?>

<?php include('leftSide.php') ?>
				
				
					<td valign="top" width="60%">

						<table border="0" cellspacing="5" cellpadding="5" width="100%">
							<tr>
								<td><font class="contentTitleText">Ski Club Sign Up</font></td>
							</tr>

							<tr>
								<td align="center" bgcolor="#FFFFFF">
								
									<?php 
									
										if ($allowSignups != "yes" && $allowSignups != "true")
										{
											print "<b><font class='regularText' style='color:red'>Sorry - Signups for the $year season are closed!</font></b><br><br>";
										}				
										else
										{ ?>
										

										<?php
											if($ERROR_CODE != 0)
												print "<b><font class='regularText' style='color:red'>Error - $ERROR_STRING</font></b><br><br>";
										?>


										<!-- colored border table -->
										<table bgcolor="#B5C2E4" border="0" cellspacing="0" cellpadding="0" width="90%">
											<tr>
												<td>


										<?php 
											if ($SUBMITTED == 0) {
										?>

												<form action="signUp.php" method="post">

														<!-- Step 1 Table -->
														<table cellspacing="1" cellpadding="4" border="0" width="100%">
															<tr bgcolor="#E9E9F3">
																<td>
																	<font class="regularText" style="font-weight:bold">Please fill out the information below</font>
																</td>
															</tr>
															<tr bgcolor="#FFFFFF">
																<td align="center">

																	<table boder="0" cellspacing="0" cellpadding="2" width="90%">
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 1) print "style='color:red'"; ?>>Child First Name:</td><td><input type="text" name="childFirstName" value="<?php print @$childFirstName; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 2) print "style='color:red'"; ?>>Child Last Name:</td><td><input type="text" name="childLastName" value="<?php print @$childLastName; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 3) print "style='color:red'"; ?>>Parent First Name:</td><td><input type="text" name="parentFirstName" value="<?php print @$parentFirstName; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 4) print "style='color:red'"; ?>>Parent Last Name:</td><td><input type="text" name="parentLastName" value="<?php print @$parentLastName; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 5) print "style='color:red'"; ?>>Street:</td><td><input type="text" name="street" value="<?php print @$street; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 6) print "style='color:red'"; ?>>City:</td>
																			<td>																			
																				<select name="city">
																					<option value="Sandown">Sandown</option>
																					<option value="Atkinson">Atkinson</option>
																					<option value="Danville">Danville</option>
																					<option value="Plaistow">Plaistow</option>

										<option value="Manchester">Manchester</option>

										<option value="E. Hampstead">E. Hampstead</option>
																					<option value="Other">Other</option>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 7) print "style='color:red'"; ?>>State:</td><td><input type="text" name="state" size="2" maxlength="2" readonly="true" value="NH"></td>
																		</tr>											
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 8) print "style='color:red'"; ?>>Zip code:</td><td><input type="text" name="zipcode" size="5" maxlength="5"value="<?php print @$zipcode; ?>"></td>
																		</tr>																	
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 9) print "style='color:red'"; ?>>Phone:</td><td><input type="text" name="phoneNumber" value="<?php print @$phoneNumber; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText" <?php if ($ERROR_CODE == 10) print "style='color:red'"; ?>>Email:</td><td><input type="text" name="email" value="<?php print @$email; ?>"></td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText">School:</td>
																			<td>
																				<select name="school">
																					<option value="Sandown North">Sandown North</option>
																					<option value="Timberlane Middle">Timberlane Middle</option>
																					<option value="Timberlane High">Timberlane High</option>
																					<option value="Other">Other</option>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td valign="top"><font class="regularText">Grade:</td>
																			<td>
																				<select name="grade">
                                                                                    <option value="3">3</option>
																					<option value="4">4</option>
																					<option value="5">5</option>
																					<option value="6">6</option>
																					<option value="7">7</option>
																					<option value="8">8</option>
																					<option value="9">9</option>
																					<option value="10">10</option>
																					<option value="11">11</option>
																					<option value="12">12</option>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td colspan="2"><input type="checkbox" name="chaperone">  <font class="regularText">I am interested in being a chaperone</font></td>
																		</tr>
																	</table>

																</td>														
															</tr>
														</table>
													</td>
												</tr>
												<tr bgcolor="#FFFFFF">
													<td align="center">
														<br>
														<input type="submit" value="Sign Up">   <input type="reset" value="Cancel">
													</td>
												</tr>
												<tr bgcolor="#FFFFFF"><td><br><br></td></tr>
											</table>

										<input type="hidden" name="submitted" value="true">
										</form>

										<?php 
											}
											else 
											{
										?>

												<!-- Step 4 Table -->
													<table cellspacing="1" cellpadding="4" border="0" width="100%">
														<tr bgcolor="#E9E9F3">
															<td>
																<font class="regularText" style="font-weight:bold">Download the handbook and packet of registration forms</font>
															</td>
														</tr>
														<tr bgcolor="#FFFFFF">
															<td align="center">
																<table boder="0" cellspacing="5" cellpadding="0" width="90%">
																	<tr>
																		<td>
																			<?php echo $contentManager->getContent('name', 'Sign Up'); ?>


																			<center>

																				<table cellspacing="0" cellpadding="5" border="0">
																				<!--
                                                                                	<tr>
																						<td><img src="images/pdfIcon.gif"></td>
																						<td><a class="regularText" style="color:blue" href="documents/SandownSkiClubHandbook<?php echo $websiteInfo['currentSeason']; ?>.pdf"><?php echo $websiteInfo['currentSeason']; ?> Sandown Ski Club Handbook</a></td>
																					</tr>
                                                                                -->
																					<tr>
																						<td><img src="images/pdfIcon.gif"></td>
																						<td><a class="regularText" style="color:blue" href="documents/PacketOfForms<?php echo $websiteInfo['currentSeason']; ?>.pdf"><?php echo $websiteInfo['currentSeason']; ?> Registration Forms Packet</a></td>
																					</tr>
																				</table>

																			</center>

																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>

												</td>
											</tr>

											<tr bgcolor="#FFFFFF">
												<td align="center">
													<br><br>
													<font class="regularText">
														Thank you for signing up for the Sandown Ski Club.  <br>This is going to be one of our best years ever.  See you at sign up night!

														<br><br><br><br><br><br><br>
														<a href="http://www.adobe.com/products/acrobat/readstep2.html"><img src="images/getAcrobat.gif" border="0"></a>
														<br><br>
													</font>
												</td>
											</tr>

										</table>

										<?php } ?>

									</td>
								
								<?php } ?>
							</tr>
						</table>

					</td>
					
<?php include('footer.php'); ?>
