Jump to content

Problem to sort folders alphabetically


100tral

Recommended Posts

hi,

in this code "Virtual Directories" and "Files" are sort alphabetically, but i don't know how to sort "Non Virtual Directories"  ???

Thanks for your help and sorry for my bad english !

 

	// 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;
}

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/181508-problem-to-sort-folders-alphabetically/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.