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


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

		$requestData= $_REQUEST;

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

		$requestData= $_REQUEST;
		$id_kelas_baru = array();

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


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

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

		$filter = '';

		$data_result = array();

		
		$order_by = "";


           $option = array(
			'1' => 'Ketua',
			'2' => 'Anggota',
			'3' => 'Personal',
			);
		$totalData = count($data_result);
		$totalFiltered = $totalData;

		$nipd = $_POST['nipd'];
		$filter_mhs = "trim(nipd)='$nipd'";

			$temp_data = array();
			$i=0;
/*			$temp_total = $proxy->GetCountDeletedRecordset($token,"nilai",$filter_mhs);
			$totalData = $temp_total['result'];
			$totalFiltered = $totalData;*/
			$temp_rec = $proxy->GetDeletedRecordset($token,"anggota_aktivitas_mahasiswa", $filter_mhs,$order_by, '','');

			if ($temp_rec['result']) {
				foreach ($temp_rec['result'] as $key) {
					$data_nilai[$key['id_akt_mhs']] = array(
						'id_ang_akt_mhs' => $key['id_ang_akt_mhs'],
						'id_akt_mhs' => $key['id_akt_mhs'],
						'judul_akt_mhs' => $key['judul_akt_mhs'],
						'jns_peran_mhs' => $key['jns_peran_mhs']
					);
					$id_kelas[$key['id_akt_mhs']] = $key['id_akt_mhs'];
				}
				//get kelas kuliah
				$in_id_kelas = "'" . implode("','", $id_kelas) . "'";
				$temp_data_kelas = [
						'act' => 'GetListAktivitasMahasiswa',
					    'token' => $token,
					    'filter' => "id_aktivitas in($in_id_kelas)",
					    'order' => '',
					    'limit' => '',
					    'offset' => ''

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

			 if ($temp_rec->data) {
					foreach ($temp_rec->data as $dt) {
						$id_kelas_exist[$dt->id_aktivitas] = $dt->id_aktivitas;
					}
					$total = 0;	
			foreach ($data_nilai as $key) {
				$temps = array();
				if (in_array($key['id_akt_mhs'], array_keys($id_kelas_exist))) {
	    			$temps[] = "<label class='mt-checkbox mt-checkbox-single mt-checkbox-outline'> <input type='checkbox' class='group-checkable check-selected' data-id='aktivitas' value='".$key['id_ang_akt_mhs']."'> <span></span></label>";
					$temps[] = $key['judul_akt_mhs'];
					if (in_array($key['jns_peran_mhs'], array_keys($option))) {
						$temps[] = $option[$key['jns_peran_mhs']];
					} else {
						$temps[] = "";
					}
					$temp_data[] = $temps;
					$total++;
				}

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