<h1> Insert Pembimbing Mahasiswa 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;
//echo $hasildata."<br>";
for ($i=3; $i<=$hasildata; $i++) // membaca data dimulai baris ke 3
{
		
		$id_sp1="id_sp='$id_sp'";
		
			$kd_prodi=trim($data->val($i,10));
			$filt_pro="kode_prodi='$kd_prodi'";
			$result=$proxy->GetRecord($gettoken,'sms',$filt_pro);
			$prodi=$result['result']['nm_lemb'];
		$record['nm_lemb']=$prodi;
		
			$id_smt=trim($data->val($i,2));
			$filt_smt="id_smt='$id_smt'";
			$result=$proxy->GetRecord($gettoken,'semester',$filt_smt);
			$nm_smt=$result['result']['nm_smt'];
		$record['nm_smt']=$nm_smt;				
//			
//			$nipd=trim($data->val($i,11));
//			$filt="nipd like '%$nipd%'";
//			//echo "<br />filter : $filt";
//			$result=$proxy->GetRecord($gettoken,'mahasiswa_pt',$filt);
//			$id_reg_pd=$result['result']['id_reg_pd'];
//			$nm_pd=$result['result']['nm_pd'];
//			
//			//echo "<br />id_reg_pd : $id_reg_pd";
//		$record['id_reg_pd']=$id_reg_pd;
		
			$judul=trim($data->val($i,3));
		$record['judul_akt_mhs']=$judul;
		
			$filter="judul_akt_mhs LIKE '%$judul%'";
			$result=$proxy->GetRecord($gettoken,'aktivitas_mahasiswa',$filter);
			$id_akt_mhs=$result['result']['id_akt_mhs'];
			//echo "<br />id aktifitas : $filter";
			//echo "<br />id aktifitas : $id_akt_mhs";
		
		$record['id_akt_mhs']=$id_akt_mhs;
//		$record['nm_pd']=$nm_pd;
//		$record['nipd']=$nipd;	
//		
//			$jns_peran_mhs=trim($data->val($i,12));
			//echo "<br /> jenis peran :$jns_peran_mhs <br />";
//		$record['jns_peran_mhs']=$jns_peran_mhs;
			$nidn_pembb1=trim($data->val($i,13));
			$id_kat_giat1=trim($data->val($i,14));
		$record['nidn_pembb1']=$nidn_pembb1;
		$record['id_kat_giat1']=$id_kat_giat1;
			$nidn_pembb2=trim($data->val($i,15));
			$id_kat_giat2=trim($data->val($i,16));
		$record['nidn_pembb2']=$nidn_pembb2;
		$record['id_kat_giat2']=$id_kat_giat2;


  		$records[]=$record; //data dikumpulkan pada array records
		//var_dump($record)."<br>";
  
  }

  //print_r($records);

  $j_encode=json_encode($records);
  $akt_je=$j_encode;
  //print_r($akt_je);
  $j_decode=json_decode($j_encode,true);
  $akt_jd=$j_decode;
  
 switch($_GET['act']){
	
	case "import":
	for($i=0;$i<1;$i++){
	  foreach ($records as $dropin){
		  if ($record['nidn_pembb2']!='' or $record['nidn_pembb2']=='0'  ){
			  	   $id_akt=trim($dropin['id_akt_mhs']);
				$rec['id_akt_mhs']=$id_akt;
				   $nidn1=trim($dropin['nidn_pembb1']);
				   //echo "<br>";
				   //echo "pembimbing :".$nidn1."<br>";
				   //$id_sdm="nidn='$sdm1'";
				   $nidn_1="nidn like '%$nidn1%'";
				   //echo $nidn_1;
				   $result=$proxy->GetRecord($gettoken,'dosen',$nidn_1);
				   $id=$result['result']['id_sdm'];
				$rec['id_sdm']=$id;
				   //echo "<br>".$id;
//				   $rec['id_reg_pd']=$dropin['id_reg_pd'];
					$pembb1=1;
				$rec['urutan_promotor']=$pembb1;
				$rec['id_kat_giat']=$id_kat_giat1;
				$recs[]=$rec;
				var_dump($recs);
				echo "<br>";
				$result4=$proxy->InsertRecord($gettoken,'bimbing_mahasiswa',json_encode($recs));
				var_dump($result4);
				
				   $nidn2=trim($dropin['nidn_pembb2']);
				   //echo "<br>";
				   //echo "pembimbing :".$nidn1."<br>";
				   //$id_sdm="nidn='$sdm1'";
				   $nidn_2="nidn like '%$nidn2%'";
				   //echo $nidn_1;
				   $result=$proxy->GetRecord($gettoken,'dosen',$nidn_2);
				   $id=$result['result']['id_sdm'];
				$rec1['id_sdm']=$id;
				   //echo "<br>".$id;
//				   $rec['id_reg_pd']=$dropin['id_reg_pd'];
					$pembb2=2;
				$rec1['urutan_promotor']=$pembb2;
				$rec1['id_kat_giat']=$id_kat_giat2;
				$recs1[]=$rec1;
				var_dump($recs1);
				$result5=$proxy->InsertRecord($gettoken,'bimbing_mahasiswa',json_encode($recs1));
				var_dump($result5);
				
				   }
				   
//		   }
//			  else{  $pemb1='1';
//				   $pemb=$dropin['sdm1'];
//				   // echo "<br>";
//				   //echo "pembimbing :".$pemb."<br>";
//				   //$id_sdm="nidn='$sdm1'";
//				   $id_sdm="nidn='$pemb'";
//				   //echo "<br> $id_sdm";
//				   $result=$proxy->GetRecord($gettoken,'dosen',$id_sdm);
//				   @$id=$result['result']['id_sdm'];
//				   @$nm=$result['result']['nm_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']."- Nama Dosen = ".$nm." - id_reg_pd =".$dropin['id_reg_pd']."- urutan_promotor =".$pemb1;
//				   //var_dump($recs);
//				   
//				   //foreach ($recs as $rec){
//				   $result=$proxy->InsertRecord($gettoken,'dosen_pembimbing',json_encode($rec));
//				   //var_dump($result4);
//				   //}
//			  }
		  } // end foreach dropin
	} // end for
		    //var_dump($recs);
		  
	break;
		  
	case "update":
	
	break ;
	}
 
 
 
//	$a=0;
//	echo "<pre style='background-color:#1699C9'>";
//	echo "Pembimbing Mahasiswa";
//	if ($result['result']) {
//		//for ($i=2; $i<=$hasildata; $i++){
//			foreach ($j_decode as $row){
//				$a++;
//				$smt=$row['nm_smt'];
//				$jdl=$row['judul_akt_mhs'];
//				//echo "<br /> $smt | $jdl";
//				$filter="judul_akt_mhs LIKE '%".$row['judul_akt_mhs']."%' and nm_smt='$smt'";
//				//echo "<br />".$filter;
//				$result1 = $proxy->GetRecord($gettoken,'aktivitas_mahasiswa',$filter);
//				$id_akt=$result1['result']['id_akt_mhs'];
//				$judul=$result1['result']['judul_akt_mhs'];
//				
//				echo "<br>$a.  Semester : ".$smt." | Judul Aktivitas : ".$judul." | NPM = ".$row['nipd']." (".$row['nm_pd'].")";
//				
//				if ($row['nipd'] !='') $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>