<?php
    include_once "includes/init.php"; 
    include 'includes/connection.php';
    $msg = "";

    // if (isset($_GET['verification'])) {
    //     if (mysqli_num_rows(mysqli_query($conn, "SELECT * FROM student_soes WHERE code='{$_GET['verification']}'")) > 0) {
    //         $query = mysqli_query($conn, "UPDATE student_soes SET code='' WHERE code='{$_GET['verification']}'");
            
    //         if ($query) {
    //             $msg = "<div class='alert alert-success'>Account verification has been successfully completed.</div>";
    //         }
    //     } else {
    //         header("Location: index.php");
    //     }
    // } 
    if (isset($_POST['log'])) {
        $email = mysqli_real_escape_string($conn, $_POST['username']);
        $password = mysqli_real_escape_string($conn, md5($_POST['PasswordHash'])); 
        $sql = "SELECT * FROM user_soes WHERE user_email='{$email}' AND PasswordHash='{$password}'";
        $result = mysqli_query($conn, $sql);

        if (mysqli_num_rows($result) === 1) {
            $row = mysqli_fetch_assoc($result);
             $_SESSION['user_email'] = $email;
              $_SESSION['user_id'] = $row['user_id'];
             $_SESSION['user_type'] = $row['user_type'];
               
            if ($row['user_status'] =="Enable") {
                $_SESSION['user_email'] = $email; 
                header("location:admin/admin.php?page=dashboad");
            } else {
                $name= $row['user_name'];
                $msg = "<div class='alert alert-info'>$name, Contuct to admistrator for verify your account and try again.</div>";
            }
        } else {
            $msg = "<div class='col-md-12'>  
                        <div class='alert alert-danger alert-dismissible'> Username and Password are incorrect Try Again
                          </div>
                      </div> ";
        }
    }
?>
<!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">ADMIN | INSTRUCTOR</h3>
        <h5 class="widget-user-desc text-right">Login</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="text" id="username" name="username" class="form-control"  required autofocus data-parsley-trigger="keyup" placeholder="Enter username...">
        
        </div>
        <div class="form-group">
        
            <input type="password" id="PasswordHash" name="PasswordHash" class="form-control"  required  data-parsley-trigger="keyup" placeholder="Password" >
          
        </div>
        <div class="row">
          <div class="col-6"> 
          </div>
          <!-- /.col -->
          <div class="col-6">
            <button type="submit" value="Login"  name="log" class="btn btn-info btn-block">Log In </button>
          </div>
          <!-- /.col -->
        </div>
      </form>  
      <hr>
        <center><span style="font-size: 18px;">&copy;</span>2025</center>
    </div>
    <!-- /.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>