<?php

if (isset($_POST["dir"])) {
    include("../connectSQL_Component.php");
    $dir = $_POST["dir"];
    $result = [];
    $Video_Table = [];
    $File_Table = [];
    $sql = "SELECT [id],[title],[file_path] FROM [BIMComponents].[dbo].[Video_Table] WHERE [dir_name] = '" . $dir . "';";
    $fetchResult = sqlsrv_query($conn, $sql);
    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
        array_push($Video_Table, $row);
    }
    $sql = "SELECT [id],[title],[type] FROM [BIMComponents].[dbo].[File_Table] WHERE [dir_name] = '" . $dir . "';";
    $fetchResult = sqlsrv_query($conn, $sql);
    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
        array_push($File_Table, $row);
    }
    $result["Video_Table"] = $Video_Table;
    $result["File_Table"] = $File_Table;
    echo json_encode($result);

    sqlsrv_close($conn);
}
