Test file list
This commit is contained in:
parent
c73d471fab
commit
b764dfad8b
@ -271,6 +271,9 @@ async function onPageLoad() {
|
|||||||
if ("news" === currentSite && "index" === currentPage) {
|
if ("news" === currentSite && "index" === currentPage) {
|
||||||
await articleInit();
|
await articleInit();
|
||||||
}
|
}
|
||||||
|
if ("files" === currentSite && "list" === currentPage) {
|
||||||
|
await listFiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function navigateTo(site, page) {
|
async function navigateTo(site, page) {
|
||||||
@ -559,3 +562,30 @@ function uploadFile() {
|
|||||||
|
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteFile(fileID){
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('action', 'deleteFile');
|
||||||
|
formData.append('file_id', fileID);
|
||||||
|
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', '/upload', true);
|
||||||
|
xhr.send(formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listFiles() {
|
||||||
|
let fileListContainer = document.getElementById("filelist");
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('action', 'getAllFiles');
|
||||||
|
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', '/upload', true);
|
||||||
|
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
displayList(xhr.responseText, fileListContainer, deleteFile);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(formData);
|
||||||
|
}
|
@ -9,6 +9,7 @@ function endpoint($endpoint_data): array
|
|||||||
"getMyFiles" => listFiles(),
|
"getMyFiles" => listFiles(),
|
||||||
"getAllFiles" => listFiles(false),
|
"getAllFiles" => listFiles(false),
|
||||||
"uploadFiles" => parseIncomingFiles(),
|
"uploadFiles" => parseIncomingFiles(),
|
||||||
|
"deleteFile" => deleteFile($endpoint_data['file_id']),
|
||||||
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
||||||
"myFileExists" => fileExists($endpoint_data['file_id'], ),
|
"myFileExists" => fileExists($endpoint_data['file_id'], ),
|
||||||
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
||||||
|
@ -174,7 +174,7 @@ function getUploadPath($type = "unknown", $filename = "hehe"): string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fileExists(int $fileId, bool $onlyMine = true): bool
|
function fileExists(int $fileId, bool $onlyMine = true): bool|string
|
||||||
{
|
{
|
||||||
if(!$fileId) {
|
if(!$fileId) {
|
||||||
return false;
|
return false;
|
||||||
@ -183,15 +183,22 @@ function fileExists(int $fileId, bool $onlyMine = true): bool
|
|||||||
if (!$onlyMine && !isAdmin()) {
|
if (!$onlyMine && !isAdmin()) {
|
||||||
$onlyMine = true;
|
$onlyMine = true;
|
||||||
}
|
}
|
||||||
$query = 'SELECT ID FROM Files WHERE ID = ?' . $onlyMine ? ' AND UploadedBy = ?' : '';
|
$query = 'SELECT Path FROM Files WHERE ID = ?' . $onlyMine ? ' AND UploadedBy = ?' : '';
|
||||||
$stmtfileexists = $mysqli->prepare($query);
|
$stmtfileexists = $mysqli->prepare($query);
|
||||||
if ($onlyMine) {
|
if ($onlyMine) {
|
||||||
$stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']);
|
$stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']);
|
||||||
} else {
|
} else {
|
||||||
$stmtfileexists->bind_param('i', $fileId);
|
$stmtfileexists->bind_param('i', $fileId);
|
||||||
}
|
}
|
||||||
|
$filePath = "";
|
||||||
|
$stmtfileexists->bind_result($filePath);
|
||||||
$stmtfileexists->execute();
|
$stmtfileexists->execute();
|
||||||
return $stmtfileexists->affected_rows > 0;
|
if (!empty($filePath)){
|
||||||
|
return $filePath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToGroup(int $groupId, int $fileId): array
|
function addToGroup(int $groupId, int $fileId): array
|
||||||
@ -229,3 +236,15 @@ function getImageURL(int $imageFileID) :string
|
|||||||
return $path;
|
return $path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteFile(int $fileID) :string
|
||||||
|
{
|
||||||
|
$out = ["Status" => "Fail"];
|
||||||
|
$file_location = fileExists($fileID, false);
|
||||||
|
if ($file_location){
|
||||||
|
if(unlink($file_location)) {
|
||||||
|
$out['Status'] = 'Success';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
3
pages/files/list.html
Normal file
3
pages/files/list.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
|
||||||
|
<page minimal_permission_level="2" secret="yes" page_title="Zoznam"></page>
|
||||||
|
<div id="filelist"></div>
|
Loading…
Reference in New Issue
Block a user