<?php
session_start();
include("include/header.php");


if(trim($_SESSION['pName'])== "" || trim($_SESSION['pID'])=="")
{
	echo "<script>";
	echo "location.replace('parentLogin.php');";
	echo "</script>";

}


$byear = date('Y');
$bmonth = 1;
$bday = 1;
$toDate = $byear + 1;
$frDate = $toDate - 20;
$errmsg = "";


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

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

	if(trim($errmsg)=="")
	{

		$selp=@mysql_query("select * from tr_parent where parent_id='".$_SESSION['pID']."'");
		$rowp=@mysql_fetch_array($selp);

		$sel=@mysql_query("select max(syID) from ma_schoolyear where sStatus='1'");
		$row=@mysql_fetch_array($sel);

		$bDate = $_POST['byear']."-".$_POST['bmonth']. "-".$_POST['bday'];
		$dtlog=date('Y-m-d H:i:s');

		$ins=@mysql_query("insert into tr_student values('','".$_POST['stSchool']."','".$_POST['stFname']."','".$_POST['stLname']."','".$bDate."','".$_POST['tchrID']."','".$_POST['stGrade']."','".$rowp['Name']."','','','1','".$row[0]."','".$rowp['parent_id']."','".$_POST['stAllergy']."','".$_POST['stAllergy_desc']."')");

		
		$errmsg = "You have successfully created your student.";
	}



}
?>
<tr>
	<td>
		<table width="100%" cellpadding="0" cellspacing="0" border="0" height='300px'>
		<tr>
			<td>&nbsp;</td>
		</tr>

		<tr>
			<td  class="fs14 onlines blue" align='center'><b><u>ADD STUDENT</u></b></td>
		</tr>
		<tr>
			<td>
				<table width="100%" cellpadding="1" cellspacing="1" border="0">
					<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='4'>".$errmsg."</td></tr>";
						?>
							<meta http-equiv="Refresh" content="3;url=parentAccount.php"><br/><br/><br/><br/><br/>
						<?php
						}
						else if($_POST['eaction']=='CANCEL')
						{
							echo '<script>';
							echo 'location.replace("parentAccount.php");';
							echo '</script>';
						?>
						
						<?php
						}
						
						else
						{
							?>
					<tr>
						<td>
							<form action="add_newstudent.php" method="POST" name="action">
								 <table width="80%" border="0" cellpadding="0" cellspacing="1" class="fs12" align='center'>
									<tr>
										<td style="background-image:url('images/spacer.gif')" width="150" height="10"></td>
										<td style="background-image:url('images/spacer.gif')" width="200" height="10"></td>
									</tr>
									<tr>
										<td class="onlines blue">First Name :</td>
										<td><input type="text" id="stFname" name="stFname" class="formInputL" maxlength="45" value="<?=$_POST['stFname']?>"/></td>
									</tr>
									<tr>
										<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
									</tr>
									<tr>
										<td class="onlines blue">Last Name :</td>
										<td><input type="text" id="stLname" name="stLname" class="formInputL" maxlength="40" value="<?=$_POST['stLname']?>"/></td>
									</tr>
									<tr>
										<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
									</tr>
									<tr>
										<td class="onlines blue">Birth Date:&nbsp;</td>
										<td><select name="byear" class="formYear"><option value=''>-Y-</option>
											<?php
											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="bmonth" class="formDDMM">
										<option value=''>-M-</option>
											<?php
										   for($i=1;$i<=12;$i++)
											{
												if($_POST['bmonth']==$i)
													echo '<option value='.$i.' selected>'.$i.'</option>';
												else
													echo '<option value='.$i.' >'.$i.'</option>';
											}
											?>
									</select>&nbsp;
										<select name="bday" class="formDDMM">
										<option value=''>-D-</option>
										<?php
										for($i=1;$i<=31;$i++)
										{
											if($_POST['bday']==$i)
												echo '<option value='.$i.' selected>'.$i.'</option>';
											else
												echo '<option value='.$i.' >'.$i.'</option>';
										}
										?>
									</select></td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td class="onlines blue">Select School :</td>
									<td><input type="hidden" id="selSchool" name="selSchool" value="0" />
										<select id="stSchool" name="stSchool" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
										<?php
										$strSql = mysql_query("select school_id,school_name from tr_schools where status=1 order by school_name");
										$resc=@mysql_num_rows($strSql);
										if($resc>0)
										{
											echo "<option value='0'>--Select--</option>";
											while($rs=@mysql_fetch_array($strSql))
											{
												if($_POST['stSchool']==$rs['school_id'])
													echo "<option value='".$rs['school_id']."' selected>".$rs['school_name']."<?option>";
												else
													echo "<option value='".$rs['school_id']."'>".$rs['school_name']."<?option>";
											}
										}
										?></select>
									</td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td class="onlines blue">Select Grade :</td>
									<td>
										<select id="stGrade" name="stGrade" class="formSelect">
										<?php
										$strSql = mysql_query("select grade_id,grade_name from ma_grades where status=1");
										$resc=@mysql_num_rows($strSql);
										if($resc>0)
										{
											echo "<option value='0' selected>--Select--</option>";
											while($rsc=@mysql_fetch_array($strSql))
											{
											   if($_POST['stGrade']==$rs['grade_id'])
												echo "<option value='".trim($rsc['grade_id'])."' selected>".$rsc['grade_name']."</option>";
											else
												echo "<option value='".trim($rsc['grade_id'])."'>".$rsc['grade_name']."</option>";
												
											}
										}
										?>
										</select>
									</td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td class="onlines blue" nowrap>Select Teacher :</td><td>
										<select id="tchrID" name="tchrID" class="formSelect">
										<?php
										$strSql = mysql_query("select teacher_id,teacher_name from tr_teachers where status=1 and school_id='".$_POST['stSchool']."' order by teacher_name");
										echo "<option value='0'>--Select--</option>";
										$resct=@mysql_num_rows($strSql);

										if($resct>0)
										{
											while($rst=@mysql_fetch_array($strSql))
											{
												if($_POST['tchrID']==$rst['teacher_id'])
													echo "<option value='".$rst['teacher_id']."' selected>".$rst['teacher_name']."</option>";
												else
													echo "<option value='".$rst['teacher_id']."'>".$rst['teacher_name']."</option>";
											}
										}
										?></select>
									</td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td class="onlines blue">Allergies?</td><td>
									<input type="checkbox" id="stAllergy" name="stAllergy" value='1'/> <input type="text" id="stAllergy_desc" name="stAllergy_desc" value=""/></td>
								</tr>
								<tr>
									<td align='center' colspan="2"><input type='submit' name='action' value='ADD'/><input type='submit' name='eaction' value='CANCEL'/></td>
								</tr>
								<tr>
									<td width="30%" class="errmsg" colspan='2'><?=$errmsg?></td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="10"></td>
								</tr>
								 <tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td colspan="2" id="errpop" class="errmsg"></td>
								</tr>
								<tr>
									<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
								</tr>
								<tr>
									<td style="background-image:url('images/spacer.gif')" width="10" height="1"></td>
								</tr>
						</table>
					</form>
				</td>
			</tr>
			<?php
				}
			?>
			<tr><td colspan="2"><hr /></td></tr>
			</table>
		</td>
	</tr>
</table>
</td>
</tr>
<?php
include("include/footer.php");
?>
