<?php
session_start();
include("header.php");
?>
<style>
.input_s1_normal   { width: 150; height: 15; font-family: Verdana; font-size: 10px; }
.input_s1_focus    { background: #efefef; }
.button_s1   { font-family: Verdana; font-size: 10px; font-weight: bold; border: 1px solid black; }

</style>
<script type="text/javascript" src="passwd/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="passwd/checkp.js"></script>
<script type="text/javascript" src="passwd/jquery.min1.js"></script>
<script type="text/javascript" src="passwd/jquery.validate.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
	  $("#form1").validate({
		rules: {
		  password: {
				required: true, minlength: 5
		  },
		  c_password: {
				required: true, equalTo: "#password", minlength: 5
		  }

		  }
		  }
	  );
	});
</script>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<!-- <td></td> -->
		<td align="center" class="fs14" colspan='2'><u><b>Signup Form</b></u></td>
	</tr>
	<tr>
		<td colspan='2'>&nbsp;</td>
	</tr>
	<tr>
		<td width="200" class="fs12" valign="top">
			
		</td>
		<td width="700" class="fs12" valign="top">
		<form name='sign' method='POST' action='signupform.php' id="form1" id="chkForm">
			 <table width="100%" cellpadding="1" cellspacing="1" border="0">
					<tr>
						<td height="10" width="20%"></td>
						<td width="30%" class="reqmsg"><i>* required fields</i></td>
						<td height="10" width="15%"></td>
						<td width="35%"></td>
					</tr>
					<tr>
						<td align="right"><b>*</b>FIRST NAME:&nbsp;</td>
						<td><input class="formInput" type="text" name="studentfName" value="<?=$_POST['studentfName']?>" /></td>
					</tr>
					<tr>
						<td align="right"><b>*</b>LAST NAME:&nbsp;</td>
						<td><input class="formInput" type="text" name="studentlName" value="<?=$_POST['studentlName']?>" /></td>
					</tr>
					<tr>
						<td align="right"><b>*</b>CONTACT#:&nbsp;</td>
						<td><input class="formInput" type="text" name="contactNo" value="<?=$_POST['contactNo']?>" /></td>
					</tr>
					<tr>
						<td align="right">BIRTH DATE:&nbsp;</td>
						<td>
							<select name="byear" class="formYear">
							<option value=''>-Y-</option>
							<?php
							$byear = date('Y');
							$toDate =$byear+1;
							$frDate = $toDate-20;

							for($i=$frDate;$i<=$toDate;$i++)
							{
								if($_POST['byear']==$i)
									echo '<option value='.$i.' selected>'.$i.'</option>';
								else
									echo '<option value='.$i.' >'.$i.'</option>';
							}

							
							?>
							</select>&nbsp;
							<select name="bdmonth" class="formDDMM">
							<option value=''>-M-</option>
							<?php
						   for($i=1;$i<=12;$i++)
							{
								if($_POST['bdmonth']==$i)
									echo '<option value='.$i.' selected>'.$i.'</option>';
								else
									echo '<option value='.$i.' >'.$i.'</option>';
							}
							?>
							</select>&nbsp;
								<select name="bdday" class="formDDMM">
								<option value=''>-D-</option>
								<?php
								for($i=1;$i<=31;$i++)
								{
									if($_POST['bdday']==$i)
										echo '<option value='.$i.' selected>'.$i.'</option>';
									else
										echo '<option value='.$i.' >'.$i.'</option>';
								}
								?>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">Select School:&nbsp;</td>
						<td><select name="school" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
						<?php
						$strSqls =@mysql_query("select school_id,school_name from tr_schools where status=1 order by school_name");
						$cnts=@mysql_num_rows($strSqls);
						if($cnts>0)
						{
							echo "<option value='0'>--Select--</option>";
							while($rs1=@mysql_fetch_array($strSqls))
							{
								
								if($_POST['school']==$rs1['school_id'])
									echo '<option value='.$rs1['school_id'].' selected>'.$rs1['school_name'].'</option>';
								else
									echo '<option value='.$rs1['school_id'].'>'.$rs1['school_name'].'</option>';
							}
							
						}
						
						 ?>
						</select></td>
					</tr>
					<tr>
						<td align="right">Select Grade:&nbsp;</td>
						<td><select name="grade" class="formSelect">
						<?php
						$strSqlg =@mysql_query("select grade_id,grade_name from ma_grades where status=1");
						$cntg=@mysql_num_rows($strSqlg);
						if($cntg>0)
						{
							echo "<option value='0'>--Select--</option>";
							while($rs2=@mysql_fetch_array($strSqlg))
							{
								
								if($_POST['grade']==$rs2['grade_id'])
									echo '<option value='.$rs2['grade_id'].'>'.$rs2['grade_name'].'</option>';
								else
									echo '<option value='.$rs2['grade_id'].'>'.$rs2['grade_name'].'</option>';
							}
						}
						 ?>
						</select></td>
					</tr>
					<tr>
						<td align="right" NOWRAP><b>*</b>PARENT/GUARDIAN NAME:&nbsp;</td>
						<td><input class="formInput" type="text" name="guardianName" value="<?=$_POST['guardianName']?>" /></td>
					</tr>
					<tr>
						<td align="right">TEACHER:&nbsp;</td>
						<td>
							<select name="tchrID" class="formSelect">
							<?php
								$strSql =@mysql_query("select teacher_id,teacher_name from tr_teachers where status=1 and school_id=".$_POST['school']." order by teacher_name");
								$cntr=@mysql_num_rows($strSql);
								echo "<option value='0'>--Select--</option>";
								
								if($cntr>0)
								{
									while($rs=@mysql_fetch_array($strSql))
									{
										if($_POST['tchrID']==$rs['teacher_id'])
											echo '<option value='.$rs['teacher_id'].' selected>'.$rs['teacher_name'].'</option>';
										else
											echo '<option value='.$rs['teacher_id'].'>'.$rs['teacher_name'].'</option>';

									}
								}

							?>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">EMAIL ADDRESS:&nbsp;</td>
						<td><input class="formInput" type="text" name="emailAdd" value="<?=$_POST['emailAdd']?>" /></td>
					</tr>
					<tr>
						<td align="right">ALLERGY ALERT:&nbsp;</td>
						<td><input type='checkbox' name='alet' value='1'><input class="formInput" type="text" name="alergy" value="<?=$_POST['alergy']?>" /></td> 
					</tr>
					<tr>
						<td align="right"><b>*</b>PASSWORD:&nbsp;</td>
						<td><input class="formInput required" type="password" name='password' id="password" value="<?=$_POST['mpassw']?>"  /></td>
					</tr>
					<tr>
						<td align="right" nowrap><b>*</b>VERIFY PASSWORD:&nbsp;</td>
						<td><input class="formInput input_s1_normal" type="password" name='c_password'  id="c_password" value="<?=$_POST['vpassw']?>" /></td>
					</tr>
					<!-- name="mpassw"
					name="vpassw" -->
					<tr>
						<td colspan="4">&nbsp;</td>
					</tr>
					<tr>
						<td colspan="2" align='center'><input class="fs12" type="submit" name="action" value="SUBMIT" />
					</tr>
				</table>
			</form>
		</td>
	</tr>
