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

if (isset($_POST['apply'])){
		$memberNo = $_POST['memberNo'];
        $pciset = $_POST['pciset'];
        $pswd = sha1($_POST['password']);
		
	//Create query 
	$qry199="SELECT * FROM pci_application WHERE memberNo='$memberNo' AND regSet='$pciset'";
	 
	$result199=mysqli_query($con, $qry199);
	
	//Check whether the query was successful or not
	if($result199) {
		if(mysqli_num_rows($result199) > 0) {
			//applicant found
			
			$msg = "Your previous registration for this interview was successful.<a href='login.php'>Login to continue with your registration</a>";
			
		}else {
			//not existing
			
			//check if member is registered with NIQS
			$qry2="SELECT * FROM members WHERE memberNo='$memberNo' and memberGrade='3'";
			$result2=mysqli_query($con, $qry2);
			if($result2){
				if(mysqli_num_rows($result2) > 0)
				{
					//member has an account
					//allow member to register
				
					$st= mysqli_query($con, "INSERT into pci_application(memberNo, password, regSet, status) values('$memberNo', '$pswd', '$pciset', 'Pending')");
					if($st){
			
						$msg = "Congratulations! You may now continue with your application. <a href='login.php'>click here to login</a>";
					}else{
					
						$msg = "<font color='red'>Your application was not successful, please try again later</font>";
					}
					
				}else{
					//not a registered member
					$msg = "<font color='red'>The membership Number provided is not associated with any registered probationer member of the Institute. Provide a valid membership number to apply for PCI.</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 ---------->
</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>Professional Competence Interview (PCI)</font></h2>

    <div class="container" style="width:50%">
	<div class="row">
		<div class="col-md-12 login-sec">
			
		    <h3 class="text-center">Application</h3>
			<p class="text-center"><b><?php echo $msg; ?></b></p>
		   <br>
		   <p align="justify">Complete the form below to start your registration.</p>
			
			<form method="post">
  <div class="form-group">
	<label for="memberNo" class="text-uppercase">Membership Number</label>
    <input type="text" class="form-control" name="memberNo" placeholder="Member No." required=""/>
  </div>
  
  <div class="form-group">
    <label for="password" class="text-uppercase">Password</label>
    <input type="password" class="form-control" name="password" placeholder="Password" required=""/>
  </div>
  
  <div class="form-group">
	<label for="memberNo" class="text-uppercase">Set</label>
    <select class="form-control" name="pciset" required="">
		<?php
		 for($i=2019; $i<=2019; $i++){ echo "<option>April, $i</option><option>September, $i</option>"; }
		?>
	</select>
  </div>
  
    <div class="form-check">
    
    <button type="submit" name="apply" class="btn btn-login float-right">Apply</button>
	Already have an account? <a href="login.php">click here to login</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>

