
<table id="kelas_dosen_data" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>    
<th>NIDN</th>                      
<th>Nama Dosen</th>
<th>Jumlah Kelas</th>
<th>Jumlah SKS</th>
</tr>
</thead>
<tbody>
<?php
session_start();
include "../../inc/config.php";
$and_jurusan = "";
if ($_POST['jurusan']!='all') {
  $and_jurusan = "and kode_jurusan='".$_POST['jurusan']."'";
}
$periode = $_POST['semester'];
$jurusan = $db->fetch_custom("select * from jurusan where status='A' $and_jurusan order by nama_jurusan asc");
$no=1;
$token = get_token();
$total_kelas = 0;
$total_sks = 0;
foreach ($jurusan as $jur) {
  //jumlah mahasiswa aktif
  $data_req = [
    'act' => 'GetDosenPengajarKelasKuliah',
      'token' => $token,
      'filter' => "id_prodi='$jur->id_sms' and id_semester='$periode'"
  ];
  $jml_kelas = 0;
  $jml_terisi = 0;
  $jml_tidak_terisi = 0;
  $get_jumlah = service_request($data_req);
/*  dump($get_jumlah);
  exit();*/
  if ($get_jumlah->data) {
    foreach ($get_jumlah->data as $data) {
      if ($data->id_dosen!="") {
          $nama_dosen[$data->id_dosen] = $data->nama_dosen;
          $jumlah_kelas_diajar[$data->id_dosen][] = $data->id_dosen;
          $jumlah_sks[$data->id_dosen][] = $data->sks_substansi_total;
          $nidn[$data->id_dosen] = $data->nidn;
      }


/*      if ($data->id_dosen!='') {
         $jumlah_kelas_terisi[$data->id_prodi] = $data->id_kelas_kuliah;
         $jml_terisi++;
      }
      if ($data->id_dosen=='') {
         $jumlah_kelas_kosong[$data->id_prodi] = $data->id_kelas_kuliah;
         $jml_tidak_terisi++;
      }*/
    }
  }

}

/*dump($nama_dosen);
dump($jumlah_kelas_diajar);
dump($jumlah_sks);*/
  //dump($get_jumlah_akm);
  // Add conditional statements to check for division by zero and NaN
/*  if ($jml_kelas != 0) {
    if ($jml_terisi != 0) {
      $prosen = ($jml_terisi/$jml_kelas)*100;
      $prosen = round($prosen, 2);
    } else {
      $prosen = 0;
    }
  } else {
    $prosen = "N/A";
  }
if ($prosen==100) {
  $btn = 'badge bg-green';
} elseif ($prosen > 50) {
  $btn = 'badge bg-light-blue';
} else {
  $btn = 'badge bg-red';
}*/

foreach ($nama_dosen as $key => $dosen) {
?>

  <tr> 
  <td><?=$no;?></td>
  <td><?=$nidn[$key];?></td>
  <td><?=$dosen;?></td>
  <td><?=count($jumlah_kelas_diajar[$key]);?></td>
  <td><?=array_sum($jumlah_sks[$key]);?></td>

  </tr>
  <?php
  $no++;
  $total_kelas+=count($jumlah_kelas_diajar[$key]);
  $total_sks+=array_sum($jumlah_sks[$key]);
}
?>
</tbody>
<tfoot>
  <tr>
  <th colspan="2" style="text-align: right;">Total</th>
  <th>&nbsp;</th>
  <th> <?=$total_kelas;?></th>
  <th> <?=$total_sks;?></th>
  </tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
  $('#kelas_dosen_data').DataTable({
    "dom": "<'row'<'col-sm-12'B>>" + "<'row'<'col-sm-6'l><'col-sm-6'f>>" +"<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-5'i><'col-sm-7'p>>",
    buttons: [
      {
        extend: 'collection',
        text: 'Export Data',
        buttons: [ 'print','pdfHtml5', 'csvHtml5', 'copyHtml5', 'excelHtml5' ]
      }
    ]
  });
});

</script>