<div class="box-body table-responsive">

<div class="box box-danger">
            <div class="box-header with-border">
              <h3 class="box-title">Filter</h3>
            </div>
            <div class="box-body">
           <form class="form-horizontal" id="send_pencarian">

               <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-5" >
                        <select id="sem_filter" name="sem_filter" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
              <?php 
              $url_rest = get_service_url('rest');
              $temp_data_semester = [
                'act' => 'GetSemester',
                  'token' => get_token(),
                  'filter' => "a_periode_aktif='1' and right(id_semester,1) in('1','2')",
                  'order' => 'id_semester desc'
              ];

            $temp_rec = json_decode($db->run($temp_data_semester,$url_rest));
            dump($temp_rec);

               $semester = $db->fetch_custom('select *,left(semester,4) as smt from semester order by semester desc');
                    foreach ($semester as $isi) {
                      if ($temp_rec->data[0]->id_semester==$isi->semester) {
                          echo "<option value='".$isi->semester."' selected>".$isi->nama_semester."</option>";
                          $smt_selected = $isi->semester;    
                        } else {
                          echo "<option value='".$isi->semester."'>".$isi->nama_semester."</option>";    
                        }
                      }
                       ?>
              </select>
              <div id="error_sem"></div>

 </div>
                      </div><!-- /.form-group -->
<div class="form-group show-jurusan">
                                        <label for="Semester" class="control-label col-lg-2">Program Studi</label>
                                        <div class="col-lg-5">
                                        <select id="jurusan" name="jurusan" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                               <?php
        $jurusan_sms = "";
        $jur_selected = 0;
        if ($_SESSION['level']!=1) {
              $jurusan_sms = "where id_sms='".$_SESSION['id_sms']."'";
              $jur_selected = 1;
        } else {
          echo '<option value="all">Semua</option>';
        }
        
                                foreach ($db->fetch_custom("select * from jurusan $jurusan_sms") as $isi) {
                                  echo "<option value='$isi->id_sms'>$isi->jenjang $isi->nama_jurusan</option>";
                               } ?>
                              </select>
 <div id="error_prodi"></div>
                 </div>
                                      </div><!-- /.form-group -->

<div class="form-group show-matakuliah">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Matakuliah</label>
                        <div class="col-lg-5">
                      <select class="form-control chzn-select" name="matkul" id="matkul">
                        <option value="all">Semua</option>
                    </select>
</div>
</div>
<div class="form-group show-kelas">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Kelas</label>
                        <div class="col-lg-5">
                      <select class="form-control chzn-select" name="kelas" id="kelas">
                        <option value="all">Semua</option>
                    </select>
</div>
</div>

 <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Pencarian NIM</label>
                        <div class="col-lg-2" >
                        <select id="nim" name="nim" data-placeholder="Pilih Angkatan ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
                        <option value="all">Semua</option>
                        <option value="nim">NIM</option>
              </select>
            </div>
            <div class="col-lg-3" style="padding-left: 0;">
              <input type="text" name="value_nim" id="value_nim" class="form-control" placeholder="Input NIM Mahasiswa (akan mencari semua nilai berdasarkan nim)" style="display: none" required="">
            </div>
              <div id="error_nim"></div>
                      </div><!-- /.form-group -->


<div class="form-group">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Filter By</label>
                        <div class="col-lg-5">
                      <select class="form-control chzn-select" name="filter_by" id="filter_by">
                        <option value="id_matkul">Mahasiwa Duplikat ID Matakuliah NEO</option>
                         <option value="kode_mata_kuliah">Mahasiwa Duplikat KODE Matakuliah</option>
                    </select>
</div>
</div>


                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <span id="filter" class="btn btn-primary btn-flat"><i class="fa fa-refresh"></i> Submit</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
            </div>
            <!-- /.box-body -->
       
          </div>

