Skip to content

Commit 328600e

Browse files
committed
package : sort folder and files separately
1 parent 6c7bcf5 commit 328600e

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

fusioninventory/inc/deployfile.class.php

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -276,33 +276,56 @@ static function getServerFileTree($params) {
276276
if (isset($params['node'])) {
277277

278278
//root node
279-
$dir = "/var/www/glpi";
279+
$dir = "/var/www/glpi"; // TODO : add config option as 0.83 version
280280

281281
// leaf node
282282
if ($params['node'] != -1) {
283283
$dir = $params['node'];
284284
}
285285

286286
if ($handle = opendir($dir)) {
287-
while (false !== ($entry = readdir($handle))) {
288-
if ($entry != "." && $entry != "..") {
289-
$filepath = $dir."/".$entry;
290-
$path['text'] = $entry;
291-
$path['id'] = $filepath;
292-
$path['draggable'] = false;
293-
294-
if (is_dir($filepath)) {
295-
$path['leaf'] = false;
296-
$path['cls'] = 'folder';
297-
} else {
298-
$path['leaf'] = true;
299-
$path['cls'] = 'file';
300-
}
301-
302-
$nodes[] = $path;
303-
}
304-
}
305-
closedir($handle);
287+
$folders = $files = array();
288+
289+
//list files in dir selected
290+
//we store folders and files separately to sort them alphabeticaly separatly
291+
while (false !== ($entry = readdir($handle))) {
292+
if ($entry != "." && $entry != "..") {
293+
$filepath = $dir."/".$entry;
294+
if (is_dir($filepath)) {
295+
$folders[$filepath] = $entry;
296+
} else {
297+
$files[$filepath] = $entry;
298+
}
299+
}
300+
}
301+
302+
//sort folders and files (and maintain index association)
303+
asort($folders);
304+
asort($files);
305+
306+
//add folders in json
307+
foreach ($folders as $filepath => $entry) {
308+
$path['text'] = $entry;
309+
$path['id'] = $filepath;
310+
$path['draggable'] = false;
311+
$path['leaf'] = false;
312+
$path['cls'] = 'folder';
313+
314+
$nodes[] = $path;
315+
}
316+
317+
//add files in json
318+
foreach ($files as $filepath => $entry) {
319+
$path['text'] = $entry;
320+
$path['id'] = $filepath;
321+
$path['draggable'] = false;
322+
$path['leaf'] = true;
323+
$path['cls'] = 'file';
324+
325+
$nodes[] = $path;
326+
}
327+
328+
closedir($handle);
306329
}
307330
}
308331

0 commit comments

Comments
 (0)