 <?php include_once PUBLIC_PATH. '/files_to_include/header_content.php'; ?>
<!-- =============================================== -->

  <!-- Left side column. contains the sidebar -->
  <aside class="main-sidebar" id="aside_menu" >
      <section class="sidebar">
          <ul class="sidebar-menu">
            <?php include_once PUBLIC_PATH. '/files_to_include/menu.php'; ?>
          </ul>
      </section>
  </aside>
   <!-- Content Wrapper. Contains page content -->
   <div class="content-wrapper " style="background-color: white; td{border: solid  2px #000; }">
   

    <!-- Main content -->
    <section class="content">
          
           <div class="row">
                <div class="col-lg-offset-1 col-lg-11">
                
              <div class="row">
                <div class="col-lg-12">
                    <div id="connectheader">
	    <div class="page-header col-sm-12">                    
                <h3 ><span class="glyphicon glyphicon-edit" style="color:blue;"></span> Modifier le profil <u><?php echo $this->profil->getNom() ; ?></u></h3>
	    </div>
	</div>
        <a href='<?php echo $this->url(array('controller'=>'Profil','action'=>'index'), null , true);?>'><span class="glyphicon glyphicon-arrow-left"></span> Retour à la liste</a>
				
		<hr>
	<div class="alert " id="msg" style="display:none" >
	<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
	</div>
        <form role="form" id="form" method='post' action='' class="col-lg-12">
                <div>  
                    <div class="col-sm-5">  
                        <div class="form-group">
                            <input type="hidden" name="idProfil" value="<?php echo $this->profil->getIdProfil();  ?>" />
                            <label for="name">Donner un nom au profil:</label><label style=" color : Red;">&nbsp; *&nbsp; </label>
                            <input type="text" class="form-control" id="name" name="name" placeholder="Nom " value="<?php echo $this->profil->getNom(); ?>" required >
                        </div>                            
                    </div>
                    &nbsp; 
                </div>  
           
                <?php
                //var_dump (count($this->menus)); exit;
                 $menuDao = new MenuDAO();
                 $ligneProfilDao=new DroitDAO();
                 
                foreach ($this->menus as $parent) :
                    $listeSousMenu = $menuDao->listerSousMenus($parent);
                         if(!empty($listeSousMenu)){
                        ?>
                         
                        <div class="clearfix"></div>
                        <hr> 
                        <div class="col-sm-12" style="color:#1ab7ea;"> Menu <?php echo utf8_encode($parent->getNom()); ?> 
                             (Cocher tout <input type="checkbox" class="checkall" concerne="<?php echo $parent->getIdMenu();?>" />)</div>
                       
                             <div class="clearfix"></div>
                       
                        <?php
                        //liste des sous menus du menu
                        $listeSousMenu = $menuDao->listerSousMenus($parent);
                        foreach ($listeSousMenu as $elt1):
                                    ?><div class="col-sm-3">  
                                        <div class="form-group" align="right">
                                            <label for="name"><?php echo utf8_encode($elt1->getNom()); ?></label>  
                                        </div>                            
                                    </div>  
                                    <div class="col-sm-9">  
                                        <div class="form-group ">
                                            <?php 
                                               //on verifie s'il a le droit et on coche' 
                                                 if($ligneProfilDao ->droitMenu($this->profil->getIdProfil(), $elt1->getIdMenu())==true)
                                                         $checked="checked";
                                                 else $checked="";
                                                         
                                            ?>
                                            
                                            <input type= 'checkbox' id="checkbox_<?php echo $elt1->getIdMenu(); ?>" <?php echo $checked; ?> class="checkin" concerne="<?php echo $parent->getIdMenu();?>"  onclick="cocherun('<?php echo $elt1->getIdMenu(); ?>')"  value="<?php echo $elt1->getIdMenu(); ?>" name="checkbox_<?php echo $elt1->getIdMenu(); ?>" />
                                        </div>                            
                                    </div>  
                                    <div class="clearfix"></div>
                                   
                                <?php
                        endforeach;
                         
                    ?> 
                    <?php
                         }
                endforeach;
                ?>  
                <div class="clearfix"></div>
                <hr>           
                <div class="col-sm-12">
                    <button type="submit" id="submission" name="submit" class="btn btn-microsoft">Modifier le profil <span><?php echo $this->profil->getNom(); ?></span></button>
                </div>   
                <div class="clearfix"></div>
            </form>
            </div>
          
          <!-- /.nav-tabs-custom -->
        </div>
     

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
 <?php include_once PUBLIC_PATH. '/files_to_include/footer_content.php'; ?>
 
 <script src="<?php echo $this->baseUrl('script/jquery-2.2.3.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('script/bootstrap.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('script/app.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('script/metisMenu.min.js');?>"></script>
    <script src="<?php echo $this->baseUrl('script/sb-admin-2.js');?>"></script>
    <script src="<?php echo $this->baseUrl("script/jquery.dataTables.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/dataTables.bootstrap.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/dataTables.buttons.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/jszip.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/pdfmake.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/vfs_fonts.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/buttons.html5.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/buttons.print.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl("script/jquery-confirm.min.js");?>"></script>
    <script src="<?php echo $this->baseUrl('script/jquery.toast.min.js');?>"></script> 
    <script src="<?php echo $this->baseUrl('script/loadingoverlay.min.js');?>"></script>
    <script type="text/javascript">
     
        $(document).ajaxSend(function(event, jqxhr, settings){
            $.LoadingOverlay("show");
        });
        
        $(document).ajaxComplete(function(event, jqxhr, settings){
            $.LoadingOverlay("hide");
        });

    
    
   
          
   
            $("#form").submit(function(e) {
                e.preventDefault();
                $("#submission").hide();
                $tdata = $("#form").serialize();
                $.ajax({
                    url: "<?php echo $this->url(array('controller' => 'Profil', 'action' => 'editer')); ?>",
                    data: $tdata, // {name: name, tableauIdL: tableauIdL, tableauIdE: tableauIdE},
                    cache: false,
                    type: "POST",
                    dataType: "json",
                    error: function(request, error) { // Info Debuggage si erreur         
                        alert("Erreur : responseText: " + request.responseText);
                        $("#submission").show();
                    },
                    success: function(data) {
                        // Informe l'utilisateur que l'opération est terminée et renvoie le résultat
                       $("#submission").show("slow");
                        var top = $("#submission").offset().top;
                        var left = $("#submission").offset().left;
                         
                        if (data.msg == 0) {
                           $.toast({
                               heading : "statut",
                               text : data.msg1,
                               hideAfter : false,
                               stack: false,
                               icon : "error",
                               position : { top : top , left : left }
                           });
                            
                            //document.getElementById("login").value=''; 
			     window.location.replace("<?php echo $this->url(array('controller' => 'Profil', 'action' => 'index')); ?>");
                        } else {
                           $.toast({
                               heading : "statut",
                               text : data.msg1,
                               hideAfter : false,
                               stack : false,
                               icon : "success",
                               position : { top : top , left : left }
                           });
                           $("#resetBtn").trigger("click");
                            //window.location.replace("<?php // echo $this->url(array('controller' => 'Utilisateur', 'action' => 'index')); ?>");
                        }
                    },
                    complete: function() { // Info Debuggage si erreur         
                        //$("#loadueclass").removeClass("fa fa-spinner fa-spin");
                    }
                });
                //---
                return false;
            });
            
            $(".checkall").on("click", function() {
            var $allCheck = $(".checkin[concerne='" + $(this).attr("concerne") + "']");
            for (var i = 0; i < $allCheck.length; i++) {
                if ($(this).prop('checked')) {
                    $allCheck.eq(i).prop('checked', true);
                } else {
                    $allCheck.eq(i).prop('checked', false);
                }
            }
            });
           
	</script>

</body>

</html>