<?php
session_start();

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


$url = get_service_url('rest');
$token = get_token();

$requestData= $_REQUEST;

$sSearch = $requestData['search']['value'];

$data_sms = $db->fetch_custom("select * from jurusan");
foreach ($data_sms as $dts) {
	$dts_sms[$dts->id_sms] = $dts->jenjang.' '.$dts->nama_jurusan;
}
$angkatan = '';
$tahun_keluar = "";
$jenis_keluar = "";
$jenis_keluar_old = "";
$filter_kelulusan_count = "";
$id_sms = "";
$id_periode_keluar = "";
$id_sms_old = "";
$angkatan_old = "";
$tahun_keluar_old = "";
$tahun_keluar_count = "";
$filter_kelulusan = "";
$periode_count = "";


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


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


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

  if ($_POST['id_periode_keluar']!='all') {
     $id_periode_keluar = "and id_periode_keluar='".trim($_POST['id_periode_keluar'])."'";    
     $periode_count = "and id_registrasi_mahasiswa in(select id_reg_pd  from reg_pd where smt_yudisium='".$_POST['id_periode_keluar']."' and id_jns_keluar is not null)"; 
  }

  $filter_kelulusan = "$id_sms $angkatan $jenis_keluar $id_periode_keluar";
  $filter_kelulusan_count = "$id_sms $angkatan  $jenis_keluar $periode_count";



$filter_kelulusan = trim($filter_kelulusan);

$filter_kelulusan_count = trim($filter_kelulusan_count);

$semester = '';
$kode_mk = '';
$nama = "";
$sSearch = addslashes($sSearch);


	if ($sSearch!='') {
				$filter_kelulusan .= "and (nim like '%".$sSearch."%' or nama_mahasiswa like E'%".$sSearch."%')";
				$filter_kelulusan_count .= "and (nim like '%".$sSearch."%' or nama_mahasiswa like E'%".$sSearch."%')";

	}





		$requestData= $_REQUEST;

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


		$filter_kelulusan = "id_registrasi_mahasiswa is not null $filter_kelulusan";
		$filter_kelulusan_count = "id_registrasi_mahasiswa is not null $filter_kelulusan_count";

		//echo $filter_kelulusan;

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

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


		$order_by = "angkatan DESC";

		
		$temp_data_kelas = [
			'act' => 'GetListMahasiswaLulusDO',
		    'token' => $token,
		    'filter' => trim($filter_kelulusan),
		    'order' => $order_by,
		    'limit' => $temp_limit,
		    'offset' => $temp_offset

		];


		$temp_rec = json_decode($db->run($temp_data_kelas,$url));

		$count = get_data_services('GetCountMahasiswaLulusDO',trim($filter_kelulusan_count));

		//dump($temp_data_kelas);
		//dump($filter_kelulusan_count);
		$totalData = $count;
		$totalFiltered = $totalData;

 

	
			$temp_data = array();
			$i=0;
			foreach ($temp_rec->data as $key) {
				$temps = array();
				$temps[] = ++$i+$temp_offset." <input type='checkbox'  class='deleteRow' value='".$key->id_registrasi_mahasiswa."'/>";
				$temps[] = $key->nim;
				$temps[] = $key->nama_mahasiswa;
				$temps[] = $key->angkatan;
				$temps[] = $key->nama_jenis_keluar;
				$temps[] = $key->tanggal_keluar;
				$temps[] = $key->id_periode_keluar;
				$temps[] = $dts_sms[$key->id_prodi];
				
				$temps[] = $key->id_registrasi_mahasiswa;

			
				$temp_data[] = $temps;
			}
			$temp_output = array(
									'draw' => intval($requestData['draw']),
									'recordsTotal' => intval( $totalData ),
									'recordsFiltered' => intval( $totalFiltered ),
									'data' => $temp_data
				);
			echo json_encode($temp_output);
