<!doctype html>
<html lang="en">
<?php require('db.php');
include('inc/logo.php');
?>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!-- Required meta tags -->
    
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title><?php echo $_SERVER['SERVER_NAME']; ?> | Forgot Password</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
    <link href="assets/vendor/fonts/circular-std/style.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/libs/css/style.css">
    <link rel="stylesheet" href="assets/vendor/fonts/fontawesome/css/fontawesome-all.css">
    <link href="sitelogo/favicon.png" rel="icon" />
    <style>
    html,
    body {
        height: 100%;
    }

    body {
        display: -ms-flexbox;
        display: flex;
        -ms-flex-align: center;
        align-items: center;
        padding-top: 40px;
        padding-bottom: 40px;
    }
    </style>
</head>

<body>
    <!-- ============================================================== -->
    <!-- login page  -->
    <!-- ============================================================== -->
    <div class="splash-container">
        <div class="card ">
            <div class="card-header text-center"><a href="index.php"><?php logo2($sitelogo); ?></a>
            
       <h3>Forgot Password?</h3>     
       <span class="splash-description">Don't worry, we'll send you an email to recover your password.</span>
    
  <?php
		
$errorMessage = '';

$request_dir = $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);

$qrysite = mysqli_query($conn,"SELECT * FROM settings");
$sql_logo = mysqli_fetch_array($qrysite);
$ademail = $sql_logo['email'];
$mobile = $sql_logo['mobile'];
$sitename = $sql_logo['sitename'];
			  
					  
if(isset($_POST["reset"]) ) {	
	
	$para = $_POST['resetpass'];

$parar = mysqli_real_escape_string($conn, $_POST['resetpass']);
$para = filter_var($parar, FILTER_SANITIZE_STRING);

$para = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',  '//', 'drop', 'update', 'delete', 'insert', 'add', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $para);


	
	$qry = mysqli_query($conn,"SELECT * FROM users WHERE email='$para' OR phone='$para' ");
	
	$data = mysqli_fetch_array($qry);
	
	$mypass = $data['pass'];
	$myName = $data['firstname'];
	$myem = $data['email'];
        $accno = $data['accno'];

$mt = mt_rand(108366,41062832237);
$uid = mt_rand(10836765,398166660123);
	
	
	$comb = array($data['email'],$data['phone']);
	
	if(in_array($para, $comb)){
		
$updat = mysqli_query($conn,"UPDATE users SET otp='$mt',acc='$uid' WHERE email ='$myem' ") or die(mysqli_error()); 



$from = "".$sitename."<no-reply@".$_SERVER['SERVER_NAME'].">"; //the email address from which this is sent
$to = $myem; //the email address you're sending the message to
$subject = "Password Reset Request"; //the subject of the message

// To send HTML mail, the Content-type header must be set
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Priority: 1\r\n";
 
// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    
$body = "<html><body>

<a href='http://".$_SERVER['SERVER_NAME']."'><img src=$img></a><br>

<h3 style='color:#f40;'>Dear $myName</h3>

You Requested for Password Recovery on Your <b>".$_SERVER['SERVER_NAME']."</b> Account.<br> <br>
'


Use the link below to reset your password <br><br>

<a href='https://".$request_dir."/forgot-password/?refid=".$uid."'><button class='button'>Click Here to Reset Your Password!</button></a> <br>



If You Didn't Make This Request kindly ignore the link and contact: <br>

 E-mail: support@".$_SERVER['SERVER_NAME']." or <br>

Call: <b>$mobile</b><p>

Support Team<br>

<b>".$_SERVER['SERVER_NAME']."</b><br>
<a href='https://".$_SERVER['SERVER_NAME']."'>www.".$_SERVER['SERVER_NAME']."</a> <p>

</body><html>";


//now mail

$send = mail($to,$subject,$body,$headers);

$successMessage = "We have emailed your password ";
			
echo '<div  class="alert alert-success col-sm-12">'.$successMessage.'</div>';	
			
			
	
		
		}else{
			
			$errorMessage = "Account doesn't exist";
			
			echo '<div  class="alert alert-danger col-sm-12">'.$errorMessage.'</div>';
			
			}
		
}

?>  
    
        

                <form method="post" action="">
                    <div class="form-group">
                        <input class="form-control form-control-lg" name="resetpass" id="resetpass" type="text" placeholder="Enter Email or Phone Number " autocomplete="off" value="" required>
                    </div>
                  
                   
                   
                    <button type="submit"  name="reset" class="btn btn-primary btn-lg btn-block">Recover Password</button>
                </form>
                
                
            </div>
           
       <a href="register.php" class="btn btn-primary btn-lg btn-block">Don't have an account? SignUp!</a><br>
        <a href="index.php" class="btn btn-primary btn-lg btn-block">Already Registered? Login Here!</a>
              
            </div>
        </div>
    </div>
  
    <!-- ============================================================== -->
    <!-- end login page  -->
    <!-- ============================================================== -->
    <!-- Optional JavaScript -->
    <script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.js"></script>
</body>
 
</html>