<?php
session_start();
include("config.php"); 
include("encryption.php");
if (isset($_SESSION["loginToken"])) {
    $token = decrypt($_SESSION["loginToken"]);
    $query1 = "SELECT * FROM `tbl_qisysconnect` WHERE `token` = '$token'";
	$result1 = $con->query($query1);
	$count = mysqli_num_rows($result1);
	if($count > 0){
	    header('Location:dashboard.php');
	    exit();
	}
}

$userName = $con->real_escape_string($_GET['username']) ;
$userPass = $con->real_escape_string($_GET['password']);
    
if (isset($_GET['username']) && isset($_GET['password'])) {
	$query1 = "SELECT * FROM `tbl_qisysconnect` WHERE `username` = '$userName' AND `password` = '$userPass'";
	$result1 = $con->query($query1);
	$data1 = $result1->fetch_object();
	
	if ($userName == $data1->username && $userPass == $data1->password) {
		$_SESSION["superadmin"] = $data1->username;
		$_SESSION["loginToken"] = encrypt($data1->token);
		header('Location:dashboard.php');
	}else{
		header('Location:index.php');
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Login</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">	
	<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
	<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="dist/fonts/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="dist/fonts/material-design-iconic-font.min.css">
	<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">	
	<link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
	<link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css">
	<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">	
	<link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css">
	<link rel="stylesheet" type="text/css" href="dist/css/util.css">
	<link rel="stylesheet" type="text/css" href="dist/css/mains.css">
</head>
<body>
	<div class="limiter">
		<div class="container-login100" style="background-image: url('dist/img/bg.jpg');">
			<div class="wrap-login100 p-l-55 p-r-55 p-t-35 p-b-54">
				<form class="login100-form validate-form" action="index.php" method="GET">
					<span class="login100-form-title p-b-49">
						Login
					</span>
					<div class="wrap-input100 validate-input m-b-23" data-validate = "Username is reauired">
						<span class="label-input100">Username</span>
						<input class="input100" type="text" name="username" placeholder="Type your email
						" required>
						<span class="focus-input100"></span>
					</div>
					<div class="wrap-input100 validate-input" data-validate="Password is required">
						<span class="label-input100">Password</span>
						<input class="input100" type="password" name="password" placeholder="Type your password" required>
						<span class="focus-input100"></span>
					</div>					
					<div class="text-right p-t-8 p-b-31">
						<a href="forget_password.php">
							Forgot password?
						</a>
					</div>					
					<div class="container-login100-form-btn">
						<div class="wrap-login100-form-btn">
							<div class="login100-form-bgbtn"></div>
							<button class="login100-form-btn">
								Login
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div id="dropDownSelect1"></div>	
	<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
	<script src="vendor/animsition/js/animsition.min.js"></script>
	<script src="vendor/bootstrap/js/popper.js"></script>
	<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
	<script src="vendor/select2/select2.min.js"></script>
	<script src="vendor/daterangepicker/moment.min.js"></script>
	<script src="vendor/daterangepicker/daterangepicker.js"></script>
	<script src="vendor/countdowntime/countdowntime.js"></script>
	<script src="dist/js/main.js"></script>
</body>
</html>
