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

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

  $kurikulum = "";
  if ($_POST['kurikulum']!='all') {
    $kurikulum = "and tahun='".$_POST['kurikulum']."'";
  }
  $jurusan = $_POST['jurusan'];
  if ($jurusan=='all') {
  	$jurusan = "";
      if ($_SESSION['level']!=1) {
          $jurusan = "and jurusan.kode_jurusan='".$_SESSION['jurusan']."'";
        }
  } else {
  	$jurusan = "and jurusan.kode_jurusan='".$_POST['jurusan']."'";
  }

  $json_response = array();
  $data = $db->fetch_custom("select mat_kurikulum.id from mat_kurikulum inner join jurusan on mat_kurikulum.kode_jurusan=jurusan.kode_jurusan where (status_error!=1 or status_error_kur!=1) $jurusan $kurikulum $semester");
  if ($data->rowCount()>0) {
     $json_response['jumlah'] = $data->rowCount();
  } else {
    $json_response['jumlah'] = 0;
  }

  echo json_encode($json_response);

?>