<?php
$errmsg='';
$sucmsg='';

include('database.php');

if(isset($_POST["i"])){
//GET DETAILS FROM DB
	if(isset($_POST["i"])){$applicant_idpci=$_POST["i"]; }
	$q = "Select * from epci_application where id=$applicant_idpci limit 1";
    $qry=mysqli_query($con, $q);
    $row=mysqli_fetch_assoc($qry);
    extract($row);
	//print_r($row);
	$myAppID = $id;
	$applicant_idpci = $id;
	$applicant_no = $memberNo;
    

	switch($memberGrade)
	{
		case 1: $memberGrade="Fellow";
		break;
		
		case 2: $memberGrade="Member";
		break;
		
		case 3: $memberGrade="Probationer";
		break;
		
		case 4: $memberGrade="Technician";
		break;
		
		case 5: $memberGrade="Student";
		break;
		
		case 6: $memberGrade="Practicing Firm";
		break;
		
		case 7: $memberGrade="Graduate";
		break;
		
		case 8: $memberGrade="State Chapter";
		break;
		
		case 9: $memberGrade="Past President";
		break;
		
	}
	
?>

<html>
<head>
<title><?php echo $applicant_no; ?> NIQS  Application Form</title>
</head> 
<body>

<div class="graph-visual tables-main" name='myarea' id='myarea'>

<?php
$errmsg='';
$sucmsg='';
$myID = $applicant_idpci;

if(isset($_POST['update'])){
    extract($_POST);
	$errmsg='';
    $sucmsg='';
    
	
    
}

//GET DETAILS FROM DB

	$q = "Select * from epci_application where id=$applicant_idpci limit 1";
    $qry=mysqli_query($con, $q);
    $row=mysqli_fetch_assoc($qry);
    extract($row);
	//print_r($row);
	$myAppID = $id;
    $applicant_no = $memberNo;

	switch($memberGrade)
	{
		case 1: $memberGrade="Fellow";
		break;
		
		case 2: $memberGrade="Member";
		break;
		
		case 3: $memberGrade="Probationer";
		break;
		
		case 4: $memberGrade="Technician";
		break;
		
		case 5: $memberGrade="Student";
		break;
		
		case 6: $memberGrade="Practicing Firm";
		break;
		
		case 7: $memberGrade="Graduate";
		break;
		
		case 8: $memberGrade="State Chapter";
		break;
		
		case 9: $memberGrade="Past President";
		break;
		
	}
	
?>



<div class="graph-visual tables-main" name='myarea' id='myarea'>
<?php
//header
echo "<table width='100%' cellspacing='0'>";



echo "<tr><td><img src='images/logo.png' width='' height=''></td><th><h2><center>THE NIGERIAN INSTITUTE OF QUANTITY SURVEYORS </h2></center><center><h3>
EXAMINATION APPLICATION - EXPERIENCED ROUTE ASSESSMENT  <br>
($regSet)</center></h3>  </th> <td>"; 
		$mypassport = "passport/".$applicant_no."_".$applicant_idpci.".jpg";
		$filemtime = filemtime($mypassport);
		
		 if(file_exists($mypassport))
		 {
			 echo "<img src='".$mypassport."?".$filemtime."' width='120px' height='150px'><font color='black'>ER".$uniqueId."</font><br><br>";
		 }

echo "</td></tr>";

echo "</table>";
echo "<table width='100%' cellspacing='0'>";

//1.0
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>1.0 PERSONAL DETAILS</b> </font></td></tr>";
echo "<tr><td colspan='3'><br>";

	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td width='40%' height='30px'> &nbsp; <b> NIQS MEMBERSHIP NUMBER: </b></td> 	<td colspan='2'> &nbsp;  ".strtoupper($memberNo)." </td></tr>";
	echo "<tr><td> &nbsp; <b> SURNAME: </b></td> 					<td colspan='2'> &nbsp;  ".strtoupper($memberSurname)." </td></tr>";
	echo "<tr><td> &nbsp; <b> OTHER NAMES: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($memberOthernames)." </td></tr>";
	echo "<tr><td> &nbsp; <b> TITLE/GENDER: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($memberTitle)."/".strtoupper($memberGender)." </td></tr>";
	echo "<tr><td> &nbsp; <b> DATE OF BIRTH: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($memberDOB)." </td></tr>";
	echo "<tr><td> &nbsp; <b> CHAPTER: </b></td> 					<td colspan='2'> &nbsp;  ".strtoupper($memberChapter)." </td></tr>";
	echo "<tr><td> &nbsp; <b> PHONE NUMBER:  </b></td> 				<td colspan='2'> &nbsp;  $memberPhone1, $memberPhone2 </td></tr>";
	echo "<tr><td> &nbsp; <b> EMAIL ADDRESS: </b></td> 				<td colspan='2'> &nbsp;  ".$memberEmail." </td></tr>";
	echo "<tr><td> &nbsp; <b> POSTAL ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberAddress)." </td></tr>";
	echo "<tr><td> &nbsp; <b> CURRENT MEMBERSHIP GRADE: </b></td> 	<td colspan='2'> &nbsp;  ".strtoupper($memberGrade)." </td></tr>";
	echo "<tr><td> &nbsp; <b> DATE OF REGISTRATION: </b></td> 		<td colspan='2'> &nbsp;  ".strtoupper($memberRegDate)." </td></tr>";
	echo "<tr><td> &nbsp; <b> DIET:  </b></td> 						<td colspan='2'> &nbsp;  ".strtoupper($regSet)." </td></tr>";
	echo "<tr><td> &nbsp; <b> DISABILITY:  </b></td> 					<td colspan='2'> &nbsp;  ".strtoupper($disability); if($disability=='YES'){ echo " - ".$disability_type; } echo "   </td></tr>";
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";
	
//2.0 olevel
$q = "Select * from epci_olevel where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> <b>2.0 O' LEVEL SUBJECTS RESULT (5 CREDITS FROM WAEC/NECO/NABTEB):</b> </font></td></tr>";
echo "<tr><td colspan='3'> <br>";
	echo "<table width='50%' border='1' cellspacing='0'>";
	echo "<tr bgcolor='skyblue'><td> &nbsp; <b> SUBJECTS </b></td> 	<td align='center'><b> GRADE </b></td></tr>";
        
        $mysubjectcount = 0;
	while($row2=mysqli_fetch_array($qry2)){
	 	$mysubjectcount = $mysubjectcount + 1;
		extract($row2);
		echo "<tr><td><b> &nbsp; ".$subject."</b></td> 	<td align='center'> ".strtoupper($grade)." </td></tr>";
	}
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";


//3.0 education
$q = "Select * from epci_education where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>3.0 EDUCATION:</b> </font></td></tr>";
echo "<tr><td colspan='3'> <br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='center'><b> SN </td> <td align='center'><b> UNIVERSITY/INSTITUTION </b></td> 	<td align='center'><b> COUNTRY </b></td>   <td align='center'><b> DEGREE/DIPLOMA NAME <br> (eg. B.Tech Quantity Surveying) </b></td>   <td><b><center> DATE COMPLETED </center></b></td> </tr>";
	
	$edd=1;
	while($row2=mysqli_fetch_array($qry2)){
		extract($row2);
		echo "<tr><td align='center'>$edd</td> <td align='center'> ".strtoupper($institution)."</td> <td align='center'> ".strtoupper($country)." </td>   <td align='center'> ".strtoupper($degree)." IN ".strtoupper($course)." </td>   <td align='center'> ".strtoupper($dateCompleted)." </td>  </tr>";
		$edd++;
	}
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";

//4.0 professional bodies
$q = "Select * from epci_body where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>4.0 MEMBERSHIP OF ANY OTHER PROFESSIONAL INSTITUTION(S): (IF ANY)</b> </font></td></tr>";
echo "<tr><td colspan='3'> <br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='center'><b> SN </td> <td align='center'><b> NAME OF INSTITUTION  </b></td> 	<td align='center'><b> CURRENT GRADE  </b></td>   <td align='center'><b> HOW MEMBERSHIP WAS ACHIEVED <br>(E.G. EXAMINATION) </b></td>   <td><b><center> YEAR REGISTERED/<br>OBTAINED/ELECTED </center></b></td> </tr>";

	$ed=1;
	while($row2=mysqli_fetch_array($qry2)){
		extract($row2);
		echo "<tr><td align='center'>$ed</td> <td align='center'> ".strtoupper($institution)."</td> <td align='center'> ".strtoupper($currentGrade)." </td>   <td align='center'> ".strtoupper($regRoute)." </td>   <td align='center'> ".strtoupper($regYear)." </td>  </tr>";
		$ed++;
	}
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";

//5.0 professional experience
$q = "Select * from epci_postgraduate where applicant_id='$applicant_idpci'";
    $qry=mysqli_query($con, $q);
	if($qry){
		
		if(mysqli_num_rows($qry) >0){
			$row=mysqli_fetch_assoc($qry);
			extract($row);
		}
    }
$q = "Select * from epci_experience where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>5.0 POSTGRADUATE EXPERIENCE:</b> </font></td></tr>";
echo "<tr><td colspan='3'> <br> <B>YEARS OF EXPERIENCE: </B> $year_range <br><br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='center'><b> SN </td> <td align='left'><b> EMPLOYER'S NAME AND ADDRESS  </b></td> <td align='center'><b> POSITION HELD & DATES  </b> <td align='left'> &nbsp; <b> DUTIES </b></td> </tr>";
	
	$xp=1;
	while($row2=mysqli_fetch_array($qry2)){
		extract($row2);
		echo "<tr><td align='center'> $xp </td> <td align='left'> ".strtoupper($employer)."</td> <td align='center'> ".strtoupper($position)." </td>   <td> <font size='2'>".strtoupper($duties)."</font> </td> </tr>";
		$xp++;
	}
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";


//6.0 Employer 
$q = "Select * from epci_employer where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);
$row2=mysqli_fetch_array($qry2);
extract($row2);
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>6.0 EMPLOYER DETAILS</b> </font></td></tr>";
	
echo "<tr><td colspan='3'><br>";

	echo "<table width='100%' border='1' cellspacing='0'>";

	echo "<tr><td width='40%'><b> &nbsp;  a)   NAME OF EMPLOYER: </b></td> 	<td colspan='2'> &nbsp;  ".strtoupper($employer)." </td></tr>";
	echo "<tr><td><b> &nbsp;  b) EMPLOYER'S BUSINESS ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($address)." </td></tr>";
	echo "<tr><td><b> &nbsp;  c)  NATURE OF EMPLOYER'S BUSINESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($nature)." </td></tr>";
	echo "<tr><td><b> &nbsp;  d)  POSITION OF APPLICANT: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($position)." </td></tr>";
	echo "<tr><td><b> &nbsp;  e)  DATE OF EMPLOYMENT: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($employmentDate)." </td></tr>";
	
	echo "</table>";

echo "</td></td>";
echo "<tr><td><b> <br> </b></td> 					<td colspan='2'>  </td></tr>";
	echo "<tr><td colspan='2'><b> f)  I hereby attest that to the best of my knowledge, the particulars given by me and the applicant here are true and correct.   </b></td> 	</tr>";
	echo "<tr><td><b>  </b></td> 				<td colspan='2' align='center'> <br><br><br><img src='images/line.jpg' width='70%'><br><b> EMPLOYER'S SIGNATURE & DATE </b>	 </td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";


// Seminar
$q = "Select * from epci_seminar where applicant_id='$applicant_idpci'";
$qry2=mysqli_query($con, $q);
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>7.0 SEMINAR/WORKSHOPS ATTENDED</b> </font></td></tr>";
echo "<tr><td colspan='3'> <br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='center'><b> SN </td> <td align='center'><b> TITLE/THEME  </b></td> <td align='center'><b> DATE  </b> <td align='center'><b> ORGANIZER </b></td> <td align='center'><b> CPD UNITS </b></td> </tr>";
	
	$xp=1;
    $seminarCpdsum = 0;
	while($row2=mysqli_fetch_array($qry2)){
		extract($row2);
		echo "<tr><td align='center'> $xp </td> <td align='center'> ".strtoupper($seminarTitle)."</td> <td align='center'> ".$seminarDate." </td>   <td align='center'> ".strtoupper($seminarOrganizer)." </td>  <td align='center'> ".strtoupper($seminarCpd)." </td> </tr>";
		$xp++;
        $seminarCpdsum = $seminarCpdsum + $seminarCpd;
	}
    echo "<tr><td> </td> <td></td><td></td><td></td> <td align='center'> <b>   $seminarCpdsum </b></th></tr>";
	echo "</table>";
	
echo "</td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";


//8.0 sponsor
$applicant_idpci = $_POST["id"];
$q = "Select * from epci_sponsor where applicant_id='$applicant_idpci'";

$qry2=mysqli_query($con, $q);
$row2=mysqli_fetch_array($qry2);
extract($row2);
$mysponsor = $memberSurname;

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> <b>8.0 SPONSOR DETAILS</b> </font></td></tr>";
echo "<tr><td colspan='3'><br>";

	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td width='40%'><b> &nbsp;  a) SPONSOR'S NIQS MEMBERSHIP NUMBER: </b></td> 	<td colspan='2'> &nbsp;  ".strtoupper($memberNo)." </td></tr>";
	echo "<tr><td><b> &nbsp;  b)  SPONSOR'S FULL NAME: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($memberSurname)." ".strtoupper($memberOthernames)." </td></tr>";
	echo "<tr><td><b> &nbsp;  c)  SPONSOR'S EMAIL ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberEmail)." </td></tr>";
	echo "<tr><td><b> &nbsp;  d)  SPONSOR'S CONTACT ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberAddress)." </td></tr>";
	echo "<tr><td><b> &nbsp;  e)  SPONSOR'S MEMBERSHIP GRADE: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberGrade)." </td></tr>";
	echo "<tr><td><b> &nbsp;  f)  SPONSOR'S RESGISTRATION DATE:: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberRegDate)." </td></tr>";
	
	echo "</table>";

