require("./global.php");
if (!isset($_GET['folderId'])) {
header("Location: ?folderId=/");
}
$parentFolder = escape($_GET['folderId']);
$folder_info = getRow($con, "SELECT * FROM " . $g_projectSlug . "_folders WHERE id='$parentFolder'");
if (isset($_POST['create_folder_package'])) {
$actionId = escape($_POST['actionId']);
$folder = escape($_POST['folder_name']);
$parentFolder = escape($_GET['folderId']);
// Assuming you have a function to generate a unique ID like 'generateRandomString()'
if (empty($actionId)) {
$id = generateRandomString();
$query = "INSERT INTO " . $g_projectSlug . "_folders (id, title, timeAdded, userId, parent_folder) VALUES ('$id', '$folder', NOW(), '$session_userId','$parentFolder')";
} else {
$query = "UPDATE " . $g_projectSlug . "_folders SET title='$folder',parent_folder='$parentFolder' WHERE id='$actionId'";
}
runQuery($query);
header("Location:./file-manager.php?folderId=$parentFolder&m=Data was saved successfully!");
}
if (isset($_GET['delete-record'])) {
$id = escape($_GET['delete-record']);
$query = "delete from " . $g_projectSlug . "_folders where id='$id'";
runQuery($query);
// Specify the parent directory where the folder was deleted from.
$parentDirectory = './uploads';
// Delete the child folder within the parent folder
$childDirectory = $parentDirectory . '/' . $folder;
if (is_dir($childDirectory)) {
rmdir($childDirectory);
}
}
if (isset($_POST['uploadfile'])) {
$timeAdded = time();
$files = $_FILES['files'];
foreach ($files['tmp_name'] as $index => $tmpName) {
$fileName = $files['name'][$index];
$fileType = $files['type'][$index];
$fileSize = $files['size'][$index];
$fileError = $files['error'][$index];
if ($fileError === UPLOAD_ERR_OK) {
$destination = './uploads/' . $fileName; // Set the destination path
move_uploaded_file($tmpName, $destination); // Move the uploaded file to the destination
// Insert file details into the database
$id = generateRandomString();
if ($fileName != "") {
$stmt = $con->prepare("INSERT INTO " . $g_projectSlug . "_files set id='$id', file='$destination', file_size='$fileSize', folder='$parentFolder', timeAdded='$timeAdded', userId='$session_id'");
if (!$stmt) {
echo "err: $query";
}
if (!$stmt->execute()) {
echo "err: $query";
}
}
}
}
header("Location:./file-manager.php?folderId=$parentFolder&m=File Has Been Uploaded successfully!");
}
if (isset($_POST['updatefile'])) {
$alternative_text = $_POST['file_alternative_text'];
$title = $_POST['file_title'];
$file_caption = $_POST['file_caption'];
$file_description = $_POST['file_description'];
$url = $_POST['file_url'];
$actionId = $_POST['file_actionId'];
$stmt = $con->prepare("UPDATE " . $g_projectSlug . "_files SET alternative_text='$alternative_text', title='$title', caption='$file_caption', description='$file_description', url='$url' WHERE id='$actionId'");
if (!$stmt) {
echo "err: $query";
}
if (!$stmt->execute()) {
echo "err: $query";
}
header("Location:./file-manager.php?folderId=$parentFolder&m=File Has Been Updated successfully!");
}
$all_file_category = getRow($con, "SELECT
SUM(CASE WHEN RIGHT(`file`, 4) IN ('.jpg', 'jpeg', '.png', '.gif', '.bmp') THEN file_size ELSE 0 END) AS pic_size,
SUM(CASE WHEN RIGHT(`file`, 4) IN ('.mp4', '.flv', '.avi', '.mov', '.wmv') THEN file_size ELSE 0 END) AS video_size,
SUM(CASE WHEN RIGHT(`file`, 4) IN ('.mp3', '.wav', '.aac', '.ogg', '.wma') THEN file_size ELSE 0 END) AS audio_size,
SUM(CASE WHEN RIGHT(`file`, 4) NOT IN ('.jpg', 'jpeg', '.png', '.gif', '.bmp', '.mp4', '.flv', '.avi', '.mov', '.wmv', '.mp3', '.wav', '.aac', '.ogg', '.wma') THEN file_size ELSE 0 END) AS doc_size,
SUM(file_size) as all_files_size
FROM
" . $g_projectSlug . "_files WHERE userId='$session_id';");
?>