<?php
$errmsg='';
$sucmsg='';
if(isset($_POST['add'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
		//update record
		
   for($i=6; $i<11; $i++)
   {
		$gname_update = "ex".$i;
		$mycourse = "course".$i;
		
		if(isset($_POST[$gname_update])){
			//echo "<br>Course ".$i." = ".$_POST[$gname_update];
			if($_POST[$gname_update] == "on"){ $newvalue = "1"; }else{ $newvalue = "0";}
		}else{ $newvalue = "0";}
		
		$qry2=mysqli_query($con, "update tpcf_exemption SET $mycourse='$newvalue' where applicant_id='$applicant_id'");
   }
}


?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">PATICULARS OF EXEMPTION  </h2>
	<div class="graph-form">
    		<div class="form-body">
			
    			<form method="post" name="exemptionform" action="index.php?page=exemption2"> 
                <?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>GDE Courses</label>
						<br>Tick as appropriate
                        <?php
						 $q = "select * from exemptioncourse where exam='GDE'";
						 $r = mysqli_query($con, $q);
						 $cx = 6;
						 
						//check old option
						$q2 = "select * from tpcf_exemption where applicant_id='$applicant_id'";
						$r2 = mysqli_query($con, $q2);
						$row2 = mysqli_fetch_array($r2);
						//extract($row2);
						//echo print_r($row2);
						
						echo "<table border='0'>";
						while($row=mysqli_fetch_assoc($r))
						{
							$gname = "ex".$cx;
							extract($row);
							
							$mycell = "course".$cx;
							$sel='';
							if($row2[$mycell]=="1"){ $sel = "checked"; }
							
							echo '<tr><td> <input type="checkbox" name="'.$gname.'" style="height:30px; padding:0px; width:30px" '.$sel.' />';
							echo '&nbsp; &nbsp; <td>'.strtoupper($exam).' - '.strtoupper($course);
							
							echo '</td></tr>';
							$cx++;
						}
							echo "</table>";
						
						?>
						
						
                    <input name="add" type="submit" class="btn btn-default" value="Update Course"/> 
                </form>  
    		</div>
    
    </div>

</div>

<div>
<a href='?page=exemption'><button class='btn'>Back</button></a>
<a href='?page=experience'><button class='btn'>Next</button></a>
</div>