<style>
    .required{
        color: #bf5050;
    }
</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>

            <div class="row" id="def">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Add Exam</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" id="routePermit"  action="<?php echo $base_url;?>exam/add" 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">
                            <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>
                      <?php  }else{$branch=$this->user_model->getbranch();?>
                          <input id="branch" name="branch" type="hidden" value="<?= $branch ?>">
                      <?php  } ?>
                       <input id="id" name="id" type="hidden" value="">
                
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="etype_id">Exam Type<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="etype_id" class="form-control col-md-7 col-xs-12" onChange="removeExam()" name="etype_id"  required="required">
                            <option value=''>Select Exam Type</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 Exam 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="name">Exam Name<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input name="name" id="name" required="required" onkeyup="myFunction()" class="form-control" placeholder="Exam Name e.g First Term">
                        </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! End date is Wrong"  name="msg1" type="text" readonly>
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="start">Start<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         
                               <input type="input" class="form-control date datepicker" id="start" name="start"  required="true" placeholder="dd-mm-yyyy"  >
                        </div>
                      </div>
                      
                      <div class="item form-group" id="msgend" 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 end date should be greater than start date"  name="msg1" 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! End date is Wrong"  name="msg1" type="text" readonly>
                        </div>
                      </div>
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="end">End<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                              <input type="input" class="form-control" id="end" name="end" required="true" placeholder="dd-mm-yyyy"  >                   
                        </div>
                      </div>
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                         
                          <button id="send" type="button" value="send" class="btn btn-success pull-right">Save</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
              </div>
            
                <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>View Exams</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>Exam Type</th>
                          <th>Start</th>
                          <th>End</th>
                           <?php if($this->user_model->is_super()){ ?>

                          <th>Branch Name</th>
                          <?php } ?>
                          <th>Status</th>
                          <th>Actions</th>
                         
                        </tr>
                      </thead>


                      <tbody class="center">
                        <?php $i=1;  foreach ($exam as $k=>$value) { ?>
                        <tr>
                          <td><?php echo $i++; ?></td>
                          <td><?php echo $value['name']; ?></td>
                        
                          
                          <td><?php echo $value['etype_name']; ?></td>
                          <td><?php echo date("d-m-Y",@strtotime($value['start'])); ?></td>
                          <td><?php echo date("d-m-Y",@strtotime($value['end'])); ?></td>
                          <?php if($this->user_model->is_super()){ ?>

                          <td><?php echo $value['b_name']; ?></td>
                          <?php } ?>
                          <td>
                            <?php 
                             $publish=$value['is_publish'];
                             if($publish=='1'){?>
                               <a href="<?php echo base_url();?>Exam/unpublish/<?php echo $value['id']?>" style="color:green;"><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Published&nbsp;<span class="label label-info">Click for UnPublish</span></a>
                               <?php } ?>
                             <?php 
                             if($publish=='0')
                                { ?>
                                    <a href="<?php echo base_url();?>Exam/publish/<?php echo $value['id']?>" style="color:red;"><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Not-Published&nbsp;<span class="label label-info">Click for Publish</span></a>   
                               <?php }?>
                                   
                                            
                            </td>

                          <td>
<?php  if($edit_delete['edit']){ ?>
                                    <a href="" onclick="edit(<?php echo $value['id']; ?>,event )"><i class="fa fa-edit"></i></a> 

<?php }   ?>
  <?php if($edit_delete['delete']){ ?>
                           <a href="" onclick="delete_user(<?php echo $value['id']; ?>,event )"><i class="fa fa-trash"></i></a>
<?php } ?>
                          </td>
                          <?php }?>
                        </tr>
                      
                      </tbody>
                    </table>
                    <!--<div class="row">
                      <div class="col-md-12 col-sm-12 col-xs-12">
                        <?php //for ($i=$total; $i >= 1; $i--) { ?>
                        <a href="<?php //echo $base_url; ?>exam/index/<?php //echo $i.'/'.$c; ?>">
                          <button class="btn btn-success pull-right"><?php //echo $i; ?></button>
                        </a>
                        <?php //} ?>
                      </div>
                    </div>-->
                  </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>
 <!-- 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>
    <!-- Jquery UI-daterangepicker -->
    <script src="<?php echo base_url(); ?>assets/vendors/datepicker/jquery-ui.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  src="<?php echo base_url(); ?>assets/js/notify.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>
       $(document).ready(function(){
    $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });



   $.ajax({
    url: '<?php echo base_url(); ?>exam/index/',data: {},
         success: function (result) {
 $(document).ajaxStop(function() {
           $('#ajaxload').hide();
});
}
});
});
   </script>

 <script>
 
 $(function() {
     var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

var lastDayWithSlashes = (lastDay.getDate()) + '/' + (lastDay.getMonth() + 1) + '/' + lastDay.getFullYear();
//alert(lastDayWithSlashes);
    // $("#end").datepicker({
    //     dateFormat: 'dd/mm/yy',
    //     minDate:0,
    //     maxDate: lastDayWithSlashes
    // });
       $("#end").datepicker({
        dateFormat: 'dd/mm/yy',
    });
    //$( "#end" ).datepicker({ dateFormat: 'dd/mm/yy' }).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>
 
    //  $('#etype_id').select2({
    //  //selectOnClose: true,
    // allowClear:true
    // });
    </script>

    <!-- Datatables -->
   <script>
$(document).ready(function(){

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

});
</script>
    
<script>
 $( function() {
     var fullDate = new Date();
     var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) :(fullDate.getMonth()+1);
     var currentDate = fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
     var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var firstDayWithSlashes = (firstDay.getDate()) + '/' + (firstDay.getMonth() + 1) + '/' + firstDay.getFullYear();
var lastDayWithSlashes = (lastDay.getDate()) + '/' + (lastDay.getMonth() + 1) + '/' + lastDay.getFullYear();

//   $( ".datepicker" ).datepicker({
//       dateFormat: 'dd/mm/yy',
//       minDate: firstDayWithSlashes,
//       maxDate: currentDate,
//       }).val();

  $( ".datepicker" ).datepicker({
       dateFormat: 'dd/mm/yy',
       }).val();
    
  } );
</script>
<script>
        $(document).ready(function(){
            
                var value = $('#branch').val();
               
                $.get("<?php echo base_url(); ?>load/exams/role/"+value,{},function(d){
                    var pre = '<option value="">Select Exam</opiton>';
                    $("#etype_id").html(pre+d);
                });
            
        });
    </script>
    <script>
        $(document).ready(function(){
            $(document).on("change","#branch",function(){
                var value = $(this).val();
               
                $.get("<?php echo base_url(); ?>load/exams/role/"+value,{},function(d){
                    var pre = '<option value="">Select Exam</opiton>';
                    $("#etype_id").html(pre+d);
                });
            });
            
        });
    </script>
    

    
 <script>
           $(document).ready(function(){
            $(document).on("change","#end",function(){
                var end = $(this).val();
                var start=$("#start").val();
              
              var date=start.split("/");
            var newDatest = date[1] + '-' + date[0] + '-' + date[2].slice(-4);
            
              var datee=end.split("/");
            var newDaten = datee[1] + '-' + datee[0] + '-' + datee[2].slice(-4);
            
                var sDate = new Date(newDatest);
                var eDate = new Date(newDaten);
               if(eDate <= sDate)
               {
                    $("#msgend").css("display", "block");
                     document.getElementById("send").disabled = true;
               }else
               {
                   $("#msgend").css("display", "none");
                             document.getElementById("send").disabled = false;
               }
            });
            
        });
 </script>   
    <script>
function myFunction() {
    
    var id = $('#name').attr('data-id');
    var val=$('#name').val();
    // val1=$('#class').val();
    var e_id = $('#etype_id').val();
    var branch  = $("#branch").val();
    // alert(branch);
    if(branch!= ""){ 
     
     if(id){
         
       $.ajax({
         url: '<?php echo base_url(); ?>exam/check_Examenames/'+e_id+'/'+val+'/'+id+'/'+branch,
        data: {},
        success: function (res) {
          
                            if(res == 1)
                            {
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                            document.getElementById("send").disabled = true;
                           
                            }
                             else{
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                             document.getElementById("send").disabled = false;
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });
    
     }
     else{
         
         $.ajax({
         url: '<?php echo base_url(); ?>exam/check_Examename/'+e_id+'/'+val+'/'+branch,
        data: {},
        success: function (res) {
                            if(res == 1)
                            {
                             //alert("Already exists");
                             
                            $("#msg").css("display", "block");
                            document.getElementById("send").disabled = true;
                           
                            }
                             else{
                             //alert("You can add class");
                             $("#msg").css("display", "none");
                             document.getElementById("send").disabled = false;
                             }
                    },
                     error: function(){
                                        alert("failure");
                                    }
                });

     }
        
    }
    else
    {
        
    }
    
}

</script>

<script>
$(document).ready(function() { 
  $("#send").click(function(event){
        
  event.preventDefault();
   
  var val=$("#send").val();
  var name=$("#name").val();
//  var classs=$("#class").val();
  var examtype=$("#etype_id").val();
  var branch=$("#branch").val();
  var start=$("#start").val();
  var end=$("#end").val();
 
    
 if(val == "send"){
      
    if(branch!="" && examtype!="" && name!="" && start!="" && end!="")
      {
    

      $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
            
    $.ajax({
        type:'POST',
        url:'<?php echo base_url();?>exam/saveexam',
        data:{examtype:examtype,name:name,start:start,end:end},
 
        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",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?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,4],
                       <?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,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                 extend: "pdfHtml5",
                  className: "btn-sm",
                  exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
          
                
                },
                {
                    extend: "print",
                    className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                 
                },
              ],
              responsive: true
            });
            },500);
            
           
            
           }
    });
    
    
    $("#id").val("");
    // $("#branch").val("");
    $("#name").val("");
    $("#start").val("");
       $("#end").val("");

}
}
else if(val=="update")
{
    
    var id=$("#id").val();
    var name=$("#name").val();
   // var classs=$("#class").val();
    var examtype=$("#etype_id").val();
    var branch=$("#branch").val();
    var start=$("#start").val();
    var end=$("#end").val();

    
    if(branch!="" && name!=""  && start!=""  && end!="" && id!="" && examtype!="")
      {
    

      $(document).ajaxStart(function() {
                $('#ajaxload').show();
            });
    $.ajax({
        type:'POST',
        url:'<?php echo base_url();?>exam/updateexam',
        data:{id:id,examtype:examtype,name:name,start:start,end:end},
 
        success: function (result) {
             $(document).ajaxStop(function() {
                $('#ajaxload').hide();
            });
            
            $.notify("Successfully Updated..", "success");


          /*  $("#success_msg").fadeIn().html("Successfully Added...");
             setTimeout(function(){
                $("#success_msg").fadeOut('slow');
            },5000);*/
           $("#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: "print",
                  className: "btn-sm",
                   exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?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,4],
                       <?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,4],
                       <?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,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                extend: 'pdf',
                className: "btn-sm",
                title: '',
                exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            },500);
            
           
            
           }
    });
    $("#id").val("");
   <?php  if($this->user_model->is_super()){ ?>
   
    <?php }?>
    $("#name").val("");
    $("#start").val("");
    $("#end").val("");
    $("#send").val("send");

}
}
else{

     $.notify("Please Fill Field..", "danger");
}


});//end if for button type checking
});



