<!-- page content -->
        <div class="right_col" role="main">
          <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">
                    <h2>Create Datesheet</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->session->flashdata('msg' )){ ?>
                            <div class="alert alert-success">
                            <?php echo $this->session->flashdata('msg'); ?>  
                            </div>
                             <?php }else if($this->session->flashdata('msgs' )){ ?>
                             <div class="alert alert-danger">
                            <?php echo $this->session->flashdata('msgs'); ?>  
                            </div>
                            <?php } ?>
                    <form action="<?php echo base_url(); ?>senior_exam/add_datesheet" id="routePermit" class="form-horizontal form-bordered" method="post">
                      
                                           <?php if($this->user_model->is_super()){ ?>
                    <div class="item form-group" id="branch1">
                        <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">
                            <option value=''>Select Branch</option>
                      <?php
                            foreach ($branch as $value) {
                      ?>
                            <option value="<?php echo $value['id']; ?>"><?php echo $value['name']?></option>

                      <?php } ?>
                          </select>
                        </div>
                      </div>
                      <div class="form-group hide" id="branch2">
                            <label class="col-md-3 control-label" for="inputSuccess">Branch</label>
                            <div class="col-md-6">
                                 <input type="text" id="branch_name" class="form-control" readonly>
                            </div>
                    </div>
                      <?php  }else{$branch=$this->user_model->getbranch();?>
                          <input id="branch" name="branch" type="hidden" value="<?= $branch ?>">
                      <?php  } ?>
                                           
                    <div class="form-group" id="class1">
                            <label class="col-md-3 control-label" for="inputSuccess">Class <span class="required">*</span></label>
                            <div class="col-md-6">
                                <select name="class" id="class" class="form-control" required>
                                    <option value="">Select class</option>
                                </select>
                                <span id="class_loader"></span> 
                                                
                            </div>
                    </div>
                    <div class="form-group hide" id="class2">
                            <label class="col-md-3 control-label" for="inputSuccess">Class</label>
                            <div class="col-md-6">
                                 <input type="text" id="class_name" class="form-control" readonly>
                            </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! Date Sheet already exists!"  name="msg" type="text" readonly>
                        </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 Exam Date Sheet already exists!"  name="msg" type="text" readonly>
                        </div>
                    </div>  
                    
                     <div class="item form-group" id="msg2" 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! Exam Date Expire!"  name="msg2" type="text" readonly>
                        </div>
                    </div> 
                    <div class="form-group">
                            <label class="col-md-3 control-label" for="inputSuccess">Exam Name <span class="required">*</span></label>
                            <div class="col-md-6">
                                <select name="exam" id="exam" class="form-control" required>
                                
                                    <option value="">Select Exam  </option>
                                              
                                </select>
                                
                            </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2">
                            <select name="sub[]" id="subject" class="form-control"  required>
                            <option value="">Select subject</option></select>
                            </div>
                            <input class="form-control col-md-4 col-xs-12 " type="hidden"  name="sub[]" value="" >
                            <label class="col-md-1 control-label" for="inputSuccess">Date</label>
                            <div class="col-md-2">
                                <input type="input" class="form-control date datepicker " name="date[]" required-temp="true" placeholder="dd-mm-yyyy" value="<?= $date; ?>" required>
                            </div>
                            
                            <label class="col-md-1 control-label" for="inputSuccess">Time Start</label>
                            <div class="col-md-2">
                                <input id="" type="text" name="time_start[]" value="10:00 AM" title="timepicker" class="form-control timepicker" style="width: 100%;" />
                            </div>
                            
                            <label class="col-md-1 control-label" for="inputSuccess">Time End</label>
                            <div class="col-md-2">
                                <input id="" type="text" name="time_end[]" value="10:00 AM" title="timepicker" class="form-control timepicker1" style="width: 100%;" />
                            </div>

                    <div class="form-group" id="newOne">
                        <hr>
                    </div>

                    <div class="row">
                        <button class="btn btn-success col-lg-offset-8 pull-right hide" type="button" id="add" name="+">ADD</button>
                    </div> 
                       
                    <div class="row">
                        <button class="btn btn-success col-lg-offset-8 pull-right" id="submit" type="submit" name="submit">Submit</button>
                       
                    </div>
                    
                    
                    <div class="row">
                        <button class="btn btn-success col-lg-offset-0 pull-center" type="button" name="submit" onClick="window.location.reload()">Reset Page</button>
                       <!-- <input type="reset"  class="btn btn-success col-lg-offset-0 pull-center" value="Reset Page" onClick="window.location.reload()">-->
                       
                    </div>
                     
                    
                                            
                </form>
                      </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>
    </div>

 <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>
       <script src="<?php echo base_url(); ?>assets/js/bootstrap-datepicker.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="<?php echo base_url(); ?>assets/build/js/custom.min.js"></script>
   
    <!-- Jquery UI-daterangepicker -->
    <script src="<?php echo base_url(); ?>assets/vendors/datepicker/jquery-ui.min.js"></script>
    
    
    
 
 <script src="<?php echo base_url()?>assets/select/js/select2.min.js"></script>
 
 
  <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>
    window.setTimeout(function() {
      $(".alert").fadeTo(500, 0).slideUp(500, function(){
          $(this).remove(); 
      });
      }, 2000);
    </script>
 
   <script>
 
     $('#class').select2({
     //selectOnClose: true,
    placeholder: "Select a Class",
    allowClear:true
    });
    </script>
    
     <script>
 
     $('#exam').select2({
     //selectOnClose: true,
    placeholder: "Select a Exam",
    allowClear:true
    });
     $('#subject').select2({
     //selectOnClose: true,
    placeholder: "Select a Subject",
    allowClear:true
    });
    </script>
    <script>
 
     $('#day').select2({
     //selectOnClose: true,
    placeholder: "Select a Day",
    allowClear:true
    });
    
    $('#branch').select2({
     //selectOnClose: true,
    placeholder: "Select a Branch",
    allowClear:true
    });
    </script>

 <script src="<?php echo base_url(); ?>assets/js/kendo.all.min.js"></script>
     <script>
                $(document).ready(function () {
                    // create TimePicker from input HTML element
                    $(".timepicker").kendoTimePicker({
                        dateInput: true
                    });
                });
            </script>
                 <script>
                $(document).ready(function () {
                    // create TimePicker from input HTML element
                    $(".timepicker1").kendoTimePicker({
                        dateInput: true
                    });
                });
            </script>



