<?php
session_start();
include("include/header.php");
$errmsg="";
?>
<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: {
		  email: {
				required: true
		  },
		  password: {
				required: true, minlength: 5
		  },
		  c_password: {
				required: true, equalTo: "#password", minlength: 5
		  },
			v_email: {
				required: true, equalTo: "#email"
		  }

		  }
		  }
	  );
	});
</script>
<!-- <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
 --><script type="text/javascript">
function lookup(inputString) {

$.post("checkemail.php",{user: ""+inputString+""},function(data){
$('#autoSuggestionsList').html(data).show();
});
}
</script>
<?php
if($_POST['action']=='SUBMIT')
{

$errmsg="";
if(trim($_POST['studentfName'])=="")
			$errmsg = $errmsg."Student First Name field is empty.<br/>";

if(trim($_POST['studentlName'])=="")
			$errmsg = $errmsg."Student Last Name field is empty.<br/>";

if(trim($_POST['guardianName'])=="")
			$errmsg = $errmsg."Parent/Guardian Name field is empty.<br/>";

if(trim($_POST['contactNo'])=="")
			$errmsg = $errmsg."Contact No. field is empty.<br/>";

if(trim($_POST['email'])=="")
			$errmsg = $errmsg."Email Id field is empty.<br/>";

if(trim($_POST['password'])=="")
			$errmsg = $errmsg."Password field is empty.<br/>";

if(trim($_POST['c_password'])=="")
			$errmsg = $errmsg."Re-type Password field is empty.<br/>";



	if($_POST['studentfName']!='' && $_POST['studentlName']!='' && $_POST['guardianName']!='' && $_POST['contactNo']!='' && $_POST['password']!='' && $_POST['c_password']!='' && $_POST['email']!='')
	{
		$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['email']."','".$_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['email']."','".$_POST['contactNo']."','1','','".$rid."','".$alert."','".$_POST['alergy']."')");


				$errmsg = "You have successfully created your account.";

	}
	

}
?>
<tr><td width="900" class="fs15 blue">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<!-- <td></td> -->
		<td align="center" class="fs14" colspan='2'><br /><u><b>Parent Signup Form</b></u></td>
	</tr>

	<tr>
		<td colspan='2'>&nbsp;</td>
	</tr>


	<tr><td colspan="2"><hr /></td></tr>
					<?php
						if(strtoupper(substr(trim($errmsg),0,8)) == "YOU HAVE")
						{
							echo "<tr valign='top' align='center'><td colspan='2'>".$errmsg."</td></tr>";
						?>
							<meta http-equiv="Refresh" content="3;url=parentLogin.php"><br/><br/><br/><br/><br/>
						<?php
						}
						else
						{
							?>

	<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>STUDENT FIRST NAME:&nbsp;</td>
						<td><input class="formInput" type="text" name="studentfName" value="<?=$_POST['studentfName']?>" /></td>
					</tr>
					<tr>
						<td align="right"><b>*</b>STUDENT 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"><b>*</b>EMAIL ADDRESS:&nbsp;</td>
						<td><input class="formInput input_s1_normal" type="email" name="email" value="<?=$_POST['email']?>" id="email" onkeyup="lookup(this.value);"/>
						<font color="red">
						<div style="display: none;" id="autoSuggestionsList"></div>
						<div style="display: none;" id="error"></div>
						</font>
					</td>
					</tr>
					<tr>
						<td align="right" nowrap><b>*</b>VERIFY EMAIL ADDRESS:&nbsp;</td>
						<td><input class="formInput input_s1_normal" type="text" name='v_email'  id="v_email" value="<?=$_POST['v_email']?>" /></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="2">&nbsp;</td>
					</tr>
					<tr>
						<td width="30%" class="errmsg" colspan='2'><?=$errmsg?></td>
					</tr>
					<tr>
						<td colspan="2" align='center'><input class="fs12" type="submit" name="action" value="SUBMIT" />
						<input class="fs12" type="submit" name="eaction" value="CANCEL" onclick="document.location.href='signupform.php';"/></td>
					</tr>

					<tr>
					 <td colspan="4" height="40" style="font-family:verdana;font-size:12px;color:#FF3300;font-weight:bold;">Note: More students can be added later in the Parent Panel after logging in.</td>
					</tr>
					<?php
						}
					?>

				</table>
			</form>
		</td>
	</tr>
	<tr><td colspan="2"><hr /><br /><br /></td></tr>

</table>
</td>
</tr>
<?php
include("include/footer.php");


?>

