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

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

}



	$school=0;
	$grade=0;
	$tchrID=0;
	$paName="";
	$paEmail="";
	$paPassword="";
	$paPhone="";
	$paCell="";

	$strSql2 = mysql_query("SELECT name,email,password,contact_no,cell_no FROM tr_parent where parent_id='".$_SESSION['pID']."'");
	$rsc2=@mysql_num_rows($strSql2);		
	if($rsc2>0)
	{
		$rs2=@mysql_fetch_array($strSql2);

		$paName=trim($rs2['name']);
		$paEmail=trim($rs2['email']);
		$paPassword=trim($rs2['password']);
		$paPhone=trim($rs2['contact_no']);
		$paCell=trim($rs2['cell_no']);
	}
	

	$strSql3 = mysql_query("SELECT syID FROM ma_schoolyear where sStatus=1 order by syID desc limit 1");
	$rsc3=@mysql_num_rows($strSql3);		
	if($rsc3>0)
	{
		$rsc3=@mysql_fetch_array($strSql3);
		 $yearRef=$rsc3['syID'];
	}

	if($_POST['action']=='CHANGE')
{
	$upd=@mysql_query("update tr_parent set Name='".$_POST['paName']."', email='".$_POST['paEmail']."', password='".$_POST['paPassword']."', contact_no='".$_POST['paPhone']."', cell_no='".$_POST['paCell']."', date_last_log='' where parent_id='".$_SESSION['pID']."'");

	$errmsg = "You have successfully updated 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>EDIT ACCOUNT</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 name='edparent' method='POST' action='edit_parent.php'>
									<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" style='padding-left:100px;'>Parent/Guardian Name :</td>
											<td><input type="text" id="paName" name="paName" class="formInput" maxlength="45" value="<?=$paName?>"/></td>
										</tr>
										<tr>
											<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
										</tr>
										<tr>
											<td class="onlines blue" style='padding-left:100px;'>Your Email :</td>
											<td><input type="text" id="paEmail" name="paEmail" class="formInput" maxlength="45" value="<?=$paEmail?>"/></td>
										</tr>
										<tr>
											<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
										</tr>
										<tr>
											<td class="onlines blue" style='padding-left:100px;'>Your Password :</td>
											<td><input type="password" id="paPassword" onKeyPress="pasChn()" name="paPassword" class="formInput" maxlength="15" value="<?=$paPassword?>"/></td>
										</tr>
										<tr>
											<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
										</tr>
										<tr>
											<td colspan="2">
												<table id="vPass" style="display:none" width="100%" cellpadding="0" cellspacing="0">
													<tr><td width="150" class="onlines blue" style='padding-left:100px;'>Verify Your Password :</td><td width="200"><input type="password" id="pavPassword" name="pavPassword" class="formInput" maxlength="15" value="<?=$paPassword?>"/></td></tr>
													<tr><td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td></tr>
												</table>
											</td>
										</tr>
										<tr>
											<td class="onlines blue" style='padding-left:100px;'>Phone No. :</td>
											<td><input type="text" id="paPhone" name="paPhone" class="formInput" maxlength="15" value="<?=$paPhone?>"/></td>
										</tr>
										<tr>
											<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="5"></td>
										</tr>
										<tr>
											<td class="onlines blue" style='padding-left:100px;'>Cellphone No. :</td>
											<td><input type="text" id="paCell" name="paCell" class="formInput" maxlength="15" value="<?=$paCell?>"/></td>
										</tr>
										<tr>
											<td colspan="2" style="background-image:url('images/spacer.gif')" width="1" height="10"></td>
										</tr> 
										 <tr>
											<td align='center' colspan="2"><input type='submit' name='action' value='CHANGE'/><input type='submit' name='eaction' value='CANCEL'/></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> 
								</table>
 							</form>
						</td>
					</tr>
			<?php
				}
			?>
			<tr><td colspan="2"><hr /></td></tr>
			</table>
		</td>
	</tr>
</table>
</td>
</tr>
<?php
include("include/footer.php");
?>
