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

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

$success = false;


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

    $query = "SELECT * FROM `member` WHERE accode ='$memno'";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    $r = mysqli_fetch_assoc($result);
 
    if ($r['gender'] == "M"){
        $gender = "MALE";
    }elseif ($r['gender'] == "F"){
        $gender = "FEMALE";
    }

    if ($r['mstatus'] == 'M') {
        $mstatus = 'MARRIED';
    } elseif ($r['mstatus'] == 'S') {
        $mstatus = 'SINGLE';
    } elseif ($r['mstatus'] == 'D') {
        $mstatus = 'DIVORCE';
    } elseif ($r['mstatus'] == 'W') {
        $mstatus = 'WIDOW';
    } else {
        $mstatus = '';
    }
    
    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
   
        'memno'         => "$memno",
        'mobile'        => "$r[mobile]",
        'bloodgrp'      => "$r[bloodgrp]",
        'qualification' => "$r[qualification]",
        'occupation'    => "$r[occupation]",
        'phydisabled'   => "$r[phydisabled]",
        'marstat'       => "$mstatus",
        'gender'        => "$gender",
        'add1'          => "$r[add1]",
        'add2'          => "$r[add2]",
        'add3'          => "$r[add3]",
        'memname'       => "$r[name]");
    header("Content-type: application\json");
    echo json_encode($rows);
}
