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

 if(isset($_GET["i"])){
		$applicant_idgdef = $_GET["i"];
	}

//delete
if(isset($_GET['r'])){
	extract($_GET);
	//print_r($_GET);
	
	$q_delete = "delete from prob_experience where applicant_id='$applicant_idgdef' AND id='$r' LIMIT 1";
	$qry_delete = mysqli_query($con, $q_delete);
	if($qry) { $sucmsg='Record deleted successfully'; }
}//end of delete


if(isset($_POST['addexperience'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
	//update record 
	if($todate=="stillonthejob"){ $enddate="Date"; }	
		$employer = str_replace("'", "\'", $employer);
		$position = str_replace("'", "\'", $position);
		$duties = str_replace("'", "\'", $duties);
		
		
	$qry2=mysqli_query($con, "INSERT INTO prob_experience values ('', '$applicant_idgdef', '$employer', '$position', '$startdate', '$enddate', '$duties', '$nature')");
	if($qry2){
		$sucmsg='Add another record below!';
		
		?>
		<script>
		if (window.alert("Record saved successfully");) { 
		   //window.location ="http://niqs.org.ng/onlineapplication/gdefull/index.php?page=sponsor";
		}
		</script>
		
		<?php
		
		
	}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 prob_experience where applicant_id='$applicant_idgdef'";
				$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>Nature of Business</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 <a href='?page=experience&r=$id&i=".$_GET['i']."'><font color='red'>delete</font></a> </td> <td>$nature</td> <td>$position </td> <td>$duties </td> <td>$startDate to $endDate</td> <td> <form method='post' action='index.php?page=experienceeditor&i=".$_GET['i']."'><input type='hidden' value='$id' name='editID'><input type='submit' value='Edit'></form> </td> </tr>";
							$yyy++;
						}
						
						echo "</tables>";
						
					}else{ $errmsg=''; $myallow = 0; }
							
				}else{
					$errmsg='';
					$myallow = 0;
				}
				
				?>
			
			
			
			
    			<form method="post" name="experienceform" action="index.php?page=experience&i=<?php echo $_GET['i']; ?>"> 
                <?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>Nature of Business</label> 
                        <input type="text" class="form-control" name="nature" 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=exemption&i=".$_GET['i']."'><button class='btn'>Back</button></a>";


if($myallow != 0){ echo "<a href='?page=sponsor&i=".$_GET['i']."'><button class='btn'>Next</button></a>"; }
?>

</div>