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

if($_GET['lgt']=="logout")
{
	$_SESSION['accountName']="";
	$_SESSION['accountID']="";
	$_SESSION['pgid']="";

}
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 account_name,account_id from tr_adminaccount where user_name='".trim($login)."' and account_ref='". trim($password)."'");
			$rs = @mysql_fetch_array($strSql);
			$rcnt=@mysql_num_rows($strSql);
			if ($rcnt > 0)
			{
				$_SESSION['accountName'] = trim($rs['account_name']);
				$_SESSION['accountID'] = trim($rs['account_id']);
				$_SESSION['pgid']="i3g3e3nious7";

				$nowDate = date('Y-m-d');
					//" " & Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
				$strSql1 = mysql_query("update tr_adminaccount set date_lastlog='".$nowDate."' where account_id='".$rs['account_id']."'");
				
			}
			else
			{
				
				$_SESSION['accountName'] = "";
				$_SESSION['accountID'] = "";
				$lginErr = "Invalid Account Name or password!";
			}
		  }
			
}
?>


<table border="0" cellpadding="1" cellspacing="1" width="100%" align="center">
<?php
if(trim($_SESSION['accountName'])!="" &&  trim($_SESSION['accountID'])!="" && trim($_SESSION['pgid'])=="i3g3e3nious7")
{
?>
    <tr><td></td><td align="center"><u><b>LUNCH PAILS ADMIN</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['accountName']?></b> to Lunch Pails Store ADMIN!</td></tr>
<?php
}
else 
{
?>
    <form action="index.php" method="POST" name="frm">
    <tr><td colspan="2" height="100">&nbsp;</td></tr>
    <tr><td width="300" align="right"><b>Login Name :</b>&nbsp;&nbsp;</td><td width="600"><input type="text" name="login" size="35" maxlength="25" 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></td><td><div style="padding-left:172px"><input type="submit" name="action" value="LOGIN" /></div></td></tr>
    <tr><td></td><td class="errmsg"><?=$lginErr?></td></tr>
    </form>
<?php
}
?>
</table>
<?php
include("footer.php");
?>