<?php include('include/server.php');?>
<?php include('header.php');?>

<?php


$reset_token = mysqli_real_escape_string($db, $_REQUEST['r']);
    $exist_reset_token = mysqli_num_rows(mysqli_query($db,"SELECT * FROM user WHERE reset='$reset_token'"));
    
    $user_info = mysqli_fetch_array(mysqli_query($db,"SELECT reset, email, accountnumber, firstname, lastname FROM user WHERE reset='$reset_token'"));

if (!isset($_REQUEST['r'])){
$exist_reset_token = mysqli_num_rows(mysqli_query($db,"SELECT * FROM user WHERE reset='$reset_token'"));    	
if($exist_reset_token == 0){$err1=1;} 
}

if  (isset($_POST['reset_password_button'])) {
    $newreset=md5(uniqid()); 
    $password=mysqli_real_escape_string($db, $_POST['password']);
    $cpassword=mysqli_real_escape_string($db, $_POST['cpassword']);
    	
    	
if($exist_reset_token == 0){$err1=1;}
if ($password!=$cpassword){$err2=1;}    
if(trim($password)==""){$err3=1;}

if(strlen($password)<=3){$err4=1;}

$error = $err1+$err2+$err3+$err4;


if ($error == 0){
   $update_password = mysqli_query($db, "UPDATE user SET reset='$newreset', password ='$password' WHERE accountnumber='$user_info[2]'");
            if ($update_password){
  
    
     //now send this email to client for password reset
  $to = $user_info[1];
    
$subject = 'Password Successfully Updated';

$from = $site_email;
 
// Setting html content type for email sending
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    
     $emailmsg = ' <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta name="x-apple-disable-message-reformatting">
  <title></title>
  <!--[if mso]>
  <style>
    table {border-collapse:collapse;border-spacing:0;border:none;margin:0;}
    div, td {padding:0;}
    div {margin:0 !important;}
  </style>
  <noscript>
    <xml>
      <o:OfficeDocumentSettings>
        <o:PixelsPerInch>96</o:PixelsPerInch>
      </o:OfficeDocumentSettings>
    </xml>
  </noscript>
  <![endif]-->
  <style>
    table, td, div, h1, p {
      font-family: Arial, sans-serif;
    }
    @media screen and (max-width: 530px) {
      .unsub {
        display: block;
        padding: 8px;
        margin-top: 14px;
        border-radius: 6px;
        background-color: #555555;
        text-decoration: none !important;
        font-weight: bold;
      }
      .col-lge {
        max-width: 100% !important;
      }
    }
    @media screen and (min-width: 531px) {
      .col-sml {
        max-width: 27% !important;
      }
      .col-lge {
        max-width: 73% !important;
      }
    }
    
    
    
   


  </style>
</head>

<body style="margin:0;padding:0;word-spacing:normal;background-color:#939297;">
  <div role="article" aria-roledescription="email" lang="en" style="text-size-adjust:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;background-color:#939297;">
    <table role="presentation" style="width:100%;border:none;border-spacing:0;">
      <tr>
        <td align="center" style="padding:0;">
          <!--[if mso]>
          <table role="presentation" align="center" style="width:600px;">
          <tr>
          <td>
          <![endif]-->
          <table role="presentation" style="width:94%;max-width:600px;border:none;border-spacing:0;text-align:left;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
            <tr>
              <td style="padding:40px 30px 30px 30px;text-align:center;font-size:24px;font-weight:bold;">
                <a href="'.$site_url.'" style="text-decoration:none;"><img src="'.$site_image.'" width="10" alt="Logo" style="width:10%">&nbsp;<span style="color:black;">'.$site_name.'</a>
              </td>
            </tr>



            <tr>
              <td style="padding:30px;background-color:#ffffff;">
                <h1 style="margin-top:0;margin-bottom:16px;font-size:26px;line-height:32px;font-weight:bold;letter-spacing:-0.02em;"><span style="color:#ff3884">Password Changed Successfully</span></h1>
                <h4>Dear <b>'.$user_info[3].' '.$user_info[4].'</b></h4>
                <br>
                <p>
                    Your requested password change has been effected and have been successfully changed to <b>'.$password.'</b>.</p>
                
                <br> 
                
                And your account number still remains '.$user_info[2].'
                <br> 
                <br> 
                  You can now go ahead to login with your new password.
                    
                    <br>
                    <p style="margin:0;"><a href="'.$site_url.'/login.php" style="background: #ff3884; text-decoration: none; padding: 10px 25px; color: #ffffff; border-radius: 4px; display:inline-block; mso-padding-alt:0;text-underline-color:#ff3884"><!--[if mso]><i style="letter-spacing: 25px;mso-font-width:-100%;mso-text-raise:20pt">&nbsp;</i><![endif]--><span style="mso-text-raise:10pt;font-weight:bold;">Login Here</span><!--[if mso]><i style="letter-spacing: 25px;mso-font-width:-100%">&nbsp;</i><![endif]--></a></p>
            

          <p>Please you are advised to keep this email only to yourself for security of your password.</p>
              </td>
            </tr>
            <tr>
              <td style="padding:0;font-size:24px;line-height:28px;font-weight:bold;">
                <a href="#" style="text-decoration:none;"><img src="'.$site_url.'/passuccess.png" width="450" alt="" style="width:100%;height:auto;display:block;border:none;text-decoration:none;color:#363636;"></a>
              </td>
            </tr>
            <tr>
              <td style="padding:35px 30px 11px 30px;font-size:0;background-color:#ffffff;border-bottom:1px solid #f0f0f5;border-color:rgba(201,201,207,.35);">

                <div class="col-lge" style="display:inline-block;width:100%;max-width:395px;vertical-align:top;padding-bottom:20px;font-family:Arial,sans-serif;font-size:16px;line-height:22px;color:#363636;">
                  
                 
                  <br><br>
                  
                  <p>Best of luck!</p>
                  
            <h4>'.$site_name.' Team</h4>
            </div>
                </div>
                
                

              </td>
            </tr>
            
        <br>

<tr>
              <td style="padding:30px;text-align:center;font-size:12px;background-color:#404040;color:#cccccc;">
                <p style="margin:0 0 8px 0;"><a href="http://www.facebook.com/" style="text-decoration:none;"><img src="https://assets.codepen.io/210284/facebook_1.png" width="40" height="40" alt="f" style="display:inline-block;color:#cccccc;"></a> <a href="http://www.twitter.com/" style="text-decoration:none;"><img src="https://assets.codepen.io/210284/twitter_1.png" width="40" height="40" alt="t" style="display:inline-block;color:#cccccc;"></a></p>
                <p style="margin:0;font-size:14px;line-height:20px;"><b>Legal:</b> This email message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please delete it from your computer. '.$site_name.', does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is acepted by '.$site_name.' in this regard and the recipient should carry out such virus and other checks as it considers appropriate. <br><br><a class="unsub" href="#" style="color:#cccccc;text-decoration:underline;"><b>&copy; '.$site_name.' 2022 </b></a></p>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </div>
</body>
</html>

 ';
 // Sending email
mail($to, $subject, $emailmsg, $headers);
	
            }

                $msg =  "<div class=\"alert alert-success alert-dismissable\">
        <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>Your password have been updated successfully! You can now proceed to login...</div>";
} else {
	
if ($err1 == 1){
$msg =  "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	


Sorry, But This Link Is Not Longer Valid.

</div>";
}		
if ($err2 == 1){
	$msg =  "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Your Password And Confirm Password Must Be The Same.

</div>";

}		
if ($err3 == 1){
$msg = "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Password Can Not Be Empty.

</div>";

}		
if ($err4 == 1){
	$msg =  "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Password Must Be Four Or More Characters.

</div>";
}	

	
}


}


