<html>
<head>
</head>
<body>
<h1> Insert Setting Periode to Feeder </h1>
         
 <!-- Database sisfo -->
<?php
//include '../kelas_kuliah/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 3
{
  /* ---------- 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,3))."%'";
  $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>";
     
   $id_smt=trim($data->val($i,2));  
   $target_maba=trim($data->val($i,4));  
   $ikut_seleksi=trim($data->val($i,5));
   $lulus_seleksi=trim($data->val($i,6));
   $terdaftar=trim($data->val($i,7));
   $mengundurkan=trim($data->val($i,8));
   $tgl_awal_kuliah=trim($data->val($i,9));
   $tgl_akhir_kuliah=trim($data->val($i,10));
   $jml_minggu=trim($data->val($i,11));
   
  $record['id_sms']=$id_sms;  // inti
  $record['id_smt']=$id_smt;     // inti
  $record['target_mhs_baru']=$target_maba;  // inti                     
  $record['calon_ikut_seleksi']= $ikut_seleksi;    // inti                           
  $record['calon_lulus_seleksi']=$lulus_seleksi;
  $record['daftar_sbg_mhs']=$terdaftar;
  $record['pst_undur_diri']=$mengundurkan;
  $record['tgl_awal_kul']=$tgl_awal_kuliah;
  $record['tgl_akhir_kul']=$tgl_akhir_kuliah;
  $record['jml_mgu_kul']=$jml_minggu;

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

  //print_r($records);

  $j_encode=json_encode($records);
  $set_Periode=$j_encode;
  //echo "SKS TOTAL= ".$sks_lls;
  //print_r($kel_kul_json);
  $j_decode=json_decode($j_encode,true);
  $set_periode_jsdec=$j_decode;
  //print_r($kel_kul_jsdec=$j_decode);
  $result=$proxy->InsertRecordset($gettoken,'daya_tampung',$set_Periode);
  //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_sms=$row['id_sms'];
    $id_smt=$row['id_smt'];
    $jum_mhs=$row['daftar_sbg_mhs'];
	$jum_minggu=$row['jml_mgu_kul'];
    
    echo "<br>Id SMS : ".$id_sms." | Id SMT : ".$id_smt." | Id MK = ".$jum_mhs." | Nama Kelas = ".$jum_minggu;
    
    if ($id_sms !='') $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>
