<?php
session_start();
require 'Database.php';
$database = new Database;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['btnnav'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);

    // Query admin table
    $database->query('SELECT * FROM admin WHERE username = :username AND password = :password');
    $database->bind(':username', $username);
    $database->bind(':password', $password);
    $rows = $database->resultset(); // fetch all rows

    if ($rows && count($rows) > 0) {
        $row = $rows[0];
        $_SESSION['username'] = $row['username'];
        $_SESSION['user_data'] = [
            "id" => $row['id'],
            "username" => $row['username'],
            "email" => $row['email']
        ];
        header('Location: dashboard/admin.php');
        exit;
    } else {
        $error = "Invalid login";
    }
}
?>

<!DOCTYPE HTML>
<html>
	
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
		<meta name="theme-color" content="#333333" />
		<title>Fast Delivery: Admin Login</title>
		<script src="../ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="description" content="Fast Courier Delivery"/>
		<meta name="keywords" content="Fast Courier Delivery" />
		<meta name="author" content="Fast Courier Delivery" />
		<meta property="og:url"           content="fastcourierdelivery.com" />
		<meta property="og:type"          content="Fast Courier Delivery" />
		<meta property="og:title"         content="Fast Courier Delivery" />
		<meta property="og:description"   content="Fast Courier Delivery" />
		<meta name="theme-color" content="#00001a" />
	<!-- Favicon -->
		<link rel="shortcut icon" href="logo.png"/>
		<!--web-fonts-->
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css' />
		<!--web-fonts-->
		<!-- Favicon -->
		<!--<link rel="shortcut icon" href="favicon.ico"/>-->
	</head>

	<style type="text/css">
	@media(min-width : 768px) {
		.input-group-addon {
			position: relative;
			left: 36%;
			top: -3px;
		}
	}

		.input-group-addon {
			position: relative;
			top: -5px;
		}
	</style>
	<script>
		$(document).ready(function () {
			$('input[type="submit"]').click(function () {
				var em, ps;
				em = $('#em').val();
				ps = $('#ps').val();
				if(ps != "" && em != "") {
					$(this).hide();
					$('#go').html("<br /><br /><br /><center><img src='img/loading.gif' height='30px'/></center>");
				}
			});
			
			$('#ps').on('keypress keydown blur focus', function () {
				//Check if text is field
				if($(this).val() != "") {
					$('#passwordfa').removeClass('fa-lock').addClass('fa-eye');
				}
				else {
					$('#passwordfa').removeClass('fa-eye').addClass('fa-lock');
				}
			});
			
			$('#passwordfa').mousedown(function () {
				$('#ps').attr('type','text');
			});
			$('#passwordfa').mouseup(function () {
				$('#ps').attr('type','password');
			});
		});
	</script>
		
	<body>
	<div class="pull-right"><a href="index.html"><img style="position: absolute; left: 10px; top:10px; height: 50px;" src="logo.png" /></a></div>
	<!--header-->
		<div class="header-w3l">
			<br /><br /><h1><b>Admin Login</a></h1>
		</div>
	<!--//header-->
	<!--main-->
	<div class="main-content-agile">
		<div class="sub-main-w3">	
			<form action="#" method="post">
				<div class="form-group input-group">
					<span class="input-group-addon" style="background-color: white;"><i style="color: black;" class="fa fa-user"></i></span>
					<input placeholder="Your login username" id="em" name="username" value="" class="user" type="text" required="">
				</div>
				<div class="form-group input-group">
					<span class="input-group-addon" style="background-color: white;"><i style="color: black; cursor: pointer" id="passwordfa" class="fa fa-lock"></i></span>
					<input  placeholder="Password" name="password" id="ps" value="" class="pass" type="password" required="">
				</div>
				
				<br />
				<p id="go"></p>
				<span style="color: white; border-right: 4px solid white; border-radius: 5px; padding-right: 60px;"><input type="checkbox" name="btnremember" /> Remember me ?</span>
				<br />
				<input type="submit" name="btnnav" value="" onclick="" />
			</form>
		</div>
		<br />
	</div>
	<!--//main-->

	<!--footer-->
	<div class="footer">
		<p>&copy; <?php echo Date("Y");?>. All rights reserved.</p>
	</div>
	<!--//footer-->
	<link href="../../../font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
	<link href="css/style1.css" rel="stylesheet" type="text/css" media="all"/> 
	<link rel="stylesheet" href="../../../maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	<script src="../../../maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
				
	<link href="dashboard/vendor/bootstrap/css/bootstrap.min.html" rel="stylesheet">

	</body>

<!-- Mirrored from swift-spectrum.online/sme/admin/pages/login by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 12 Mar 2021 12:27:49 GMT -->
</html>