1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| function getFolder($path){
global $database, $dateFormat, $json;
userPermissions();
$path = mysql_escape_string($path);
// For Virtual Directories
if($path == '' || $path == '/'){
$query = sprintf('select * from %spermissions inner join %sbins on %spermissions.binid=%sbins.id where userid="%s" and %sbins.name ="%s" order by display',
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$_SESSION['userid'],
$GLOBALS['tablePrefix'],
$_SESSION['user']);
$result = mysql_query($query,$database) or die( error('Get Folder query failed') );
while($bins = mysql_fetch_assoc($result)) {
$listing[] = array( displayname => $bins['display'],
scheme => $bins['scheme'],
type => "directory",
name => $bins['name'],
path => '/'. $bins['name'],
virtual => "true" );
}
$query = sprintf('select * from %spermissions inner join %sbins on %spermissions.binid=%sbins.id where userid="%s" and %sbins.name !="%s" order by display',
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$GLOBALS['tablePrefix'],
$_SESSION['userid'],
$GLOBALS['tablePrefix'],
$_SESSION['user']);
$result = mysql_query($query, $database) or die( error('Get Folder query failed') );
$vdcount = mysql_num_rows($result);
switch(true) {
case ($vdcount >= 1):
$virtual = "closed";
break;
case ($vdcount == 1):
$virtual = "true";
break;
default :
$virtual = "false";
}
if($vdcount > 0)
while($bins = mysql_fetch_assoc($result)){
$listing[] = array( displayname => $bins['display'],
scheme => $bins['scheme'],
type => "directory",
name => $bins['name'],
path => '/'. $bins['name'],
virtual => $virtual );
}
echo $json->encode($listing);
exit;
}
// Non Virtual Directories
if( getUserAuth('view', $path) ){
logAction('list',$path);
$fullpath = getUserPath($path).$path;
databaseSync($fullpath,$path);
// Directories
if (is_dir($fullpath)) {
if ($dh = opendir($fullpath)) {
while (($file = readdir($dh)) !== false) {
if(substr($file,0,1) != '.' && is_dir($fullpath . '/' . $file)) {
$listing[] = array(
type => "directory",
name => $file,
path => $path .'/'. $file );
}
}
closedir($dh);
}
}
else error("directory doesnt exist $fullpath");
// Files
$query = sprintf('select *,date_format(`date`,"%s") as `dateformatted` from %sfilesystem where path="%s" and status="%s" order by `filename',
$dateFormat,
$GLOBALS['tablePrefix'],
$fullpath,
"found" );
$result = mysql_query($query,$database) or die( error('Get Folder query failed') );
while($files = mysql_fetch_assoc($result)) {
$listing[] = array( type => "file",
name => $files['filename'],
date => $files['dateformatted'],
id => $files['id'] );
}
}
else error("Access Denied $path");
echo $json->encode($listing);
exit;
} |
Partager