 <?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="col-lg-12">
                   
                    <h3 class="page-header"><i class="fa fa-plus" style="color:blue;"></i> Création des profils</h3>
                    <a href='<?php echo $this->url(array('controller'=>'Profil','action'=>'index'),null, true);?>'>Retour à la liste</a>
                    <div class="clearfix"></div>
                    <br>
                </div>
                <form role="form" id="form" method='post' action='' class="col-lg-12">
                <div>  
                    <div class="col-sm-5">  
                        <div class="form-group">
                            <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="" 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 class="clearfix"></div>
                       
                        <?php
                        //liste des sous menus du menu
                        $listeSousMenu = $menuDao->listerSousMenus($parent);
                       
                        foreach ($listeSousMenu as $elt1):
                                    ?><div class="col-sm-4">  
                                        <div class="form-group" align="right">
                                            <label for="name"><?php echo utf8_encode($elt1->getNom()); ?></label>  
                                        </div>                            
                                    </div>  
                                    <div class="col-sm-4">  
                                        <div class="form-group">
                                            <input type= 'checkbox' id="checkbox_<?php echo $elt1->getIdMenu(); ?>" 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;
                        
                    ?>
                      </div>               
                    <?php
                }
                }
                
                ?> 
                                 
                <div class="clearfix"></div>
                <hr>           
                <div class="col-sm-12">
                    <button type="submit" id="submission" name="submit" class="btn btn-microsoft">Créer le profil </button>
                </div> 
                <br>
                <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/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/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' => 'enregistrer')); ?>",
                    data: $tdata, // {name: name, tableauIdL: tableauIdL, tableauIdE: tableauIdE},
                    cache: false,
                    method: "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 == 1) {
                           $.toast({
                               heading : "statut",
                               text : data.msg1,
                               hideAfter : false,
                               stack: false,
                               icon : "error",
                           });
                            
                            //document.getElementById("login").value=''; 
			    // window.location.replace("<?php // echo $this->url(array('controller' => 'Utilisateur', '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>