<?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++)

	{
	  $status=trim($data->val($i,3));
	  $tgl_keluar=trim($data->val($i,4));
	  $sk_yud=trim($data->val($i,5));
	  $tglls=trim($data->val($i,6));
	  //$ket='LULUS';	  
	  $jdl_skripsi=trim($data->val($i,12));
	  $no_ijazah=trim($data->val($i,9));
	  $bln_awal_bim=trim($data->val($i,10));
	  $bln_akhir_bim=trim($data->val($i,11));
	  $ipk=trim($data->val($i,8));
	  $nim=trim($data->val($i,1));
	  $nipd="nipd LIKE '%$nim%'";
	  //echo "nipd = $nipd";
	  $result=$proxy->GetRecord($gettoken,'mahasiswa_pt',$nipd);
	  $coba=$result['result'];
	  $id_reg_pd=$coba['id_reg_pd'];
	  //echo "id reg pd = $id_reg_pd";
	  
	  $record['id_reg_pd'] = $id_reg_pd;
	  $record['id_jns_keluar'] = $status;
	  $record['tgl_keluar'] = $tgl_keluar;
	  //$record['ket'] = $ket;
	  $record['sk_yudisium'] = $sk_yud;
	  $record['tgl_sk_yudisium'] = $tglls;
	  $record['judul_skripsi'] = $jdl_skripsi;
	  $record['ipk'] = $ipk;
	  $record['no_seri_ijazah'] = $no_ijazah;
	  $record['bln_awal_bimbingan'] = $bln_awal_bim;
	  $record['bln_akhir_bimbingan'] = $bln_akhir_bim;
	  $record['sdm1'] =trim($data->val($i,13));
	  $record['sdm2'] =trim($data->val($i,14));
	  $records[]=$record;
	}
	  for($i=0;$i<1;$i++){
		  foreach($records as $baris){
		  //echo $baris['id_reg_pd']."-".$baris['nipd']."-".$tglls."-".$jdl_skripsi."<br>";
		  $key=array('id_reg_pd'=>$baris['id_reg_pd']);
		  $data=array('id_jns_keluar'=>$baris['id_jns_keluar'],
						 'tgl_keluar'=>$baris['tgl_keluar'],
						 'sk_yudisium'=>$baris['sk_yudisium'],
					'tgl_sk_yudisium'=>$baris['tgl_sk_yudisium'],
					  'jalur_skripsi'=>1,    
					  'judul_skripsi'=>$baris['judul_skripsi'],
								'ipk'=>$baris['ipk'],
				  'no_seri_ijazah'=>$baris['no_seri_ijazah'],
		       'bln_awal_bimbingan'=>$baris['bln_awal_bimbingan'],
		      'bln_akhir_bimbingan'=>$baris['bln_akhir_bimbingan']);
			  
		  $rubahs[]=array('key'=>$key,'data'=>$data);
		  //echo "update =$rubahs";
		  //if ($hasildata) $sukses++;
			//  else $gagal++;

		  } // end foreach
		  $je_updt=json_encode($rubahs);
		  
		  //print_r($je_updt);
		  //$result=$proxy->UpdateRecordset($gettoken,'mahasiswa_pt',$je_updt); // fix
		  foreach ($rubahs as $rubah){
		  $upd=$proxy->UpdateRecord($gettoken,'mahasiswa_pt',json_encode($rubah));	
		  var_dump($upd);	  
		  
		  }
		 // var_dump($result);
		  
	      } // end for
	  
		  /* skrip dibawah ini untuk menyimpan record pada tabel dosen_pembimbing/data postgresql siak/akt_ajar_sp */
	for($i=0;$i<1;$i++){
	  foreach ($records as $dropin){
		  if ($baris['sdm2']!=''){
				   $pemb1='1';
				   $sdm1=trim($dropin['sdm1']);
				   //$id_sdm="nidn='$sdm1'";
				   $id_sdm="nidn like '%$sdm1%'";
				   //echo $id_sdm;
				   $result=$proxy->GetRecord($gettoken,'dosen',$id_sdm);
				   @$id=$result['result']['id_sdm'];
				   
				   
				   $rec['id_sdm']=$id;
				   $rec['id_reg_pd']=$dropin['id_reg_pd'];
				   $rec['urutan_promotor']=$pemb1;
				   $recs[]=$rec;
				   echo "<br>Pembimbing 1 =".$rec['id_sdm']."- id_reg_pd =".$dropin['id_reg_pd']."- urutan_promotor =".$pemb1."<br>";
				   //var_dump($recs);
				   //foreach ($recs as $rec){
				   $result4=$proxy->InsertRecord($gettoken,'dosen_pembimbing',json_encode($rec));
				   //var_dump($result4);
				   //}
				   //echo "<br />";
				   
				   $pemb2='2';
				   $sdm2=trim($dropin['sdm2']);
				   //$id_sdm1="nidn='$sdm2'";
				   $id_sdm1="nidn like '%$sdm2%'";
				   $result1=$proxy->GetRecord($gettoken,'dosen',$id_sdm1);
				   @$id1=$result1['result']['id_sdm'];
				   
				   
				   $rec1['id_sdm']=$id1;
				   $rec1['id_reg_pd']=$dropin['id_reg_pd'];
				   $rec1['urutan_promotor']=$pemb2;
				   $recs1[]=$rec1;
				   echo "Pembimbing 2 =".$id1."- id_reg_pd =".$dropin['id_reg_pd']."- urutan_promotor =".$pemb2."<br>";
				   //var_dump($recs1);
				   //foreach ($recs1 as $rec1){
				   $result3=$proxy->InsertRecord($gettoken,'dosen_pembimbing',json_encode($rec1));
				   //var_dump($result3);
				   //}
				   
				   
				   }
			  else{  $pemb1='1';
				   $sdm1=$dropin['sdm1'];
				   //$id_sdm="nidn='$sdm1'";
				   $id_sdm="nidn like '%$sdm1%'";
				   $result=$proxy->GetRecord($gettoken,'dosen',$id_sdm);
				   @$id=$result['result']['id_sdm'];
				   
				   
				   $rec['id_sdm']=$id;
				   $rec['id_reg_pd']=$dropin['id_reg_pd'];
				   $rec['urutan_promotor']=$pemb1;
				   $recs[]=$rec;
				   echo "Pembimbing 1 =".$rec['id_sdm']."- id_reg_pd =".$dropin['id_reg_pd']."- urutan_promotor =".$pemb1."<br>";
				   //var_dump($recs);
				   
				   //foreach ($recs as $rec){
				   $result=$proxy->InsertRecord($gettoken,'dosen_pembimbing',json_encode($rec));
				   //var_dump($result4);
				   //}
			  }
		  } // end foreach dropin
	} // end for
	echo "<pre style='background-color:#1699C9'>";
	//if ($upd['result']) { 
	for($i=0;$i<1;$i++){
			foreach($records as $ada){
				$nim=$ada['id_reg_pd'];
				$filt="id_reg_pd='$nim' And p.id_jns_keluar='1'";
				$result=$proxy->GetRecord($gettoken,'mahasiswa_pt',$filt);
				$nipd=$result['result']['nipd'];
				$nama=$result['result']['nm_pd'];
				$ijzah=$result['result']['no_seri_ijazah'];
				echo "NPM = ".$nipd." - Nama =".$nama." - No Ijazah = ".$ijzah."<br />";
				if ($result['result'])
				   $sukses++;
		  	    else $gagal++;
			}
	}
	//}
	echo "</pre>";
		
		echo "<br /><b>Update data selesai.</b> <br>";
		echo "Data yang berhasil diupdate : " . $sukses .  "<br>";
		echo "Data yang gagal diupdate : ".$gagal .  "<br>";
		echo "kembali ke <a href='?module=home'>depan</a>";

?>
