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

$columns = array(
	'nama_kur',
	'mulai_berlaku',
	'jml_sks_wajib',
	'jml_sks_pilihan',
	'total_sks',
	'nama_jurusan',
	'status_error',
	'kurikulum.id'
	);


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


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

} else {
	if (isset($_POST['jurusan_user'])) {
		$query = $new_table->get_custom("select kurikulum.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from kurikulum left join jurusan on kurikulum.kode_jurusan=jurusan.kode_jurusan where jurusan.kode_jurusan='".$_POST['jurusan_user']."' ",$columns);

	} else {
		$query = $new_table->get_custom("select kurikulum.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from kurikulum left join jurusan on kurikulum.kode_jurusan=jurusan.kode_jurusan ",$columns);
	}

}





$data = array();

foreach ($query	as $value) {
	$ResultData = array();
	$ResultData[] = $value->nama_kur;
	$ResultData[] = $value->mulai_berlaku;
	$ResultData[] = $value->total_sks;
	$ResultData[] = $value->jml_sks_wajib;
	$ResultData[] = $value->jml_sks_pilihan;
	$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();



