<?php
header('Access-Control-Allow-Origin: *');
include "../../inc/config.php";
include "../../inc/feeder_function.php";
include "../../lib/nusoap/nusoap.php";

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

$token = get_token();;

$json_response = array();

$filter_sms = "";
$filter_angkatan = "";
$filter_status = "";

      if ($_POST['jurusan']!="all") {
            $filter_sms = "p.id_reg_pd is not null and p.id_sms='".$_POST['jurusan']."'";
        } else {
            $filter_sms = "p.id_reg_pd is not null";
        }
        
        $filter_angkatan = "and (left(p.mulai_smt,4) BETWEEN '".$_POST['angkatan_awal']."' and '".$_POST['angkatan_akhir']."')";


        if ($_POST['status_mhs']!='') {
            if (in_array('aktif', $_POST['status_mhs']) && count($_POST['status_mhs'])==1) {
               $filter_status  = "and (p.id_jns_keluar is null or p.id_jns_keluar='')";
            } elseif (in_array('aktif', $_POST['status_mhs']) && count($_POST['status_mhs'])>1) {
               $filter_status  .= "and (p.id_jns_keluar is null or p.id_jns_keluar='')";
               foreach ($_POST['status_mhs'] as $val) {
                   if ($val!='aktif') {
                       $array_status[] = "'$val'";
                   }
               }
               $implode_status = implode(",", $array_status);
               $filter_status  .= " and p.id_jns_keluar IN(".$implode_status.")";
            } else {
               foreach ($_POST['status_mhs'] as $val) {
                   if ($val!='aktif') {
                       $array_status[] = "'$val'";
                   }
               }
               $implode_status = implode(",", $array_status);
               $filter_status  = "and p.id_jns_keluar IN(".$implode_status.")";
            }
        }


        $data_rec = array();
        $filter_mahasiswa = "$filter_sms $filter_angkatan $filter_status";


        $order_by = "nipd ASC";

        $count = $proxy->GetCountRecordset($token,'mahasiswa_pt',$filter_mahasiswa);
        $jml = $count['result'];

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

        echo json_encode($json_response);
?>