<?php
include("connectSQL_Component.php");


$array = [];
$table = [];
if(isset($_GET["type"])){
    $type = urldecode($_GET["type"]);
    $sql = "SELECT * FROM [BIMComponents].[dbo].[API_Table] Where [type] = '".$type."';";
}
else
$sql = "SELECT * FROM [BIMComponents].[dbo].[API_Table]";
$fetchResult = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($fetchResult)) {
    array_push($table, $row);
}
$array["table"] = $table;
$table = [];
$sql = "SELECT DISTINCT object FROM [BIMComponents].[dbo].[API_Table]";
$fetchResult = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($fetchResult)) {
    if ($row["object"] != null)
        array_push($table, $row);
}
$array["objectFilter"] = $table;
$table = [];
$sql = "SELECT DISTINCT usage FROM [BIMComponents].[dbo].[API_Table]";
$fetchResult = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($fetchResult)) {
    if ($row["usage"] != null)
        array_push($table, $row);
}
$array["usageFilter"] = $table;

echo json_encode($array);
