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

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

  if ($_POST['matkul']!='all') {
    $query_matkul = "and kode_mk='".$_POST['matkul']."'";
  }
  if ($_POST['kelas']!='all') {
    $query_kelas  = "and nama_kelas='".$_POST['kelas']."'";
  }
$status_data = "";
  if ($_POST['status_data']!='all') {
    $status_data  = "and status_error='".$_POST['status_data']."'";
  } else {
    $status_data  = "and status_error!=1";
  }

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

$json_response = array();
$data = $db->fetch_custom("select *,nilai_evaluasi_mahasiswa.id as id_krs from nilai_evaluasi_mahasiswa inner join jurusan on nilai_evaluasi_mahasiswa.kode_jurusan_kelas=jurusan.kode_jurusan where nilai_evaluasi_mahasiswa.id is not null $sem $jurusan $status_data $query_matkul $query_kelas");
if ($data->rowCount()>0) {
   $json_response['jumlah'] = $data->rowCount();
} else {
  $json_response['jumlah'] = 0;
}

echo json_encode($json_response);

?>
