$querypath = ''; // To prevent ...path LIKE '//%'... in query
{
} else {
$querypath=''; // to prevent ...path LIKE '//%'... in query
}
else
{
$querypath = $path;
$querypath = $path;
}
}
//search for all files that are not deleted => visibility != 2
// Search for all files that are not deleted => visibility != 2
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`<>'2' AND `props`.`to_group_id`=".$to_group_id."");
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`<>'2' AND `props`.`to_group_id`=".$to_group_id."");
//add tem to the zip file
// Add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query))
while ($not_deleted_file = Database::fetch_assoc($query)) {
// For other users, we need to create a zipfile with only visible files and folders
//for other users, we need to create a zipfile with only visible files and folders
else {
else
if ($path == '/') {
{
$querypath = ''; // To prevent ...path LIKE '//%'... in query
if($path=='/')
} else {
{
$querypath=''; // to prevent ...path LIKE '//%'... in query
}
else
{
$querypath = $path;
$querypath = $path;
}
}
//big problem: visible files that are in a hidden folder are included when we do a query for visiblity='v'!!!
// A big problem: Visible files that are in a hidden folder are included when we do a query for visiblity='v'
//so... I do it in a couple of steps:
// So... I do it in a couple of steps:
//1st: get all files that are visible in the given path
// 1st: Get all files that are visible in the given path
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`='1' AND `docs`.`filetype`='file' AND `props`.`to_group_id`=".$to_group_id);
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`='1' AND `docs`.`filetype`='file' AND `props`.`to_group_id`=".$to_group_id);
//add them to an array
// Add them to an array
while ($all_visible_files = Database::fetch_assoc($query))
while ($all_visible_files = Database::fetch_assoc($query)) {
//2nd: get all folders that are invisible in the given path
// 2nd: Get all folders that are invisible in the given path
$query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`<>'1' AND `docs`.`filetype`='folder'");
$query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`<>'1' AND `docs`.`filetype`='folder'");
//if we get invisible folders, we have to filter out these results from all visible files we found
// If we get invisible folders, we have to filter out these results from all visible files we found
if(Database::num_rows($query2)>0)
if (Database::num_rows($query2) > 0) {
{
// Add tem to an array
//add tem to an array
while ($invisible_folders = Database::fetch_assoc($query2)) {
while ($invisible_folders = Database::fetch_assoc($query2))
//3rd: Get all files that are in the found invisible folder (these are "invisible" too)
$query3 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$invisible_folders['path']."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`='1'");
$query3 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$invisible_folders['path']."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`='1'");
//add tem to an array
// Add tem to an array
while ($files_in_invisible_folder = Database::fetch_assoc($query3))
while ($files_in_invisible_folder = Database::fetch_assoc($query3)) {