<h1> Insert Aktifitas Kuliah 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 2
{
		//$records=array();
		$record['id_smt']=trim($data->val($i,2));
		
		// mencari id_reg_pd
		$nim=trim($data->val($i,3));
			  $nipd="nipd like '%$nim%'";
			  //echo $i.".   ".$nim."<br>";
			  $result=$proxy->GetRecord($gettoken,'mahasiswa_pt',$nipd);
			  $coba=$result['result'];
		$record['id_reg_pd']=$coba['id_reg_pd'];                        // inti
		$record['id_stat_mhs']=trim($data->val($i,5));//}                    // Perhatikan Status MHS
		$record['ips']=trim($data->val($i,6));                         // inti
		$record['sks_smt']=trim($data->val($i,7));
		$record['ipk']=trim($data->val($i,8));
		$record['sks_total']=trim($data->val($i,9));                  // inti
  		$records[]=$record; //data dikumpulkan pada array records
  
  }

  //print_r($records);

  $j_encode=json_encode($records);
  $akm_je=$j_encode;
  //print_r($akm_je);
  $j_decode=json_decode($j_encode,true);
  $akm_jd=$j_decode;
  
 switch($_GET['act']){
	
	case "import":
			
			$result=$proxy->InsertRecordset($gettoken,'kuliah_mahasiswa',$akm_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'>";
	if ($result['result']) {
		//for ($i=2; $i<=$hasildata; $i++){
			foreach ($j_decode as $row){
				$a++;
				$id_smt=$row['id_smt'];
				$id_reg_pd=$row['id_reg_pd'];
				$id_stat_mhs=$row['id_stat_mhs'];
				$ips=$row['ips'];
				$sks_smt=$row['sks_smt'];
				$ipk=$row['ipk'];
				$sks_total=$row['sks_total'];
				echo "<br>$a.  Semester : ".$id_smt." | Id reg Pd : ".$id_reg_pd." | Id stat mhs = ".$id_stat_mhs." | IPs = ".$ips." | SKS Smt = ".$sks_smt." | IPk = ".$ipk." | SKS Tot = ".$sks_total;
				
				if ($id_reg_pd !='') $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>