<?php
session_start();
include "../../../inc/config.php";
$url = get_service_url('rest');
$token = get_token();
$semester = '';
$id_prodi = "";
$id_sms = "";
$id_smt = "";
if ($_POST['semester']!='all') {
  $semester = "and id_semester='".$_POST['semester']."'";
  $id_smt = "and id_smt='".$_POST['semester']."'";
}

if ($_POST['jurusan']!='all') {
  $id_prodi = "and id_prodi='".$_POST['jurusan']."'";
  $id_sms = "and id_sms='".$_POST['jurusan']."'";
}
 
$filter_aktivitas = "id_aktivitas in(select id_akt_mhs from anggota_akt_mhs) $semester $id_prodi";
$nim ="";
$and_id_akt = "";
if ($_POST['nim']!='all') {
  if ($id_prodi!="" or $id_smt!="") {
    $and_id_akt = "id_aktivitas in(select id_akt_mhs from akt_mhs where id_akt_mhs is not null $id_smt $id_sms) and";
  }
  $data_dic = array(
  'act' => 'GetListAnggotaAktivitasMahasiswa',
  'token' => $token,
  'filter' => "$and_id_akt nim like '%".$_POST['value_nim']."%'"
  );
  $temp_recs = json_decode($db->run($data_dic,$url));
  //dump($temp_recs);
  $jumlah = count($temp_recs->data);

} else {
  $data_dic = array(
  'act' => 'GetCountAktivitasMahasiswa',
  'token' => $token,
  'filter' => $filter_aktivitas
  );
  $temp_recs = json_decode($db->run($data_dic,$url));
  $jumlah = $temp_recs->data;
}

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

echo json_encode($json_response);
?>