<?php
ob_start();

include('include/config.php');

if(isset($_SESSION['adminuserName'])){
    session_unset();
    unset($_SESSION['adminuserName']);
//    unset($_SESSION['userEmail']);
    session_destroy();
    header("location: $admin_baseurl");
    exit;
}

?>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Login - Afsar Ebrahim : Admin Panel</title>

    <link rel="icon" type="image/png" href="<?php echo $admin_baseurl . 'images/';?>fav.png">
    <link rel="stylesheet" href="vendor/fontawesome/css/font-awesome.css" />
    <link rel="stylesheet" href="vendor/metisMenu/dist/metisMenu.css" />
    <link rel="stylesheet" href="vendor/animate.css/animate.css" />
    <link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.css" />
    <link rel="stylesheet" href="fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css" />
    <link rel="stylesheet" href="fonts/pe-icon-7-stroke/css/helper.css" />
    <link rel="stylesheet" href="styles/style.css">

    <style>
        .hpanel .panel-body {
            -webkit-box-shadow: 0 0 4px 0 rgba(0, 0, 0, .08), 0 2px 4px 0 rgba(0, 0, 0, .12);
            box-shadow: 0 0 4px 0 rgba(0, 0, 0, .08), 0 2px 4px 0 rgba(0, 0, 0, .12);
        }

        .container-login100 {
            background-image: url(images/bg-login.jpg);
            width: 100%;
            /*            min-height: 100vh;*/
            display: -webkit-box;
            display: -webkit-flex;
            display: -moz-box;
            display: -ms-flexbox;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            align-items: center;
            padding: 15px;
            background-repeat: no-repeat;
            background-size: cover;
            background-position: center;
            position: relative;
            z-index: 1;
        }

        ::placeholder {
            color: #ccc !important;
            opacity: 1;
            font-size: 12px;
        }

        :-ms-input-placeholder {
            color: #ccc !important;
            font-size: 12px;
        }

        ::-ms-input-placeholder {
            color: #ccc !important;
            font-size: 12px;
        }


        .alert-danger{
            -webkit-animation: seconds 1.0s forwards;
            -webkit-animation-iteration-count: 1;
            -webkit-animation-delay: 5s;
            animation: seconds 1.0s forwards;
            animation-iteration-count: 1;
            animation-delay: 5s;
            position: relative;

        }

        @-webkit-keyframes seconds {
            0% {
                opacity: 1;
            }

            100% {
                opacity: 0;
                left: -9999px;
                position: absolute;
            }
        }

        @keyframes seconds {
            0% {
                opacity: 1;
            }

            100% {
                opacity: 0;
                left: -9999px;
                position: absolute;
            }
        }

    </style>

</head>

<body class="blank container-login100">
    <div class="color-line"></div>
    <div class="">
        <div class="login-container">
            <div class="row">
                <div class="col-md-12">
                    <div class="text-center m-b-md">
                        <h3 style="    text-transform: uppercase;font-weight:800; font-size: 18px; color:#0A1A32">PLEASE LOGIN TO Afsar Ebrahim</h3>
                    </div>
                    <div class="hpanel">
                        <div class="panel-body" style="padding: 40px 20px;border-radius: 35px 15px;">
                            <form action="" id="loginForm" method="post">
                                <div class="form-group">
                                    <label class="control-label" for="username">Username</label>
                                    <input type="email" placeholder="admin@gmail.com" title="Please enter you username" required="" value="" name="user_name" id="user_name" class="form-control">

                                </div><br>
                                <div class="form-group">
                                    <label class="control-label" for="password">Password</label>
                                    <input type="password" title="Please enter your password" placeholder="Password please" required="" value="" name="password" id="password" class="form-control">
                                    <!--                                <span class="help-block small">Yur strong password</span>-->
                                </div>
                                <br>
                                <button type="submit" name="submit" class="btn btn-success btn-block">Login</button>
                                <!--                            <a class="btn btn-default btn-block" href="register.php">Register</a>-->
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <?php
                if(isset($_POST['submit']))
                {
                    $admin_username = filter_var($_POST['user_name'],FILTER_SANITIZE_STRING);
                    $mypassword = md5(filter_var($_POST['password'],FILTER_SANITIZE_STRING));
                    
                    
                     $sql="SELECT * FROM `user_login` WHERE `email`='$admin_username' and `password`='$mypassword' and `type` ='admin'";
//                    echo $sql; die;
                    $result = mysqli_query($conn, $sql);
                    if (mysqli_num_rows($result) > 0) {
                        while($row = mysqli_fetch_assoc($result)) {             
//                            $_SESSION['userName'] = $row["name"];
//                            $_SESSION['userEmail'] = $row["email"];       
                            $_SESSION['adminuserName'] = $row["username"]; 
                        }
                           header("Location: ".$admin_baseurl."dashboard.php");
                    }
                    else
                    {
                    ?>
            <div class="col-sm-12">
                <div style="text-align:center;" class="alert alert-danger" id="myerrordiv">
                    <i class="fa fa-ban-circle fa-lg"></i>
                    <strong>ERROR!</strong>
                    <a href="<?php echo $baseurl; ?>" class="alert-link"> You are not a right User! Or Username / Password may be Incorrect</a>
                </div>
            </div>
            <?php       
                    }                               
                }
                    
            ?>
            <div class="row">
                <div class="col-md-12 text-center" style="color:#fff">
                    Copyright <?php echo $current_year;?> - Afsar Ebrahim"
                </div>
            </div>
        </div>
    </div>

    <!-- Vendor scripts -->
    <script src="vendor/jquery/dist/jquery.min.js"></script>
    <script src="vendor/jquery-ui/jquery-ui.min.js"></script>
    <script src="vendor/slimScroll/jquery.slimscroll.min.js"></script>
    <script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="vendor/metisMenu/dist/metisMenu.min.js"></script>
    <script src="vendor/iCheck/icheck.min.js"></script>
    <script src="vendor/sparkline/index.js"></script>

    <!-- App scripts -->
    <script src="scripts/homer.js"></script>
    <script>
        var admin_home_url1 = "<?php echo $admin_baseurl . 'dashboard.php';?>";

        //        $('.alert-danger').delay(1000).hide(500);
        //        $('#myerrordiv').delay(5000).fadeOut('slow');

        //        $(document).ready(function () { 
        //            setTimeout(function() {
        //                $('#myerrordiv').slideUp("slow");
        //            }, 1000);
        //});

    </script>

</body>

</html>
