<?php
session_start();
//ob_start();

require("../includes/config.php");
require("../includes/dbcon.php");

if( !empty($_POST) )
{
	$email=trim($_REQUEST['email']);
	$password=trim($_REQUEST['pwd']);
	
	$userSql="select * from enrollment_officer where email = '".$email."' and password = '".$password."'";
	$userRs=mysql_query($userSql);
	$totRows=mysql_num_rows($userRs);	
	$userValue = mysql_fetch_array($userRs);	
	$name=$userValue['fisrt_name']." ".$userValue['middle_name']." ".$userValue['last_name'];

	$err_msg="";
	if($totRows>0)
	{	
		if(md5($_REQUEST['security_code']) == $_SESSION['captcha_code'])
		{	
			unset($_SESSION['captcha_code']);
			$_SESSION['uid'] = $userValue['officer_id'];
			$_SESSION['name'] = $name;
			header("location:userList.php");
		}	
		else 
		{	
			$err_msg=urlencode("Sorry, you have provided an invalid security code<br>");
			header("location:index.php?err_msg=".$err_msg);		
		}
	}
	else
	{
		$err_msg.="Sorry ! Please provide correct Email/Password";
		header("location:index.php?err_msg=".$err_msg);	
	}
}

ob_end_flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../style/design.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {font-size: 0.8em}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>:::   Admin Login Page   :::</title>
<script language="JavaScript" src="../includes/js/common.js"></script>
<script language="JavaScript">
function validate()
{
	var is_valid=true
			
	is_valid = blank_check( document.frm.email.value, "PLEASE INPUT EMAIL ADDRESS" )
		if( is_valid == false ) { document.frm.email.focus(); return is_valid }	

	is_valid = email_check( document.frm.email.value, "PLEASE INPUT CORRECT EMAIL" )
    if( is_valid == false ) { document.frm.email.focus(); return is_valid }

	is_valid = blank_check( document.frm.pwd.value, "PLEASE INPUT YOUR PASSWORD" )	
    if( is_valid == false ) { document.frm.pwd.focus(); return is_valid }

	is_valid = blank_check( document.frm.security_code.value, "PLEASE INPUT SECURITY CODE" )	
    if( is_valid == false ) { document.frm.security_code.focus(); return is_valid }
	
	return is_valid
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" valign="top">
<?php
include_once("includes/header.php");
?>
<form name="frm" method="post" action="" onSubmit="return validate()">
	<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">	 
	 <tr>
	   <td width="30%" valign="top">
		<div class="bodySubHeader">
		<span class="bsht03">Admin Login</span>		
		</div>
		</td>
	 </tr> 
	</table>	

	<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
	 <tr>
	   <td height="30" align="center" valign="top" colspan="3" class="ErrorMessage"> <strong><?=$_REQUEST['err_msg']?> </strong></td>	   
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Email:</strong></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="email" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Password:</strong></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="pwd" type="password"/></td>
	 </tr>		
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Humans Only!</strong></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top" class="ImagePaddingOne"><img src="../security_verify.php" />			
	   </td>
	 </tr>
	 <tr>
	   <td height="25" align="left" valign="middle">&nbsp;</td>
	   <td height="25" align="left" valign="middle">&nbsp;</td>
	   <td height="25" align="left" valign="middle" class="browseEventContents">(Letters are Case sensitive) </td>
	 </tr>
	 <tr>
	   <td align="left" valign="top">&nbsp;</td>
	   <td width="30" align="left" valign="top">&nbsp;</td>
	   <td align="left" valign="top"><input name="security_code" id="security_code" type="text" /></td>
	 </tr>
	 <tr>
	   <td height="35" align="left" valign="bottom">&nbsp;</td>
	   <td width="30" height="35" align="left" valign="bottom">&nbsp;</td>
	   <td height="35" align="left" valign="bottom"><input name="Submit" type="submit" value="Login" /></td>
	 </tr>	 
	</table>
</form>
<?php
include_once("../includes/footer.php");
?>
		</td>
	</tr>
</table>
</body>
</html>