<?php
session_start();
include "../../../inc/config.php";
include "../../new_data.php";
$new_data = new new_data("mysql");	
$columns = array(
	'kode_mk',
	'nama_mk',
	'semester',
	'jns_mk',
	'sks_tm',
	'tahun',
	'nama_jurusan',
	'status_error',
	'status_error_kur',
	'mat_kurikulum.id'
	);

$sem_kur_filter = '';
$semester = '';
$jns_mk = '';
$jurusan = '';
$status = '';
$status_mkur = "";
if (isset($_POST['semester'])) {
	if ($_POST['sem_kur_filter']!='all') {
		$sem_kur_filter = " and tahun='".$_POST['sem_kur_filter']."'";
	}

	if ($_POST['semester']!='all') {
		$semester = "and semester='".$_POST['semester']."'";
	}

	if ($_POST['jns_mk']!='all') {
		$jns_mk = "and jns_mk='".$_POST['jns_mk']."'";
	}

	if ($_POST['jurusan']=='all') {
		if ($_SESSION['level']!=1) {
			$jurusan = "and mat_kurikulum.kode_jurusan='".$_SESSION['jurusan']."'";
		}
	} else {
		$jurusan = "and mat_kurikulum.kode_jurusan='".$_POST['jurusan']."'";
	}

	if ($_POST['status_filter']!='all') {
		$status = " and status_error='".$_POST['status_filter']."'";
	} 
	if ($_POST['status_mkur']!='all') {
		$status_mkur = " and status_error_kur='".$_POST['status_mkur']."'";
	}
	$query = $new_data->get_custom("select mat_kurikulum.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from mat_kurikulum left join jurusan on mat_kurikulum.kode_jurusan=jurusan.kode_jurusan where 1=1 $sem_kur_filter $jurusan	$semester $status $status_mkur $jns_mk ",$columns);

} else {
	if ($_SESSION['level']!=1) {
		$jurusan = "and mat_kurikulum.kode_jurusan='".$_SESSION['jurusan']."'";
	}
	$query = $new_data->get_custom("select mat_kurikulum.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from mat_kurikulum left join jurusan on mat_kurikulum.kode_jurusan=jurusan.kode_jurusan where 1=1 $jurusan ",$columns);

}
 $stat = array(
  'A' => "Wajib",
  'B' => "Pilihan",
  'C' => "Wajib Peminatan",
  'D' => "Pilihan Peminatan",
  'S' => "Tugas Akhir / Skripsi"
  );

$data = array();
$jns = "";
foreach ($query	as $value) {
	$ResultData = array();
	$ResultData[] = "<input type='checkbox'  class='deleteRow' value='".$value->id."'/>";
	$ResultData[] = $value->kode_mk;
	$ResultData[] = $value->nama_mk;
	$ResultData[] = $value->semester;

	if (in_array($value->jns_mk, array_keys($stat))) {
		$jns = $stat[$value->jns_mk];
	}

	$ResultData[] = $jns;
	$jmlsks_mk=$value->sks_tm+$value->sks_prak+$value->sks_prak_lap+$value->sks_sim;
	$ResultData[] = $jmlsks_mk;
	$ResultData[] = $value->tahun;
	$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;
	}
	if ($value->status_error_kur==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_kur;
	} elseif ($value->status_error_kur==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_kur;
	} else {
		$ResultData[] = '<button rel="tooltip" type="button" class="btn btn-xs btn-danger" data-toggle="tooltip" data-placement="left" title="'.$value->keterangan_kur.'" data-original-title="'.$value->keterangan_kur.'"><i class="fa fa-info-circle"></i></button> '.$value->status_error_kur;
	}
	$ResultData[] = $value->id;

	$data[] = $ResultData;
}

//get sukses mkur
$belum_mkur = $db->fetch_custom_single("select count(*) as jml from mat_kurikulum where status_error_kur=0 $sem_kur_filter $jurusan	$semester $jns_mk ");
$belum_mkur_count = $belum_mkur->jml;

//get sukses mkur
$sukses_mkur = $db->fetch_custom_single("select count(*) as jml from mat_kurikulum where status_error_kur=1 $sem_kur_filter $jurusan	$semester $jns_mk ");
$sukses_mkur_count = $sukses_mkur->jml;
//get sukses mkur
$error_mkur = $db->fetch_custom_single("select count(*) as jml from mat_kurikulum where status_error_kur=2 $sem_kur_filter $jurusan	$semester $jns_mk ");
$error_mkur_count = $error_mkur->jml;
//set data
$new_data->set_data($data);
$new_data->set_callback(
array(
	'belum_mkur' => $belum_mkur_count,
	'sukses_kur' => $sukses_mkur_count,
	'error_kur' => $error_mkur_count
	)
);
//create our json
$new_data->create_data();

