<?php
include("connectSQL_Component.php");
if (isset($_GET["parent"])) {

    $parent = $_GET["parent"];
    $type = $_GET["type"];
    $year = [];
    $rvtName = [];
    $category = [];
    $componentGroup = [];

    if($type != ""){
        $sql = "SELECT * FROM [BIMComponents].[dbo].[Component_Info2] WHERE [componentGroup] LIKE '%".$type."%';";
    }else{
        $sql = "SELECT * FROM [BIMComponents].[dbo].[Component_Info2] WHERE [componentGroup] LIKE '%".$parent."%';";
    }
    
    $fetchResult = sqlsrv_query($conn, $sql);
    while ($row = sqlsrv_fetch_array($fetchResult)) {        
        array_push($rvtName, $row["componentName"]);
        array_push($year, $row["revitVersion"]);
        array_push($category, $row["category"]);
        array_push($componentGroup, $row["componentGroup"]);
    }
    
    $array = array();
    $array["rvtName"] = $rvtName;
    $array["year"] = $year;
    $array["category"] = $category;
    $array["componentGroup"] = $componentGroup;
    echo json_encode($array);
}
sqlsrv_close($conn);
