@@ -276,33 +276,56 @@ static function getServerFileTree($params) {
276
276
if (isset ($ params ['node ' ])) {
277
277
278
278
//root node
279
- $ dir = "/var/www/glpi " ;
279
+ $ dir = "/var/www/glpi " ; // TODO : add config option as 0.83 version
280
280
281
281
// leaf node
282
282
if ($ params ['node ' ] != -1 ) {
283
283
$ dir = $ params ['node ' ];
284
284
}
285
285
286
286
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 );
306
329
}
307
330
}
308
331
0 commit comments