<?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"];
$success = false;


if (isset($_REQUEST["accode"])) {
    $accode = $_REQUEST['accode'];

    $query = "SELECT accode,memcode,name,aadhaar,dob FROM $zroot.`member` WHERE accode ='$accode'";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    $r = mysqli_fetch_assoc($result);
    $memcode = $r['memcode'];

    $query1 = "SELECT name FROM $zroot.`member` WHERE accode ='$memcode'";
    $result1 = mysqli_query($conn, $query1) or die(mysqli_error($conn));
    $r1 = mysqli_fetch_assoc($result1);
    $famname = $r1['name'];
    
    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
        'memcode'   => "$memcode",
        'name'      => "$r[name]",
        'aadhaar'   => "$r[aadhaar]",
        'dob'       => "$r[dob]",
        'famname'   => "$famname");
    header("Content-type: application\json");
    echo json_encode($rows);
}

if (isset($_REQUEST["sonno"])) {
    $sonno = $_REQUEST['sonno'];

    $query = "SELECT accode,memcode,name FROM $zroot.`member` WHERE accode ='$sonno'";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    $r = mysqli_fetch_assoc($result);
    $memcode = $r['memcode'];

    $query1 = "SELECT name,accode FROM $zroot.`member` WHERE accode ='$memcode'";
    $result1 = mysqli_query($conn, $query1) or die(mysqli_error($conn));
    $r1 = mysqli_fetch_assoc($result1);
    $famaccode = $r1['accode'];
    $famname = $r1['name'];
    
    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
        'memcode'   => "$memcode",
        'sonname'      => "$r[name]",
        'memno'      => "$famaccode",
        'memname'   => "$famname");
    header("Content-type: application\json");
    echo json_encode($rows);
}

