<?php
include "include/config.php";
?>
<?php include "loader.php"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Forgot Password </title>
    <link rel="stylesheet" href="res/bootstrap@5.2.0.min.css">
    <link rel="stylesheet" href="res/chartist.min.css">
    <link rel="stylesheet" href="@css/style.css">
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Nunito&family=Nunito+Sans&display=swap" rel="stylesheet">




<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" 
href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css"></style>
<script type="text/javascript" 
src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>

    <style>
      body{
      height: 100vh;
      padding: 10px;
      background: white;
      font-family: 'Roboto', sans-serif;
    }
      .form-control{
        border: none;
        border-bottom: 1px solid gray;
        border-radius:0px;
        height: 46px;
        margin-top: 10px;
        outline: none;
      }
      .form-control:hover{
         box-shadow: none;
         
         border: none;
        border-bottom: 1px solid #54B68F;
        border-radius:0px;
        outline: none;
      }
      form{
        width: 310px;
      }
      .card{
        border-radius:4px;
        border: none;
        width 340px;
    background: white;
        padding: 10px;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        color: white;
      }
      .btn{
        background:#54B68F;
        width: 100%;
        height: 52px;
        margin-top: 10px;
        color: white;
      }
      .btn:hover{
        background:#54B68F;
      }
      .fp a{
        padding: 10px;
        margin-top: 10px;
        color: #FFFAF6BA;
      }
      .fp{
        margin-top: 15px;
        margin-bottom: 10px;
      }
      .db{
        margin-top:500px;
      }
      .db p{
        margin-bottom: -3px;
        font-size: 12px;
        text-align: center;
      }
      .db span{
        font-weight: bold;
      }
      h1{
        background: white;
        padding: 4px;
        border-radius:6px;
        width: 130px;
      }
      @media only screen and (max-width:500px){
        .db {
          margin-top:550px;
          
        }
      }
    </style>
</head>
<body   style="background:;">
  
<div class="content">
    <br> <br> <br>
       <?php

if (isset($_GET['error'])) {?>
<div class="alert alert-success" style="text-align:center;">
<p><i class="fa fa-check-circle">  </i> <?php echo $_GET['error'];?></p>
</div>
<?php
}
?>

       <?php

if (isset($_GET['errorp'])) {?>
<div class="alert alert-danger" style="text-align:center;">
<p><i class="fa fa-check-warning">  </i> <?php echo $_GET['errorp'];?></p>
</div>
<?php
}
?>
<div class="flex">
  <div class="card">
  <center>

     <img class="ic" src="logo1.png" alt="" width="100px" height=""> 
         <h3 style="color: #54B68F; margin-top:-10px;"><b>Password Reset</b></h3>
</center>

    <form action="password_reset.php" method="POST">
      <input required type="email" name="email" id="" placeholder="Enter your Email" class="form-control">
     <button type="submit" class="btn btn" name="send">Continue <i class='fa fa-arrow-right'></i> </button>      
   
    
    <div class="fp">
      <a style="color:#54B68F;"href="index.php">I know my password- Login</a>
    </div>

    </form>
  </div>

        
</div>

<?php


require __DIR__ . '/email/class.phpmailer.php';
require __DIR__ . '/email/class.smtp.php';



if (isset($_POST['send'])) {
    
    $msubject = "Password Checked successfully";
    $email = $_POST['email'];


    $mail = new PHPMailer();


    $mail->SMTPDebug = 0;

    try {
        
$mail->isSMTP();
$mail->Host       = 'ufez.online';
$mail->SMTPAuth   = true;
$mail->Username   = 'contact@ufez.online';
$mail->Password   = '@Mypass==locked'; 
$mail->SMTPSecure = 'tls'; 
$mail->Port       = 587;
        
        $mail->setFrom('contact@ufez.online', 'UFEZ-Password Reset');


        $query  = "SELECT  *FROM ufez_members where email='$email'";
        $result = mysqli_query($conn, $query);

        if ($result) {
            while ($row = mysqli_fetch_assoc($result)) {
                $to = $row['email'];
                $tr = $row['organazation'];
                $pass ="Hello " .$tr. " your UFEZ password is " .$row['pass']. " You can change the password after login";
                $mail->addAddress($to);
            }
            mysqli_free_result($result);
        }


        $mail->isHTML(true);
        $mail->Subject = $msubject;
        $mail->Body    = $pass;


        if ($mail->send()) {
            echo "<center style='color:#54B68F;'>We have sent an email containing your login password  to  $email</center>    ";
        } else {
            echo "<center style='color:red;'> Sorry no Organazation is attached to $email  </center>";
        }
    } catch (Exception $e) {
        echo "Failed to send email. Error: " . $e->getMessage();
    }
}
?>



 <br><br>
  </center>

</div>
<script>

function capital() {
    var x=document.getElementById("uper");
    x.value= x.value.toUpperCase();
}
  
  function shownav(){
    document.getElementById("sidebar").classList.toggle("active");
    shownav();
  }
 
$(document).ready(function(){
    $('#myTable').dataTable();
});
</script>
 <br>
</body>
</html>
