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

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

//GET DETAILS FROM DB

	$q = "Select * from tpcr_application where id=$applicant_id 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='https://register.niqs.org.ng/tpcfull/images/logo.png' width='100px' height='150px'></td><th><h2><center>NIGERIAN INSTITUTE OF QUANTITY SURVEYORS </h2></center><center><h3>
 APPLICATION FOR TEST OF PROFESSIONAL COMPETENCE <br>
(TPC REFERRAL CANDIDATE - $regSet)</center></h3>    </th> <td>"; 
		$mypassport = "passport/".$applicant_no."_".$applicant_id.".jpg";
		 $filemtime = filemtime($mypassport);
		
		 if(file_exists($mypassport))
		 {
			 echo "<img src='".$mypassport."?".$filemtime."' width='120px' height='150px'><font color='black'>TR".$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)." </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 centre
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> <b>2.0 PREFERRED EXAMINATION CENTRE</b> </font></td></tr>";
echo "<tr><td colspan='3'> ".strtoupper($examCentre)." </td></tr>";
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";

//3.0 olevel
/*
$q = "Select * from tpcr_olevel where applicant_id='$applicant_id'";
$qry2=mysqli_query($con, $q);

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> <b>3.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>";

	while($row2=mysqli_fetch_array($qry2)){
		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>";
*/


//6.0 entries
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>3.0 DETAILS OF REFERENCE </b> </font></td></tr>";
echo "<tr><td colspan='3'><font color='black' size='4'>  <b> &nbsp;  </b> </font></td></tr>";

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>3.1 DETAILS OF EXAMINATION WHERE THE CANDIDATE FIRST RECORDED THE REFERENCE(S) </b> </font></td></tr>";


echo "<tr><td colspan='3'> <br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='left'> &nbsp; <b> EXAMINATION  NUMBER </b></td> <td align='left'> <b> &nbsp; YEAR </b></td> <td align='left'> <b> &nbsp; EXAMINATION CENTRE</b></td> <td align='left'> <b> &nbsp; SUBJECTS </b></td> </tr>";
	
	
		//get course count
                $q = "select * from tpc_course";
                $r = mysqli_query($con, $q);
                $coursecount = mysqli_num_rows($r);
                
		$cx = 1;
		 
		//check old option
		$q2 = "select * from tpcr_firstreg where applicant_id=$applicant_id";
		$r2 = mysqli_query($con, $q2);
		
		$row2 = mysqli_fetch_array($r2);
		extract($row2);
		//echo print_r($row2);
		
		echo "<tr><td align='left'> &nbsp; $examNo </td> <td align='left'> &nbsp; $examYear </td> <td align='left'> &nbsp; $examCentre </td>   <td align='left'> ";
		
			echo "<table width='100%' border='1' cellspacing='0'>";
		while($row=mysqli_fetch_assoc($r))
		{
			$gname = "ex".$cx;
			extract($row);
			$mycell = "course".$cx;

			if($row2[$mycell]=="1"){ echo '<tr><td> &nbsp; '.strtoupper($course).'</td></tr>'; }
			
			$cx++;
			
			//selection check 
			//$firstattempt = intval($row2['course1'])+intval($row2['course2'])+intval($row2['course3'])+intval($row2['course4'])+intval($row2['course5'])+intval($row2['course6'])+intval($row2['course7'])+intval($row2['course8'])+intval($row2['course9'])+intval($row2['course10']);
			

$firstattempt = (int)$row2['course1']+ (int) $row2['course2']+ (int) $row2['course3']+ (int) $row2['course4']+ (int) $row2['course5']+ (int) $row2['course6']+ (int) $row2['course7']+ (int) $row2['course8']+ (int) $row2['course9']+ (int) $row2['course10'];
		}	
		
		echo "</table>";
		echo "</table>";
			
	echo " </td>  </tr>";
	
	
echo "<tr><td><b> <br> </b></td> 						<td colspan='2'> </td></tr>";


echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>3.2 DETAILS OF EXAMINATION WHERE THE CANDIDATE LAST ATTEMPTED THE REFERENCE(S) </b> </font></td></tr>";

echo "<tr><td colspan='3'> <br>";
	echo "<table width='100%' border='1' cellspacing='0'>";
	echo "<tr><td align='left'> &nbsp; <b> EXAMINATION  NUMBER </b></td> <td align='left'> <b> &nbsp; YEAR </b></td> <td align='left'> <b> &nbsp; EXAMINATION CENTRE</b></td> <td align='left'> <b> &nbsp; SUBJECTS </b></td> </tr>";
	
	
		
                $q = "select * from tpc_course";
                $r = mysqli_query($con, $q);
                $cx = 1;
		 
		//check old option
		$q2 = "select * from tpcr_lastreg where applicant_id=$applicant_id";
		$r2 = mysqli_query($con, $q2);
		$row2 = mysqli_fetch_array($r2);
		extract($row2);
		//echo print_r($row2);
		echo "<tr><td align='left'> &nbsp; $examNo </td> <td align='left'> &nbsp; $examYear </td> <td align='left'> &nbsp; $examCentre </td>   <td align='left'> ";
		
			echo "<table width='100%' border='1' cellspacing='0'>";
			
			$lastattempt = 0;
		while($row=mysqli_fetch_assoc($r))
		{
			$gname = "ex".$cx;
			extract($row);
			$mycell = "course".$cx;

			if($row2[$mycell]=="1"){ echo '<tr><td> &nbsp; '.strtoupper($course).'</td></tr>'; $lastattempt++; }
			
			$cx++;
			
			//selection check 
			//$lastattempt = $row2['course1']+$row2['course2']+$row2['course3']+$row2['course4']+$row2['course5']+$row2['course6']+$row2['course7']+$row2['course8']+$row2['course9']+$row2['course10'];
		}	
		
		echo "</table>";
		echo "</table>";
		
		
	echo " </td>  </tr>";
	
	
