<style type="text/css">
  .nav-tabs-custom>.nav-tabs {
    border-bottom-color: #3c8dbc;
  }
.nav-tabs-custom>.nav-tabs>li.active>a {
    border-left-color: #3c8dbc;
    border-right-color: #3c8dbc;
  }
.table-striped > tbody > tr .selected {
  background: #e2ea8a;
}
.DTTT_selected {
  background: #e2ea8a;  
}
</style>
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        Restore Mahasiswa Feeder
                    </h1>
                        <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=base_index();?>hapus-mahasiswa">Restore Mahasiswa</a></li>
                        <li class="active">Restore Mahasiswa List</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
<div class="nav-tabs-custom">
            <ul class="nav nav-tabs" id="myTab">
              <li class="active"><a href="#peserta" data-toggle="tab" aria-expanded="true"><i class="fa fa-user"></i> 1. Restore Biodata</a></li>
              <li class=""><a href="#history_tab" data-toggle="tab" aria-expanded="false"><i class="fa fa-hourglass"></i> 2. Restore History </a></li>
              <li><a href="#other" data-toggle="tab"><i class="fa fa-search-plus"></i> 3. Restore Data Lainya</a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="peserta">
                <?php
                include "tab_mahasiswa.php";
                ?>
              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="history_tab">
                <?php
                include "tab_history.php";
                ?>
              </div>
              <div class="tab-pane" id="other">
                <?php
                include "tab_lain.php";
                ?>
              </div>
<!--               /.tab-pane
<div class="tab-pane" id="penguji">
  <?php
  //include "penguji_view.php";
  ?>
</div>
<div class="tab-pane" id="rekap">
   <?php
  //include "rekap_penguji_view.php";
  ?>
</div> -->
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
          </div>


                        </div>
                    </div>
<!-- modal jadwal -->
<div class="modal fade" id="modal_kelas_jadwal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"><div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Detail Data</h4> </div> <div class="modal-body" id="isi_kelas_jadwal"> </div> <div class="modal-footer"> <button type="button" class="btn btn-success restore-mhs-button" data-uri="<?=base_admin();?>modul/restore_mahasiswa/restore_mahasiswa_action.php"><i class="fa fa-undo"></i> Restore</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div></div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div>
<!-- modal dosen -->

<div class="modal" data-backdrop="static" data-keyboard="false" id="modal-restore-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog"> <div class="modal-content"><div class="modal-header"> <button type="button" class="close cancel-restore" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Konfirmasi</h4> </div> <div class="modal-body"> <p>Apakah Anda yakin ingin MeRestore data ini?</p> </div> <div class="modal-footer"> <button type="button" id="restore" class="btn btn-success"><i class="fa fa-undo"></i> Restore</button> <button type="button" class="btn btn-default cancel-restore" data-dismiss="modal">Cancel</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
        <?php
      
      
  foreach ($db->fetch_all("sys_menu") as $isi) {

  //jika url = url dari table menu
  if ($path_url==$isi->url) {
   if ($role_act["up_act"]=="Y") {
  $detail = "<span data-id='+aData[indek]+' data-uri=".base_admin()."modul/restore_mahasiswa/restore_mahasiswa_action.php".' class="btn btn-primary lihat-detail btn-flat" data-type="mhs" data-toggle="tooltp" title="Lihat Detail Data"><i class="fa fa-eye"></i></span>';

  $restore = "<span data-id='+aData[indek]+' data-uri=".base_admin()."modul/restore_mahasiswa/restore_mahasiswa_action.php".' data-type="mhs" class="btn btn-success restore-mhs btn-flat" data-toggle="tooltp" title="Restore Mahasiswa"><i class="fa fa-undo"></i> Restore</span>';
  } else {
    $edit ="";
    $detail ="";
  }
                   } 
  }
  
?>  
                </section><!-- /.content -->
        <script type="text/javascript">

var table = $("#dtb_hapus_mhs").DataTable({
           "fnCreatedRow": function( nRow, aData, iDataIndex ) {
            var indek = aData.length-1;           
     $('td:eq('+indek+')', nRow).html('<?=$detail;?> <?=$restore;?>');
       $(nRow).attr('id', 'line_'+aData[indek]);
   },
           'bProcessing': true,
           'destroy': true,
            'bServerSide': true,
             // "searching": false,
              
               "ordering": false,
            "ajax":{
              url :"<?=base_admin();?>modul/restore_mahasiswa/restore_mahasiswa_data.php",
            type: "post",  // method  , by default get
          error: function (xhr, error, thrown) {
            console.log(xhr);
              $(".dtb_akm-error").html("");
              $("#dtb_akm").append('<tbody class="dtb_akm-error"><tr><th colspan="8">No data found in the server</th></tr></tbody>');
              $("#dtb_akm_processing").css("display","none");

            }
          },
          "language": {
             searchPlaceholder: "Pencarian dengan 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.
   },

});

var table_history = $("#dtb_history").DataTable({
           "fnCreatedRow": function( nRow, aData, iDataIndex ) {
            var indek = aData.length-1;           
     $('td:eq('+indek+')', nRow).html('<?=$detail_history;?> <?=$restore_history;?>');
       $(nRow).attr('id', 'line_'+aData[indek]);
   },
           'bProcessing': true,
           'destroy': true,
            'bServerSide': true,
             // "searching": false,
              
               "ordering": false,
            "ajax":{
              url :"<?=base_admin();?>modul/restore_mahasiswa/history_data.php",
            type: "post",  // method  , by default get
          error: function (xhr, error, thrown) {
            console.log(xhr);
             /* $("#dtb_history").append('<tbody class="dtb_akm-error"><tr><th colspan="9">No data found in the server</th></tr></tbody>');*/
            }
          },
          "language": {
             searchPlaceholder: "Pencarian dengan NIM Nama atau ID Mahasiswa",
          "processing": "<i class=\"fa fa-spinner fa-spin\"></i> Loading data, please wait..." //add a loading image,simply putting <img src="loader.gif" /> tag.
   },

});

