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


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

		$requestData= $_REQUEST;


		$sSearch = $requestData['search']['value'];
		$dt_agama = array();

		$data_sms = $db->fetch_custom("select * from agama");
		foreach ($data_sms as $dts) {
			$dt_agama[$dts->id_agama] = $dts->nm_agama;
		}

		$filter_mhs = "";
		if ($sSearch) {
				$filter_mhs = "lower(nm_pd) like '%".strtolower($sSearch)."%'";
		}

		$client = new nusoap_client($db->get_service_url('soap'), true);
		$proxy = $client->getProxy();
		$token = $db->get_token();

		$requestData= $_REQUEST;

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


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

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

		$filter = '';

		$data_result = array();

		
		$order_by = "nm_pd asc";



		$totalData = count($data_result);
		$totalFiltered = $totalData;

			

			$temp_data = array();
			$i=0;
			$temp_total = $proxy->GetCountDeletedRecordset($token,"mahasiswa",$filter_mhs);
			$totalData = $temp_total['result'];
			$totalFiltered = $totalData;
			$temp_rec = $proxy->GetDeletedRecordset($token,"mahasiswa", $filter_mhs,$order_by, $temp_limit,$temp_offset);

			if ($temp_rec['result']) {
			foreach ($temp_rec['result'] as $key) {
/*
				print_r($key);
				print_r($dt_agama);
*/
				$temps = array();
				$temps[] = $key['id_pd'];
				$temps[] = $key['nm_pd'];
				$temps[] = $key['tgl_lahir'];
				$temps[] = $key['tmpt_lahir'];
				$temps[] = $key['jk'];
				if (in_array(trim($key['id_agama']), array_keys($dt_agama))) {
					$temps[] = $dt_agama[trim($key['id_agama'])];
				} else {
					$temps[] = "";
				}
				$temps[] = $key['nik'];
				$temps[] = $key['nm_ibu_kandung'];
				$temps[] = $key['id_pd'];
				$temp_data[] = $temps;
			}

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