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

$url = get_service_url('url_rest');
$token = get_token();


$json_response = array();
$jml=0;

$id_sms = '';
        $nim = "";
$semester = "";

        if ($_POST['sem_filter']!='') {
          $semester = "and id_semester='".$_POST['sem_filter']."'";
        }

        if ($_POST['nim']!='all') {
          $nim = "and trim(nim)='".trim($_POST['value_nim'])."'";
        }

         if ($_POST['status']=='all') {
            $status = '';
          } else {
            $status = "and id_status_mahasiswa='".$_POST['status']."'";

          }

     $filter_angkatan = "and (angkatan BETWEEN '".$_POST['angkatan_awal']."' and '".$_POST['angkatan_akhir']."')";

        $prodi = trim($_POST['jurusan']);
        if ($prodi=='all') {
            $jurusan = "";
            $id_sms = "";
          if ($_SESSION['level']!=1) {
                $id_sms = "and id_prodi='".$_SESSION['id_sms']."'";
          }

        } else {
            $id_sms = "and id_prodi='".$prodi."' ";
        }



       $filter_kelas = "nim is not null $nim $filter_angkatan $semester $id_sms $status";

          $count_akm = [
      'act' => 'GetCountPerkuliahanMahasiswa',
        'token' => $token,
        'filter' => $filter_kelas,
       ];


    $temp_recs = json_decode($db->run($count_akm,$url));

    $jml = $temp_recs->data;
       

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

echo json_encode($json_response);
?>