<script>
 $( function() {
    $( ".datepicker" ).datepicker({ dateFormat: 'd-m-yy' }).val();
  } );
</script>



    <script>
$(document).ready(function(e) {
  
  var values = [];
  var n=0;
  var x = 1;
  var max_fields      = 12;
  var newDiv  = $("#newOne");
  
  $("#add").click(function(e){

    var dataComp='';
    e.preventDefault();
       //text box increment 
       if(x < max_fields){ //max input box allowed
            x++;
             
             var val = $("#branch").val();
              var c = $("#class").val();
              $.get("<?php echo base_url(); ?>Load/subjects/"+c+"/"+val,{},function(data){
               
                var pre = "<option value=''>Select Subject</option>";
                dataComp=pre+data;
                
                $(newDiv).append('<div class="form-group"><div class="col-md-2"><select name="sub[]" id="subject'+n+'" class="form-control"  required><option value="">Select subject</option></select></div><input class="form-control col-md-4 col-xs-12 " type="hidden"  name="sub[]" value="" ><label class="col-md-1 control-label" for="inputSuccess">Date</label><div class="col-md-2"><input type="input" class="form-control date datepicker" name="date[]" required-temp="true" placeholder="dd-mm-yyyy" value="<?= $date; ?>" required></div><label class="col-md-1 control-label" for="inputSuccess">Time Start</label><div class="col-md-2"><input id="" class="form-control timepicker" type="text"  name="time_start[]" required/ ></div><label class="col-md-1 control-label" for="inputSuccess">Time End</label><div class="col-md-2"><input id="" class="form-control timepicker1" type="text"  name="time_end[]" required/></div><input  type="button" class="remove_field btn btn-primary pull-right" style="margin-top:10;" id="btn/'+n+'"  value="X"></div>'); 
           
            $("#subject"+n).html(dataComp);


                    
            $("#subject"+n).select2();

             $('body').on('change',"#subject"+n, function(){
                  
                  values=values?values:[];
                  var number = $(this).val();
                  if($.inArray(number, values) !== -1) {
                      $(this).val('');
                     
                  } 
                  else {
                      values.push(number);
                  } 
                
                });
               
            })
          }
          ++n;
      }); 
     
    $(newDiv).on("click",".remove_field", function(e){ //user click on remove text
       var id =$(this).attr('id');
     
     //var last = str.substring(str.lastIndexOf("/") + 1, str.length);
     var last = id.substring(id.lastIndexOf("/") + 1, id.length);
     e.preventDefault(); $(this).parent('div').remove(); x--;
    });


    $("#exam").change(function(e){
        var val = $("#exam").val();
        
      
                                 var branch = $("#branch").val();
        var classs = $("#class").val();
         var sub = $("#subject").val();
       
        
        $.ajax({
         url: '<?php echo base_url(); ?>Load/check_exam_exist/'+val+'/'+branch+'/'+classs+'/'+sub,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                             
                             
                                $("#msg").css("display", "block");
                                document.getElementById("submit").disabled = true;
                                    
                            
                           
                            }
                            else{
                                
                                //alert("You can add class");
                                $("#msg").css("display", "none");
                                document.getElementById("submit").disabled = false;
                                $( "#add" ).removeClass("hide");
                                $("#class1").hide();
                                $("#class2").removeClass("hide");
                                var class_name = $("#class :selected").text();
                                $("#class_name").val(class_name);
                                $("#branch1").hide();
                                $("#branch2").removeClass("hide");
                                var branch_name = $("#branch :selected").text();
                                $("#branch_name").val(branch_name);
                             }
                    },
                    
                });
                                
                                //End
                               
                    
                });
                
       
        
        
    });

  

    </script>


