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


if(isset($_POST['update'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
		//update record
	$qry2=mysqli_query($con, "UPDATE pci_tpc SET tpcMonth='$tpcMonth', tpcYear='$tpcYear', tpcNo='$tpcNo', tpcCentre='$tpcCentre' where applicant_id='$applicant_idpci'");
	if($qry2){
		$sucmsg='Successful!';
	}else{
		$errmsg='Not Successful!';
	}
	
    
}

if(isset($_POST['ricsmember'])){
    $qry3=mysqli_query($con, "UPDATE pci_tpc SET tpcNo='NA', tpcMonth='', tpcYear='', tpcCentre='' where applicant_id='$applicant_idpci'"); 
       if($qry3){
		$sucmsg='Record Updated. Click Next button below to proceed';
	}
	
}




//GET DETAILS FROM DB
	
	$q = "Select * from pci_tpc 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);
			
		}else{ $errmsg='details not found!'; }
				
	}else{
		$errmsg='details not found!';
	}
?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">RICS MEMBER  </h2>
	<div class="graph-form">
    		<div class="form-body">
    			<form method="POST" name="tpcform" action="index.php?page=tpc"> 
    			<input name="ricsmember" type="submit" class="btn btn-default" value="Click Here"/> 
    			</form>
    		</div>
    	</div>
 </div>
 
 
<div class="graph-visual tables-main">
<h2 class="inner-tittle">NIQS TPC EXAMINATION (Fill below) </h2>
	<div class="graph-form">
    		<div class="form-body">
    			 
                <?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                }
                
                ?><form method="POST" name="tpcform" action="index.php?page=tpc"> 
                    <div class="form-group"> 
                        <label>Month of Examination</label> 
                        <select class="form-control" name="tpcMonth" required="" style="height:auto">
                         <option><?php echo $tpcMonth; ?></option>
                         <option>JANUARY</option>
                         <option>FEBRUARY</option>
                         <option>MARCH</option>
                         <option>APRIL</option>
                         <option>MAY</option>
                         <option>JUNE</option>
                         <option>JULY</option>
                         <option>AUGUST</option>
                         <option>SEPTEMBER</option>
                         <option>OCTOBER</option>
                         <option>NOVEMBER</option>
                         <option>DECEMBER</option>
                         
                        </select>  
                    </div> 
                    
					<div class="form-group"> 
                        <label>Year of Examination</label> 
                        <select class="form-control" name="tpcYear" required="" style="height:auto"> 
                        
                        <option><?php echo $tpcYear; ?></option>
                        <?php
                         for($sali=date('Y'); $sali>1969; $sali--)
                          { echo "<option>".$sali."</option>"; }
                          
                        ?>
                        </select>
                    </div> 
                    
					<div class="form-group"> 
                        <label>Examination Number</label> 
                        <input type="text" class="form-control" name="tpcNo" value="<?php 
                        
                        if ($tpcNo!= "NA"){ echo $tpcNo;}else{echo ""; } 
                        
                        ?>" required="" /> 
                    </div> 
					
					<div class="form-group"> 
                        <label>Examination Centre</label> 
                        <input type="text" class="form-control" name="tpcCentre" value="<?php echo $tpcCentre; ?>" required="" /> 
                    </div> 
					
                    <input name="update" type="submit" class="btn btn-default" value="Update Details"/> 
                </form> 
    		</div>
    
    </div>

</div>


   
<?php

 echo "<div>";
 echo "  <a href='?page=body'><button class='btn'>Back</button></a>"; 
 if((strlen($tpcNo)>0)&&($tpcNo!="NA")){
 echo "  <a href='?page=logbook'><button class='btn'>Next</button></a>"; 
 }elseif((strlen($tpcNo)>0)&&($tpcNo=="NA")){
 echo "  <a href='?page=experience'><button class='btn'>Next</button></a>"; 
 }
 
 echo "</div>";

?>