<?php
//include 'session.php';
include "module/excel_reader2.php";
@$data = new Spreadsheet_Excel_Reader($_FILES['fileexcel']['tmp_name']);
@$hasildata = $data->rowcount($sheet_index=0);
//echo $hasildata;
$sukses = 0;
$gagal = 0;
$sukses1=0;
for ($i=3; $i<=$hasildata; $i++)
{
		$npm=trim($data->val($i,2));
		$nipd="nipd LIKE '%$npm%'";
		//echo "<br>".$nipd."<br>";
		$result=$proxy->GetRecord($gettoken,'mahasiswa_pt',$nipd);
		$id_reg_pd=$result['result']['id_reg_pd'];
		//echo "id_reg_pd ='".$id_reg_pd."<br>";
		$kd_mk=trim($data->val($i,4));
		$filt="kode_mk ILIKE '%$kd_mk%'";
		//echo $filt."<br>";
		$result=$proxy->GetRecord($gettoken,'mata_kuliah',$filt);
		$id_mk=$result['result']['id_mk'];
		//echo "id kelas : ".$id_kls. "<br>";
		$kode_mk_asal =trim($data->val($i,6));
		$nm_mk_asal =trim($data->val($i,7));
		$sks_asal  =trim($data->val($i,8));
		$sks_diakui  =trim($data->val($i,9));
		$nilai_huruf_asal   =trim($data->val($i,10));
		$nilai_huruf_diakui   =trim($data->val($i,11));
		$nilai_angka_diakui    =trim($data->val($i,12));
		
	$record['id_reg_pd'] = $id_reg_pd;	
	$record['id_mk'] = $id_mk; 
	$record['kode_mk_asal'] =$kode_mk_asal;
	$record['nm_mk_asal'] =$nm_mk_asal;
	$record['sks_asal'] =$sks_asal;
	$record['sks_diakui'] =$sks_diakui;
	$record['nilai_huruf_asal'] =$nilai_huruf_asal;
	$record['nilai_huruf_diakui'] =$nilai_huruf_diakui;
	$record['nilai_angka_diakui'] =$nilai_angka_diakui;
  	$records[]=$record;
	
}
	$je_nil_trans=json_encode($records);
	$jd_nil_trans=json_decode($je_nil_trans,true);
	//print_r($je_nil_trans);
	
	$result=$proxy->InsertRecordset($gettoken,'nilai_transfer',$je_nil_trans);    // fix insert banyak records
	var_dump($result);
	
	echo "<pre style='background-color:#1699C9'>";
	
	
	
	if ($result['result']) {
		for($i=0;$i<1;$i++){
			foreach($jd_nil_trans as $row){
				$id_reg_pd=$row['id_reg_pd'];
				$id="p.id_reg_pd='$id_reg_pd'";
				//echo $id."<br />";
				$result1=$proxy->GetRecord($gettoken,'nilai_transfer',$id);
				@$nipd=$result1['result']['nipd'];
				if ($nipd != '') {
				@$kd_mk=$result1['result']['kode_mk_asal'];
				@$sks_trans=$result1['result']['sks_diakui'];
				@$nilai_trans=$result1['result']['nilai_huruf_diakui'];
				@$nilai_angka_diakui=$result1['result']['nilai_angka_diakui'];
				//if ($nipd !='' and $kd_mk !=''){
					echo "<br>NPM : ".@$nipd." | Kode MK : ".@$kd_mk." | Sks Diakui = ".@$sks_trans." | Nilai Huruf Diakui = ".@$nilai_trans.
							     " | Nilai Angka Diakui = ".@$nilai_angka_diakui;
					$sukses1++;
				}
				$gagal++;
				//$rec['id_mk']=$id_mk;
//				$rec['sks_diakui']=$sks_trans;
//				$rec['nilai_huruf_diakui']=$nilai_trans;
//				$rec['nilai_angka_diakui']=$nilai_angka_diakui;
//				$recs[]=$rec;
//				//$kd_mk=$row['kode_mk'];
//				$je_trans=json_encode($recs);
//				$jd_trans=json_decode($je_trans,true);
//					//foreach($jd_trans as $trans){
//						@$nipd=$trans['nipd'];
//						@$nm_mk=$trans['nm_mk_asal'];
//						@$sks=$trans['sks_diakui'];
//						@$n_huruf=$trans['nilai_huruf_diakui'];
//						@$n_angka=$trans['nilai_angka_diakui'];
//				    	//if ($nipd !='') {
						//	$sukses++;
				    		
						//else {$gagal++;}
					//}
			}	
		}	
	}
	echo "</pre>";
	
echo "<b>import data selesai.</b> <br>";
echo "Data yang berhasil di import : " . $sukses .  "<br>";
echo "Data yang gagal diimport : ".$gagal .  "<br>";
echo "kembali ke <a href='?module=home'>depan</a>";	
?>