<html>
<head>
</head>
<body>
<h1> Insert kelas_kuliah to Feeder </h1>
         
 <!-- Database sisfo -->
<?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=3; $i<=$hasildata; $i++) // membaca data dimulai baris ke 2
{
  /* ---------- Mencari id_sms -------------*/
  //echo "<br>";
  //echo "id_sp='".$id_sp."'<br>";
  $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,2))."%'";
  $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'];
  //$jen=$result['result']['id_jenj_didik']; 
  //echo "id_sms = '".$id_sms."'<br>";
  //echo "id_jenj_didik = '".$jen."'<br>";
  //$sks=$data->val($i,1);
  
  // mencari id_mk pada tabel mata_kuliah
		$kd_mk=trim($data->val($i,4)); 
		$kd="p.id_sms='$id_sms' AND kode_mk ILIKE '%$kd_mk%'";
		$result=$proxy->GetRecord($gettoken,'mata_kuliah',$kd);
		$id_mk=$result['result']['id_mk'];
		$sks_mk=$result['result']['sks_mk'];
		$sks_tm=$result['result']['sks_tm'];
		$sks_prak=$result['result']['sks_prak'];
		$sks_prak_lap=$result['result']['sks_prak_lap'];
		$sks_sim=$result['result']['sks_sim'];
		//echo "id MK : $id_mk <br>";
  
     

   $bahasan_case=trim($data->val($i,12));
   $a_selenggara_pditt=trim($data->val($i,13));
   $a_pengguna_pditt=trim($data->val($i,14));
   $kuota_pditt=trim($data->val($i,15));
   $tgl_mulai_koas=trim($data->val($i,16));
   $tgl_selesai_koas=trim($data->val($i,17));
   $id_mou=trim($data->val($i,18));
   $id_kls_pditt=trim($data->val($i,19));
   
  $record['id_sms']=$id_sms;  // inti
  $record['id_smt']=trim($data->val($i,3));     // inti
  $record['id_mk']=$id_mk;  // inti                     
  $record['nm_kls']= trim($data->val($i,6));    // inti                             
  $record['sks_tm']=$sks_tm;
  $record['sks_prak']=$sks_prak;
  $record['sks_prak_lap']=$sks_prak_lap;
  $record['sks_sim']=$sks_sim;
  $record['sks_mk']=$sks_mk;
//  $record['bahasan_case']=$bahasan_case;
//  $record['a_selenggara_pditt']=$a_selenggara_pditt;
//  $record['a_pengguna_pditt']=$a_pengguna_pditt;
//  $record['kuota_pditt']=$kuota_pditt;
  $record['tgl_mulai_koas']=$tgl_mulai_koas;
  $record['tgl_selesai_koas']=$tgl_selesai_koas;
//  $record['id_mou']=$id_mou;
//  $record['id_kls_pditt']=$id_kls_pditt;
  
  //$record['tgl_mulai_efektif']='2014-11-21';
  //$record['tgl_akhir_efektif']='2018-11-21';

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

  //print_r($records);

  $j_encode=json_encode($records);
  $kel_kul_json=$j_encode;
  //echo "SKS TOTAL= ".$sks_lls;
  //print_r($kel_kul_json);
  $j_decode=json_decode($j_encode,true);
  $kel_kul_jsdec=$j_decode;
  //print_r($kel_kul_jsdec=$j_decode);
  $result=$proxy->InsertRecordset($gettoken,'kelas_kuliah',$kel_kul_json);
  //print_r($result);
  //var_dump($result);
	echo "<pre style='background-color:#1699C9'>";
 if ($result['result']) {
	 $x=0;
  //for ($i=2; $i<=$hasildata; $i++){
   foreach ($j_decode as $row){
	$x++;
    $id_sms=$row['id_sms'];
    $id_smt=$row['id_smt'];
    $id_mk=$row['id_mk'];
	$nm_kelas=$row['nm_kls'];
    
    echo "<br>$x.  Id SMS : ".$id_sms." | Id SMT : ".$id_smt." | Id MK = ".$id_mk." | Nama Kelas = ".$nm_kelas;
    
    if ($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>";
?>

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