?>


<title><?php echo $site_name; ?> - Reset Password </title>

<div class="inner-banner">
</div>
<section class="w3l-breadcrumb">
    <div class="container">
        <ul class="breadcrumbs-custom-path">
            <li><a href="index.php">Home</a></li>
            <li class="active"><span class="fa fa-arrow-right mx-2" aria-hidden="true"></span>Reset Password</li>
        </ul>
    </div>
</section>
<br>

<div class="w3l-contact-info py-5" id="contact">
    <div class="container py-lg-5 py-md-4">
        <div class="title text-center">
            <h3 class="title-big" style="opacity:70%">Create New Password</h3>
            
        </div>
        <div class="row">
            <div class="col-lg-6">
            </div>
            
        </div>
        
        <br><br>
        <div class="container">
            <div class="col-lg-6 form-inner-cont mt-lg-0 mt-sm-5 mt-4">
                <form action="" method="post" class="signin-form">
                     <?php echo $msg ; ?>
                    <div class="form-input">
                        <input type="password" name="password" id="w3lSender" placeholder="Enter New Password"
                            required="">
                    </div>
                    
                    <div class="form-input">
                        <input type="password" name="cpassword" id="w3lSender" placeholder=" Confirm Password"
                            required="">
                    </div>

                    
                    <div class="text-right">
                        <button type="submit" name="reset_password_button" class="btn btn-style btn-primary">Submit</button>
                        <br>
                    
                    </div>
                    <br>
                    <h4 style="float:left;color:blue;"><a style="text-decoration:none" href="login.php">Login Here</a></h4>
                </form>
            </div>
        </div>
    </div>
</div>




<?php include('footer.php');?>