echo "</td></td>";
echo "<tr><td><b> <br> </b></td> 					<td colspan='2'>  </td></tr>";
	echo "<tr><td colspan='2'><b> g) I hereby declare that to the best of my knowledge, the particulars given by me and the applicant here are true and correct.   </b></td> 	</tr>";	
echo "<tr><td><b>  </b></td> 				<td colspan='2' align='center' width='50%'> <br><br><br><img src='images/line.jpg' width='70%'><br><b> SPONSOR'S SIGNATURE & DATE </b>	 </td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";

//--

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> &nbsp; <b>9.0 APPLICANT'S DECLARATION</b> </font></td></tr>";
echo "<tr><td colspan='2' align='justify'><br>I declare that the particulars given on this form are true and correct and that I will abide by the Rules and Regulations governing the Institute’s Examinations.   <br><br><br></td> 	</tr>";
echo "<tr><td colspan='2'><b>Applicant's Signature............................................................................ Date..............................................    </b></td> 	</tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";
//--

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> &nbsp; <b>10.0 STATE CHAPTER CHAIRMAN/SECRETARY (COMPULSORY) TO BE COMPLETED MANUALLY</b> </font></td></tr>";
echo "<tr><td colspan='3'><br>";

	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td height='40px' width='30%'> &nbsp; <b> CHAPTER: </b></td> 	<td colspan='2' > &nbsp; &nbsp;  ".strtoupper($memberChapter)." <br> </td></tr>";
	echo "<tr><td> &nbsp;<b> NAME: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> NIQS MEMBERSHIP NUMBER: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> DESIGNATION: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> PHONE NUMBER: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> DATE: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> EMAIL: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "<tr><td> &nbsp;<b> SIGNATURE: </b></td> 	<td colspan='2'> <br><br> </td></tr>";
	echo "</table>";