<div class="callout callout-danger">
<h4>Informasi!</h4>
<p>Data yang tampil adalah hanya data yang punya DUPLIKAT, artinya mahasiswa memiliki KRS/Matkul duplikat di periode yang dipilih.</p>
</div>

    <table id="dtb_hapus_kelas" class="table table-bordered table-striped" width="100%">
                                   <thead>
                                     <tr>
   <th><input type="checkbox"  id="bulkDelete"  /> <button id="deleteTriger"><i class="fa fa-trash"></i></button></th>
                      
                          <th>Semester</th>
                          <th>NIM</th>
                          <th>Nama</th>
                          <th>Kode MK</th>
                          <th>Nama MK</th>
                          <th>Kelas</th>
                          <th>Nilai Angka</th>
                          <th>Nilai Indeks</th>
                          <th>Nilai Huruf</th>
                          <th>Prodi</th>
                          <th>Action</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div><!-- /.box-body -->
                          
        <?php
      
      
  foreach ($db->fetch_all("sys_menu") as $isi) {

  //jika url = url dari table menu
  if ($path_url==$isi->url) {

  if ($role_act['del_act']=='Y') {
   $del = "<span data-id='+aData[indek]+' data-uri=".base_admin()."modul/hapus_krs_feeder/hapus.php".' class="btn btn-danger hapus_akm_feeder btn-flat"><i class="fa fa-trash"></i></span>';
  } else {
    $del="";
  }
                   } 
  }
  
?>  
        <script type="text/javascript">
