<?php
if(!isset($_SERVER['HTTP_REFERER'])){
    // redirect them to your desired location
    header('location:../index.php');
    exit;
}
?>
<div class="row" id="table1">
	<div class="col-md-10">
    	<div class="box">
        	<div class="box-header">
            	<a href="#modalInsertform" onClick="showModal(this)" class="btn btn-success btn-sm pull-right" data-id="<?php echo $row["id"]; ?>" data-toggle="modal">Ajouter <span class="glyphicon glyphicon-plus"></span></a>
                 <h3 class="box-title">Affectation des module de tous les enseignants </h3>
            </div><!-- /.box-header -->
            <div class="box-body table-responsive">
				<table id="example1" class="table table-bordered table-striped">
                	<thead>
                                <th class="col-md-1">N°</th>
                                <th class="col-md-1">Spécialisation</th>
                                <th class="col-md-4">Module</th>
                                <th class="col-md-3">Enseignant</th>
                                <th class="col-md-1">Heurs(h)</th>
                                <th class="col-md-2">Action</th>
                     </thead>
                     <tbody>
<?php
include_once('../controller/config.php');

$sql="select affectation_module.id as sr_id,affectation_module.fee as s_fee,affectation_module.anneeId as g_name,modules.Designation as s_name,teacher.i_name as t_name
	  from affectation_module
      inner join modules
      on affectation_module.moduleId=modules.moduleId 
      inner join teacher
      on affectation_module.ensignaintId=teacher.id";
$result=mysqli_query($conn,$sql);
$count = 0;
$current_date_number=date("d");

if(mysqli_num_rows($result) > 0) {
	while($row=mysqli_fetch_assoc($result)){
		
		$count++;
		$sr_id=$row['sr_id'];
?>   
    
                        <tr>
                           	<td><?php echo $count; ?></td>
                            <td id="td1_<?php echo $row['sr_id']; ?>"><?php echo $row['g_name']; ?></td>
                            <td id="td2_<?php echo $row['sr_id']; ?>"><?php echo $row['s_name']; ?></td>
                            <td id="td3_<?php echo $row['sr_id']; ?>"><?php echo $row['t_name']; ?></td>
                            <td id="td4_<?php echo $row['sr_id']; ?>"><?php echo $row['s_fee']; ?></td>
                            <td>             
<?php
$sql1="SELECT * FROM student_subject WHERE sr_id='$sr_id'";

$result1=mysqli_query($conn,$sql1);

if(mysqli_num_rows($result1) > 0) {
	
	echo '<a href="#" id="edit1_sfee_'.$count.'" onClick="editSubjectFee(this)" class="btn btn-warning btn-xs cant-edit" data-id="'.$sr_id.','.$count.','.$row["s_fee"].'" >Modifier les heures</a>';

}else{
	
	echo '<a href="#modalUpdateform" id="edit_sfee_'.$count.'" onClick="showModal(this)" class="btn btn-info btn-xs" data-id="'.$sr_id.','.$count.'" data-toggle="modal">Modifier</a>';  
	echo ' <a href="#" class="confirm-delete btn btn-danger btn-xs" id="delete_sfee_'.$count.'" data-id="'.$sr_id.'">Supprimer</a>'; 
                                            	
}

if($current_date_number > 5){
	//disabled
	echo "<script>$('.cant-edit').addClass('disabled');</script>";
}

?>       

                        	</td>
                    	</tr>
<?php } } ?>
                	</tbody>
				</table>	
    		</div>
     	</div>
	</div>
</div>

        

       
       

