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


$columns = array(
	'semester',
	'nim',
	'nama',
	'status_kuliah',
	'ips',
	'ipk',
	'sks_smt',
	'sks_total',
	'nama_jurusan',
	'status_error',
	'nilai_akm.id'
	);

if (isset($_POST['semester'])) {
	
	if ($_POST['semester']=='all') {
		$semester = '';
	} else {
		$semester = "and semester='".$_POST['semester']."' ";
	}
	if ($_POST['valid']=='all') {
		$valid = '';
	} else {
		$valid = "and valid='".$_POST['valid']."' ";
	}
	if ($_POST['jurusan']=='all') {
		$jurusan = '';
			if ($_SESSION['level']!=1) {
			$jurusan = "and nilai_akm.kode_jurusan='".$_SESSION['jurusan']."'";
		}
	} else {
		$jurusan = "and nilai_akm.kode_jurusan='".$_POST['jurusan']."' ";
	}
	//status kuliah
	if ($_POST['status_kuliah']=='all') {
		$status_kuliah = '';
	} else {
		$status_kuliah = "and status_kuliah='".$_POST['status_kuliah']."' ";
	}

	
	if ($_POST['status_filter']=='all') {
		$status = '';
	} else {
		$status = " and status_error='".$_POST['status_filter']."' ";
	}
	$query = $akm_table->get_custom("select nilai_akm.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from nilai_akm left join jurusan on nilai_akm.kode_jurusan=jurusan.kode_jurusan where semester!='' $semester $jurusan $status $status_kuliah $valid ",$columns);

	//echo "select * from nilai_akm $semester $jurusan $status $status_kuliah $valid ";
} else {
	if (isset($_POST['jurusan_user'])) {
		$query = $akm_table->get_custom("select nilai_akm.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from nilai_akm left join jurusan on nilai_akm.kode_jurusan=jurusan.kode_jurusan where jurusan.kode_jurusan='".$_POST['jurusan_user']."' ",$columns);
	} else {
		$query = $akm_table->get_custom("select nilai_akm.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from nilai_akm left join jurusan on nilai_akm.kode_jurusan=jurusan.kode_jurusan ",$columns);
	}
}
$data = array();
$status_kuliah = $db->fetch_custom("select * from status_mahasiswa_akm");
foreach ($status_kuliah as $st) {
	$stat_kuliah[$st->id_status] = $st->nama_status;
}
foreach ($query	as $value) {
	$ResultData = array();
	$ResultData[] = "<input type='checkbox'  class='deleteRow' value='".$value->id."'  />";
	$ResultData[] = $value->semester;
	$ResultData[] = $value->nim;
	$ResultData[] = $value->nama;

	if (in_array($value->status_kuliah, array_keys($stat_kuliah))) {
		$ResultData[] = $stat_kuliah[$value->status_kuliah];
	} else {
		$ResultData[] = '';
	}
	      
	$ResultData[] = $value->ips;
	$ResultData[] = $value->ipk;
	$ResultData[] = $value->sks_smt;
	$ResultData[] = $value->sks_total;
	$ResultData[] = $value->nama_jurusan;
	if ($value->valid==1) {
		$ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-success" data-toggle="tooltip" data-placement="left" title="" data-original-title="Valid"><i class="fa fa-check"></i></button> '.$value->valid;
	} elseif ($value->valid==0) {
		$ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-warning tips" data-toggle="tooltip" data-placement="left" title="Belum Divalidasi" data-original-title="Belum Divalidasi"><i class="fa fa-info-circle"></i></button> '.$value->valid;
	} else {
		$sks_sem = "";
		if ($value->ket_sks_sem!='') {
			$sks_sem = $value->ket_sks_sem."<br>";
		}
		$ips_val = "";
		if ($value->ket_valid_ips!='') {
			$ips_val = $value->ket_valid_ips."<br>";
		}
		$ipk_val = "";
		if ($value->ket_valid_ipk!='') {
			$ipk_val = $value->ket_valid_ipk."<br>";
		}
		$ips_ipk = "";
		if ($value->ket_valid_ips_ipk!='') {
			$ips_ipk = $value->ket_valid_ips_ipk."<br>";
		}
		$krs_ada = "";
		if ($value->ket_krs_ada!='') {
			$krs_ada = $value->ket_krs_ada."<br>";
		}

		$ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-danger" data-toggle="tooltip" data-placement="left" data-html="true" data-original-title="'.$sks_sem.$ips_val.$ipk_val.$ips_ipk.$krs_ada.'"><i class="fa fa-info-circle"></i></button> '.$value->valid;
	}
	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
$akm_table->set_data($data);
//create our json
$akm_table->create_data();

