<style>
    
#def{
  display:none;
}
#hide_cls{
  display:none;
}
.required{
        color:#bf5050;
    }
#new_type{
    disabled:false !important;
}
</style>  

        <!-- page content -->
        <div class="right_col" role="main">
            <!-- page add content -->
            <div class="">
            <div class="page-title">
                <div class="title_left">
                    
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
               
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title" id="scroll">
                       <h2 style="float:left;">Section View</h2>
                     <input id="add_cls" class="btn btn-success" style="margin-left:30%;" value="Add Section"  type="button">
                    <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">
                      <div id="def">
                    <form class="form-horizontal form-label-left" id="myform" action="" method="post">

                    <?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="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="branch" class="form-control col-md-7 col-xs-12" name="branch" required="required" style="width: 100%;">
                            <option value=''>Select branch</option>
                      <?php
                            $branch = $this->db->select("name,id")->from("branch")->get()->result(); 
                            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="name">Class<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="class_id" id="class_id"  class="" required="required" style="width: 100%;height: 40px;">
                                <option value="">Select Class</option>
                            </select>  
                        </div>
                      </div>
                      
                          <input type="hidden" name="edit_id" id="edit_id">
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="des">Section Name<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="section_name" class="form-control col-md-7 col-xs-12"  name="section_name" placeholder="Section Name" required="required" type="text" pattern="[A-Za-z]{1,10}" title="only Alphabatic letters">
                          
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="des">Description
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <textarea id="description" class="form-control col-md-7 col-xs-12" name="description"></textarea>
                        </div>
                      </div>
                      <div style=" margin-left:200px;color:red;"><h4>  <?php @$e=$_GET['error']; echo @$e; ?><h4></div>
        <div style=" margin-left:200px;color:green;"><h4>  <?php @$s=$_GET['status']; echo @$s; ?><h4></div> 
                      
                      
                     <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                            <a href="<?php echo base_url();?>Section"><input id="hide_cls" class="btn btn-danger " value="Cancel"  type="button" style="float:right;"></a>
                         <button id="new_type" type="submit" value="Add" class="btn btn-success" style="float:right;">Save</button>
                         
                        </div>
                      </div>
                    </form>
                    
                      </div>
                   

                    <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                      <thead>
                        <tr>
                          <th> # </th>
                          <th>Section Name</th>
                          
                          <th>Description</th>
                          <th>Class</th>
                          <?php if($is_super){ ?>
                          <th>Branch</th>
                          <?php } ?>
                          <th>Actions</th>
                          
                          
                        </tr>
                      </thead>


                      <tbody class="center">
                        
                      </tbody>
                    </table>
                   
                      

                  </div>
                </div>
              </div>

            </div>
          </div>
        </div>
        </div>

        <!-- /page content -->

        <!-- footer content -->
        <footer>
          <div class="pull-right">
            Prudmac
          </div>
          <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
        <div id='ajaxload' style='position:fixed;top:0;left:0;bottom:0; width:100%;height:100%;z-index:1000;background:rgba(2,132,130,0.5);display:none;'>
            <i class='fa fa-spinner fa-spin fa-4x' style='position: relative;top: 50%;left: 60%;margin-top: -50px;margin-left: -40px;'></i>
        </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>

    <!-- Datatables -->
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/jszip/dist/jszip.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/vfs_fonts.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <!--Notify-->
    <script  src="<?php echo base_url(); ?>assets/js/notify.js"></script>

    <!-- Datatables -->
    <!-- Datatables -->
    <!-- Form Validator -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/bootstrapValidator.js"></script>
<!-- Form Validator-->
  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrapValidator.css"/>
    
<script src="<?php echo base_url()?>assets/select/js/select2.min.js"></script>
<script>

    $('#class_id').select2({
     $('#class_id').val('').trigger('change.select2');
    allowClear: true

    });
</script>    
    
    
<script type="text/javascript">
    $(document).ready(function() {
        $('#routePermit')
            .on('init.form.bv', function(e, data) {
                //console.log(data);
            })
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    class_id: {
                        trigger:'blur',
                        validators: {
                            notEmpty: {
                                message: 'Please select Class'
                            }
                        }
                    },
                    
                    section_name: {
                        trigger:'blur',
                        validators: {
                            notEmpty: {
                                message: 'Please Enter Section Name'
                            }
                        }
                    },
                
                   
                }
            });
    });
    
$("#zzz").click(function(){
   $('#routePermit').bootstrapValidator("resetForm",true);    
});
$(document).ready(function(){
    $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });

   $.ajax({
    url: '<?php echo base_url(); ?>Section/fetch_section/',data: {},
         success: function (result) {
             
 $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
             //alert('test');
              $("#datatable-buttons").dataTable().fnDestroy();
               setTimeout(function(){ 
               $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
            },500);
           }
           
     });//end ajax for loading form


});
</script>
</script>
    
    
    <!-- /Datatables -->

    <script>
        $(document).ready(function(){
            var value = $('#branch').val();
                $.get("<?php echo base_url(); ?>load/classs/role/"+value,{},function(d){
                    var pre = '<option value="">Select Class</opiton>';
                    $("#class_id").html(pre+d);
            });
        });
        $(document).on("change","#branch",function(){
            var value = $(this).val();
            $.get("<?php echo base_url(); ?>load/classs/role/"+value,{},function(d){
                var pre = '<option value="">Select Class</opiton>';
                $("#class_id").html(pre+d);
            });
          });

    </script>
