<html>
<head>
<title>Insert Kurikulum</title>
<?php
//include 'session.php';
include "module/excel_reader2.php";
@$data = new Spreadsheet_Excel_Reader($_FILES['fileexcel']['tmp_name']);
@$hasildata = $data->rowcount($sheet_index=0);
$sukses = 0;
$gagal = 0;

for ($i=2; $i<=$hasildata; $i++) // membaca data dimulai baris ke 2
{//echo "<br>";
		//echo "id_sp='".$id_sp."'<br>";
		$id_sp1="id_sp='".$id_sp."'";
		//echo $id_sp1."<br>";
		$prodi=trim($data->val($i,2)); 			  
		//echo "kode prodi : ".trim($data->val($i,2)."<br>";
		$kode_prodi="kode_prodi ILIKE '%$prodi%'";
		$filter=$kode_prodi." AND ".$id_sp1;
		//echo $filter."<br>";
		//$tbl_sms='sms';
		//$result=$proxy->GetRecord($gettoken,$tbl_sms,$kode_prodi);
		$result=$proxy->GetRecord($gettoken,'sms',$filter);
		//var_dump($result);
		//$coba=$result['result'];
		$id_sms=$result['result']['id_sms'];
		$jen=$result['result']['id_jenj_didik']; 
		//echo "id_sms = '".$id_sms."'<br>";
		//echo "id_jenj_didik = '".$jen."'<br>";
  $record['id_kurikulum_sp']='';
  $record['id_sms']=$id_sms;
  $record['id_jenj_didik']=$jen;
  $record['id_smt']=trim($data->val($i,5)); 
  $record['nm_kurikulum_sp']= trim($data->val($i,3));                         // inti
  $record['jml_sem_normal']=8;
  $record['jml_sks_lulus']=(integer)trim($data->val($i,8));
  $record['jml_sks_wajib']=(integer)trim($data->val($i,6));
  $record['jml_sks_pilihan']=(integer)trim($data->val($i,7));
  //$record['tgl_mulai_efektif']='2014-11-21';
  //$record['tgl_akhir_efektif']='2018-11-21';

  $records[]=$record; //data dikumpulkan pada array records
  
  }

  $j_encode=json_encode($records);
  $je_kurikulum=$j_encode;
  //echo "SKS TOTAL= ".$sks_lls;
  //print_r($kel_kul_json);
  $j_decode=json_decode($j_encode,true);
  $jd_kurikulumc=$j_decode;
  //print_r($kel_kul_jsdec=$j_decode);
  $result=$proxy->InsertRecordset($gettoken,'kurikulum',$je_kurikulum);
  
  //print_r($result);
  //var_dump($result);
    echo "<pre style='background-color:#1699C9'>";
	if ($result['result']) {
		//for ($i=2; $i<=$hasildata; $i++){
			foreach ($j_decode as $row){
				//$id_kurikulum=$result['result']['id_kurikulum_sp'];
				$id_sms=$row['id_sms'];
				$nm_kur=$row['nm_kurikulum_sp'];
				$smt=$row['id_smt'];
				//$sks=$row['sks_mk'];
				
				echo "<br>Id_SMS MK : ".$id_sms." | Nm Kurikulum = ".$nm_kur. " | Semester = ".$smt;
				
				if ($nm_kur !='') $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>";
?>

</tr>
</tr>
</body>
</html>
