forked from MonstaApps/Monsta-FTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.js
1224 lines (899 loc) · 37.8 KB
/
ajax.js
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function ajaxStart() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
alert(lang_no_xmlhttp);
}
return xmlhttp;
}
var globalBrowser;
function detectBrowser() {
var userAgent = navigator.userAgent.toLowerCase()
// IE version check (IE10+ supports file input onChange and drag & drop uploads)
if (userAgent.indexOf("msie") != -1) {
if (parseFloat((userAgent.match(/.*(?:rv|ie)[\/: ](.+?)([ \);]|$)/) || [])[1]) >= 10)
globalBrowser = "ie10+";
else
globalBrowser = "ie9-";
}
// Other browsers
if (userAgent.indexOf("firefox") != -1)
globalBrowser = "firefox";
if (userAgent.indexOf("safari") != -1)
globalBrowser = "safari";
if (userAgent.indexOf("chrome") != -1)
globalBrowser = "chrome"; // Chrome check must follow Safari as userAgent for Chrome includes "Safari"
if (userAgent.indexOf("opera") != -1)
globalBrowser = "opera";
}
var globalOs;
function detectOs() {
if (navigator.appVersion.indexOf("Win") != -1) globalOs = "win";
if (navigator.appVersion.indexOf("Mac") != -1) globalOs = "mac";
}
function listenDropFiles() {
// Set the drag & drop div ID
var dropFilesDiv = document.getElementById("ajaxContentWindow");
var dropFilesCheckDiv = document.getElementById("dropFilesCheckDiv");
var xmlhttp = new XMLHttpRequest();
// Check if upload is supported
if (xmlhttp.upload) {
// Add listener to file drop div
dropFilesDiv.addEventListener("dragover", stopBrowserActions, false);
dropFilesDiv.addEventListener("dragleave", stopBrowserActions, false);
dropFilesDiv.addEventListener("drop", captureDropFiles, false);
// D&D supported message
//dropFilesCheckDiv.innerHTML = lang_support_drop;
//dropFilesCheckDiv.className = 'dropFilesCheckPassColor';
} else {
// D&D unsupported message
//dropFilesCheckDiv.innerHTML = lang_no_support_drop;
//dropFilesCheckDiv.className = 'dropFilesCheckFailColor';
}
}
function listenContextMenu() {
if (globalBrowser == "ie")
document.attachEvent("onclick", hideFileContextMenu);
else
document.addEventListener("click", hideFileContextMenu, true);
}
function captureDropFiles(e) {
stopBrowserActions(e);
// Get the dropped files
var globalFiles = e.target.files || e.dataTransfer.files; // firefox/safari || chrome
// Upload files
if (globalFiles.length > 0)
processFileUploads(e, 1, 0, globalFiles);
}
var globalFileUploadPreCount;
var globalFileUploadCount;
var globalFileUploadTotal;
var globalFiles = new Array();
var globalPaths = new Array();
function processFileUploads(e, isDrop, isFolder, globalFiles) {
var xmlhttp = ajaxStart();
// Check upload is supported
if (xmlhttp.upload) {
// Turn off repeat button
if (isDrop == 1 || isFolder == 1)
hideRepeatButton();
// CHROME - DRAG & DROP FOLDER
if (globalBrowser == "chrome" && isDrop == 1) {
//globalFileUploadCount=0;
var items = e.dataTransfer.items;
// Check there is at least 1 file
if (items.length > 0) {
// Resize file listing window
setFileWindowSize("ajaxContentWindow", 0, 360);
// Count files to upload
globalFileUploadPreCount = 0;
for (var i = 0; i < items.length; i++) {
var item = items[i].webkitGetAsEntry();
traverseFileTree(item, "");
}
// The uploading of files needs a slight delay to allow the
// traverseFileTree() function to start counting the files to upload
setTimeout(function() {
uploadFilesChrome()
}, 500);
}
}
// CHROME - SELECT FOLDER
if (isFolder == 1) {
// Reset arrays
globalFiles = [];
globalPaths = [];
// Process the files
var folderContents = e.target.files;
// Check there is at least 1 file
if (folderContents.length > 0) {
// Resize file listing window
setFileWindowSize("ajaxContentWindow", 0, 360);
for (var i = 0, j = 0, file, filePath, fileName; file = folderContents[i]; i++) {
// Check file is not a folder (represented by a dot)
if (file.name != ".") {
fileName = file.webkitRelativePath;
displayTransferWindow(file, fileName, j); // display file in transfer window
filePath = fileName.replace(file.name, "");
globalFiles[j] = file; // record file to array
globalPaths[j] = encodeURIComponent(filePath); // record path to array
j++;
}
}
// Upload the folder
uploadFoldersChrome(globalFiles);
}
}
// OTHER BROWSERS - DRAG & DROP (OR SELECT FILE/S (ALSO CHROME))
if (globalBrowser != "chrome" || (isFolder == 0 && isDrop == 0)) {
// Reset this value for Chrome folder drops
globalFileUploadPreCount = 0;
// Set the files input field if not drag & drop
if (globalFiles == '')
globalFiles = document.getElementById('uploadFile').files;
// Check there is at least 1 file
if (globalFiles.length > 0) {
// Resize file listing window
setFileWindowSize("ajaxContentWindow", 0, 360);
// Open transfer window
for (var i = 0, file; file = globalFiles[i]; i++) {
displayTransferWindow(file, file.name, i);
}
// Display indicator icon
showIndicatorDiv();
// Upload first file (subsequent files upload as each one finishes)
globalFileUploadCount = 0;
globalFileUploadTotal = globalFiles.length;
fileUploader(globalFiles, "", globalFileUploadCount, 0, isDrop);
}
}
} else {
// Submit to iframe if AJAX upload not supported
submitToIframe("&ftpAction=iframe_upload");
}
}
function uploadFilesChrome(globalFolders) {
globalFileUploadCount = 0; // must be set as a var
var filePath = globalPaths[0]; // parse the first path
fileUploader(globalFiles, filePath, globalFileUploadCount, 0, 1);
}
function uploadFoldersChrome(globalFiles) {
// This function exists parallel to uploadFilesChrome() because the
// value of globalFiles gets reset between processFileUploads() and
// uploadFilesChrome().
globalFileUploadCount = 0; // must be set as a var
globalFileUploadTotal = globalFiles.length;
var filePath = globalPaths[0]; // parse the first path
fileUploader(globalFiles, filePath, globalFileUploadCount, 1, 0);
}
function traverseFileTree(item, filePath) {
// If File
if (item.isFile) {
item.file(function(file) {
var fileName = filePath + file.name;
displayTransferWindow(file, fileName, globalFileUploadPreCount); // display file in transfer window
globalFiles[globalFileUploadPreCount] = file; // record file to array
globalPaths[globalFileUploadPreCount] = encodeURIComponent(filePath); // record path to array
globalFileUploadPreCount++;
});
}
// If Directory
if (item.isDirectory) {
var dirReader = item.createReader();
// Read list of files/folders and call this function on each
dirReader.readEntries(function(entries) {
for (var i = 0; i < entries.length; i++) {
traverseFileTree(entries[i], filePath + item.name + "/");
}
});
}
}
function displayTransferWindow(file, fileName, rowID) {
rowID++; // Add 1 for table headers
showPopUp('uploadProgressDiv');
// Append a table row to transfer div
var table = document.getElementById("uploadProgressTable");
var row = table.insertRow(rowID);
row.id = "row" + rowID;
var cell1 = row.insertCell(0); // blank
var cell2 = row.insertCell(1);
cell2.innerHTML = formatStrLen(fileName, 65, 1); // file name
var cell3 = row.insertCell(2);
cell3.innerHTML = formatFileSize(file.size); // file size
var cell4 = row.insertCell(3);
cell4.innerHTML = '<div class="floatLeft" id="progressParent' + rowID + '">' + lang_transfer_pending + '</div><div class="progressBar" id="percent' + rowID + '"></div>'; // progress bar
var cell5 = row.insertCell(4);
cell5.innerHTML = '<div id="timeE' + rowID + '"></div>'; // time elapsed
var cell6 = row.insertCell(5);
cell6.innerHTML = '<div id="uploaded' + rowID + '"></div>'; // size uploaded
var cell7 = row.insertCell(6);
cell7.innerHTML = '<div id="rate' + rowID + '"></div>'; // transfer rate
var cell8 = row.insertCell(7);
cell8.innerHTML = '<div id="timeR' + rowID + '"></div>'; // time remaining
var cell9 = row.insertCell(8);
cell9.innerHTML = '<div id="close' + rowID + '"></div>'; // close button (for rejects)
// Set background color of even-numbered rows
if (rowID % 2 == 0)
row.className = 'trBg1';
else
row.className = 'trBg0';
}
function fileUploader(globalFiles, filePath, rowID, isFolder, isDrop) {
showIndicatorDiv();
// Get file from array
file = globalFiles[rowID];
rowID++; // Add 1 for table headers
// Check the file size doesn't exceed allowed limit
if (file.size > upload_limit) {
// Change progress to error message
document.getElementById('progressParent' + rowID).innerHTML = '<span class="sizeErrorSpan">' + lang_file_size_error + '</span>' // status
// Add close button to row
document.getElementById('close' + rowID).innerHTML = '<span class="progressClose" onclick="deleteProgressRow(' + rowID + ')">x</span>' // status
// Start next transfer
globalFileUploadCount++;
// Check if another file needs uploading
if (globalFileUploadCount < globalFileUploadTotal || globalFileUploadCount < globalFileUploadPreCount) {
// Set path (if exists)
if (globalPaths[globalFileUploadCount] != undefined)
filePath = globalPaths[globalFileUploadCount]
fileUploader(globalFiles, filePath, globalFileUploadCount, isFolder, isDrop);
} else {
// Reset arrays
globalFiles = [];
globalPaths = [];
// Display repeat button
if (isDrop == 0 && isFolder == 0)
showRepeatButton();
// Reset form for Chrome
if (isFolder == 1) {
resetForm();
}
// Hide indicator icon
hidePopUp('indicatorDiv');
}
} else {
// File size accepted
var xmlhttp = ajaxStart();
// Set action for change of state (listener)
xmlhttp.onreadystatechange = function stateChanged() {
// Check if upload has completed
if (xmlhttp.readyState == 4) {
// Set the values of the progress fields to max (finished)
document.getElementById('progress' + rowID).value = 100; // progress bar
document.getElementById('percent' + rowID).innerHTML = '100%'; // percent
document.getElementById('timeR' + rowID).innerHTML = formatSecondsToTime(0); // time remaining
document.getElementById('progressParent' + rowID).innerHTML = '<span class="transferringSpan">' + lang_transferring_to_ftp + '</span>' // status
document.getElementById('percent' + rowID).innerHTML = ""; // percent
document.getElementById('timeE' + rowID).innerHTML = ""; // time elapsed
//document.getElementById('uploaded'+rowID).innerHTML = formatFileSize(file.size); (commented out because by the time the function returns, the value has already been cleared)
document.getElementById('uploaded' + rowID).innerHTML = ""; // uploaded
document.getElementById('rate' + rowID).innerHTML = ""; // transfer rate
document.getElementById('timeR' + rowID).innerHTML = ""; // time remaining
// Refresh open folder (delay half second to complete progress display)
setTimeout(function() {
openThisFolder(globalOpenFolder, 0)
}, 500)
// Delete the progress row from table (delay half second to complete progress display)
setTimeout(function() {
deleteProgressRow(rowID)
}, 500)
// Start next transfer
globalFileUploadCount++;
// Check if another file needs uploading
if (globalFileUploadCount < globalFileUploadTotal || globalFileUploadCount < globalFileUploadPreCount) {
// Set path (if exists)
if (globalPaths[globalFileUploadCount] != undefined)
filePath = globalPaths[globalFileUploadCount]
fileUploader(globalFiles, filePath, globalFileUploadCount, isFolder, isDrop);
} else {
// Reset arrays
globalFiles = [];
globalPaths = [];
// Display repeat button
if (isDrop == 0 && isFolder == 0)
showRepeatButton();
// Reset form for Chrome
if (isFolder == 1) {
resetForm();
}
}
}
}
// Create the progress bar
document.getElementById('progressParent' + rowID).innerHTML = '<progress id="progress' + rowID + '"min="0" max="100" value="0"></progress>';
var start = new Date().getTime(),
elapsed = '0.0';
var time = 0;
var elapsed = 0;
var bytesPerSecond = 0;
var timeToUpload = 0;
var progress = 0;
var progressBar;
// Update progress info
xmlhttp.upload.onprogress = function(e) {
if (e.lengthComputable) {
// Get elapsed time
time = new Date().getTime() - start;
elapsed = Math.floor(time / 1000);
// Set the elapsed time
document.getElementById('timeE' + rowID).innerHTML = formatSecondsToTime(elapsed);
// Set the uploaded amount
document.getElementById('uploaded' + rowID).innerHTML = formatFileSize(e.loaded);
// Get the transfer rate
if (elapsed == 0)
bytesPerSecond = e.loaded; // if less than 1s set xfer rate to file size
else
bytesPerSecond = e.loaded / elapsed;
// Set the transfer rate
document.getElementById('rate' + rowID).innerHTML = formatFileSize(bytesPerSecond) + '/s';
// Get remaining time
timeToUpload = Math.round((e.total - e.loaded) / bytesPerSecond);
// Set the remaining time
document.getElementById('timeR' + rowID).innerHTML = formatSecondsToTime(timeToUpload);
// Get the progress
progressBar = document.getElementById('progress' + rowID);
progressBar.value = (e.loaded / e.total) * 100;
// Set the progress bar
//progressBar.innerHTML = Math.round(progressBar.value)+'%'; // Display % for unsupported browsers
// Display %age complete
document.getElementById('percent' + rowID).innerHTML = Math.round(progressBar.value) + '%';
}
};
// Post form
xmlhttp.open("POST", "?ftpAction=upload&filePath=" + filePath, true);
xmlhttp.setRequestHeader("Cache-Control", "no-cache");
xmlhttp.setRequestHeader("X-Filename", file.name);
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.setRequestHeader("X-File-Size", file.size);
xmlhttp.setRequestHeader("X-File-Type", file.type);
//xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");
xmlhttp.send(file);
}
}
function stopBrowserActions(e) {
e.stopPropagation();
e.preventDefault();
}
function processForm(vars) {
// Display indicator icon
showIndicatorDiv();
var xmlhttp = ajaxStart();
// Get form data
vars = vars + generateVars();
// Add window dimensions
vars = vars + "&windowWidth=" + window.innerWidth;
vars = vars + "&windowHeight=" + window.innerHeight;
// Return HTML from AJAX to div (when complete)
xmlhttp.onreadystatechange = function stateChanged() {
if (xmlhttp.readyState == 4) {
document.getElementById("ajaxContentWindow").innerHTML = xmlhttp.responseText;
}
}
// Post form
xmlhttp.open("POST", "?", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlhttp.setRequestHeader("Content-length", vars.length); // Commented out as not neccessary (Browsers can determine this themselves)
//xmlhttp.setRequestHeader("Connection", "close"); // Commented out as not neccessary
xmlhttp.send(vars);
// Hide indicator icon
hidePopUp('indicatorDiv');
}
function generateVars() {
var theForm = document.getElementById('ftpActionForm');
var vars = '';
for (i = 0; i < theForm.elements.length; i++) {
if (theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "checkbox" || theForm.elements[i].type == "select-one" || theForm.elements[i].type == "radio" || theForm.elements[i].type == "hidden" || theForm.elements[i].type == "password" || theForm.elements[i].type == "button") {
// Text, Texarea, Hidden, Password, Button
if (theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "hidden" || theForm.elements[i].type == "password" || theForm.elements[i].type == "button") {
vars += "&";
vars += theForm.elements[i].name;
vars += "=";
vars += encodeURIComponent(theForm.elements[i].value);
}
// Checkbox
if (theForm.elements[i].type == "checkbox") {
vars += "&";
vars += theForm.elements[i].name;
vars += "=";
if (theForm.elements[i].checked == true)
vars += theForm.elements[i].value;
}
// Radio
if (theForm.elements[i].type == "radio") {
if (theForm.elements[i].checked == true) {
vars += "&";
vars += theForm.elements[i].name;
vars += "=";
vars += theForm.elements[i].value;
}
}
// Select (single only - multiple not supported)
if (theForm.elements[i].type == "select-one") {
vars += "&";
vars += theForm.elements[i].name;
vars += "=";
if (theForm.elements[i].options[theForm.elements[i].selectedIndex].value != "")
vars += encodeURIComponent(theForm.elements[i].options[theForm.elements[i].selectedIndex].value);
else
vars += encodeURIComponent(theForm.elements[i].options[theForm.elements[i].selectedIndex].text);
}
}
}
return vars;
}
function showPopUp(windowID) {
var theWin = document.getElementById(windowID);
theWin.style.visibility = 'visible';
theWin.style.display = '';
// Change cursor to progress
document.getElementById("ajaxContentWindow").style.cursor = 'progress';
}
function hidePopUp(windowID) {
var theWin = document.getElementById(windowID);
theWin.style.visibility = 'hidden';
theWin.style.display = 'none';
// Change cursor from progress to default
document.getElementById("ajaxContentWindow").style.cursor = 'default';
}
function centerPopUp(windowID, popUpWidth, popUpHeight) {
var popUpLeft;
var popUpTop;
popUpLeft = (window.innerWidth - popUpWidth) / 2;
popUpTop = (window.innerHeight - popUpHeight) / 2;
var theWin = document.getElementById(windowID);
theWin.style.position = 'absolute';
theWin.style.left = popUpLeft + 'px';
theWin.style.top = popUpTop + 'px';
theWin.style.width = popUpWidth + 'px';
theWin.style.height = popUpHeight + 'px';
}
function showIndicatorDiv() {
showPopUp('indicatorDiv');
centerPopUp('indicatorDiv', 32, 32);
}
function checkboxSelectAll() {
// Determine if "select all" checkbox is checked
if (document.getElementById("checkboxSelector").checked == true) {
var isChecked = 1;
activateActionButtons(1, 0);
} else {
var isChecked = 0;
activateActionButtons(0, 0);
}
// Go through each checkbox
var theForm = document.getElementById('ftpActionForm');
for (i = 0; i < theForm.elements.length; i++) {
if (theForm.elements[i].type == "checkbox") {
if (isChecked == 1)
theForm.elements[i].checked = true;
else
theForm.elements[i].checked = false;
}
}
}
var globalEditorDefaultSize = 170;
function setFileWindowSize(divID, height, dedn) {
if (dedn == 0)
dedn = globalEditorDefaultSize;
if (height == 0) {
var screenHeight = window.innerHeight;
var height = screenHeight - dedn;
}
document.getElementById("ajaxContentWindow").style.height = height + 'px';
}
function uploadFileCheck(e) {
if (document.getElementById("uploadFile").value == "")
alert(lang_no_file_selected);
else
processFileUploads(e, 0, 0, '')
}
function refreshListing() {
openThisFolder(globalOpenFolder, 0);
}
var globalOpenFolder;
function openThisFolder(folder, hideRepeatBtn) {
if (folder == undefined)
folder = "";
else
globalOpenFolder = folder;
// Submit form
processForm('&ftpAction=openFolder&openFolder=' + folder);
// Hide Repeat Upload button
if (hideRepeatBtn == 1) {
hideRepeatButton();
resetForm();
}
}
function showRepeatButton() {
// Files do not upload properly in Firefox
if (globalBrowser != "firefox") {
document.getElementById("repeatUploadDiv").style.visibility = 'visible';
document.getElementById("repeatUploadDiv").style.display = '';
}
}
function hideRepeatButton() {
document.getElementById("repeatUploadDiv").style.visibility = 'hidden';
document.getElementById("repeatUploadDiv").style.display = 'none';
}
function checkFilesSelected() {
// Go through each checkbnox
var theForm = document.getElementById('ftpActionForm');
var isChecked = 0;
for (i = 0; i < theForm.elements.length; i++) {
if (theForm.elements[i].type == "checkbox") {
if (theForm.elements[i].checked == true)
isChecked = 1;
}
}
if (isChecked == 0) {
alert(lang_none_selected);
return 0;
} else {
return 1;
}
}
function checkFileChecked() {
var isChecked = 0;
// Go through each checkbox for a tick
var theForm = document.getElementById('ftpActionForm');
for (i = 0; i < theForm.elements.length; i++) {
if (theForm.elements[i].type == "checkbox" && theForm.elements[i].checked == true)
isChecked = 1;
}
// If at least one box is ticked, activate action buttons
if (isChecked == 1) {
activateActionButtons(1, 0);
} else {
activateActionButtons(0, 0);
}
}
function activateActionButtons(active, paste) {
// Paste button
if (paste == 1 || globalClipboardAction == 'copy')
document.getElementById('actionButtonPaste').disabled = false;
else
document.getElementById('actionButtonPaste').disabled = true;
// All other buttons
if (active == 1) {
/* document.getElementById('actionButtonDl').disabled = false; // download */
document.getElementById('actionButtonCut').disabled = false; // cut
document.getElementById('actionButtonCopy').disabled = false; // copy
document.getElementById('actionButtonRename').disabled = false; // rename
document.getElementById('actionButtonDelete').disabled = false; // delete
if (document.getElementById('actionButtonChmod'))
document.getElementById('actionButtonChmod').disabled = false; // chmod
} else {
/* document.getElementById('actionButtonDl').disabled = true; */
document.getElementById('actionButtonCut').disabled = true;
document.getElementById('actionButtonCopy').disabled = true;
document.getElementById('actionButtonRename').disabled = true;
document.getElementById('actionButtonDelete').disabled = true;
if (document.getElementById('actionButtonChmod'))
document.getElementById('actionButtonChmod').disabled = true;
}
}
function alertCopyWarning() {
// This function is not active by default, but can
// be activated on the actionFunctionCopy() function
alert('WARNING: As files cannot be copied on the remote server they \n will be downloaded to the client server and uploaded to the \n destination folder. Depending on the size and number of files \n being copied, this may take several minutes.');
}
var globalClipboardAction;
function setClipboard(type) {
globalClipboardAction = type;
}
function parseDownloadError(error) {
processForm('&ftpAction=openFolder&error=' + error);
}
function updateChmodNum(cbId, n) {
var c = document.getElementById("chmodNum").value;
if (c == "")
c = 0;
if (document.getElementById(cbId).checked == true)
c = parseInt(c) + n;
else
c = c - n;
document.getElementById("chmodNum").value = c;
}
function displayContextMenu(e, file, folder, isLin) {
stopBrowserActions(e);
showFileContextMenu(e, file, folder, isLin);
}
function hideFileContextMenu() {
document.getElementById("contextMenu").style.visibility = 'hidden';
document.getElementById("contextMenu").style.display = 'none';
}
var globalContextHeight;
function showFileContextMenu(e, file, folder, isLin) {
globalContextHeight = 12; // top and bottom padding
// Set function for paste
if (file == "" && (globalClipboardAction == "cut" || globalClipboardAction == "copy"))
var pasteOnclick = "actionFunctionPaste('" + folder + "')";
else
var pasteOnclick = "";
var menuHTML = "";
// Open folder or Download file
if (folder != "")
menuHTML += createContextMenuItem(lang_context_open, "openThisFolder('" + folder + "',1)", 1);
if (file != "")
menuHTML += createContextMenuItem(lang_context_download, "window.location='?dl=" + file + "'", 1);
if (folder != "" || file != "") {
// Check if file is editable
if (file != "") {
var extension = file.substring(file.lastIndexOf('.') + 1);
if (editableExts.indexOf(extension) > -1)
menuHTML += createContextMenuItem(lang_context_edit, "actionFunctionEdit('" + file + "')", 1);
}
menuHTML += createContextMenuItem(lang_context_cut, "actionFunctionCut('" + file + "','" + folder + "')", 0);
menuHTML += createContextMenuItem(lang_context_copy, "actionFunctionCopy('" + file + "','" + folder + "')", 0);
menuHTML += createContextMenuItem(lang_context_paste, pasteOnclick, 0);
menuHTML += createContextMenuItem(lang_context_rename, "actionFunctionRename('" + file + "','" + folder + "')", 0);
menuHTML += createContextMenuItem(lang_context_delete, "actionFunctionDelete('" + file + "','" + folder + "')", isLin);
// Include "Chmod" if Linux
if (isLin == 1)
menuHTML += createContextMenuItem(lang_context_chmod, "actionFunctionChmod('" + file + "','" + folder + "')", 0);
} else {
menuHTML += createContextMenuItem(lang_context_cut, "", 0);
menuHTML += createContextMenuItem(lang_context_copy, "", 0);
menuHTML += createContextMenuItem(lang_context_paste, pasteOnclick, 0);
}
// Load the menu HTML into the menu DIV
document.getElementById("contextMenu").innerHTML = menuHTML;
// Position div to cursor
positionDivToCursor(e, "contextMenu");
}
function createContextMenuItem(label, onclick, divider) {
if (onclick == "")
var menuHTML = '<div class="contextMenuDivInactive" class="contextMenuInactive">' + label + '</div>';
else
var menuHTML = '<div class="contextMenuDiv" onclick="' + onclick + '" onmouseover="this.className=\'contextMenuDivMouseOver\';" onmouseout="this.className=\'contextMenuDiv\';">' + label + '</div>';
// Add horizontal divider
if (divider == 1) {
menuHTML += '<div class="contextMenuDivider"></div>';
globalContextHeight = parseInt(globalContextHeight) + 12;
}
// Set height of the menu
globalContextHeight = parseInt(globalContextHeight) + 29;
return menuHTML;
}
function actionFunctionEdit(file) {
var vars = '&ftpAction=edit&file=' + file;
processForm(vars);
}
function actionFunctionCut(file, folder) {
var vars = '&ftpAction=cut&folderSingle=' + folder + '&fileSingle=' + file;
// Check if a file or folder is set or 1+ checkboxes selected
if (file != '' || folder != '' || checkFilesSelected() == 1) {
processForm(vars);
setClipboard('cut');
activateActionButtons(0, 1);
}
}
function actionFunctionCopy(file, folder) {
var vars = '&ftpAction=copy&folderSingle=' + folder + '&fileSingle=' + file;
// Check if a file or folder is set or 1+ checkboxes selected
if (file != '' || folder != '' || checkFilesSelected() == 1) {
//alertCopyWarning();
processForm(vars);
setClipboard('copy');
activateActionButtons(0, 1);
}
}
function actionFunctionPaste(folder) {
var vars = '&ftpAction=paste';
// Check if a folder has been right-clicked on for paste
if (folder != "")
vars += '&rightClickFolder=' + folder;
processForm(vars);
activateActionButtons(0, 0);
// Reset clipboard action for cut
if (globalClipboardAction == "cut")
globalClipboardAction = "";
}
function actionFunctionRename(file, folder) {
var vars = '&ftpAction=rename&folderSingle=' + folder + '&fileSingle=' + file;
// Check if a file or folder is set or 1+ checkboxes selected
if (file != '' || folder != '' || checkFilesSelected() == 1) {
processForm(vars);
}
}
function actionFunctionDelete(file, folder) {
var vars = '&ftpAction=delete';
if (file != '' || folder != '')
vars += '&folderSingle=' + folder + '&fileSingle=' + file;
// Check if a file or folder is set or 1+ checkboxes selected
if (file != '' || folder != '' || checkFilesSelected() == 1) {
processForm(vars);
activateActionButtons(0, 0);
}
}
function actionFunctionChmod(file, folder) {
var vars = '&ftpAction=chmod&folderSingle=' + folder + '&fileSingle=' + file;
// Check if a file or folder is set or 1+ checkboxes selected
if (file != '' || folder != '' || checkFilesSelected() == 1) {
processForm(vars);
}
}
function actionFunctionLogout() {
document.location.href = '?logout=1'
}
function selectFile(theId, checkIE) {
if (checkIE == 0 || (checkIE == 1 && globalBrowser != "ie")) {
// Remove any existing borders
unselectFiles();
// Add border to item
document.getElementById(theId).style.border = '1px dotted gray';
document.getElementById(theId).style.marginLeft = '-1px';
document.getElementById(theId).style.marginRight = '-1px';
}
}
function unselectFolder(folder) {
var href = document.getElementById(folder);
href.style.border = '';
href.style.marginLeft = '0px';
href.style.marginRight = '0px';
}
function unselectFiles() {