<?php
$errmsg='';
$sucmsg='';
if(isset($_POST['addexperience'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    	$employer = str_replace("'", "", $employer);
    	$position = str_replace("'", "", $position);
    	$duties = str_replace("'", "", $duties);
    	
	//update record 
	if($todate=="stillonthejob"){ $enddate="Date"; }	
		
	$qry2=mysqli_query($con, "INSERT INTO epci_experience values ('', '$applicant_idpci', '$employer', '$position', '$startdate', '$enddate', '$duties')");
	if($qry2){
		$sucmsg='Successful!';
	}else{
		$errmsg='Not Successful!';
	}
	
    
}



?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">PROFESSIONAL EXPERIENCE</h2>
Please list all employer details to date, starting with the most recent.
	<div class="graph-form">
    		<div class="form-body">
				<?php
				//GET DETAILS FROM DB
	
				$q = "Select * from epci_experience where applicant_id='$applicant_idpci'";
				$qry=mysqli_query($con, $q);
				if($qry){
					
					if(mysqli_num_rows($qry) >0){
						$myallow = 1;  //allow next button to display
						$yyy = 1;
						echo "<table border='1' width='100%'>";
						echo "<tr><td><b>SN</b></td> <td><b>Employer </b></td>  <td><b>Position </b></td>  <td><b>Duties </b></td>  <td><b>Dates</b></td> <td><b>Action</b></td> </tr> ";
						
						while($row=mysqli_fetch_assoc($qry))
						{
							extract($row);
							echo "<tr><td>$yyy</td> <td>$employer </td> <td>$position </td> <td>$duties </td> <td>$startDate to $endDate</td> <td> <form method='post' action='index.php?page=experienceeditor'><input type='hidden' value='$id' name='editID'><input type='submit' value='Edit'></form> </td></tr>";
							$yyy++;
						}
						
						echo "</tables>";
						
					}else{ $errmsg='No experience found!'; $myallow = 0; }
							
				}else{
					$errmsg='No experience found!';
					$myallow = 0;
				}
				
				?>
			
			
			
			
    			<form method="post" name="sponsorform" action="index.php?page=experience"> 
                <?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>Employer</label> 
                        <input type="text" class="form-control" name="employer" placeholder="Employer name/address" required="" />  
                    </div> 
                    
					<div class="form-group"> 
                        <label>Position Held</label> 
                        <input type="text" class="form-control" name="position" required="" /> 
                    </div> 
                    
					<div class="form-group"> 
                        <label>Duties</label> 
                        <input type="text" class="form-control" name="duties" required="" /> 
                    </div> 
					
					<div class="form-group"> 
                        <label>Start Date</label> 
                        <input type="date" class="form-control" name="startdate" required="" />  
                    </div> 
                    
					<div class="form-group"> 
                        <label>End Date</label> 
                        <input type="date" class="form-control" name="enddate" />  
                    </div> 
                    
                     
                    <div class="form-group"> 
                        <label></label> 
                        <input type="radio" name="todate" value="stillonthejob" style="width:auto"/>  Still on the Job &nbsp; &nbsp; &nbsp; 
                        <input type="radio" name="todate" value="leftthejob" style="width:auto"/ checked>  Left the Job
                    </div> 
					
                    <input name="addexperience" type="submit" class="btn btn-default" value="Add"/> 
                </form> 
    		</div>
    
    </div>

</div>

   
<div>

<?php
	  echo "<a href='?page=postgraduate'><button class='btn'>Back</button></a>";
	  echo "<a href='?page=employer'><button class='btn'>Next</button></a>"; 

?>
</div>
