<?php
session_start();
require 'database.php';
$msg ="";

if(isset($_POST['loginsumbit'])){
	$username= $_POST['username'];
    $pswd=sha1($_POST['password']);
	//$pswd=$_POST['password'];
		
	//Create query 
	$qry199="SELECT * FROM exam_admin WHERE username='$username' AND password='$pswd'";
	//echo sha1("123456");
	$result199=mysqli_query($con, $qry199);
	
	//Check whether the query was successful or not
	if($result199) {
		if(mysqli_num_rows($result199) > 0) {
			//applicant found
			session_regenerate_id();
			$reger = mysqli_fetch_assoc($result199);
			$_SESSION['admin_id'] = $reger['id']; 
			$_SESSION['applicant_status']=$reger['status']; 
			//setcookie('admin_id', $reger['id']);
			//setcookie('applicant_status', $reger['id']);
			
			//session_write_close();

			//echo " Login Successful, <a href='index.php'>Click here to continue </a> ";
			//echo "admin ID: ".$_SESSION['admin_id'];
			echo '<script>window.location = "index.php?i='.$_SESSION['admin_id'].'";</script>';
			//header("location: index.php");
			
		}else {
			//Login failed
			$msg = "<font color='red'>User not found!</font>";	
			
		}
	}
}
?>
<html>
<head>

<link href="css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"/>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-1.11.1.min.js"></script>
<link href="login.css" rel="stylesheet"/>
<!------ Include the above in your HEAD tag ---------->
<title>NIQS Examination Application</title>
</head>

<body bgcolor="black">
		
<section class="login-block" style="padding-top:0px; background-color:eeeeee;">
			<h2 class="text-center"> <font color="blue">NIGERIAN INSTITUTE OF QUANTITY SURVEYORS<BR>Administrator</font></h2>

    <div class="container" style="width:50%">
	<div class="row">
		<div class="col-md-12 login-sec">
			
		    <h3 class="text-center"></h3>
			<p class="text-center"><b><?php echo $msg; ?></b></p>
		   <br>
		   
		   <form method="post" action="login.php">
  <div class="form-group">
	<label for="take" class="text-uppercase">Username</label>
    <input type="text" class="form-control" name="username" required=""/>
  </div>
  
  <div class="form-group">
    <label for="password" class="text-uppercase">Password</label>
    <input type="password" class="form-control" name="password" required=""/>
    
  </div>
  
   
  
  
    <div class="form-check">
    
    <button type="submit" name="loginsumbit" class="btn btn-login float-right">Login</button>
	
  </div>
  
</form>
		</div>
		
</div>
</section> 
<br><br><br>

<div align='center' class="copy-text">&COPY;<?php echo date('Y'); ?>  All right reserved. &nbsp; &nbsp;Nigerian Institute of Quantity Surveyors</div>

</body>
</html>