$( ".restore-mhs-button").click(function() {
        event.preventDefault();
    var currentBtn = $(this);

    uri = currentBtn.attr('data-uri');
    id = $(".id-hapus-modal").attr("data-id");
    type = $(".data-type-modal").attr("data-type");
    if (data_type=='mhs') {
      var type = 'mhs';
      var class_error = $('.error_data_delete');
      var success_warning = $('.success-warning');
      var isi_warning_delete = $('.isi_warning_delete');
    } else {
      var type = 'mhs_pt';
      var class_error = $('.error_data_delete_history');
      var success_warning = $('.success-warning-history');
      var isi_warning_delete = $('.isi_warning_delete_history');
    }

    var txt;
    var r = confirm("Apakah Anda yakin ingin MeRestore data ini?");
    if (r == true) {
      $("#loadnya").show();
      $.ajax({
          type: "POST",
          url: uri+"?act=restore",
          data : {id : id,type:type},
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              $('#modal_kelas_jadwal').modal('hide');
              if (data=='good') {
                //$('.success-warning').fadeIn(1000);
                class_error.hide();
                success_warning.fadeIn("fast", function() {
                  $(this).delay(1000).fadeOut("slow");
                    $("#line_"+id).fadeOut("slow");
                    table.draw(false);
                    table_history.draw(false);
                });
                 $('html, body').animate({
                    scrollTop: (success_warning.first().offset().top)
                },500);

               /* $('.success-warning').show();*/
/*                
                $(".success-warning").fadeOut(1000,function(){
                });*/

              } else {
                success_warning.hide();
                class_error.show();
                isi_warning_delete.html(data);
              }

          }
          });
    }/* else {
      txt = "You pressed Cancel!";
    }*/

  
 //$('#modal_kelas_jadwal').modal('hide');
/*    $('#modal-restore-confirm')
        .modal({ keyboard: false })
        .one('click', '#restore', function (e) {
        $("#loadnya").show();
                $.ajax({
          type: "POST",
          url: uri+"?act=restore",
          data : {id : id,type:type},
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              $("#line_"+id).fadeOut("slow");
              table.draw(false);
          }
          });
          $('#modal-restore-confirm').modal('hide');

        });*/
 });
 $(".table").on('click','.restore-mhs',function(event) {

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

    uri = currentBtn.attr('data-uri');
    id = currentBtn.attr('data-id'); 
    
    //$("#line_"+id).addClass('warna');
    $(this).parents('tr').css('background', '#e2ea8a');
    data_type = currentBtn.attr('data-type');
    if (data_type=='mhs') {
      var type = 'mhs';
      var class_error = $('.error_data_delete');
      var success_warning = $('.success-warning');
      var isi_warning_delete = $('.isi_warning_delete');
    } else {
      var type = 'mhs_pt';
      var class_error = $('.error_data_delete_history');
      var success_warning = $('.success-warning-history');
      var isi_warning_delete = $('.isi_warning_delete_history');
    }

    $('#modal-restore-confirm')
        .modal({ keyboard: false })
        .one('click', '#restore', function (e) {
        $("#loadnya").show();
                $.ajax({
          type: "POST",
          url: uri+"?act=restore",
          data : {id : id,type:type},
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              if (data=='good') {
                //$('.success-warning').fadeIn(1000);
                class_error.hide();
                success_warning.fadeIn("fast", function() {
                  $(this).delay(1000).fadeOut("slow");
                    $("#line_"+id).fadeOut("slow");
                    table.draw(false);
                    table_history.draw(false);
                });
                 $('html, body').animate({
                    scrollTop: (success_warning.first().offset().top)
                },500);

               /* $('.success-warning').show();*/
/*                
                $(".success-warning").fadeOut(1000,function(){
                });*/

              } else {
                success_warning.hide();
                class_error.show();
                isi_warning_delete.html(data);
              }

          }
          });
            $('#modal-restore-confirm').modal('hide');
        });

  });


$(".table").on('click','.lihat-detail',function(event) {
        $("#loadnya").show();
        event.preventDefault();
        var currentBtn = $(this);
        id = currentBtn.attr('data-id');
        data_type = currentBtn.attr('data-type');
        if (data_type=='mhs') {
          var type = 'mhs';
        } else {
          var type = 'mhs_pt';
        }
        $.ajax({
            url : "<?=base_admin();?>modul/restore_mahasiswa/detail_modal.php",
            type : "post",
            data : {id_pd:id,type:type},
            success: function(data) {
                $("#isi_kelas_jadwal").html(data);
                $("#loadnya").hide();
          }
        });
    $('#modal_kelas_jadwal').modal({ keyboard: false,backdrop:'static' });
    });

$('.cancel-restore').click(function() {
   $('.table tr').css('background', '');

});

$(document).ready(() => {
  let url = location.href.replace(/\/$/, "");
 
  if (location.hash) {
    const hash = url.split("#");
    $('#myTab a[href="#'+hash[1]+'"]').tab("show");
    url = location.href.replace(/\/#/, "#");
    history.replaceState(null, null, url);
    setTimeout(() => {
      $(window).scrollTop(0);
    }, 400);
  } 
   
  $('a[data-toggle="tab"]').on("click", function() {
    let newUrl;
    const hash = $(this).attr("href");
    if(hash == "#peserta") {
      newUrl = url.split("#")[0];
    } else {
      newUrl = url.split("#")[0] + hash;
    }
    newUrl += "/";
    history.replaceState(null, null, newUrl);
  });
});  
</script>  
            