<?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'];
    $sonno = $_REQUEST['sonno'];
    $fathno = $_REQUEST['fathno'];
    $dauno = $_REQUEST['dauno'];

    $query = "SELECT accode,name,familyid FROM `member` WHERE accode ='$memno'";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    $r = mysqli_fetch_assoc($result);


    $query2 = "SELECT accode,name FROM `member` WHERE accode ='$sonno' and familyid = '$r[familyid]' and relation = 'SON'";
    $result2 = mysqli_query($conn, $query2)or die(mysqli_error($conn));
    $r2 = mysqli_fetch_assoc($result2);
 
    $sonname = $r2['name'];

    $query3 = "SELECT accode,name,familyid  FROM `member` WHERE accode ='$fathno' ";
    $result3 = mysqli_query($conn, $query3)or die(mysqli_error($conn));
    $r3 = mysqli_fetch_assoc($result3);
    
    $fathname = $r3['name'];
    
    $query4 = "SELECT accode,name FROM `member` WHERE  accode ='$dauno' and  familyid = '$r3[familyid]' and relation = 'DAUGHTER'";
    $result4 = mysqli_query($conn, $query4)or die(mysqli_error($conn));
    $r4 = mysqli_fetch_assoc($result4);
    $dauname = $r4['name'];

    $query23 = "SELECT sagai,lagan FROM `company`";
    $result23 = mysqli_query($conn, $query23)or die(mysqli_error($conn));
    $r23 = mysqli_fetch_assoc($result23);

    $sagai = $r23['sagai'];
    $lagan = $r23['lagan'];
    

    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
   
    'sagai'      =>   "$sagai",
    'lagan'      =>   "$lagan",
    'totamt'      =>   "$totamt",
    'memno'      =>   "$memno",
    'memname'    =>   "$r[name]",
    'sonname'    =>   "$sonname",
    'fathname'   =>   "$fathname",
    'dauname'    =>   "$dauname");


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