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

$token = $db->get_token();
$url = $db->get_service_url("rest");
$jml = 0;

$id_sms = "";

if ($_POST["nim"] == "all") {
    if ($_POST['jurusan']=='all') {
      $jml_prodi = $db->fetch_custom_single("select count(*) as jml from jurusan");
      $jml = $jml_prodi->jml;
    } else {
      $semester = "id_semester='" . $_POST["sem_filter"] . "'";
    if ($_POST["nama_kelas"] == "all") {
        $kelas = "";
    } else {
        $kelas = "and id_kelas_kuliah='" . $_POST["nama_kelas"] . "'";
    }

    if ($_POST["matkul"] == "all") {
        $matkul = "";
    } else {
        $matkul = "and id_matkul='" . $_POST["matkul"] . "'";
    }
    if ($_POST["jurusan"] == "all") {
        $id_sms = "";
    } else {
        $id_sms = "and id_prodi='" . $_POST["jurusan"] . "' ";
    }

    $filter_kelas = "$semester $id_sms $kelas $matkul";
    $temp_count_mk = [
        "act" => "GetCountNilaiPerkuliahanKelas",
        "token" => $token,
        "filter" => $filter_kelas,
    ];
    //   dump($temp_count_mk);
    $temp_count = json_decode($db->run($temp_count_mk,$url));
      // dump($temp_count);
      if(!empty($temp_count->data)) {
          $jml = $temp_count->data;
      }
    }
} else {
    $jml = 1;
}

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

echo json_encode($json_response);
?>