 <?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 roles</h3>
                    <a href='<?php echo $this->url(array('controller'=>'Role','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-6">  
                        <div class="form-group">
                            <label for="name">Nom du role:</label><label style=" color : Red;">&nbsp; *&nbsp; </label>
                            <input type="text" class="form-control" id="name" name="name" placeholder="Nom " value="" required>
                        </div>                            
                    </div>
                    <div class="col-sm-6">  
                        <div class="form-group">
                            <label for="name">Description du role:</label><label style=" color : Red;">&nbsp; *&nbsp; </label>
                            <input type="text" class="form-control" id="description" name="description" placeholder="Description " value="" required>
                        </div>                            
                    </div>
                    &nbsp; 
                </div>  
            
                <?php
                
                 $authDao = new AuthorisationDAO();
                 
                foreach ($this->auths as $parent){
                         $listeSousAuth = $authDao->listerSousAuths($parent);
                         //var_dump (count($listeSousAuth)); exit;
                         if(!empty($listeSousAuth)){
                        ?>
                         
                        <div class="clearfix"></div>
                        <hr> 
                        <div class="col-sm-12" style="color:#1ab7ea;"><?php echo utf8_encode($parent->getLabel()); ?> 
                             (Check All <input type="checkbox" class="checkall" concerne="<?php echo $parent->getCode();?>" />)
                       
                             <div class="clearfix"></div>
                       
                        <?php
                       
                       
                        foreach ($listeSousAuth as $elt1):
                                    ?><div class="col-sm-6">  
                                        <div class="form-group" align="right">
                                            <label for="name"><?php echo utf8_encode($elt1->getLabel()); ?></label>  
                                        </div>                            
                                    </div>  
                                    <div class="col-sm-6">  
                                        <div class="form-group">
                                            <input type= 'checkbox' id="checkbox_<?php echo $elt1->getCode(); ?>" class="checkin" concerne="<?php echo $parent->getCode();?>"  onclick="cocherun('<?php echo $elt1->getCode(); ?>')"  value="<?php echo $elt1->getCode(); ?>" name="checkbox_<?php echo $elt1->getCode(); ?>" />
                                        </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 Role </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' => 'Role', '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>