<?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=2; $i<=$hasildata; $i++)
{
		$id_sp1="id_sp='".$id_sp."'";
		//echo $id_sp1."<br>";
		//$prodi=$data->val($i,2);      
		//echo "kode prodi : ".$data->val($i,2)."<br>";
		$kode_prodi="kode_prodi ILIKE '%".trim($data->val($i,11))."%'";
		$filter=$kode_prodi." AND ".$id_sp1;
		//echo $filter."<br>";
		$result=$proxy->GetRecord($gettoken,'sms',$filter);
		//var_dump($result);
		//$coba=$result['result'];
		$id_sms=$result['result']['id_sms'];
		
		$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));
		$smt=trim($data->val($i,6));
		$kelas=trim($data->val($i,7));
		$filt="p.id_smt='$smt' AND nm_kls='$kelas' AND kode_mk='$kd_mk' AND p.id_sms= '$id_sms'";
		//echo $filt."<br>";
		$result=$proxy->GetRecord($gettoken,'kelas_kuliah',$filt);
		$id_kls=$result['result']['id_kls'];
		//echo "id kelas : ".$id_kls. "<br>";
		
	$record['id_kls'] = $id_kls; 
	$record['id_reg_pd'] = $id_reg_pd;
	  $nilai= $data->val($i,8);
	  $indeks=$data->val($i,9);
	  //echo "Nilai =".$nilai."dan Indeks =".$indeks;
	$record['asal_data']=9;
	$record['nilai_huruf'] =$nilai;
	$record['nilai_indeks'] =$indeks;
  	$records[]=$record;
	
}
	$je_krs=json_encode($records);
	$jd_krs=json_decode($je_krs,true);
	//print_r($je_nil);
	
	
		$result=$proxy->InsertRecordset($gettoken,'nilai',$je_krs);    // fix insert banyak records

	echo "<pre style='background-color:#1699C9'>";
	if ($result['result']) {
		for($i=0;$i<1;$i++){
			foreach($jd_krs as $row){
				$id_kls=$row['id_kls'];
				$id_reg_pd=$row['id_reg_pd'];
				//$kd_mk1=$row['kode_mk'];
	
			echo "<br>Id Kelas : ".$id_kls." | Id reg pd : ".$id_reg_pd;//." | Kode MK = ".$kd_mk1;
			if ($id_reg_pd !='' and $id_kls !='') $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>";
?>
	
?>