<?php $__env->startSection('contenu'); ?>
    <div class="navbar-fixed">
        <nav>
            <div class="nav-wrapper">
                <div class="col s12">
                    <a href="/privileges" class="breadcrumb">Gestion Privilege</a>
                
                <ul id="nav-mobile" class="right hide-on-med-and-down">
             <li><a href="/">Home</a></li>
           </ul> 
           </div>
            </div>
        </nav>
    </div>
    
    <div class="container">
       
       
            
           <!-- Medecin Observateur !-->
                <div id="MO" class="section scrollspy">
                    <br>
                    <br>
                    <h4 class="light-blue-text text-darken-1 center">Liste des Enseignant</h4>

                    <div class="input-field">
                        <input id="search" type="search" >
                        <label for="search"><i class="material-icons">search</i></label>
                    </div>
                    <table class="highlight">

                        <thead class="thead">
                        <tr>
                            <th data-field="cin">CIN</th>
                            <th data-field="nom">Nom</th>
                            <th data-field="prenom">Prenom</th>
                            <th></th>

                        </tr>
                        </thead>


                        <tbody class="tbody" id="med">

                        <?php foreach($enseignants as $enseignant): ?>
                           <tr id=<?php echo $enseignant->id_Enseignant."css"; ?> class="ens" >
                           
                                <td><?php echo $enseignant->CIN; ?></td>
                                <td><?php echo $enseignant->nom; ?></td>
                                <td><?php echo $enseignant->prenom; ?></td>
                            
                            </tr>
                        <?php endforeach; ?>

                        </tbody>
                    </table>
                </div>
                

 <!-- Modal Structure -->
  <div id="modal1" class="modal modal-fixed-footer">
    <div class="modal-content">
      <h5 id="nom_enseignant"><!-- Nom Enseignant !-->Nom Prenom</h5>
       <form  method="post">
              <?php echo csrf_field(); ?>

       <table class="highlight">

                        <thead class="thead">
                        <tr>
                          
                            <th data-field="nom">Privilege</th>
                            <th></th>

                        </tr>
                        </thead>


                        <tbody class="tbody" id="med">

                        <?php foreach($privileges as $privilege): ?>
                            <tr id=<?php echo $privilege->id_Privilege.'t'; ?> >
                                <td><?php echo $privilege->nom; ?></td>
                               
                                <td>
                                    <input type="checkbox" value="yes"
                                           name=<?php echo $privilege->id_Privilege.""; ?> id=<?php echo $privilege->id_Privilege.""; ?> />
                                    <label for=<?php echo $privilege->id_Privilege; ?> >Check</label>
                                </td>
                            </tr>
                        <?php endforeach; ?>

                        </tbody>
                    </table>
                      <input type="submit" value="done" class="waves-effect waves-light btn" />
  </form>
    </div>
    <div class="modal-footer">
    </div>
  
   
          
                 
  
     </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.scrollspy').scrollSpy();
        });
       
        $(document).ready(function () {
            $('.tooltipped').tooltip({delay: 50});
        });
        $(document).ready(function () {
            $('select').material_select();
        });
        $(document).ready(function() {
             <?php  echo "var enseignants = ".$enseignants."\n";?>
             $(".ens").click(function(event) {

                var id_Enseignant = $(this).attr('id');
                var id_Enseignant =id_Enseignant.substr(0,id_Enseignant.indexOf('css'))
                $('form').attr('action',"privileges/"+id_Enseignant+"/edit");
                $('#nom_enseignant').text(enseignants[parseInt(id_Enseignant)-1]['nom']+" "+enseignants[parseInt(id_Enseignant)-1]['prenom']);
                //Dans cette partie on parcourus le tableau en cochant chaque privilege de l'enseignant
                $('#modal1').openModal();
                
                 
                
            });
        });
 


    </script>
    <script type="text/javascript">

        <?php  echo "var enseignants = ".$enseignants."\n";?>
        var $_token = $('input[name=_token]').val();
        $(function () {
              function verif(id_Enseignant,data){
                for(i=0;i<data.length;i++){
                    if(id_Enseignant==data[i]['id_Enseignant']){
                        return true;
                    }
                }
                return false;
            }
            //A chaque changement du input search il va une requéte ajax 
            $('#search').on('input', function () {
                var rech = $('#search').val();
                $.ajax({
                    url: "privileges/show",
                    type: "post",
                    dataType : 'json' ,
                    data: {'_token': $_token, 'rech': rech},
                    success: function (data) {

                        for(var i=0;i<enseignants.length;i++){
                            
                            if(verif(enseignants[i]['id_Enseignant'],data)){
                                $('#'+enseignants[i]['id_Enseignant']+"css").css('display','table-row');
                            }else {
                                $('#'+enseignants[i]['id_Enseignant']+"css").css('display','none');
                            }
                        }
                   
                     
                    }
                });
            });

        });
    </script>

<?php $__env->stopSection(); ?>


<?php echo $__env->make('template', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>