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

$token = $db->get_token();
$url = $db->get_service_url('rest');


$filter = "";
$filter_kelas = "";


		$requestData= $_REQUEST;

		$sSearch = $requestData['search']['value'];
		
		//$Data = $this->input->get('columns');
		//$orders = $requestData['order'];
		//$temp_order = 


		$iStart = $requestData['start'];
		$iLength = $requestData['length'];

		$temp_limit = $iLength;
		$temp_offset = $iStart?$iStart : 0;

$sSearch = addslashes($sSearch);


$angkatan = "";
$id_prodi = "";
$angkatan_count = "";
$id_prodi_count = "";
$search_nilai = "";
$filter_nilai_count = "";

if ($_POST['angkatan']!='all') {
	$angkatan = "and id_periode_masuk='".$_POST['angkatan']."'";
	$angkatan_count = "and id_registrasi_mahasiswa in(select id_reg_pd from reg_pd where mulai_smt='".$_POST['angkatan']."')";
}

if ($_POST['jurusan']!='all') {
  	$id_prodi = "and id_prodi='".$_POST['jurusan']."'";
  	$id_prodi_count = "and id_registrasi_mahasiswa in(select id_reg_pd from reg_pd where id_sms='".$_POST['jurusan']."')";
}



if ($sSearch!='') {

		$search_nilai = "and (nim like '%".$sSearch."%' or lower(nama_mahasiswa) like '%".strtolower($sSearch)."%' or lower(kode_matkul_diakui) like '%".strtolower($sSearch)."%')";
}

		$filter_nilai = "id_transfer is not null $angkatan $id_prodi $search_nilai";
		$filter_nilai_count = "id_transfer is not null $angkatan_count $id_prodi_count $search_nilai";
		$order_by = "nim desc";

				$temp_data_akm = [
			'act' => 'GetNilaiTransferPendidikanMahasiswa',
		    'token' => $token,
		    'filter' => $filter_nilai,
		    'order' => '',
		    'limit' => $temp_limit,
		    'offset' => $temp_offset

		];




		$temp_data = json_decode($db->run($temp_data_akm,$url));

		//print_r($temp_data);


		$count_akm = [
			'act' => 'GetCountNilaiTransferPendidikanMahasiswa',
		    'token' => $token,
		    'filter' => $filter_nilai_count
		];

		
		
		$temp_recs = json_decode($db->run($count_akm,$url));



		

		$totalData = $temp_recs->data;
		$totalFiltered = $totalData;

		$temp_datas = array();
		$i=0;
		
		foreach ($temp_data->data as $dt) {
			
						$temps = array();
					$temps[] = ++$i+$temp_offset." <input type='checkbox'  class='deleteRow' value='".$dt->id_transfer."'/>";
					$temps[] = $dt->nim;
					$temps[] = $dt->nama_mahasiswa;
					$temps[] = $dt->id_periode_masuk;
	                $temps[] = $dt->nama_mata_kuliah_asal;
	                $temps[] = $dt->sks_mata_kuliah_asal;
	                $temps[] = $dt->nilai_huruf_asal;
	                $temps[] = $dt->kode_matkul_diakui;
	                $temps[] = $dt->sks_mata_kuliah_diakui;
	                $temps[] = $dt->nilai_huruf_diakui;
	                $temps[] = $dt->nilai_angka_diakui;
	                $temps[] = $dt->nama_jenis_aktivitas;
	                $temps[] = $dt->id_semester;
	                $temps[] = $dt->nama_program_studi;
	                $temps[] = $dt->id_transfer;
					
				$temp_datas[] = $temps;
			}
			$temp_output = array(
									'draw' => intval($requestData['draw']),
									'recordsTotal' => intval( $totalData ),
									'recordsFiltered' => intval( $totalFiltered ),
									'data' => $temp_datas
				);

			echo json_encode($temp_output);