function edit(id,event){
    $("#msg").css("display", "none");
    document.getElementById("send").disabled = false;
   // $("h2").html("Update User");
  event.preventDefault();
  $.ajax({
     url: '<?php echo base_url(); ?>exam/get_record_exam/'+id,
         success: function (result)
          { 
           
            var obj=JSON.parse(result);
            var branch = obj.branch_id;
            
             <?php if($this->user_model->is_super()){ ?>
             $.ajax({
                    url: '<?= base_url(); ?>load/exams/role/'+branch,
                    success:function(d){
                        $("#etype_id").html(d);
                        $("#etype_id").val(obj.etype_id);
                    },
                    error:function(){
                      alert('Error occur...!!');
                    }
                  });
                
           /* $.ajax({
                    url: '<?= base_url(); ?>load/classs/role/'+branch,
                    success:function(d){
                        $("#class").html(d);
                        $("#class").val(obj.class_id);
                    },
                    error:function(){
                      alert('Error occur...!!');
                    }
                  }); */       
                <?php }else
                {
                    
                } ?>
                
            $("#id").val(obj.id);
            $("#name").val(obj.name);
            $('#name').attr("data-id",obj.id);
            //alert(obj.start);
            var date=obj.start.split("-");
            var newDate = date[2] + '-' + date[1] + '-' + date[0].slice(-4);
            
            var date2=obj.end.split("-");
            var newDate2 = date2[2] + '-' + date2[1] + '-' + date2[0].slice(-4);
            //alert(newDate);
            $("#start").val(newDate);
            $("#etype_id").val(obj.etype_id);
           // $("#class").val(obj.class_id);
            $("#end").val(newDate2);
      
       
            $("#send").val("update");
           
         $('html, body').animate({
        scrollTop: $("#def").offset().top
    }, 1000);
            //$("tbody.center").html(result);
            }
      });
      
}







</script>
<script>
function delete_user(id,event){
    
  var id = id ;
  event.preventDefault();
  $.ajax({
      type:'POST',
     url: '<?php echo base_url(); ?>exam/delete_record_exam',
     data:{id:id},
     success: function (result) {
             console.log(result);
              $("#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",
                    exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?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,4],
                       <?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,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm",
                    exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                  extend: "print",
                  className: "btn-sm",
                    exportOptions: {
                       <?php  if($this->user_model->is_super()){ ?>
                        columns: [0,1,2,3,4],
                       <?php }else{?>
                       columns: [0,1,2,3],
                       <?php }?>
                        modifier: {
                            selected: true
                        }
                    }
                },
              ],
              responsive: true
            });
            },500);
           }
      });
}

function removeExam(){
    $("#name").val('');
}



</script>
  </body>
</html>