$(document).ready(function() {
  $("#nim").change(function(){
    if (this.value=='nim') {
      $('#sem_filter option:first').text('Semua');
      $("#sem_filter").trigger('chosen:updated');
      $("#value_nim").show();
      /* $(".show-jurusan").hide();
      $(".show-matakuliah").hide();
      $(".show-kelas").hide();*/
    } else {
      $('#sem_filter option:first').text('Pilih Semester');
      $("#sem_filter").trigger('chosen:updated');
      $("#value_nim").hide();
      /* $(".show-jurusan").show();
      $(".show-matakuliah").show();
      $(".show-kelas").show();*/
      $("#nim").parent().parent().removeClass('has-error');
      $("#error_nim").html('');
    }

  });
  $("#matkul").change(function(){
    $("#kelas").html('');
    $("#kelas").chosen();
    $("#loadnya").show();
    $("#img_loader").show();
    
      $.ajax({
          url : "<?=base_admin();?>modul/hapus_krs_feeder/get_kelas.php",
          type : "post",
          data : {matkul : $(this).val(),jurusan : $("#jurusan").val(),semester : $("#sem_filter").val() },
          success : function(data) {
            $("#loadnya").hide();
            $("#img_loader").hide();
              $("#kelas").html(data);
              $("#kelas").trigger('chosen:updated');

          }

      });
     
  });


  $("#jurusan").change(function(){
    $("#matkul").html('');
    $("#matkul").chosen();
    $("#loadnya").show();
    $("#img_loader").show();
    
      $.ajax({
          url : "<?=base_admin();?>modul/hapus_krs_feeder/matakuliah.php",
          type : "post",
          data : {jurusan : $(this).val(),semester : $("#sem_filter").val() },
          success : function(data) {
            $("#loadnya").hide();
            $("#img_loader").hide();
              $("#matkul").html(data);
              $("#matkul").trigger('chosen:updated');

          }

      });
     
  });

  $("#sem_filter").change(function(){
             $("#matkul").html('');
        $("#matkul").chosen();
        $("#loadnya").show();
        $("#img_loader").show();
    
      $.ajax({
          url : "<?=base_admin();?>modul/hapus_krs_feeder/matakuliah.php",
          type : "post",
          data : {semester : $(this).val(),jurusan :  $("#jurusan").val() },
          success : function(data) {
              $("#loadnya").hide();
              $("#img_loader").hide();
              $("#matkul").html(data);
              $("#matkul").trigger('chosen:updated');
          }

      });
     
  });

$("#search_by").change(function(){
  if ($(this).val()!='all') {
      $("#keyword").attr("required", true);
      $("#keyword").val("");
      $("#keyword").attr('placeholder','Ketik '+$("#search_by :selected").text())
      $('.keyshow').slideDown();
  } else {
    $('.keyshow').slideUp();
    $("#keyword").val("");
    $("#keyword").attr("required", false);
  }

});
  

var dataTable = $("#dtb_hapus_kelas").DataTable({
           "fnCreatedRow": function( nRow, aData, iDataIndex ) {
               var indek = aData.length-1; 
     $('td:eq('+indek+')', nRow).html('<?=$del;?>');
       $(nRow).attr('id', 'line_'+aData[indek]);
   },
   "lengthMenu": [[100,300,500,1000,5000,10000], [100,300,500,1000,5000,10000]],
           'bProcessing': true,
            'bServerSide': true,
            "searching": false,
               "ordering": false,
                 "columnDefs": [ {
              "targets": [0,8],
              "orderable": false,
             

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/hapus_krs_feeder/hapus_krs_duplikat/data.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
                    d.semester = $("#sem_filter").val();
                    d.kode_mk = $("#matkul").val();
                    d.kelas = $("#kelas").val();
                    d.nim = $("#nim").val();
                    d.value_nim = $("#value_nim").val();
                    d.cari_duplikat = $("#cari_duplikat").val();
                     d.filter_by = $("#filter_by").val();
                     
             <?php
            if ($_SESSION['level']!=1) {
              ?>
              d.jurusan = "<?=$_SESSION['id_sms'];?>";
              <?php
            } else {
              ?>
              d.jurusan =  $("#jurusan").val();
              <?php
            }
            ?>
            },
          error: function (xhr, error, thrown) {
            console.log(error);
            console.log(xhr);
              $(".dtb_akm-error").html("");
              $("#dtb_akm").append('<tbody class="dtb_akm-error"><tr><th colspan="9">No data found in the server</th></tr></tbody>');
              $("#dtb_akm_processing").css("display","none");

            }
          },
          "language": {
             searchPlaceholder: "Pencarian dengan NIM atau Nama",
          "processing": "<i class=\"fa fa-spinner fa-spin\"></i> Loading data, please wait..." //add a loading image,simply putting <img src="loader.gif" /> tag.
   },

        });

/*    $('#send_pencarian').validate({
              errorClass: "help-block",
        errorElement: "span",
        highlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-success").addClass("has-error");
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-error").addClass("has-success");
        },
         submitHandler: function(form) {
                    //filter
            $('#filter').on('click', function() {
              dataTable.ajax.reload();
            });

        }

      });*/

//filter
$('#filter').on('click', function() {
    if($("#value_nim").is(":visible") && $("#value_nim").val()=="") {
      $("#nim").parent().parent().addClass('has-error');
      $("#error_nim").html('<span for="nim" class="help-block">Nim Wajib Diisi</span>');
      return;
    } 

   $("#nim").parent().parent().removeClass('has-error');
   $("#error_nim").html('');

  dataTable.ajax.reload();
});



$("#bulkDelete").on('click',function() { // bulk checked
          var status = this.checked;
          $(".deleteRow").each( function() {
            $(this).prop("checked",status);
          });
        });

$('#deleteTriger').on("click", function(event){
          if( $('.deleteRow:checked').length > 0 ){
            event.preventDefault();


            var ids = [];
            $('.deleteRow').each(function(){
              if($(this).is(':checked')) {
                ids.push($(this).val());
              }
            });
            var ids_string = ids.toString();


            $('#ucing')
        .modal({ keyboard: false })
        .one('click', '#delete', function (e) {

          $("#loadnya").show();
          $.ajax({
              type: "POST",
              url: "<?=base_admin();?>modul/hapus_krs_feeder/hapus.php?act=del_massal",
              data: {data_ids:ids_string},
               async: true,
              success: function(result) {
                $("#loadnya").hide();
                console.log(result);
                dataTable.draw(false);
              },
              async:true
            });
          $('#ucing').modal('hide');



        });


          }
        });

    $(".table").on('click','.hapus_akm_feeder',function(event) {

    event.preventDefault();
    var currentBtn = $(this);

    uri = currentBtn.attr('data-uri');
    id = currentBtn.attr('data-id'); 
    

    $('#ucing')
        .modal({ keyboard: false })
        .one('click', '#delete', function (e) {
        $("#loadnya").show();
                $.ajax({
          type: "POST",
          url: uri+"?act=delete&id="+id,
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              dataTable.draw(false);
          }
          });
          $('#ucing').modal('hide');

        });

  });
});



</script>  
            