Debian Codegraph @

qchem/dirlist.php

raw
1 <?php
2 //
3 // PHP script to display directory listing
4 //
5
6 //
7 // These values must match values in write.php
8 // Set parameters defining:
9 // base: base of directory path
10 // admin: name of administrative user
11 //
12 $base = "data";
13 $admin = "admin";
14
15 //
16 // Get subdirectory from AJAX _POST
17 //
18 $subdir = $_POST['path'];
19 if ( $subdir[0] == "/" )
20 $subdir = substr($subdir, 1);
21
22 //
23 // Get username
24 //
25 $user = $_SERVER['PHP_AUTH_USER'];
26
27 //
28 // Build file path
29 //
30 $mypath = $base;
31 if ( "$user" != "$admin")
32 $mypath = "$mypath/$user";
33 if (strlen($subdir) > 2)
34 $mypath = "$mypath/$subdir";
35
36 //
37 // Set allowed extensions to show user
38 //
39 $molext = array (".xyz", ".mol");
40 $txtext = array (".inp", ".out", ".sum");
41
42 //
43 // Read sorted list of files and directories into array
44 //
45 $filelist = scandir($mypath);
46
47 //
48 // Set values for icon images
49 //
50 $iconFolder = "<img src=\"icon_folder.png\" width=\"16\" height=\"16\" />";
51 $iconMol = "<img src=\"icon_molecule.png\" width=\"16\" height=\"16\" />";
52 $iconText = "<img src=\"icon_textfile.png\" width=\"16\" height=\"16\" />";
53 $iconDelete = "<img src=\"icon_delete.png\" width=\"16\" height=\"16\" />";
54
55 //
56 // Output list of all directories
57 //
58 if (strlen($subdir) > 2) {
59 echo "<div class=\"DelColumn\" >&nbsp;</div>";
60 echo "<div class=\"DirOrFile\" onclick=\"dirList();\">";
61 echo "$iconFolder Home Directory</div>";
62 }
63 for ($i=0; $i < count($filelist); $i++) {
64 if (strlen($filelist[$i]) > 2) {
65 if ( strpos($filelist[$i], ".") === false ) {
66 echo "<div class=\"DelColumn\" >&nbsp;</div>";
67 echo "<div class=\"DirOrFile\" onclick=\"dirList('$filelist[$i]');\">";
68 echo "$iconFolder $filelist[$i]</div>";
69 }
70 }
71 }
72
73 //
74 // Output list of all files
75 //
76 for ($i=0; $i < count($filelist); $i++) {
77 if (strlen($filelist[$i]) > 2) {
78 // If file is of 'molecule' type, show file
79 for ($j=0; $j < count($molext); $j++) {
80 if (strpos($filelist[$i],$molext[$j]) > 0) {
81 echo "<div class=\"DelColumn\" onclick=\"fillDelWin('$mypath/$filelist[$i]');\">";
82 echo "$iconDelete </div> ";
83 echo "<div class=\"DirOrFile\" onclick=\"showname('$mypath/$filelist[$i]');\">";
84 echo "$iconMol $filelist[$i]</div>";
85 }
86 }
87 // If file is of allowed 'text' type, show file
88 for ($j=0; $j < count($txtext); $j++) {
89 if (strpos($filelist[$i],$txtext[$j]) > 0) {
90 echo "<div class=\"DelColumn\" onclick=\"fillDelWin('$mypath/$filelist[$i]');\">";
91 echo "$iconDelete </div> ";
92 echo "<div class=\"DirOrFile\" onclick=\"showname('$mypath/$filelist[$i]');\">";
93 echo "$iconText $filelist[$i]</div>";
94 }
95 }
96 }
97 }
98
99 // Finished
100 return;
101 ?>