<?php
session_start();
include "../../inc/config.php";

$columns = array(
  'nipd',
  'nama',
  'nm_prestasi',
  'nm_tkt_prestasi',
  'peringkat',
  'id_aktivitas',
  'status_error',
  'prestasi_mahasiswa.id'
  );

if (isset($_POST['jurusan'])) {
  
  if ($_POST['jurusan']=='all') {
    $jurusan = '';
    if ($_SESSION['level']!=1) {
      $jurusan = "and prestasi_mahasiswa.kode_jurusan='".$_SESSION['jurusan']."'";
    }
  } else {
    $jurusan = "and prestasi_mahasiswa.kode_jurusan='".$_POST['jurusan']."'";
  }
  
  if ($_POST['status_filter']=='all') {
    $status = '';
  } else {
    $status = " and status_error='".$_POST['status_filter']."'";
  }
  $query = $new_table->get_custom("select prestasi_mahasiswa.*,nm_tkt_prestasi,concat(jenjang,' ',nama_jurusan) as nama_jurusan from prestasi_mahasiswa inner join tingkat_prestasi on prestasi_mahasiswa.id_tkt_prestasi=tingkat_prestasi.id_tkt_prestasi left join jurusan on prestasi_mahasiswa.kode_jurusan=jurusan.kode_jurusan 
  	where prestasi_mahasiswa.id is not null $jurusan $status ",$columns);
} else {
  if (isset($_POST['jurusan_user'])) {
  	      $query = $new_table->get_custom("select prestasi_mahasiswa.*,nm_tkt_prestasi,concat(jenjang,' ',nama_jurusan) as nama_jurusan from prestasi_mahasiswa inner join tingkat_prestasi on prestasi_mahasiswa.id_tkt_prestasi=tingkat_prestasi.id_tkt_prestasi left join jurusan on prestasi_mahasiswa.kode_jurusan=jurusan.kode_jurusan 
  	where jurusan.kode_jurusan='".$_POST['jurusan_user']."' ",$columns);
  } else {
      $query = $new_table->get_custom("select prestasi_mahasiswa.*,nm_tkt_prestasi,concat(jenjang,' ',nama_jurusan) as nama_jurusan from prestasi_mahasiswa inner join tingkat_prestasi on prestasi_mahasiswa.id_tkt_prestasi=tingkat_prestasi.id_tkt_prestasi left join jurusan on prestasi_mahasiswa.kode_jurusan=jurusan.kode_jurusan ",$columns);

  }

}


$data = array();
foreach ($query as $value) {

  $ResultData = array();
  $ResultData[] = "<input type='checkbox'  class='deleteRow' value='".$value->id."'/>";
  $ResultData[] = $value->nipd;
  $ResultData[] = $value->nama;
  $ResultData[] = $value->nm_prestasi;
  $ResultData[] = $value->nm_tkt_prestasi;
  $ResultData[] = $value->peringkat;
   $ResultData[] = $value->id_aktivitas;
  $ResultData[] = $value->nama_jurusan;
  if ($value->status_error==1) {
    $ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-success" data-toggle="tooltip" data-placement="left" title="" data-original-title="Sukses"><i class="fa fa-info-circle"></i></button> '.$value->status_error;
  } elseif ($value->status_error==0) {
    $ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-warning tips" data-toggle="tooltip" data-placement="left" title="Belum diproses" data-original-title="Belum diproses"><i class="fa fa-info-circle"></i></button> '.$value->status_error;
  } else {
    $ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-danger" data-toggle="tooltip" data-placement="left" title="'.$value->keterangan.'" data-original-title="'.$value->keterangan.'"><i class="fa fa-info-circle"></i></button> '.$value->status_error;
  }
  $ResultData[] = $value->id;

  $data[] = $ResultData;
}
//set data
$new_table->set_data($data);
//create our json
$new_table->create_data();

?>