<?php
// * 印出BIMDate底下檔案結構，提供給jstree
$folder = 'BIM專案管理';
if (isset($_GET["folder"])) {
    $folder = $_GET["folder"];
}
$root = '../../assets/BIMData';

FindPath($root, $folder);

function FindPath($root, $folder)
{
    $rootPath = $root . '/' . $folder;
    $paths = array_diff(scandir($root . '/' . $folder), array('.', '..', 'Thumbs.db'));
    echo ("<ul>");
    foreach ($paths as $path) {
        if (str_contains($path, '.')) {
            $date = date("Y-m-d H:i:s", filemtime("../." . substr($rootPath, 4) . "/" . $path));
            if (str_contains($path, '.pdf')) {
                echo ("<li data-jstree='{ " . '"type" : "pdf"' . " }' >");
            } else if (str_contains($path, '.doc')) {
                echo ("<li data-jstree='{ " . '"type" : "word"' . " }' >");
            } else if (str_contains($path, '.ppt')) {
                echo ("<li data-jstree='{ " . '"type" : "ppt"' . " }' >");
            } else {
                echo ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
            }

            $path = "<a href='" . substr($rootPath, 4) . "/" . $path . "' time='" . $date . "'>" . $path . "</a>";
            echo ($path);
            echo ("</li>");
        } else {
            echo ("<li>");
            echo ($path);
            FindPath($rootPath, $path);
            echo ("</li>");
        }
    }
    echo ("</ul>");
}
