<?php
//include "inc/config.php";


include "../../inc/config.php";

include "../../lib/prosesupdate/ProgressUpdater.php";


$config = $db->fetch_single_row('config_user','id',1);

if ($config->live=='Y') {
	$url = 'http://'.$config->url.':'.$config->port.'/ws/live.php?wsdl'; // gunakan live
} else {
	$url = 'http://'.$config->url.':'.$config->port.'/ws/sandbox.php?wsdl'; // gunakan sandbox
}
//untuk coba-coba
// $url = 'http://pddikti.uinsgd.ac.id:8082/ws/live.php?wsdl'; // gunakan live bila

$client = new nusoap_client($url, true);
$proxy = $client->getProxy();



# MENDAPATKAN TOKEN
$username = $config->username;
$password = $config->password;
$result = $proxy->GetToken($username, $password);
$token = $result;

$mulai_berlaku = $_POST['semester'];
$jurusan = $_POST['jurusan'];
$data_jur = $db->fetch_single_row('jurusan','id_sms',$jurusan);


$filter_check = "id_sms='".$data_jur->id_sms."' and id_jenj_didik='".$data_jur->id_jenj_didik."' and id_smt='".$mulai_berlaku."' and soft_delete='0'";
$temp_check = $proxy->GetRecord($token,'kurikulum',$filter_check);

$check_exist_data = array(
							'mulai_berlaku' => $mulai_berlaku,
							'kode_jurusan' => $data_jur->kode_jurusan
						 );

if ($temp_check['result']) {
if ($db->check_exist('kurikulum',$check_exist_data)==true) {
	echo "Data Kurikulum Sudah Ada Dibawah";
} else {
	$data_insert = array(
		'nama_kur' => $temp_check['result']['nm_kurikulum_sp'],
		'mulai_berlaku' => $temp_check['result']['id_smt'],
		'kode_jurusan' => $data_jur->kode_jurusan,
		'jml_sks_wajib' =>$temp_check['result']['jml_sks_wajib'],
		'jml_sks_pilihan' => $temp_check['result']['jml_sks_pilihan'],
		'total_sks' =>$temp_check['result']['jml_sks_lulus']
		);
	$db->insert('kurikulum',$data_insert);

	echo "Data Kurikulum Berhasil Di Download Dari Feeder";
}

} else {
	echo "Data Kurikulum Tidak Ada Di Feeder";
}

?>