       
           <style>
    .required{
        color: #bf5050;
    }
    
</style>  
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3></h3>
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Add Subject</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">


                    <form class="form-horizontal form-label-left" action="<?php echo $base_url; ?>subject/savesub" method="post">
                        <?php 
                       if(!$this->user_model->is_super()){
                            ?>
                        <input type="hidden" name="branchid" value="<?php echo $branch; ?>" id="branch_id"  /><?php 
                        }else{?>
                      <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 class="form-control" name="branch" id="branch">
                                      <option value="">Select Branch</option>
                                       <?php      
                               
                             foreach ($branch as $key => $value) {
                                
                  ?>
                    <option value="<?php echo $value['id']; ?>"><?php echo $this->user_model->limitText($value['name'], 8);?></option>

                  <?php } ?>
                                 </select> 
                           </div>
                      </div>
                       <?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 class="form-control" name="class" id="class">
                                      <option value="">Select Class</option>
                            
                                 </select>                    
                        </div>
                      </div>    
                       <div class="item form-group" id="msg" style="display:none;">
                           <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name"> 
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="msgfield" style="background-color:#e86d6d; color:white;" class="form-control col-md-7 col-xs-12" value="Sorry! This Subject name already exists!"  name="msg" type="text" readonly>
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="b_head">Name<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="b_head" class="form-control col-md-7 col-xs-12 abc1" maxlength="25" onKeyup="myFunction()" name="subname" placeholder="Subject Name...." required="required" type="text">
                        </div>
                      </div>
                      
                      
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <input id="send" type="submit" disabled="true" class="btn btn-success pull-right" value="Save" />
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
             
              </div>
                <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>View Added Subject</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">
                      
                    <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Name</th>
                          <th>Class</th>
                         
                          <th>Actions</th>
                        </tr>
                      </thead>


                      <tbody class="center">
                        <?php $i=1; foreach ($subject as $key => $value) { ?>
                        <tr>
                          <td><?php echo $i++; ?></td>
                          <td><?php echo $this->user_model->limitText($value['name'], 20); ?></td>
                          <td><?php echo $this->user_model->limitText($value['class_name'], 20); ?></td>
                          
                          
                          <td>
<?php  if($edit_delete['edit']){ ?>
                            <a href="<?php echo $base_url; ?>subject/actions/edit/<?php echo base64_encode(json_encode($value['id'].SALT)); ?>"><i class="fa fa-edit"></i></a> 
<?php } if($edit_delete['delete']){ ?>
                            <a href="<?php echo $base_url; ?>subject/actions/delete/<?php echo base64_encode(json_encode($value['id'].SALT)); ?>"><i class="fa fa-trash"></i></a>
<?php } ?>
                          </td>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>

                  
                    
                  </div>
                </div>
              </div>
             
              </div>
            
            </div>
          </div>
        </div>
        <!-- /page content -->
        <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.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>
 
    <!-- Datatables -->
    
 

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

     <script src="<?php echo base_url()?>assets/select/js/select2.min.js"></script>
    <script>
 
     $('#branch').select2({
     //selectOnClose: true,
    
   
    allowClear:true
    });
    </script>
   <script>
 
     $('#class').select2({
     //selectOnClose: true,
    allowClear:true
    });
    </script>
    <script>
 
     $('#section').select2({
     //selectOnClose: true,
    allowClear:true
    });
    </script>
    <script>
      $(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>
      <script>
function myFunction() {
     val1=$('#class').val();
      val=$('#b_head').val();
     id = $('#b_head').attr('data-id');
     if(id){
       $.ajax({
         url: '<?php echo base_url(); ?>subject/check_useredit/'+id+'/'+val+'/'+val1,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                                 $("#send").prop('disabled',true)
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                           
                           
                            }
                             else{
                                  $("#send").prop('disabled',false)
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                           
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });
    
     }else{
         $.ajax({
         url: '<?php echo base_url(); ?>subject/check_user/'+val+'/'+val1,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                                  $("#send").prop('disabled',true)
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                           
                           
                            }
                             else{
                                  $("#send").prop('disabled',false)
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                            
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });
    
     }
     //alert($val);
    
}
</script>
      