<?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;
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'];
		$id_sms=$result['result']['id_sms'];
		//echo "id_reg_pd ='".$id_reg_pd."<br>";
		$kd_mk=trim($data->val($i,4));
		$filt="kode_mk ILIKE '%$kd_mk%' AND p.id_sms='$id_sms'";
		//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_mk=$row['id_mk'];
				$id_reg_pd=$row['id_reg_pd'];
				$sks_trans=$row['sks_diakui'];
				$nilai_trans=$row['nilai_huruf_diakui'];
				
				//$kd_mk=$row['kode_mk'];
			
			
			echo "<br>Id reg pd : ".$id_reg_pd." | Id MK : ".$id_mk." | Sks Diakui = ".$sks_trans." | Nilai Huruf Diakui = ".$nilai_trans;
			if ($id_reg_pd !='' and $id_mk !='' ) $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>";
	
?>