<?php
session_start();
//header("location:javascript://history.go(-1)");
if (isset($_SESSION['login_id'])) {
    header('location: dashboard.php');
}
?>
<!DOCTYPE html>
<html>

<head>
    <title>Fairy Herbal Portal</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="css/style2.css">

    <!-----		sweet alert css and js link	---->
    <link rel="stylesheet" href="dist/sweetalert.css">
    <script src="dist/sweetalert.min.js"> </script>
    <style>
        .logo-text {
            line-height: 50px;
            font-size: 20px;
            font-weight: 600;
            color: #696969;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="login-signup">
            <div class="row">
                <div class="col-sm-6 col-sm-offset-3 nav-tab-holder">
                    <div class="col-sm-6 col-sm-offset-3 text-center" style="border: 1px solid white; padding-right: 22px">
                        <br>
                        <span class="logo-text"> Forgot Password </span>
                    </div>
                </div>
            </div>

            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="home">
                    <div class="row">

                        <div class="col-sm-6 col-sm-offset-3">
                            <article role="login">
                                <form class="signup" method="post">

                                    <div class="form-group">
                                        <h6>Please enter your email address or phone number to reset your account password.</h6>
                                    </div>

                                    <div class="form-group">
                                        <input type="text" class="form-control" placeholder="Enter your email or mobile" name="email" id="email">
                                        <div id="email_error" style="color:red"></div>
                                    </div>

                                    <div id="err" style="color:red"></div>
                                    <div class="form-group">
                                        <input type="button" class="btn btn-success btn-block" value="Search" name="search" id="search" onclick="forgot_password(this.value)">
                                    </div>
                                </form>
                                <a style="float:right" href="index.php">Back to login</a>
                            </article>
                        </div>

                        <div class="col-sm-6">

                        </div>

                    </div>
                    <!-- end of row -->
                </div>
                <!-- end of home -->


            </div>
        </div>
    </div>
    <!---  end conttainer -->
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <script type="text/javascript" src="js/jquery.redirect.js"></script>
    <script src="js/custom.js"></script>
    <script>
        function forgot_password(search_account) {
            var email = $('#email').val();

            if (email != "") {
                $('#email_error').text("");
                $.ajax({
	             type:"POST",
	             url:"login_code.php",
                 data:{email:email,
                    search_account:search_account
                },
	             success:function(response){
                     console.log(response);
                     if($.trim(response)  == "not_found")
                     {
                        $('#email_error').text("Your search did not return any results. Please try again with other information.");
                     }
                     else if($.trim(response) == 1){
						 $('#email').val('');
                         //$('#email.error').text("Mail has been sent to your email id");
						 alert("Your account password reset successfully.\nNew password has been sent to your email or mobile");
                     }
                     else
                     {
                         alert("Your account password reset successfully.\nNew password has been sent to your email or mobile");
                     }
	             },
	             
	         });

            } else {
                $('#email_error').text("Fill in at least one field to search for your account");
            }
        }
    </script>
</body>

</html>