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

$_SESSION['pName']="";
$_SESSION['pID']="";
$_SESSION['xsid']="";


if($_POST['action']=="LOGIN")
{
	
	$login=$_POST['login'];
	$password=$_POST['password'];
	$lginErr="";

	    if (trim($login)=="")
			$lginErr = "Login Name field is empty";
		
		if (trim($password)=="")
		{
			if(trim(lginErr)=="")
				$lginErr = $lginErr . "<br/>Password field is empty";
			else
				$lginErr = "Password field is empty";
		} 

		if (trim($lginErr)=="")
		{
			
			$strSql = mysql_query("select Name,parent_id from tr_parent where email='".trim($login)."' and password='". trim($password)."'");
			$rs = @mysql_fetch_array($strSql);
			$rcnt=@mysql_num_rows($strSql);
			if ($rcnt > 0)
			{
				$_SESSION['pName'] = trim($rs['Name']);
				$_SESSION['pID'] = trim($rs['parent_id']);
				$nowDate = date('Y-m-d');
					//" " & Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
				$strSql1 = mysql_query("update tr_parent set date_lastlog='".$nowDate."' where account_id='".$rs['parent_id']."'");
				
			}
			else
			{
				
				$_SESSION['pName'] = "";
				$_SESSION['pID'] = "";
				$lginErr = "Invalid Account Name or password!";
			}
		  }
			
}
?>
<tr><td width="900" class="fs15 blue">


<table border="0" cellpadding="1" cellspacing="1" width="100%" align="center">
<?php
if(trim($_SESSION['pName'])!="" &&  trim($_SESSION['pID'])!="")
{
 echo "<script>";
echo "location.replace('parentAccount.php');";
 echo "</script>";

?>
    <tr><td></td><td align="center"><u><b>LUNCH PAILS PARENT PANEL</b></u></td></tr>
    <tr class="fs12"><td width="200">
	<?php //include("sidemenu.php");?></td>
        <td width="700" align="center" valign="middle">Welcome <b><?=$_SESSION['pName']?></b> to Lunch Pails PARENT PANEL!</td></tr>
<?php
}
else 
{
?>
    <form action="parentLogin.php" method="POST" name="frm">
    <tr><td align="center" colspan="2" height="60px"><u><b>LUNCH PAILS PARENT LOGIN</b></u></td></tr>
    <tr><td width="300" align="right"><b>Email Id :</b>&nbsp;&nbsp;</td><td width="600"><input type="text" name="login" size="35" maxlength="100" value="<?=$login?>" /></td></tr>
    <tr><td width="300" align="right"><b>Password :</b>&nbsp;&nbsp;</td><td width="600"><input type="password" name="password" size="35" maxlength="25" value="<?=$password?>" /></td></tr>
    <tr><td align="right"><a href="signupform.php" style="text-decoration:none;">Click here to Register</a></td><td><div style="padding-left:172px"><input type="submit" name="action" value="LOGIN" /></div></td></tr>
	<tr><td align="right"><a href="forget_pasw.php" style="text-decoration:none;">Forgot Your Password ?</a></td></tr>
    <tr><td></td><td class="errmsg"><?=$lginErr?></td></tr>
	<tr><td align="center" colspan="2" height="60px">&nbsp;</td></tr>
    </form>	
<?php
}
?>
</table></td></tr>
<?php
include("include/footer.php");
?>