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

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

    if($type != ""){
        $sql = "SELECT * FROM [BIMComponents].[dbo].[Component_Info] WHERE [componentGroup] LIKE '%".$parent."%' AND [category] = '".$type."';";
    }else{
        $sql = "SELECT * FROM [BIMComponents].[dbo].[Component_Info] 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 = array();
    $array["rvtName"] = $rvtName;
    $array["year"] = $year;
    $array["category"] = $category;
    echo json_encode($array);
}
sqlsrv_close($conn);