<script>
function edit(id,event){
  event.preventDefault();
  $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
  $.ajax({
     url: '<?php echo base_url(); ?>Section/get_record/'+id,
         success: function (result)
          { 
        $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
           //alert('true');
            var obj=JSON.parse(result);
           $("#edit_id").val(obj.section_id);
            $("#class_id").val(obj.class_id);
            $("#section_name").val(obj.section_name);
            $("#description").val(obj.description);
            $('#section_name').attr("data-id",obj.section_id);
            $("#new_type").val("Update");
            $("#new_type").html('Update');
             $('#def').show();
           $('#hide_cls').show();
        $('#add_cls').hide();
        $("button[type=submit]").prop("disabled",false);
            
        
         $('html, body').animate({
        scrollTop: $("#scroll").offset().top
    }, 1000);
            //$("tbody.center").html(result);
            }
      });
}
</script>   
    
    <script>
      $(document).ready(function() {
        var handleDataTableButtons = function() {
          if ($("#datatable-buttons").length) {
            $("#datatable-buttons").DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
          }
        };

        TableManageButtons = function() {
          "use strict";
          return {
            init: function() {
              handleDataTableButtons();
            }
          };
        }();

        TableManageButtons.init();
      });
     </script>
    <!-- /Datatables -->

  <script>
   $(document).ready(function() {
$("#add_cls").click(function(event){
 $('#def').show();
 $('#hide_cls').show();
 $('#add_cls').hide();
});
});
</script>
 <script>
   $(document).ready(function() {
$("#hide_cls").click(function(event){
 $('#def').hide();
 $('#hide_cls').hide();
 $('#add_cls').show();
});
});
</script>
<script>
   $(document).ready(function() { 
    $("#new_type").click(function(event){
  event.preventDefault();
   $('#def').hide();
 $('#hide_cls').hide();
 $('#add_cls').show();
  var value=$("#new_type").val();
  var name1=$("#class_id").val();
  var name=$("#section_name").val();
  var des=$("#description").val();
  if(des === ''){
      des = '-';
  }
  var branch=$("#branch").val();
if(name1=="" ||name=="" ||  branch=="")
  {
    alert("Please fill the fields");
    $('#def').show();
 $('#hide_cls').show();
 $('#add_cls').hide();
    return false;
    
  }
if(value=="Add")
{
   //alert(name1); 
   $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
$.ajax({
 url:'<?php echo base_url();?>section/save_cls/'+name1+'/'+name+'/'+des+'/'+branch,data:{},
        success: function (result) {
 $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
        $.notify("Successfully Added..", "success");
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
            },500);
           }
    });
$("#new_type").val("Add");
$("#class_id").val("");

 $("#section_name").val("");
 $("#description").val("");

}
else if(value=="Update")
{
  var id=$("#edit_id").val();
  var up_name1=$("#class_id").val();
  var up_name=$("#section_name").val();
  var up_des=$("#description").val();
  $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
  $.ajax({
    url:'<?php echo base_url()?>section/up_cls/'+id+'/'+up_name1+'/'+up_name+'/'+up_des, data:{},
    success: function (result) {
        
        $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
             $.notify("Successfully Updated..", "success");
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
            },500);
           }
  });
  $("#new_type").val("Add");
  $("#new_type").html('Add');
  $("#class_id").val("");
 
 $("#section_name").val("");
 $("#description").val("");
//  $("#myform").reset();
}
});//end if for button type checking
});
</script>
<script>
   
function active(id,event){
event.preventDefault();
$(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
  $.ajax({
     url: '<?php echo base_url(); ?>section/cl_active/'+id,
      success: function (result) {
            $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
            $.notify("Successfully Activated..", "info");
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
            },500);
           }
      });
}
</script>
<script>
   
function deactive(id,event){
event.preventDefault();
        $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });

  $.ajax({
     url: '<?php echo base_url(); ?>section/cl_deactive/'+id,
      success: function (result) {
          $(document).ajaxStop(function() {
           $('#ajaxload').hide();
      });
        $.notify("Successfully Deactivated..", "info");
           $("#datatable-buttons").dataTable().fnDestroy();
           setTimeout(function(){ 
                $("tbody.center").html(result);
                $('#datatable-buttons').DataTable({
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                    },
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  exportOptions: {
                    columns: [ 0, 1, 2, 3 ]
                },
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
            },500);
           }
      });
}
</script>
  </body>
</html>