<?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;


$memno = $_REQUEST['memno'];
$memname = $_REQUEST['memname'];
$para = trim($_REQUEST['para']);
$ccond = "";
if ($para == "C") {
    $ccond = "and accode ='$memno'";
} elseif ($para == "N") {
    $ccond = "and accode ='$memname'";
} elseif ($para == "W") {
    $ccond = "and accode in (select memcode from $zdb.widowhelp where (memcode = '$memno' or memcode ='$memname') and active = '1' )";
} else {
    $ccond = "";
}


$query = "SELECT accode,name,lavajam,add1,add2,add3,familyid FROM `member` WHERE accode !='' $ccond";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$r = mysqli_fetch_assoc($result);


$rows = array();
$ctr = 0;
$rows = array(
    'success' => true,
    'memno' => "$r[accode]",
    'openbal' => "$r[lavajam]",
    'add1' => "$r[add1]",
    'add2' => "$r[add2]",
    'add3' => "$r[add3]",
    'memname' => "$r[accode]"
);
header("Content-type: application\json");
echo json_encode($rows);