echo "</td><tr>";


echo "</table>";
?>
</div>

<?php 

//double check passport
/*if(!file_exists($mypassport))
{
   echo '<script>alert("Your passport is missing");</script>';
   echo '<script>window.location = "http://niqs.org.ng/onlineapplication/epci/index.php?page=passport";</script>';
   exit();
}

//double check o'level subjects
if($mysubjectcount < 5)
{
   echo '<script>alert("Your O-Level subjects is less than 5");</script>';
   echo '<script>window.location = "http://niqs.org.ng/onlineapplication/epci/index.php?page=olevel";</script>';
   exit();
} 

//double check employer
if(strlen($employer)==0){
	//ok do nothing
   echo '<script>alert("Your employer details are missing");</script>';
   echo '<script>window.location = "http://niqs.org.ng/onlineapplication/epci/index.php?page=employer";</script>';
   exit();
}


//double check sponsor
if(strlen($mysponsor)==0){
	//ok do nothing
   echo '<script>alert("Your sponsor details are missing");</script>';
   echo '<script>window.location = "http://niqs.org.ng/onlineapplication/epci/index.php?page=sponsor";</script>';
   exit();
}


*/
 ?>  



</div>
</body>
</html>

<script>
window.print();
//history.back();
</script>


<?php
}else{
	//send user back
	echo '<script>alert("Invalid Token"); history.back(); </script>';
}
?>