function displayFiles($path) { echo "<table class='table table-hover file-list'>\n <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>"; $file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store')); foreach ($file_array as $file) { $url = "../" . $path . "/" . $file; if (is_dir($url)) { $name = $file; $folder_path = $path . "/" . $file; $size = formatBytes(getFolderSize($url), 1); $date = date("d/m/Y", stat($url)['mtime']); echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' data-path=\"{$folder_path}\" class='file-list-folder'>{$name}</a>"; echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$folder_path}\"><i class='fa fa-remove'></i></button>"; echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' data-path=\"{$folder_path}\"><i class='fa fa-edit'></i></button>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } else { $finfo = finfo_open(FILEINFO_MIME_TYPE); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); $preview = canPreview($content_type); if ($preview == "no") { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>"; } else { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>"; } echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>"; echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } echo "</table>"; }
function displayFiles($path) { global $connection, $config; //calculate permissions $permissions = validatePermissions(validateUser()); //Switch mode based on path echo "<table class='table table-hover file-list'>"; if ($path == "/") { //Root: list containers echo "<thead><tr><th>Nome</th></tr></thead>"; $request = "SELECT * FROM teachers_users"; $result = $connection->query($request); while ($line = $result->fetch_assoc()) { $name = $line["user"]; $title = ucfirst($name); if (file_exists($config->plugin_notes_engine_fpath . "/" . $name)) { echo "<tr><td><span class='fa-stack fa-3x'><i class='fa fa-folder'></i></span> <a href='#' id='{$name}' class='file-list-folder'>{$title}</a></td></tr>"; } } } else { //check if it is a VFS folder then if it is not check if it is a container if (strpos($path, "/") !== false) { $folders = explode("/", $path); $folder = end($folders); } else { $folder = $path; } echo "<thead><tr><th>Nome</th><th>Insegnante</th><th>Dimensione</th><th>Ultima modifica</th></tr></thead>"; $request = "SELECT * FROM notes_vfs WHERE id = '{$folder}'"; $result = $connection->query($request); $line = $result->fetch_assoc(); if (isset($line["name"])) { //it is a VFS folder, check for folders with parent=$folder, then download blob list and get items in that folder, save name for later use $folder_container = $line["container"]; $request = "SELECT * FROM notes_vfs WHERE parent = '{$folder}'"; $result = $connection->query($request); } else { //it is a container: $name = str_replace("/", "", $path); $request = "SELECT * FROM teachers_users WHERE user='******'"; $result = $connection->query($request); $line = $result->fetch_assoc(); $folder_container = $line["user"]; if (file_exists($config->plugin_notes_engine_fpath . "/" . $folder_container)) { $request = "SELECT * FROM notes_vfs WHERE parent = '/' AND container='{$folder_container}'"; $result = $connection->query($request); } else { echo "Error fetching container: name does not exists"; return; } } $dir_array = []; while ($line = $result->fetch_assoc()) { $name = $line["name"]; $id = $line["id"]; $container = ucfirst($line["container"]); $dir_array[] = $id; echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' id='{$id}' class='file-list-folder'>{$name}</a>"; if ($permissions == $line["container"] or $permissions == "all") { echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' id='{$id}'><i class='fa fa-remove'></i></button>"; echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' id='{$id}'><i class='fa fa-edit'></i></button>"; } echo "</td><td><span class='text-muted container-value'>{$container}</span></td><td></td><td></td></tr>"; } //get file list $file_array = array_diff(array_diff(scandir($config->plugin_notes_engine_fpath . "/" . $path), array('..', '.', '.DS_Store')), $dir_array); foreach ($file_array as $file) { $url = $config->plugin_notes_engine_fpath . "/" . $path . "/" . $file; if (!is_dir($url)) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $container = ucfirst($folder_container); $content_type = finfo_file($finfo, $url); $file_icon = getFileTypeIcon($content_type, $file); $size = formatBytes(filesize($url), 1); $date = date("d/m/Y", filemtime($url)); $preview = canPreview($content_type); if ($preview == "no") { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>"; } else { echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>"; } if ($permissions == $folder_container or $permissions == "all") { echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>"; if (isEditable($content_type)) { if ($content_type == "text/html") { $mode = "html"; } else { $mode = "code"; } echo "<button type='button' class='btn btn-link pull-right lmb edit-file tooltipped' data-toggle='tooltip' title='Modifica' data-edit-mode='{$mode}' data-path='{$url}'><i class='fa fa-edit'></i></button>"; } } echo "</td><td><span class='text-muted container-value'>{$container}</span></td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>"; } } } echo "</table>"; }