<?php

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

$society = $_SESSION["society_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$zroot = $_SESSION["zdir"];
$fseries = $_SESSION["society_" . $dbname];
$keycond  = "and `series`= '$fseries'";

$flatno = $_REQUEST['flatno'];
$flatcond = '';

if (!empty($_REQUEST['flatno'])) {
    $flatcond = "AND `flatno` = '$flatno' ";
}



$getflat = mysqli_query($conn, "SELECT name, name2, block, wing, floor, unit, area FROM `accmast` WHERE `accode` != '' $keycond $flatcond ")or die(mysqli_error($conn));
$fflat = mysqli_fetch_array($getflat);

if ($flatno != "") {
    $flat = 1;
    $name = $fflat['name'];
    $name2 = $fflat['name2'];
    $block = $fflat['block'];
    $wing = $fflat['wing'];
    $floor = $fflat['floor'];
    $unit = $fflat['unit'];
    $area = $fflat['area'];
} 



$rows = array('flat' => $flat,
    'name' => "$name",
    'name2' => "$name2",
    'block' => "$block",
    'wing' => "$wing",
    'floor' => "$floor",
    'unit' => "$unit",
    'area' => "$area"
);

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