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

if(isset($_POST['loginsumbit'])){
	$memberNo = $_POST['memberNo'];
        $pciset = $_POST['pciset'];
	//$pswd=sha1($_POST['password']);
	$pswd=$_POST['password'];
		
	//Create query 
	$qry199="SELECT * FROM tpcr_application WHERE memberNo='$memberNo' AND password='$pswd' AND regSet='$pciset' LIMIT 1";
	
	$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['applicant_id'] = $reger['id']; 
			$myid = $reger['id'];
			$_SESSION['pin'] = $reger['password']; 
			$_SESSION['applicant_no'] = $reger['memberNo'];     
            $_SESSION['applicant_status']=$reger['status'];     
            $_SESSION['applicant_set']=$reger['regSet'];
			session_write_close();
			$urll = "index.php?i=".$myid;
			
			echo '<script>window.location = "'.$urll.'";</script>';
			
			//echo '<script>window.location = "index.php";</script>';
			//header("location: index.php");
			
		}else {
			//Login failed
			$msg = "<font color='red'>Applicant with the provided details 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>TPC Referral Registration</title>
</head>

<body bgcolor="black">
		
<section class="login-block" style="padding-top:0px; background-color:eeeeee;">
			<h2 class="text-center"> <font color="blue">THE NIGERIAN INSTITUTE OF QUANTITY SURVEYORS<BR>Test of Professional Competence (TPC Referral)</font></h2>

    <div class="container" style="width:50%">
	<div class="row">
		<div class="col-md-12 login-sec">
			
		    <h3 class="text-center">Proceed with Application</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">Membership Number</label>
    <input type="text" class="form-control" name="memberNo"  value="<?php if(isset($pin)){ echo $memberNumber; } ?>" placeholder="Member No." required=""/>
  </div>
  
  <div class="form-group">
    <label for="password" class="text-uppercase">PIN</label>
    <input type="text" class="form-control" name="password" value="<?php if(isset($pin)){ echo $pin; } ?>" placeholder="PIN" required=""/>
    
  </div>
  
   
  <div class="form-group">
	<label for="take" class="text-uppercase">Diet</label>
    <select class="form-control" name="pciset" required="">  <?php if(isset($pin)){ echo "<option>$regSet</option>"; } ?>
		<?php
		  $qset = "select * from tpc_set";
		  $rset = mysqli_query($con, $qset);
		  
		  while($rowset = mysqli_fetch_array($rset))
		  {
			echo "<option>".$rowset['setMonth'].", ".$rowset['setYear']."</option>"; 
		  }
		?>
		
	</select>
  </div>
  
    <div class="form-check">
    
    <button type="submit" name="loginsumbit" class="btn btn-login float-right">Proceed</button>
	Don't have an account yet? <a href="index.php">click here to apply</a>
	
  </div>
  
</form>
<div class="copy-text">&COPY;<?php echo date('Y'); ?>  All right reserved. &nbsp; &nbsp; The Nigerian Institute of Quantity Surveyors</div>
		</div>
		
</div>
</section>
</body>
</html>

