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

$json_response = array();

$jurusan = $_POST['jurusan'];

	        $sem = "";
    if ($_POST['sem']!='all') {
      $sem = "and nilai_akm.semester='".$_POST['sem']."'";
    }
    
if ($jurusan=='all') {
	$jurusan = "";
	 if ($_SESSION['level']!=1) {
        $jurusan = "and jurusan.kode_jurusan='".$_SESSION['jurusan']."'";
      }
} else {
	$jurusan = "and jurusan.kode_jurusan='".$_POST['jurusan']."'";
}
$data = $db->fetch_custom("select *,nilai_akm.id as id_akm from nilai_akm inner join jurusan on nilai_akm.kode_jurusan=jurusan.kode_jurusan where nilai_akm.id is not null $sem $jurusan and status_error!=1");
$datas = $db->fetch_custom("select *,nilai_akm.id as id_akm from nilai_akm inner join jurusan on nilai_akm.kode_jurusan=jurusan.kode_jurusan where nilai_akm.id is not null $sem $jurusan and (valid=2 or valid=0)");
if ($data->rowCount()>0 && $datas->rowCount()<1 ) {
   $json_response['jumlah'] = $data->rowCount();
} else {
  $json_response['jumlah'] = 0;
}

echo json_encode($json_response);

?>
