<?php
// Enable error reporting and display errors on the screen
error_reporting(E_ALL);
ini_set('display_errors', 1);

include("./include/config.php");

if (isset($_SESSION['a_user'])) {
    header("Location:dashboard.php");
}else {

?>


<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">

	<link rel="stylesheet" href="assets/styles/style.min.css">
	
	<title>Log in </title>

	<link rel="shortcut icon" type="image/x-icon" href="assets/images/logo1.png">


	<!-- Waves Effect -->
	<link rel="stylesheet" href="assets/plugin/waves/waves.min.css">

	<!-- Sweet Alert -->
	<link rel="stylesheet" href="assets/plugin/sweet-alert/sweetalert.css">

</head>

<style>
    .fixed-navbar {
           background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important
    }
      .header .logo {
           background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important
    }
    .menu-mobile-button{
                   background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important
    }
    .btn-primary {
             background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important
    }
        .btn-primary:hover {
             background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important;
    }
    @media (min-width: 800px) {
.menu-active .header .logo:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 75px;
    height: 50px;
    background: linear-gradient(181deg, #6e89ff, #304087, #12193c) !important;
    z-index: -2;
}
    
}
</style>
<body>



	<div id="single-wrapper">
		<form class="frm-single" action="" method="POST">
			<div class="inside">
			    <center>
			        <!--<img src="./images/logo.png" width="200px">-->
			    </center><br>
				<div class="title"><strong>Admin </strong></div>
				<!-- /.title -->
				<!-- /.frm-title -->
				<div class="frm-input"><input type="text" placeholder="Username" name="uname" class="frm-inp"
						required><i class="fa fa-user frm-ico"></i></div>
				<!-- /.frm-input -->
				<div class="frm-input"><input type="password" placeholder="Password" name="pwd" class="frm-inp"
						required><i class="fa fa-lock frm-ico"></i></div>
			
				<button type="submit" name="login" class="frm-submit btn-primary">Login<i
						class="fa fa-arrow-circle-right"></i></button>

				<div class="row small-spacing">
					<div class="col-sm-12">
						<!-- <div class="txt-login-with txt-center">or login with</div> -->
						<!-- /.txt-login-with -->
				
					</div>
					<!-- /.col-sm-12 -->
					<!-- <div class="col-sm-6"><button type="button" class="btn btn-sm btn-icon btn-icon-left btn-social-with-text btn-facebook text-white waves-effect waves-light"><i class="ico fa fa-facebook"></i><span>Facebook</span></button></div> -->
					<!-- /.col-sm-6 -->
					<!-- <div class="col-sm-6"><button type="button" class="btn btn-sm btn-icon btn-icon-left btn-social-with-text btn-google-plus text-white waves-effect waves-light"><i class="ico fa fa-google-plus"></i>Google+</button></div> -->
					<!-- /.col-sm-6 -->
				</div>
				<!-- /.row -->
				<!-- <a href="../staff/index.php" class="a-link"><i class="fa fa-key"></i>I am Staff</a> -->
			<!-- <div class="frm-footer">NinjaAdmin © 2016.</div> --> 
				<!-- /.footer -->
			</div>
			<!-- .inside -->
			
		</form>
		<!-- /.frm-single -->
	</div><!--/#single-wrapper -->
	<?php
	if (isset($_POST['login'])) {



		$userName = mysqli_real_escape_string($conn, $_POST['uname']);
		$userPassword = mysqli_real_escape_string($conn, $_POST['pwd']);
  
     
            $sql_a = "SELECT * FROM `admin_login` WHERE `al_pwd` = '$userPassword' AND `al_username` = '$userName'";
            $result_a = mysqli_query($conn, $sql_a) or die("Query Failed.");

            if (mysqli_num_rows($result_a) > 0) {
                while ($row = mysqli_fetch_assoc($result_a)) {
                    $_SESSION["a_id"] = $row['al_id'];
                    $_SESSION["a_user"] = $row['al_username'];
                    $_SESSION["a_name"] = $row['al_name'];
                    header("Location: dashboard.php");
                    exit;
                }
            } else {
                echo '<script>alert("Invalid Username or Password")</script>';
            }
     
	}
	?>
	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
		<script src="assets/script/html5shiv.min.js"></>
		<script src="assets/script/respond.min.js"></script>
	<![endif]-->
	<!-- 
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="assets/scripts/jquery.min.js"></script>
	<script src="assets/scripts/modernizr.min.js"></script>
	<script src="assets/plugin/bootstrap/js/bootstrap.min.js"></script>
	<script src="assets/plugin/nprogress/nprogress.js"></script>
	<script src="assets/plugin/waves/waves.min.js"></script>
	<script src="assets/plugin/sweet-alert/sweetalert.min.js"></script>

	<script src="assets/scripts/main.min.js"></script>
</body>

</html>

<?php

}

?>