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

if(isset($_POST['upload'])){
    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);
    
		//update record
	$newfile_name = "otherdoc/".$applicant_no."_".$applicant_idpci.".pdf";
	//echo $newfile_name;

     $path = $_FILES['applicantfile']['name'];
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     $file_s = filesize($_FILES['applicantfile']['tmp_name']);
    
    
    $file_s = $file_s/(1024 * 1000);
    
    //$file_s = round($file_s);

   
    if($ext=="pdf"){

        if($file_s<=2){
            if(move_uploaded_file($_FILES['applicantfile']['tmp_name'], $newfile_name)){
                $sucmsg='Successful!';
            }else{
                $errmsg='Not Successful!';
            }

        }else{ $errmsg= 'Your file size is greater than 2MB'; }

    }else{ $errmsg=$ext.' file not accepted!'; }
  
    
}



//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);
?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">RECORD OF PROFESSIONAL EXPERIENCE  </h2>
<P> Please attach a PDF copy of the specified Report (not more than 2MB)</P>
	<div class="graph-form">
    		<div class="form-body">
    			<form method="post" name="otherdocform" action="index.php?page=otherdoc" enctype="multipart/form-data"> 
                <?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                }
                
                ?>
                    <div class="form-group"> 
                        <label>Upload Files</label> <br><br><font color="red"><b>PDF only. </b> </font><br>
                        <input type="file" class="form-control" name="applicantfile" style="height:auto" accept="pdf" required="" /> 
                    </div> 
                    
                    <input name="upload" type="submit" class="btn btn-default" value="Upload File"/> 
                </form> 
				<br>
				<?php
				$myfile = "otherdoc/".$memberNo."_".$applicant_idpci.".pdf";
				 if(file_exists($myfile))
				 {
                        
                     $filemtime = filemtime($myfile);
					 echo "<iframe src='".$myfile."?".$filemtime."' width='80%' height='400px'></iframe>";
				 }
				?>
    		</div>
    
    </div>

</div>

<div>
<a href='?page=sponsor'><button class='btn'>Back</button></a>

<?php
if(file_exists($myfile))
{


    echo "<a href='?page=preview'><button class='btn'>Next</button></a>";
}else{ echo "Upload record of professional experience to proceed"; }
?>

</div>