<h1> Insert Anggota Aktifitas 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%' AND nm_smt ='$nm_smt' And nm_lemb like '%$prodi%'";
			$result=$proxy->GetRecord($gettoken,'aktivitas_mahasiswa',$filter);
			$id_akt_mhs=$result['result']['id_akt_mhs'];
			//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;
  		$records[]=$record; //data dikumpulkan pada array records
		//print_r($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":
			
			$result=$proxy->InsertRecordset($gettoken,'anggota_aktivitas_mahasiswa',$akt_je);
		    //var_dump($result);
		  
	break;
		  
	case "update":
	
	//echo "ini case update";
	
//		for($i=0;$i<1;$i++){
//				foreach($j_decode as $row){
//					$key = array('id_smt' => $row['id_smt'],'id_reg_pd' => $row['id_reg_pd']);
//					$data = array('id_stat_mhs' => $row['id_stat_mhs'],
//					   			  		   'ips'=> $row['ips'],
//					   			       'sks_smt'=> $row['sks_smt'],
//									       'ipk'=> $row['ipk'],
//									 'sks_total'=> $row['sks_total']);
//					
//		
//					$updates[] = array('key'=>$key,'data'=>$data);
//					
//				$j_upd=json_encode($updates);
//				//echo "<br> json_update ".$j_upd;
//			$result = $proxy->UpdateRecordset($gettoken,'kuliah_mahasiswa',$j_upd);
//			//var_dump($result);
//				}
//		}
	
	
	break ;
	}
	$a=0;
	echo "<pre style='background-color:#1699C9'>";
	echo "Anggota Aktifitas";
	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>