<?php
session_start();
include 'include/config.php';
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Admin Dashboard</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description" />
        <meta content="Coderthemes" name="author" />
        <!-- App favicon -->
        <link rel="shortcut icon" href="assets/images/favicon.ico">

        <!-- App css -->
        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" id="app-style"/>
        <?php 
        // include "training.php"; 
        
        ?>
    </head>

    <body class="loading authentication-bg" data-layout-config='{"darkMode":false}'>

        <div class="account-pages pt-2 pt-sm-5 pb-2 pb-sm-5">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-xxl-4 col-lg-5">
                        <div class="card">
                            <!-- Logo-->
                            <div class="card-header pt-4 pb-4 text-center bg-primary">
                                <a href="index.php">
                                    <span class="text-white"><h3 class="m-0">Admin Login</h3></span>
                                </a>
                            </div>

                            <div class="card-body p-4">
                                <?php
                                 if(isset($_POST['login'])){
                                    $user = $_POST['user'];
                                    $pass = $_POST['pass'];
                                    
                                    $sql = "SELECT * FROM admin WHERE user = '$user' && pass = '$pass' ";
                                    $res = mysqli_query($conn, $sql);
                                    $row = mysqli_fetch_assoc($res);
                                    if(mysqli_num_rows($res) > 0){

                                        $_SESSION['id'] = $row['id'];
                                        echo "<script> window.location.href = 'dashboard.php' </script>";

                                    }else{
                                        echo "<h6 class='text-danger' >Your Login Details Not Right..</h6>";
                                    }
                                }
                                ?>
                              
                                <form action="" method="POST" >

                                    <div class="mb-3">
                                        <label for="fullname" class="form-label">Username</label>
                                        <input class="form-control" name="user" type="text" id="fullname" placeholder="Enter your name" required>
                                    </div>

                                    <div class="mb-3">
                                        <label for="password" class="form-label">Password</label>
                                        <div class="input-group input-group-merge">
                                            <input type="password" name="pass" id="password" class="form-control" placeholder="Enter your password">
                                            <div class="input-group-text" data-password="false">
                                                <span class="password-eye"></span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="mb-3 text-center">
                                        <button class="btn btn-primary" name="login" type="submit"> Login </button>
                                    </div>

                                </form>
                            </div> <!-- end card-body -->
                        </div>
                        <!-- end card -->
                            
                        <!-- <div class="row mt-3">
                            <div class="col-12 text-center">
                                <p class="text-muted">Already have account? <a href="pages-login.php" class="text-muted ms-1"><b>Log In</b></a></p>
                            </div> 
                        </div> -->
                        <!-- end row -->

                    </div> <!-- end col -->
                </div>
                <!-- end row -->
            </div>
            <!-- end container -->
        </div>
        <!-- end page -->

        <footer class="footer footer-alt">
            2023 © Admin
        </footer>

        <!-- bundle -->
        <script src="assets/js/vendor.min.js"></script>
        <script src="assets/js/app.min.js"></script>
        
    </body>
</html>