                    <style>
            .per-table td {
                padding: 5px 5px;
            }
            
            .sub-submenu {
                margin-left: 50px;
            }
        </style>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
               
              </div>
            </div>

            <div class="clearfix"></div>
            <form action="<?php echo base_url(); ?>admin/permission/assign" method="post">
            <div class="row">

              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Permission</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                        
                          <?php if($this->user_model->is_super()){ ?>
                     <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Branch <span class="text-danger">*</span>
                        </label>
                        <div class="col-md-12 col-sm-12 col-xs-12">
                          <select id="branch" class="form-control col-md-7 col-sm-9 col-xs-12" name="branch" required="required">
                            <option value=''>Select branch</option>
                            <option value='0'>Super Branch</option>
                      <?php
                            foreach ($branch as $value) {
                      ?>
                            <option value="<?php echo $value['id']; ?>"><?php echo $value['name']?></option>

                      <?php } ?>
                          </select>
                        </div>
                      </div>
                      <?php }else{$branch=$this->user_model->getbranch();?>
                          <input id="branch" name="branch" type="hidden" value="<?= $branch ?>">
                      <?php  } ?>
                      

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="role">Role <span class="required">*</span>
                        </label>
                        <div class="col-md-12 col-sm-12 col-xs-12">
                          <select id="role" class="form-control col-md-7 col-xs-12" name="role" required="required">
                           <option value="">Select Role</option>
                          </select>
                        </div>
                      </div>

                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" id="all"> All
                                    </label>
                                </div>
                                <hr>
                            </div>
                            <button class="btn btn-success pull-right" type="submit">Save</button>
                        </div>
                  </div>
                  <!-- /x-panel body -->
                </div>
                <!-- /x-panel -->
              </div>
              <!-- /.col end -->
            </div>
            <!-- /.row end -->
            <div id="permision_wrapper">
                <?php
           
                    echo $per_menu;
                ?>
            </div>
            </form>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        <footer>
          <div class="pull-right">
            Prudmac
          </div>
          <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.min.js"></script>
    <!-- Custom JS -->
    <script src="<?php echo base_url(); ?>assets/js/main.js"></script>
    <!-- Bootstrap -->
    <script src="<?php echo base_url(); ?>assets/vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo base_url(); ?>assets/vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="<?php echo base_url(); ?>assets/vendors/nprogress/nprogress.js"></script>
    <!-- Chart.js -->
    <script src="<?php echo base_url(); ?>assets/vendors/Chart.js/dist/Chart.min.js"></script>
    <!-- gauge.js -->
    <script src="<?php echo base_url(); ?>assets/vendors/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="<?php echo base_url(); ?>assets/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="<?php echo base_url(); ?>assets/vendors/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="<?php echo base_url(); ?>assets/vendors/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.pie.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.time.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.stack.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="<?php echo base_url(); ?>assets/js/flot/jquery.flot.orderBars.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/date.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/jquery.flot.spline.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/flot/curvedLines.js"></script>
    <!-- jVectorMap -->
    <script src="<?php echo base_url(); ?>assets/js/maps/jquery-jvectormap-2.0.3.min.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="<?php echo base_url(); ?>assets/js/moment/moment.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/datepicker/daterangepicker.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="<?php echo base_url(); ?>assets/build/js/custom.min.js"></script>
  <!-- Select2 -->
    <script src="<?php echo base_url(); ?>assets/vendors/select2/dist/js/select2.min.js"></script>
<script>
 <?php if($this->user_model->is_super()){ ?>
    $("#branch").select2();
    $(document).ready(function(){
 
});
 <?php } ?>          
</script>
<script>
    $("#role").select2();
    $(document).ready(function(){
 var userid = $('#role').val();
});
           
</script>
    <script>
      $(document).on("change","#branch",function(){
        var branch = $(this).val();
        if(branch){
          $.ajax({
            url: '<?= base_url(); ?>/load/setRoles/',
            type: 'POST',
            data: {'branch' : branch},
            success:function(d){
              $('#role').html(d);
            },
            error:function(){
              alert('Error occur...!!');
            }
          });
        }
      });
    $(function(){
        var branch = $('#branch').val();
        if(branch){
          $.ajax({
            url: '<?= base_url(); ?>/load/setRoles/',
            type: 'POST',
            data: {'branch' : branch},
            success:function(d){
              $('#role').html(d);
            },
            error:function(){
              alert('Error occur...!!');
            }
          });
        }
      });
    </script>
    
    <script>
        $(document).ready(function(){
            $(document).on("change","#role",function(){
                var value = $(this).val();
                $.get("<?php echo base_url(); ?>load/per_menu/"+value,{},function(d){
                    $("#permision_wrapper").html(d);
                });
            });
            // $(document).on("change","#user",function(){
            //     var value = $(this).val();
            //     $.get("<?php echo base_url(); ?>load/per_menu/"+value,{},function(d){
            //         $("#permision_wrapper").html(d);
            //     });
            // });
            
        });
$('#all').click(function() {   
                if ($(this).is(':checked')) {
                    $(".sub_menu").prop( "checked", true );
                } else {
                    $(".sub_menu").prop( "checked", false );
                }
            });
$(document).on('click',"input[class='sub_menu _module']",function() {
var val = '.'+$(this).attr('id');   

                if ($(this).is(':checked')) {
                    //alert(".selSub_"+$(this).attr('id'));
                    $(".selSub_"+$(this).attr('id')).prop("checked",true);
                    $(""+val+"").prop( "checked", true );
                } else {
                    $(".selSub_"+$(this).attr('id')).prop("checked",false);
                    $(""+val+"").prop( "checked", false );
                }
            });
    </script>

  </body>
</html>