<?php

$msg = "";

include 'includes/connection.php';

if (isset($_GET['reset'])) {
    if (mysqli_num_rows(mysqli_query($conn, "SELECT * FROM student_soes WHERE code='{$_GET['reset']}'")) > 0) {
        if (isset($_POST['submit'])) {
            $password = mysqli_real_escape_string($conn, md5($_POST['password']));
            $confirm_password = mysqli_real_escape_string($conn, md5($_POST['confirm-password']));

            if ($password === $confirm_password) {
                $query = mysqli_query($conn, "UPDATE student_soes SET PasswordHash='{$password}', code='' WHERE code='{$_GET['reset']}'");

                if ($query) {
                     $msg = "<div class='alert alert-info'>Password succesfull changed.</div>";
                    header("Location:index.php");
                }
            } else {
                $msg = "<div class='alert alert-danger'>Password and Confirm Password do not match.</div>";
            }
        }
    } else {
        $msg = "<div class='alert alert-danger'>Reset Link do not match.</div>";
    }
} else {
    header("Location: reset.php");
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <link href="assets/img/icon4.png" rel="icon">
  <link href="assets/img/icon4.png" rel="apple-touch-icon">
  <title>Cybercode Africa| Cybersecurity Training and resources</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="stp_con/fontawesome-free/css/all.min.css">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="stp_con/overlayScrollbars/css/OverlayScrollbars.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="assets/css/adminlte.min.css">  
  <!-- daterange picker -->
  <link rel="stylesheet" href="stp_con/daterangepicker/daterangepicker.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="stp_con/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="stp_con/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- Tempusdominus Bootstrap 4 -->
  <link rel="stylesheet" href="stp_con/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="stp_con/select2/css/select2.min.css">
  <link rel="stylesheet" href="stp_con/select2-bootstrap4-theme/select2-bootstrap4.min.css">
  <!-- Bootstrap4 Duallistbox -->
  <link rel="stylesheet" href="stp_con/bootstrap4-duallistbox/bootstrap-duallistbox.min.css">
  <!-- BS Stepper -->
  <link rel="stylesheet" href="stp_con/bs-stepper/css/bs-stepper.min.css">
  <!-- dropzonejs --> 
   <link href="assets/css/sb-admin-2.min.css" rel="stylesheet">
    
    <link rel="stylesheet" type="text/css" href="stp_con/parsley/parsley.css"/>
     <style>
    body {  
      background-image: url('assets/img/back.png'); /* replace with your image */
      background-size: cover;
      background-position: center;
      position: relative; 
      margin: 0px auto; 
    }
    .whatsapp-button {
      position: fixed;
      bottom: 20px;
      right: 20px; 
      color: white;
      border: none;
      border-radius: 50px;
      padding: 12px 24px;
      font-size: 16px;
      font-weight: bold;
      cursor: pointer;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
      z-index: 999;
    }
</style>
</head>
<body class="hold-transition login-page">

<div class="login-box">

  <!-- /.login-logo -->
 <div class="container-fluid">
  <div class="row">

    <div class="col-md-12">
    <!-- Widget: user widget style 1 -->
    <div class="card card-widget widget-user card-info card-outline">
      <!-- Add the bg color to the header using any of the bg-* classes -->
     <div class="widget-user-header text-white"
           style="background: url('assets/img/cyber1.jpg') center center;size: 20%">
        <h3 class="widget-user-username text-right">USER</h3>
        <h5 class="widget-user-desc text-right">Change Password</h5>
      </div> 
      <div class="widget-user-image">
        <img class="img-circle" src="assets/img/icon.png" alt="User Avatar">
     </div> 

    <div class="card-body"> 
      <br>
    <center><p><strong style="color: #2182f9;">CYBERCODE</strong><br>Securing The Digital Future</p></center> 
     <?php echo $msg; ?>
      <form action="" method="post" id="login_form"> 
        <div class="form-group">
					        
            <input type="password" id="password" name="password" class="form-control"  required  data-parsley-trigger="keyup" placeholder="Password..." >
            
            </div>
            <div class="form-group"> 
            <input  type="password" name="confirm-password"  class="form-control"  required autofocus data-parsley-type="password" data-parsley-trigger="keyup" placeholder="Enter Your Confirm Password">
            
            </div> 
        <div class="row">
          <div class="col-4">  
          </div>
          <!-- /.col -->
          <div class="col-8"> 
            <button type="submit" value="submit"  name="submit" class="btn btn-info btn-block">Change Password </button>
          </div> 
          <!-- /.col -->
        </div>
      </form>  
      <hr>
        <center><p class="mb-0 text-muted">Back to! <a href="index.php" class="f-w-400">Sign In</a></p>
    </div>
    <button class="whatsapp-button btn-info" onclick="contactViaWhatsApp()">Contact Us</button>
    <!-- /.card-body -->
  </div>
</div>
</div>
</div>

  <!-- /.card -->
</div>
<hr> 
<!-- /.login-box -->


<!-- jQuery -->
<script src="stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
 <script src="assets/js/sb-admin-2.min.js"></script> 
<script type="text/javascript" src="stp_con/parsley/dist/parsley.min.js"></script>
<script src="assets/js/adminlte.min.js"></script>
</body>
</html>
<script>

$(document).ready(function(){

    $('#login_form').parsley();
 
});

</script>
 

<script>
  function contactViaWhatsApp() {
    // Replace with your actual WhatsApp number, format: 255xxxxxxxxx (no + or 0)
    const phoneNumber = '255757660790';
    const message = 'Hello, I would like to contact you!';
    const url = `https://api.whatsapp.com/send/?phone=${phoneNumber}&text=Hello%2C+I+would+like+to+contact+you%21&type=phone_number&app_absent=0`;
    window.open(url, '_blank');
  }
</script>
