This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
file_manager.php
executable file
·296 lines (243 loc) · 9.06 KB
/
file_manager.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
session_start();
require("include/functions.php");
$config_file = 'config.php';
if (file_exists($config_file)) {
require("config.php");
} else {
header("Location: error.php?e=config");
die();
}
require("include/apply_config.php");
$force_loggedin = TRUE;
require("include/check_login.php");
if (isset($_GET["ToAddMemberID"])){
$ToAddMemberID=filter_var($_GET["ToAddMemberID"], FILTER_SANITIZE_NUMBER_INT);
$tab=filter_var($_GET["tab"], FILTER_SANITIZE_NUMBER_INT);
$action = filter_var($_GET["action"], FILTER_SANITIZE_NUMBER_INT);
if ($action == 1){
query_one("UPDATE FilesToAddMembers SET ReturnCode='1' WHERE ToAddMemberID=$ToAddMemberID", $connection);
header("Location: $app_url/file_manager.php?tab=$tab");
die();
}
elseif ($action == 2){
query_one("DELETE FROM FilesToAddMembers WHERE ToAddMemberID=$ToAddMemberID", $connection);
header("Location: $app_url/file_manager.php?tab=$tab");
die();
}
}
if (isset($_GET["tab"])){
$tab=filter_var($_GET["tab"], FILTER_SANITIZE_NUMBER_INT);
}
else {
$tab = -1;
}
if ($special_noprocess == FALSE){
add_in_background($absolute_dir, $connection);
}
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<title>$app_custom_name - Files manager</title>
<meta http-equiv=\"refresh\" content=\"30\">\n";
require("include/get_css3.php");
require("include/get_jqueryui.php");
if ($use_googleanalytics) {
echo $googleanalytics_code;
}
#Execute custom code for head, if set
if (is_file("$absolute_dir/customhead.php")) {
include("customhead.php");
}
?>
</head>
<body>
<!--Blueprint container-->
<div class="container">
<?php
require("include/topbar.php");
echo "<h2>Added files status</h2>";
$query = "SELECT *, DATE_FORMAT(FilesToAdd.StartTime, '%d-%b-%Y %H:%i:%s') AS StartTime from FilesToAdd, Users WHERE FilesToAdd.UserID=Users.UserID ORDER BY FilesToAdd.StartTime DESC";
$result = mysqli_query($connection, $query)
or die (mysqli_error($connection));
$nrows = mysqli_num_rows($result);
if ($nrows>0){
$no_files = query_one("SELECT COUNT(*) FROM FilesToAddMembers", $connection);
$no_files_done = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE ReturnCode='0'", $connection);
$no_files_todo = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE ReturnCode='1'", $connection);
$no_files_running = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE ReturnCode='2'", $connection);
$no_files_error = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE ReturnCode='9'", $connection);
$percent = floor(($no_files_done/($no_files-$no_files_error))*100);
echo "<p><strong>Overall statistics</strong> [<a href=\"file_manager.php\">Refresh</a>]:
<ul>
<li>Completed files: $no_files_done</li>
<li>Files being processed: $no_files_running</li>
<li>Files yet to add: $no_files_todo</li>\n";
if ($no_files_error > 0){
echo "<li><img src=\"images/exclamation.png\"> Files with errors: $no_files_error</li>";
}
echo "</ul>\n";
if ($percent<100) {
echo "<div class=\"progress\"><div class=\"progress-bar\" role=\"progressbar\" aria-valuenow=\"$percent\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: $percent%;\"><span class=\"sr-only\">$percent% Complete</span></div></div>";
$how_many = bgHowManyAdd();
if ($how_many > 0){
$PID_array = bgHowManyAdd_PID();
if ($how_many == 1){
echo "<br>$how_many script is running in the background:";
}
else{
echo "<br>$how_many scripts are running in the background:";
}
echo "<ul>\n";
for ($h=0; $h < $how_many; $h++) {
$this_PID = $PID_array[$h];
$how_long = bgProcess_howlong($this_PID);
$how_long = explode(":", $how_long);
$how_long_h = $how_long[0];
$how_long_m = $how_long[1];
if ($how_long_h == "00" && $how_long_m == "00"){
$how_long = "less than a minute";
}
elseif ($how_long_h == "00" && $how_long_m == "01"){
$how_long = "1 minute";
}
elseif ($how_long_h == "00" && $how_long_m != "00"){
$how_long = "$how_long_m minutes";
}
else {
$how_long = "$how_long_h hours and $how_long_m minutes";
}
echo "<li>Script running for $how_long\n</li>";
}
echo "</ul>\n";
}
}
else {
echo "\n<div class=\"progress\"><div class=\"progress-bar\" role=\"progressbar\" aria-valuenow=\"100\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 100%;\"><span class=\"sr-only\">100% Complete</span></div></div>";
}
echo "<br></p>";
if ($tab >= 0){
echo "<script type=\"text/javascript\">
$(function() {
$( \"#accordion\" ).accordion({
collapsible: true,
autoHeight: false,
active: $tab,
icons: { \"header\": \"ui-icon-plus\", \"headerSelected\": \"ui-icon-minus\" }
});
});
</script>
";
}
else {
echo "<script type=\"text/javascript\">
$(function() {
$( \"#accordion\" ).accordion({
collapsible: true,
autoHeight: false,
active: false,
icons: { \"header\": \"ui-icon-plus\", \"headerSelected\": \"ui-icon-minus\" }
});
});
</script>
";
}
echo "
<div id=\"accordion\">";
for ($i=0; $i < $nrows; $i++) {
$row = mysqli_fetch_array($result);
extract($row);
$no_files = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE FilesToAddID='$FilesToAddID'", $connection);
$no_files_done = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE FilesToAddID='$FilesToAddID' AND ReturnCode='0'", $connection);
$no_files_todo = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE FilesToAddID='$FilesToAddID' AND ReturnCode='1'", $connection);
$no_files_inprogress = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE FilesToAddID='$FilesToAddID' AND ReturnCode='2'", $connection);
$no_files_error = query_one("SELECT COUNT(*) FROM FilesToAddMembers WHERE FilesToAddID ='$FilesToAddID' AND ReturnCode='9'", $connection);
$percent = floor(($no_files_done/$no_files)*100);
echo "
<h3><a href=\"#\">Path: $FilesPath ($percent% completed)</a></h3>
<div>
<p>Path: $FilesPath<br>Started on: <strong>$StartTime</strong> by $UserFullname<br>
<ul>
<li>Completed files: $no_files_done</li>
<li>Files being processed: $no_files_inprogress</li>
<li>Files yet to add: $no_files_todo</li>
<li>Files with errors: $no_files_error</li>
</ul>\n";
#don't show table with details unless it is requested or there is a problem
$this_show = FALSE;
if ($no_files_error > 0 || $no_files_inprogress > 0 || $no_files_todo > 0){
$this_show = TRUE;
}
if ($tab == $i){
$this_show = TRUE;
}
if ($this_show){
echo "<table>\n";
echo "<tr><td>
</td><td><strong>File</strong></td><td> </td><td><strong>Status</strong></td></tr>\n";
$query_1 = "SELECT * from FilesToAddMembers WHERE FilesToAddID='$FilesToAddID' ORDER BY ReturnCode DESC";
$result_1 = mysqli_query($connection, $query_1)
or die (mysqli_error($connection));
$nrows_1 = mysqli_num_rows($result_1);
if ($nrows_1>0){
for ($j=0; $j < $nrows_1; $j++) {
$row_1 = mysqli_fetch_array($result_1);
extract($row_1);
echo "<tr><td> </td><td>$FullPath</td><td> </td>\n";
if ($ReturnCode == 1){
echo "<td> <img src=\"images/database.png\"> To add</td></tr>\n";
}
elseif ($ReturnCode == 0){
echo "<td> <img src=\"images/accept.png\"> Added to archive</td></tr>\n";
}
elseif ($ReturnCode == 2){
echo "<td> <img src=\"images/ajax-loader.gif\"> Working... ";
$mins_working = query_one("SELECT TIMESTAMPDIFF(MINUTE, TimeStamp, NOW()) FROM FilesToAddMembers
WHERE ToAddMemberID='$ToAddMemberID'", $connection);
if ($mins_working > 5){
echo "(working for more than five minutes, <a href=\"file_manager.php?ToAddMemberID=$ToAddMemberID&tab=$i&action=1\" title=\"Reset\">reset</a> or
<a href=\"file_manager.php?ToAddMemberID=$ToAddMemberID&tab=$i&action=2\" title=\"Reset\">delete</a>?)";
}
echo "</td></tr>\n";
}
elseif ($ReturnCode == 9){
echo "<td> <img src=\"images/error.png\"> Error: $ErrorCode<br>
<a href=\"file_manager.php?ToAddMemberID=$ToAddMemberID&tab=$i&action=1\" title=\"Reset\">reset</a> |
<a href=\"file_manager.php?ToAddMemberID=$ToAddMemberID&tab=$i&action=2\" title=\"Reset\">delete</a>
</td></tr>\n";
}
}
}
echo "</table>\n";
}
else{
echo "<p><a href=\"file_manager.php?tab=$i\" title=\"Show details\">Show details</a>";
}
echo "</div>\n";
}
echo "</div><!-- End accordion -->\n";
}
else {
echo "<p>There are no files waiting to be added.
<p><a href=\"add.php\">Add files</a>.\n";
}
?>
</div>
<div class="span-24 last">
</div>
<div class="span-24 last">
<?php
require("include/bottom.php");
?>
</div>
</div>
<?php
session_write_close();
flush(); @ob_flush();
if ($special_noprocess == FALSE){
add_in_background($absolute_dir, $connection);
}
?>
</body>
</html>