<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include("includes/function.php");

$zdb = $_SESSION["zdbyear_$dbname"];
$ztit = $_SESSION["tit"];
$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];
$maindb = 'invmain';

mysqli_select_db($conn, $zdb);

if (isset($_REQUEST["exam"])) {
    $exam = $_REQUEST["exam"];
    $section = $_REQUEST["section"];
    $session = $_REQUEST["session"];
   


    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `examcode`='$exam' AND `section`='$section' AND `session`='$session'") or die(mysqli_error($conn));
    $get = mysqli_num_rows($result);
    if ($get > 0) {

        $exam1 = 1;
    } else {
        $exam1 = '';
    }

    $result2 = mysqli_query($conn, "SELECT * FROM `paprate` WHERE  `examcode`='$exam' AND `section`='$section' ") or die(mysqli_error($conn));
    $get2 = mysqli_num_rows($result2);
   
    if ($get2 > 0) {
        
        $rates = 1;
    } else {
        $rates = '';
    }

    $result3 = mysqli_query($conn, "SELECT * FROM `demdmain` WHERE `vouchno` != '' AND `examcode`='$exam' and section = '$section' AND 
                           `session`='$session' group by custcode order by custcode, vouchno desc") or die(mysqli_error($conn));
    $get3 = mysqli_num_rows($result3);
    if ($get3 > 0) {

        $demnd = 1;
    } else {
        $demnd = '';
    }

    $rows = [ 'exam1' => $exam1,
        'rates' => $rates,
        'demnd' => $demnd,
    ];

    header("Content-type: application\json");
    echo json_encode($rows);
}

    
        
    
    