<?php
$errmsg='';
$sucmsg='';
if(isset($_POST['addexperience'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
	//update record 
	if($todate=="stillonthejob"){ $enddate="Date"; }	
		
	$qry2=mysqli_query($con, "UPDATE pci_experience SET employer='$employer', position='$position', startDate='$startdate', endDate='$enddate', duties='$duties' where applicant_id='$applicant_idpci' and id='$editID'");
	
	if($qry2){
		$sucmsg='Successful!';
		echo '<script>window.location = "index.php?page=experience";</script>';
	}else{
		$errmsg='Not Successful!';
	}
	
    
}



?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">PROFESSIONAL EXPERIENCE</h2>
Updating Professional Experience.
	<div class="graph-form">
    		<div class="form-body">
				<?php
				//GET DETAILS FROM DB
				if(isset($_POST['editID'])){ $editID=$_POST['editID']; }else{ $editID="0"; }
				$q = "Select * from pci_experience where applicant_id='$applicant_idpci' and id=$editID";
				
				$qry=mysqli_query($con, $q);
				if($qry){
					
					if(mysqli_num_rows($qry) >0){
						$row=mysqli_fetch_assoc($qry);
						extract($row);
						$sucmsg='Edit the details below then click <b>Update Record</b>';
						
					}else{ $errmsg='No experience found!'; }
							
				}else{
					$errmsg='No experience found!';
				}
				
				?>
			
			
			
			
                <?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                
                	//form for edit
                ?>
                
                   <form method="post" name="experienceform" action="index.php?page=experienceeditor"> 
                    <div class="form-group"> 
                        <label>Employer</label> 
                        <input type="text" class="form-control" name="employer" value="<?php echo $employer; ?>" placeholder="Employer name/address" required="" />  
                        <input type="hidden" class="form-control" name="editID" value="<?php echo $id; ?>" placeholder="Employer name/address" required="" />  
                        
                    </div> 
                    
					<div class="form-group"> 
                        <label>Position Held</label> 
                        <input type="text" class="form-control" name="position" value="<?php echo $position; ?>" required="" /> 
                    </div> 
                    
					<div class="form-group"> 
                        <label>Duties</label> 
                        <input type="text" class="form-control" name="duties" value="<?php echo $duties; ?>" required="" /> 
                    </div> 
					
					<div class="form-group"> 
                        <label>Start Date</label> 
                        <input type="date" class="form-control" name="startdate" value="<?php echo $startDate; ?>" required="" />  
                        
                    </div> 
                    
					<div class="form-group"> 
                        <label>End Date</label> 
                        <input type="date" class="form-control" name="enddate" value="<?php echo $endDate; ?>" />  
                    </div> 
                    
                     
                    <div class="form-group"> 
                        <label></label> 
                        <input type="radio" name="todate" value="stillonthejob" style="width:auto" required=""/>  Still on the Job &nbsp; &nbsp; &nbsp; 
                        <input type="radio" name="todate" value="leftthejob" style="width:auto" required=""/>  Left the Job
                    </div> 
					
                    <input name="addexperience" type="submit" class="btn btn-default" value="Update Record"/> 
                </form>  
    		</div>
    		<?php
    		 }
    		?>
    </div>

</div>


<div>
<a href='?page=experience'><button class='btn'>Back to Professional Experience</button></a>
</div>