<?php require('includes/login.php'); ?>
<?php
	$msg='';
	if(isset($_POST['email'])){
		$usersEmail = $_POST['email'];
		
		// Create database connection
		include('includes/connection.php');
		$sql_pass = mysql_query("select username, password, fname, lname from users where username='$usersEmail' limit 1");
		$count_pass = mysql_num_rows($sql_pass);
		if($count_pass>0){
			$row_pass = mysql_fetch_array($sql_pass);
			$username = $row_pass['username'];
			$password = $row_pass['password'];
			$fname = $row_pass['fname'];
			$lname = $row_pass['lname'];
			
			include_once('includes/mail.php');
			$subj = 'Message from Lmi India';
			$message = '<html>
							<head>
							  <title>Message from Lmi India</title>
							</head>
							<body>
							  <p>Hello '.$fname.' '.$lname.',</p>
							  <p></p>
							  <p>Your Username / Email : <b>'.$username.'</b></p>
							  <p>Your Password : <b>'.$password.'</b></p>
							</body>
						</html>';
			$m = mymail($usersEmail,$fname,$subj,$message);
			if($m){
				header("location:forget-password.php?email-sent");
			}
		}else{
				header("location:forget-password.php?email-sent-error");
		}
	}
?>
<?php
	if(isset($_GET['email-sent'])){
		$msg='<div class="alert alert-success" role="alert">
					<button type="button" class="close" data-dismiss="alert" aria-label="Close">
							  <span aria-hidden="true">&times;</span>
							</button>
					Email Sent! Please check your email inbox</div>';
	}else if(isset($_GET['email-sent-error'])){
		$msg='<div class="alert alert-danger" role="alert">
					<button type="button" class="close" data-dismiss="alert" aria-label="Close">
							  <span aria-hidden="true">&times;</span>
							</button>
					Email not Found!</div>';
	}
?>

<!DOCTYPE html>

<html lang="en">

	<head>

		<meta http-equiv="content-type" content="text/html; charset=UTF-8">

		<meta charset="utf-8">

		<title>Lmi-India</title>

		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="SHORTCUT ICON" href="http://www.lmi-india.in/wp-content/themes/Revera/images/favicon.ico" type="image/x-icon">

		<link href="css/bootstrap.min.css" rel="stylesheet">

		<link href='http://fonts.googleapis.com/css?family=Ledger' rel='stylesheet' type='text/css'>

		<!--[if lt IE 9]>

			<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>

		<![endif]-->

		<link href="css/styles.css" rel="stylesheet">

	</head>

	<body>

		<div class="container">

			<div class="row">

				<div class="col-sm-6 col-sm-offset-3 loginLogo center">

					<img src="./images/logo.jpg" style="width:150px;">

				</div>

			</div>

			<div class="row">

				<div class="col-sm-4 col-sm-offset-4 border1px loginForm">
					<?php echo $msg; ?>
					<form action="forget-password.php" method="post">

						<fieldset>

						  <legend>Forgot Password?</legend>

						  <div class="control-group">

							<div class="controls">

							  <input type="email" class="form-control input-xlarge" id="input01" name="email" placeholder="Enter you registered email address" required>

							</div>

						  </div>

						  <hr/>

							<!--<div class="control-group">

							<div class="controls">

								<a href="forget-password.php">Forgot Password?</a>

							</div>

						  </div>-->

						  <div class="form-actions">

							<button type="submit" class="btn btn-primary">Submit</button>
							<a href="index.php" class="btn btn-primary">Back</a>

						  </div>

						</fieldset>

					</form>

				</div>

			</div>

		</div>

         

		<!-- script references -->

		<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

		<script src="js/bootstrap.min.js"></script>

	</body>

</html>