</table>
</td>
</tr>
<?php
include("footer.php");

if($_POST['action']=='SUBMIT')
{


	if($_POST['studentfName']!='' && $_POST['studentfName']!='' && $_POST['studentlName']!='' && $_POST['guardianName']!='' && $_POST['contactNo']!='' && $_POST['password']!='' && $_POST['c_password']!='' )
	{
		$bDate = $_POST['byear']."-".$_POST['bdmonth']. "-".$_POST['bdday'];
		$dtlog=date('Y-m-d H:i:s');

		$insp=@mysql_query("insert into tr_parent values('','".$_POST['guardianName']."','".$_POST['emailAdd']."','".$_POST['password']."','".$_POST['contactNo']."','','".$dtlog."')");
		
		$rid=mysql_insert_id();

		if($_POST['alet']=="")
			$alert='0';
		else
			$alert='1';

		
		
		$ins=@mysql_query("insert into tr_student values('','".$_POST['school']."','".$_POST['studentfName']."','".$_POST['studentlName']."','".$bDate."','".$_POST['tchrID']."','".$_POST['grade']."','".$_POST['guardianName']."','".$_POST['emailAdd']."','".$_POST['contactNo']."','1','','".$rid."','".$alert."','".$_POST['alergy']."')");


		echo '<script>';
		echo 'alert("Data Submitted Successfully");';
		echo 'location.replace("signupform.php");';
		echo '</script>';
	}
	else
	{
		echo '<script>';
		echo 'alert("Enter Required Fields");';
		echo '</script>';
	}

}
?>

