<?php
header('Access-Control-Allow-Origin: *');
include "../../../inc/config.php";
$token = get_token();
$url = get_service_url();

$json_response = array();

$filter_jurusan = "";
$filter_kurikulum = "";
$filter_matkul = "";
$filter_mk = "";
$jumlah = 0;
        if ($_POST['jurusan']!="all") {
            if ($_POST['kurikulum']!='all') {
                  if ($_POST['matkul']!='all') {
                      $temp_count_mk_kur = [
                          'act' => 'GetCountRencanaEvaluasi',
                          'token' => $token,
                          'filter' => "id_matkul='".$_POST['matkul']."'",
                        ];
                    $temp_count_mk_kur_data = json_decode($db->run($temp_count_mk_kur,$url));
                    if(!empty($temp_count_mk_kur_data->data)) {
                      $jumlah = $temp_count_mk_kur_data->data;
                    }
                  } else {
                    $temp_count_mk_kur = [
                          'act' => 'GetMatkulKurikulum',
                            'token' => $token,
                            'filter' => "id_kurikulum='".$_POST['kurikulum']."'",
                            'order' => '',
                            'limit' => "",
                            'offset' => ""
                        ];
                    $temp_count_mk_kur_data = json_decode($db->run($temp_count_mk_kur,$url));
                    if(!empty($temp_count_mk_kur_data->data)) {
                      $datas = $temp_count_mk_kur_data->data;
                      foreach ($temp_count_mk_kur_data->data as $dt) {
                        $id_mk[$dt->id_matkul] = "'".$dt->id_matkul."'";
                      }
                      $implode_id_mk = implode(",", $id_mk);

                      $temp_count_mk_kur = [
                          'act' => 'GetCountRencanaEvaluasi',
                          'token' => $token,
                          'filter' => "id_matkul in($implode_id_mk)",
                        ];
                    $temp_count_mk_kur_data = json_decode($db->run($temp_count_mk_kur,$url));
                    if(!empty($temp_count_mk_kur_data->data)) {
                      $jumlah = $temp_count_mk_kur_data->data;
                    }
                  }

                }
              } else {
                $temp_count_mk = [
                      'act' => 'GetCountRencanaEvaluasi',
                        'token' => $token,
                        'filter' => "id_prodi='".$_POST['jurusan']."'"
                    ];
                $temp_count = json_decode($db->run($temp_count_mk,$url));
                if(!empty($temp_count->data)) {
                  $jumlah = $temp_count->data;
                }

              }
          
          } else {
            $temp_count_mk = [
                  'act' => 'GetCountRencanaEvaluasi',
                    'token' => $token,
                    'filter' => ""
                ];
            $temp_count = json_decode($db->run($temp_count_mk,$url));
            if(!empty($temp_count->data)) {
              $jumlah = $temp_count->data;
            }

          }

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

        echo json_encode($json_response);
?>