<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>Subject Allocation</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 id="alow" class="form-horizontal form-label-left" action="<?php echo $base_url; ?>subject/savealloc" 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" required>
                                      <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" required>
                                      <option value="">Select Class</option>
                            
                                 </select>                    
                        </div>
                      </div>    
                   <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Section <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <select class="form-control" name="section" id="section">
                                      <option value="">Select Section</option>
                            
                                 </select>                    
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Teacher<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <select class="form-control" name="teacher" id="teacher" required>
                                      <option value="">Select Teacher</option>
                            
                                 </select>                  
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Subjects<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <div class="form-group" id="sub">

                                  
                                 
                            </div>
                                                     
                        </div>
                      </div>
              
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <input id="send" type="submit" 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 Allocation</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">
                    <div class="row">
                      </div>
                    <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                      <thead>
                        <tr>
                          <th>#</th>
                          
                          <th style="width:100px;">Teacher</th>
                          <th style="width:100px;">Subject</th>
                          <th style="width:100px;">Class</th>
                           <th style="width:100px;">Section</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 $value['firstname']." ".$value['lastname']; ?></td>
                          <td><?php echo $this->user_model->limitText($value['subname'], 13); ?></td>
                          <td><?php echo $this->user_model->limitText($value['class_name'], 15); ?></td>
                          <td><?php echo $this->user_model->limitText($value['section_name'], 15); ?></td>
                          
                          <td>
<?php  if($edit_delete['edit']){ ?>
                            <a href="<?php echo $base_url; ?>subject/actionsalloc/edit/<?php echo $value['id']; ?>"><i class="fa fa-edit"></i></a> 
<?php } if($edit_delete['delete']){ ?>
                            <a href="<?php echo $base_url; ?>subject/actionsalloc/del/<?php echo $value['id']; ?>"><i class="fa fa-trash"></i></a>
<?php } ?>
                          </td>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>
                    
                  </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>
         
         
         <script>

$(document).ready(function(){
                $("#datatable-buttons").DataTable({
                
                dom: "lBfrtip",
              "bPaginate": true,
              "pageLength":35,
              "lengthMenu": [[35, 70, 100, -1], [35, 70, 100, "All"]],
               
             buttons: [
                 {
                  extend: "print",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "copy",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "csv",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "excel",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                extend: 'pdfHtml5',
                className: "btn-sm",
                title: '',
                exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            

});
</script>
    
        <script>
         $(document).ready(function(){
        var value=$('#branch_id').val();
        
           $('#send').hide();
           teacher(value);
           $.get("<?php echo base_url(); ?>load/classs/role/"+value,{},function(d){
                    var pre = '<option value="">Select Class</opiton>';
                    $("#class").html(pre+d);
                });
            });
            function teacher(id){
              
              $.get("<?php echo base_url(); ?>load/teacher/"+id,{},function(d){
                    var pre = '<option value="">Select Teacher</option>';
                    
                    $("#teacher").html(pre+d);
                });
            }
    
             $('#branch').change(function(){
                 
                var value=$(this).val();
                teacher(value);
                $('#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 value=$(this).val();
                $('#send').show();
                
                $.get("<?php echo base_url(); ?>load/section/role/"+value,{},function(d){
                    var pre = '<option value="">Select Section</opiton>';
                    $("#section").html(pre+d);
                });

            });
        
              $('#section').change(function(){
                 var cl=$('#class').val();
                var se=$(this).val();
                $('#send').show();
                
                $.get("<?php echo base_url(); ?>load/subjectagainstclasssection/"+cl+'/'+se,{},function(d)
                
                {
            
                    $("#sub").html(d);
                });
                

            });
            $('#teacher').change(function(){
                 
                var te=$(this).val();
                var cl=$('#class').val();
                var se=$('#section').val();
                
                $.get("<?php echo base_url(); ?>load/viewagainstteacher/"+te,{},function(d){
                    
                    $("tbody.center").html(d);
                });
                $.get("<?php echo base_url(); ?>load/suballocagainstteachersesstion/"+te+"/"+cl+'/'+se,{},function(d){
                    for(i = 0; i < d.length; i++)
                        $(".subjects").each(function(){
                            var custm=d[i].id;
                            if($(this).val() == d[i].id){
                                $('#hit'+custm).text("already Assign");
                                $(this).attr('disabled',true);
                              }
                        });
                    
                },'json');

            });
             
            </script>
            
           <script>
        $(document).ready(function(){
            $('#send').click(function(){
                var teacher=$("#teacher").val();
            var chkArray = [];
            $(".chkbx:checked").each(function(){
		         chkArray.push($(this).val());
	         });
       
           var selected;
	selected = chkArray.join(',') ;
	if(selected.length > 0){
	    if(teacher !="")
	    {
	        $("#alow").submit();
	    }else
	    {
	        alert('Please Select Teacher');
	        return false;
	    }
		
	}else{
		alert("Please at least check one subject");	
		return false;
	}
        });
        });
    </script>
 <script>
      $(function(){
      
        $(document).on("click","#go-search",function(e){
          e.preventDefault();
          var p = 1;
          var s = $("#search").val();
          if(s=="")
            s="all";
          window.location = "<?php echo base_url();?>subject/allocation/"+s+"/"+p;
        });
        $(document).on("click","button",function(){
          var val = $(this).attr("data-href");
          window.location = val;
        });
      });
    </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>
 
     $('#teacher').select2({
     //selectOnClose: true,
    allowClear:true
    });
    </script>
