<?php
session_start();
header('Access-Control-Allow-Origin: *');
include "../../inc/config.php";
/** Error reporting */
//error_reporting(E_ALL);
 
include "../../lib/nusoap/nusoap.php";

//require_once '../../lib/Writer.php';

require_once '../../lib/php-export-data.class.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();
$json_response = array();

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

$id_sms = '';
        

        $prodi = trim($_POST['jurusan']);
        $jurusan = $db->fetch_custom_single("select id_sms,nama_jurusan from jurusan where trim(kode_jurusan)='$prodi'");
        $id_sms = "p.id_sms='".$jurusan->id_sms."' ";


        if ($_POST['matkul']=='all') {
          $table = "mata_kuliah";
          $filter_kelas = "$id_sms";
        } else {
           $table = "mata_kuliah_kurikulum";
          $filter_kelas = "p.id_kurikulum_sp='".$_POST['matkul']."'";
        }

        $order_by = "";
            $count = $proxy->GetCountRecordset($token,$table,$filter_kelas);
            $limit=$count['result'];
            $jml=$count['result'];
       

if ($jml>0) {
   $json_response['jumlah'] = $jml;
} else {
  $json_response['jumlah'] = 0;
}

echo json_encode($json_response);
?>