<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").html(pre+d);
                });
                $.get("<?php echo base_url(); ?>Load/exam/"+value,{},function(data){
                    var pre = "<option value=''>Select Exam</option>";
                    $("#exam").html(pre+data);
                  });
            
        });
</script>

<script>
    
    
      $(function(){
        $(document).on("change","#branch",function(){
          var val = $(this).val();
          $.get("<?php echo base_url(); ?>Load/classs/role/"+val,{},function(data){
            var pre = "<option value=''>Select Class</option>";
            $("#class").html(pre+data);
          });
          $.get("<?php echo base_url(); ?>Load/exam/"+val,{},function(data){
            var pre = "<option value=''>Select Exam</option>";
            $("#exam").html(pre+data);
          });
        });
        
        $(document).on("change","#class",function(){
          var val = $("#branch").val();
              var c = $("#class").val();
       $.get("<?php echo base_url(); ?>Load/subjects/"+c+"/"+val,{},function(data){
            var pre = "<option value=''>Select Subject</option>";
            $("#subject").html(pre+data);
          });
          
        });
       
      });
      
        
    </script>

//     <script>
// function myFunction() {
//     $val=$('#username').val();
//     $val=$('#exam').val();
//     $.ajax({
//          url: '<?php echo base_url(); ?>exam/check_dateSheet/'+ id+ '/'+ $val,
//         data: {},
//         success: function (res) {
//                             if(res == 1)
//                             {
//                              //alert("Already exists");
                             
//                             $("#msg").css("display", "block");
//                             document.getElementById("new_type").disabled = true;
                           
//                             }
//                              else{
//                              //alert("You can add class");
//                              $("#msg").css("display", "none");
//                              document.getElementById("new_type").disabled = false;
//                              }
//                     },
//                      error: function(){
//                                         alert("failure");
//                                     }
//                 });
    
// }

// </script>

   


  </body>
</html>