<?php
require_once("db.php");
require_once("config.php");
if(!empty($_POST['email']))
{
    $reseta = mysqli_real_escape_string($db, $_POST['email']); 
    $lenght=20;
    $key=substr(str_shuffle(md5(time())),0,$lenght);
    $adminemail = "noreply@alphachequers.com";

    //check data
    $sql = mysqli_query($db, "SELECT * FROM logins WHERE email='$reseta'");
    $result =mysqli_num_rows($sql);
    if ($result > 0){
        while($row = mysqli_fetch_assoc($sql)) {
            $email = $row['email'];
        }
        $expFormat = mktime(
            date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
            );
       
           $expDate = date("Y-m-d H:i:s",$expFormat);

        //if username matches create key using php date
        $mysqli_result = mysqli_query($db, "UPDATE logins SET reset='$key', exp_date='$expDate'  WHERE email ='$reseta'");
       // $row =mysqli_fetch_array($mysqli_result) or die(mysqli_error($db));
        if ($mysqli_result){
            $message = "<a href='https://alphachequers.com/us/change-password.php?user=".$email."&key=".$key."'>Click To Reset password</a>";
            $header = 'From: ' .$adminemail;
            mail($email,'Password Reset Request',$message,$header);
            header('location: forget-password.php?success=emailSent');
            exit;
            
        } else {

            header('location: forget-password.php?error=emailNotSent');
            exit;


        }
    }
    else {
        header('location: forget-password.php?error=emailNotFound');
            exit;
    }
    mysqli_close($db);
}
?>


<!DOCTYPE html>
<html lang="en">
 


<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Alpha Chequers™ - Reset Password </title>
    <!-- Favicon icon -->
    <link rel="shortcut icon" href="../Account/Signin/assets/img/myfavicon.png" type="image/x-icon">
    <!-- Custom Stylesheet -->
    <link rel="stylesheet" href="../Account/vendor/waves/waves.min.css">
    <link rel="stylesheet" href="../Account/css/style.css">
      <style>
      .float{
    position:fixed;
    width:60px;
    height:60px;
    bottom:40px;
    right:40px;
    background-color:#25d366;
    color:#FFF;
    border-radius:50px;
    text-align:center;
  font-size:30px;
    box-shadow: 2px 2px 3px #999;
  z-index:100;
}

.my-float{
    margin-top:16px;
}
        .goog-te-combo{
        	height: 30px !important;
        	padding: 0px !important;
        }
        .goog-logo-link {
           display:none !important;
        }
        
        .goog-te-gadget {
           color: transparent !important;
           height: 35px !important;
           margin: 0px !important;
        }
        
        .goog-te-gadget .goog-te-combo {
           color: #000000 !important;
}
.logo-title{
    height:30px; 
    padding-top: 3px !important; 
    border: 1px solid #; 
    width: 130px;
    margin-left: 30px

}
.small-logo{
    height:30px; 
    width: 30px; 
    border: 1px solid #; 
    float: left;
}
.mini-logo{
    border: 1px solid # !important;
     margin: 0px auto !important;
      height: 34px !important; 
      width: 180px;
}
    </style>
</head>

<body>

    <div id="preloader">
        <div class="sk-three-bounce">
            <div class="sk-child sk-bounce1"></div>
            <div class="sk-child sk-bounce2"></div>
            <div class="sk-child sk-bounce3"></div>
        </div>
    </div>

    <div id="main-wrapper" style="margin-top: 0px !important">
       
        <div class="authincation section-padding" style="margin-top: 0px !important; padding-top: 0px !important; padding-bottom: 10px !important">
            <div class="container h-100">
                <div class="row justify-content-center h-100 align-items-center">
                    <div class="col-xl-5 col-md-6" style="border: 1px solid #; margin-top: 30px !important">
                        
                    <div class="mini-logo text-center my-5">
                    <div class="small-logo"><img src="../Account/Signin/assets/img/small-logo.png" height="30" width="30" alt=""></div>                               
                     <div  class="logo-title"><span style="font-weight: bold; font-family: 'Trebuchet MS', sans-serif; color: #007bff">ALPHA <span style="color: orange">CHEQUERS<span style="color: #fff">™</span></span></span></div>
                     </div>
                   <br/>





                        <div class="auth-form card">
                            <div class="card-header justify-content-center">
                                <h4 class="card-title">Reset password</h4>
                            </div>
                                                        
                            

                            <?php 
				     if($_GET['success']){
						 
						 if($_GET['success'] == 'emailSent'){
							 ?>
						<p class='alertme' style='color: green; text-align: center !important'>
						A password reset link was sent to your email!
                         </p>
						<br/>
						<?php
							 
						 }
						 
					 }
				  
				  
			 
				    if(isset($_GET['error'])){
				  
				    if($_GET['error'] == 'emailNotSent'){
						?>
						<p class='alertme' style='color: red; text-align: center !important'>
						Error occured, password reset link not sent!
                    </p>
						<br/>
						<?php						
					}else if($_GET['error'] == 'emailNotFound'){
						?>
						<p class='alertme' style='color: red; text-align: center !important'>
						Email is not found in the database!
                    </p>
						<br/>
						<?php
					} }
                    ?>
                            
                            
                            
                            
                            
                            <div class="card-body">
                                <form action="" method="post">
                                    <div class="form-group">
                                        <label>Email</label>
                                        <input type="email" name="email" class="form-control"placeholder="Enter your email">
                                        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
                                    </div>
                                    <div class="text-center">
                                        <button name="password-reset-token" type="submit" class="btn btn-success btn-block" style="background: #007bff !important; border: 2px solid #007bff; width: 160px !important">Reset</button>
                                    </div>
                                    
                                </form>
                                <div class="new-account mt-3">
                                    <p>Don't have an account? <a class="text-primary" href="../Account/Signup/client-register.php">Sign
                                            up</a></p>
                                          	<div id="google_translate_element"></div>

<script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element'); } </script> <script type="text/javascript" src="../../../translate.google.com/translate_a/elementa0d8.js?cb=googleTranslateElementInit"></script>
                                    <script>
    function googleTranslateElementInit() {
     new google.translate.TranslateElement(
                {pageLanguage: 'en'},
                'google_translate_element'
            );
        /*
        To remove the "powered by google",
        uncomment one of the following code blocks.
        NB: This breaks Google's Attribution Requirements:
        https://developers.google.com/translate/v2/attribution#attribution-and-logos
    */

    // Native (but only works in browsers that support query selector)
    if(typeof(document.querySelector) == 'function') {
        document.querySelector('.goog-logo-link').setAttribute('style', 'display: none');
        document.querySelector('.goog-te-gadget').setAttribute('style', 'font-size: 0');
    }

    // If you have jQuery - works cross-browser - uncomment this
    jQuery('.goog-logo-link').css('display', 'none');
    jQuery('.goog-te-gadget').css('font-size', '0');
    }
    </script>
    <script src="../translate.google.com/translate_a/elementa0d8.js?cb=googleTranslateElementInit"></script>
   
                                            	
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>




    </div>





    <script src="../Account/js/global.js"></script>
    
    <script src="../Account/vendor/waves/waves.min.js"></script>
    <script src="../Account/js/scripts.js"></script>


</body> 
</html>