echo "<tr><td><b> <br> </b></td> 						<td colspan='2'> </td></tr>";

echo "<tr><td><b> <br> </b></td> 						<td colspan='2'> </td></tr>";

echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'>  <b>3.3 ENTRY FOR CURRENT EXAMINATION </b> </font></td></tr>";


echo "<tr><td colspan='3'> <br>";
	
		$q = "select * from tpc_course2020";
                $r = mysqli_query($con, $q);
                $cx = 1;
		
		 
		//check old option
		$q2 = "select * from tpcr_currentreg where applicant_id=$applicant_id";
		$r2 = mysqli_query($con, $q2);
		$row2 = mysqli_fetch_array($r2);
		extract($row2);
		//echo print_r($row2);
		
			echo "<table width='100%' border='1' cellspacing='0'>";
			echo "<tr><td align='center'> &nbsp; <b> S/N </b></td> <td align='left'> <b> &nbsp; SUBJECTS </b></td></tr>";
			$sn=1;

			$currentattempt = 0;
		while($row=mysqli_fetch_assoc($r))
		{
			$gname = "ex".$cx;
			extract($row);
			$mycell = "course".$cx;

			if($row2[$mycell]=="1"){ echo '<tr><td align="center"> '.$sn.' </td> <td> &nbsp; '.strtoupper($course).'</td></tr>'; $sn++; $currentattempt++; }
			
			$cx++;
			
			//selection check 
			//$currentattempt = $row2['course1']+$row2['course2']+$row2['course3']+$row2['course4']+$row2['course5']+$row2['course6']+$row2['course7']+$row2['course8']+$row2['course9']+$row2['course10'];
		}	
		
		echo "</table>";
		
		
	echo " </td>  </tr>";
	
	
echo "<tr><td><b> <br><br> </b></td> 						<td colspan='2'> </td></tr>";


//8.0 Employer 
$q = "Select * from tpcr_employer where applicant_id='$applicant_id'";
$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>4.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>";




//9.0 sponsor
$q = "Select * from tpcr_sponsor where applicant_id='$applicant_id'";
$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>5.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) NIQS MEMBERSHIP NUMBER: </b></td> 	<td colspan='2'> &nbsp;  ".strtoupper($memberNo)." </td></tr>";
	echo "<tr><td><b> &nbsp;  b)  FULL NAME: </b></td> 				<td colspan='2'> &nbsp;  ".strtoupper($memberSurname)." ".strtoupper($memberOthernames)." </td></tr>";
	echo "<tr><td><b> &nbsp;  c)  EMAIL ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberEmail)." </td></tr>";
	echo "<tr><td><b> &nbsp;  d)  CONTACT ADDRESS: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberAddress)." </td></tr>";
	echo "<tr><td><b> &nbsp;  e)  MEMBERSHIP GRADE: </b></td> 			<td colspan='2'> &nbsp;  ".strtoupper($memberGrade)." </td></tr>";
	echo "<tr><td><b> &nbsp;  f)  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>";

//10.0
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> &nbsp; <b>6.0 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>";
//

//11.0
echo "<tr><td colspan='3' bgcolor='black'><font color='white' size='4'> &nbsp; <b>7.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 "<br><br>";
echo "<p align='justify'>By completing and submitting this application form, you agree to be bound by all existing NIQS Examination Policies, Rules and Guidelines and the rules guiding the ".$regSet." professional examination in particular.</p>";
echo "</td><tr>";


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

<div>


<?php 

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


//double check first reg
if($firstattempt==0){
   echo '<script>alert("Details of first attempt missing");</script>';
   echo '<script>window.location = "https://register.niqs.org.ng/tpcref/index.php?page=firstreg";</script>';
   exit();
} 

//double check last reg
if($lastattempt==0){
   echo '<script>alert("Details of last attempt missing");</script>';
   echo '<script>window.location = "https://register.niqs.org.ng/tpcref/index.php?page=lastreg";</script>';
   exit();
} 

//double check current reg
if($currentattempt==0){
   echo '<script>alert("No course registered");</script>';
   echo '<script>window.location = "https://register.niqs.org.ng/tpcref/index.php?page=currentreg";</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 = "https://register.niqs.org.ng/tpcref/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 = "https://register.niqs.org.ng/tpcref/index.php?page=sponsor";</script>';
   exit();
}


if($status == "Pending"){ 
	echo "<b><font color='red'>NOTE: Please ensure that all information on this form is correct. You will not be able to edit this form once submitted.</font></b> <br><br>
	<a href='?page=sponsor'><button class='btn'>Back</button></a> <a href='submitform.php?i=".$myAppID."'><button class='btn' name='btnsubmit' id='btnsubmit'  class='btn'>Submit</button></a>";
}else{
	//echo "<a href='printform.php?i=$myAppID'><button name='btn' id='btn' class='btn'>Print</button></a>";
	//print form
	echo "<form action='printform.php' method='post'>";
	echo "<input type='hidden' name='i' value='$myAppID' />";
	echo "<input type='submit' value='Print Form' />";
	echo "</form>";
}
 ?>  
</div>

	
<script>
function printform(){    
   var originalContents = document.body.innerHTML;
   document.getElementById('btn').style.display="none";
     var printContents = document.getElementById('myarea').innerHTML;      
   document.body.innerHTML = printContents;   
   window.print();     
   document.body.innerHTML = originalContents;
}
</script>