<?php
session_start();
require '../config/database.php';
require 'model/model.php';

if (isset($_REQUEST['logout']) && $_REQUEST['logout'] == 'true') {    
    if (isset($_SESSION)) {
        session_destroy();
        header('location:index.php');
        exit;
    }
}

if (isset($_SESSION['admin_id'])) {
    echo "<script>window.location='dashboard.php'</script>";
    exit;
}

if (isset($_POST['signinbtn'])) {  

	$email = $_POST['email'];
	$password = $_POST['password'];

	$login_data = login($email,$password);
}

$message= '';
if(isset($_REQUEST['login']) && $_REQUEST['login']=='fail'){
    $message = "<span style='color:red;'>You have entered wrong password</span>"; 
}
if(isset($_REQUEST['login']) && $_REQUEST['login']=='failed'){
    $message = "<span style='color:red;'>You have entered wrong email or password</span>"; 
}

?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>Operators Licence Database Portal</title>
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<meta name="author" content=""/>
		
		<!-- Favicon -->
		<link rel="shortcut icon" href="favicon.ico">
		<link rel="icon" href="favicon.ico" type="image/x-icon">
		
		<!-- vector map CSS -->
		<link href="../vendors/bower_components/jasny-bootstrap/dist/css/jasny-bootstrap.min.css" rel="stylesheet" type="text/css"/>
		
		<!-- Custom CSS -->
		<link href="dist/css/style.css" rel="stylesheet" type="text/css">
	</head>
	<body>
		<!--Preloader-->
		<div class="preloader-it">
			<div class="la-anim-1"></div>
		</div>
		<!--/Preloader-->
		
		<div class="wrapper pa-0">
			<header class="sp-header">
				<div class="sp-logo-wrap pull-left">
					<a href="index.php">
						<!-- <img class="brand-img mr-10" src="../img/logo.png" alt="brand"/> -->
						<span class="brand-text">Operators Licence Database Portal</span>
					</a>
				</div>
				<!-- <div class="form-group mb-0 pull-right">
					<span class="inline-block pr-10">Don't have an account?</span>
					<a class="inline-block btn btn-primary  btn-rounded btn-outline" href="signup.php">Sign Up</a>
				</div> -->
				<div class="clearfix"></div>
			</header>
			
			<!-- Main Content -->
			<div class="page-wrapper pa-0 ma-0 auth-page">
				<div class="container-fluid">
					<!-- Row -->
					<div class="table-struct full-width full-height">
						<div class="table-cell vertical-align-middle auth-form-wrap">
							<div class="auth-form  ml-auto mr-auto no-float">
								<div class="row">
									<div class="col-sm-12 col-xs-12">
										<div class="mb-30">
											<h4 class="text-center txt-dark mb-10">Sign in to Operators Licence Database Portal</h4>
											<h6 class="text-center nonecase-font txt-grey">Enter your details below</h6>
										</div>
										<?php echo $message;?>	
										<div class="form-wrap">
											<form action="" method="post" name="signin" id="signin" enctype="multipart/form-data">
												<div class="form-group">
													<label class="control-label mb-10" for="exampleInputEmail_2">Email address</label>
													<input type="email" name="email" class="form-control" required="" id="email" placeholder="Enter email">
												</div>
												<div class="form-group">
													<label class="pull-left control-label mb-10" for="exampleInputpwd_2">Password</label>
<!--													<a class="capitalize-font txt-primary block mb-10 pull-right font-12" href="forgot-password.html">forgot password ?</a>-->
													<div class="clearfix"></div>
													<input type="password" class="form-control" required="" id="password" name="password" placeholder="Enter pwd">
												</div>
												
<!--												<div class="form-group">-->
<!--													<div class="checkbox checkbox-primary pr-10 pull-left">-->
<!--														<input id="checkbox_2" type="checkbox">-->
<!--														<label for="checkbox_2"> Keep me logged in</label>-->
<!--													</div>-->
<!--													<div class="clearfix"></div>-->
<!--												</div>-->
												<div class="form-group text-center">
													<input type="submit" value="Sign in" name="signinbtn" id="signinbtn" class="btn btn-primary btn-rounded">
												</div>
											</form>
										</div>
									</div>	
								</div>
							</div>
						</div>
					</div>
					<!-- /Row -->	
				</div>
				
			</div>
			<!-- /Main Content -->
		
		</div>
		<!-- /#wrapper -->
		
		<!-- JavaScript -->
		
		<!-- jQuery -->
		<script src="../vendors/bower_components/jquery/dist/jquery.min.js"></script>
		
		<!-- Bootstrap Core JavaScript -->
		<script src="../vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="../vendors/bower_components/jasny-bootstrap/dist/js/jasny-bootstrap.min.js"></script>
		
		<!-- Slimscroll JavaScript -->
		<script src="dist/js/jquery.slimscroll.js"></script>
		
		<!-- Init JavaScript -->
		<script src="dist/js/init.js"></script>
	</body>
</html>
