<?php
clearstatcache();
$errmsg='';
$sucmsg='';
if(isset($_POST['upload'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
		//update record
	$newfile_name = "passport/".$applicant_no."_".$applicant_idpci.".jpg";
	
 
  //  $check = getimagesize($_FILES["passport"]["tmp_name"]);
  $path = $_FILES['passport']['name'];
  $ext = pathinfo($path, PATHINFO_EXTENSION);
  
  //echo $ext;
  //get size, width and height
  list($width, $height, $type, $attr) = getimagesize($_FILES['passport']['tmp_name']); 
  //echo '<script>alert("Height: '.$height.' Width: '.$width.'");</script>';
  
     if($height>300)
     {
        echo '<script>alert("Your passport height('.$height.'px) exceed the maximum height of 300px");</script>';
     }elseif($width>300){
        echo '<script>alert("Your passport width('.$width.'px) exceed the maximum width of 300px");</script>';
     
     }else{
     	//upload passport	
	if(move_uploaded_file($_FILES['passport']['tmp_name'], $newfile_name)){
		$sucmsg='Successful!';
	}else{	$errmsg='Not Successful!'; }
    }
    
    
 
  }




//GET DETAILS FROM DB

	$q = "Select * from pci_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">PASSPORT PHOTOGRAPH</h2>
	<div class="graph-form">
    		<div class="form-body">
    			<form method="post" name="passportform" action="index.php?page=passport" 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/Update Passport </label> <br><br><font color="red"><b>jpg format only. Dimension of not more than 300 X 300 pixel</b> </font><br>
                        <input type="file" class="form-control" id="passport" name="passport" style="height:auto" required="" onchange="validateFileExtension(this.value);"/>
                        
                        
                         
                    </div> 
                    
                    <input name="upload" type="submit" class="btn btn-default" value="Upload Passport"/>
                </form> 
				<br>
				<?php
				
				$mypassport = "passport/".$applicant_no."_".$applicant_idpci.".jpg";
				$filemtime = filemtime($mypassport);
				
				 if(file_exists($mypassport))
				 {
					 
					 echo "<img src='".$mypassport."?".$filemtime."' width='20%'>";

				 }
				?>
    		</div>
    
    </div>

</div>

<div>
<a href='?page=mydetails'><button class='btn'>Back</button></a>
<?php 
if(file_exists($mypassport))
{
  echo "<a href='?page=disability'><button class='btn'>Next</button></a>";
} ?>
</div>

<script type="text/javascript">
 function validateFileExtension(fld) {
  

    var uploadfile = document.getElementById('passport');
   if (uploadfile.value.match(/jpg$/) || uploadfile .value.match(/JPG$/))
    {
      
      
      return true;
    } else{alert("This is not a valid JPeg Image"); uploadfile.value=""; }
    
    
 }
 
 

</script>
