<?php
session_start();
include "../../inc/config.php";
$columns = array(
	'nim',
	'nama',
	'nik',
	'nisn',
	'no_hp',
	'email',
	'jln',
	'id_wil',
	'nama_jurusan',
	'status_error',
	'update_nik.id'
	);

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

 where update_nik.id is not null $jurusan $status",$columns);
} else {
	if (isset($_POST['jurusan_user'])) {
		$query = $new_table->get_custom("select update_nik.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from update_nik left join jurusan on update_nik.kode_jurusan=jurusan.kode_jurusan
 where jurusan.kode_jurusan='".$_POST['jurusan_user']."' ",$columns);
	} else {
		$query = $new_table->get_custom("select update_nik.*,concat(jenjang,' ',nama_jurusan) as nama_jurusan from update_nik left join jurusan on update_nik.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->nim;
	$ResultData[] = $value->nama;
	$ResultData[] = $value->nik;
	$ResultData[] = $value->nisn;
	$ResultData[] = $value->no_hp;
	$ResultData[] = $value->email;
	$ResultData[] = $value->jln;
	$ResultData[] = $value->id_wil;
	$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();
