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


include "../../inc/config.php";

include "../../lib/prosesupdate/ProgressUpdater.php";

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

$angkatan = "";
$id_sms = "";
$filter_kelas = "";
$status_mhs = "";
		
		$requestData= $_REQUEST;

  		$nim = "nim like '%".$_POST['nim']."%' and id_prodi='".$_POST['jurusan']."'";

		$filter_kelas = trim($nim);
		

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

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

		$temp_total = [
			'act' => 'GetCountPerkuliahanMahasiswa',
		    'token' => $token,
		    'filter' => "$nim",
		];
		$temp_total = json_decode($db->run($temp_total,$url));
		$totalData = $temp_total->data;
		$order_by = "id_semester desc";

		$totalFiltered = $totalData;
		$temp_data_krs = [
			'act' => 'GetDetailPerkuliahanMahasiswa',
		    'token' => $token,
		    'filter' => "$nim",
		    'order' => "id_semester desc",
		    'limit' => $temp_limit,
		    'offset' => $temp_offset

		];

		$temp_data_krs = json_decode($db->run($temp_data_krs,$url));
			$temp_data = array();
			$i=0;
			if ($temp_data_krs->data) {
			foreach ($temp_data_krs->data as $key) {
			
				$temps = array();
				$temps[] = ++$i+$temp_offset;
				$temps[] = $key->id_semester;
				$temps[] = $key->nim;
				$temps[] = $key->nama_mahasiswa;
				$temps[] = $key->ips;
				$temps[] = $key->ipk;
				$temps[] = $key->id_status_mahasiswa;
				$temps[] = $key->nama_program_studi;
				$temps[] = $key->id_registrasi_mahasiswa.'|'.$key->id_semester.'|'.$key->id_prodi;
			
				$temp_data[] = $temps;
			}
			$temp_output = array(
									'draw' => intval($requestData['draw']),
									'recordsTotal' => intval( $totalData ),
									'recordsFiltered' => intval( $totalFiltered ),
									'data' => $temp_data
				);
			echo json_encode($temp_output);
} else {
	$temp_output = array(
									'draw' => intval($requestData['draw']),
									'recordsTotal' => intval( $totalData ),
									'recordsFiltered' => intval( $totalFiltered ),
									'data' => $temp_data
				);
	echo json_encode($temp_output);
}