<?php
 session_start();

 //require('../en/php/connectdb.php');
// require_once '../en/php/class.user.php';
 

 
 $username = "";

 $msg = "";

//3. If the form is submitted or not.
//3.1 If the form is submitted
if (isset($_POST['dat']) and isset($_POST['pw'])){
//3.1.1 Assigning posted values to variables.

$username = $_POST['dat'];
$upass = $_POST['pw'];
//3.1.2 Checking the values are existing in the database or not
$conn = mysqli_connect('localhost','spcxinvs_com','spcxinvs_com','spcxinvs_com');

     $sql = "select * from admins where email = '$username' and password = '$upass'";
    $query = mysqli_query($conn, $sql);

        
        $row = mysqli_fetch_array($query, MYSQLI_ASSOC);
        
        $count = mysqli_num_rows($query);


//3.1.2 If the posted values are equal to the database values, then session will be created for the user.
if ($count == 0){
    $msg = "<div class='alert alert-danger'>
                        <button class='close' data-dismiss='alert'>&times;</button>
                          Invalid Username or Password!
                   
              </div>";
}
//3.1.3 If the login credentials doesn't match, he will be shown with an error message.
if($count == 1){
            
            
       
        $_SESSION['admin'] = $row["id"];
        header("Location: dashboard.php");
       
         
        }


   // Redirect user to index.php
        

}

//3.1.4 if the user is logged in Greets the user with message
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Admin login</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="../favicon.png" rel="icon">
  <link href="../apple-touch-icon.png" rel="apple-touch-icon">
  <link href="paymentfonts.css" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
  <link href="../assets/vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet">
    
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Poppins&display=swap');

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box
}

body {
    background-color: #1b1b1b;
    height: 100vh;
    font-family: 'Poppins', sans-serif;
}

.wrapper {
    max-width: 500px;
    border-radius: 10px;
    margin: 50px auto;
    padding: 30px 40px;
    box-shadow: 20px 20px 80px rgb(206, 206, 206)
}

.h2 {
    font-family: 'Kaushan Script', cursive;
    font-size: 3.5rem;
    font-weight: bold;
    color: #913f9e;
    font-style: italic
}

.h6 {
    font-family: 'Poppins', sans-serif
}

.input-field {
    border-radius: 5px;
    padding: 5px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border: 1px solid #913f9e;
    color: #913f9e
}

.input-field:hover {
    color: #7b4ca0;
    border: 1px solid #7b4ca0
}

input {
    border: none;
    outline: none;
    box-shadow: none;
    width: 100%;
    padding: 0px 2px;
    font-family: 'Poppins', sans-serif
}

.fa-eye-slash.btn {
    border: none;
    outline: none;
    box-shadow: none
}

a {
    text-decoration: none;
    color: #913f9e;
    font-weight: 700
}

a:hover {
    text-decoration: none;
    color: #7b4ca0
}

.option {
    position: relative;
    padding-left: 30px;
    cursor: pointer
}

.option label.text-muted {
    display: block;
    cursor: pointer
}

.option input {
    display: none
}

.checkmark {
    position: absolute;
    top: 3px;
    left: 0;
    height: 20px;
    width: 20px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    cursor: pointer
}

.option input:checked~.checkmark:after {
    display: block
}

.option .checkmark:after {
    content: "";
    width: 13px;
    height: 13px;
    display: block;
    background: #913f9e;
    position: absolute;
    top: 48%;
    left: 53%;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: 300ms ease-in-out 0s
}

.option input[type="radio"]:checked~.checkmark {
    background: #fff;
    transition: 300ms ease-in-out 0s;
    border: 1px solid #913f9e
}

.option input[type="radio"]:checked~.checkmark:after {
    transform: translate(-50%, -50%) scale(1)
}

.btn.btn-block {
    border-radius: 20px;
    background-color: #913f9e;
    color: #fff
}

.btn.btn-block:hover {
    background-color: #55268be0
}

@media(max-width: 575px) {
    .wrapper {
        margin: 10px
    }
}

@media(max-width:424px) {
    .wrapper {
        padding: 30px 10px;
        margin: 5px
    }

    .option {
        position: relative;
        padding-left: 22px
    }

    .option label.text-muted {
        font-size: 0.95rem
    }

    .checkmark {
        position: absolute;
        top: 2px
    }

    .option .checkmark:after {
        top: 50%
    }

    #forgot {
        font-size: 0.95rem
    }
} 
  </style>

</head>
    
<body>
    
    <div class="wrapper bg-white mt-5">
    <div class="h2 text-center"><img src="../asset/images/logo_1627515886.png"  class="mx-auto"></div>
    <div class="h6 text-muted text-center pt-2">Welcome Admin, Please Enter your login details</div>
    <?php  echo $msg;  ?>
    <form method="post" action="" class="pt-3">
        <div class="form-group py-2">
            <div class="input-field"> <span class="far fa-user p-2"></span> <input type="text" name="dat" placeholder="Username or Email Address" required class=""> </div>
        </div>
        <div class="form-group py-1 pb-2">
            <div class="input-field"> <span class="fas fa-lock p-2"></span> <input type="password" name="pw" placeholder="Enter your Password" required class="" id="myInput"> <button type="button" class="btn bg-white text-muted" onclick="myFunction()"> <span id="myicon" class="far fa-eye-slash"></span> </button> </div>
        </div>
        <div class="d-flex align-items-start">
            <div class="remember"> <!--<label class="option text-muted"> Remember me <input type="radio" name="radio"> <span class="checkmark"></span> </label>--> <a href="../../index.html"><i class="fa fa-home"></i> Go To Home</a></div>
            
        </div> <button class="btn btn-block text-center my-3">Log in</button>
        
    </form>
</div>
    
    
    

    
    
   
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
<script>
    function myFunction() {
  var x = document.getElementById("myInput");
  var y = document.getElementById("myicon");
  if (x.type === "password") {
    x.type = "text";
    y.className = "far fa-eye-slash";
    
  } else {
    x.type = "password";
    y.className = "far fa-eye";
  }
}
</script>


</body>
    
</html>