<?php
session_start();
include "../../inc/config.php";
    $token = get_token();
    $url_rest = $db->get_service_url('rest');
    $id = $_POST['akt_id'];
      $data_req_akt = [
        'act' => 'GetMataKuliah',
          'token' => $token,
          'filter' => "id_matkul='$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];
      $id_matkul = $akt_data->id_matkul;
      
?>
<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_program_studi;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Kode Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->kode_mata_kuliah;?></td>
          <td class="info2"><strong>Jenis Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->id_jenis_mata_kuliah;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Nama Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->nama_mata_kuliah;?></td>
          <td class="info2"><strong>SKS Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->sks_mata_kuliah;?></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>POSISI MATAKULIAH DI KURIKULUM</b></h4>
       <table id="dtb_anggota" class="table table-bordered table-striped table-detail">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">No</th>
                          <th>KURIKULUM</th>
                          <th>Mulai Berlaku</th>
                          <th>SMT</th>
                          <th>Wajib?</th>
                          <th>Aksi</th>
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetMatkulKurikulum',
          'token' => $token,
          'filter' => "id_matkul='$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) {
        $wajib = '<span class="btn btn-xs btn-warning">Tidak</span>';
        if ($anggota->apakah_wajib=='1') {
            $wajib = '<span class="btn btn-xs btn-success">Ya</span>';
        }
        ?>
        <tr id="line_<?=$anggota->id_matkul.'_'.$anggota->id_kurikulum;?>">
          <td><?=$no_anggota;?></td>
          <td><?=$anggota->nama_kurikulum;?></td>
          <td><?=$anggota->semester_mulai_berlaku;?></td>
          <td><?=$anggota->semester;?></td>
          <td><?=$wajib;?></td>
           <td><span data-id="<?=$anggota->id_matkul.'_'.$anggota->id_kurikulum;?>" data-jenis="matkur" data-uri="<?=base_admin()?>modul/manage_matakuliah/hapus.php" class="btn btn-danger hapus btn-flat btn-sm" data-toggle="tooltip" data-title="Hapus Matakuliah Kurikulum"><i class="fa fa-trash"></i></span></td>
        </tr>

        <?php
        $no_anggota++;
      }
?>
                                        </tbody>
                                    </table>
        <h4><b>RENCANA PEMBELAJARAN</b></h4>
       <table id="dtb_pembelajaran" class="table table-bordered table-striped table-detail">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">No</th>
                          <th>Pertemuan</th>
                          <th>Materi</th>
                          <th>Materi Inggris</th>
                          <th>Aksi</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetListRencanaPembelajaran',
          'token' => $token,
          'filter' => "id_matkul='$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_rencana_ajar;?>">
          <td><?=$no_anggota;?></td>
          <td><?=$pembimbing->pertemuan;?></td>
          <td><?=$pembimbing->materi_indonesia;?></td>
          <td><?=$pembimbing->materi_inggris;?></td>
          <td><span data-id="<?=$pembimbing->id_rencana_ajar;?>" data-jenis="pembelajaran" data-uri="<?=base_admin()?>modul/manage_matakuliah/hapus.php" class="btn btn-danger hapus btn-flat btn-sm" data-toggle="tooltip" data-title="Hapus Rencana Pembelajaran"><i class="fa fa-trash"></i></span> <span data-id='<?=$pembimbing->id_rencana_ajar;?>' data-toggle='tooltip' data-title='Edit Data' class='btn btn-sm btn-primary edit-pembelajaran btn-flat'><i class='fa fa-pencil'></i></span></td>
        </tr>

        <?php
        $no_anggota++;
      }
?>
                                        </tbody>
                                    </table>
        <h4><b>RENCANA EVALUASI</b></h4>
       <table id="dtb_penguji" class="table table-bordered table-striped table-detail">
                                   <thead>
                                     <tr>
                          
                          <th width="5%">Nomor</th>
                          <th>Basis Evaluasi</th>
                          <th>Komponen Evaluasi</th>
                          <th>Deskripsi</th>
                          <th>Bobot</th>
                          <th>Aksi</th>
                        </tr>
                                      </thead>
                                        <tbody>
<?php
      $data_req_akt = [
        'act' => 'GetListRencanaEvaluasi',
          'token' => $token,
          'filter' => "id_matkul='$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_rencana_evaluasi;?>">
          <td><?=$penguji->nomor_urut;?></td>
          <td><?=$penguji->jenis_evaluasi;?></td>
          <td><?=$penguji->nama_evaluasi;?></td>
          <td><?=$penguji->deskripsi_indonesia;?></td>
          <td><?=$penguji->bobot_evaluasi;?></td>
          <td><span data-id="<?=$penguji->id_rencana_evaluasi;?>" data-jenis="evaluasi" data-uri="<?=base_admin()?>modul/manage_matakuliah/hapus.php" class="btn btn-danger hapus btn-flat btn-sm" data-toggle="tooltip" data-title="Hapus Evaluasi"><i class="fa fa-trash"></i></span></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>
<div class="modal" id="modal_edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"><div class="modal-header"><h4 class="modal-title judul-modal">Detail Aktivitas</h4> </div> <div class="modal-body" ><div id="isi_modal_edit"></div><div id="panel_pindah_kelas"></div> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </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,
 });

var dataTable_pembelajaran;

dataTable_pembelajaran = $("#dtb_pembelajaran").DataTable({
           'bProcessing': true,
            'bServerSide': true,
            // "searching": false,
               "ordering": false,
            "ajax":{
              url :"<?=base_admin();?>modul/manage_matakuliah/data_pembelajaran.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
              d.id_matkul = "<?=$id_matkul;?>";
             },
          error: function (xhr, error, thrown) {
            console.log(xhr);
            }
          }
});

  $("#dtb_pembimbing").dataTable({
  "paging": false,
  "searching" : false,
   "bInfo": false,
 });
   $("#dtb_penguji").dataTable({
  "paging": false,
  "searching" : false,
   "bInfo": false,
 });

$(".table-detail").on('click','.edit-pembelajaran',function(event) {
    $("#loadnya").show();
    event.preventDefault();
    $(".judul-modal").html("Edit Pembelajaran");
    var currentBtn = $(this);

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

    $.ajax({
        url : "<?=base_admin();?>modul/manage_matakuliah/edit_pembelajaran.php",
        type : "post",
        data : {id_rencana_ajar : id},
        success: function(data) {
            $("#isi_modal_edit").html(data);
            $("#loadnya").hide();
      }
    });

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

});

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



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


$(".table-detail").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");

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

        });

  });

</script>
