<?php
include_once "./class/testing.php";
include_once "./class/kriteria.php";
include_once "./class/penilaian.php";

$crud=new testing();
$_kriteria=new kriteria();
$_penilaian=new penilaian();
?>
<div class="row">

    <div class="col-12">
    
    <div class="card mb-4">
    
      <div class="card-header pb-0">
        <h4 class="m-0">Data Testing <small style="font-size: .6em; font-weight:300"> | Menampilkan data yang akan dicari klasifikasinya dan hasil klasifikasinya</small></h4>
      </div>
      <div class="card-body" style="font-size: .8em;">
        <?php 
          if(@$_SESSION['con']!="") { ?>
          <div class="alert alert-success alert-dismissable" style="opacity:0.8; padding: 5px 10px;">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            <i class="icon fa fa-check"></i>
            <?php 
            if(@$_SESSION['con']==1) { echo "Data berhasil ditambah."; }
            elseif(@$_SESSION['con']==2) { echo "Data berhasil diubah."; }
            elseif(@$_SESSION['con']==3) { echo "Data berhasil dihapus."; }
            ?>
          </div>
        <?php unset($_SESSION['con']); } ?>
        <div class="table-responsive p-0">
        <table class="csstable align-items-center mb-0" id="tabel_data" width="100%" border="0" cellpadding="4" cellspacing="0">
            <thead>
                <tr>
                    <th width="3%" class="no_sort">No</th>
                    <th width="8%">Kode</th>                        
                    <th width="12%">Nama</th>
                    <?php
                    $r_kriteria = $_kriteria->tampil_kriteria();
                    if($r_kriteria)
                              foreach ($r_kriteria as $key => $d_kriteria) { ?>
                                <th style="text-align: center;"><?php echo $d_kriteria['kriteria']; ?></th>
                    <?php } ?>
                    <?php
                    $r_kriteria = $_kriteria->tampil_keputusan();
                    if($r_kriteria)
                              foreach ($r_kriteria as $key => $d_kriteria) { ?>
                                <th style="text-align: center;"><?php echo $d_kriteria['kriteria']; ?></th>
                    <?php } ?>
                    
                    <th width="5%" class="no_sort">
                        <a href="?p=testing-input&stat=tambah" class="btn btn-primary btn-xs" style="margin-bottom:0px"><div style="width:65px;"><i class="fa fa-plus"></i></div></a>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php
                $no=0;
                $result = $crud->tampil_hasil();
                if($result)
                foreach ($result as $key => $data) {
                    $no++;
                ?>
                <tr>
                <td><?php echo $no; ?></td>
                    <td><?php echo $data['kode']; ?></td>
                    <td><?php echo $data['nama']; ?></td>
                    <?php
                    $r_kriteria = $_kriteria->tampil_kriteria();
                    if($r_kriteria)
                        foreach ($r_kriteria as $key => $d_kriteria) {
                          if($d_kriteria['masukan']==1){ 
                          $r_nilai = $_penilaian->tampil_satu($data['id_testing'], $d_kriteria['id_kriteria']);
                          ?>
                          <td style="text-align: center;"><?php echo @$r_nilai[0]['nilai']; ?></td>
                        <?php } else { 
                          $r_nilai = $_penilaian->tampil_satu_b($data['id_testing'], $d_kriteria['id_kriteria']);
                          ?>
                          <td style="text-align: center;"><?php echo @$r_nilai[0]['masukan']; ?></td>
                    <?php } } $hasil=($data['nilai']!="") ? $data['nilai'] : "Tidak Ditemukan"; ?>
                    <td style="text-align: center; font-weight: bold;"><?php echo $hasil; ?></td>
                    <td>
                        <a href="?p=testing-input&stat=ubah&id=<?php echo $data['id_testing']; ?>&f=i" class="btn btn-success btn-xs" style="padding: 5px 10px; margin-bottom:0px" title="Ubah Data"><i class="fa fa-pen" style="font-size:0.8em"></i></a>
                        <a href="?p=perhitungan&id=<?php echo $data['id_testing']; ?>" class="btn btn-info btn-xs" style="padding: 5px 10px; margin-bottom:0px" title="Perhitungan"><i class="fa fa-calculator" style="font-size:0.8em"></i></a>
                        <a href="javascript:void(0);" class="btn btn-danger btn-xs openHapus" style="padding: 5px 10px; margin-bottom:0px" data-title=" <?php echo $data['kode']." - ".$data['nama']; ?>" data-href="?p=testing-input&stat=hapus&id=<?php echo $data['id_testing']; ?>"><i class="fa fa-trash" style="font-size:0.8em"></i></a>                          
                    </td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
        </div>
        
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="modalHapus" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="text-align: left;">
                <h4 class="modal-title pull-left" id="myModalLabel">Hapus Data?</h4>
                <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>