<?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"];
$myyear = $_SESSION[$myyear];
$user = $_SESSION['username_' . $dbname];
$maindb = 'demdmain';

mysqli_select_db($conn, $zdb);

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


    $result2 = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `examcode`='$fexam' AND `section`='$section' AND `session`='$session'") or die(mysqli_error($conn));
    $get2 = mysqli_num_rows($result2);

    if ($get2 == 0) {
        $fexam = true;
    } else {
        $fexam = false;
    }
    
    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `examcode`='$texam' AND `section`='$section' AND `session`='$session'  and year = '$myyear'") or die(mysqli_error($conn));
    $get = mysqli_num_rows($result);

    if ($get > 0) {
        $toexam = true;
    } else {
        $toexam = false;
    }

    

    $rows = [ 'toexam' => $toexam,
        'fexam' => $fexam,
    ];
    
    header("Content-type: application\json");
    echo json_encode($rows);
}
    
        
    
    