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

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$zroot = $_SESSION["zdbroot"];

$fseries = $_SESSION["series_" . $dbname];
$keycond = "and `series`='$fseries'";

$success = false;


if (isset($_REQUEST["memcode"])) {
    
    $memcode = $_REQUEST['memcode'];
    
    $query2 = "SELECT * FROM $zroot.`member` WHERE accode ='$memcode'";
    $result2 = mysqli_query($conn, $query2) or die(mysqli_error($conn));
    $r2 = mysqli_fetch_assoc($result2);
    
    

    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
        'name'   => "$r2[name]",
        'add1'   => "$r2[add1]",
        'add2'   => "$r2[add2]",
        'add3'   => "$r2[add3]",
        'gender'   => "$r2[gender]",
        'mstatus'   => "$r2[mstatus]",
        'phydisabled'   => "$r2[phydisabled]",
        'mobile'   => "$r2[mobile]");

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

if (isset($_REQUEST["formem"])) {
    
    $formem = $_REQUEST['formem'];
    $hall = $_REQUEST['hall'];
    
    $query3 = "SELECT * FROM `hallname` WHERE code = '$hall' $keycond ";
    $result3 = mysqli_query($conn, $query3) or die(mysqli_error($conn));
    $r3 = mysqli_fetch_assoc($result3);
    
    if ($formem == 'Member'){
        $amt = $r3['memcharge'];
    } else {
        $amt = $r3['noncharge'];
    } 

    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
        
        'amount'   => "$amt");

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