<?php
session_start();
include "../../../inc/config.php";
    $url_rest = get_service_url('rest');
    $token = get_token();
    $ids = $_POST['akt_id'];
        if ($_POST['jenis']=='bimbing') {
          $table = "GetMahasiswaBimbinganDosen";
          $filter_where = "id_bimbing_mahasiswa='".$ids."'";
        } else {
          $table = "GetListUjiMahasiswa";
          $filter_where = "id_uji='".$ids."'";
        }

      $data_param = [
        'act' => $table,
          'token' => $token,
          'filter' => trim($filter_where)

      ];
      $data_uji_bimbing = service_request($data_param);

    $id = $data_uji_bimbing->data[0]->id_aktivitas;
      $data_req_akt = [
        'act' => 'GetListAktivitasMahasiswa',
          'token' => $token,
          'filter' => "id_aktivitas='$id'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $check_akt_exist_json = json_decode($db->run($data_req_akt,$url_rest));
      $akt_data = $check_akt_exist_json->data[0];
      
?>
<style type="text/css">
  .vertical-alignment-helper {
    display:table;
    height: 100%;
    width: 100%;
    pointer-events:none;
}
.vertical-align-center {
    /* To center vertically */
    display: table-cell;
    vertical-align: middle;
    pointer-events:none;
}
.modal-content {
    /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
    width:inherit;
 max-width:inherit; /* For Bootstrap 4 - to avoid the modal window stretching full width */
    height:inherit;
    /* To center horizontally */
    margin: 0 auto;
    pointer-events:all;
}
.modal {
  overflow-y:auto;
}
</style>
<table id="tabelku" class="table table-bordered table-striped" cellspacing="0" width="100%">
        <tbody><tr>
          <td class="info2" width="20%"><strong>Program Studi</strong></td>
          <td width="30%"><?=$akt_data->nama_prodi;?></td>
          <td class="info2" width="20%"><strong>Semester </strong></td>
          <td><?=$akt_data->nama_semester;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Judul</strong></td>
          <td colspan="3"><?=$akt_data->judul;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Jenis Aktivitas</strong></td>
          <td><?=$akt_data->nama_jenis_aktivitas;?></td>
          <td class="info2"><strong>ID/Keterangan</strong></td>
          <td><?=$akt_data->keterangan;?></td>
        </tr>
      </tbody></table>
 <div class="alert alert-danger error_data" style="display:none">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <span class="isi_warning"></span>
        </div>
        <h4><b>Peserta Aktivitas</b></h4>
       <table id="dtb_anggota" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">No</th>
                          <th>NIM</th>
                          <th>Nama Peserta</th>
                          <th>Peran</th>
                          <th>Aksi</th>
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetListAnggotaAktivitasMahasiswa',
          'token' => $token,
          'filter' => "id_aktivitas='$id'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $akt_data_anggota = json_decode($db->run($data_req_akt,$url_rest));
      $no_anggota=1;
      foreach ($akt_data_anggota->data as $anggota) {
        ?>
        <tr id="line_<?=$anggota->id_anggota;?>">
          <td><?=$no_anggota;?></td>
          <td><?=$anggota->nim;?></td>
          <td><?=$anggota->nama_mahasiswa;?></td>
          <td><?=$anggota->nama_jenis_peran;?></td>
           <td>#</td>
        </tr>

        <?php
        $no_anggota++;
      }
?>
                                        </tbody>
                                    </table>
        <h4><b>Dosen Pembimbing</b></h4>
       <table id="dtb_pembimbing" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">No</th>
                          <th>NIDN</th>
                          <th>Nama Dosen</th>
                          <th>Ke</th>
                          <th>Kategori Kegiatan</th>
                          <th>Aksi</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetListBimbingMahasiswa',
          'token' => $token,
          'filter' => "id_aktivitas='$id'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $akt_data_pembimbing = json_decode($db->run($data_req_akt,$url_rest));
      //print_r($akt_data_pembimbing);
      $no_anggota=1;
      foreach ($akt_data_pembimbing->data as $pembimbing) {
        ?>
        <tr id="line_<?=$pembimbing->id_bimbing_mahasiswa;?>">
          <td><?=$no_anggota;?></td>
          <td><?=$pembimbing->nidn;?></td>
          <td><?=$pembimbing->nama_dosen;?></td>
          <td><?=$pembimbing->pembimbing_ke;?></td>
          <td><?=$pembimbing->nama_kategori_kegiatan;?></td>
           <td>
            <?php
            if ($_POST['jenis']!='bimbing') {
              ?>
              <span data-id="<?=$pembimbing->id_bimbing_mahasiswa;?>" data-jenis="pembimbing" data-uri="<?=base_admin()?>modul/hapus__aktivitas_mahasiswa/peserta/hapus.php" class="btn btn-danger hapus btn-flat btn-sm" data-toggle="tooltip" data-title="Hapus Pembimbing"><i class="fa fa-trash"></i></span>
              <?php
            }
            ?>
            </td>
        </tr>

        <?php
        $no_anggota++;
      }
?>
                                        </tbody>
                                    </table>
        <h4><b>Dosen Penguji</b></h4>
       <table id="dtb_penguji" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">No</th>
                          <th>NIDN</th>
                          <th>Nama Dosen</th>
                          <th>Ke</th>
                          <th>Kategori Kegiatan</th>
                          <th>Aksi</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetListUjiMahasiswa',
          'token' => $token,
          'filter' => "id_aktivitas='$id'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $akt_data_penguji = json_decode($db->run($data_req_akt,$url_rest));
      //print_r($akt_data_pembimbing);
      $no_anggota=1;
      foreach ($akt_data_penguji->data as $penguji) {
        ?>
        <tr id="line_<?=$penguji->id_uji;?>">
          <td><?=$no_anggota;?></td>
          <td><?=$penguji->nidn;?></td>
          <td><?=$penguji->nama_dosen;?></td>
          <td><?=$penguji->penguji_ke;?></td>
          <td><?=$penguji->nama_kategori_kegiatan;?></td>
          <td>
            <?php
            if ($_POST['jenis']!='uji') {
              ?>
              <span data-id="<?=$penguji->id_uji;?>" data-jenis="penguji" data-uri="<?=base_admin()?>modul/hapus__aktivitas_mahasiswa/peserta/hapus.php" class="btn btn-danger hapus btn-flat btn-sm" data-toggle="tooltip" data-title="Hapus Penguji"><i class="fa fa-trash"></i></span>
              <?php
            }
            ?>
            </td>
        </tr>

        <?php
        $no_anggota++;
      }
?>
                                        </tbody>
                                    </table>
<!-- Modal -->
<div class="modal" data-backdrop="static" data-keyboard="false" id="hapus_ucing" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
            <div class="modal-content">
                <div class="modal-header">
                     <h4 class="modal-title" id="myModalLabel">Konfirmasi</h4>

                </div>
                <div class="modal-body"><p>Apakah Anda yakin ingin menghapus data ini?</p></div>
                <div class="modal-footer">
                    <button type="button" id="delete" class="btn btn-danger">Delete</button>
                    <button type="button" class="btn btn-default cancel_hapus">Cancel</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
$(".cancel_hapus").on("click",function(){
  $("#hapus_ucing").modal( 'hide' ).data( 'bs.modal', null );
});


 $("#dtb_anggota").dataTable({
  //"paging": false,
  "searching" : false,
   //"bInfo": false,
 });
  $("#dtb_pembimbing").dataTable({
  "paging": false,
  "searching" : false,
   "bInfo": false,
 });
   $("#dtb_penguji").dataTable({
  "paging": false,
  "searching" : false,
   "bInfo": false,
 });
    $("#add_dosen").on('click',function(event) {
        $("#loadnya").show();
        event.preventDefault();
        var currentBtn = $(this);

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

        $.ajax({
            url : "<?=base_admin();?>modul/kelas_jadwal/modal_list_dosen.php",
            type : "post",
            success: function(data) {
                $("#isi_dosen").html(data);
                $("#loadnya").hide();
          }
        });

    $('#modal_list_dosen').modal({ keyboard: false,backdrop:'static' });

    });

$('.close_main').click(function() {
    location.reload();
});

    function pilih_dosen(id_dosen){
        // $('#loadnya').show();
        $.ajax({
            type: 'POST',
            url: '<?=base_admin();?>modul/kelas_jadwal/komponen_tambah_dosen.php',
            data: 'id_dosen='+id_dosen,
            success: function(result) {
              // $('#loadnya').hide();
              $("#modal_list_dosen").modal( 'hide' ).data( 'bs.modal', null );
              $("#dosen_ajar").append(result);
            },
            //async:false
        });
    }

$(document).on("click", ".hapus_komponen_dosen", function() {
      $(this).parent().parent().remove(); 
});


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

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

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

    $("#line_"+id).css("background-color:#aab7d1");
    
/*    var result = confirm("Yakin akan dihapus?");
if (result) {
                 $.ajax({
          type: "POST",
          url: uri+"?act=delete&jenis="+jenis+"&id="+id,
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              $("#line_"+id).fadeOut("slow");
              dataTable.draw(false);
          }
          });
}*/

    $('#hapus_ucing')
        .modal({ keyboard: false })
        .one('click', '#delete', function (e) {
        $("#loadnya").show();
                $.ajax({
          type: "POST",
          url: uri+"?act=delete_aktivitas&jenis="+jenis+"&id="+id,
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              if (data=='good') {
                $("#line_"+id).fadeOut("slow");
                dataTable.draw();
              } else {
                $('.error_data').show();
                $('.isi_warning').html(data);
              }
              
          }
          });
          $('#hapus_ucing').modal('hide');

        });

  });

</script>
