Browse code

added appinfo/info.xml appinfo/signature.json CHANGELOG.txt README.md css/style.css js/sendfax.js

DoubleBastionAdmin authored on 11/01/2024 22:43:17
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,820 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: { userid: userid },
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: { userid: userid },
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: { userid: userid },
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+
107
+  // Upload files to be faxed
108
+  $("#uploadfileforfax").change(function(e){
109
+
110
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
+     $('#faxdocpreview').addClass('icon-loading');
112
+     $('#filestotsize').show();
113
+
114
+     var userid = "<?php p($userId); ?>";
115
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
+
117
+     var formData = new FormData();
118
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
+
120
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
+
122
+     var fileup = $('#uploadfileforfax').val();
123
+     var fileuptrim = fileup.split('\\').pop();
124
+
125
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
+         var duplicatescheck = 1;
127
+     } else var duplicatescheck = 0;
128
+
129
+     var extension = fileup.replace(/^.*\./, '');
130
+
131
+     if (extension == fileup) {
132
+         extension = "";
133
+     } else {
134
+         extension = extension.toLowerCase();
135
+     }
136
+
137
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
+
139
+     if ($.inArray(extension, validExtensions) != -1) {
140
+
141
+       if (duplicatescheck == 0) {
142
+
143
+         if (currentflsize < 20971520) {
144
+
145
+            if (n < 21) {
146
+
147
+               uploadedtofax.push(fileuptrim);
148
+
149
+               $.ajax({
150
+                 url: baseUrl + '/' + userid,
151
+                 type: "POST",
152
+                 data: formData,
153
+                 cache: false,
154
+                 processData: false,
155
+                 contentType: false,
156
+                 success: function(totalflsize) {
157
+
158
+                   $('#filessizetext').text(totalflsize);
159
+
160
+                   // Check if the total file size is over 20 MB
161
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
+
163
+                   if (rectotfilesz > 20.00) {
164
+                       $('#filestotsize').css('color', '#ba3555');
165
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
+                       $('#submitfax').attr("disabled", true);
167
+                   } else {
168
+                       $('#submitfax').attr("disabled", false);
169
+                       $('#filestotsize').css('color', '#1eb16a');
170
+                     }
171
+
172
+
173
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
+                   n++;
175
+
176
+                   // Preview the file when you click on its name
177
+                   $("div:visible[id*='indfilediv']").each(function() {
178
+                        $(this).on("click", function(eventclck) {
179
+                           var faxfilenameinit = $(this).text();
180
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
+                           var faxfilename = faxfilenamesec.replace("X","");
182
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
+                           var extenlst = faxfilename.replace(/^.*\./, '');
184
+
185
+                           if (extenlst == faxfilename) {
186
+                               extenlst = "";
187
+                           } else {
188
+                               extenlst = extenlst.toLowerCase();
189
+                           }
190
+
191
+                           if (extenlst == 'pdf') {
192
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
+                                  $("#faxdocpreview").empty();
195
+                                  $("#faxdocpreview").append($iframe);
196
+                           } else if (extenlst == 'txt') {
197
+                                  $("#faxdocpreview").empty();
198
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
+                           } else if (extenlst == 'html') {
200
+                                  $("#faxdocpreview").empty();
201
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
+                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
+                           } else if (extenlst == 'png') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
+                           } else if (extenlst == 'odt') {
211
+                                  $("#faxdocpreview").empty();
212
+                                  function odfInit() {
213
+                                     var odfelement = document.getElementById("faxdocpreview");
214
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
+                                     odfcanvas.load(baseUrl);
216
+                                  }
217
+                                  window.setTimeout(odfInit, 0);
218
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
+                                  var xhr = new XMLHttpRequest();
221
+                                  xhr.responseType = 'arraybuffer';
222
+                                  xhr.open('GET', tiffile);
223
+                                  xhr.onload = function (evnt) {
224
+                                      var tiff = new Tiff({buffer: xhr.response});
225
+                                      var tifcanvas = tiff.toCanvas();
226
+                                      $("#faxdocpreview").empty();
227
+                                      $("#faxdocpreview").append(tifcanvas);
228
+                                  };
229
+                                  xhr.send();
230
+                           }
231
+
232
+                           $("#faxdocpreview").show();
233
+                           $("#faxfoldersview").hide();
234
+                        });
235
+                   });
236
+
237
+                   // Remove uploaded files
238
+                   $('[class*="indupfldl"]').last().click(function() {
239
+
240
+                           var userid = "<?php p($userId); ?>";
241
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
+
243
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
+
245
+                           var removedfilesplit = removedfilenameinit.split(") ");
246
+                           var removedflnb = parseInt(removedfilesplit[0]);
247
+
248
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
+                           $(this).hide();
250
+
251
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
+
253
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
+                                           return value != removedfilename;
255
+                           });
256
+
257
+                           $.ajax({
258
+                                   url: baseUrl + '/' + userid,
259
+                                   type: "POST",
260
+                                   data: { removedfilename: removedfilename },
261
+                                   success: function(totalflsize) {
262
+
263
+                                      $('#filessizetext').text(totalflsize);
264
+
265
+                                      // Check file size
266
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
+
268
+                                      if (rectotfilesz > 20.00) {
269
+                                          $('#filestotsize').css('color', '#ba3555');
270
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
+                                          $('#submitfax').attr("disabled", true);
272
+                                      } else {
273
+                                          $('#submitfax').attr("disabled", false);
274
+                                          $('#filestotsize').css('color', '#1eb16a');
275
+                                        }
276
+
277
+                                      // Rewrite order numbers for files that follow
278
+                                      --n;
279
+                                      $("div:visible[id*='indfilediv']").each(function() {
280
+
281
+                                          var getdivtext =  $(this).text();
282
+                                          var splitdivtext = getdivtext.split(") ");
283
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
+                                          var newnbvalue = currentnbvalue - 1;
285
+
286
+                                          if (currentnbvalue > removedflnb) {
287
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
+                                              $(this).text(replacedstr);
289
+                                          }
290
+                                      });
291
+
292
+                                      $("div:visible[id*='indflpicked']").each(function() {
293
+
294
+                                          var getdivtext =  $(this).text();
295
+                                          var splitdivtext = getdivtext.split(") ");
296
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
+                                          var newnbvalue = currentnbvalue - 1;
298
+
299
+                                          if (currentnbvalue > removedflnb) {
300
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
+                                              $(this).text(replacedstr);
302
+                                          }
303
+                                      });
304
+
305
+                                   },
306
+                                   error: function() {
307
+                                          alert('Error !');
308
+                                   }
309
+                           });
310
+
311
+                           $('#faxdocpreview').removeClass('icon-loading');
312
+                           $("#faxdocpreview").empty();
313
+                   });
314
+
315
+                   // Preview the uploaded file
316
+                   var faxfilename = e.target.files[0].name;
317
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
+
319
+                   if (extension == 'pdf') {
320
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
+                              $("#faxdocpreview").empty();
323
+                              $("#faxdocpreview").append($iframe);
324
+                   } else if (extension == 'txt') {
325
+                              var reader = new FileReader();
326
+                              reader.readAsText(e.target.files[0]);
327
+                              reader.onload = function(e) {
328
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
+                                  $("#faxdocpreview").empty();
330
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
+                              };
332
+                   } else if (extension == 'html') {
333
+                              var reader = new FileReader();
334
+                              reader.readAsText(e.target.files[0]);
335
+                              reader.onload = function(e) {
336
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
+                                  $("#faxdocpreview").empty();
338
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
+                              };
340
+                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
+                              $("#faxdocpreview").empty();
342
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
+
344
+                              var reader = new FileReader();
345
+                              reader.onload = function (e) {
346
+                                  readjpg[faxfilename] = e.target.result;
347
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
+                              }
349
+                              reader.readAsDataURL(e.target.files[0]);
350
+                   } else if (extension == 'png') {
351
+                              $("#faxdocpreview").empty();
352
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
+
354
+                              var reader = new FileReader();
355
+                              reader.onload = function (e) {
356
+                                  readpng[faxfilename] = e.target.result;
357
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
+                              }
359
+                              reader.readAsDataURL(e.target.files[0]);
360
+                   } else if (extension == 'odt') {
361
+                              $("#faxdocpreview").empty();
362
+                              function odfInit() {
363
+                                 var odfelement = document.getElementById("faxdocpreview");
364
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
+                                 odfcanvas.load(baseUrl);
366
+                              }
367
+                              window.setTimeout(odfInit, 0);
368
+                   } else if (extension == 'tif' || extension == 'tiff') {
369
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
+                              var xhr = new XMLHttpRequest();
371
+                              xhr.responseType = 'arraybuffer';
372
+                              xhr.open('GET', tiffile);
373
+                              xhr.onload = function (e) {
374
+                                  var tiff = new Tiff({buffer: xhr.response});
375
+                                  var tifcanvas = tiff.toCanvas();
376
+                                  $("#faxdocpreview").empty();
377
+                                  $("#faxdocpreview").append(tifcanvas);
378
+                              };
379
+                              xhr.send();
380
+                   }
381
+
382
+                   $("#faxdocpreview").show();
383
+                   $('#pf_upload_msg').hide();
384
+                   $('#faxdocpreview').removeClass('icon-loading');
385
+                   $("#faxfoldersview").hide();
386
+                 },
387
+                 error: function(data){
388
+                     alert('Error!');
389
+                 }
390
+               });
391
+
392
+            } else {
393
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
+                  $('#pf_upload_msg').hide();
395
+                  $('#faxdocpreview').removeClass('icon-loading');
396
+              }
397
+         } else {
398
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
+              $('#pf_upload_msg').hide();
400
+              $('#faxdocpreview').removeClass('icon-loading');
401
+           }
402
+       } else {
403
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
+            $('#pf_upload_msg').hide();
405
+            $('#faxdocpreview').removeClass('icon-loading');
406
+         }
407
+
408
+     } else {
409
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
+          $('#pf_upload_msg').hide();
411
+          $('#faxdocpreview').removeClass('icon-loading');
412
+       }
413
+  });
414
+
415
+
416
+  // Pick file to fax, from Nextcloud
417
+  var faxfilename = null;
418
+
419
+  $("#choosefilen").on("click", function(evn) {
420
+
421
+                OC.dialogs.filepicker(
422
+                        t('settings', "Select a file to send as fax."),
423
+                        function (path) {
424
+
425
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
+                              $('#faxdocpreview').addClass('icon-loading');
427
+                              $('#filestotsize').show();
428
+
429
+                              var userid = "<?php p($userId); ?>";
430
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
+
432
+                              faxfilename = path.split('/').pop();
433
+
434
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
+                                  var duplicatescheck = 1;
436
+                              } else var duplicatescheck = 0;
437
+
438
+                              var extension = faxfilename.replace(/^.*\./, '');
439
+
440
+                              if (extension == faxfilename) {
441
+                                  extension = "";
442
+                              } else {
443
+                                  extension = extension.toLowerCase();
444
+                              }
445
+
446
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
+
448
+                              if ($.inArray(extension, validExtensions) != -1) {
449
+
450
+                                 if (duplicatescheck == 0) {
451
+
452
+                                    if (n < 21) {
453
+
454
+                                       uploadedtofax.push(faxfilename);
455
+
456
+                                       $.ajax({
457
+                                          url: baseUrl + '/' + userid,
458
+                                          type: "POST",
459
+                                          data: { path: path },
460
+                                          success: function(totalflsize) {
461
+
462
+                                                $('#filessizetext').text(totalflsize);
463
+
464
+                                                // Check if the total file size is over 20 MB
465
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
+
467
+                                                if (rectotfilesz > 20.00) {
468
+                                                    $('#filestotsize').css('color', '#ba3555');
469
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
+                                                    $('#submitfax').attr("disabled", true);
471
+                                                } else {
472
+                                                    $('#submitfax').attr("disabled", false);
473
+                                                    $('#filestotsize').css('color', '#1eb16a');
474
+                                                }
475
+
476
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
+                                                n++;
478
+
479
+                                                // Preview each file when you click on its name
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
+                                                      } else if (extenlst == 'png') {
509
+                                                              $("#faxdocpreview").empty();
510
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
511
+                                                      } else if (extenlst == 'odt') {
512
+                                                              $("#faxdocpreview").empty();
513
+                                                              function odfInit() {
514
+                                                                 var odfelement = document.getElementById("faxdocpreview");
515
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
516
+                                                                 odfcanvas.load(baseUrl);
517
+                                                              }
518
+                                                              window.setTimeout(odfInit, 0);
519
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
520
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
521
+                                                              var xhr = new XMLHttpRequest();
522
+                                                              xhr.responseType = 'arraybuffer';
523
+                                                              xhr.open('GET', tiffile);
524
+                                                              xhr.onload = function (evnt) {
525
+                                                                  var tiff = new Tiff({buffer: xhr.response});
526
+                                                                  var tifcanvas = tiff.toCanvas();
527
+                                                                  $("#faxdocpreview").empty();
528
+                                                                  $("#faxdocpreview").append(tifcanvas);
529
+                                                              };
530
+                                                              xhr.send();
531
+                                                      }
532
+
533
+                                                      $("#faxdocpreview").show();
534
+                                                      $("#faxfoldersview").hide();
535
+                                                   });
536
+                                                });
537
+
538
+                                                // Remove picked files
539
+                                                $('[class*="indpckfldl"]').last().click(function() {
540
+                                                    var userid = "<?php p($userId); ?>";
541
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
542
+
543
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
544
+
545
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
546
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
547
+
548
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
549
+                                                    $(this).hide();
550
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
551
+
552
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
553
+                                                             return value != removedfilename;
554
+                                                    });
555
+
556
+                                                    $.ajax({
557
+                                                        url: baseUrl + '/' + userid,
558
+                                                        type: "POST",
559
+                                                        data: { removedfilename: removedfilename },
560
+                                                        success: function(totalflsize) {
561
+
562
+                                                             $('#filessizetext').text(totalflsize);
563
+
564
+                                                             // Check file size
565
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
566
+
567
+                                                             if (rectotfilesz > 20.00) {
568
+                                                                 $('#filestotsize').css('color', '#ba3555');
569
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
570
+                                                                 $('#submitfax').attr("disabled", true);
571
+                                                             } else {
572
+                                                                 $('#submitfax').attr("disabled", false);
573
+                                                                 $('#filestotsize').css('color', '#1eb16a');
574
+                                                               }
575
+
576
+                                                             // Rewrite order numbers for files that follow
577
+                                                             --n;
578
+                                                             $("div:visible[id*='indflpicked']").each(function() {
579
+
580
+                                                                  var getdivtext =  $(this).text();
581
+                                                                  var splitdivtext = getdivtext.split(") ");
582
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
583
+                                                                  var newnbvalue = currentnbvalue - 1;
584
+
585
+                                                                  if (currentnbvalue > removedflnb) {
586
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
587
+                                                                      $(this).text(replacedstr);
588
+                                                                  }
589
+                                                             });
590
+                                                        },
591
+                                                        error: function() {
592
+                                                             alert('Error !');
593
+                                                        }
594
+                                                    });
595
+
596
+                                                    $('#faxdocpreview').removeClass('icon-loading');
597
+                                                    $("#faxdocpreview").empty();
598
+                                                });
599
+
600
+
601
+		                                // Preview the picked file
602
+		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
603
+		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
604
+
605
+		                                if (extension == 'pdf') {
606
+		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
607
+		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
608
+		                                    $("#faxdocpreview").empty();
609
+		                                    $("#faxdocpreview").append($iframe);
610
+		                                } else if (extension == 'txt') {
611
+						           $.get(flUrl, function(textdata) {
612
+		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
613
+		                                             $("#faxdocpreview").empty();
614
+		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
615
+							   });
616
+		                                } else if (extension == 'html') {
617
+							   $.get(flUrl, function(htmldata) {
618
+		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
+		                                             $("#faxdocpreview").empty();
620
+		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
621
+							   });
622
+		                                } else if (extension == 'jpg' || extension == 'jpeg') {
623
+		                                           $("#faxdocpreview").empty();
624
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
625
+		                                } else if (extension == 'png') {
626
+		                                           $("#faxdocpreview").empty();
627
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
628
+                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
629
+		                                } else if (extension == 'odt') {
630
+		                                       $("#faxdocpreview").empty();
631
+		                                       function odfInit() {
632
+		                                           var odfelement = document.getElementById("faxdocpreview");
633
+		                                           odfcanvas = new odf.OdfCanvas(odfelement);
634
+		                                           odfcanvas.load(flUrl);
635
+		                                       }
636
+		                                       window.setTimeout(odfInit, 0);
637
+
638
+		                                } else if (extension == 'tif' || extension == 'tiff') {
639
+		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
640
+		                                       var xhr = new XMLHttpRequest();
641
+		                                       xhr.responseType = 'arraybuffer';
642
+		                                       xhr.open('GET', tiffile);
643
+		                                       xhr.onload = function (event) {
644
+		                                           var tiff = new Tiff({buffer: xhr.response});
645
+		                                           var tifcanvas = tiff.toCanvas();
646
+		                                           $("#faxdocpreview").empty();
647
+		                                           $("#faxdocpreview").append(tifcanvas);
648
+		                                       };
649
+		                                       xhr.send();
650
+		                                }
651
+
652
+		                                $("#faxdocpreview").show();
653
+
654
+		                                $('#pf_choose_msg').hide();
655
+		                                $('#faxdocpreview').removeClass('icon-loading');
656
+		                                $("#faxfoldersview").hide();
657
+
658
+                                          },
659
+
660
+                                          error: function(data){
661
+                                             alert('Error!');
662
+                                          }
663
+
664
+                                       });
665
+
666
+                                    } else {
667
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
668
+                                        $('#pf_choose_msg').hide();
669
+                                        $('#faxdocpreview').removeClass('icon-loading');
670
+                                      }
671
+                                 } else {
672
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
673
+                                      $('#pf_choose_msg').hide();
674
+                                      $('#faxdocpreview').removeClass('icon-loading');
675
+                                   }
676
+
677
+                              } else {
678
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
679
+                                   $('#pf_choose_msg').hide();
680
+                                   $('#faxdocpreview').removeClass('icon-loading');
681
+                                }
682
+
683
+                        }
684
+                );
685
+  });
686
+
687
+
688
+  // Submit the fax
689
+  $("#submitfax").on("click", function(event){
690
+
691
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
692
+
693
+     var toNumberinit = $('#faxto').val();
694
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
695
+     var toNumber = toNumbersec.split(",");
696
+
697
+     for(var v = 0; v < toNumber.length; v++) {
698
+         toNumber[v] = "+" + toNumber[v];
699
+     }
700
+
701
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
702
+     $('#faxdocpreview').addClass('icon-loading');
703
+
704
+     $('#submitfax').attr("disabled", true);
705
+
706
+     var userid = "<?php p($userId); ?>";
707
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
708
+
709
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
710
+
711
+     if (uploadedtofax.length != 0) {
712
+
713
+         if (toNumberwc != '') {
714
+
715
+             $.ajax({
716
+                url: baseUrl + '/' + userid,
717
+                type: "POST",
718
+                data: {
719
+                       uploadedtofax: uploadedtofax,
720
+                       selectedcid: selectedcid,
721
+                       toNumber: toNumber
722
+                      },
723
+                success: function(phaxioresult) {
724
+
725
+                   if (phaxioresult.success == true) {
726
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
727
+                   } else {
728
+                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
729
+                   }
730
+
731
+                   $("div:visible[id*='indfilediv']").hide();
732
+                   $("div:visible[id*='indflpicked']").hide();
733
+                   $('[class*="indupfldl"]').hide();
734
+                   $('[class*="indpckfldl"]').hide();
735
+                   $('#faxdocpreview').hide();
736
+                   $('#filestotsize').hide();
737
+                   $('#pf_submit_msg').hide();
738
+                },
739
+                error: function(phaxioresult) {
740
+
741
+                   alert('Error ! Please check your settings !');
742
+
743
+                   $("div:visible[id*='indfilediv']").hide();
744
+                   $("div:visible[id*='indflpicked']").hide();
745
+                   $('[class*="indupfldl"]').hide();
746
+                   $('[class*="indpckfldl"]').hide();
747
+                   $('#pf_submit_msg').hide();
748
+                   $('#filestotsize').hide();
749
+                   $('#faxdocpreview').hide();
750
+
751
+                   location.reload(true);
752
+                }
753
+             });
754
+
755
+         } else {
756
+              $('#pf_submit_msg').hide();
757
+              $('#faxdocpreview').removeClass('icon-loading');
758
+              alert("Please enter the fax number of the recipient !");
759
+         }
760
+
761
+     } else {
762
+              $('#pf_submit_msg').hide();
763
+              $('#faxdocpreview').removeClass('icon-loading');
764
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
765
+     }
766
+  });
767
+
768
+  $("#receivedfaxdir").on("click", function(event){
769
+     $("#faxdocpreview").hide();
770
+     $("#faxfoldersview").show();
771
+     $("#faxfoldersview").addClass("icon-loading");
772
+     $("#faxfoldersview :last-child").remove();
773
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
774
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
775
+     $("#app-content").scrollTop(50);
776
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
777
+  });
778
+
779
+  $("#sentfaxdir").on("click", function(event){
780
+     $("#faxdocpreview").hide();
781
+     $("#faxfoldersview").show();
782
+     $("#faxfoldersview").addClass("icon-loading");
783
+     $("#faxfoldersview :last-child").remove();
784
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
785
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
786
+     $("#app-content").scrollTop(50);
787
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
788
+  });
789
+
790
+  $("#receivedfaileddir").on("click", function(event){
791
+     $("#faxdocpreview").hide();
792
+     $("#faxfoldersview").show();
793
+     $("#faxfoldersview").addClass("icon-loading");
794
+     $("#faxfoldersview :last-child").remove();
795
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
796
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
797
+     $("#app-content").scrollTop(50);
798
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
799
+  });
800
+
801
+  $("#sentfaileddir").on("click", function(event){
802
+     $("#faxdocpreview").hide();
803
+     $("#faxfoldersview").show();
804
+     $("#faxfoldersview").addClass("icon-loading");
805
+     $("#faxfoldersview :last-child").remove();
806
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
807
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
808
+     $("#app-content").scrollTop(50);
809
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
810
+  });
811
+
812
+  $(".indivflpckd").on("click", function(event){
813
+     $("#faxfoldersview").hide();
814
+  });
815
+
816
+  $(".indivflcls").on("click", function(event){
817
+     $("#faxfoldersview").hide();
818
+  });
819
+
820
+});
Browse code

removed appinfo/info.xml appinfo/signature.json CHANGELOG.txt README.md css/style.css js/sendfax.js img/pax_fax_screenshot.png

DoubleBastionAdmin authored on 11/01/2024 22:39:32
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,816 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
-  var locHref = window.location.href;
33
-  var pathSplit = locHref.split('/');
34
-  var firstPathEl = '';
35
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
-
37
-  // Check the available balance
38
-  $("#checkbalance").on("click", function(event) {
39
-
40
-     $('#checkbalance').addClass('icon-loading');
41
-
42
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
-
44
-     $.ajax({
45
-          url: getbalanceUrl + '/' + userid,
46
-          type: "POST",
47
-          data: { userid: userid },
48
-          cache: false,
49
-          processData: false,
50
-          contentType: false,
51
-          success: function(phaxiobalance) {
52
-                 var balanceindlrs = phaxiobalance / 100;
53
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
-                 $('#currentbalance').text(balanceproc);
55
-
56
-                 $('#checkbalance').removeClass('icon-loading');
57
-          }
58
-     });
59
-  });
60
-
61
-  // Select the Caller ID
62
-  $("#selectcalleridbttn").on("click", function(event) {
63
-
64
-     $('#selectcalleridbttn').addClass('icon-loading');
65
-
66
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
-     var selectednmbr = null;
68
-
69
-     $.ajax({
70
-          url: getfaxnumbersUrl + '/' + userid,
71
-          type: "POST",
72
-          data: { userid: userid },
73
-          cache: false,
74
-          processData: false,
75
-          contentType: false,
76
-          success: function(phaxionmbrs) {
77
-
78
-                    $('#currentfaxnmbrs').empty();
79
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
-
82
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
-                    });
85
-
86
-                    $('#selectcalleridbttn').removeClass('icon-loading');
87
-
88
-          }
89
-     });
90
-  });
91
-
92
-  // Clean the Pax_Fax/temp_files directory
93
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
-
95
-  $.ajax({
96
-          url: cleanflUrl + '/' + userid,
97
-          type: "POST",
98
-          data: { userid: userid },
99
-          cache: false,
100
-          processData: false,
101
-          contentType: false
102
-  });
103
-
104
-  var n = 1;
105
-  var uploadedtofax = [];
106
-
107
-  // Upload files to be faxed
108
-  $("#uploadfileforfax").change(function(e){
109
-
110
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
-     $('#faxdocpreview').addClass('icon-loading');
112
-     $('#filestotsize').show();
113
-
114
-     var userid = "<?php p($userId); ?>";
115
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
-
117
-     var formData = new FormData();
118
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
-
120
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
-
122
-     var fileup = $('#uploadfileforfax').val();
123
-     var fileuptrim = fileup.split('\\').pop();
124
-
125
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
-         var duplicatescheck = 1;
127
-     } else var duplicatescheck = 0;
128
-
129
-     var extension = fileup.replace(/^.*\./, '');
130
-
131
-     if (extension == fileup) {
132
-         extension = "";
133
-     } else {
134
-         extension = extension.toLowerCase();
135
-     }
136
-
137
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
-
139
-     if ($.inArray(extension, validExtensions) != -1) {
140
-
141
-       if (duplicatescheck == 0) {
142
-
143
-         if (currentflsize < 20971520) {
144
-
145
-            if (n < 21) {
146
-
147
-               uploadedtofax.push(fileuptrim);
148
-
149
-               $.ajax({
150
-                 url: baseUrl + '/' + userid,
151
-                 type: "POST",
152
-                 data: formData,
153
-                 cache: false,
154
-                 processData: false,
155
-                 contentType: false,
156
-                 success: function(totalflsize) {
157
-
158
-                   $('#filessizetext').text(totalflsize);
159
-
160
-                   // Check if the total file size is over 20 MB
161
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
-
163
-                   if (rectotfilesz > 20.00) {
164
-                       $('#filestotsize').css('color', '#ba3555');
165
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
-                       $('#submitfax').attr("disabled", true);
167
-                   } else {
168
-                       $('#submitfax').attr("disabled", false);
169
-                       $('#filestotsize').css('color', '#1eb16a');
170
-                     }
171
-
172
-
173
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
-                   n++;
175
-
176
-                   // Preview the file when you click on its name
177
-                   $("div:visible[id*='indfilediv']").each(function() {
178
-                        $(this).on("click", function(eventclck) {
179
-                           var faxfilenameinit = $(this).text();
180
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
-                           var faxfilename = faxfilenamesec.replace("X","");
182
-                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
-                           var extenlst = faxfilename.replace(/^.*\./, '');
184
-
185
-                           if (extenlst == faxfilename) {
186
-                               extenlst = "";
187
-                           } else {
188
-                               extenlst = extenlst.toLowerCase();
189
-                           }
190
-
191
-                           if (extenlst == 'pdf') {
192
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
-                                  $("#faxdocpreview").empty();
195
-                                  $("#faxdocpreview").append($iframe);
196
-                           } else if (extenlst == 'txt') {
197
-                                  $("#faxdocpreview").empty();
198
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
-                           } else if (extenlst == 'html') {
200
-                                  $("#faxdocpreview").empty();
201
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
-                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
-                                  $("#faxdocpreview").empty();
204
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
-                           } else if (extenlst == 'png') {
207
-                                  $("#faxdocpreview").empty();
208
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
-                           } else if (extenlst == 'odt') {
211
-                                  $("#faxdocpreview").empty();
212
-                                  function odfInit() {
213
-                                     var odfelement = document.getElementById("faxdocpreview");
214
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
-                                     odfcanvas.load(baseUrl);
216
-                                  }
217
-                                  window.setTimeout(odfInit, 0);
218
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
-                                  var xhr = new XMLHttpRequest();
221
-                                  xhr.responseType = 'arraybuffer';
222
-                                  xhr.open('GET', tiffile);
223
-                                  xhr.onload = function (evnt) {
224
-                                      var tiff = new Tiff({buffer: xhr.response});
225
-                                      var tifcanvas = tiff.toCanvas();
226
-                                      $("#faxdocpreview").empty();
227
-                                      $("#faxdocpreview").append(tifcanvas);
228
-                                  };
229
-                                  xhr.send();
230
-                           }
231
-
232
-                           $("#faxdocpreview").show();
233
-                           $("#faxfoldersview").hide();
234
-                        });
235
-                   });
236
-
237
-                   // Remove uploaded files
238
-                   $('[class*="indupfldl"]').last().click(function() {
239
-
240
-                           var userid = "<?php p($userId); ?>";
241
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
-
243
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
-
245
-                           var removedfilesplit = removedfilenameinit.split(") ");
246
-                           var removedflnb = parseInt(removedfilesplit[0]);
247
-
248
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
-                           $(this).hide();
250
-
251
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
-
253
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
-                                           return value != removedfilename;
255
-                           });
256
-
257
-                           $.ajax({
258
-                                   url: baseUrl + '/' + userid,
259
-                                   type: "POST",
260
-                                   data: { removedfilename: removedfilename },
261
-                                   success: function(totalflsize) {
262
-
263
-                                      $('#filessizetext').text(totalflsize);
264
-
265
-                                      // Check file size
266
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
-
268
-                                      if (rectotfilesz > 20.00) {
269
-                                          $('#filestotsize').css('color', '#ba3555');
270
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
-                                          $('#submitfax').attr("disabled", true);
272
-                                      } else {
273
-                                          $('#submitfax').attr("disabled", false);
274
-                                          $('#filestotsize').css('color', '#1eb16a');
275
-                                        }
276
-
277
-                                      // Rewrite order numbers for files that follow
278
-                                      --n;
279
-                                      $("div:visible[id*='indfilediv']").each(function() {
280
-
281
-                                          var getdivtext =  $(this).text();
282
-                                          var splitdivtext = getdivtext.split(") ");
283
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
-                                          var newnbvalue = currentnbvalue - 1;
285
-
286
-                                          if (currentnbvalue > removedflnb) {
287
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
-                                              $(this).text(replacedstr);
289
-                                          }
290
-                                      });
291
-
292
-                                      $("div:visible[id*='indflpicked']").each(function() {
293
-
294
-                                          var getdivtext =  $(this).text();
295
-                                          var splitdivtext = getdivtext.split(") ");
296
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
-                                          var newnbvalue = currentnbvalue - 1;
298
-
299
-                                          if (currentnbvalue > removedflnb) {
300
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
-                                              $(this).text(replacedstr);
302
-                                          }
303
-                                      });
304
-
305
-                                   },
306
-                                   error: function() {
307
-                                          alert('Error !');
308
-                                   }
309
-                           });
310
-
311
-                           $('#faxdocpreview').removeClass('icon-loading');
312
-                           $("#faxdocpreview").empty();
313
-                   });
314
-
315
-                   // Preview the uploaded file
316
-                   var faxfilename = e.target.files[0].name;
317
-                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
-
319
-                   if (extension == 'pdf') {
320
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
-                              $("#faxdocpreview").empty();
323
-                              $("#faxdocpreview").append($iframe);
324
-                   } else if (extension == 'txt') {
325
-                              var reader = new FileReader();
326
-                              reader.readAsText(e.target.files[0]);
327
-                              reader.onload = function(e) {
328
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
-                                  $("#faxdocpreview").empty();
330
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
-                              };
332
-                   } else if (extension == 'html') {
333
-                              var reader = new FileReader();
334
-                              reader.readAsText(e.target.files[0]);
335
-                              reader.onload = function(e) {
336
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
-                                  $("#faxdocpreview").empty();
338
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
-                              };
340
-                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
-                              $("#faxdocpreview").empty();
342
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
-
344
-                              var reader = new FileReader();
345
-                              reader.onload = function (e) {
346
-                                  readjpg[faxfilename] = e.target.result;
347
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
-                              }
349
-                              reader.readAsDataURL(e.target.files[0]);
350
-                   } else if (extension == 'png') {
351
-                              $("#faxdocpreview").empty();
352
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
-
354
-                              var reader = new FileReader();
355
-                              reader.onload = function (e) {
356
-                                  readpng[faxfilename] = e.target.result;
357
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
-                              }
359
-                              reader.readAsDataURL(e.target.files[0]);
360
-                   } else if (extension == 'odt') {
361
-                              $("#faxdocpreview").empty();
362
-                              function odfInit() {
363
-                                 var odfelement = document.getElementById("faxdocpreview");
364
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
-                                 odfcanvas.load(baseUrl);
366
-                              }
367
-                              window.setTimeout(odfInit, 0);
368
-                   } else if (extension == 'tif' || extension == 'tiff') {
369
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
-                              var xhr = new XMLHttpRequest();
371
-                              xhr.responseType = 'arraybuffer';
372
-                              xhr.open('GET', tiffile);
373
-                              xhr.onload = function (e) {
374
-                                  var tiff = new Tiff({buffer: xhr.response});
375
-                                  var tifcanvas = tiff.toCanvas();
376
-                                  $("#faxdocpreview").empty();
377
-                                  $("#faxdocpreview").append(tifcanvas);
378
-                              };
379
-                              xhr.send();
380
-                   }
381
-
382
-                   $("#faxdocpreview").show();
383
-                   $('#pf_upload_msg').hide();
384
-                   $('#faxdocpreview').removeClass('icon-loading');
385
-                   $("#faxfoldersview").hide();
386
-                 },
387
-                 error: function(data){
388
-                     alert('Error!');
389
-                 }
390
-               });
391
-
392
-            } else {
393
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
-                  $('#pf_upload_msg').hide();
395
-                  $('#faxdocpreview').removeClass('icon-loading');
396
-              }
397
-         } else {
398
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
-              $('#pf_upload_msg').hide();
400
-              $('#faxdocpreview').removeClass('icon-loading');
401
-           }
402
-       } else {
403
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
-            $('#pf_upload_msg').hide();
405
-            $('#faxdocpreview').removeClass('icon-loading');
406
-         }
407
-
408
-     } else {
409
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
-          $('#pf_upload_msg').hide();
411
-          $('#faxdocpreview').removeClass('icon-loading');
412
-       }
413
-  });
414
-
415
-
416
-  // Pick file to fax, from Nextcloud
417
-  var faxfilename = null;
418
-
419
-  $("#choosefilen").on("click", function(evn) {
420
-
421
-                OC.dialogs.filepicker(
422
-                        t('settings', "Select a file to send as fax."),
423
-                        function (path) {
424
-
425
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
-                              $('#faxdocpreview').addClass('icon-loading');
427
-                              $('#filestotsize').show();
428
-
429
-                              var userid = "<?php p($userId); ?>";
430
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
-
432
-                              faxfilename = path.split('/').pop();
433
-
434
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
-                                  var duplicatescheck = 1;
436
-                              } else var duplicatescheck = 0;
437
-
438
-                              var extension = faxfilename.replace(/^.*\./, '');
439
-
440
-                              if (extension == faxfilename) {
441
-                                  extension = "";
442
-                              } else {
443
-                                  extension = extension.toLowerCase();
444
-                              }
445
-
446
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
-
448
-                              if ($.inArray(extension, validExtensions) != -1) {
449
-
450
-                                 if (duplicatescheck == 0) {
451
-
452
-                                    if (n < 21) {
453
-
454
-                                       uploadedtofax.push(faxfilename);
455
-
456
-                                       $.ajax({
457
-                                          url: baseUrl + '/' + userid,
458
-                                          type: "POST",
459
-                                          data: { path: path },
460
-                                          success: function(totalflsize) {
461
-
462
-                                                $('#filessizetext').text(totalflsize);
463
-
464
-                                                // Check if the total file size is over 20 MB
465
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
-
467
-                                                if (rectotfilesz > 20.00) {
468
-                                                    $('#filestotsize').css('color', '#ba3555');
469
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
-                                                    $('#submitfax').attr("disabled", true);
471
-                                                } else {
472
-                                                    $('#submitfax').attr("disabled", false);
473
-                                                    $('#filestotsize').css('color', '#1eb16a');
474
-                                                }
475
-
476
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
-                                                n++;
478
-
479
-                                                // Preview each file when you click on its name
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
-                                                      } else if (extenlst == 'png') {
509
-                                                              $("#faxdocpreview").empty();
510
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
511
-                                                      } else if (extenlst == 'odt') {
512
-                                                              $("#faxdocpreview").empty();
513
-                                                              function odfInit() {
514
-                                                                 var odfelement = document.getElementById("faxdocpreview");
515
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
516
-                                                                 odfcanvas.load(baseUrl);
517
-                                                              }
518
-                                                              window.setTimeout(odfInit, 0);
519
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
520
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
521
-                                                              var xhr = new XMLHttpRequest();
522
-                                                              xhr.responseType = 'arraybuffer';
523
-                                                              xhr.open('GET', tiffile);
524
-                                                              xhr.onload = function (evnt) {
525
-                                                                  var tiff = new Tiff({buffer: xhr.response});
526
-                                                                  var tifcanvas = tiff.toCanvas();
527
-                                                                  $("#faxdocpreview").empty();
528
-                                                                  $("#faxdocpreview").append(tifcanvas);
529
-                                                              };
530
-                                                              xhr.send();
531
-                                                      }
532
-
533
-                                                      $("#faxdocpreview").show();
534
-                                                      $("#faxfoldersview").hide();
535
-                                                   });
536
-                                                });
537
-
538
-                                                // Remove picked files
539
-                                                $('[class*="indpckfldl"]').last().click(function() {
540
-                                                    var userid = "<?php p($userId); ?>";
541
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
542
-
543
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
544
-
545
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
546
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
547
-
548
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
549
-                                                    $(this).hide();
550
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
551
-
552
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
553
-                                                             return value != removedfilename;
554
-                                                    });
555
-
556
-                                                    $.ajax({
557
-                                                        url: baseUrl + '/' + userid,
558
-                                                        type: "POST",
559
-                                                        data: { removedfilename: removedfilename },
560
-                                                        success: function(totalflsize) {
561
-
562
-                                                             $('#filessizetext').text(totalflsize);
563
-
564
-                                                             // Check file size
565
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
566
-
567
-                                                             if (rectotfilesz > 20.00) {
568
-                                                                 $('#filestotsize').css('color', '#ba3555');
569
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
570
-                                                                 $('#submitfax').attr("disabled", true);
571
-                                                             } else {
572
-                                                                 $('#submitfax').attr("disabled", false);
573
-                                                                 $('#filestotsize').css('color', '#1eb16a');
574
-                                                               }
575
-
576
-                                                             // Rewrite order numbers for files that follow
577
-                                                             --n;
578
-                                                             $("div:visible[id*='indflpicked']").each(function() {
579
-
580
-                                                                  var getdivtext =  $(this).text();
581
-                                                                  var splitdivtext = getdivtext.split(") ");
582
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
583
-                                                                  var newnbvalue = currentnbvalue - 1;
584
-
585
-                                                                  if (currentnbvalue > removedflnb) {
586
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
587
-                                                                      $(this).text(replacedstr);
588
-                                                                  }
589
-                                                             });
590
-                                                        },
591
-                                                        error: function() {
592
-                                                             alert('Error !');
593
-                                                        }
594
-                                                    });
595
-
596
-                                                    $('#faxdocpreview').removeClass('icon-loading');
597
-                                                    $("#faxdocpreview").empty();
598
-                                                });
599
-
600
-
601
-		                                // Preview the picked file
602
-		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
603
-		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
604
-
605
-		                                if (extension == 'pdf') {
606
-		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
607
-		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
608
-		                                    $("#faxdocpreview").empty();
609
-		                                    $("#faxdocpreview").append($iframe);
610
-		                                } else if (extension == 'txt') {
611
-						           $.get(flUrl, function(textdata) {
612
-		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
613
-		                                             $("#faxdocpreview").empty();
614
-		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
615
-							   });
616
-		                                } else if (extension == 'html') {
617
-							   $.get(flUrl, function(htmldata) {
618
-		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
-		                                             $("#faxdocpreview").empty();
620
-		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
621
-							   });
622
-		                                } else if (extension == 'jpg' || extension == 'jpeg') {
623
-		                                           $("#faxdocpreview").empty();
624
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
625
-		                                } else if (extension == 'png') {
626
-		                                           $("#faxdocpreview").empty();
627
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
628
-                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
629
-		                                } else if (extension == 'odt') {
630
-		                                       $("#faxdocpreview").empty();
631
-		                                       function odfInit() {
632
-		                                           var odfelement = document.getElementById("faxdocpreview");
633
-		                                           odfcanvas = new odf.OdfCanvas(odfelement);
634
-		                                           odfcanvas.load(flUrl);
635
-		                                       }
636
-		                                       window.setTimeout(odfInit, 0);
637
-
638
-		                                } else if (extension == 'tif' || extension == 'tiff') {
639
-		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
640
-		                                       var xhr = new XMLHttpRequest();
641
-		                                       xhr.responseType = 'arraybuffer';
642
-		                                       xhr.open('GET', tiffile);
643
-		                                       xhr.onload = function (event) {
644
-		                                           var tiff = new Tiff({buffer: xhr.response});
645
-		                                           var tifcanvas = tiff.toCanvas();
646
-		                                           $("#faxdocpreview").empty();
647
-		                                           $("#faxdocpreview").append(tifcanvas);
648
-		                                       };
649
-		                                       xhr.send();
650
-		                                }
651
-
652
-		                                $("#faxdocpreview").show();
653
-
654
-		                                $('#pf_choose_msg').hide();
655
-		                                $('#faxdocpreview').removeClass('icon-loading');
656
-		                                $("#faxfoldersview").hide();
657
-
658
-                                          },
659
-
660
-                                          error: function(data){
661
-                                             alert('Error!');
662
-                                          }
663
-
664
-                                       });
665
-
666
-                                    } else {
667
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
668
-                                        $('#pf_choose_msg').hide();
669
-                                        $('#faxdocpreview').removeClass('icon-loading');
670
-                                      }
671
-                                 } else {
672
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
673
-                                      $('#pf_choose_msg').hide();
674
-                                      $('#faxdocpreview').removeClass('icon-loading');
675
-                                   }
676
-
677
-                              } else {
678
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
679
-                                   $('#pf_choose_msg').hide();
680
-                                   $('#faxdocpreview').removeClass('icon-loading');
681
-                                }
682
-
683
-                        }
684
-                );
685
-  });
686
-
687
-
688
-  // Submit the fax
689
-  $("#submitfax").on("click", function(event){
690
-
691
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
692
-
693
-     var toNumberinit = $('#faxto').val();
694
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
695
-     var toNumber = toNumbersec.split(",");
696
-
697
-     for(var v = 0; v < toNumber.length; v++) {
698
-         toNumber[v] = "+" + toNumber[v];
699
-     }
700
-
701
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
702
-     $('#faxdocpreview').addClass('icon-loading');
703
-
704
-     $('#submitfax').attr("disabled", true);
705
-
706
-     var userid = "<?php p($userId); ?>";
707
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
708
-
709
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
710
-
711
-     if (uploadedtofax.length != 0) {
712
-
713
-         if (toNumberwc != '') {
714
-
715
-             $.ajax({
716
-                url: baseUrl + '/' + userid,
717
-                type: "POST",
718
-                data: {
719
-                       uploadedtofax: uploadedtofax,
720
-                       selectedcid: selectedcid,
721
-                       toNumber: toNumber
722
-                      },
723
-                success: function(phaxioresult) {
724
-
725
-                   if (phaxioresult.success == true) {
726
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
727
-                   } else {
728
-                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
729
-                   }
730
-
731
-                   $("div:visible[id*='indfilediv']").hide();
732
-                   $("div:visible[id*='indflpicked']").hide();
733
-                   $('[class*="indupfldl"]').hide();
734
-                   $('[class*="indpckfldl"]').hide();
735
-                   $('#faxdocpreview').hide();
736
-                   $('#filestotsize').hide();
737
-                   $('#pf_submit_msg').hide();
738
-                },
739
-                error: function(phaxioresult) {
740
-
741
-                   alert('Error ! Please check your settings !');
742
-
743
-                   $("div:visible[id*='indfilediv']").hide();
744
-                   $("div:visible[id*='indflpicked']").hide();
745
-                   $('[class*="indupfldl"]').hide();
746
-                   $('[class*="indpckfldl"]').hide();
747
-                   $('#pf_submit_msg').hide();
748
-                   $('#filestotsize').hide();
749
-                   $('#faxdocpreview').hide();
750
-
751
-                   location.reload(true);
752
-                }
753
-             });
754
-
755
-         } else {
756
-              $('#pf_submit_msg').hide();
757
-              $('#faxdocpreview').removeClass('icon-loading');
758
-              alert("Please enter the fax number of the recipient !");
759
-         }
760
-
761
-     } else {
762
-              $('#pf_submit_msg').hide();
763
-              $('#faxdocpreview').removeClass('icon-loading');
764
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
765
-     }
766
-  });
767
-
768
-  $("#receivedfaxdir").on("click", function(event){
769
-     $("#faxdocpreview").hide();
770
-     $("#faxfoldersview").show();
771
-     $("#faxfoldersview").addClass("icon-loading");
772
-     $("#faxfoldersview :last-child").remove();
773
-     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
774
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
775
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
776
-  });
777
-
778
-  $("#sentfaxdir").on("click", function(event){
779
-     $("#faxdocpreview").hide();
780
-     $("#faxfoldersview").show();
781
-     $("#faxfoldersview").addClass("icon-loading");
782
-     $("#faxfoldersview :last-child").remove();
783
-     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
784
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
785
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
786
-  });
787
-
788
-  $("#receivedfaileddir").on("click", function(event){
789
-     $("#faxdocpreview").hide();
790
-     $("#faxfoldersview").show();
791
-     $("#faxfoldersview").addClass("icon-loading");
792
-     $("#faxfoldersview :last-child").remove();
793
-     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
794
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
795
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
796
-  });
797
-
798
-  $("#sentfaileddir").on("click", function(event){
799
-     $("#faxdocpreview").hide();
800
-     $("#faxfoldersview").show();
801
-     $("#faxfoldersview").addClass("icon-loading");
802
-     $("#faxfoldersview :last-child").remove();
803
-     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
804
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
805
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
806
-  });
807
-
808
-  $(".indivflpckd").on("click", function(event){
809
-     $("#faxfoldersview").hide();
810
-  });
811
-
812
-  $(".indivflcls").on("click", function(event){
813
-     $("#faxfoldersview").hide();
814
-  });
815
-
816
-});
Browse code

added fonts and made CSS changes for Nextcloud 28

DoubleBastionAdmin authored on 11/01/2024 04:45:38
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,816 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: { userid: userid },
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: { userid: userid },
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: { userid: userid },
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+
107
+  // Upload files to be faxed
108
+  $("#uploadfileforfax").change(function(e){
109
+
110
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
+     $('#faxdocpreview').addClass('icon-loading');
112
+     $('#filestotsize').show();
113
+
114
+     var userid = "<?php p($userId); ?>";
115
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
+
117
+     var formData = new FormData();
118
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
+
120
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
+
122
+     var fileup = $('#uploadfileforfax').val();
123
+     var fileuptrim = fileup.split('\\').pop();
124
+
125
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
+         var duplicatescheck = 1;
127
+     } else var duplicatescheck = 0;
128
+
129
+     var extension = fileup.replace(/^.*\./, '');
130
+
131
+     if (extension == fileup) {
132
+         extension = "";
133
+     } else {
134
+         extension = extension.toLowerCase();
135
+     }
136
+
137
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
+
139
+     if ($.inArray(extension, validExtensions) != -1) {
140
+
141
+       if (duplicatescheck == 0) {
142
+
143
+         if (currentflsize < 20971520) {
144
+
145
+            if (n < 21) {
146
+
147
+               uploadedtofax.push(fileuptrim);
148
+
149
+               $.ajax({
150
+                 url: baseUrl + '/' + userid,
151
+                 type: "POST",
152
+                 data: formData,
153
+                 cache: false,
154
+                 processData: false,
155
+                 contentType: false,
156
+                 success: function(totalflsize) {
157
+
158
+                   $('#filessizetext').text(totalflsize);
159
+
160
+                   // Check if the total file size is over 20 MB
161
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
+
163
+                   if (rectotfilesz > 20.00) {
164
+                       $('#filestotsize').css('color', '#ba3555');
165
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
+                       $('#submitfax').attr("disabled", true);
167
+                   } else {
168
+                       $('#submitfax').attr("disabled", false);
169
+                       $('#filestotsize').css('color', '#1eb16a');
170
+                     }
171
+
172
+
173
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
+                   n++;
175
+
176
+                   // Preview the file when you click on its name
177
+                   $("div:visible[id*='indfilediv']").each(function() {
178
+                        $(this).on("click", function(eventclck) {
179
+                           var faxfilenameinit = $(this).text();
180
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
+                           var faxfilename = faxfilenamesec.replace("X","");
182
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
+                           var extenlst = faxfilename.replace(/^.*\./, '');
184
+
185
+                           if (extenlst == faxfilename) {
186
+                               extenlst = "";
187
+                           } else {
188
+                               extenlst = extenlst.toLowerCase();
189
+                           }
190
+
191
+                           if (extenlst == 'pdf') {
192
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
+                                  $("#faxdocpreview").empty();
195
+                                  $("#faxdocpreview").append($iframe);
196
+                           } else if (extenlst == 'txt') {
197
+                                  $("#faxdocpreview").empty();
198
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
+                           } else if (extenlst == 'html') {
200
+                                  $("#faxdocpreview").empty();
201
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
+                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
+                           } else if (extenlst == 'png') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
+                           } else if (extenlst == 'odt') {
211
+                                  $("#faxdocpreview").empty();
212
+                                  function odfInit() {
213
+                                     var odfelement = document.getElementById("faxdocpreview");
214
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
+                                     odfcanvas.load(baseUrl);
216
+                                  }
217
+                                  window.setTimeout(odfInit, 0);
218
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
+                                  var xhr = new XMLHttpRequest();
221
+                                  xhr.responseType = 'arraybuffer';
222
+                                  xhr.open('GET', tiffile);
223
+                                  xhr.onload = function (evnt) {
224
+                                      var tiff = new Tiff({buffer: xhr.response});
225
+                                      var tifcanvas = tiff.toCanvas();
226
+                                      $("#faxdocpreview").empty();
227
+                                      $("#faxdocpreview").append(tifcanvas);
228
+                                  };
229
+                                  xhr.send();
230
+                           }
231
+
232
+                           $("#faxdocpreview").show();
233
+                           $("#faxfoldersview").hide();
234
+                        });
235
+                   });
236
+
237
+                   // Remove uploaded files
238
+                   $('[class*="indupfldl"]').last().click(function() {
239
+
240
+                           var userid = "<?php p($userId); ?>";
241
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
+
243
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
+
245
+                           var removedfilesplit = removedfilenameinit.split(") ");
246
+                           var removedflnb = parseInt(removedfilesplit[0]);
247
+
248
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
+                           $(this).hide();
250
+
251
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
+
253
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
+                                           return value != removedfilename;
255
+                           });
256
+
257
+                           $.ajax({
258
+                                   url: baseUrl + '/' + userid,
259
+                                   type: "POST",
260
+                                   data: { removedfilename: removedfilename },
261
+                                   success: function(totalflsize) {
262
+
263
+                                      $('#filessizetext').text(totalflsize);
264
+
265
+                                      // Check file size
266
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
+
268
+                                      if (rectotfilesz > 20.00) {
269
+                                          $('#filestotsize').css('color', '#ba3555');
270
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
+                                          $('#submitfax').attr("disabled", true);
272
+                                      } else {
273
+                                          $('#submitfax').attr("disabled", false);
274
+                                          $('#filestotsize').css('color', '#1eb16a');
275
+                                        }
276
+
277
+                                      // Rewrite order numbers for files that follow
278
+                                      --n;
279
+                                      $("div:visible[id*='indfilediv']").each(function() {
280
+
281
+                                          var getdivtext =  $(this).text();
282
+                                          var splitdivtext = getdivtext.split(") ");
283
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
+                                          var newnbvalue = currentnbvalue - 1;
285
+
286
+                                          if (currentnbvalue > removedflnb) {
287
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
+                                              $(this).text(replacedstr);
289
+                                          }
290
+                                      });
291
+
292
+                                      $("div:visible[id*='indflpicked']").each(function() {
293
+
294
+                                          var getdivtext =  $(this).text();
295
+                                          var splitdivtext = getdivtext.split(") ");
296
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
+                                          var newnbvalue = currentnbvalue - 1;
298
+
299
+                                          if (currentnbvalue > removedflnb) {
300
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
+                                              $(this).text(replacedstr);
302
+                                          }
303
+                                      });
304
+
305
+                                   },
306
+                                   error: function() {
307
+                                          alert('Error !');
308
+                                   }
309
+                           });
310
+
311
+                           $('#faxdocpreview').removeClass('icon-loading');
312
+                           $("#faxdocpreview").empty();
313
+                   });
314
+
315
+                   // Preview the uploaded file
316
+                   var faxfilename = e.target.files[0].name;
317
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
+
319
+                   if (extension == 'pdf') {
320
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
+                              $("#faxdocpreview").empty();
323
+                              $("#faxdocpreview").append($iframe);
324
+                   } else if (extension == 'txt') {
325
+                              var reader = new FileReader();
326
+                              reader.readAsText(e.target.files[0]);
327
+                              reader.onload = function(e) {
328
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
+                                  $("#faxdocpreview").empty();
330
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
+                              };
332
+                   } else if (extension == 'html') {
333
+                              var reader = new FileReader();
334
+                              reader.readAsText(e.target.files[0]);
335
+                              reader.onload = function(e) {
336
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
+                                  $("#faxdocpreview").empty();
338
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
+                              };
340
+                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
+                              $("#faxdocpreview").empty();
342
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
+
344
+                              var reader = new FileReader();
345
+                              reader.onload = function (e) {
346
+                                  readjpg[faxfilename] = e.target.result;
347
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
+                              }
349
+                              reader.readAsDataURL(e.target.files[0]);
350
+                   } else if (extension == 'png') {
351
+                              $("#faxdocpreview").empty();
352
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
+
354
+                              var reader = new FileReader();
355
+                              reader.onload = function (e) {
356
+                                  readpng[faxfilename] = e.target.result;
357
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
+                              }
359
+                              reader.readAsDataURL(e.target.files[0]);
360
+                   } else if (extension == 'odt') {
361
+                              $("#faxdocpreview").empty();
362
+                              function odfInit() {
363
+                                 var odfelement = document.getElementById("faxdocpreview");
364
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
+                                 odfcanvas.load(baseUrl);
366
+                              }
367
+                              window.setTimeout(odfInit, 0);
368
+                   } else if (extension == 'tif' || extension == 'tiff') {
369
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
+                              var xhr = new XMLHttpRequest();
371
+                              xhr.responseType = 'arraybuffer';
372
+                              xhr.open('GET', tiffile);
373
+                              xhr.onload = function (e) {
374
+                                  var tiff = new Tiff({buffer: xhr.response});
375
+                                  var tifcanvas = tiff.toCanvas();
376
+                                  $("#faxdocpreview").empty();
377
+                                  $("#faxdocpreview").append(tifcanvas);
378
+                              };
379
+                              xhr.send();
380
+                   }
381
+
382
+                   $("#faxdocpreview").show();
383
+                   $('#pf_upload_msg').hide();
384
+                   $('#faxdocpreview').removeClass('icon-loading');
385
+                   $("#faxfoldersview").hide();
386
+                 },
387
+                 error: function(data){
388
+                     alert('Error!');
389
+                 }
390
+               });
391
+
392
+            } else {
393
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
+                  $('#pf_upload_msg').hide();
395
+                  $('#faxdocpreview').removeClass('icon-loading');
396
+              }
397
+         } else {
398
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
+              $('#pf_upload_msg').hide();
400
+              $('#faxdocpreview').removeClass('icon-loading');
401
+           }
402
+       } else {
403
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
+            $('#pf_upload_msg').hide();
405
+            $('#faxdocpreview').removeClass('icon-loading');
406
+         }
407
+
408
+     } else {
409
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
+          $('#pf_upload_msg').hide();
411
+          $('#faxdocpreview').removeClass('icon-loading');
412
+       }
413
+  });
414
+
415
+
416
+  // Pick file to fax, from Nextcloud
417
+  var faxfilename = null;
418
+
419
+  $("#choosefilen").on("click", function(evn) {
420
+
421
+                OC.dialogs.filepicker(
422
+                        t('settings', "Select a file to send as fax."),
423
+                        function (path) {
424
+
425
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
+                              $('#faxdocpreview').addClass('icon-loading');
427
+                              $('#filestotsize').show();
428
+
429
+                              var userid = "<?php p($userId); ?>";
430
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
+
432
+                              faxfilename = path.split('/').pop();
433
+
434
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
+                                  var duplicatescheck = 1;
436
+                              } else var duplicatescheck = 0;
437
+
438
+                              var extension = faxfilename.replace(/^.*\./, '');
439
+
440
+                              if (extension == faxfilename) {
441
+                                  extension = "";
442
+                              } else {
443
+                                  extension = extension.toLowerCase();
444
+                              }
445
+
446
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
+
448
+                              if ($.inArray(extension, validExtensions) != -1) {
449
+
450
+                                 if (duplicatescheck == 0) {
451
+
452
+                                    if (n < 21) {
453
+
454
+                                       uploadedtofax.push(faxfilename);
455
+
456
+                                       $.ajax({
457
+                                          url: baseUrl + '/' + userid,
458
+                                          type: "POST",
459
+                                          data: { path: path },
460
+                                          success: function(totalflsize) {
461
+
462
+                                                $('#filessizetext').text(totalflsize);
463
+
464
+                                                // Check if the total file size is over 20 MB
465
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
+
467
+                                                if (rectotfilesz > 20.00) {
468
+                                                    $('#filestotsize').css('color', '#ba3555');
469
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
+                                                    $('#submitfax').attr("disabled", true);
471
+                                                } else {
472
+                                                    $('#submitfax').attr("disabled", false);
473
+                                                    $('#filestotsize').css('color', '#1eb16a');
474
+                                                }
475
+
476
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
+                                                n++;
478
+
479
+                                                // Preview each file when you click on its name
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
+                                                      } else if (extenlst == 'png') {
509
+                                                              $("#faxdocpreview").empty();
510
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
511
+                                                      } else if (extenlst == 'odt') {
512
+                                                              $("#faxdocpreview").empty();
513
+                                                              function odfInit() {
514
+                                                                 var odfelement = document.getElementById("faxdocpreview");
515
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
516
+                                                                 odfcanvas.load(baseUrl);
517
+                                                              }
518
+                                                              window.setTimeout(odfInit, 0);
519
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
520
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
521
+                                                              var xhr = new XMLHttpRequest();
522
+                                                              xhr.responseType = 'arraybuffer';
523
+                                                              xhr.open('GET', tiffile);
524
+                                                              xhr.onload = function (evnt) {
525
+                                                                  var tiff = new Tiff({buffer: xhr.response});
526
+                                                                  var tifcanvas = tiff.toCanvas();
527
+                                                                  $("#faxdocpreview").empty();
528
+                                                                  $("#faxdocpreview").append(tifcanvas);
529
+                                                              };
530
+                                                              xhr.send();
531
+                                                      }
532
+
533
+                                                      $("#faxdocpreview").show();
534
+                                                      $("#faxfoldersview").hide();
535
+                                                   });
536
+                                                });
537
+
538
+                                                // Remove picked files
539
+                                                $('[class*="indpckfldl"]').last().click(function() {
540
+                                                    var userid = "<?php p($userId); ?>";
541
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
542
+
543
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
544
+
545
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
546
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
547
+
548
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
549
+                                                    $(this).hide();
550
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
551
+
552
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
553
+                                                             return value != removedfilename;
554
+                                                    });
555
+
556
+                                                    $.ajax({
557
+                                                        url: baseUrl + '/' + userid,
558
+                                                        type: "POST",
559
+                                                        data: { removedfilename: removedfilename },
560
+                                                        success: function(totalflsize) {
561
+
562
+                                                             $('#filessizetext').text(totalflsize);
563
+
564
+                                                             // Check file size
565
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
566
+
567
+                                                             if (rectotfilesz > 20.00) {
568
+                                                                 $('#filestotsize').css('color', '#ba3555');
569
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
570
+                                                                 $('#submitfax').attr("disabled", true);
571
+                                                             } else {
572
+                                                                 $('#submitfax').attr("disabled", false);
573
+                                                                 $('#filestotsize').css('color', '#1eb16a');
574
+                                                               }
575
+
576
+                                                             // Rewrite order numbers for files that follow
577
+                                                             --n;
578
+                                                             $("div:visible[id*='indflpicked']").each(function() {
579
+
580
+                                                                  var getdivtext =  $(this).text();
581
+                                                                  var splitdivtext = getdivtext.split(") ");
582
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
583
+                                                                  var newnbvalue = currentnbvalue - 1;
584
+
585
+                                                                  if (currentnbvalue > removedflnb) {
586
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
587
+                                                                      $(this).text(replacedstr);
588
+                                                                  }
589
+                                                             });
590
+                                                        },
591
+                                                        error: function() {
592
+                                                             alert('Error !');
593
+                                                        }
594
+                                                    });
595
+
596
+                                                    $('#faxdocpreview').removeClass('icon-loading');
597
+                                                    $("#faxdocpreview").empty();
598
+                                                });
599
+
600
+
601
+		                                // Preview the picked file
602
+		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
603
+		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
604
+
605
+		                                if (extension == 'pdf') {
606
+		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
607
+		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
608
+		                                    $("#faxdocpreview").empty();
609
+		                                    $("#faxdocpreview").append($iframe);
610
+		                                } else if (extension == 'txt') {
611
+						           $.get(flUrl, function(textdata) {
612
+		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
613
+		                                             $("#faxdocpreview").empty();
614
+		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
615
+							   });
616
+		                                } else if (extension == 'html') {
617
+							   $.get(flUrl, function(htmldata) {
618
+		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
+		                                             $("#faxdocpreview").empty();
620
+		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
621
+							   });
622
+		                                } else if (extension == 'jpg' || extension == 'jpeg') {
623
+		                                           $("#faxdocpreview").empty();
624
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
625
+		                                } else if (extension == 'png') {
626
+		                                           $("#faxdocpreview").empty();
627
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
628
+                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
629
+		                                } else if (extension == 'odt') {
630
+		                                       $("#faxdocpreview").empty();
631
+		                                       function odfInit() {
632
+		                                           var odfelement = document.getElementById("faxdocpreview");
633
+		                                           odfcanvas = new odf.OdfCanvas(odfelement);
634
+		                                           odfcanvas.load(flUrl);
635
+		                                       }
636
+		                                       window.setTimeout(odfInit, 0);
637
+
638
+		                                } else if (extension == 'tif' || extension == 'tiff') {
639
+		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
640
+		                                       var xhr = new XMLHttpRequest();
641
+		                                       xhr.responseType = 'arraybuffer';
642
+		                                       xhr.open('GET', tiffile);
643
+		                                       xhr.onload = function (event) {
644
+		                                           var tiff = new Tiff({buffer: xhr.response});
645
+		                                           var tifcanvas = tiff.toCanvas();
646
+		                                           $("#faxdocpreview").empty();
647
+		                                           $("#faxdocpreview").append(tifcanvas);
648
+		                                       };
649
+		                                       xhr.send();
650
+		                                }
651
+
652
+		                                $("#faxdocpreview").show();
653
+
654
+		                                $('#pf_choose_msg').hide();
655
+		                                $('#faxdocpreview').removeClass('icon-loading');
656
+		                                $("#faxfoldersview").hide();
657
+
658
+                                          },
659
+
660
+                                          error: function(data){
661
+                                             alert('Error!');
662
+                                          }
663
+
664
+                                       });
665
+
666
+                                    } else {
667
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
668
+                                        $('#pf_choose_msg').hide();
669
+                                        $('#faxdocpreview').removeClass('icon-loading');
670
+                                      }
671
+                                 } else {
672
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
673
+                                      $('#pf_choose_msg').hide();
674
+                                      $('#faxdocpreview').removeClass('icon-loading');
675
+                                   }
676
+
677
+                              } else {
678
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
679
+                                   $('#pf_choose_msg').hide();
680
+                                   $('#faxdocpreview').removeClass('icon-loading');
681
+                                }
682
+
683
+                        }
684
+                );
685
+  });
686
+
687
+
688
+  // Submit the fax
689
+  $("#submitfax").on("click", function(event){
690
+
691
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
692
+
693
+     var toNumberinit = $('#faxto').val();
694
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
695
+     var toNumber = toNumbersec.split(",");
696
+
697
+     for(var v = 0; v < toNumber.length; v++) {
698
+         toNumber[v] = "+" + toNumber[v];
699
+     }
700
+
701
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
702
+     $('#faxdocpreview').addClass('icon-loading');
703
+
704
+     $('#submitfax').attr("disabled", true);
705
+
706
+     var userid = "<?php p($userId); ?>";
707
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
708
+
709
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
710
+
711
+     if (uploadedtofax.length != 0) {
712
+
713
+         if (toNumberwc != '') {
714
+
715
+             $.ajax({
716
+                url: baseUrl + '/' + userid,
717
+                type: "POST",
718
+                data: {
719
+                       uploadedtofax: uploadedtofax,
720
+                       selectedcid: selectedcid,
721
+                       toNumber: toNumber
722
+                      },
723
+                success: function(phaxioresult) {
724
+
725
+                   if (phaxioresult.success == true) {
726
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
727
+                   } else {
728
+                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
729
+                   }
730
+
731
+                   $("div:visible[id*='indfilediv']").hide();
732
+                   $("div:visible[id*='indflpicked']").hide();
733
+                   $('[class*="indupfldl"]').hide();
734
+                   $('[class*="indpckfldl"]').hide();
735
+                   $('#faxdocpreview').hide();
736
+                   $('#filestotsize').hide();
737
+                   $('#pf_submit_msg').hide();
738
+                },
739
+                error: function(phaxioresult) {
740
+
741
+                   alert('Error ! Please check your settings !');
742
+
743
+                   $("div:visible[id*='indfilediv']").hide();
744
+                   $("div:visible[id*='indflpicked']").hide();
745
+                   $('[class*="indupfldl"]').hide();
746
+                   $('[class*="indpckfldl"]').hide();
747
+                   $('#pf_submit_msg').hide();
748
+                   $('#filestotsize').hide();
749
+                   $('#faxdocpreview').hide();
750
+
751
+                   location.reload(true);
752
+                }
753
+             });
754
+
755
+         } else {
756
+              $('#pf_submit_msg').hide();
757
+              $('#faxdocpreview').removeClass('icon-loading');
758
+              alert("Please enter the fax number of the recipient !");
759
+         }
760
+
761
+     } else {
762
+              $('#pf_submit_msg').hide();
763
+              $('#faxdocpreview').removeClass('icon-loading');
764
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
765
+     }
766
+  });
767
+
768
+  $("#receivedfaxdir").on("click", function(event){
769
+     $("#faxdocpreview").hide();
770
+     $("#faxfoldersview").show();
771
+     $("#faxfoldersview").addClass("icon-loading");
772
+     $("#faxfoldersview :last-child").remove();
773
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
774
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
775
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
776
+  });
777
+
778
+  $("#sentfaxdir").on("click", function(event){
779
+     $("#faxdocpreview").hide();
780
+     $("#faxfoldersview").show();
781
+     $("#faxfoldersview").addClass("icon-loading");
782
+     $("#faxfoldersview :last-child").remove();
783
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
784
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
785
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
786
+  });
787
+
788
+  $("#receivedfaileddir").on("click", function(event){
789
+     $("#faxdocpreview").hide();
790
+     $("#faxfoldersview").show();
791
+     $("#faxfoldersview").addClass("icon-loading");
792
+     $("#faxfoldersview :last-child").remove();
793
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
794
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
795
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
796
+  });
797
+
798
+  $("#sentfaileddir").on("click", function(event){
799
+     $("#faxdocpreview").hide();
800
+     $("#faxfoldersview").show();
801
+     $("#faxfoldersview").addClass("icon-loading");
802
+     $("#faxfoldersview :last-child").remove();
803
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
804
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
805
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
806
+  });
807
+
808
+  $(".indivflpckd").on("click", function(event){
809
+     $("#faxfoldersview").hide();
810
+  });
811
+
812
+  $(".indivflcls").on("click", function(event){
813
+     $("#faxfoldersview").hide();
814
+  });
815
+
816
+});
Browse code

removed appinfo/info.xml appinfo/signature.json CHANGELOG.txt css/style.css js/sendfax.js templates/settings.php

DoubleBastionAdmin authored on 11/01/2024 04:39:02
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,818 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
-  var locHref = window.location.href;
33
-  var pathSplit = locHref.split('/');
34
-  var firstPathEl = '';
35
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
-
37
-  // Check the available balance
38
-  $("#checkbalance").on("click", function(event) {
39
-
40
-     $('#checkbalance').addClass('icon-loading');
41
-
42
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
-
44
-     $.ajax({
45
-          url: getbalanceUrl + '/' + userid,
46
-          type: "POST",
47
-          data: { userid: userid },
48
-          cache: false,
49
-          processData: false,
50
-          contentType: false,
51
-          success: function(phaxiobalance) {
52
-                 var balanceindlrs = phaxiobalance / 100;
53
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
-                 $('#currentbalance').text(balanceproc);
55
-
56
-                 $('#checkbalance').removeClass('icon-loading');
57
-          }
58
-     });
59
-  });
60
-
61
-  // Select the Caller ID
62
-  $("#selectcalleridbttn").on("click", function(event) {
63
-
64
-     $('#selectcalleridbttn').addClass('icon-loading');
65
-
66
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
-     var selectednmbr = null;
68
-
69
-     $.ajax({
70
-          url: getfaxnumbersUrl + '/' + userid,
71
-          type: "POST",
72
-          data: { userid: userid },
73
-          cache: false,
74
-          processData: false,
75
-          contentType: false,
76
-          success: function(phaxionmbrs) {
77
-
78
-                    $('#currentfaxnmbrs').empty();
79
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
-
82
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
-                    });
85
-
86
-                    $('#selectcalleridbttn').removeClass('icon-loading');
87
-
88
-          }
89
-     });
90
-  });
91
-
92
-  // Clean the Pax_Fax/temp_files directory
93
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
-
95
-  $.ajax({
96
-          url: cleanflUrl + '/' + userid,
97
-          type: "POST",
98
-          data: { userid: userid },
99
-          cache: false,
100
-          processData: false,
101
-          contentType: false
102
-  });
103
-
104
-  var n = 1;
105
-  var uploadedtofax = [];
106
-
107
-  // Upload files to be faxed
108
-  $("#uploadfileforfax").change(function(e){
109
-
110
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
-     $('#faxdocpreview').addClass('icon-loading');
112
-     $('#filestotsize').show();
113
-
114
-     var userid = "<?php p($userId); ?>";
115
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
-
117
-     var formData = new FormData();
118
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
-
120
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
-
122
-     var fileup = $('#uploadfileforfax').val();
123
-     var fileuptrim = fileup.split('\\').pop();
124
-
125
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
-         var duplicatescheck = 1;
127
-     } else var duplicatescheck = 0;
128
-
129
-     var extension = fileup.replace(/^.*\./, '');
130
-
131
-     if (extension == fileup) {
132
-         extension = "";
133
-     } else {
134
-         extension = extension.toLowerCase();
135
-     }
136
-
137
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
-
139
-     if ($.inArray(extension, validExtensions) != -1) {
140
-
141
-       if (duplicatescheck == 0) {
142
-
143
-         if (currentflsize < 20971520) {
144
-
145
-            if (n < 21) {
146
-
147
-               uploadedtofax.push(fileuptrim);
148
-
149
-               $.ajax({
150
-                 url: baseUrl + '/' + userid,
151
-                 type: "POST",
152
-                 data: formData,
153
-                 cache: false,
154
-                 processData: false,
155
-                 contentType: false,
156
-                 success: function(totalflsize) {
157
-
158
-                   $('#filessizetext').text(totalflsize);
159
-
160
-                   // Check if the total file size is over 20 MB
161
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
-
163
-                   if (rectotfilesz > 20.00) {
164
-                       $('#filestotsize').css('color', '#ba3555');
165
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
-                       $('#submitfax').attr("disabled", true);
167
-                   } else {
168
-                       $('#submitfax').attr("disabled", false);
169
-                       $('#filestotsize').css('color', '#1eb16a');
170
-                     }
171
-
172
-
173
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
-                   n++;
175
-
176
-                   // Preview the file when you click on its name
177
-                   $("div:visible[id*='indfilediv']").each(function() {
178
-                        $(this).on("click", function(eventclck) {
179
-                           var faxfilenameinit = $(this).text();
180
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
-                           var faxfilename = faxfilenamesec.replace("X","");
182
-                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
-                           var extenlst = faxfilename.replace(/^.*\./, '');
184
-
185
-                           if (extenlst == faxfilename) {
186
-                               extenlst = "";
187
-                           } else {
188
-                               extenlst = extenlst.toLowerCase();
189
-                           }
190
-
191
-                           if (extenlst == 'pdf') {
192
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
-                                  $("#faxdocpreview").empty();
195
-                                  $("#faxdocpreview").append($iframe);
196
-                           } else if (extenlst == 'txt') {
197
-                                  $("#faxdocpreview").empty();
198
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
-                           } else if (extenlst == 'html') {
200
-                                  $("#faxdocpreview").empty();
201
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
-                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
-                                  $("#faxdocpreview").empty();
204
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
-                           } else if (extenlst == 'png') {
207
-                                  $("#faxdocpreview").empty();
208
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
-                           } else if (extenlst == 'odt') {
211
-                                  $("#faxdocpreview").empty();
212
-                                  function odfInit() {
213
-                                     var odfelement = document.getElementById("faxdocpreview");
214
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
-                                     odfcanvas.load(baseUrl);
216
-                                  }
217
-                                  window.setTimeout(odfInit, 0);
218
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
-                                  var xhr = new XMLHttpRequest();
221
-                                  xhr.responseType = 'arraybuffer';
222
-                                  xhr.open('GET', tiffile);
223
-                                  xhr.onload = function (evnt) {
224
-                                      var tiff = new Tiff({buffer: xhr.response});
225
-                                      var tifcanvas = tiff.toCanvas();
226
-                                      $("#faxdocpreview").empty();
227
-                                      $("#faxdocpreview").append(tifcanvas);
228
-                                  };
229
-                                  xhr.send();
230
-                           }
231
-
232
-                           $("#faxdocpreview").show();
233
-                           $("#faxfoldersview").hide();
234
-                        });
235
-                   });
236
-
237
-                   // Remove uploaded files
238
-                   $('[class*="indupfldl"]').last().click(function() {
239
-
240
-                           var userid = "<?php p($userId); ?>";
241
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
-
243
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
-
245
-                           var removedfilesplit = removedfilenameinit.split(") ");
246
-                           var removedflnb = parseInt(removedfilesplit[0]);
247
-
248
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
-                           $(this).hide();
250
-
251
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
-
253
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
-                                           return value != removedfilename;
255
-                           });
256
-
257
-                           $.ajax({
258
-                                   url: baseUrl + '/' + userid,
259
-                                   type: "POST",
260
-                                   data: { removedfilename: removedfilename },
261
-                                   success: function(totalflsize) {
262
-
263
-                                      $('#filessizetext').text(totalflsize);
264
-
265
-                                      // Check file size
266
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
-
268
-                                      if (rectotfilesz > 20.00) {
269
-                                          $('#filestotsize').css('color', '#ba3555');
270
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
-                                          $('#submitfax').attr("disabled", true);
272
-                                      } else {
273
-                                          $('#submitfax').attr("disabled", false);
274
-                                          $('#filestotsize').css('color', '#1eb16a');
275
-                                        }
276
-
277
-                                      // Rewrite order numbers for files that follow
278
-                                      --n;
279
-                                      $("div:visible[id*='indfilediv']").each(function() {
280
-
281
-                                          var getdivtext =  $(this).text();
282
-                                          var splitdivtext = getdivtext.split(") ");
283
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
-                                          var newnbvalue = currentnbvalue - 1;
285
-
286
-                                          if (currentnbvalue > removedflnb) {
287
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
-                                              $(this).text(replacedstr);
289
-                                          }
290
-                                      });
291
-
292
-                                      $("div:visible[id*='indflpicked']").each(function() {
293
-
294
-                                          var getdivtext =  $(this).text();
295
-                                          var splitdivtext = getdivtext.split(") ");
296
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
-                                          var newnbvalue = currentnbvalue - 1;
298
-
299
-                                          if (currentnbvalue > removedflnb) {
300
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
-                                              $(this).text(replacedstr);
302
-                                          }
303
-                                      });
304
-
305
-                                   },
306
-                                   error: function() {
307
-                                          alert('Error !');
308
-                                   }
309
-                           });
310
-
311
-                           $('#faxdocpreview').removeClass('icon-loading');
312
-                           $("#faxdocpreview").empty();
313
-                   });
314
-
315
-                   // Preview the uploaded file
316
-                   var faxfilename = e.target.files[0].name;
317
-                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
-
319
-                   if (extension == 'pdf') {
320
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
-                              $("#faxdocpreview").empty();
323
-                              $("#faxdocpreview").append($iframe);
324
-                   } else if (extension == 'txt') {
325
-                              var reader = new FileReader();
326
-                              reader.readAsText(e.target.files[0]);
327
-                              reader.onload = function(e) {
328
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
-                                  $("#faxdocpreview").empty();
330
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
-                              };
332
-                   } else if (extension == 'html') {
333
-                              var reader = new FileReader();
334
-                              reader.readAsText(e.target.files[0]);
335
-                              reader.onload = function(e) {
336
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
-                                  $("#faxdocpreview").empty();
338
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
-                              };
340
-                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
-                              $("#faxdocpreview").empty();
342
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
-
344
-                              var reader = new FileReader();
345
-                              reader.onload = function (e) {
346
-                                  readjpg[faxfilename] = e.target.result;
347
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
-                              }
349
-                              reader.readAsDataURL(e.target.files[0]);
350
-                   } else if (extension == 'png') {
351
-                              $("#faxdocpreview").empty();
352
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
-
354
-                              var reader = new FileReader();
355
-                              reader.onload = function (e) {
356
-                                  readpng[faxfilename] = e.target.result;
357
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
-                              }
359
-                              reader.readAsDataURL(e.target.files[0]);
360
-                   } else if (extension == 'odt') {
361
-                              $("#faxdocpreview").empty();
362
-                              function odfInit() {
363
-                                 var odfelement = document.getElementById("faxdocpreview");
364
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
-                                 odfcanvas.load(baseUrl);
366
-                              }
367
-                              window.setTimeout(odfInit, 0);
368
-                   } else if (extension == 'tif' || extension == 'tiff') {
369
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
-                              var xhr = new XMLHttpRequest();
371
-                              xhr.responseType = 'arraybuffer';
372
-                              xhr.open('GET', tiffile);
373
-                              xhr.onload = function (e) {
374
-                                  var tiff = new Tiff({buffer: xhr.response});
375
-                                  var tifcanvas = tiff.toCanvas();
376
-                                  $("#faxdocpreview").empty();
377
-                                  $("#faxdocpreview").append(tifcanvas);
378
-                              };
379
-                              xhr.send();
380
-                   }
381
-
382
-                   $("#faxdocpreview").show();
383
-                   $('#pf_upload_msg').hide();
384
-                   $('#faxdocpreview').removeClass('icon-loading');
385
-                   $("#faxfoldersview").hide();
386
-                 },
387
-                 error: function(data){
388
-                     alert('Error!');
389
-                 }
390
-               });
391
-
392
-            } else {
393
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
-                  $('#pf_upload_msg').hide();
395
-                  $('#faxdocpreview').removeClass('icon-loading');
396
-              }
397
-         } else {
398
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
-              $('#pf_upload_msg').hide();
400
-              $('#faxdocpreview').removeClass('icon-loading');
401
-           }
402
-       } else {
403
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
-            $('#pf_upload_msg').hide();
405
-            $('#faxdocpreview').removeClass('icon-loading');
406
-         }
407
-
408
-     } else {
409
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
-          $('#pf_upload_msg').hide();
411
-          $('#faxdocpreview').removeClass('icon-loading');
412
-       }
413
-  });
414
-
415
-
416
-  // Pick file to fax, from Nextcloud
417
-  var faxfilename = null;
418
-
419
-  $("#choosefilen").on("click", function(evn) {
420
-
421
-                OC.dialogs.filepicker(
422
-                        t('settings', "Select a file to send as fax."),
423
-                        function (path) {
424
-
425
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
-                              $('#faxdocpreview').addClass('icon-loading');
427
-                              $('#filestotsize').show();
428
-
429
-                              var userid = "<?php p($userId); ?>";
430
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
-
432
-                              faxfilename = path.split('/').pop();
433
-
434
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
-                                  var duplicatescheck = 1;
436
-                              } else var duplicatescheck = 0;
437
-
438
-                              var extension = faxfilename.replace(/^.*\./, '');
439
-
440
-                              if (extension == faxfilename) {
441
-                                  extension = "";
442
-                              } else {
443
-                                  extension = extension.toLowerCase();
444
-                              }
445
-
446
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
-
448
-                              if ($.inArray(extension, validExtensions) != -1) {
449
-
450
-                                 if (duplicatescheck == 0) {
451
-
452
-                                    if (n < 21) {
453
-
454
-                                       uploadedtofax.push(faxfilename);
455
-
456
-                                       $.ajax({
457
-                                          url: baseUrl + '/' + userid,
458
-                                          type: "POST",
459
-                                          data: { path: path },
460
-                                          success: function(totalflsize) {
461
-
462
-                                                $('#filessizetext').text(totalflsize);
463
-
464
-                                                // Check if the total file size is over 20 MB
465
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
-
467
-                                                if (rectotfilesz > 20.00) {
468
-                                                    $('#filestotsize').css('color', '#ba3555');
469
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
-                                                    $('#submitfax').attr("disabled", true);
471
-                                                } else {
472
-                                                    $('#submitfax').attr("disabled", false);
473
-                                                    $('#filestotsize').css('color', '#1eb16a');
474
-                                                }
475
-
476
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
-                                                n++;
478
-
479
-                                                // Preview each file when you click on its name
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
-//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
-                                                      } else if (extenlst == 'png') {
510
-                                                              $("#faxdocpreview").empty();
511
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
-//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
-                                                      } else if (extenlst == 'odt') {
514
-                                                              $("#faxdocpreview").empty();
515
-                                                              function odfInit() {
516
-                                                                 var odfelement = document.getElementById("faxdocpreview");
517
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
-                                                                 odfcanvas.load(baseUrl);
519
-                                                              }
520
-                                                              window.setTimeout(odfInit, 0);
521
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
-                                                              var xhr = new XMLHttpRequest();
524
-                                                              xhr.responseType = 'arraybuffer';
525
-                                                              xhr.open('GET', tiffile);
526
-                                                              xhr.onload = function (evnt) {
527
-                                                                  var tiff = new Tiff({buffer: xhr.response});
528
-                                                                  var tifcanvas = tiff.toCanvas();
529
-                                                                  $("#faxdocpreview").empty();
530
-                                                                  $("#faxdocpreview").append(tifcanvas);
531
-                                                              };
532
-                                                              xhr.send();
533
-                                                      }
534
-
535
-                                                      $("#faxdocpreview").show();
536
-                                                      $("#faxfoldersview").hide();
537
-                                                   });
538
-                                                });
539
-
540
-                                                // Remove picked files
541
-                                                $('[class*="indpckfldl"]').last().click(function() {
542
-                                                    var userid = "<?php p($userId); ?>";
543
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
-
545
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
-
547
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
-
550
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
-                                                    $(this).hide();
552
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
-
554
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
-                                                             return value != removedfilename;
556
-                                                    });
557
-
558
-                                                    $.ajax({
559
-                                                        url: baseUrl + '/' + userid,
560
-                                                        type: "POST",
561
-                                                        data: { removedfilename: removedfilename },
562
-                                                        success: function(totalflsize) {
563
-
564
-                                                             $('#filessizetext').text(totalflsize);
565
-
566
-                                                             // Check file size
567
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
-
569
-                                                             if (rectotfilesz > 20.00) {
570
-                                                                 $('#filestotsize').css('color', '#ba3555');
571
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
-                                                                 $('#submitfax').attr("disabled", true);
573
-                                                             } else {
574
-                                                                 $('#submitfax').attr("disabled", false);
575
-                                                                 $('#filestotsize').css('color', '#1eb16a');
576
-                                                               }
577
-
578
-                                                             // Rewrite order numbers for files that follow
579
-                                                             --n;
580
-                                                             $("div:visible[id*='indflpicked']").each(function() {
581
-
582
-                                                                  var getdivtext =  $(this).text();
583
-                                                                  var splitdivtext = getdivtext.split(") ");
584
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
-                                                                  var newnbvalue = currentnbvalue - 1;
586
-
587
-                                                                  if (currentnbvalue > removedflnb) {
588
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
-                                                                      $(this).text(replacedstr);
590
-                                                                  }
591
-                                                             });
592
-                                                        },
593
-                                                        error: function() {
594
-                                                             alert('Error !');
595
-                                                        }
596
-                                                    });
597
-
598
-                                                    $('#faxdocpreview').removeClass('icon-loading');
599
-                                                    $("#faxdocpreview").empty();
600
-                                                });
601
-
602
-
603
-		                                // Preview the picked file
604
-		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
-		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
-
607
-		                                if (extension == 'pdf') {
608
-		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
-		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
-		                                    $("#faxdocpreview").empty();
611
-		                                    $("#faxdocpreview").append($iframe);
612
-		                                } else if (extension == 'txt') {
613
-						           $.get(flUrl, function(textdata) {
614
-		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
-		                                             $("#faxdocpreview").empty();
616
-		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
-							   });
618
-		                                } else if (extension == 'html') {
619
-							   $.get(flUrl, function(htmldata) {
620
-		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
-		                                             $("#faxdocpreview").empty();
622
-		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
-							   });
624
-		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
-		                                           $("#faxdocpreview").empty();
626
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
-		                                } else if (extension == 'png') {
628
-		                                           $("#faxdocpreview").empty();
629
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
-                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
-		                                } else if (extension == 'odt') {
632
-		                                       $("#faxdocpreview").empty();
633
-		                                       function odfInit() {
634
-		                                           var odfelement = document.getElementById("faxdocpreview");
635
-		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
-		                                           odfcanvas.load(flUrl);
637
-		                                       }
638
-		                                       window.setTimeout(odfInit, 0);
639
-
640
-		                                } else if (extension == 'tif' || extension == 'tiff') {
641
-		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
-		                                       var xhr = new XMLHttpRequest();
643
-		                                       xhr.responseType = 'arraybuffer';
644
-		                                       xhr.open('GET', tiffile);
645
-		                                       xhr.onload = function (event) {
646
-		                                           var tiff = new Tiff({buffer: xhr.response});
647
-		                                           var tifcanvas = tiff.toCanvas();
648
-		                                           $("#faxdocpreview").empty();
649
-		                                           $("#faxdocpreview").append(tifcanvas);
650
-		                                       };
651
-		                                       xhr.send();
652
-		                                }
653
-
654
-		                                $("#faxdocpreview").show();
655
-
656
-		                                $('#pf_choose_msg').hide();
657
-		                                $('#faxdocpreview').removeClass('icon-loading');
658
-		                                $("#faxfoldersview").hide();
659
-
660
-                                          },
661
-
662
-                                          error: function(data){
663
-                                             alert('Error!');
664
-                                          }
665
-
666
-                                       });
667
-
668
-                                    } else {
669
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
-                                        $('#pf_choose_msg').hide();
671
-                                        $('#faxdocpreview').removeClass('icon-loading');
672
-                                      }
673
-                                 } else {
674
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
-                                      $('#pf_choose_msg').hide();
676
-                                      $('#faxdocpreview').removeClass('icon-loading');
677
-                                   }
678
-
679
-                              } else {
680
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
-                                   $('#pf_choose_msg').hide();
682
-                                   $('#faxdocpreview').removeClass('icon-loading');
683
-                                }
684
-
685
-                        }
686
-                );
687
-  });
688
-
689
-
690
-  // Submit the fax
691
-  $("#submitfax").on("click", function(event){
692
-
693
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
-
695
-     var toNumberinit = $('#faxto').val();
696
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
-     var toNumber = toNumbersec.split(",");
698
-
699
-     for(var v = 0; v < toNumber.length; v++) {
700
-         toNumber[v] = "+" + toNumber[v];
701
-     }
702
-
703
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
-     $('#faxdocpreview').addClass('icon-loading');
705
-
706
-     $('#submitfax').attr("disabled", true);
707
-
708
-     var userid = "<?php p($userId); ?>";
709
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
710
-
711
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
712
-
713
-     if (uploadedtofax.length != 0) {
714
-
715
-         if (toNumberwc != '') {
716
-
717
-             $.ajax({
718
-                url: baseUrl + '/' + userid,
719
-                type: "POST",
720
-                data: {
721
-                       uploadedtofax: uploadedtofax,
722
-                       selectedcid: selectedcid,
723
-                       toNumber: toNumber
724
-                      },
725
-                success: function(phaxioresult) {
726
-
727
-                   if (phaxioresult.success == true) {
728
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
729
-                   } else {
730
-                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
731
-                   }
732
-
733
-                   $("div:visible[id*='indfilediv']").hide();
734
-                   $("div:visible[id*='indflpicked']").hide();
735
-                   $('[class*="indupfldl"]').hide();
736
-                   $('[class*="indpckfldl"]').hide();
737
-                   $('#faxdocpreview').hide();
738
-                   $('#filestotsize').hide();
739
-                   $('#pf_submit_msg').hide();
740
-                },
741
-                error: function(phaxioresult) {
742
-
743
-                   alert('Error ! Please check your settings !');
744
-
745
-                   $("div:visible[id*='indfilediv']").hide();
746
-                   $("div:visible[id*='indflpicked']").hide();
747
-                   $('[class*="indupfldl"]').hide();
748
-                   $('[class*="indpckfldl"]').hide();
749
-                   $('#pf_submit_msg').hide();
750
-                   $('#filestotsize').hide();
751
-                   $('#faxdocpreview').hide();
752
-
753
-                   location.reload(true);
754
-                }
755
-             });
756
-
757
-         } else {
758
-              $('#pf_submit_msg').hide();
759
-              $('#faxdocpreview').removeClass('icon-loading');
760
-              alert("Please enter the fax number of the recipient !");
761
-         }
762
-
763
-     } else {
764
-              $('#pf_submit_msg').hide();
765
-              $('#faxdocpreview').removeClass('icon-loading');
766
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
767
-     }
768
-  });
769
-
770
-  $("#receivedfaxdir").on("click", function(event){
771
-     $("#faxdocpreview").hide();
772
-     $("#faxfoldersview").show();
773
-     $("#faxfoldersview").addClass("icon-loading");
774
-     $("#faxfoldersview :last-child").remove();
775
-     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
776
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
777
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
778
-  });
779
-
780
-  $("#sentfaxdir").on("click", function(event){
781
-     $("#faxdocpreview").hide();
782
-     $("#faxfoldersview").show();
783
-     $("#faxfoldersview").addClass("icon-loading");
784
-     $("#faxfoldersview :last-child").remove();
785
-     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
786
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
787
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
788
-  });
789
-
790
-  $("#receivedfaileddir").on("click", function(event){
791
-     $("#faxdocpreview").hide();
792
-     $("#faxfoldersview").show();
793
-     $("#faxfoldersview").addClass("icon-loading");
794
-     $("#faxfoldersview :last-child").remove();
795
-     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
796
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
797
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
798
-  });
799
-
800
-  $("#sentfaileddir").on("click", function(event){
801
-     $("#faxdocpreview").hide();
802
-     $("#faxfoldersview").show();
803
-     $("#faxfoldersview").addClass("icon-loading");
804
-     $("#faxfoldersview :last-child").remove();
805
-     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
806
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
807
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
808
-  });
809
-
810
-  $(".indivflpckd").click(function(event){
811
-     $("#faxfoldersview").hide();
812
-  });
813
-
814
-  $(".indivflcls").on("click", function(event){
815
-     $("#faxfoldersview").hide();
816
-  });
817
-
818
-});
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js l10n/en_GB.js l10n/en_GB.json lib/Controller/AuthorApiController.php lib/AppInfo/Application.php lib/Notification/Notifier.php l10n/en_US.js l10n/en_US.json

DoubleBastionAdmin authored on 02/11/2023 18:51:43
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,818 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: { userid: userid },
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: { userid: userid },
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: { userid: userid },
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+
107
+  // Upload files to be faxed
108
+  $("#uploadfileforfax").change(function(e){
109
+
110
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
+     $('#faxdocpreview').addClass('icon-loading');
112
+     $('#filestotsize').show();
113
+
114
+     var userid = "<?php p($userId); ?>";
115
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
+
117
+     var formData = new FormData();
118
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
+
120
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
+
122
+     var fileup = $('#uploadfileforfax').val();
123
+     var fileuptrim = fileup.split('\\').pop();
124
+
125
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
+         var duplicatescheck = 1;
127
+     } else var duplicatescheck = 0;
128
+
129
+     var extension = fileup.replace(/^.*\./, '');
130
+
131
+     if (extension == fileup) {
132
+         extension = "";
133
+     } else {
134
+         extension = extension.toLowerCase();
135
+     }
136
+
137
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
+
139
+     if ($.inArray(extension, validExtensions) != -1) {
140
+
141
+       if (duplicatescheck == 0) {
142
+
143
+         if (currentflsize < 20971520) {
144
+
145
+            if (n < 21) {
146
+
147
+               uploadedtofax.push(fileuptrim);
148
+
149
+               $.ajax({
150
+                 url: baseUrl + '/' + userid,
151
+                 type: "POST",
152
+                 data: formData,
153
+                 cache: false,
154
+                 processData: false,
155
+                 contentType: false,
156
+                 success: function(totalflsize) {
157
+
158
+                   $('#filessizetext').text(totalflsize);
159
+
160
+                   // Check if the total file size is over 20 MB
161
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
+
163
+                   if (rectotfilesz > 20.00) {
164
+                       $('#filestotsize').css('color', '#ba3555');
165
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
+                       $('#submitfax').attr("disabled", true);
167
+                   } else {
168
+                       $('#submitfax').attr("disabled", false);
169
+                       $('#filestotsize').css('color', '#1eb16a');
170
+                     }
171
+
172
+
173
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
+                   n++;
175
+
176
+                   // Preview the file when you click on its name
177
+                   $("div:visible[id*='indfilediv']").each(function() {
178
+                        $(this).on("click", function(eventclck) {
179
+                           var faxfilenameinit = $(this).text();
180
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
+                           var faxfilename = faxfilenamesec.replace("X","");
182
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
+                           var extenlst = faxfilename.replace(/^.*\./, '');
184
+
185
+                           if (extenlst == faxfilename) {
186
+                               extenlst = "";
187
+                           } else {
188
+                               extenlst = extenlst.toLowerCase();
189
+                           }
190
+
191
+                           if (extenlst == 'pdf') {
192
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
+                                  $("#faxdocpreview").empty();
195
+                                  $("#faxdocpreview").append($iframe);
196
+                           } else if (extenlst == 'txt') {
197
+                                  $("#faxdocpreview").empty();
198
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
+                           } else if (extenlst == 'html') {
200
+                                  $("#faxdocpreview").empty();
201
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
+                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
+                           } else if (extenlst == 'png') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
+                           } else if (extenlst == 'odt') {
211
+                                  $("#faxdocpreview").empty();
212
+                                  function odfInit() {
213
+                                     var odfelement = document.getElementById("faxdocpreview");
214
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
+                                     odfcanvas.load(baseUrl);
216
+                                  }
217
+                                  window.setTimeout(odfInit, 0);
218
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
+                                  var xhr = new XMLHttpRequest();
221
+                                  xhr.responseType = 'arraybuffer';
222
+                                  xhr.open('GET', tiffile);
223
+                                  xhr.onload = function (evnt) {
224
+                                      var tiff = new Tiff({buffer: xhr.response});
225
+                                      var tifcanvas = tiff.toCanvas();
226
+                                      $("#faxdocpreview").empty();
227
+                                      $("#faxdocpreview").append(tifcanvas);
228
+                                  };
229
+                                  xhr.send();
230
+                           }
231
+
232
+                           $("#faxdocpreview").show();
233
+                           $("#faxfoldersview").hide();
234
+                        });
235
+                   });
236
+
237
+                   // Remove uploaded files
238
+                   $('[class*="indupfldl"]').last().click(function() {
239
+
240
+                           var userid = "<?php p($userId); ?>";
241
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
+
243
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
+
245
+                           var removedfilesplit = removedfilenameinit.split(") ");
246
+                           var removedflnb = parseInt(removedfilesplit[0]);
247
+
248
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
+                           $(this).hide();
250
+
251
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
+
253
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
+                                           return value != removedfilename;
255
+                           });
256
+
257
+                           $.ajax({
258
+                                   url: baseUrl + '/' + userid,
259
+                                   type: "POST",
260
+                                   data: { removedfilename: removedfilename },
261
+                                   success: function(totalflsize) {
262
+
263
+                                      $('#filessizetext').text(totalflsize);
264
+
265
+                                      // Check file size
266
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
+
268
+                                      if (rectotfilesz > 20.00) {
269
+                                          $('#filestotsize').css('color', '#ba3555');
270
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
+                                          $('#submitfax').attr("disabled", true);
272
+                                      } else {
273
+                                          $('#submitfax').attr("disabled", false);
274
+                                          $('#filestotsize').css('color', '#1eb16a');
275
+                                        }
276
+
277
+                                      // Rewrite order numbers for files that follow
278
+                                      --n;
279
+                                      $("div:visible[id*='indfilediv']").each(function() {
280
+
281
+                                          var getdivtext =  $(this).text();
282
+                                          var splitdivtext = getdivtext.split(") ");
283
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
+                                          var newnbvalue = currentnbvalue - 1;
285
+
286
+                                          if (currentnbvalue > removedflnb) {
287
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
+                                              $(this).text(replacedstr);
289
+                                          }
290
+                                      });
291
+
292
+                                      $("div:visible[id*='indflpicked']").each(function() {
293
+
294
+                                          var getdivtext =  $(this).text();
295
+                                          var splitdivtext = getdivtext.split(") ");
296
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
+                                          var newnbvalue = currentnbvalue - 1;
298
+
299
+                                          if (currentnbvalue > removedflnb) {
300
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
+                                              $(this).text(replacedstr);
302
+                                          }
303
+                                      });
304
+
305
+                                   },
306
+                                   error: function() {
307
+                                          alert('Error !');
308
+                                   }
309
+                           });
310
+
311
+                           $('#faxdocpreview').removeClass('icon-loading');
312
+                           $("#faxdocpreview").empty();
313
+                   });
314
+
315
+                   // Preview the uploaded file
316
+                   var faxfilename = e.target.files[0].name;
317
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
+
319
+                   if (extension == 'pdf') {
320
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
+                              $("#faxdocpreview").empty();
323
+                              $("#faxdocpreview").append($iframe);
324
+                   } else if (extension == 'txt') {
325
+                              var reader = new FileReader();
326
+                              reader.readAsText(e.target.files[0]);
327
+                              reader.onload = function(e) {
328
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
+                                  $("#faxdocpreview").empty();
330
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
+                              };
332
+                   } else if (extension == 'html') {
333
+                              var reader = new FileReader();
334
+                              reader.readAsText(e.target.files[0]);
335
+                              reader.onload = function(e) {
336
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
+                                  $("#faxdocpreview").empty();
338
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
+                              };
340
+                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
+                              $("#faxdocpreview").empty();
342
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
+
344
+                              var reader = new FileReader();
345
+                              reader.onload = function (e) {
346
+                                  readjpg[faxfilename] = e.target.result;
347
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
+                              }
349
+                              reader.readAsDataURL(e.target.files[0]);
350
+                   } else if (extension == 'png') {
351
+                              $("#faxdocpreview").empty();
352
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
+
354
+                              var reader = new FileReader();
355
+                              reader.onload = function (e) {
356
+                                  readpng[faxfilename] = e.target.result;
357
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
+                              }
359
+                              reader.readAsDataURL(e.target.files[0]);
360
+                   } else if (extension == 'odt') {
361
+                              $("#faxdocpreview").empty();
362
+                              function odfInit() {
363
+                                 var odfelement = document.getElementById("faxdocpreview");
364
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
+                                 odfcanvas.load(baseUrl);
366
+                              }
367
+                              window.setTimeout(odfInit, 0);
368
+                   } else if (extension == 'tif' || extension == 'tiff') {
369
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
+                              var xhr = new XMLHttpRequest();
371
+                              xhr.responseType = 'arraybuffer';
372
+                              xhr.open('GET', tiffile);
373
+                              xhr.onload = function (e) {
374
+                                  var tiff = new Tiff({buffer: xhr.response});
375
+                                  var tifcanvas = tiff.toCanvas();
376
+                                  $("#faxdocpreview").empty();
377
+                                  $("#faxdocpreview").append(tifcanvas);
378
+                              };
379
+                              xhr.send();
380
+                   }
381
+
382
+                   $("#faxdocpreview").show();
383
+                   $('#pf_upload_msg').hide();
384
+                   $('#faxdocpreview').removeClass('icon-loading');
385
+                   $("#faxfoldersview").hide();
386
+                 },
387
+                 error: function(data){
388
+                     alert('Error!');
389
+                 }
390
+               });
391
+
392
+            } else {
393
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
+                  $('#pf_upload_msg').hide();
395
+                  $('#faxdocpreview').removeClass('icon-loading');
396
+              }
397
+         } else {
398
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
+              $('#pf_upload_msg').hide();
400
+              $('#faxdocpreview').removeClass('icon-loading');
401
+           }
402
+       } else {
403
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
+            $('#pf_upload_msg').hide();
405
+            $('#faxdocpreview').removeClass('icon-loading');
406
+         }
407
+
408
+     } else {
409
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
+          $('#pf_upload_msg').hide();
411
+          $('#faxdocpreview').removeClass('icon-loading');
412
+       }
413
+  });
414
+
415
+
416
+  // Pick file to fax, from Nextcloud
417
+  var faxfilename = null;
418
+
419
+  $("#choosefilen").on("click", function(evn) {
420
+
421
+                OC.dialogs.filepicker(
422
+                        t('settings', "Select a file to send as fax."),
423
+                        function (path) {
424
+
425
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
+                              $('#faxdocpreview').addClass('icon-loading');
427
+                              $('#filestotsize').show();
428
+
429
+                              var userid = "<?php p($userId); ?>";
430
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
+
432
+                              faxfilename = path.split('/').pop();
433
+
434
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
+                                  var duplicatescheck = 1;
436
+                              } else var duplicatescheck = 0;
437
+
438
+                              var extension = faxfilename.replace(/^.*\./, '');
439
+
440
+                              if (extension == faxfilename) {
441
+                                  extension = "";
442
+                              } else {
443
+                                  extension = extension.toLowerCase();
444
+                              }
445
+
446
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
+
448
+                              if ($.inArray(extension, validExtensions) != -1) {
449
+
450
+                                 if (duplicatescheck == 0) {
451
+
452
+                                    if (n < 21) {
453
+
454
+                                       uploadedtofax.push(faxfilename);
455
+
456
+                                       $.ajax({
457
+                                          url: baseUrl + '/' + userid,
458
+                                          type: "POST",
459
+                                          data: { path: path },
460
+                                          success: function(totalflsize) {
461
+
462
+                                                $('#filessizetext').text(totalflsize);
463
+
464
+                                                // Check if the total file size is over 20 MB
465
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
+
467
+                                                if (rectotfilesz > 20.00) {
468
+                                                    $('#filestotsize').css('color', '#ba3555');
469
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
+                                                    $('#submitfax').attr("disabled", true);
471
+                                                } else {
472
+                                                    $('#submitfax').attr("disabled", false);
473
+                                                    $('#filestotsize').css('color', '#1eb16a');
474
+                                                }
475
+
476
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
+                                                n++;
478
+
479
+                                                // Preview each file when you click on its name
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
+//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
+                                                      } else if (extenlst == 'png') {
510
+                                                              $("#faxdocpreview").empty();
511
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
+//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
+                                                      } else if (extenlst == 'odt') {
514
+                                                              $("#faxdocpreview").empty();
515
+                                                              function odfInit() {
516
+                                                                 var odfelement = document.getElementById("faxdocpreview");
517
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
+                                                                 odfcanvas.load(baseUrl);
519
+                                                              }
520
+                                                              window.setTimeout(odfInit, 0);
521
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
+                                                              var xhr = new XMLHttpRequest();
524
+                                                              xhr.responseType = 'arraybuffer';
525
+                                                              xhr.open('GET', tiffile);
526
+                                                              xhr.onload = function (evnt) {
527
+                                                                  var tiff = new Tiff({buffer: xhr.response});
528
+                                                                  var tifcanvas = tiff.toCanvas();
529
+                                                                  $("#faxdocpreview").empty();
530
+                                                                  $("#faxdocpreview").append(tifcanvas);
531
+                                                              };
532
+                                                              xhr.send();
533
+                                                      }
534
+
535
+                                                      $("#faxdocpreview").show();
536
+                                                      $("#faxfoldersview").hide();
537
+                                                   });
538
+                                                });
539
+
540
+                                                // Remove picked files
541
+                                                $('[class*="indpckfldl"]').last().click(function() {
542
+                                                    var userid = "<?php p($userId); ?>";
543
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
+
545
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
+
547
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
+
550
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
+                                                    $(this).hide();
552
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
+
554
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
+                                                             return value != removedfilename;
556
+                                                    });
557
+
558
+                                                    $.ajax({
559
+                                                        url: baseUrl + '/' + userid,
560
+                                                        type: "POST",
561
+                                                        data: { removedfilename: removedfilename },
562
+                                                        success: function(totalflsize) {
563
+
564
+                                                             $('#filessizetext').text(totalflsize);
565
+
566
+                                                             // Check file size
567
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
+
569
+                                                             if (rectotfilesz > 20.00) {
570
+                                                                 $('#filestotsize').css('color', '#ba3555');
571
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
+                                                                 $('#submitfax').attr("disabled", true);
573
+                                                             } else {
574
+                                                                 $('#submitfax').attr("disabled", false);
575
+                                                                 $('#filestotsize').css('color', '#1eb16a');
576
+                                                               }
577
+
578
+                                                             // Rewrite order numbers for files that follow
579
+                                                             --n;
580
+                                                             $("div:visible[id*='indflpicked']").each(function() {
581
+
582
+                                                                  var getdivtext =  $(this).text();
583
+                                                                  var splitdivtext = getdivtext.split(") ");
584
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
+                                                                  var newnbvalue = currentnbvalue - 1;
586
+
587
+                                                                  if (currentnbvalue > removedflnb) {
588
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
+                                                                      $(this).text(replacedstr);
590
+                                                                  }
591
+                                                             });
592
+                                                        },
593
+                                                        error: function() {
594
+                                                             alert('Error !');
595
+                                                        }
596
+                                                    });
597
+
598
+                                                    $('#faxdocpreview').removeClass('icon-loading');
599
+                                                    $("#faxdocpreview").empty();
600
+                                                });
601
+
602
+
603
+		                                // Preview the picked file
604
+		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
+		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
+
607
+		                                if (extension == 'pdf') {
608
+		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
+		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
+		                                    $("#faxdocpreview").empty();
611
+		                                    $("#faxdocpreview").append($iframe);
612
+		                                } else if (extension == 'txt') {
613
+						           $.get(flUrl, function(textdata) {
614
+		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
+		                                             $("#faxdocpreview").empty();
616
+		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
+							   });
618
+		                                } else if (extension == 'html') {
619
+							   $.get(flUrl, function(htmldata) {
620
+		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
+		                                             $("#faxdocpreview").empty();
622
+		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
+							   });
624
+		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
+		                                           $("#faxdocpreview").empty();
626
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
+		                                } else if (extension == 'png') {
628
+		                                           $("#faxdocpreview").empty();
629
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
+                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
+		                                } else if (extension == 'odt') {
632
+		                                       $("#faxdocpreview").empty();
633
+		                                       function odfInit() {
634
+		                                           var odfelement = document.getElementById("faxdocpreview");
635
+		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
+		                                           odfcanvas.load(flUrl);
637
+		                                       }
638
+		                                       window.setTimeout(odfInit, 0);
639
+
640
+		                                } else if (extension == 'tif' || extension == 'tiff') {
641
+		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
+		                                       var xhr = new XMLHttpRequest();
643
+		                                       xhr.responseType = 'arraybuffer';
644
+		                                       xhr.open('GET', tiffile);
645
+		                                       xhr.onload = function (event) {
646
+		                                           var tiff = new Tiff({buffer: xhr.response});
647
+		                                           var tifcanvas = tiff.toCanvas();
648
+		                                           $("#faxdocpreview").empty();
649
+		                                           $("#faxdocpreview").append(tifcanvas);
650
+		                                       };
651
+		                                       xhr.send();
652
+		                                }
653
+
654
+		                                $("#faxdocpreview").show();
655
+
656
+		                                $('#pf_choose_msg').hide();
657
+		                                $('#faxdocpreview').removeClass('icon-loading');
658
+		                                $("#faxfoldersview").hide();
659
+
660
+                                          },
661
+
662
+                                          error: function(data){
663
+                                             alert('Error!');
664
+                                          }
665
+
666
+                                       });
667
+
668
+                                    } else {
669
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
+                                        $('#pf_choose_msg').hide();
671
+                                        $('#faxdocpreview').removeClass('icon-loading');
672
+                                      }
673
+                                 } else {
674
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
+                                      $('#pf_choose_msg').hide();
676
+                                      $('#faxdocpreview').removeClass('icon-loading');
677
+                                   }
678
+
679
+                              } else {
680
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
+                                   $('#pf_choose_msg').hide();
682
+                                   $('#faxdocpreview').removeClass('icon-loading');
683
+                                }
684
+
685
+                        }
686
+                );
687
+  });
688
+
689
+
690
+  // Submit the fax
691
+  $("#submitfax").on("click", function(event){
692
+
693
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
+
695
+     var toNumberinit = $('#faxto').val();
696
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
+     var toNumber = toNumbersec.split(",");
698
+
699
+     for(var v = 0; v < toNumber.length; v++) {
700
+         toNumber[v] = "+" + toNumber[v];
701
+     }
702
+
703
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
+     $('#faxdocpreview').addClass('icon-loading');
705
+
706
+     $('#submitfax').attr("disabled", true);
707
+
708
+     var userid = "<?php p($userId); ?>";
709
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
710
+
711
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
712
+
713
+     if (uploadedtofax.length != 0) {
714
+
715
+         if (toNumberwc != '') {
716
+
717
+             $.ajax({
718
+                url: baseUrl + '/' + userid,
719
+                type: "POST",
720
+                data: {
721
+                       uploadedtofax: uploadedtofax,
722
+                       selectedcid: selectedcid,
723
+                       toNumber: toNumber
724
+                      },
725
+                success: function(phaxioresult) {
726
+
727
+                   if (phaxioresult.success == true) {
728
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
729
+                   } else {
730
+                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
731
+                   }
732
+
733
+                   $("div:visible[id*='indfilediv']").hide();
734
+                   $("div:visible[id*='indflpicked']").hide();
735
+                   $('[class*="indupfldl"]').hide();
736
+                   $('[class*="indpckfldl"]').hide();
737
+                   $('#faxdocpreview').hide();
738
+                   $('#filestotsize').hide();
739
+                   $('#pf_submit_msg').hide();
740
+                },
741
+                error: function(phaxioresult) {
742
+
743
+                   alert('Error ! Please check your settings !');
744
+
745
+                   $("div:visible[id*='indfilediv']").hide();
746
+                   $("div:visible[id*='indflpicked']").hide();
747
+                   $('[class*="indupfldl"]').hide();
748
+                   $('[class*="indpckfldl"]').hide();
749
+                   $('#pf_submit_msg').hide();
750
+                   $('#filestotsize').hide();
751
+                   $('#faxdocpreview').hide();
752
+
753
+                   location.reload(true);
754
+                }
755
+             });
756
+
757
+         } else {
758
+              $('#pf_submit_msg').hide();
759
+              $('#faxdocpreview').removeClass('icon-loading');
760
+              alert("Please enter the fax number of the recipient !");
761
+         }
762
+
763
+     } else {
764
+              $('#pf_submit_msg').hide();
765
+              $('#faxdocpreview').removeClass('icon-loading');
766
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
767
+     }
768
+  });
769
+
770
+  $("#receivedfaxdir").on("click", function(event){
771
+     $("#faxdocpreview").hide();
772
+     $("#faxfoldersview").show();
773
+     $("#faxfoldersview").addClass("icon-loading");
774
+     $("#faxfoldersview :last-child").remove();
775
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
776
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
777
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
778
+  });
779
+
780
+  $("#sentfaxdir").on("click", function(event){
781
+     $("#faxdocpreview").hide();
782
+     $("#faxfoldersview").show();
783
+     $("#faxfoldersview").addClass("icon-loading");
784
+     $("#faxfoldersview :last-child").remove();
785
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
786
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
787
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
788
+  });
789
+
790
+  $("#receivedfaileddir").on("click", function(event){
791
+     $("#faxdocpreview").hide();
792
+     $("#faxfoldersview").show();
793
+     $("#faxfoldersview").addClass("icon-loading");
794
+     $("#faxfoldersview :last-child").remove();
795
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
796
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
797
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
798
+  });
799
+
800
+  $("#sentfaileddir").on("click", function(event){
801
+     $("#faxdocpreview").hide();
802
+     $("#faxfoldersview").show();
803
+     $("#faxfoldersview").addClass("icon-loading");
804
+     $("#faxfoldersview :last-child").remove();
805
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
806
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
807
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
808
+  });
809
+
810
+  $(".indivflpckd").click(function(event){
811
+     $("#faxfoldersview").hide();
812
+  });
813
+
814
+  $(".indivflcls").on("click", function(event){
815
+     $("#faxfoldersview").hide();
816
+  });
817
+
818
+});
Browse code

CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js l10n/en_GB.js l10n/en_GB.json lib/Controller/AuthorApiController.php lib/AppInfo/Application.php

DoubleBastionAdmin authored on 02/11/2023 18:44:01
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,822 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
-  var locHref = window.location.href;
33
-  var pathSplit = locHref.split('/');
34
-  var firstPathEl = '';
35
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
-
37
-  // Check the available balance
38
-  $("#checkbalance").on("click", function(event) {
39
-
40
-     $('#checkbalance').addClass('icon-loading');
41
-
42
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
-
44
-     $.ajax({
45
-          url: getbalanceUrl + '/' + userid,
46
-          type: "POST",
47
-          data: { userid: userid },
48
-          cache: false,
49
-          processData: false,
50
-          contentType: false,
51
-          success: function(phaxiobalance) {
52
-                 var balanceindlrs = phaxiobalance / 100;
53
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
-                 $('#currentbalance').text(balanceproc);
55
-
56
-                 $('#checkbalance').removeClass('icon-loading');
57
-          }
58
-     });
59
-  });
60
-
61
-  // Select the Caller ID
62
-  $("#selectcalleridbttn").on("click", function(event) {
63
-
64
-     $('#selectcalleridbttn').addClass('icon-loading');
65
-
66
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
-     var selectednmbr = null;
68
-
69
-     $.ajax({
70
-          url: getfaxnumbersUrl + '/' + userid,
71
-          type: "POST",
72
-          data: { userid: userid },
73
-          cache: false,
74
-          processData: false,
75
-          contentType: false,
76
-          success: function(phaxionmbrs) {
77
-
78
-                    $('#currentfaxnmbrs').empty();
79
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
-
82
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
-                    });
85
-
86
-                    $('#selectcalleridbttn').removeClass('icon-loading');
87
-
88
-          }
89
-     });
90
-  });
91
-
92
-  // Clean the Pax_Fax/temp_files directory
93
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
-
95
-  $.ajax({
96
-          url: cleanflUrl + '/' + userid,
97
-          type: "POST",
98
-          data: { userid: userid },
99
-          cache: false,
100
-          processData: false,
101
-          contentType: false
102
-  });
103
-
104
-  var n = 1;
105
-  var uploadedtofax = [];
106
-
107
-  // Upload files to be faxed
108
-  $("#uploadfileforfax").change(function(e){
109
-
110
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
-     $('#faxdocpreview').addClass('icon-loading');
112
-     $('#filestotsize').show();
113
-
114
-     var userid = "<?php p($userId); ?>";
115
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
-
117
-     var formData = new FormData();
118
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
-
120
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
-
122
-     var fileup = $('#uploadfileforfax').val();
123
-     var fileuptrim = fileup.split('\\').pop();
124
-
125
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
-         var duplicatescheck = 1;
127
-     } else var duplicatescheck = 0;
128
-
129
-     var extension = fileup.replace(/^.*\./, '');
130
-
131
-     if (extension == fileup) {
132
-         extension = "";
133
-     } else {
134
-         extension = extension.toLowerCase();
135
-     }
136
-
137
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
-
139
-     if ($.inArray(extension, validExtensions) != -1) {
140
-
141
-       if (duplicatescheck == 0) {
142
-
143
-         if (currentflsize < 20971520) {
144
-
145
-            if (n < 21) {
146
-
147
-               uploadedtofax.push(fileuptrim);
148
-
149
-               $.ajax({
150
-                 url: baseUrl + '/' + userid,
151
-                 type: "POST",
152
-                 data: formData,
153
-                 cache: false,
154
-                 processData: false,
155
-                 contentType: false,
156
-                 success: function(totalflsize) {
157
-
158
-                   $('#filessizetext').text(totalflsize);
159
-
160
-                   // Check if the total file size is over 20 MB
161
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
-
163
-                   if (rectotfilesz > 20.00) {
164
-                       $('#filestotsize').css('color', '#ba3555');
165
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
-                       $('#submitfax').attr("disabled", true);
167
-                   } else {
168
-                       $('#submitfax').attr("disabled", false);
169
-                       $('#filestotsize').css('color', '#1eb16a');
170
-                     }
171
-
172
-
173
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
-                   n++;
175
-
176
-                   // Preview the file when you click on its name
177
-                   $("div:visible[id*='indfilediv']").each(function() {
178
-                        $(this).on("click", function(eventclck) {
179
-                           var faxfilenameinit = $(this).text();
180
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
-                           var faxfilename = faxfilenamesec.replace("X","");
182
-                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
-                           var extenlst = faxfilename.replace(/^.*\./, '');
184
-
185
-                           if (extenlst == faxfilename) {
186
-                               extenlst = "";
187
-                           } else {
188
-                               extenlst = extenlst.toLowerCase();
189
-                           }
190
-
191
-                           if (extenlst == 'pdf') {
192
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
-                                  $("#faxdocpreview").empty();
195
-                                  $("#faxdocpreview").append($iframe);
196
-                           } else if (extenlst == 'txt') {
197
-                                  $("#faxdocpreview").empty();
198
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
-                           } else if (extenlst == 'html') {
200
-                                  $("#faxdocpreview").empty();
201
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
-                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
-                                  $("#faxdocpreview").empty();
204
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
-                           } else if (extenlst == 'png') {
207
-                                  $("#faxdocpreview").empty();
208
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
-                           } else if (extenlst == 'odt') {
211
-                                  $("#faxdocpreview").empty();
212
-                                  function odfInit() {
213
-                                     var odfelement = document.getElementById("faxdocpreview");
214
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
-                                     odfcanvas.load(baseUrl);
216
-                                  }
217
-                                  window.setTimeout(odfInit, 0);
218
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
-                                  var xhr = new XMLHttpRequest();
221
-                                  xhr.responseType = 'arraybuffer';
222
-                                  xhr.open('GET', tiffile);
223
-                                  xhr.onload = function (evnt) {
224
-                                      var tiff = new Tiff({buffer: xhr.response});
225
-                                      var tifcanvas = tiff.toCanvas();
226
-                                      $("#faxdocpreview").empty();
227
-                                      $("#faxdocpreview").append(tifcanvas);
228
-                                  };
229
-                                  xhr.send();
230
-                           }
231
-
232
-                           $("#faxdocpreview").show();
233
-                           $("#faxfoldersview").hide();
234
-                        });
235
-                   });
236
-
237
-                   // Remove uploaded files
238
-                   $('[class*="indupfldl"]').last().click(function() {
239
-
240
-                           var userid = "<?php p($userId); ?>";
241
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
-
243
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
-
245
-                           var removedfilesplit = removedfilenameinit.split(") ");
246
-                           var removedflnb = parseInt(removedfilesplit[0]);
247
-
248
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
-                           $(this).hide();
250
-
251
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
-
253
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
-                                           return value != removedfilename;
255
-                           });
256
-
257
-                           $.ajax({
258
-                                   url: baseUrl + '/' + userid,
259
-                                   type: "POST",
260
-                                   data: { removedfilename: removedfilename },
261
-                                   success: function(totalflsize) {
262
-
263
-                                      $('#filessizetext').text(totalflsize);
264
-
265
-                                      // Check file size
266
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
-
268
-                                      if (rectotfilesz > 20.00) {
269
-                                          $('#filestotsize').css('color', '#ba3555');
270
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
-                                          $('#submitfax').attr("disabled", true);
272
-                                      } else {
273
-                                          $('#submitfax').attr("disabled", false);
274
-                                          $('#filestotsize').css('color', '#1eb16a');
275
-                                        }
276
-
277
-                                      // Rewrite order numbers for files that follow
278
-                                      --n;
279
-                                      $("div:visible[id*='indfilediv']").each(function() {
280
-
281
-                                          var getdivtext =  $(this).text();
282
-                                          var splitdivtext = getdivtext.split(") ");
283
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
-                                          var newnbvalue = currentnbvalue - 1;
285
-
286
-                                          if (currentnbvalue > removedflnb) {
287
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
-                                              $(this).text(replacedstr);
289
-                                          }
290
-                                      });
291
-
292
-                                      $("div:visible[id*='indflpicked']").each(function() {
293
-
294
-                                          var getdivtext =  $(this).text();
295
-                                          var splitdivtext = getdivtext.split(") ");
296
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
-                                          var newnbvalue = currentnbvalue - 1;
298
-
299
-                                          if (currentnbvalue > removedflnb) {
300
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
-                                              $(this).text(replacedstr);
302
-                                          }
303
-                                      });
304
-
305
-                                   },
306
-                                   error: function() {
307
-                                          alert('Error !');
308
-                                   }
309
-                           });
310
-
311
-                           $('#faxdocpreview').removeClass('icon-loading');
312
-                           $("#faxdocpreview").empty();
313
-                   });
314
-
315
-                   // Preview the uploaded file
316
-                   var faxfilename = e.target.files[0].name;
317
-                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
-
319
-                   if (extension == 'pdf') {
320
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
-                              $("#faxdocpreview").empty();
323
-                              $("#faxdocpreview").append($iframe);
324
-                   } else if (extension == 'txt') {
325
-                              var reader = new FileReader();
326
-                              reader.readAsText(e.target.files[0]);
327
-                              reader.onload = function(e) {
328
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
-                                  $("#faxdocpreview").empty();
330
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
-                              };
332
-                   } else if (extension == 'html') {
333
-                              var reader = new FileReader();
334
-                              reader.readAsText(e.target.files[0]);
335
-                              reader.onload = function(e) {
336
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
-                                  $("#faxdocpreview").empty();
338
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
-                              };
340
-                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
-                              $("#faxdocpreview").empty();
342
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
-
344
-                              var reader = new FileReader();
345
-                              reader.onload = function (e) {
346
-                                  readjpg[faxfilename] = e.target.result;
347
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
-                              }
349
-                              reader.readAsDataURL(e.target.files[0]);
350
-                   } else if (extension == 'png') {
351
-                              $("#faxdocpreview").empty();
352
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
-
354
-                              var reader = new FileReader();
355
-                              reader.onload = function (e) {
356
-                                  readpng[faxfilename] = e.target.result;
357
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
-                              }
359
-                              reader.readAsDataURL(e.target.files[0]);
360
-                   } else if (extension == 'odt') {
361
-                              $("#faxdocpreview").empty();
362
-                              function odfInit() {
363
-                                 var odfelement = document.getElementById("faxdocpreview");
364
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
-                                 odfcanvas.load(baseUrl);
366
-                              }
367
-                              window.setTimeout(odfInit, 0);
368
-                   } else if (extension == 'tif' || extension == 'tiff') {
369
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
-                              var xhr = new XMLHttpRequest();
371
-                              xhr.responseType = 'arraybuffer';
372
-                              xhr.open('GET', tiffile);
373
-                              xhr.onload = function (e) {
374
-                                  var tiff = new Tiff({buffer: xhr.response});
375
-                                  var tifcanvas = tiff.toCanvas();
376
-                                  $("#faxdocpreview").empty();
377
-                                  $("#faxdocpreview").append(tifcanvas);
378
-                              };
379
-                              xhr.send();
380
-                   }
381
-
382
-                   $("#faxdocpreview").show();
383
-                   $('#pf_upload_msg').hide();
384
-                   $('#faxdocpreview').removeClass('icon-loading');
385
-                   $("#faxfoldersview").hide();
386
-                 },
387
-                 error: function(data){
388
-                     alert('Error!');
389
-                 }
390
-               });
391
-
392
-            } else {
393
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
-                  $('#pf_upload_msg').hide();
395
-                  $('#faxdocpreview').removeClass('icon-loading');
396
-              }
397
-         } else {
398
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
-              $('#pf_upload_msg').hide();
400
-              $('#faxdocpreview').removeClass('icon-loading');
401
-           }
402
-       } else {
403
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
-            $('#pf_upload_msg').hide();
405
-            $('#faxdocpreview').removeClass('icon-loading');
406
-         }
407
-
408
-     } else {
409
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
-          $('#pf_upload_msg').hide();
411
-          $('#faxdocpreview').removeClass('icon-loading');
412
-       }
413
-  });
414
-
415
-
416
-  // Pick file to fax, from Nextcloud
417
-  var faxfilename = null;
418
-
419
-  $("#choosefilen").on("click", function(evn) {
420
-
421
-                OC.dialogs.filepicker(
422
-                        t('settings', "Select a file to send as fax."),
423
-                        function (path) {
424
-
425
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
-                              $('#faxdocpreview').addClass('icon-loading');
427
-                              $('#filestotsize').show();
428
-
429
-                              var userid = "<?php p($userId); ?>";
430
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
-
432
-                              faxfilename = path.split('/').pop();
433
-
434
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
-                                  var duplicatescheck = 1;
436
-                              } else var duplicatescheck = 0;
437
-
438
-                              var extension = faxfilename.replace(/^.*\./, '');
439
-
440
-                              if (extension == faxfilename) {
441
-                                  extension = "";
442
-                              } else {
443
-                                  extension = extension.toLowerCase();
444
-                              }
445
-
446
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
-
448
-                              if ($.inArray(extension, validExtensions) != -1) {
449
-
450
-                                 if (duplicatescheck == 0) {
451
-
452
-                                    if (n < 21) {
453
-
454
-                                       uploadedtofax.push(faxfilename);
455
-
456
-                                       $.ajax({
457
-                                          url: baseUrl + '/' + userid,
458
-                                          type: "POST",
459
-                                          data: { path: path },
460
-                                          success: function(totalflsize) {
461
-
462
-                                                $('#filessizetext').text(totalflsize);
463
-
464
-                                                // Check if the total file size is over 20 MB
465
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
-
467
-                                                if (rectotfilesz > 20.00) {
468
-                                                    $('#filestotsize').css('color', '#ba3555');
469
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
-                                                    $('#submitfax').attr("disabled", true);
471
-                                                } else {
472
-                                                    $('#submitfax').attr("disabled", false);
473
-                                                    $('#filestotsize').css('color', '#1eb16a');
474
-                                                }
475
-
476
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
-                                                n++;
478
-
479
-                                                // Preview each file when you click on its name
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
-//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
-                                                      } else if (extenlst == 'png') {
510
-                                                              $("#faxdocpreview").empty();
511
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
-//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
-                                                      } else if (extenlst == 'odt') {
514
-                                                              $("#faxdocpreview").empty();
515
-                                                              function odfInit() {
516
-                                                                 var odfelement = document.getElementById("faxdocpreview");
517
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
-                                                                 odfcanvas.load(baseUrl);
519
-                                                              }
520
-                                                              window.setTimeout(odfInit, 0);
521
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
-                                                              var xhr = new XMLHttpRequest();
524
-                                                              xhr.responseType = 'arraybuffer';
525
-                                                              xhr.open('GET', tiffile);
526
-                                                              xhr.onload = function (evnt) {
527
-                                                                  var tiff = new Tiff({buffer: xhr.response});
528
-                                                                  var tifcanvas = tiff.toCanvas();
529
-                                                                  $("#faxdocpreview").empty();
530
-                                                                  $("#faxdocpreview").append(tifcanvas);
531
-                                                              };
532
-                                                              xhr.send();
533
-                                                      }
534
-
535
-                                                      $("#faxdocpreview").show();
536
-                                                      $("#faxfoldersview").hide();
537
-                                                   });
538
-                                                });
539
-
540
-                                                // Remove picked files
541
-                                                $('[class*="indpckfldl"]').last().click(function() {
542
-                                                    var userid = "<?php p($userId); ?>";
543
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
-
545
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
-
547
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
-
550
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
-                                                    $(this).hide();
552
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
-
554
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
-                                                             return value != removedfilename;
556
-                                                    });
557
-
558
-                                                    $.ajax({
559
-                                                        url: baseUrl + '/' + userid,
560
-                                                        type: "POST",
561
-                                                        data: { removedfilename: removedfilename },
562
-                                                        success: function(totalflsize) {
563
-
564
-                                                             $('#filessizetext').text(totalflsize);
565
-
566
-                                                             // Check file size
567
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
-
569
-                                                             if (rectotfilesz > 20.00) {
570
-                                                                 $('#filestotsize').css('color', '#ba3555');
571
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
-                                                                 $('#submitfax').attr("disabled", true);
573
-                                                             } else {
574
-                                                                 $('#submitfax').attr("disabled", false);
575
-                                                                 $('#filestotsize').css('color', '#1eb16a');
576
-                                                               }
577
-
578
-                                                             // Rewrite order numbers for files that follow
579
-                                                             --n;
580
-                                                             $("div:visible[id*='indflpicked']").each(function() {
581
-
582
-                                                                  var getdivtext =  $(this).text();
583
-                                                                  var splitdivtext = getdivtext.split(") ");
584
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
-                                                                  var newnbvalue = currentnbvalue - 1;
586
-
587
-                                                                  if (currentnbvalue > removedflnb) {
588
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
-                                                                      $(this).text(replacedstr);
590
-                                                                  }
591
-                                                             });
592
-                                                        },
593
-                                                        error: function() {
594
-                                                             alert('Error !');
595
-                                                        }
596
-                                                    });
597
-
598
-                                                    $('#faxdocpreview').removeClass('icon-loading');
599
-                                                    $("#faxdocpreview").empty();
600
-                                                });
601
-
602
-
603
-		                                // Preview the picked file
604
-		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
-		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
-
607
-		                                if (extension == 'pdf') {
608
-		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
-		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
-		                                    $("#faxdocpreview").empty();
611
-		                                    $("#faxdocpreview").append($iframe);
612
-		                                } else if (extension == 'txt') {
613
-						           $.get(flUrl, function(textdata) {
614
-		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
-		                                             $("#faxdocpreview").empty();
616
-		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
-							   });
618
-		                                } else if (extension == 'html') {
619
-							   $.get(flUrl, function(htmldata) {
620
-		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
-		                                             $("#faxdocpreview").empty();
622
-		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
-							   });
624
-		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
-		                                           $("#faxdocpreview").empty();
626
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
-		                                } else if (extension == 'png') {
628
-		                                           $("#faxdocpreview").empty();
629
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
-                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
-		                                } else if (extension == 'odt') {
632
-		                                       $("#faxdocpreview").empty();
633
-		                                       function odfInit() {
634
-		                                           var odfelement = document.getElementById("faxdocpreview");
635
-		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
-		                                           odfcanvas.load(flUrl);
637
-		                                       }
638
-		                                       window.setTimeout(odfInit, 0);
639
-
640
-		                                } else if (extension == 'tif' || extension == 'tiff') {
641
-		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
-		                                       var xhr = new XMLHttpRequest();
643
-		                                       xhr.responseType = 'arraybuffer';
644
-		                                       xhr.open('GET', tiffile);
645
-		                                       xhr.onload = function (event) {
646
-		                                           var tiff = new Tiff({buffer: xhr.response});
647
-		                                           var tifcanvas = tiff.toCanvas();
648
-		                                           $("#faxdocpreview").empty();
649
-		                                           $("#faxdocpreview").append(tifcanvas);
650
-		                                       };
651
-		                                       xhr.send();
652
-		                                }
653
-
654
-		                                $("#faxdocpreview").show();
655
-
656
-		                                $('#pf_choose_msg').hide();
657
-		                                $('#faxdocpreview').removeClass('icon-loading');
658
-		                                $("#faxfoldersview").hide();
659
-
660
-                                          },
661
-
662
-                                          error: function(data){
663
-                                             alert('Error!');
664
-                                          }
665
-
666
-                                       });
667
-
668
-                                    } else {
669
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
-                                        $('#pf_choose_msg').hide();
671
-                                        $('#faxdocpreview').removeClass('icon-loading');
672
-                                      }
673
-                                 } else {
674
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
-                                      $('#pf_choose_msg').hide();
676
-                                      $('#faxdocpreview').removeClass('icon-loading');
677
-                                   }
678
-
679
-                              } else {
680
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
-                                   $('#pf_choose_msg').hide();
682
-                                   $('#faxdocpreview').removeClass('icon-loading');
683
-                                }
684
-
685
-                        }
686
-                );
687
-  });
688
-
689
-
690
-  // Submit the fax
691
-  $("#submitfax").on("click", function(event){
692
-
693
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
-
695
-     var toNumberinit = $('#faxto').val();
696
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
-     var toNumber = toNumbersec.split(",");
698
-
699
-     for(var v = 0; v < toNumber.length; v++) {
700
-         toNumber[v] = "+" + toNumber[v];
701
-     }
702
-
703
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
-     $('#faxdocpreview').addClass('icon-loading');
705
-
706
-     $('#submitfax').attr("disabled", true);
707
-
708
-     var userid = "<?php p($userId); ?>";
709
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
710
-
711
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
712
-
713
-     if (uploadedtofax.length != 0) {
714
-
715
-         if (toNumberwc != '') {
716
-
717
-             $.ajax({
718
-                url: baseUrl + '/' + userid,
719
-                type: "POST",
720
-                data: {
721
-                       uploadedtofax: uploadedtofax,
722
-                       selectedcid: selectedcid,
723
-                       toNumber: toNumber
724
-                      },
725
-                success: function(phaxioresult) {
726
-
727
-                   if (phaxioresult.success == true) {
728
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
729
-                   } else {
730
-                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
731
-                   }
732
-
733
-                   $("div:visible[id*='indfilediv']").hide();
734
-                   $("div:visible[id*='indflpicked']").hide();
735
-                   $('[class*="indupfldl"]').hide();
736
-                   $('[class*="indpckfldl"]').hide();
737
-                   $('#faxdocpreview').hide();
738
-                   $('#filestotsize').hide();
739
-                   $('#pf_submit_msg').hide();
740
-
741
-                   location.reload(true);
742
-
743
-                },
744
-
745
-                error: function(phaxioresult) {
746
-
747
-                   alert('Error ! Please check your settings !');
748
-
749
-                   $("div:visible[id*='indfilediv']").hide();
750
-                   $("div:visible[id*='indflpicked']").hide();
751
-                   $('[class*="indupfldl"]').hide();
752
-                   $('[class*="indpckfldl"]').hide();
753
-                   $('#pf_submit_msg').hide();
754
-                   $('#filestotsize').hide();
755
-                   $('#faxdocpreview').hide();
756
-
757
-                   location.reload(true);
758
-                }
759
-             });
760
-
761
-         } else {
762
-              $('#pf_submit_msg').hide();
763
-              $('#faxdocpreview').removeClass('icon-loading');
764
-              alert("Please enter the fax number of the recipient !");
765
-         }
766
-
767
-     } else {
768
-              $('#pf_submit_msg').hide();
769
-              $('#faxdocpreview').removeClass('icon-loading');
770
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
771
-     }
772
-  });
773
-
774
-  $("#receivedfaxdir").on("click", function(event){
775
-     $("#faxdocpreview").hide();
776
-     $("#faxfoldersview").show();
777
-     $("#faxfoldersview").addClass("icon-loading");
778
-     $("#faxfoldersview :last-child").remove();
779
-     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
780
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
781
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
782
-  });
783
-
784
-  $("#sentfaxdir").on("click", function(event){
785
-     $("#faxdocpreview").hide();
786
-     $("#faxfoldersview").show();
787
-     $("#faxfoldersview").addClass("icon-loading");
788
-     $("#faxfoldersview :last-child").remove();
789
-     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
790
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
791
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
792
-  });
793
-
794
-  $("#receivedfaileddir").on("click", function(event){
795
-     $("#faxdocpreview").hide();
796
-     $("#faxfoldersview").show();
797
-     $("#faxfoldersview").addClass("icon-loading");
798
-     $("#faxfoldersview :last-child").remove();
799
-     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
800
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
801
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
802
-  });
803
-
804
-  $("#sentfaileddir").on("click", function(event){
805
-     $("#faxdocpreview").hide();
806
-     $("#faxfoldersview").show();
807
-     $("#faxfoldersview").addClass("icon-loading");
808
-     $("#faxfoldersview :last-child").remove();
809
-     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
810
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
811
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
812
-  });
813
-
814
-  $(".indivflpckd").click(function(event){
815
-     $("#faxfoldersview").hide();
816
-  });
817
-
818
-  $(".indivflcls").on("click", function(event){
819
-     $("#faxfoldersview").hide();
820
-  });
821
-
822
-});
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 22/03/2023 19:45:04
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,822 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: { userid: userid },
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: { userid: userid },
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: { userid: userid },
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+
107
+  // Upload files to be faxed
108
+  $("#uploadfileforfax").change(function(e){
109
+
110
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
+     $('#faxdocpreview').addClass('icon-loading');
112
+     $('#filestotsize').show();
113
+
114
+     var userid = "<?php p($userId); ?>";
115
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
+
117
+     var formData = new FormData();
118
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
+
120
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
+
122
+     var fileup = $('#uploadfileforfax').val();
123
+     var fileuptrim = fileup.split('\\').pop();
124
+
125
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
+         var duplicatescheck = 1;
127
+     } else var duplicatescheck = 0;
128
+
129
+     var extension = fileup.replace(/^.*\./, '');
130
+
131
+     if (extension == fileup) {
132
+         extension = "";
133
+     } else {
134
+         extension = extension.toLowerCase();
135
+     }
136
+
137
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
+
139
+     if ($.inArray(extension, validExtensions) != -1) {
140
+
141
+       if (duplicatescheck == 0) {
142
+
143
+         if (currentflsize < 20971520) {
144
+
145
+            if (n < 21) {
146
+
147
+               uploadedtofax.push(fileuptrim);
148
+
149
+               $.ajax({
150
+                 url: baseUrl + '/' + userid,
151
+                 type: "POST",
152
+                 data: formData,
153
+                 cache: false,
154
+                 processData: false,
155
+                 contentType: false,
156
+                 success: function(totalflsize) {
157
+
158
+                   $('#filessizetext').text(totalflsize);
159
+
160
+                   // Check if the total file size is over 20 MB
161
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
+
163
+                   if (rectotfilesz > 20.00) {
164
+                       $('#filestotsize').css('color', '#ba3555');
165
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
+                       $('#submitfax').attr("disabled", true);
167
+                   } else {
168
+                       $('#submitfax').attr("disabled", false);
169
+                       $('#filestotsize').css('color', '#1eb16a');
170
+                     }
171
+
172
+
173
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
+                   n++;
175
+
176
+                   // Preview the file when you click on its name
177
+                   $("div:visible[id*='indfilediv']").each(function() {
178
+                        $(this).on("click", function(eventclck) {
179
+                           var faxfilenameinit = $(this).text();
180
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
+                           var faxfilename = faxfilenamesec.replace("X","");
182
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
+                           var extenlst = faxfilename.replace(/^.*\./, '');
184
+
185
+                           if (extenlst == faxfilename) {
186
+                               extenlst = "";
187
+                           } else {
188
+                               extenlst = extenlst.toLowerCase();
189
+                           }
190
+
191
+                           if (extenlst == 'pdf') {
192
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
+                                  $("#faxdocpreview").empty();
195
+                                  $("#faxdocpreview").append($iframe);
196
+                           } else if (extenlst == 'txt') {
197
+                                  $("#faxdocpreview").empty();
198
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
+                           } else if (extenlst == 'html') {
200
+                                  $("#faxdocpreview").empty();
201
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
+                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
+                           } else if (extenlst == 'png') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
+                           } else if (extenlst == 'odt') {
211
+                                  $("#faxdocpreview").empty();
212
+                                  function odfInit() {
213
+                                     var odfelement = document.getElementById("faxdocpreview");
214
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
+                                     odfcanvas.load(baseUrl);
216
+                                  }
217
+                                  window.setTimeout(odfInit, 0);
218
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
+                                  var xhr = new XMLHttpRequest();
221
+                                  xhr.responseType = 'arraybuffer';
222
+                                  xhr.open('GET', tiffile);
223
+                                  xhr.onload = function (evnt) {
224
+                                      var tiff = new Tiff({buffer: xhr.response});
225
+                                      var tifcanvas = tiff.toCanvas();
226
+                                      $("#faxdocpreview").empty();
227
+                                      $("#faxdocpreview").append(tifcanvas);
228
+                                  };
229
+                                  xhr.send();
230
+                           }
231
+
232
+                           $("#faxdocpreview").show();
233
+                           $("#faxfoldersview").hide();
234
+                        });
235
+                   });
236
+
237
+                   // Remove uploaded files
238
+                   $('[class*="indupfldl"]').last().click(function() {
239
+
240
+                           var userid = "<?php p($userId); ?>";
241
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
+
243
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
+
245
+                           var removedfilesplit = removedfilenameinit.split(") ");
246
+                           var removedflnb = parseInt(removedfilesplit[0]);
247
+
248
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
+                           $(this).hide();
250
+
251
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
+
253
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
+                                           return value != removedfilename;
255
+                           });
256
+
257
+                           $.ajax({
258
+                                   url: baseUrl + '/' + userid,
259
+                                   type: "POST",
260
+                                   data: { removedfilename: removedfilename },
261
+                                   success: function(totalflsize) {
262
+
263
+                                      $('#filessizetext').text(totalflsize);
264
+
265
+                                      // Check file size
266
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
+
268
+                                      if (rectotfilesz > 20.00) {
269
+                                          $('#filestotsize').css('color', '#ba3555');
270
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
+                                          $('#submitfax').attr("disabled", true);
272
+                                      } else {
273
+                                          $('#submitfax').attr("disabled", false);
274
+                                          $('#filestotsize').css('color', '#1eb16a');
275
+                                        }
276
+
277
+                                      // Rewrite order numbers for files that follow
278
+                                      --n;
279
+                                      $("div:visible[id*='indfilediv']").each(function() {
280
+
281
+                                          var getdivtext =  $(this).text();
282
+                                          var splitdivtext = getdivtext.split(") ");
283
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
+                                          var newnbvalue = currentnbvalue - 1;
285
+
286
+                                          if (currentnbvalue > removedflnb) {
287
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
+                                              $(this).text(replacedstr);
289
+                                          }
290
+                                      });
291
+
292
+                                      $("div:visible[id*='indflpicked']").each(function() {
293
+
294
+                                          var getdivtext =  $(this).text();
295
+                                          var splitdivtext = getdivtext.split(") ");
296
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
+                                          var newnbvalue = currentnbvalue - 1;
298
+
299
+                                          if (currentnbvalue > removedflnb) {
300
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
+                                              $(this).text(replacedstr);
302
+                                          }
303
+                                      });
304
+
305
+                                   },
306
+                                   error: function() {
307
+                                          alert('Error !');
308
+                                   }
309
+                           });
310
+
311
+                           $('#faxdocpreview').removeClass('icon-loading');
312
+                           $("#faxdocpreview").empty();
313
+                   });
314
+
315
+                   // Preview the uploaded file
316
+                   var faxfilename = e.target.files[0].name;
317
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
+
319
+                   if (extension == 'pdf') {
320
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
+                              $("#faxdocpreview").empty();
323
+                              $("#faxdocpreview").append($iframe);
324
+                   } else if (extension == 'txt') {
325
+                              var reader = new FileReader();
326
+                              reader.readAsText(e.target.files[0]);
327
+                              reader.onload = function(e) {
328
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
+                                  $("#faxdocpreview").empty();
330
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
+                              };
332
+                   } else if (extension == 'html') {
333
+                              var reader = new FileReader();
334
+                              reader.readAsText(e.target.files[0]);
335
+                              reader.onload = function(e) {
336
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
+                                  $("#faxdocpreview").empty();
338
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
+                              };
340
+                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
+                              $("#faxdocpreview").empty();
342
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
+
344
+                              var reader = new FileReader();
345
+                              reader.onload = function (e) {
346
+                                  readjpg[faxfilename] = e.target.result;
347
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
+                              }
349
+                              reader.readAsDataURL(e.target.files[0]);
350
+                   } else if (extension == 'png') {
351
+                              $("#faxdocpreview").empty();
352
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
+
354
+                              var reader = new FileReader();
355
+                              reader.onload = function (e) {
356
+                                  readpng[faxfilename] = e.target.result;
357
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
+                              }
359
+                              reader.readAsDataURL(e.target.files[0]);
360
+                   } else if (extension == 'odt') {
361
+                              $("#faxdocpreview").empty();
362
+                              function odfInit() {
363
+                                 var odfelement = document.getElementById("faxdocpreview");
364
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
+                                 odfcanvas.load(baseUrl);
366
+                              }
367
+                              window.setTimeout(odfInit, 0);
368
+                   } else if (extension == 'tif' || extension == 'tiff') {
369
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
+                              var xhr = new XMLHttpRequest();
371
+                              xhr.responseType = 'arraybuffer';
372
+                              xhr.open('GET', tiffile);
373
+                              xhr.onload = function (e) {
374
+                                  var tiff = new Tiff({buffer: xhr.response});
375
+                                  var tifcanvas = tiff.toCanvas();
376
+                                  $("#faxdocpreview").empty();
377
+                                  $("#faxdocpreview").append(tifcanvas);
378
+                              };
379
+                              xhr.send();
380
+                   }
381
+
382
+                   $("#faxdocpreview").show();
383
+                   $('#pf_upload_msg').hide();
384
+                   $('#faxdocpreview').removeClass('icon-loading');
385
+                   $("#faxfoldersview").hide();
386
+                 },
387
+                 error: function(data){
388
+                     alert('Error!');
389
+                 }
390
+               });
391
+
392
+            } else {
393
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
+                  $('#pf_upload_msg').hide();
395
+                  $('#faxdocpreview').removeClass('icon-loading');
396
+              }
397
+         } else {
398
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
+              $('#pf_upload_msg').hide();
400
+              $('#faxdocpreview').removeClass('icon-loading');
401
+           }
402
+       } else {
403
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
+            $('#pf_upload_msg').hide();
405
+            $('#faxdocpreview').removeClass('icon-loading');
406
+         }
407
+
408
+     } else {
409
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
+          $('#pf_upload_msg').hide();
411
+          $('#faxdocpreview').removeClass('icon-loading');
412
+       }
413
+  });
414
+
415
+
416
+  // Pick file to fax, from Nextcloud
417
+  var faxfilename = null;
418
+
419
+  $("#choosefilen").on("click", function(evn) {
420
+
421
+                OC.dialogs.filepicker(
422
+                        t('settings', "Select a file to send as fax."),
423
+                        function (path) {
424
+
425
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
+                              $('#faxdocpreview').addClass('icon-loading');
427
+                              $('#filestotsize').show();
428
+
429
+                              var userid = "<?php p($userId); ?>";
430
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
+
432
+                              faxfilename = path.split('/').pop();
433
+
434
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
+                                  var duplicatescheck = 1;
436
+                              } else var duplicatescheck = 0;
437
+
438
+                              var extension = faxfilename.replace(/^.*\./, '');
439
+
440
+                              if (extension == faxfilename) {
441
+                                  extension = "";
442
+                              } else {
443
+                                  extension = extension.toLowerCase();
444
+                              }
445
+
446
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
+
448
+                              if ($.inArray(extension, validExtensions) != -1) {
449
+
450
+                                 if (duplicatescheck == 0) {
451
+
452
+                                    if (n < 21) {
453
+
454
+                                       uploadedtofax.push(faxfilename);
455
+
456
+                                       $.ajax({
457
+                                          url: baseUrl + '/' + userid,
458
+                                          type: "POST",
459
+                                          data: { path: path },
460
+                                          success: function(totalflsize) {
461
+
462
+                                                $('#filessizetext').text(totalflsize);
463
+
464
+                                                // Check if the total file size is over 20 MB
465
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
+
467
+                                                if (rectotfilesz > 20.00) {
468
+                                                    $('#filestotsize').css('color', '#ba3555');
469
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
+                                                    $('#submitfax').attr("disabled", true);
471
+                                                } else {
472
+                                                    $('#submitfax').attr("disabled", false);
473
+                                                    $('#filestotsize').css('color', '#1eb16a');
474
+                                                }
475
+
476
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
+                                                n++;
478
+
479
+                                                // Preview each file when you click on its name
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
+//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
+                                                      } else if (extenlst == 'png') {
510
+                                                              $("#faxdocpreview").empty();
511
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
+//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
+                                                      } else if (extenlst == 'odt') {
514
+                                                              $("#faxdocpreview").empty();
515
+                                                              function odfInit() {
516
+                                                                 var odfelement = document.getElementById("faxdocpreview");
517
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
+                                                                 odfcanvas.load(baseUrl);
519
+                                                              }
520
+                                                              window.setTimeout(odfInit, 0);
521
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
+                                                              var xhr = new XMLHttpRequest();
524
+                                                              xhr.responseType = 'arraybuffer';
525
+                                                              xhr.open('GET', tiffile);
526
+                                                              xhr.onload = function (evnt) {
527
+                                                                  var tiff = new Tiff({buffer: xhr.response});
528
+                                                                  var tifcanvas = tiff.toCanvas();
529
+                                                                  $("#faxdocpreview").empty();
530
+                                                                  $("#faxdocpreview").append(tifcanvas);
531
+                                                              };
532
+                                                              xhr.send();
533
+                                                      }
534
+
535
+                                                      $("#faxdocpreview").show();
536
+                                                      $("#faxfoldersview").hide();
537
+                                                   });
538
+                                                });
539
+
540
+                                                // Remove picked files
541
+                                                $('[class*="indpckfldl"]').last().click(function() {
542
+                                                    var userid = "<?php p($userId); ?>";
543
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
+
545
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
+
547
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
+
550
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
+                                                    $(this).hide();
552
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
+
554
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
+                                                             return value != removedfilename;
556
+                                                    });
557
+
558
+                                                    $.ajax({
559
+                                                        url: baseUrl + '/' + userid,
560
+                                                        type: "POST",
561
+                                                        data: { removedfilename: removedfilename },
562
+                                                        success: function(totalflsize) {
563
+
564
+                                                             $('#filessizetext').text(totalflsize);
565
+
566
+                                                             // Check file size
567
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
+
569
+                                                             if (rectotfilesz > 20.00) {
570
+                                                                 $('#filestotsize').css('color', '#ba3555');
571
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
+                                                                 $('#submitfax').attr("disabled", true);
573
+                                                             } else {
574
+                                                                 $('#submitfax').attr("disabled", false);
575
+                                                                 $('#filestotsize').css('color', '#1eb16a');
576
+                                                               }
577
+
578
+                                                             // Rewrite order numbers for files that follow
579
+                                                             --n;
580
+                                                             $("div:visible[id*='indflpicked']").each(function() {
581
+
582
+                                                                  var getdivtext =  $(this).text();
583
+                                                                  var splitdivtext = getdivtext.split(") ");
584
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
+                                                                  var newnbvalue = currentnbvalue - 1;
586
+
587
+                                                                  if (currentnbvalue > removedflnb) {
588
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
+                                                                      $(this).text(replacedstr);
590
+                                                                  }
591
+                                                             });
592
+                                                        },
593
+                                                        error: function() {
594
+                                                             alert('Error !');
595
+                                                        }
596
+                                                    });
597
+
598
+                                                    $('#faxdocpreview').removeClass('icon-loading');
599
+                                                    $("#faxdocpreview").empty();
600
+                                                });
601
+
602
+
603
+		                                // Preview the picked file
604
+		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
+		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
+
607
+		                                if (extension == 'pdf') {
608
+		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
+		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
+		                                    $("#faxdocpreview").empty();
611
+		                                    $("#faxdocpreview").append($iframe);
612
+		                                } else if (extension == 'txt') {
613
+						           $.get(flUrl, function(textdata) {
614
+		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
+		                                             $("#faxdocpreview").empty();
616
+		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
+							   });
618
+		                                } else if (extension == 'html') {
619
+							   $.get(flUrl, function(htmldata) {
620
+		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
+		                                             $("#faxdocpreview").empty();
622
+		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
+							   });
624
+		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
+		                                           $("#faxdocpreview").empty();
626
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
+		                                } else if (extension == 'png') {
628
+		                                           $("#faxdocpreview").empty();
629
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
+                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
+		                                } else if (extension == 'odt') {
632
+		                                       $("#faxdocpreview").empty();
633
+		                                       function odfInit() {
634
+		                                           var odfelement = document.getElementById("faxdocpreview");
635
+		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
+		                                           odfcanvas.load(flUrl);
637
+		                                       }
638
+		                                       window.setTimeout(odfInit, 0);
639
+
640
+		                                } else if (extension == 'tif' || extension == 'tiff') {
641
+		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
+		                                       var xhr = new XMLHttpRequest();
643
+		                                       xhr.responseType = 'arraybuffer';
644
+		                                       xhr.open('GET', tiffile);
645
+		                                       xhr.onload = function (event) {
646
+		                                           var tiff = new Tiff({buffer: xhr.response});
647
+		                                           var tifcanvas = tiff.toCanvas();
648
+		                                           $("#faxdocpreview").empty();
649
+		                                           $("#faxdocpreview").append(tifcanvas);
650
+		                                       };
651
+		                                       xhr.send();
652
+		                                }
653
+
654
+		                                $("#faxdocpreview").show();
655
+
656
+		                                $('#pf_choose_msg').hide();
657
+		                                $('#faxdocpreview').removeClass('icon-loading');
658
+		                                $("#faxfoldersview").hide();
659
+
660
+                                          },
661
+
662
+                                          error: function(data){
663
+                                             alert('Error!');
664
+                                          }
665
+
666
+                                       });
667
+
668
+                                    } else {
669
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
+                                        $('#pf_choose_msg').hide();
671
+                                        $('#faxdocpreview').removeClass('icon-loading');
672
+                                      }
673
+                                 } else {
674
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
+                                      $('#pf_choose_msg').hide();
676
+                                      $('#faxdocpreview').removeClass('icon-loading');
677
+                                   }
678
+
679
+                              } else {
680
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
+                                   $('#pf_choose_msg').hide();
682
+                                   $('#faxdocpreview').removeClass('icon-loading');
683
+                                }
684
+
685
+                        }
686
+                );
687
+  });
688
+
689
+
690
+  // Submit the fax
691
+  $("#submitfax").on("click", function(event){
692
+
693
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
+
695
+     var toNumberinit = $('#faxto').val();
696
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
+     var toNumber = toNumbersec.split(",");
698
+
699
+     for(var v = 0; v < toNumber.length; v++) {
700
+         toNumber[v] = "+" + toNumber[v];
701
+     }
702
+
703
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
+     $('#faxdocpreview').addClass('icon-loading');
705
+
706
+     $('#submitfax').attr("disabled", true);
707
+
708
+     var userid = "<?php p($userId); ?>";
709
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
710
+
711
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
712
+
713
+     if (uploadedtofax.length != 0) {
714
+
715
+         if (toNumberwc != '') {
716
+
717
+             $.ajax({
718
+                url: baseUrl + '/' + userid,
719
+                type: "POST",
720
+                data: {
721
+                       uploadedtofax: uploadedtofax,
722
+                       selectedcid: selectedcid,
723
+                       toNumber: toNumber
724
+                      },
725
+                success: function(phaxioresult) {
726
+
727
+                   if (phaxioresult.success == true) {
728
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
729
+                   } else {
730
+                       alert("Error ! The fax couldn't be sent because of the following error: "+ phaxioresult.errortype +" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
731
+                   }
732
+
733
+                   $("div:visible[id*='indfilediv']").hide();
734
+                   $("div:visible[id*='indflpicked']").hide();
735
+                   $('[class*="indupfldl"]').hide();
736
+                   $('[class*="indpckfldl"]').hide();
737
+                   $('#faxdocpreview').hide();
738
+                   $('#filestotsize').hide();
739
+                   $('#pf_submit_msg').hide();
740
+
741
+                   location.reload(true);
742
+
743
+                },
744
+
745
+                error: function(phaxioresult) {
746
+
747
+                   alert('Error ! Please check your settings !');
748
+
749
+                   $("div:visible[id*='indfilediv']").hide();
750
+                   $("div:visible[id*='indflpicked']").hide();
751
+                   $('[class*="indupfldl"]').hide();
752
+                   $('[class*="indpckfldl"]').hide();
753
+                   $('#pf_submit_msg').hide();
754
+                   $('#filestotsize').hide();
755
+                   $('#faxdocpreview').hide();
756
+
757
+                   location.reload(true);
758
+                }
759
+             });
760
+
761
+         } else {
762
+              $('#pf_submit_msg').hide();
763
+              $('#faxdocpreview').removeClass('icon-loading');
764
+              alert("Please enter the fax number of the recipient !");
765
+         }
766
+
767
+     } else {
768
+              $('#pf_submit_msg').hide();
769
+              $('#faxdocpreview').removeClass('icon-loading');
770
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
771
+     }
772
+  });
773
+
774
+  $("#receivedfaxdir").on("click", function(event){
775
+     $("#faxdocpreview").hide();
776
+     $("#faxfoldersview").show();
777
+     $("#faxfoldersview").addClass("icon-loading");
778
+     $("#faxfoldersview :last-child").remove();
779
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
780
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
781
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
782
+  });
783
+
784
+  $("#sentfaxdir").on("click", function(event){
785
+     $("#faxdocpreview").hide();
786
+     $("#faxfoldersview").show();
787
+     $("#faxfoldersview").addClass("icon-loading");
788
+     $("#faxfoldersview :last-child").remove();
789
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
790
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
791
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
792
+  });
793
+
794
+  $("#receivedfaileddir").on("click", function(event){
795
+     $("#faxdocpreview").hide();
796
+     $("#faxfoldersview").show();
797
+     $("#faxfoldersview").addClass("icon-loading");
798
+     $("#faxfoldersview :last-child").remove();
799
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
800
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
801
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
802
+  });
803
+
804
+  $("#sentfaileddir").on("click", function(event){
805
+     $("#faxdocpreview").hide();
806
+     $("#faxfoldersview").show();
807
+     $("#faxfoldersview").addClass("icon-loading");
808
+     $("#faxfoldersview :last-child").remove();
809
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
810
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
811
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
812
+  });
813
+
814
+  $(".indivflpckd").click(function(event){
815
+     $("#faxfoldersview").hide();
816
+  });
817
+
818
+  $(".indivflcls").on("click", function(event){
819
+     $("#faxfoldersview").hide();
820
+  });
821
+
822
+});
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 22/03/2023 19:26:29
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,831 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
-  var locHref = window.location.href;
33
-  var pathSplit = locHref.split('/');
34
-  var firstPathEl = '';
35
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
-
37
-  // Check the available balance
38
-  $("#checkbalance").on("click", function(event) {
39
-
40
-     $('#checkbalance').addClass('icon-loading');
41
-
42
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
-
44
-     $.ajax({
45
-          url: getbalanceUrl + '/' + userid,
46
-          type: "POST",
47
-          data: {userid: userid},
48
-          cache: false,
49
-          processData: false,
50
-          contentType: false,
51
-          success: function(phaxiobalance) {
52
-                 var balanceindlrs = phaxiobalance / 100;
53
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
-                 $('#currentbalance').text(balanceproc);
55
-
56
-                 $('#checkbalance').removeClass('icon-loading');
57
-          }
58
-     });
59
-  });
60
-
61
-  // Select the Caller ID
62
-  $("#selectcalleridbttn").on("click", function(event) {
63
-
64
-     $('#selectcalleridbttn').addClass('icon-loading');
65
-
66
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
-     var selectednmbr = null;
68
-
69
-     $.ajax({
70
-          url: getfaxnumbersUrl + '/' + userid,
71
-          type: "POST",
72
-          data: {userid: userid},
73
-          cache: false,
74
-          processData: false,
75
-          contentType: false,
76
-          success: function(phaxionmbrs) {
77
-
78
-                    $('#currentfaxnmbrs').empty();
79
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
-
82
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
-                    });
85
-
86
-                    $('#selectcalleridbttn').removeClass('icon-loading');
87
-
88
-          }
89
-     });
90
-  });
91
-
92
-  // Clean the Pax_Fax/temp_files directory
93
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
-
95
-  $.ajax({
96
-          url: cleanflUrl + '/' + userid,
97
-          type: "POST",
98
-          data: {userid: userid},
99
-          cache: false,
100
-          processData: false,
101
-          contentType: false
102
-  });
103
-
104
-  var n = 1;
105
-  var uploadedtofax = [];
106
-
107
-  // Upload files to be faxed
108
-  $("#uploadfileforfax").change(function(e){
109
-
110
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
-     $('#faxdocpreview').addClass('icon-loading');
112
-     $('#filestotsize').show();
113
-
114
-     var userid = "<?php p($userId); ?>";
115
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
-
117
-     var formData = new FormData();
118
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
-
120
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
-
122
-     var fileup = $('#uploadfileforfax').val();
123
-     var fileuptrim = fileup.split('\\').pop();
124
-
125
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
-         var duplicatescheck = 1;
127
-     } else var duplicatescheck = 0;
128
-
129
-     var extension = fileup.replace(/^.*\./, '');
130
-
131
-     if (extension == fileup) {
132
-         extension = "";
133
-     } else {
134
-         extension = extension.toLowerCase();
135
-     }
136
-
137
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
-
139
-     if ($.inArray(extension, validExtensions) != -1) {
140
-
141
-       if (duplicatescheck == 0) {
142
-
143
-         if (currentflsize < 20971520) {
144
-
145
-            if (n < 21) {
146
-
147
-               uploadedtofax.push(fileuptrim);
148
-
149
-               $.ajax({
150
-                 url: baseUrl + '/' + userid,
151
-                 type: "POST",
152
-                 data: formData,
153
-                 cache: false,
154
-                 processData: false,
155
-                 contentType: false,
156
-                 success: function(totalflsize) {
157
-
158
-                   $('#filessizetext').text(totalflsize);
159
-
160
-                   // Check if the total file size is over 20 MB
161
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
-
163
-                   if (rectotfilesz > 20.00) {
164
-                       $('#filestotsize').css('color', '#ba3555');
165
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
-                       $('#submitfax').attr("disabled", true);
167
-                   } else {
168
-                       $('#submitfax').attr("disabled", false);
169
-                       $('#filestotsize').css('color', '#1eb16a');
170
-                     }
171
-
172
-
173
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
-                   n++;
175
-
176
-                   // Preview the file when you click on its name
177
-                   $("div:visible[id*='indfilediv']").each(function() {
178
-                        $(this).on("click", function(eventclck) {
179
-                           var faxfilenameinit = $(this).text();
180
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
-                           var faxfilename = faxfilenamesec.replace("X","");
182
-                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
-                           var extenlst = faxfilename.replace(/^.*\./, '');
184
-
185
-                           if (extenlst == faxfilename) {
186
-                               extenlst = "";
187
-                           } else {
188
-                               extenlst = extenlst.toLowerCase();
189
-                           }
190
-
191
-                           if (extenlst == 'pdf') {
192
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
-                                  $("#faxdocpreview").empty();
195
-                                  $("#faxdocpreview").append($iframe);
196
-                           } else if (extenlst == 'txt') {
197
-                                  $("#faxdocpreview").empty();
198
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
-                           } else if (extenlst == 'html') {
200
-                                  $("#faxdocpreview").empty();
201
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
-                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
-                                  $("#faxdocpreview").empty();
204
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
-                           } else if (extenlst == 'png') {
207
-                                  $("#faxdocpreview").empty();
208
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
-                           } else if (extenlst == 'odt') {
211
-                                  $("#faxdocpreview").empty();
212
-                                  function odfInit() {
213
-                                     var odfelement = document.getElementById("faxdocpreview");
214
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
-                                     odfcanvas.load(baseUrl);
216
-                                  }
217
-                                  window.setTimeout(odfInit, 0);
218
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
-                                  var xhr = new XMLHttpRequest();
221
-                                  xhr.responseType = 'arraybuffer';
222
-                                  xhr.open('GET', tiffile);
223
-                                  xhr.onload = function (evnt) {
224
-                                      var tiff = new Tiff({buffer: xhr.response});
225
-                                      var tifcanvas = tiff.toCanvas();
226
-                                      $("#faxdocpreview").empty();
227
-                                      $("#faxdocpreview").append(tifcanvas);
228
-                                  };
229
-                                  xhr.send();
230
-                           }
231
-
232
-                           $("#faxdocpreview").show();
233
-                           $("#faxfoldersview").hide();
234
-                        });
235
-                   });
236
-
237
-                   // Remove uploaded files
238
-                   $('[class*="indupfldl"]').last().click(function() {
239
-
240
-                           var userid = "<?php p($userId); ?>";
241
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
-
243
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
-
245
-                           var removedfilesplit = removedfilenameinit.split(") ");
246
-                           var removedflnb = parseInt(removedfilesplit[0]);
247
-
248
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
-                           $(this).hide();
250
-
251
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
-
253
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
-                                           return value != removedfilename;
255
-                           });
256
-
257
-                           $.ajax({
258
-                                   url: baseUrl + '/' + userid,
259
-                                   type: "POST",
260
-                                   data: {removedfilename: removedfilename},
261
-                                   success: function(totalflsize) {
262
-
263
-                                      $('#filessizetext').text(totalflsize);
264
-
265
-                                      // Check file size
266
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
-
268
-                                      if (rectotfilesz > 20.00) {
269
-                                          $('#filestotsize').css('color', '#ba3555');
270
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
-                                          $('#submitfax').attr("disabled", true);
272
-                                      } else {
273
-                                          $('#submitfax').attr("disabled", false);
274
-                                          $('#filestotsize').css('color', '#1eb16a');
275
-                                        }
276
-
277
-                                      // Rewrite order numbers for files that follow
278
-                                      --n;
279
-                                      $("div:visible[id*='indfilediv']").each(function() {
280
-
281
-                                          var getdivtext =  $(this).text();
282
-                                          var splitdivtext = getdivtext.split(") ");
283
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
-                                          var newnbvalue = currentnbvalue - 1;
285
-
286
-                                          if (currentnbvalue > removedflnb) {
287
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
-                                              $(this).text(replacedstr);
289
-                                          }
290
-                                      });
291
-
292
-                                      $("div:visible[id*='indflpicked']").each(function() {
293
-
294
-                                          var getdivtext =  $(this).text();
295
-                                          var splitdivtext = getdivtext.split(") ");
296
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
-                                          var newnbvalue = currentnbvalue - 1;
298
-
299
-                                          if (currentnbvalue > removedflnb) {
300
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
-                                              $(this).text(replacedstr);
302
-                                          }
303
-                                      });
304
-
305
-                                   },
306
-                                   error: function() {
307
-                                          alert('Error !');
308
-                                   }
309
-                           });
310
-
311
-                           $('#faxdocpreview').removeClass('icon-loading');
312
-                           $("#faxdocpreview").empty();
313
-                   });
314
-
315
-                   // Preview the uploaded file
316
-                   var faxfilename = e.target.files[0].name;
317
-                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
-
319
-                   if (extension == 'pdf') {
320
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
-                              $("#faxdocpreview").empty();
323
-                              $("#faxdocpreview").append($iframe);
324
-                   } else if (extension == 'txt') {
325
-                              var reader = new FileReader();
326
-                              reader.readAsText(e.target.files[0]);
327
-                              reader.onload = function(e) {
328
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
-                                  $("#faxdocpreview").empty();
330
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
-                              };
332
-                   } else if (extension == 'html') {
333
-                              var reader = new FileReader();
334
-                              reader.readAsText(e.target.files[0]);
335
-                              reader.onload = function(e) {
336
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
-                                  $("#faxdocpreview").empty();
338
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
-                              };
340
-                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
-                              $("#faxdocpreview").empty();
342
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
-
344
-                              var reader = new FileReader();
345
-                              reader.onload = function (e) {
346
-                                  readjpg[faxfilename] = e.target.result;
347
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
-                              }
349
-                              reader.readAsDataURL(e.target.files[0]);
350
-                   } else if (extension == 'png') {
351
-                              $("#faxdocpreview").empty();
352
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
-
354
-                              var reader = new FileReader();
355
-                              reader.onload = function (e) {
356
-                                  readpng[faxfilename] = e.target.result;
357
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
-                              }
359
-                              reader.readAsDataURL(e.target.files[0]);
360
-                   } else if (extension == 'odt') {
361
-                              $("#faxdocpreview").empty();
362
-                              function odfInit() {
363
-                                 var odfelement = document.getElementById("faxdocpreview");
364
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
-                                 odfcanvas.load(baseUrl);
366
-                              }
367
-                              window.setTimeout(odfInit, 0);
368
-                   } else if (extension == 'tif' || extension == 'tiff') {
369
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
-                              var xhr = new XMLHttpRequest();
371
-                              xhr.responseType = 'arraybuffer';
372
-                              xhr.open('GET', tiffile);
373
-                              xhr.onload = function (e) {
374
-                                  var tiff = new Tiff({buffer: xhr.response});
375
-                                  var tifcanvas = tiff.toCanvas();
376
-                                  $("#faxdocpreview").empty();
377
-                                  $("#faxdocpreview").append(tifcanvas);
378
-                              };
379
-                              xhr.send();
380
-                   }
381
-
382
-                   $("#faxdocpreview").show();
383
-                   $('#pf_upload_msg').hide();
384
-                   $('#faxdocpreview').removeClass('icon-loading');
385
-                   $("#faxfoldersview").hide();
386
-                 },
387
-                 error: function(data){
388
-                     alert('Error!');
389
-                 }
390
-               });
391
-
392
-            } else {
393
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
-                  $('#pf_upload_msg').hide();
395
-                  $('#faxdocpreview').removeClass('icon-loading');
396
-              }
397
-         } else {
398
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
-              $('#pf_upload_msg').hide();
400
-              $('#faxdocpreview').removeClass('icon-loading');
401
-           }
402
-       } else {
403
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
-            $('#pf_upload_msg').hide();
405
-            $('#faxdocpreview').removeClass('icon-loading');
406
-         }
407
-
408
-     } else {
409
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
-          $('#pf_upload_msg').hide();
411
-          $('#faxdocpreview').removeClass('icon-loading');
412
-       }
413
-  });
414
-
415
-
416
-  // Pick file to fax, from Nextcloud
417
-  var faxfilename = null;
418
-
419
-  $("#choosefilen").on("click", function(evn) {
420
-
421
-                OC.dialogs.filepicker(
422
-                        t('settings', "Select a file to send as fax."),
423
-                        function (path) {
424
-
425
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
-                              $('#faxdocpreview').addClass('icon-loading');
427
-                              $('#filestotsize').show();
428
-
429
-                              var userid = "<?php p($userId); ?>";
430
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
-
432
-                              faxfilename = path.split('/').pop();
433
-
434
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
-                                  var duplicatescheck = 1;
436
-                              } else var duplicatescheck = 0;
437
-
438
-                              var extension = faxfilename.replace(/^.*\./, '');
439
-
440
-                              if (extension == faxfilename) {
441
-                                  extension = "";
442
-                              } else {
443
-                                  extension = extension.toLowerCase();
444
-                              }
445
-
446
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
-
448
-                              if ($.inArray(extension, validExtensions) != -1) {
449
-
450
-                                 if (duplicatescheck == 0) {
451
-
452
-                                    if (n < 21) {
453
-
454
-                                       uploadedtofax.push(faxfilename);
455
-
456
-                                       $.ajax({
457
-                                          url: baseUrl + '/' + userid,
458
-                                          type: "POST",
459
-                                          data: {path: path},
460
-                                          success: function(totalflsize) {
461
-
462
-                                                $('#filessizetext').text(totalflsize);
463
-
464
-                                                // Check if the total file size is over 20 MB
465
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
-
467
-                                                if (rectotfilesz > 20.00) {
468
-                                                    $('#filestotsize').css('color', '#ba3555');
469
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
-                                                    $('#submitfax').attr("disabled", true);
471
-                                                } else {
472
-                                                    $('#submitfax').attr("disabled", false);
473
-                                                    $('#filestotsize').css('color', '#1eb16a');
474
-                                                }
475
-
476
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
-                                                n++;
478
-
479
-                                                // Preview each file when you click on its name
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
-//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
-                                                      } else if (extenlst == 'png') {
510
-                                                              $("#faxdocpreview").empty();
511
-                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
-//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
-                                                      } else if (extenlst == 'odt') {
514
-                                                              $("#faxdocpreview").empty();
515
-                                                              function odfInit() {
516
-                                                                 var odfelement = document.getElementById("faxdocpreview");
517
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
-                                                                 odfcanvas.load(baseUrl);
519
-                                                              }
520
-                                                              window.setTimeout(odfInit, 0);
521
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
-                                                              var xhr = new XMLHttpRequest();
524
-                                                              xhr.responseType = 'arraybuffer';
525
-                                                              xhr.open('GET', tiffile);
526
-                                                              xhr.onload = function (evnt) {
527
-                                                                  var tiff = new Tiff({buffer: xhr.response});
528
-                                                                  var tifcanvas = tiff.toCanvas();
529
-                                                                  $("#faxdocpreview").empty();
530
-                                                                  $("#faxdocpreview").append(tifcanvas);
531
-                                                              };
532
-                                                              xhr.send();
533
-                                                      }
534
-
535
-                                                      $("#faxdocpreview").show();
536
-                                                      $("#faxfoldersview").hide();
537
-                                                   });
538
-                                                });
539
-
540
-                                                // Remove picked files
541
-                                                $('[class*="indpckfldl"]').last().click(function() {
542
-                                                    var userid = "<?php p($userId); ?>";
543
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
-
545
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
-
547
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
-
550
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
-                                                    $(this).hide();
552
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
-
554
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
-                                                             return value != removedfilename;
556
-                                                    });
557
-
558
-                                                    $.ajax({
559
-                                                        url: baseUrl + '/' + userid,
560
-                                                        type: "POST",
561
-                                                        data: {removedfilename: removedfilename},
562
-                                                        success: function(totalflsize) {
563
-
564
-                                                             $('#filessizetext').text(totalflsize);
565
-
566
-                                                             // Check file size
567
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
-
569
-                                                             if (rectotfilesz > 20.00) {
570
-                                                                 $('#filestotsize').css('color', '#ba3555');
571
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
-                                                                 $('#submitfax').attr("disabled", true);
573
-                                                             } else {
574
-                                                                 $('#submitfax').attr("disabled", false);
575
-                                                                 $('#filestotsize').css('color', '#1eb16a');
576
-                                                               }
577
-
578
-                                                             // Rewrite order numbers for files that follow
579
-                                                             --n;
580
-                                                             $("div:visible[id*='indflpicked']").each(function() {
581
-
582
-                                                                  var getdivtext =  $(this).text();
583
-                                                                  var splitdivtext = getdivtext.split(") ");
584
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
-                                                                  var newnbvalue = currentnbvalue - 1;
586
-
587
-                                                                  if (currentnbvalue > removedflnb) {
588
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
-                                                                      $(this).text(replacedstr);
590
-                                                                  }
591
-                                                             });
592
-                                                        },
593
-                                                        error: function() {
594
-                                                             alert('Error !');
595
-                                                        }
596
-                                                    });
597
-
598
-                                                    $('#faxdocpreview').removeClass('icon-loading');
599
-                                                    $("#faxdocpreview").empty();
600
-                                                });
601
-
602
-
603
-		                                // Preview the picked file
604
-		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
-		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
-
607
-		                                if (extension == 'pdf') {
608
-		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
-		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
-		                                    $("#faxdocpreview").empty();
611
-		                                    $("#faxdocpreview").append($iframe);
612
-		                                } else if (extension == 'txt') {
613
-						           $.get(flUrl, function(textdata) {
614
-		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
-		                                             $("#faxdocpreview").empty();
616
-		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
-							   });
618
-		                                } else if (extension == 'html') {
619
-							   $.get(flUrl, function(htmldata) {
620
-		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
-		                                             $("#faxdocpreview").empty();
622
-		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
-							   });
624
-		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
-		                                           $("#faxdocpreview").empty();
626
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
-		                                } else if (extension == 'png') {
628
-		                                           $("#faxdocpreview").empty();
629
-		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
-                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
-		                                } else if (extension == 'odt') {
632
-		                                       $("#faxdocpreview").empty();
633
-		                                       function odfInit() {
634
-		                                           var odfelement = document.getElementById("faxdocpreview");
635
-		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
-		                                           odfcanvas.load(flUrl);
637
-		                                       }
638
-		                                       window.setTimeout(odfInit, 0);
639
-
640
-		                                } else if (extension == 'tif' || extension == 'tiff') {
641
-		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
-		                                       var xhr = new XMLHttpRequest();
643
-		                                       xhr.responseType = 'arraybuffer';
644
-		                                       xhr.open('GET', tiffile);
645
-		                                       xhr.onload = function (event) {
646
-		                                           var tiff = new Tiff({buffer: xhr.response});
647
-		                                           var tifcanvas = tiff.toCanvas();
648
-		                                           $("#faxdocpreview").empty();
649
-		                                           $("#faxdocpreview").append(tifcanvas);
650
-		                                       };
651
-		                                       xhr.send();
652
-		                                }
653
-
654
-		                                $("#faxdocpreview").show();
655
-
656
-		                                $('#pf_choose_msg').hide();
657
-		                                $('#faxdocpreview').removeClass('icon-loading');
658
-		                                $("#faxfoldersview").hide();
659
-
660
-                                          },
661
-
662
-                                          error: function(data){
663
-                                             alert('Error!');
664
-                                          }
665
-
666
-                                       });
667
-
668
-                                    } else {
669
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
-                                        $('#pf_choose_msg').hide();
671
-                                        $('#faxdocpreview').removeClass('icon-loading');
672
-                                      }
673
-                                 } else {
674
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
-                                      $('#pf_choose_msg').hide();
676
-                                      $('#faxdocpreview').removeClass('icon-loading');
677
-                                   }
678
-
679
-                              } else {
680
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
-                                   $('#pf_choose_msg').hide();
682
-                                   $('#faxdocpreview').removeClass('icon-loading');
683
-                                }
684
-
685
-                        }
686
-                );
687
-  });
688
-
689
-
690
-  // Submit the fax
691
-  $("#submitfax").on("click", function(event){
692
-
693
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
-
695
-     var toNumberinit = $('#faxto').val();
696
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
-     var toNumber = toNumbersec.split(",");
698
-
699
-     for(var v = 0; v < toNumber.length; v++) {
700
-         toNumber[v] = "+" + toNumber[v];
701
-     }
702
-
703
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
-     $('#faxdocpreview').addClass('icon-loading');
705
-
706
-     var userid = "<?php p($userId); ?>";
707
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
708
-
709
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
710
-
711
-         if (uploadedtofax.length != 0) {
712
-
713
-           if (toNumberwc != '') {
714
-
715
-             $.ajax({
716
-                url: baseUrl + '/' + userid,
717
-                type: "POST",
718
-                data: {uploadedtofax: uploadedtofax,
719
-                       selectedcid: selectedcid,
720
-                       toNumber: toNumber
721
-                      },
722
-                success: function(phaxioresult) {
723
-
724
-                   if (phaxioresult.success == true) {
725
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
726
-                   } else {
727
-                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
728
-                   }
729
-
730
-                   $("div:visible[id*='indfilediv']").hide();
731
-                   $("div:visible[id*='indflpicked']").hide();
732
-                   $('[class*="indupfldl"]').hide();
733
-                   $('[class*="indpckfldl"]').hide();
734
-
735
-                   $('#faxdocpreview').hide();
736
-
737
-                   $('#filestotsize').hide();
738
-                   $('#submitfax').attr("disabled", true);
739
-                   $("#receivedfaxdir").attr("disabled", true);
740
-                   $("#sentfaxdir").attr("disabled", true);
741
-                   $("#receivedfaileddir").attr("disabled", true);
742
-                   $("#sentfaileddir").attr("disabled", true);
743
-
744
-                   location.reload(true);
745
-
746
-                },
747
-
748
-                error: function(phaxioresult) {
749
-
750
-                   alert('Error ! Please check your settings !');
751
-
752
-                   $("div:visible[id*='indfilediv']").hide();
753
-                   $("div:visible[id*='indflpicked']").hide();
754
-                   $('[class*="indupfldl"]').hide();
755
-                   $('[class*="indpckfldl"]').hide();
756
-
757
-                   $('#pf_submit_msg').hide();
758
-                   $('#filestotsize').hide();
759
-                   $('#faxdocpreview').hide();
760
-                   $('#submitfax').attr("disabled", true);
761
-
762
-
763
-                   $("#receivedfaxdir").attr("disabled", true);
764
-                   $("#sentfaxdir").attr("disabled", true);
765
-                   $("#receivedfaileddir").attr("disabled", true);
766
-                   $("#sentfaileddir").attr("disabled", true);
767
-
768
-                          location.reload(true);
769
-                }
770
-             });
771
-           } else {
772
-              $('#pf_submit_msg').hide();
773
-              $('#faxdocpreview').removeClass('icon-loading');
774
-              alert("Please enter the fax number of the recipient !");
775
-             }
776
-         } else {
777
-              $('#pf_submit_msg').hide();
778
-              $('#faxdocpreview').removeClass('icon-loading');
779
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
780
-           }
781
-  });
782
-
783
-  $("#receivedfaxdir").on("click", function(event){
784
-     $("#faxdocpreview").hide();
785
-     $("#faxfoldersview").show();
786
-     $("#faxfoldersview").addClass("icon-loading");
787
-     $("#faxfoldersview :last-child").remove();
788
-     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
789
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
790
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
791
-  });
792
-
793
-  $("#sentfaxdir").on("click", function(event){
794
-     $("#faxdocpreview").hide();
795
-     $("#faxfoldersview").show();
796
-     $("#faxfoldersview").addClass("icon-loading");
797
-     $("#faxfoldersview :last-child").remove();
798
-     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
799
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
800
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
801
-  });
802
-
803
-  $("#receivedfaileddir").on("click", function(event){
804
-     $("#faxdocpreview").hide();
805
-     $("#faxfoldersview").show();
806
-     $("#faxfoldersview").addClass("icon-loading");
807
-     $("#faxfoldersview :last-child").remove();
808
-     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
809
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
810
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
811
-  });
812
-
813
-  $("#sentfaileddir").on("click", function(event){
814
-     $("#faxdocpreview").hide();
815
-     $("#faxfoldersview").show();
816
-     $("#faxfoldersview").addClass("icon-loading");
817
-     $("#faxfoldersview :last-child").remove();
818
-     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
819
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
820
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
821
-  });
822
-
823
-  $(".indivflpckd").click(function(event){
824
-     $("#faxfoldersview").hide();
825
-  });
826
-
827
-  $(".indivflcls").on("click", function(event){
828
-     $("#faxfoldersview").hide();
829
-  });
830
-
831
-});
Browse code

added README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/sendfax.js templates/navigation/index.php lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 03/09/2022 21:02:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,831 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: {userid: userid},
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: {userid: userid},
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: {userid: userid},
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+
107
+  // Upload files to be faxed
108
+  $("#uploadfileforfax").change(function(e){
109
+
110
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
111
+     $('#faxdocpreview').addClass('icon-loading');
112
+     $('#filestotsize').show();
113
+
114
+     var userid = "<?php p($userId); ?>";
115
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
116
+
117
+     var formData = new FormData();
118
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
119
+
120
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
121
+
122
+     var fileup = $('#uploadfileforfax').val();
123
+     var fileuptrim = fileup.split('\\').pop();
124
+
125
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
126
+         var duplicatescheck = 1;
127
+     } else var duplicatescheck = 0;
128
+
129
+     var extension = fileup.replace(/^.*\./, '');
130
+
131
+     if (extension == fileup) {
132
+         extension = "";
133
+     } else {
134
+         extension = extension.toLowerCase();
135
+     }
136
+
137
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
138
+
139
+     if ($.inArray(extension, validExtensions) != -1) {
140
+
141
+       if (duplicatescheck == 0) {
142
+
143
+         if (currentflsize < 20971520) {
144
+
145
+            if (n < 21) {
146
+
147
+               uploadedtofax.push(fileuptrim);
148
+
149
+               $.ajax({
150
+                 url: baseUrl + '/' + userid,
151
+                 type: "POST",
152
+                 data: formData,
153
+                 cache: false,
154
+                 processData: false,
155
+                 contentType: false,
156
+                 success: function(totalflsize) {
157
+
158
+                   $('#filessizetext').text(totalflsize);
159
+
160
+                   // Check if the total file size is over 20 MB
161
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
162
+
163
+                   if (rectotfilesz > 20.00) {
164
+                       $('#filestotsize').css('color', '#ba3555');
165
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
166
+                       $('#submitfax').attr("disabled", true);
167
+                   } else {
168
+                       $('#submitfax').attr("disabled", false);
169
+                       $('#filestotsize').css('color', '#1eb16a');
170
+                     }
171
+
172
+
173
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
174
+                   n++;
175
+
176
+                   // Preview the file when you click on its name
177
+                   $("div:visible[id*='indfilediv']").each(function() {
178
+                        $(this).on("click", function(eventclck) {
179
+                           var faxfilenameinit = $(this).text();
180
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
181
+                           var faxfilename = faxfilenamesec.replace("X","");
182
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
183
+                           var extenlst = faxfilename.replace(/^.*\./, '');
184
+
185
+                           if (extenlst == faxfilename) {
186
+                               extenlst = "";
187
+                           } else {
188
+                               extenlst = extenlst.toLowerCase();
189
+                           }
190
+
191
+                           if (extenlst == 'pdf') {
192
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
193
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
194
+                                  $("#faxdocpreview").empty();
195
+                                  $("#faxdocpreview").append($iframe);
196
+                           } else if (extenlst == 'txt') {
197
+                                  $("#faxdocpreview").empty();
198
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
199
+                           } else if (extenlst == 'html') {
200
+                                  $("#faxdocpreview").empty();
201
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
202
+                           } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
205
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
206
+                           } else if (extenlst == 'png') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
209
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
210
+                           } else if (extenlst == 'odt') {
211
+                                  $("#faxdocpreview").empty();
212
+                                  function odfInit() {
213
+                                     var odfelement = document.getElementById("faxdocpreview");
214
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
215
+                                     odfcanvas.load(baseUrl);
216
+                                  }
217
+                                  window.setTimeout(odfInit, 0);
218
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
219
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
220
+                                  var xhr = new XMLHttpRequest();
221
+                                  xhr.responseType = 'arraybuffer';
222
+                                  xhr.open('GET', tiffile);
223
+                                  xhr.onload = function (evnt) {
224
+                                      var tiff = new Tiff({buffer: xhr.response});
225
+                                      var tifcanvas = tiff.toCanvas();
226
+                                      $("#faxdocpreview").empty();
227
+                                      $("#faxdocpreview").append(tifcanvas);
228
+                                  };
229
+                                  xhr.send();
230
+                           }
231
+
232
+                           $("#faxdocpreview").show();
233
+                           $("#faxfoldersview").hide();
234
+                        });
235
+                   });
236
+
237
+                   // Remove uploaded files
238
+                   $('[class*="indupfldl"]').last().click(function() {
239
+
240
+                           var userid = "<?php p($userId); ?>";
241
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
242
+
243
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
244
+
245
+                           var removedfilesplit = removedfilenameinit.split(") ");
246
+                           var removedflnb = parseInt(removedfilesplit[0]);
247
+
248
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
249
+                           $(this).hide();
250
+
251
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
252
+
253
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
254
+                                           return value != removedfilename;
255
+                           });
256
+
257
+                           $.ajax({
258
+                                   url: baseUrl + '/' + userid,
259
+                                   type: "POST",
260
+                                   data: {removedfilename: removedfilename},
261
+                                   success: function(totalflsize) {
262
+
263
+                                      $('#filessizetext').text(totalflsize);
264
+
265
+                                      // Check file size
266
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
267
+
268
+                                      if (rectotfilesz > 20.00) {
269
+                                          $('#filestotsize').css('color', '#ba3555');
270
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
271
+                                          $('#submitfax').attr("disabled", true);
272
+                                      } else {
273
+                                          $('#submitfax').attr("disabled", false);
274
+                                          $('#filestotsize').css('color', '#1eb16a');
275
+                                        }
276
+
277
+                                      // Rewrite order numbers for files that follow
278
+                                      --n;
279
+                                      $("div:visible[id*='indfilediv']").each(function() {
280
+
281
+                                          var getdivtext =  $(this).text();
282
+                                          var splitdivtext = getdivtext.split(") ");
283
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
284
+                                          var newnbvalue = currentnbvalue - 1;
285
+
286
+                                          if (currentnbvalue > removedflnb) {
287
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
288
+                                              $(this).text(replacedstr);
289
+                                          }
290
+                                      });
291
+
292
+                                      $("div:visible[id*='indflpicked']").each(function() {
293
+
294
+                                          var getdivtext =  $(this).text();
295
+                                          var splitdivtext = getdivtext.split(") ");
296
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
297
+                                          var newnbvalue = currentnbvalue - 1;
298
+
299
+                                          if (currentnbvalue > removedflnb) {
300
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
301
+                                              $(this).text(replacedstr);
302
+                                          }
303
+                                      });
304
+
305
+                                   },
306
+                                   error: function() {
307
+                                          alert('Error !');
308
+                                   }
309
+                           });
310
+
311
+                           $('#faxdocpreview').removeClass('icon-loading');
312
+                           $("#faxdocpreview").empty();
313
+                   });
314
+
315
+                   // Preview the uploaded file
316
+                   var faxfilename = e.target.files[0].name;
317
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
318
+
319
+                   if (extension == 'pdf') {
320
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
321
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
322
+                              $("#faxdocpreview").empty();
323
+                              $("#faxdocpreview").append($iframe);
324
+                   } else if (extension == 'txt') {
325
+                              var reader = new FileReader();
326
+                              reader.readAsText(e.target.files[0]);
327
+                              reader.onload = function(e) {
328
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
329
+                                  $("#faxdocpreview").empty();
330
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
331
+                              };
332
+                   } else if (extension == 'html') {
333
+                              var reader = new FileReader();
334
+                              reader.readAsText(e.target.files[0]);
335
+                              reader.onload = function(e) {
336
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
337
+                                  $("#faxdocpreview").empty();
338
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
339
+                              };
340
+                   } else if (extension == 'jpg' || extension == 'jpeg') {
341
+                              $("#faxdocpreview").empty();
342
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
343
+
344
+                              var reader = new FileReader();
345
+                              reader.onload = function (e) {
346
+                                  readjpg[faxfilename] = e.target.result;
347
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
348
+                              }
349
+                              reader.readAsDataURL(e.target.files[0]);
350
+                   } else if (extension == 'png') {
351
+                              $("#faxdocpreview").empty();
352
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
353
+
354
+                              var reader = new FileReader();
355
+                              reader.onload = function (e) {
356
+                                  readpng[faxfilename] = e.target.result;
357
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
358
+                              }
359
+                              reader.readAsDataURL(e.target.files[0]);
360
+                   } else if (extension == 'odt') {
361
+                              $("#faxdocpreview").empty();
362
+                              function odfInit() {
363
+                                 var odfelement = document.getElementById("faxdocpreview");
364
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
365
+                                 odfcanvas.load(baseUrl);
366
+                              }
367
+                              window.setTimeout(odfInit, 0);
368
+                   } else if (extension == 'tif' || extension == 'tiff') {
369
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
370
+                              var xhr = new XMLHttpRequest();
371
+                              xhr.responseType = 'arraybuffer';
372
+                              xhr.open('GET', tiffile);
373
+                              xhr.onload = function (e) {
374
+                                  var tiff = new Tiff({buffer: xhr.response});
375
+                                  var tifcanvas = tiff.toCanvas();
376
+                                  $("#faxdocpreview").empty();
377
+                                  $("#faxdocpreview").append(tifcanvas);
378
+                              };
379
+                              xhr.send();
380
+                   }
381
+
382
+                   $("#faxdocpreview").show();
383
+                   $('#pf_upload_msg').hide();
384
+                   $('#faxdocpreview').removeClass('icon-loading');
385
+                   $("#faxfoldersview").hide();
386
+                 },
387
+                 error: function(data){
388
+                     alert('Error!');
389
+                 }
390
+               });
391
+
392
+            } else {
393
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
394
+                  $('#pf_upload_msg').hide();
395
+                  $('#faxdocpreview').removeClass('icon-loading');
396
+              }
397
+         } else {
398
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
399
+              $('#pf_upload_msg').hide();
400
+              $('#faxdocpreview').removeClass('icon-loading');
401
+           }
402
+       } else {
403
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
404
+            $('#pf_upload_msg').hide();
405
+            $('#faxdocpreview').removeClass('icon-loading');
406
+         }
407
+
408
+     } else {
409
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
410
+          $('#pf_upload_msg').hide();
411
+          $('#faxdocpreview').removeClass('icon-loading');
412
+       }
413
+  });
414
+
415
+
416
+  // Pick file to fax, from Nextcloud
417
+  var faxfilename = null;
418
+
419
+  $("#choosefilen").on("click", function(evn) {
420
+
421
+                OC.dialogs.filepicker(
422
+                        t('settings', "Select a file to send as fax."),
423
+                        function (path) {
424
+
425
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
426
+                              $('#faxdocpreview').addClass('icon-loading');
427
+                              $('#filestotsize').show();
428
+
429
+                              var userid = "<?php p($userId); ?>";
430
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
431
+
432
+                              faxfilename = path.split('/').pop();
433
+
434
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
435
+                                  var duplicatescheck = 1;
436
+                              } else var duplicatescheck = 0;
437
+
438
+                              var extension = faxfilename.replace(/^.*\./, '');
439
+
440
+                              if (extension == faxfilename) {
441
+                                  extension = "";
442
+                              } else {
443
+                                  extension = extension.toLowerCase();
444
+                              }
445
+
446
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "jpeg", "odt", "txt", "html", "png"];
447
+
448
+                              if ($.inArray(extension, validExtensions) != -1) {
449
+
450
+                                 if (duplicatescheck == 0) {
451
+
452
+                                    if (n < 21) {
453
+
454
+                                       uploadedtofax.push(faxfilename);
455
+
456
+                                       $.ajax({
457
+                                          url: baseUrl + '/' + userid,
458
+                                          type: "POST",
459
+                                          data: {path: path},
460
+                                          success: function(totalflsize) {
461
+
462
+                                                $('#filessizetext').text(totalflsize);
463
+
464
+                                                // Check if the total file size is over 20 MB
465
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
466
+
467
+                                                if (rectotfilesz > 20.00) {
468
+                                                    $('#filestotsize').css('color', '#ba3555');
469
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
470
+                                                    $('#submitfax').attr("disabled", true);
471
+                                                } else {
472
+                                                    $('#submitfax').attr("disabled", false);
473
+                                                    $('#filestotsize').css('color', '#1eb16a');
474
+                                                }
475
+
476
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div>");
477
+                                                n++;
478
+
479
+                                                // Preview each file when you click on its name
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg' || extenlst == 'jpeg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
508
+//                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
+                                                      } else if (extenlst == 'png') {
510
+                                                              $("#faxdocpreview").empty();
511
+                                                              $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
512
+//                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
+                                                      } else if (extenlst == 'odt') {
514
+                                                              $("#faxdocpreview").empty();
515
+                                                              function odfInit() {
516
+                                                                 var odfelement = document.getElementById("faxdocpreview");
517
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
+                                                                 odfcanvas.load(baseUrl);
519
+                                                              }
520
+                                                              window.setTimeout(odfInit, 0);
521
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
+                                                              var xhr = new XMLHttpRequest();
524
+                                                              xhr.responseType = 'arraybuffer';
525
+                                                              xhr.open('GET', tiffile);
526
+                                                              xhr.onload = function (evnt) {
527
+                                                                  var tiff = new Tiff({buffer: xhr.response});
528
+                                                                  var tifcanvas = tiff.toCanvas();
529
+                                                                  $("#faxdocpreview").empty();
530
+                                                                  $("#faxdocpreview").append(tifcanvas);
531
+                                                              };
532
+                                                              xhr.send();
533
+                                                      }
534
+
535
+                                                      $("#faxdocpreview").show();
536
+                                                      $("#faxfoldersview").hide();
537
+                                                   });
538
+                                                });
539
+
540
+                                                // Remove picked files
541
+                                                $('[class*="indpckfldl"]').last().click(function() {
542
+                                                    var userid = "<?php p($userId); ?>";
543
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
+
545
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
+
547
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
+
550
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
+                                                    $(this).hide();
552
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
+
554
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
+                                                             return value != removedfilename;
556
+                                                    });
557
+
558
+                                                    $.ajax({
559
+                                                        url: baseUrl + '/' + userid,
560
+                                                        type: "POST",
561
+                                                        data: {removedfilename: removedfilename},
562
+                                                        success: function(totalflsize) {
563
+
564
+                                                             $('#filessizetext').text(totalflsize);
565
+
566
+                                                             // Check file size
567
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
+
569
+                                                             if (rectotfilesz > 20.00) {
570
+                                                                 $('#filestotsize').css('color', '#ba3555');
571
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
+                                                                 $('#submitfax').attr("disabled", true);
573
+                                                             } else {
574
+                                                                 $('#submitfax').attr("disabled", false);
575
+                                                                 $('#filestotsize').css('color', '#1eb16a');
576
+                                                               }
577
+
578
+                                                             // Rewrite order numbers for files that follow
579
+                                                             --n;
580
+                                                             $("div:visible[id*='indflpicked']").each(function() {
581
+
582
+                                                                  var getdivtext =  $(this).text();
583
+                                                                  var splitdivtext = getdivtext.split(") ");
584
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
+                                                                  var newnbvalue = currentnbvalue - 1;
586
+
587
+                                                                  if (currentnbvalue > removedflnb) {
588
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
+                                                                      $(this).text(replacedstr);
590
+                                                                  }
591
+                                                             });
592
+                                                        },
593
+                                                        error: function() {
594
+                                                             alert('Error !');
595
+                                                        }
596
+                                                    });
597
+
598
+                                                    $('#faxdocpreview').removeClass('icon-loading');
599
+                                                    $("#faxdocpreview").empty();
600
+                                                });
601
+
602
+
603
+		                                // Preview the picked file
604
+		                                var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
605
+		                                var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
606
+
607
+		                                if (extension == 'pdf') {
608
+		                                    var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
609
+		                                    var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
610
+		                                    $("#faxdocpreview").empty();
611
+		                                    $("#faxdocpreview").append($iframe);
612
+		                                } else if (extension == 'txt') {
613
+						           $.get(flUrl, function(textdata) {
614
+		                                             readtxtfile[faxfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
615
+		                                             $("#faxdocpreview").empty();
616
+		                                             $("#faxdocpreview").append(readtxtfile[faxfilename]);
617
+							   });
618
+		                                } else if (extension == 'html') {
619
+							   $.get(flUrl, function(htmldata) {
620
+		                                             readhtmlfile[faxfilename] = htmldata.replace(/(?:\r\n|\r|\n)/g, '<br>');
621
+		                                             $("#faxdocpreview").empty();
622
+		                                             $("#faxdocpreview").append(readhtmlfile[faxfilename]);
623
+							   });
624
+		                                } else if (extension == 'jpg' || extension == 'jpeg') {
625
+		                                           $("#faxdocpreview").empty();
626
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
627
+		                                } else if (extension == 'png') {
628
+		                                           $("#faxdocpreview").empty();
629
+		                                           $("#faxdocpreview").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
630
+                                                           $("#uploadedpng").attr('src', readpng[faxfilename]);
631
+		                                } else if (extension == 'odt') {
632
+		                                       $("#faxdocpreview").empty();
633
+		                                       function odfInit() {
634
+		                                           var odfelement = document.getElementById("faxdocpreview");
635
+		                                           odfcanvas = new odf.OdfCanvas(odfelement);
636
+		                                           odfcanvas.load(flUrl);
637
+		                                       }
638
+		                                       window.setTimeout(odfInit, 0);
639
+
640
+		                                } else if (extension == 'tif' || extension == 'tiff') {
641
+		                                       var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
642
+		                                       var xhr = new XMLHttpRequest();
643
+		                                       xhr.responseType = 'arraybuffer';
644
+		                                       xhr.open('GET', tiffile);
645
+		                                       xhr.onload = function (event) {
646
+		                                           var tiff = new Tiff({buffer: xhr.response});
647
+		                                           var tifcanvas = tiff.toCanvas();
648
+		                                           $("#faxdocpreview").empty();
649
+		                                           $("#faxdocpreview").append(tifcanvas);
650
+		                                       };
651
+		                                       xhr.send();
652
+		                                }
653
+
654
+		                                $("#faxdocpreview").show();
655
+
656
+		                                $('#pf_choose_msg').hide();
657
+		                                $('#faxdocpreview').removeClass('icon-loading');
658
+		                                $("#faxfoldersview").hide();
659
+
660
+                                          },
661
+
662
+                                          error: function(data){
663
+                                             alert('Error!');
664
+                                          }
665
+
666
+                                       });
667
+
668
+                                    } else {
669
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
670
+                                        $('#pf_choose_msg').hide();
671
+                                        $('#faxdocpreview').removeClass('icon-loading');
672
+                                      }
673
+                                 } else {
674
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
675
+                                      $('#pf_choose_msg').hide();
676
+                                      $('#faxdocpreview').removeClass('icon-loading');
677
+                                   }
678
+
679
+                              } else {
680
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tiff/tif, jpeg/jpg, odt, txt, html, png.');
681
+                                   $('#pf_choose_msg').hide();
682
+                                   $('#faxdocpreview').removeClass('icon-loading');
683
+                                }
684
+
685
+                        }
686
+                );
687
+  });
688
+
689
+
690
+  // Submit the fax
691
+  $("#submitfax").on("click", function(event){
692
+
693
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
694
+
695
+     var toNumberinit = $('#faxto').val();
696
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
697
+     var toNumber = toNumbersec.split(",");
698
+
699
+     for(var v = 0; v < toNumber.length; v++) {
700
+         toNumber[v] = "+" + toNumber[v];
701
+     }
702
+
703
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
704
+     $('#faxdocpreview').addClass('icon-loading');
705
+
706
+     var userid = "<?php p($userId); ?>";
707
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
708
+
709
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
710
+
711
+         if (uploadedtofax.length != 0) {
712
+
713
+           if (toNumberwc != '') {
714
+
715
+             $.ajax({
716
+                url: baseUrl + '/' + userid,
717
+                type: "POST",
718
+                data: {uploadedtofax: uploadedtofax,
719
+                       selectedcid: selectedcid,
720
+                       toNumber: toNumber
721
+                      },
722
+                success: function(phaxioresult) {
723
+
724
+                   if (phaxioresult.success == true) {
725
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
726
+                   } else {
727
+                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
728
+                   }
729
+
730
+                   $("div:visible[id*='indfilediv']").hide();
731
+                   $("div:visible[id*='indflpicked']").hide();
732
+                   $('[class*="indupfldl"]').hide();
733
+                   $('[class*="indpckfldl"]').hide();
734
+
735
+                   $('#faxdocpreview').hide();
736
+
737
+                   $('#filestotsize').hide();
738
+                   $('#submitfax').attr("disabled", true);
739
+                   $("#receivedfaxdir").attr("disabled", true);
740
+                   $("#sentfaxdir").attr("disabled", true);
741
+                   $("#receivedfaileddir").attr("disabled", true);
742
+                   $("#sentfaileddir").attr("disabled", true);
743
+
744
+                   location.reload(true);
745
+
746
+                },
747
+
748
+                error: function(phaxioresult) {
749
+
750
+                   alert('Error ! Please check your settings !');
751
+
752
+                   $("div:visible[id*='indfilediv']").hide();
753
+                   $("div:visible[id*='indflpicked']").hide();
754
+                   $('[class*="indupfldl"]').hide();
755
+                   $('[class*="indpckfldl"]').hide();
756
+
757
+                   $('#pf_submit_msg').hide();
758
+                   $('#filestotsize').hide();
759
+                   $('#faxdocpreview').hide();
760
+                   $('#submitfax').attr("disabled", true);
761
+
762
+
763
+                   $("#receivedfaxdir").attr("disabled", true);
764
+                   $("#sentfaxdir").attr("disabled", true);
765
+                   $("#receivedfaileddir").attr("disabled", true);
766
+                   $("#sentfaileddir").attr("disabled", true);
767
+
768
+                          location.reload(true);
769
+                }
770
+             });
771
+           } else {
772
+              $('#pf_submit_msg').hide();
773
+              $('#faxdocpreview').removeClass('icon-loading');
774
+              alert("Please enter the fax number of the recipient !");
775
+             }
776
+         } else {
777
+              $('#pf_submit_msg').hide();
778
+              $('#faxdocpreview').removeClass('icon-loading');
779
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
780
+           }
781
+  });
782
+
783
+  $("#receivedfaxdir").on("click", function(event){
784
+     $("#faxdocpreview").hide();
785
+     $("#faxfoldersview").show();
786
+     $("#faxfoldersview").addClass("icon-loading");
787
+     $("#faxfoldersview :last-child").remove();
788
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
789
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
790
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
791
+  });
792
+
793
+  $("#sentfaxdir").on("click", function(event){
794
+     $("#faxdocpreview").hide();
795
+     $("#faxfoldersview").show();
796
+     $("#faxfoldersview").addClass("icon-loading");
797
+     $("#faxfoldersview :last-child").remove();
798
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
799
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
800
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
801
+  });
802
+
803
+  $("#receivedfaileddir").on("click", function(event){
804
+     $("#faxdocpreview").hide();
805
+     $("#faxfoldersview").show();
806
+     $("#faxfoldersview").addClass("icon-loading");
807
+     $("#faxfoldersview :last-child").remove();
808
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
809
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
810
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
811
+  });
812
+
813
+  $("#sentfaileddir").on("click", function(event){
814
+     $("#faxdocpreview").hide();
815
+     $("#faxfoldersview").show();
816
+     $("#faxfoldersview").addClass("icon-loading");
817
+     $("#faxfoldersview :last-child").remove();
818
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
819
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
820
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
821
+  });
822
+
823
+  $(".indivflpckd").click(function(event){
824
+     $("#faxfoldersview").hide();
825
+  });
826
+
827
+  $(".indivflcls").on("click", function(event){
828
+     $("#faxfoldersview").hide();
829
+  });
830
+
831
+});
Browse code

removed README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/sendfax.js templates/navigation/index.php lib/Controller/AuthorApiController.php lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 03/09/2022 20:58:28
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,877 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
-  var locHref = window.location.href;
33
-  var pathSplit = locHref.split('/');
34
-  var firstPathEl = '';
35
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
-
37
-  // Check the available balance
38
-  $("#checkbalance").on("click", function(event) {
39
-
40
-     $('#checkbalance').addClass('icon-loading');
41
-
42
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
-
44
-     $.ajax({
45
-          url: getbalanceUrl + '/' + userid,
46
-          type: "POST",
47
-          data: {userid: userid},
48
-          cache: false,
49
-          processData: false,
50
-          contentType: false,
51
-          success: function(phaxiobalance) {
52
-                 var balanceindlrs = phaxiobalance / 100;
53
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
-                 $('#currentbalance').text(balanceproc);
55
-
56
-                 $('#checkbalance').removeClass('icon-loading');
57
-          }
58
-     });
59
-  });
60
-
61
-  // Select the Caller ID
62
-  $("#selectcalleridbttn").on("click", function(event) {
63
-
64
-     $('#selectcalleridbttn').addClass('icon-loading');
65
-
66
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
-     var selectednmbr = null;
68
-
69
-     $.ajax({
70
-          url: getfaxnumbersUrl + '/' + userid,
71
-          type: "POST",
72
-          data: {userid: userid},
73
-          cache: false,
74
-          processData: false,
75
-          contentType: false,
76
-          success: function(phaxionmbrs) {
77
-
78
-                    $('#currentfaxnmbrs').empty();
79
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
-
82
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
-                    });
85
-
86
-                    $('#selectcalleridbttn').removeClass('icon-loading');
87
-
88
-          }
89
-     });
90
-  });
91
-
92
-  // Clean the Pax_Fax/temp_files directory
93
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
-
95
-  $.ajax({
96
-          url: cleanflUrl + '/' + userid,
97
-          type: "POST",
98
-          data: {userid: userid},
99
-          cache: false,
100
-          processData: false,
101
-          contentType: false
102
-  });
103
-
104
-  var n = 1;
105
-  var uploadedtofax = [];
106
-  var ordernmbrs = [];
107
-
108
-  // Upload files to be faxed
109
-  $("#uploadfileforfax").change(function(e){
110
-
111
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
112
-     $('#faxdocpreview').addClass('icon-loading');
113
-     $('#filestotsize').show();
114
-
115
-     var userid = "<?php p($userId); ?>";
116
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
117
-
118
-     var formData = new FormData();
119
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
120
-
121
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
122
-
123
-     var fileup = $('#uploadfileforfax').val();
124
-     var fileuptrim = fileup.split('\\').pop();
125
-
126
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
127
-         var duplicatescheck = 1;
128
-     } else var duplicatescheck = 0;
129
-
130
-     var extension = fileup.replace(/^.*\./, '');
131
-
132
-     if (extension == fileup) {
133
-         extension = "";
134
-     } else {
135
-         extension = extension.toLowerCase();
136
-     }
137
-
138
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
139
-
140
-     if ($.inArray(extension, validExtensions) != -1) {
141
-
142
-       if (duplicatescheck == 0) {
143
-
144
-         if (currentflsize < 20971520) {
145
-
146
-            if (n < 21) {
147
-
148
-               uploadedtofax.push(fileuptrim);
149
-
150
-               $.ajax({
151
-                 url: baseUrl + '/' + userid,
152
-                 type: "POST",
153
-                 data: formData,
154
-                 cache: false,
155
-                 processData: false,
156
-                 contentType: false,
157
-                 success: function(totalflsize) {
158
-
159
-                   $('#filessizetext').text(totalflsize);
160
-
161
-                   // Check if the total file size is over 20 MB
162
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
163
-
164
-                   if (rectotfilesz > 20.00) {
165
-                       $('#filestotsize').css('color', '#ba3555');
166
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
167
-                       $('#submitfax').attr("disabled", true);
168
-                   } else {
169
-                       $('#submitfax').attr("disabled", false);
170
-                       $('#filestotsize').css('color', '#18bf6e');
171
-                     }
172
-
173
-
174
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
175
-                   n++;
176
-
177
-                   // Preview the file when you click on its name
178
-                   $("div:visible[id*='indfilediv']").each(function() {
179
-                        $(this).on("click", function(eventclck) {
180
-                           var faxfilenameinit = $(this).text();
181
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
182
-                           var faxfilename = faxfilenamesec.replace("X","");
183
-                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
184
-                           var extenlst = faxfilename.replace(/^.*\./, '');
185
-
186
-                           if (extenlst == faxfilename) {
187
-                               extenlst = "";
188
-                           } else {
189
-                               extenlst = extenlst.toLowerCase();
190
-                           }
191
-
192
-                           if (extenlst == 'pdf') {
193
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
194
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
195
-                                  $("#faxdocpreview").empty();
196
-                                  $("#faxdocpreview").append($iframe);
197
-                           } else if (extenlst == 'txt') {
198
-                                  $("#faxdocpreview").empty();
199
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
200
-                           } else if (extenlst == 'html') {
201
-                                  $("#faxdocpreview").empty();
202
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
203
-                           } else if (extenlst == 'jpg') {
204
-                                  $("#faxdocpreview").empty();
205
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
206
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
207
-                           } else if (extenlst == 'png') {
208
-                                  $("#faxdocpreview").empty();
209
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
210
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
211
-                           } else if (extenlst == 'odt') {
212
-                                  $("#faxdocpreview").empty();
213
-                                  function odfInit() {
214
-                                     var odfelement = document.getElementById("faxdocpreview");
215
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
216
-                                     odfcanvas.load(baseUrl);
217
-                                  }
218
-                                  window.setTimeout(odfInit, 0);
219
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
220
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
221
-                                  var xhr = new XMLHttpRequest();
222
-                                  xhr.responseType = 'arraybuffer';
223
-                                  xhr.open('GET', tiffile);
224
-                                  xhr.onload = function (evnt) {
225
-                                      var tiff = new Tiff({buffer: xhr.response});
226
-                                      var tifcanvas = tiff.toCanvas();
227
-                                      $("#faxdocpreview").empty();
228
-                                      $("#faxdocpreview").append(tifcanvas);
229
-                                  };
230
-                                  xhr.send();
231
-                           }
232
-
233
-                           $("#faxdocpreview").show();
234
-                           $("#faxfoldersview").hide();
235
-                        });
236
-                   });
237
-
238
-                   // Remove uploaded files
239
-                   $('[class*="indupfldl"]').last().click(function() {
240
-
241
-                           var userid = "<?php p($userId); ?>";
242
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
243
-
244
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
245
-
246
-                           var removedfilesplit = removedfilenameinit.split(") ");
247
-                           var removedflnb = parseInt(removedfilesplit[0]);
248
-
249
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
250
-                           $(this).hide();
251
-
252
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
253
-
254
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
255
-                                           return value != removedfilename;
256
-                           });
257
-
258
-                           $.ajax({
259
-                                   url: baseUrl + '/' + userid,
260
-                                   type: "POST",
261
-                                   data: {removedfilename: removedfilename},
262
-                                   success: function(totalflsize) {
263
-
264
-                                      $('#filessizetext').text(totalflsize);
265
-
266
-                                      // Check file size
267
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
268
-
269
-                                      if (rectotfilesz > 20.00) {
270
-                                          $('#filestotsize').css('color', '#ba3555');
271
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
272
-                                          $('#submitfax').attr("disabled", true);
273
-                                      } else {
274
-                                          $('#submitfax').attr("disabled", false);
275
-                                          $('#filestotsize').css('color', '#18bf6e');
276
-                                        }
277
-
278
-                                      // Rewrite order numbers for files that follow
279
-                                      --n;
280
-                                      $("div:visible[id*='indfilediv']").each(function() {
281
-
282
-                                          var getdivtext =  $(this).text();
283
-                                          var splitdivtext = getdivtext.split(") ");
284
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
285
-                                          var newnbvalue = currentnbvalue - 1;
286
-
287
-                                          if (currentnbvalue > removedflnb) {
288
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
289
-                                              $(this).text(replacedstr);
290
-                                          }
291
-                                      });
292
-
293
-                                      $("div:visible[id*='indflpicked']").each(function() {
294
-
295
-                                          var getdivtext =  $(this).text();
296
-                                          var splitdivtext = getdivtext.split(") ");
297
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
298
-                                          var newnbvalue = currentnbvalue - 1;
299
-
300
-                                          if (currentnbvalue > removedflnb) {
301
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
302
-                                              $(this).text(replacedstr);
303
-                                          }
304
-                                      });
305
-
306
-                                   },
307
-                                   error: function() {
308
-                                          alert('Error !');
309
-                                   }
310
-                           });
311
-
312
-                           $('#faxdocpreview').removeClass('icon-loading');
313
-                           $("#faxdocpreview").empty();
314
-                   });
315
-
316
-                   // Preview the uploaded file
317
-                   var faxfilename = e.target.files[0].name;
318
-                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
319
-
320
-                   if (extension == 'pdf') {
321
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
322
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
323
-                              $("#faxdocpreview").empty();
324
-                              $("#faxdocpreview").append($iframe);
325
-                   } else if (extension == 'txt') {
326
-                              var reader = new FileReader();
327
-                              reader.readAsText(e.target.files[0]);
328
-                              reader.onload = function(e) {
329
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
330
-                                  $("#faxdocpreview").empty();
331
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
332
-                              };
333
-                   } else if (extension == 'html') {
334
-                              var reader = new FileReader();
335
-                              reader.readAsText(e.target.files[0]);
336
-                              reader.onload = function(e) {
337
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
338
-                                  $("#faxdocpreview").empty();
339
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
340
-                              };
341
-                   } else if (extension == 'jpg') {
342
-                              $("#faxdocpreview").empty();
343
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
344
-
345
-                              var reader = new FileReader();
346
-                              reader.onload = function (e) {
347
-                                  readjpg[faxfilename] = e.target.result;
348
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
349
-                              }
350
-                              reader.readAsDataURL(e.target.files[0]);
351
-                   } else if (extension == 'png') {
352
-                              $("#faxdocpreview").empty();
353
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
354
-
355
-                              var reader = new FileReader();
356
-                              reader.onload = function (e) {
357
-                                  readpng[faxfilename] = e.target.result;
358
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
359
-                              }
360
-                              reader.readAsDataURL(e.target.files[0]);
361
-                   } else if (extension == 'odt') {
362
-                              $("#faxdocpreview").empty();
363
-                              function odfInit() {
364
-                                 var odfelement = document.getElementById("faxdocpreview");
365
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
366
-                                 odfcanvas.load(baseUrl);
367
-                              }
368
-                              window.setTimeout(odfInit, 0);
369
-                   } else if (extension == 'tif' || extension == 'tiff') {
370
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
371
-                              var xhr = new XMLHttpRequest();
372
-                              xhr.responseType = 'arraybuffer';
373
-                              xhr.open('GET', tiffile);
374
-                              xhr.onload = function (e) {
375
-                                  var tiff = new Tiff({buffer: xhr.response});
376
-                                  var tifcanvas = tiff.toCanvas();
377
-                                  $("#faxdocpreview").empty();
378
-                                  $("#faxdocpreview").append(tifcanvas);
379
-                              };
380
-                              xhr.send();
381
-                   }
382
-
383
-                   $("#faxdocpreview").show();
384
-                   $('#pf_upload_msg').hide();
385
-                   $('#faxdocpreview').removeClass('icon-loading');
386
-                   $("#faxfoldersview").hide();
387
-                 },
388
-                 error: function(data){
389
-                     alert('Error!');
390
-                 }
391
-               });
392
-
393
-            } else {
394
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
395
-                  $('#pf_upload_msg').hide();
396
-                  $('#faxdocpreview').removeClass('icon-loading');
397
-              }
398
-         } else {
399
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
400
-              $('#pf_upload_msg').hide();
401
-              $('#faxdocpreview').removeClass('icon-loading');
402
-           }
403
-       } else {
404
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
405
-            $('#pf_upload_msg').hide();
406
-            $('#faxdocpreview').removeClass('icon-loading');
407
-         }
408
-
409
-     } else {
410
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
411
-          $('#pf_upload_msg').hide();
412
-          $('#faxdocpreview').removeClass('icon-loading');
413
-       }
414
-  });
415
-
416
-
417
-  // Pick file to fax, from Nextcloud
418
-  var faxfilename = null;
419
-
420
-  $("#choosefilen").on("click", function(evn) {
421
-
422
-                OC.dialogs.filepicker(
423
-                        t('settings', "Select a file to send as fax."),
424
-                        function (path) {
425
-
426
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
427
-                              $('#faxdocpreview').addClass('icon-loading');
428
-                              $('#filestotsize').show();
429
-
430
-                              var userid = "<?php p($userId); ?>";
431
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
432
-
433
-                              faxfilename = path.split('/').pop();
434
-
435
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
436
-                                  var duplicatescheck = 1;
437
-                              } else var duplicatescheck = 0;
438
-
439
-                              var extension = faxfilename.replace(/^.*\./, '');
440
-
441
-                              if (extension == faxfilename) {
442
-                                  extension = "";
443
-                              } else {
444
-                                  extension = extension.toLowerCase();
445
-                              }
446
-
447
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
448
-
449
-                              if ($.inArray(extension, validExtensions) != -1) {
450
-
451
-                                 if (duplicatescheck == 0) {
452
-
453
-                                    if (n < 21) {
454
-
455
-                                       uploadedtofax.push(faxfilename);
456
-
457
-                                       $.ajax({
458
-                                          url: baseUrl + '/' + userid,
459
-                                          type: "POST",
460
-                                          data: {path: path},
461
-                                          success: function(totalflsize) {
462
-
463
-                                                $('#filessizetext').text(totalflsize);
464
-
465
-                                                // Check if the total file size is over 20 MB
466
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
467
-
468
-                                                if (rectotfilesz > 20.00) {
469
-                                                    $('#filestotsize').css('color', '#ba3555');
470
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
471
-                                                    $('#submitfax').attr("disabled", true);
472
-                                                } else {
473
-                                                    $('#submitfax').attr("disabled", false);
474
-                                                    $('#filestotsize').css('color', '#18bf6e');
475
-                                                }
476
-
477
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
478
-                                                n++;
479
-
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
508
-                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
-                                                      } else if (extenlst == 'png') {
510
-                                                              $("#faxdocpreview").empty();
511
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
512
-                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
-                                                      } else if (extenlst == 'odt') {
514
-                                                              $("#faxdocpreview").empty();
515
-                                                              function odfInit() {
516
-                                                                 var odfelement = document.getElementById("faxdocpreview");
517
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
-                                                                 odfcanvas.load(baseUrl);
519
-                                                              }
520
-                                                              window.setTimeout(odfInit, 0);
521
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
-                                                              var xhr = new XMLHttpRequest();
524
-                                                              xhr.responseType = 'arraybuffer';
525
-                                                              xhr.open('GET', tiffile);
526
-                                                              xhr.onload = function (evnt) {
527
-                                                                  var tiff = new Tiff({buffer: xhr.response});
528
-                                                                  var tifcanvas = tiff.toCanvas();
529
-                                                                  $("#faxdocpreview").empty();
530
-                                                                  $("#faxdocpreview").append(tifcanvas);
531
-                                                              };
532
-                                                              xhr.send();
533
-                                                      }
534
-
535
-                                                      $("#faxdocpreview").show();
536
-                                                      $("#faxfoldersview").hide();
537
-                                                   });
538
-                                                });
539
-
540
-                                                // Remove picked files
541
-                                                $('[class*="indpckfldl"]').last().click(function() {
542
-                                                    var userid = "<?php p($userId); ?>";
543
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
-
545
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
-
547
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
-
550
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
-                                                    $(this).hide();
552
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
-
554
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
-                                                             return value != removedfilename;
556
-                                                    });
557
-
558
-                                                    $.ajax({
559
-                                                        url: baseUrl + '/' + userid,
560
-                                                        type: "POST",
561
-                                                        data: {removedfilename: removedfilename},
562
-                                                        success: function(totalflsize) {
563
-
564
-                                                             $('#filessizetext').text(totalflsize);
565
-
566
-                                                             // Check file size
567
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
-
569
-                                                             if (rectotfilesz > 20.00) {
570
-                                                                 $('#filestotsize').css('color', '#ba3555');
571
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
-                                                                 $('#submitfax').attr("disabled", true);
573
-                                                             } else {
574
-                                                                 $('#submitfax').attr("disabled", false);
575
-                                                                 $('#filestotsize').css('color', '#18bf6e');
576
-                                                               }
577
-
578
-                                                             // Rewrite order numbers for files that follow
579
-                                                             --n;
580
-                                                             $("div:visible[id*='indflpicked']").each(function() {
581
-
582
-                                                                  var getdivtext =  $(this).text();
583
-                                                                  var splitdivtext = getdivtext.split(") ");
584
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
-                                                                  var newnbvalue = currentnbvalue - 1;
586
-
587
-                                                                  if (currentnbvalue > removedflnb) {
588
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
-                                                                      $(this).text(replacedstr);
590
-                                                                  }
591
-                                                             });
592
-                                                        },
593
-                                                        error: function() {
594
-                                                             alert('Error !');
595
-                                                        }
596
-                                                    });
597
-
598
-                                                    $('#faxdocpreview').removeClass('icon-loading');
599
-                                                    $("#faxdocpreview").empty();
600
-                                                });
601
-
602
-                                          // Preview the picked file
603
-                                          var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
604
-                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
605
-
606
-                                          if (extension == 'pdf') {
607
-                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
608
-                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
609
-                                              $("#faxdocpreview").empty();
610
-                                              $("#faxdocpreview").append($iframe);
611
-                                          } else if (extension == 'txt') {
612
-
613
-                                              $.ajax({
614
-                                                  url: pickUrl + '/' + userid,
615
-                                                  type: "POST",
616
-                                                  data: {pickedfilename: faxfilename},
617
-                                                  success: function(getpickedfile) {
618
-                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
-                                                      $("#faxdocpreview").empty();
620
-                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
621
-                                                  },
622
-                                                  error: function() {
623
-                                                      alert('Unexpected error !');
624
-                                                  }
625
-                                              });
626
-
627
-                                          } else if (extension == 'html') {
628
-
629
-                                              $.ajax({
630
-                                                  url: pickUrl + '/' + userid,
631
-                                                  type: "POST",
632
-                                                  data: {pickedfilename: faxfilename},
633
-                                                  success: function(getpickedfile) {
634
-                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
635
-                                                      $("#faxdocpreview").empty();
636
-                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
637
-                                                  },
638
-                                                  error: function() {
639
-                                                      alert('Unexpected error !');
640
-                                                  }
641
-                                              });
642
-
643
-                                          } else if (extension == 'jpg') {
644
-
645
-                                              $.ajax({
646
-                                                  url: pickUrl + '/' + userid,
647
-                                                  type: "POST",
648
-                                                  data: {pickedfilename: faxfilename},
649
-                                                  success: function(getpickedfile) {
650
-                                                      $("#faxdocpreview").empty();
651
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
652
-                                                      readjpg[faxfilename] = getpickedfile;
653
-                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
654
-                                                  },
655
-                                                  error: function() {
656
-                                                      alert('Unexpected error !');
657
-                                                  }
658
-                                              });
659
-
660
-                                          } else if (extension == 'png') {
661
-
662
-                                              $.ajax({
663
-                                                  url: pickUrl + '/' + userid,
664
-                                                  type: "POST",
665
-                                                  data: {pickedfilename: faxfilename},
666
-                                                  success: function(getpickedfile) {
667
-                                                      $("#faxdocpreview").empty();
668
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
669
-                                                      readpng[faxfilename] = getpickedfile;
670
-                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
671
-                                                  },
672
-                                                  error: function() {
673
-                                                      alert('Unexpected error !');
674
-                                                  }
675
-                                              });
676
-
677
-                                          } else if (extension == 'odt') {
678
-                                              $("#faxdocpreview").empty();
679
-                                              function odfInit() {
680
-                                                  var odfelement = document.getElementById("faxdocpreview");
681
-                                                  odfcanvas = new odf.OdfCanvas(odfelement);
682
-                                                  odfcanvas.load(flUrl);
683
-                                               }
684
-                                               window.setTimeout(odfInit, 0);
685
-
686
-                                          } else if (extension == 'tif' || extension == 'tiff') {
687
-                                               var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
688
-                                               var xhr = new XMLHttpRequest();
689
-                                               xhr.responseType = 'arraybuffer';
690
-                                               xhr.open('GET', tiffile);
691
-                                               xhr.onload = function (event) {
692
-                                                   var tiff = new Tiff({buffer: xhr.response});
693
-                                                   var tifcanvas = tiff.toCanvas();
694
-                                                   $("#faxdocpreview").empty();
695
-                                                   $("#faxdocpreview").append(tifcanvas);
696
-                                               };
697
-                                               xhr.send();
698
-                                          }
699
-
700
-                                          $("#faxdocpreview").show();
701
-
702
-                                          $('#pf_choose_msg').hide();
703
-                                          $('#faxdocpreview').removeClass('icon-loading');
704
-                                          $("#faxfoldersview").hide();
705
-
706
-                                          },
707
-
708
-                                          error: function(data){
709
-                                             alert('Error!');
710
-                                          }
711
-
712
-                                       });
713
-
714
-                                    } else {
715
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
716
-                                        $('#pf_choose_msg').hide();
717
-                                        $('#faxdocpreview').removeClass('icon-loading');
718
-                                      }
719
-                                 } else {
720
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
721
-                                      $('#pf_choose_msg').hide();
722
-                                      $('#faxdocpreview').removeClass('icon-loading');
723
-                                   }
724
-
725
-                              } else {
726
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
727
-                                   $('#pf_choose_msg').hide();
728
-                                   $('#faxdocpreview').removeClass('icon-loading');
729
-                                }
730
-
731
-                        }
732
-                );
733
-  });
734
-
735
-
736
-  // Submit the fax
737
-  $("#submitfax").on("click", function(event){
738
-
739
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
740
-
741
-     var toNumberinit = $('#faxto').val();
742
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
743
-     var toNumber = toNumbersec.split(",");
744
-
745
-     for(var v = 0; v < toNumber.length; v++) {
746
-         toNumber[v] = "+" + toNumber[v];
747
-     }
748
-
749
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
750
-     $('#faxdocpreview').addClass('icon-loading');
751
-
752
-     var userid = "<?php p($userId); ?>";
753
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
754
-
755
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
756
-
757
-         if (uploadedtofax.length != 0) {
758
-
759
-           if (toNumberwc != '') {
760
-
761
-             $.ajax({
762
-                url: baseUrl + '/' + userid,
763
-                type: "POST",
764
-                data: {uploadedtofax: uploadedtofax,
765
-                       selectedcid: selectedcid,
766
-                       toNumber: toNumber
767
-                      },
768
-                success: function(phaxioresult) {
769
-
770
-                   if (phaxioresult.success == true) {
771
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
772
-                   } else {
773
-                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
774
-                   }
775
-
776
-                   $("div:visible[id*='indfilediv']").hide();
777
-                   $("div:visible[id*='indflpicked']").hide();
778
-                   $('[class*="indupfldl"]').hide();
779
-                   $('[class*="indpckfldl"]').hide();
780
-
781
-                   $('#faxdocpreview').hide();
782
-
783
-                   $('#filestotsize').hide();
784
-                   $('#submitfax').attr("disabled", true);
785
-                   $("#receivedfaxdir").attr("disabled", true);
786
-                   $("#sentfaxdir").attr("disabled", true);
787
-                   $("#receivedfaileddir").attr("disabled", true);
788
-                   $("#sentfaileddir").attr("disabled", true);
789
-
790
-                   location.reload(true);
791
-
792
-                },
793
-
794
-                error: function(phaxioresult) {
795
-
796
-                   alert('Error ! Please check your settings !');
797
-
798
-                   $("div:visible[id*='indfilediv']").hide();
799
-                   $("div:visible[id*='indflpicked']").hide();
800
-                   $('[class*="indupfldl"]').hide();
801
-                   $('[class*="indpckfldl"]').hide();
802
-
803
-                   $('#pf_submit_msg').hide();
804
-                   $('#filestotsize').hide();
805
-                   $('#faxdocpreview').hide();
806
-                   $('#submitfax').attr("disabled", true);
807
-
808
-
809
-                   $("#receivedfaxdir").attr("disabled", true);
810
-                   $("#sentfaxdir").attr("disabled", true);
811
-                   $("#receivedfaileddir").attr("disabled", true);
812
-                   $("#sentfaileddir").attr("disabled", true);
813
-
814
-                          location.reload(true);
815
-                }
816
-             });
817
-           } else {
818
-              $('#pf_submit_msg').hide();
819
-              $('#faxdocpreview').removeClass('icon-loading');
820
-              alert("Please enter the fax number of the recipient !");
821
-             }
822
-         } else {
823
-              $('#pf_submit_msg').hide();
824
-              $('#faxdocpreview').removeClass('icon-loading');
825
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
826
-           }
827
-  });
828
-
829
-  $("#receivedfaxdir").on("click", function(event){
830
-     $("#faxdocpreview").hide();
831
-     $("#faxfoldersview").show();
832
-     $("#faxfoldersview").addClass("icon-loading");
833
-     $("#faxfoldersview :last-child").remove();
834
-     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
835
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
836
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
837
-  });
838
-
839
-  $("#sentfaxdir").on("click", function(event){
840
-     $("#faxdocpreview").hide();
841
-     $("#faxfoldersview").show();
842
-     $("#faxfoldersview").addClass("icon-loading");
843
-     $("#faxfoldersview :last-child").remove();
844
-     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
845
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
846
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
847
-  });
848
-
849
-  $("#receivedfaileddir").on("click", function(event){
850
-     $("#faxdocpreview").hide();
851
-     $("#faxfoldersview").show();
852
-     $("#faxfoldersview").addClass("icon-loading");
853
-     $("#faxfoldersview :last-child").remove();
854
-     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
855
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
856
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
857
-  });
858
-
859
-  $("#sentfaileddir").on("click", function(event){
860
-     $("#faxdocpreview").hide();
861
-     $("#faxfoldersview").show();
862
-     $("#faxfoldersview").addClass("icon-loading");
863
-     $("#faxfoldersview :last-child").remove();
864
-     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
865
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
866
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
867
-  });
868
-
869
-  $(".indivflpckd").click(function(event){
870
-     $("#faxfoldersview").hide();
871
-  });
872
-
873
-  $(".indivflcls").on("click", function(event){
874
-     $("#faxfoldersview").hide();
875
-  });
876
-
877
-});
Browse code

added CHANGELOG.txt Contributors.txt appinfo/info.xml appinfo/signature.json js/sendfax.js templates/settings.php

DoubleBastionAdmin authored on 28/04/2022 22:58:31
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,877 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Adjust the path, so that the uploaded pdf files can be previewed while Nextcloud is served on a subdomain or on a subdirectory, by Nginx or by Apache
32
+  var locHref = window.location.href;
33
+  var pathSplit = locHref.split('/');
34
+  var firstPathEl = '';
35
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
36
+
37
+  // Check the available balance
38
+  $("#checkbalance").on("click", function(event) {
39
+
40
+     $('#checkbalance').addClass('icon-loading');
41
+
42
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
43
+
44
+     $.ajax({
45
+          url: getbalanceUrl + '/' + userid,
46
+          type: "POST",
47
+          data: {userid: userid},
48
+          cache: false,
49
+          processData: false,
50
+          contentType: false,
51
+          success: function(phaxiobalance) {
52
+                 var balanceindlrs = phaxiobalance / 100;
53
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
54
+                 $('#currentbalance').text(balanceproc);
55
+
56
+                 $('#checkbalance').removeClass('icon-loading');
57
+          }
58
+     });
59
+  });
60
+
61
+  // Select the Caller ID
62
+  $("#selectcalleridbttn").on("click", function(event) {
63
+
64
+     $('#selectcalleridbttn').addClass('icon-loading');
65
+
66
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
67
+     var selectednmbr = null;
68
+
69
+     $.ajax({
70
+          url: getfaxnumbersUrl + '/' + userid,
71
+          type: "POST",
72
+          data: {userid: userid},
73
+          cache: false,
74
+          processData: false,
75
+          contentType: false,
76
+          success: function(phaxionmbrs) {
77
+
78
+                    $('#currentfaxnmbrs').empty();
79
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
80
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
81
+
82
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
83
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
84
+                    });
85
+
86
+                    $('#selectcalleridbttn').removeClass('icon-loading');
87
+
88
+          }
89
+     });
90
+  });
91
+
92
+  // Clean the Pax_Fax/temp_files directory
93
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
94
+
95
+  $.ajax({
96
+          url: cleanflUrl + '/' + userid,
97
+          type: "POST",
98
+          data: {userid: userid},
99
+          cache: false,
100
+          processData: false,
101
+          contentType: false
102
+  });
103
+
104
+  var n = 1;
105
+  var uploadedtofax = [];
106
+  var ordernmbrs = [];
107
+
108
+  // Upload files to be faxed
109
+  $("#uploadfileforfax").change(function(e){
110
+
111
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
112
+     $('#faxdocpreview').addClass('icon-loading');
113
+     $('#filestotsize').show();
114
+
115
+     var userid = "<?php p($userId); ?>";
116
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
117
+
118
+     var formData = new FormData();
119
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
120
+
121
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
122
+
123
+     var fileup = $('#uploadfileforfax').val();
124
+     var fileuptrim = fileup.split('\\').pop();
125
+
126
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
127
+         var duplicatescheck = 1;
128
+     } else var duplicatescheck = 0;
129
+
130
+     var extension = fileup.replace(/^.*\./, '');
131
+
132
+     if (extension == fileup) {
133
+         extension = "";
134
+     } else {
135
+         extension = extension.toLowerCase();
136
+     }
137
+
138
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
139
+
140
+     if ($.inArray(extension, validExtensions) != -1) {
141
+
142
+       if (duplicatescheck == 0) {
143
+
144
+         if (currentflsize < 20971520) {
145
+
146
+            if (n < 21) {
147
+
148
+               uploadedtofax.push(fileuptrim);
149
+
150
+               $.ajax({
151
+                 url: baseUrl + '/' + userid,
152
+                 type: "POST",
153
+                 data: formData,
154
+                 cache: false,
155
+                 processData: false,
156
+                 contentType: false,
157
+                 success: function(totalflsize) {
158
+
159
+                   $('#filessizetext').text(totalflsize);
160
+
161
+                   // Check if the total file size is over 20 MB
162
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
163
+
164
+                   if (rectotfilesz > 20.00) {
165
+                       $('#filestotsize').css('color', '#ba3555');
166
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
167
+                       $('#submitfax').attr("disabled", true);
168
+                   } else {
169
+                       $('#submitfax').attr("disabled", false);
170
+                       $('#filestotsize').css('color', '#18bf6e');
171
+                     }
172
+
173
+
174
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
175
+                   n++;
176
+
177
+                   // Preview the file when you click on its name
178
+                   $("div:visible[id*='indfilediv']").each(function() {
179
+                        $(this).on("click", function(eventclck) {
180
+                           var faxfilenameinit = $(this).text();
181
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
182
+                           var faxfilename = faxfilenamesec.replace("X","");
183
+                           var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
184
+                           var extenlst = faxfilename.replace(/^.*\./, '');
185
+
186
+                           if (extenlst == faxfilename) {
187
+                               extenlst = "";
188
+                           } else {
189
+                               extenlst = extenlst.toLowerCase();
190
+                           }
191
+
192
+                           if (extenlst == 'pdf') {
193
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
194
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
195
+                                  $("#faxdocpreview").empty();
196
+                                  $("#faxdocpreview").append($iframe);
197
+                           } else if (extenlst == 'txt') {
198
+                                  $("#faxdocpreview").empty();
199
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
200
+                           } else if (extenlst == 'html') {
201
+                                  $("#faxdocpreview").empty();
202
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
203
+                           } else if (extenlst == 'jpg') {
204
+                                  $("#faxdocpreview").empty();
205
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
206
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
207
+                           } else if (extenlst == 'png') {
208
+                                  $("#faxdocpreview").empty();
209
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
210
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
211
+                           } else if (extenlst == 'odt') {
212
+                                  $("#faxdocpreview").empty();
213
+                                  function odfInit() {
214
+                                     var odfelement = document.getElementById("faxdocpreview");
215
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
216
+                                     odfcanvas.load(baseUrl);
217
+                                  }
218
+                                  window.setTimeout(odfInit, 0);
219
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
220
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
221
+                                  var xhr = new XMLHttpRequest();
222
+                                  xhr.responseType = 'arraybuffer';
223
+                                  xhr.open('GET', tiffile);
224
+                                  xhr.onload = function (evnt) {
225
+                                      var tiff = new Tiff({buffer: xhr.response});
226
+                                      var tifcanvas = tiff.toCanvas();
227
+                                      $("#faxdocpreview").empty();
228
+                                      $("#faxdocpreview").append(tifcanvas);
229
+                                  };
230
+                                  xhr.send();
231
+                           }
232
+
233
+                           $("#faxdocpreview").show();
234
+                           $("#faxfoldersview").hide();
235
+                        });
236
+                   });
237
+
238
+                   // Remove uploaded files
239
+                   $('[class*="indupfldl"]').last().click(function() {
240
+
241
+                           var userid = "<?php p($userId); ?>";
242
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
243
+
244
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
245
+
246
+                           var removedfilesplit = removedfilenameinit.split(") ");
247
+                           var removedflnb = parseInt(removedfilesplit[0]);
248
+
249
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
250
+                           $(this).hide();
251
+
252
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
253
+
254
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
255
+                                           return value != removedfilename;
256
+                           });
257
+
258
+                           $.ajax({
259
+                                   url: baseUrl + '/' + userid,
260
+                                   type: "POST",
261
+                                   data: {removedfilename: removedfilename},
262
+                                   success: function(totalflsize) {
263
+
264
+                                      $('#filessizetext').text(totalflsize);
265
+
266
+                                      // Check file size
267
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
268
+
269
+                                      if (rectotfilesz > 20.00) {
270
+                                          $('#filestotsize').css('color', '#ba3555');
271
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
272
+                                          $('#submitfax').attr("disabled", true);
273
+                                      } else {
274
+                                          $('#submitfax').attr("disabled", false);
275
+                                          $('#filestotsize').css('color', '#18bf6e');
276
+                                        }
277
+
278
+                                      // Rewrite order numbers for files that follow
279
+                                      --n;
280
+                                      $("div:visible[id*='indfilediv']").each(function() {
281
+
282
+                                          var getdivtext =  $(this).text();
283
+                                          var splitdivtext = getdivtext.split(") ");
284
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
285
+                                          var newnbvalue = currentnbvalue - 1;
286
+
287
+                                          if (currentnbvalue > removedflnb) {
288
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
289
+                                              $(this).text(replacedstr);
290
+                                          }
291
+                                      });
292
+
293
+                                      $("div:visible[id*='indflpicked']").each(function() {
294
+
295
+                                          var getdivtext =  $(this).text();
296
+                                          var splitdivtext = getdivtext.split(") ");
297
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
298
+                                          var newnbvalue = currentnbvalue - 1;
299
+
300
+                                          if (currentnbvalue > removedflnb) {
301
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
302
+                                              $(this).text(replacedstr);
303
+                                          }
304
+                                      });
305
+
306
+                                   },
307
+                                   error: function() {
308
+                                          alert('Error !');
309
+                                   }
310
+                           });
311
+
312
+                           $('#faxdocpreview').removeClass('icon-loading');
313
+                           $("#faxdocpreview").empty();
314
+                   });
315
+
316
+                   // Preview the uploaded file
317
+                   var faxfilename = e.target.files[0].name;
318
+                   var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
319
+
320
+                   if (extension == 'pdf') {
321
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
322
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
323
+                              $("#faxdocpreview").empty();
324
+                              $("#faxdocpreview").append($iframe);
325
+                   } else if (extension == 'txt') {
326
+                              var reader = new FileReader();
327
+                              reader.readAsText(e.target.files[0]);
328
+                              reader.onload = function(e) {
329
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
330
+                                  $("#faxdocpreview").empty();
331
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
332
+                              };
333
+                   } else if (extension == 'html') {
334
+                              var reader = new FileReader();
335
+                              reader.readAsText(e.target.files[0]);
336
+                              reader.onload = function(e) {
337
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
338
+                                  $("#faxdocpreview").empty();
339
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
340
+                              };
341
+                   } else if (extension == 'jpg') {
342
+                              $("#faxdocpreview").empty();
343
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
344
+
345
+                              var reader = new FileReader();
346
+                              reader.onload = function (e) {
347
+                                  readjpg[faxfilename] = e.target.result;
348
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
349
+                              }
350
+                              reader.readAsDataURL(e.target.files[0]);
351
+                   } else if (extension == 'png') {
352
+                              $("#faxdocpreview").empty();
353
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
354
+
355
+                              var reader = new FileReader();
356
+                              reader.onload = function (e) {
357
+                                  readpng[faxfilename] = e.target.result;
358
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
359
+                              }
360
+                              reader.readAsDataURL(e.target.files[0]);
361
+                   } else if (extension == 'odt') {
362
+                              $("#faxdocpreview").empty();
363
+                              function odfInit() {
364
+                                 var odfelement = document.getElementById("faxdocpreview");
365
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
366
+                                 odfcanvas.load(baseUrl);
367
+                              }
368
+                              window.setTimeout(odfInit, 0);
369
+                   } else if (extension == 'tif' || extension == 'tiff') {
370
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
371
+                              var xhr = new XMLHttpRequest();
372
+                              xhr.responseType = 'arraybuffer';
373
+                              xhr.open('GET', tiffile);
374
+                              xhr.onload = function (e) {
375
+                                  var tiff = new Tiff({buffer: xhr.response});
376
+                                  var tifcanvas = tiff.toCanvas();
377
+                                  $("#faxdocpreview").empty();
378
+                                  $("#faxdocpreview").append(tifcanvas);
379
+                              };
380
+                              xhr.send();
381
+                   }
382
+
383
+                   $("#faxdocpreview").show();
384
+                   $('#pf_upload_msg').hide();
385
+                   $('#faxdocpreview').removeClass('icon-loading');
386
+                   $("#faxfoldersview").hide();
387
+                 },
388
+                 error: function(data){
389
+                     alert('Error!');
390
+                 }
391
+               });
392
+
393
+            } else {
394
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
395
+                  $('#pf_upload_msg').hide();
396
+                  $('#faxdocpreview').removeClass('icon-loading');
397
+              }
398
+         } else {
399
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
400
+              $('#pf_upload_msg').hide();
401
+              $('#faxdocpreview').removeClass('icon-loading');
402
+           }
403
+       } else {
404
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
405
+            $('#pf_upload_msg').hide();
406
+            $('#faxdocpreview').removeClass('icon-loading');
407
+         }
408
+
409
+     } else {
410
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
411
+          $('#pf_upload_msg').hide();
412
+          $('#faxdocpreview').removeClass('icon-loading');
413
+       }
414
+  });
415
+
416
+
417
+  // Pick file to fax, from Nextcloud
418
+  var faxfilename = null;
419
+
420
+  $("#choosefilen").on("click", function(evn) {
421
+
422
+                OC.dialogs.filepicker(
423
+                        t('settings', "Select a file to send as fax."),
424
+                        function (path) {
425
+
426
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
427
+                              $('#faxdocpreview').addClass('icon-loading');
428
+                              $('#filestotsize').show();
429
+
430
+                              var userid = "<?php p($userId); ?>";
431
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
432
+
433
+                              faxfilename = path.split('/').pop();
434
+
435
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
436
+                                  var duplicatescheck = 1;
437
+                              } else var duplicatescheck = 0;
438
+
439
+                              var extension = faxfilename.replace(/^.*\./, '');
440
+
441
+                              if (extension == faxfilename) {
442
+                                  extension = "";
443
+                              } else {
444
+                                  extension = extension.toLowerCase();
445
+                              }
446
+
447
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
448
+
449
+                              if ($.inArray(extension, validExtensions) != -1) {
450
+
451
+                                 if (duplicatescheck == 0) {
452
+
453
+                                    if (n < 21) {
454
+
455
+                                       uploadedtofax.push(faxfilename);
456
+
457
+                                       $.ajax({
458
+                                          url: baseUrl + '/' + userid,
459
+                                          type: "POST",
460
+                                          data: {path: path},
461
+                                          success: function(totalflsize) {
462
+
463
+                                                $('#filessizetext').text(totalflsize);
464
+
465
+                                                // Check if the total file size is over 20 MB
466
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
467
+
468
+                                                if (rectotfilesz > 20.00) {
469
+                                                    $('#filestotsize').css('color', '#ba3555');
470
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
471
+                                                    $('#submitfax').attr("disabled", true);
472
+                                                } else {
473
+                                                    $('#submitfax').attr("disabled", false);
474
+                                                    $('#filestotsize').css('color', '#18bf6e');
475
+                                                }
476
+
477
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
478
+                                                n++;
479
+
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
508
+                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
+                                                      } else if (extenlst == 'png') {
510
+                                                              $("#faxdocpreview").empty();
511
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
512
+                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
+                                                      } else if (extenlst == 'odt') {
514
+                                                              $("#faxdocpreview").empty();
515
+                                                              function odfInit() {
516
+                                                                 var odfelement = document.getElementById("faxdocpreview");
517
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
+                                                                 odfcanvas.load(baseUrl);
519
+                                                              }
520
+                                                              window.setTimeout(odfInit, 0);
521
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
523
+                                                              var xhr = new XMLHttpRequest();
524
+                                                              xhr.responseType = 'arraybuffer';
525
+                                                              xhr.open('GET', tiffile);
526
+                                                              xhr.onload = function (evnt) {
527
+                                                                  var tiff = new Tiff({buffer: xhr.response});
528
+                                                                  var tifcanvas = tiff.toCanvas();
529
+                                                                  $("#faxdocpreview").empty();
530
+                                                                  $("#faxdocpreview").append(tifcanvas);
531
+                                                              };
532
+                                                              xhr.send();
533
+                                                      }
534
+
535
+                                                      $("#faxdocpreview").show();
536
+                                                      $("#faxfoldersview").hide();
537
+                                                   });
538
+                                                });
539
+
540
+                                                // Remove picked files
541
+                                                $('[class*="indpckfldl"]').last().click(function() {
542
+                                                    var userid = "<?php p($userId); ?>";
543
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
+
545
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
+
547
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
+
550
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
+                                                    $(this).hide();
552
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
+
554
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
+                                                             return value != removedfilename;
556
+                                                    });
557
+
558
+                                                    $.ajax({
559
+                                                        url: baseUrl + '/' + userid,
560
+                                                        type: "POST",
561
+                                                        data: {removedfilename: removedfilename},
562
+                                                        success: function(totalflsize) {
563
+
564
+                                                             $('#filessizetext').text(totalflsize);
565
+
566
+                                                             // Check file size
567
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
+
569
+                                                             if (rectotfilesz > 20.00) {
570
+                                                                 $('#filestotsize').css('color', '#ba3555');
571
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
+                                                                 $('#submitfax').attr("disabled", true);
573
+                                                             } else {
574
+                                                                 $('#submitfax').attr("disabled", false);
575
+                                                                 $('#filestotsize').css('color', '#18bf6e');
576
+                                                               }
577
+
578
+                                                             // Rewrite order numbers for files that follow
579
+                                                             --n;
580
+                                                             $("div:visible[id*='indflpicked']").each(function() {
581
+
582
+                                                                  var getdivtext =  $(this).text();
583
+                                                                  var splitdivtext = getdivtext.split(") ");
584
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
+                                                                  var newnbvalue = currentnbvalue - 1;
586
+
587
+                                                                  if (currentnbvalue > removedflnb) {
588
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
+                                                                      $(this).text(replacedstr);
590
+                                                                  }
591
+                                                             });
592
+                                                        },
593
+                                                        error: function() {
594
+                                                             alert('Error !');
595
+                                                        }
596
+                                                    });
597
+
598
+                                                    $('#faxdocpreview').removeClass('icon-loading');
599
+                                                    $("#faxdocpreview").empty();
600
+                                                });
601
+
602
+                                          // Preview the picked file
603
+                                          var flUrl = firstPathEl+"/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
604
+                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
605
+
606
+                                          if (extension == 'pdf') {
607
+                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
608
+                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
609
+                                              $("#faxdocpreview").empty();
610
+                                              $("#faxdocpreview").append($iframe);
611
+                                          } else if (extension == 'txt') {
612
+
613
+                                              $.ajax({
614
+                                                  url: pickUrl + '/' + userid,
615
+                                                  type: "POST",
616
+                                                  data: {pickedfilename: faxfilename},
617
+                                                  success: function(getpickedfile) {
618
+                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
+                                                      $("#faxdocpreview").empty();
620
+                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
621
+                                                  },
622
+                                                  error: function() {
623
+                                                      alert('Unexpected error !');
624
+                                                  }
625
+                                              });
626
+
627
+                                          } else if (extension == 'html') {
628
+
629
+                                              $.ajax({
630
+                                                  url: pickUrl + '/' + userid,
631
+                                                  type: "POST",
632
+                                                  data: {pickedfilename: faxfilename},
633
+                                                  success: function(getpickedfile) {
634
+                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
635
+                                                      $("#faxdocpreview").empty();
636
+                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
637
+                                                  },
638
+                                                  error: function() {
639
+                                                      alert('Unexpected error !');
640
+                                                  }
641
+                                              });
642
+
643
+                                          } else if (extension == 'jpg') {
644
+
645
+                                              $.ajax({
646
+                                                  url: pickUrl + '/' + userid,
647
+                                                  type: "POST",
648
+                                                  data: {pickedfilename: faxfilename},
649
+                                                  success: function(getpickedfile) {
650
+                                                      $("#faxdocpreview").empty();
651
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
652
+                                                      readjpg[faxfilename] = getpickedfile;
653
+                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
654
+                                                  },
655
+                                                  error: function() {
656
+                                                      alert('Unexpected error !');
657
+                                                  }
658
+                                              });
659
+
660
+                                          } else if (extension == 'png') {
661
+
662
+                                              $.ajax({
663
+                                                  url: pickUrl + '/' + userid,
664
+                                                  type: "POST",
665
+                                                  data: {pickedfilename: faxfilename},
666
+                                                  success: function(getpickedfile) {
667
+                                                      $("#faxdocpreview").empty();
668
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
669
+                                                      readpng[faxfilename] = getpickedfile;
670
+                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
671
+                                                  },
672
+                                                  error: function() {
673
+                                                      alert('Unexpected error !');
674
+                                                  }
675
+                                              });
676
+
677
+                                          } else if (extension == 'odt') {
678
+                                              $("#faxdocpreview").empty();
679
+                                              function odfInit() {
680
+                                                  var odfelement = document.getElementById("faxdocpreview");
681
+                                                  odfcanvas = new odf.OdfCanvas(odfelement);
682
+                                                  odfcanvas.load(flUrl);
683
+                                               }
684
+                                               window.setTimeout(odfInit, 0);
685
+
686
+                                          } else if (extension == 'tif' || extension == 'tiff') {
687
+                                               var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
688
+                                               var xhr = new XMLHttpRequest();
689
+                                               xhr.responseType = 'arraybuffer';
690
+                                               xhr.open('GET', tiffile);
691
+                                               xhr.onload = function (event) {
692
+                                                   var tiff = new Tiff({buffer: xhr.response});
693
+                                                   var tifcanvas = tiff.toCanvas();
694
+                                                   $("#faxdocpreview").empty();
695
+                                                   $("#faxdocpreview").append(tifcanvas);
696
+                                               };
697
+                                               xhr.send();
698
+                                          }
699
+
700
+                                          $("#faxdocpreview").show();
701
+
702
+                                          $('#pf_choose_msg').hide();
703
+                                          $('#faxdocpreview').removeClass('icon-loading');
704
+                                          $("#faxfoldersview").hide();
705
+
706
+                                          },
707
+
708
+                                          error: function(data){
709
+                                             alert('Error!');
710
+                                          }
711
+
712
+                                       });
713
+
714
+                                    } else {
715
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
716
+                                        $('#pf_choose_msg').hide();
717
+                                        $('#faxdocpreview').removeClass('icon-loading');
718
+                                      }
719
+                                 } else {
720
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
721
+                                      $('#pf_choose_msg').hide();
722
+                                      $('#faxdocpreview').removeClass('icon-loading');
723
+                                   }
724
+
725
+                              } else {
726
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
727
+                                   $('#pf_choose_msg').hide();
728
+                                   $('#faxdocpreview').removeClass('icon-loading');
729
+                                }
730
+
731
+                        }
732
+                );
733
+  });
734
+
735
+
736
+  // Submit the fax
737
+  $("#submitfax").on("click", function(event){
738
+
739
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
740
+
741
+     var toNumberinit = $('#faxto').val();
742
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
743
+     var toNumber = toNumbersec.split(",");
744
+
745
+     for(var v = 0; v < toNumber.length; v++) {
746
+         toNumber[v] = "+" + toNumber[v];
747
+     }
748
+
749
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
750
+     $('#faxdocpreview').addClass('icon-loading');
751
+
752
+     var userid = "<?php p($userId); ?>";
753
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
754
+
755
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
756
+
757
+         if (uploadedtofax.length != 0) {
758
+
759
+           if (toNumberwc != '') {
760
+
761
+             $.ajax({
762
+                url: baseUrl + '/' + userid,
763
+                type: "POST",
764
+                data: {uploadedtofax: uploadedtofax,
765
+                       selectedcid: selectedcid,
766
+                       toNumber: toNumber
767
+                      },
768
+                success: function(phaxioresult) {
769
+
770
+                   if (phaxioresult.success == true) {
771
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
772
+                   } else {
773
+                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
774
+                   }
775
+
776
+                   $("div:visible[id*='indfilediv']").hide();
777
+                   $("div:visible[id*='indflpicked']").hide();
778
+                   $('[class*="indupfldl"]').hide();
779
+                   $('[class*="indpckfldl"]').hide();
780
+
781
+                   $('#faxdocpreview').hide();
782
+
783
+                   $('#filestotsize').hide();
784
+                   $('#submitfax').attr("disabled", true);
785
+                   $("#receivedfaxdir").attr("disabled", true);
786
+                   $("#sentfaxdir").attr("disabled", true);
787
+                   $("#receivedfaileddir").attr("disabled", true);
788
+                   $("#sentfaileddir").attr("disabled", true);
789
+
790
+                   location.reload(true);
791
+
792
+                },
793
+
794
+                error: function(phaxioresult) {
795
+
796
+                   alert('Error ! Please check your settings !');
797
+
798
+                   $("div:visible[id*='indfilediv']").hide();
799
+                   $("div:visible[id*='indflpicked']").hide();
800
+                   $('[class*="indupfldl"]').hide();
801
+                   $('[class*="indpckfldl"]').hide();
802
+
803
+                   $('#pf_submit_msg').hide();
804
+                   $('#filestotsize').hide();
805
+                   $('#faxdocpreview').hide();
806
+                   $('#submitfax').attr("disabled", true);
807
+
808
+
809
+                   $("#receivedfaxdir").attr("disabled", true);
810
+                   $("#sentfaxdir").attr("disabled", true);
811
+                   $("#receivedfaileddir").attr("disabled", true);
812
+                   $("#sentfaileddir").attr("disabled", true);
813
+
814
+                          location.reload(true);
815
+                }
816
+             });
817
+           } else {
818
+              $('#pf_submit_msg').hide();
819
+              $('#faxdocpreview').removeClass('icon-loading');
820
+              alert("Please enter the fax number of the recipient !");
821
+             }
822
+         } else {
823
+              $('#pf_submit_msg').hide();
824
+              $('#faxdocpreview').removeClass('icon-loading');
825
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
826
+           }
827
+  });
828
+
829
+  $("#receivedfaxdir").on("click", function(event){
830
+     $("#faxdocpreview").hide();
831
+     $("#faxfoldersview").show();
832
+     $("#faxfoldersview").addClass("icon-loading");
833
+     $("#faxfoldersview :last-child").remove();
834
+     var fxreceived = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received");
835
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxreceived + "' width='100%' height='100%'></iframe>");
836
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
837
+  });
838
+
839
+  $("#sentfaxdir").on("click", function(event){
840
+     $("#faxdocpreview").hide();
841
+     $("#faxfoldersview").show();
842
+     $("#faxfoldersview").addClass("icon-loading");
843
+     $("#faxfoldersview :last-child").remove();
844
+     var fxsent = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_sent");
845
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsent + "' width='100%' height='100%'></iframe>");
846
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
847
+  });
848
+
849
+  $("#receivedfaileddir").on("click", function(event){
850
+     $("#faxdocpreview").hide();
851
+     $("#faxfoldersview").show();
852
+     $("#faxfoldersview").addClass("icon-loading");
853
+     $("#faxfoldersview :last-child").remove();
854
+     var fxrecfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
855
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxrecfailed + "' width='100%' height='100%'></iframe>");
856
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
857
+  });
858
+
859
+  $("#sentfaileddir").on("click", function(event){
860
+     $("#faxdocpreview").hide();
861
+     $("#faxfoldersview").show();
862
+     $("#faxfoldersview").addClass("icon-loading");
863
+     $("#faxfoldersview :last-child").remove();
864
+     var fxsentfailed = OC.generateUrl("/apps/files/?dir=/Pax_Fax/faxes_received_failed");
865
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='" + fxsentfailed + "' width='100%' height='100%'></iframe>");
866
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
867
+  });
868
+
869
+  $(".indivflpckd").click(function(event){
870
+     $("#faxfoldersview").hide();
871
+  });
872
+
873
+  $(".indivflcls").on("click", function(event){
874
+     $("#faxfoldersview").hide();
875
+  });
876
+
877
+});
Browse code

removed CHANGELOG.txt Contributors.txt appinfo/info.xml appinfo/signature.json js/sendfax.js templates/settings.php

DoubleBastionAdmin authored on 28/04/2022 22:55:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,867 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Check the available balance
32
-  $("#checkbalance").on("click", function(event) {
33
-
34
-     $('#checkbalance').addClass('icon-loading');
35
-
36
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
37
-
38
-     $.ajax({
39
-          url: getbalanceUrl + '/' + userid,
40
-          type: "POST",
41
-          data: {userid: userid},
42
-          cache: false,
43
-          processData: false,
44
-          contentType: false,
45
-          success: function(phaxiobalance) {
46
-                 var balanceindlrs = phaxiobalance / 100;
47
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
48
-                 $('#currentbalance').text(balanceproc);
49
-
50
-                 $('#checkbalance').removeClass('icon-loading');
51
-          }
52
-     });
53
-  });
54
-
55
-  // Select the Caller ID
56
-  $("#selectcalleridbttn").on("click", function(event) {
57
-
58
-     $('#selectcalleridbttn').addClass('icon-loading');
59
-
60
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
61
-     var selectednmbr = null;
62
-
63
-     $.ajax({
64
-          url: getfaxnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: {userid: userid},
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(phaxionmbrs) {
71
-
72
-                    $('#currentfaxnmbrs').empty();
73
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
74
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
75
-
76
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
77
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
78
-                    });
79
-
80
-                    $('#selectcalleridbttn').removeClass('icon-loading');
81
-
82
-          }
83
-     });
84
-  });
85
-
86
-  // Clean the Pax_Fax/temp_files directory
87
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
88
-
89
-  $.ajax({
90
-          url: cleanflUrl + '/' + userid,
91
-          type: "POST",
92
-          data: {userid: userid},
93
-          cache: false,
94
-          processData: false,
95
-          contentType: false
96
-  });
97
-
98
-  var n = 1;
99
-  var uploadedtofax = [];
100
-  var ordernmbrs = [];
101
-
102
-  // Upload files to be faxed
103
-  $("#uploadfileforfax").change(function(e){
104
-
105
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
106
-     $('#faxdocpreview').addClass('icon-loading');
107
-     $('#filestotsize').show();
108
-
109
-     var userid = "<?php p($userId); ?>";
110
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
111
-
112
-     var formData = new FormData();
113
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
114
-
115
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
116
-
117
-     var fileup = $('#uploadfileforfax').val();
118
-     var fileuptrim = fileup.split('\\').pop();
119
-
120
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
121
-         var duplicatescheck = 1;
122
-     } else var duplicatescheck = 0;
123
-
124
-     var extension = fileup.replace(/^.*\./, '');
125
-
126
-     if (extension == fileup) {
127
-         extension = "";
128
-     } else {
129
-         extension = extension.toLowerCase();
130
-     }
131
-
132
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
133
-
134
-     if ($.inArray(extension, validExtensions) != -1) {
135
-
136
-       if (duplicatescheck == 0) {
137
-
138
-         if (currentflsize < 20971520) {
139
-
140
-            if (n < 21) {
141
-
142
-               uploadedtofax.push(fileuptrim);
143
-
144
-               $.ajax({
145
-                 url: baseUrl + '/' + userid,
146
-                 type: "POST",
147
-                 data: formData,
148
-                 cache: false,
149
-                 processData: false,
150
-                 contentType: false,
151
-                 success: function(totalflsize) {
152
-
153
-                   $('#filessizetext').text(totalflsize);
154
-
155
-                   // Check if the total file size is over 20 MB
156
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
157
-
158
-                   if (rectotfilesz > 20.00) {
159
-                       $('#filestotsize').css('color', '#ba3555');
160
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
161
-                       $('#submitfax').attr("disabled", true);
162
-                   } else {
163
-                       $('#submitfax').attr("disabled", false);
164
-                       $('#filestotsize').css('color', '#18bf6e');
165
-                     }
166
-
167
-
168
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
169
-                   n++;
170
-
171
-                   // Preview the file when you click on its name
172
-                   $("div:visible[id*='indfilediv']").each(function() {
173
-                        $(this).on("click", function(eventclck) {
174
-                           var faxfilenameinit = $(this).text();
175
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
176
-                           var faxfilename = faxfilenamesec.replace("X","");
177
-                           var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
178
-                           var extenlst = faxfilename.replace(/^.*\./, '');
179
-
180
-                           if (extenlst == faxfilename) {
181
-                               extenlst = "";
182
-                           } else {
183
-                               extenlst = extenlst.toLowerCase();
184
-                           }
185
-
186
-                           if (extenlst == 'pdf') {
187
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
188
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
189
-                                  $("#faxdocpreview").empty();
190
-                                  $("#faxdocpreview").append($iframe);
191
-                           } else if (extenlst == 'txt') {
192
-                                  $("#faxdocpreview").empty();
193
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
194
-                           } else if (extenlst == 'html') {
195
-                                  $("#faxdocpreview").empty();
196
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
197
-                           } else if (extenlst == 'jpg') {
198
-                                  $("#faxdocpreview").empty();
199
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
200
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
201
-                           } else if (extenlst == 'png') {
202
-                                  $("#faxdocpreview").empty();
203
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
204
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
205
-                           } else if (extenlst == 'odt') {
206
-                                  $("#faxdocpreview").empty();
207
-                                  function odfInit() {
208
-                                     var odfelement = document.getElementById("faxdocpreview");
209
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
210
-                                     odfcanvas.load(baseUrl);
211
-                                  }
212
-                                  window.setTimeout(odfInit, 0);
213
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
214
-                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
215
-                                  var xhr = new XMLHttpRequest();
216
-                                  xhr.responseType = 'arraybuffer';
217
-                                  xhr.open('GET', tiffile);
218
-                                  xhr.onload = function (evnt) {
219
-                                      var tiff = new Tiff({buffer: xhr.response});
220
-                                      var tifcanvas = tiff.toCanvas();
221
-                                      $("#faxdocpreview").empty();
222
-                                      $("#faxdocpreview").append(tifcanvas);
223
-                                  };
224
-                                  xhr.send();
225
-                           }
226
-
227
-                           $("#faxdocpreview").show();
228
-                           $("#faxfoldersview").hide();
229
-                        });
230
-                   });
231
-
232
-                   // Remove uploaded files
233
-                   $('[class*="indupfldl"]').last().click(function() {
234
-
235
-                           var userid = "<?php p($userId); ?>";
236
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
237
-
238
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
239
-
240
-                           var removedfilesplit = removedfilenameinit.split(") ");
241
-                           var removedflnb = parseInt(removedfilesplit[0]);
242
-
243
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
244
-                           $(this).hide();
245
-
246
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
247
-
248
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
249
-                                           return value != removedfilename;
250
-                           });
251
-
252
-                           $.ajax({
253
-                                   url: baseUrl + '/' + userid,
254
-                                   type: "POST",
255
-                                   data: {removedfilename: removedfilename},
256
-                                   success: function(totalflsize) {
257
-
258
-                                      $('#filessizetext').text(totalflsize);
259
-
260
-                                      // Check file size
261
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
262
-
263
-                                      if (rectotfilesz > 20.00) {
264
-                                          $('#filestotsize').css('color', '#ba3555');
265
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
266
-                                          $('#submitfax').attr("disabled", true);
267
-                                      } else {
268
-                                          $('#submitfax').attr("disabled", false);
269
-                                          $('#filestotsize').css('color', '#18bf6e');
270
-                                        }
271
-
272
-                                      // Rewrite order numbers for files that follow
273
-                                      --n;
274
-                                      $("div:visible[id*='indfilediv']").each(function() {
275
-
276
-                                          var getdivtext =  $(this).text();
277
-                                          var splitdivtext = getdivtext.split(") ");
278
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
279
-                                          var newnbvalue = currentnbvalue - 1;
280
-
281
-                                          if (currentnbvalue > removedflnb) {
282
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
283
-                                              $(this).text(replacedstr);
284
-                                          }
285
-                                      });
286
-
287
-                                      $("div:visible[id*='indflpicked']").each(function() {
288
-
289
-                                          var getdivtext =  $(this).text();
290
-                                          var splitdivtext = getdivtext.split(") ");
291
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
292
-                                          var newnbvalue = currentnbvalue - 1;
293
-
294
-                                          if (currentnbvalue > removedflnb) {
295
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
296
-                                              $(this).text(replacedstr);
297
-                                          }
298
-                                      });
299
-
300
-                                   },
301
-                                   error: function() {
302
-                                          alert('Error !');
303
-                                   }
304
-                           });
305
-
306
-                           $('#faxdocpreview').removeClass('icon-loading');
307
-                           $("#faxdocpreview").empty();
308
-                   });
309
-
310
-                   // Preview the uploaded file
311
-                   var faxfilename = e.target.files[0].name;
312
-                   var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
313
-
314
-                   if (extension == 'pdf') {
315
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
316
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
317
-                              $("#faxdocpreview").empty();
318
-                              $("#faxdocpreview").append($iframe);
319
-                   } else if (extension == 'txt') {
320
-                              var reader = new FileReader();
321
-                              reader.readAsText(e.target.files[0]);
322
-                              reader.onload = function(e) {
323
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
324
-                                  $("#faxdocpreview").empty();
325
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
326
-                              };
327
-                   } else if (extension == 'html') {
328
-                              var reader = new FileReader();
329
-                              reader.readAsText(e.target.files[0]);
330
-                              reader.onload = function(e) {
331
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
332
-                                  $("#faxdocpreview").empty();
333
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
334
-                              };
335
-                   } else if (extension == 'jpg') {
336
-                              $("#faxdocpreview").empty();
337
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
338
-
339
-                              var reader = new FileReader();
340
-                              reader.onload = function (e) {
341
-                                  readjpg[faxfilename] = e.target.result;
342
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
343
-                              }
344
-                              reader.readAsDataURL(e.target.files[0]);
345
-                   } else if (extension == 'png') {
346
-                              $("#faxdocpreview").empty();
347
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
348
-
349
-                              var reader = new FileReader();
350
-                              reader.onload = function (e) {
351
-                                  readpng[faxfilename] = e.target.result;
352
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
353
-                              }
354
-                              reader.readAsDataURL(e.target.files[0]);
355
-                   } else if (extension == 'odt') {
356
-                              $("#faxdocpreview").empty();
357
-                              function odfInit() {
358
-                                 var odfelement = document.getElementById("faxdocpreview");
359
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
360
-                                 odfcanvas.load(baseUrl);
361
-                              }
362
-                              window.setTimeout(odfInit, 0);
363
-                   } else if (extension == 'tif' || extension == 'tiff') {
364
-                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
365
-                              var xhr = new XMLHttpRequest();
366
-                              xhr.responseType = 'arraybuffer';
367
-                              xhr.open('GET', tiffile);
368
-                              xhr.onload = function (e) {
369
-                                  var tiff = new Tiff({buffer: xhr.response});
370
-                                  var tifcanvas = tiff.toCanvas();
371
-                                  $("#faxdocpreview").empty();
372
-                                  $("#faxdocpreview").append(tifcanvas);
373
-                              };
374
-                              xhr.send();
375
-                   }
376
-
377
-                   $("#faxdocpreview").show();
378
-                   $('#pf_upload_msg').hide();
379
-                   $('#faxdocpreview').removeClass('icon-loading');
380
-                   $("#faxfoldersview").hide();
381
-                 },
382
-                 error: function(data){
383
-                     alert('Error!');
384
-                 }
385
-               });
386
-
387
-            } else {
388
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
389
-                  $('#pf_upload_msg').hide();
390
-                  $('#faxdocpreview').removeClass('icon-loading');
391
-              }
392
-         } else {
393
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
394
-              $('#pf_upload_msg').hide();
395
-              $('#faxdocpreview').removeClass('icon-loading');
396
-           }
397
-       } else {
398
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
399
-            $('#pf_upload_msg').hide();
400
-            $('#faxdocpreview').removeClass('icon-loading');
401
-         }
402
-
403
-     } else {
404
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
405
-          $('#pf_upload_msg').hide();
406
-          $('#faxdocpreview').removeClass('icon-loading');
407
-       }
408
-  });
409
-
410
-
411
-  // Pick file to fax, from Nextcloud
412
-  var faxfilename = null;
413
-
414
-  $("#choosefilen").on("click", function(evn) {
415
-
416
-                OC.dialogs.filepicker(
417
-                        t('settings', "Select a file to send as fax."),
418
-                        function (path) {
419
-
420
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
421
-                              $('#faxdocpreview').addClass('icon-loading');
422
-                              $('#filestotsize').show();
423
-
424
-                              var userid = "<?php p($userId); ?>";
425
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
426
-
427
-                              faxfilename = path.split('/').pop();
428
-
429
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
430
-                                  var duplicatescheck = 1;
431
-                              } else var duplicatescheck = 0;
432
-
433
-                              var extension = faxfilename.replace(/^.*\./, '');
434
-
435
-                              if (extension == faxfilename) {
436
-                                  extension = "";
437
-                              } else {
438
-                                  extension = extension.toLowerCase();
439
-                              }
440
-
441
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
442
-
443
-                              if ($.inArray(extension, validExtensions) != -1) {
444
-
445
-                                 if (duplicatescheck == 0) {
446
-
447
-                                    if (n < 21) {
448
-
449
-                                       uploadedtofax.push(faxfilename);
450
-
451
-                                       $.ajax({
452
-                                          url: baseUrl + '/' + userid,
453
-                                          type: "POST",
454
-                                          data: {path: path},
455
-                                          success: function(totalflsize) {
456
-
457
-                                                $('#filessizetext').text(totalflsize);
458
-
459
-                                                // Check if the total file size is over 20 MB
460
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
461
-
462
-                                                if (rectotfilesz > 20.00) {
463
-                                                    $('#filestotsize').css('color', '#ba3555');
464
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
465
-                                                    $('#submitfax').attr("disabled", true);
466
-                                                } else {
467
-                                                    $('#submitfax').attr("disabled", false);
468
-                                                    $('#filestotsize').css('color', '#18bf6e');
469
-                                                }
470
-
471
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
472
-                                                n++;
473
-
474
-                                                $("div:visible[id*='indflpicked']").each(function() {
475
-                                                   $(this).on("click", function(event) {
476
-                                                      var faxfilenameinit = $(this).text();
477
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
478
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
479
-                                                      var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
480
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
481
-
482
-                                                      if (extenlst == faxfilenamesp) {
483
-                                                           extenlst = "";
484
-                                                      } else {
485
-                                                           extenlst = extenlst.toLowerCase();
486
-                                                      }
487
-
488
-                                                      if (extenlst == 'pdf') {
489
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
490
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
491
-                                                           $("#faxdocpreview").empty();
492
-                                                           $("#faxdocpreview").append($iframe);
493
-                                                      } else if (extenlst == 'txt') {
494
-                                                              $("#faxdocpreview").empty();
495
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
496
-                                                      } else if (extenlst == 'html') {
497
-                                                              $("#faxdocpreview").empty();
498
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
499
-                                                      } else if (extenlst == 'jpg') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
502
-                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
503
-                                                      } else if (extenlst == 'png') {
504
-                                                              $("#faxdocpreview").empty();
505
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
506
-                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
507
-                                                      } else if (extenlst == 'odt') {
508
-                                                              $("#faxdocpreview").empty();
509
-                                                              function odfInit() {
510
-                                                                 var odfelement = document.getElementById("faxdocpreview");
511
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
512
-                                                                 odfcanvas.load(baseUrl);
513
-                                                              }
514
-                                                              window.setTimeout(odfInit, 0);
515
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
516
-                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
517
-                                                              var xhr = new XMLHttpRequest();
518
-                                                              xhr.responseType = 'arraybuffer';
519
-                                                              xhr.open('GET', tiffile);
520
-                                                              xhr.onload = function (evnt) {
521
-                                                                  var tiff = new Tiff({buffer: xhr.response});
522
-                                                                  var tifcanvas = tiff.toCanvas();
523
-                                                                  $("#faxdocpreview").empty();
524
-                                                                  $("#faxdocpreview").append(tifcanvas);
525
-                                                              };
526
-                                                              xhr.send();
527
-                                                      }
528
-
529
-                                                      $("#faxdocpreview").show();
530
-                                                      $("#faxfoldersview").hide();
531
-                                                   });
532
-                                                });
533
-
534
-                                                // Remove picked files
535
-                                                $('[class*="indpckfldl"]').last().click(function() {
536
-                                                    var userid = "<?php p($userId); ?>";
537
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
538
-
539
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
540
-
541
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
542
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
543
-
544
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
545
-                                                    $(this).hide();
546
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
547
-
548
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
549
-                                                             return value != removedfilename;
550
-                                                    });
551
-
552
-                                                    $.ajax({
553
-                                                        url: baseUrl + '/' + userid,
554
-                                                        type: "POST",
555
-                                                        data: {removedfilename: removedfilename},
556
-                                                        success: function(totalflsize) {
557
-
558
-                                                             $('#filessizetext').text(totalflsize);
559
-
560
-                                                             // Check file size
561
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
562
-
563
-                                                             if (rectotfilesz > 20.00) {
564
-                                                                 $('#filestotsize').css('color', '#ba3555');
565
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
566
-                                                                 $('#submitfax').attr("disabled", true);
567
-                                                             } else {
568
-                                                                 $('#submitfax').attr("disabled", false);
569
-                                                                 $('#filestotsize').css('color', '#18bf6e');
570
-                                                               }
571
-
572
-                                                             // Rewrite order numbers for files that follow
573
-                                                             --n;
574
-                                                             $("div:visible[id*='indflpicked']").each(function() {
575
-
576
-                                                                  var getdivtext =  $(this).text();
577
-                                                                  var splitdivtext = getdivtext.split(") ");
578
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
579
-                                                                  var newnbvalue = currentnbvalue - 1;
580
-
581
-                                                                  if (currentnbvalue > removedflnb) {
582
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
583
-                                                                      $(this).text(replacedstr);
584
-                                                                  }
585
-                                                             });
586
-                                                        },
587
-                                                        error: function() {
588
-                                                             alert('Error !');
589
-                                                        }
590
-                                                    });
591
-
592
-                                                    $('#faxdocpreview').removeClass('icon-loading');
593
-                                                    $("#faxdocpreview").empty();
594
-                                                });
595
-
596
-                                          // Preview the picked file
597
-                                          var flUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
598
-                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
599
-
600
-                                          if (extension == 'pdf') {
601
-                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
602
-                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
603
-                                              $("#faxdocpreview").empty();
604
-                                              $("#faxdocpreview").append($iframe);
605
-                                          } else if (extension == 'txt') {
606
-
607
-                                              $.ajax({
608
-                                                  url: pickUrl + '/' + userid,
609
-                                                  type: "POST",
610
-                                                  data: {pickedfilename: faxfilename},
611
-                                                  success: function(getpickedfile) {
612
-                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
613
-                                                      $("#faxdocpreview").empty();
614
-                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
615
-                                                  },
616
-                                                  error: function() {
617
-                                                      alert('Unexpected error !');
618
-                                                  }
619
-                                              });
620
-
621
-                                          } else if (extension == 'html') {
622
-
623
-                                              $.ajax({
624
-                                                  url: pickUrl + '/' + userid,
625
-                                                  type: "POST",
626
-                                                  data: {pickedfilename: faxfilename},
627
-                                                  success: function(getpickedfile) {
628
-                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
629
-                                                      $("#faxdocpreview").empty();
630
-                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
631
-                                                  },
632
-                                                  error: function() {
633
-                                                      alert('Unexpected error !');
634
-                                                  }
635
-                                              });
636
-
637
-                                          } else if (extension == 'jpg') {
638
-
639
-                                              $.ajax({
640
-                                                  url: pickUrl + '/' + userid,
641
-                                                  type: "POST",
642
-                                                  data: {pickedfilename: faxfilename},
643
-                                                  success: function(getpickedfile) {
644
-                                                      $("#faxdocpreview").empty();
645
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
646
-                                                      readjpg[faxfilename] = getpickedfile;
647
-                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
648
-                                                  },
649
-                                                  error: function() {
650
-                                                      alert('Unexpected error !');
651
-                                                  }
652
-                                              });
653
-
654
-                                          } else if (extension == 'png') {
655
-
656
-                                              $.ajax({
657
-                                                  url: pickUrl + '/' + userid,
658
-                                                  type: "POST",
659
-                                                  data: {pickedfilename: faxfilename},
660
-                                                  success: function(getpickedfile) {
661
-                                                      $("#faxdocpreview").empty();
662
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
663
-                                                      readpng[faxfilename] = getpickedfile;
664
-                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
665
-                                                  },
666
-                                                  error: function() {
667
-                                                      alert('Unexpected error !');
668
-                                                  }
669
-                                              });
670
-
671
-                                          } else if (extension == 'odt') {
672
-                                              $("#faxdocpreview").empty();
673
-                                              function odfInit() {
674
-                                                  var odfelement = document.getElementById("faxdocpreview");
675
-                                                  odfcanvas = new odf.OdfCanvas(odfelement);
676
-                                                  odfcanvas.load(flUrl);
677
-                                               }
678
-                                               window.setTimeout(odfInit, 0);
679
-
680
-                                          } else if (extension == 'tif' || extension == 'tiff') {
681
-                                               var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
682
-                                               var xhr = new XMLHttpRequest();
683
-                                               xhr.responseType = 'arraybuffer';
684
-                                               xhr.open('GET', tiffile);
685
-                                               xhr.onload = function (event) {
686
-                                                   var tiff = new Tiff({buffer: xhr.response});
687
-                                                   var tifcanvas = tiff.toCanvas();
688
-                                                   $("#faxdocpreview").empty();
689
-                                                   $("#faxdocpreview").append(tifcanvas);
690
-                                               };
691
-                                               xhr.send();
692
-                                          }
693
-
694
-                                          $("#faxdocpreview").show();
695
-
696
-                                          $('#pf_choose_msg').hide();
697
-                                          $('#faxdocpreview').removeClass('icon-loading');
698
-                                          $("#faxfoldersview").hide();
699
-
700
-                                          },
701
-
702
-                                          error: function(data){
703
-                                             alert('Error!');
704
-                                          }
705
-
706
-                                       });
707
-
708
-                                    } else {
709
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
710
-                                        $('#pf_choose_msg').hide();
711
-                                        $('#faxdocpreview').removeClass('icon-loading');
712
-                                      }
713
-                                 } else {
714
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
715
-                                      $('#pf_choose_msg').hide();
716
-                                      $('#faxdocpreview').removeClass('icon-loading');
717
-                                   }
718
-
719
-                              } else {
720
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
721
-                                   $('#pf_choose_msg').hide();
722
-                                   $('#faxdocpreview').removeClass('icon-loading');
723
-                                }
724
-
725
-                        }
726
-                );
727
-  });
728
-
729
-
730
-  // Submit the fax
731
-  $("#submitfax").on("click", function(event){
732
-
733
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
734
-
735
-     var toNumberinit = $('#faxto').val();
736
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
737
-     var toNumber = toNumbersec.split(",");
738
-
739
-     for(var v = 0; v < toNumber.length; v++) {
740
-         toNumber[v] = "+" + toNumber[v];
741
-     }
742
-
743
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
744
-     $('#faxdocpreview').addClass('icon-loading');
745
-
746
-     var userid = "<?php p($userId); ?>";
747
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
748
-
749
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
750
-
751
-         if (uploadedtofax.length != 0) {
752
-
753
-           if (toNumberwc != '') {
754
-
755
-             $.ajax({
756
-                url: baseUrl + '/' + userid,
757
-                type: "POST",
758
-                data: {uploadedtofax: uploadedtofax,
759
-                       selectedcid: selectedcid,
760
-                       toNumber: toNumber
761
-                      },
762
-                success: function(phaxioresult) {
763
-
764
-                   if (phaxioresult.success == true) {
765
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
766
-                   } else {
767
-                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
768
-                   }
769
-
770
-                   $("div:visible[id*='indfilediv']").hide();
771
-                   $("div:visible[id*='indflpicked']").hide();
772
-                   $('[class*="indupfldl"]').hide();
773
-                   $('[class*="indpckfldl"]').hide();
774
-
775
-                   $('#faxdocpreview').hide();
776
-
777
-                   $('#filestotsize').hide();
778
-                   $('#submitfax').attr("disabled", true);
779
-                   $("#receivedfaxdir").attr("disabled", true);
780
-                   $("#sentfaxdir").attr("disabled", true);
781
-                   $("#receivedfaileddir").attr("disabled", true);
782
-                   $("#sentfaileddir").attr("disabled", true);
783
-
784
-                   location.reload(true);
785
-
786
-                },
787
-
788
-                error: function(phaxioresult) {
789
-
790
-                   alert('Error ! Please check your settings !');
791
-
792
-                   $("div:visible[id*='indfilediv']").hide();
793
-                   $("div:visible[id*='indflpicked']").hide();
794
-                   $('[class*="indupfldl"]').hide();
795
-                   $('[class*="indpckfldl"]').hide();
796
-
797
-                   $('#pf_submit_msg').hide();
798
-                   $('#filestotsize').hide();
799
-                   $('#faxdocpreview').hide();
800
-                   $('#submitfax').attr("disabled", true);
801
-
802
-
803
-                   $("#receivedfaxdir").attr("disabled", true);
804
-                   $("#sentfaxdir").attr("disabled", true);
805
-                   $("#receivedfaileddir").attr("disabled", true);
806
-                   $("#sentfaileddir").attr("disabled", true);
807
-
808
-                          location.reload(true);
809
-                }
810
-             });
811
-           } else { 
812
-              $('#pf_submit_msg').hide();
813
-              $('#faxdocpreview').removeClass('icon-loading');
814
-              alert("Please enter the fax number of the recipient !");
815
-             }  
816
-         } else {
817
-              $('#pf_submit_msg').hide();
818
-              $('#faxdocpreview').removeClass('icon-loading');
819
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
820
-           }
821
-  });
822
-
823
-  $("#receivedfaxdir").on("click", function(event){
824
-     $("#faxdocpreview").hide();
825
-     $("#faxfoldersview").show();
826
-     $("#faxfoldersview").addClass("icon-loading");
827
-     $("#faxfoldersview :last-child").remove();
828
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received' width='100%' height='100%'></iframe>");
829
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
830
-  });
831
-
832
-  $("#sentfaxdir").on("click", function(event){
833
-     $("#faxdocpreview").hide();
834
-     $("#faxfoldersview").show();
835
-     $("#faxfoldersview").addClass("icon-loading");
836
-     $("#faxfoldersview :last-child").remove();
837
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent' width='100%' height='100%'></iframe>");
838
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
839
-  });
840
-
841
-  $("#receivedfaileddir").on("click", function(event){
842
-     $("#faxdocpreview").hide();
843
-     $("#faxfoldersview").show();
844
-     $("#faxfoldersview").addClass("icon-loading");
845
-     $("#faxfoldersview :last-child").remove();
846
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received_failed' width='100%' height='100%'></iframe>");
847
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
848
-  });
849
-
850
-  $("#sentfaileddir").on("click", function(event){
851
-     $("#faxdocpreview").hide();
852
-     $("#faxfoldersview").show();
853
-     $("#faxfoldersview").addClass("icon-loading");
854
-     $("#faxfoldersview :last-child").remove();
855
-     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent_failed' width='100%' height='100%'></iframe>");
856
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
857
-  });
858
-
859
-  $(".indivflpckd").click(function(event){
860
-     $("#faxfoldersview").hide();
861
-  });
862
-
863
-  $(".indivflcls").on("click", function(event){
864
-     $("#faxfoldersview").hide();
865
-  });
866
-
867
-});
Browse code

added Contributors.txt CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 10/04/2022 21:51:43
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,867 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Check the available balance
32
+  $("#checkbalance").on("click", function(event) {
33
+
34
+     $('#checkbalance').addClass('icon-loading');
35
+
36
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
37
+
38
+     $.ajax({
39
+          url: getbalanceUrl + '/' + userid,
40
+          type: "POST",
41
+          data: {userid: userid},
42
+          cache: false,
43
+          processData: false,
44
+          contentType: false,
45
+          success: function(phaxiobalance) {
46
+                 var balanceindlrs = phaxiobalance / 100;
47
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
48
+                 $('#currentbalance').text(balanceproc);
49
+
50
+                 $('#checkbalance').removeClass('icon-loading');
51
+          }
52
+     });
53
+  });
54
+
55
+  // Select the Caller ID
56
+  $("#selectcalleridbttn").on("click", function(event) {
57
+
58
+     $('#selectcalleridbttn').addClass('icon-loading');
59
+
60
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
61
+     var selectednmbr = null;
62
+
63
+     $.ajax({
64
+          url: getfaxnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: {userid: userid},
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(phaxionmbrs) {
71
+
72
+                    $('#currentfaxnmbrs').empty();
73
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
74
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
75
+
76
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
77
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
78
+                    });
79
+
80
+                    $('#selectcalleridbttn').removeClass('icon-loading');
81
+
82
+          }
83
+     });
84
+  });
85
+
86
+  // Clean the Pax_Fax/temp_files directory
87
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
88
+
89
+  $.ajax({
90
+          url: cleanflUrl + '/' + userid,
91
+          type: "POST",
92
+          data: {userid: userid},
93
+          cache: false,
94
+          processData: false,
95
+          contentType: false
96
+  });
97
+
98
+  var n = 1;
99
+  var uploadedtofax = [];
100
+  var ordernmbrs = [];
101
+
102
+  // Upload files to be faxed
103
+  $("#uploadfileforfax").change(function(e){
104
+
105
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
106
+     $('#faxdocpreview').addClass('icon-loading');
107
+     $('#filestotsize').show();
108
+
109
+     var userid = "<?php p($userId); ?>";
110
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
111
+
112
+     var formData = new FormData();
113
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
114
+
115
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
116
+
117
+     var fileup = $('#uploadfileforfax').val();
118
+     var fileuptrim = fileup.split('\\').pop();
119
+
120
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
121
+         var duplicatescheck = 1;
122
+     } else var duplicatescheck = 0;
123
+
124
+     var extension = fileup.replace(/^.*\./, '');
125
+
126
+     if (extension == fileup) {
127
+         extension = "";
128
+     } else {
129
+         extension = extension.toLowerCase();
130
+     }
131
+
132
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
133
+
134
+     if ($.inArray(extension, validExtensions) != -1) {
135
+
136
+       if (duplicatescheck == 0) {
137
+
138
+         if (currentflsize < 20971520) {
139
+
140
+            if (n < 21) {
141
+
142
+               uploadedtofax.push(fileuptrim);
143
+
144
+               $.ajax({
145
+                 url: baseUrl + '/' + userid,
146
+                 type: "POST",
147
+                 data: formData,
148
+                 cache: false,
149
+                 processData: false,
150
+                 contentType: false,
151
+                 success: function(totalflsize) {
152
+
153
+                   $('#filessizetext').text(totalflsize);
154
+
155
+                   // Check if the total file size is over 20 MB
156
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
157
+
158
+                   if (rectotfilesz > 20.00) {
159
+                       $('#filestotsize').css('color', '#ba3555');
160
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
161
+                       $('#submitfax').attr("disabled", true);
162
+                   } else {
163
+                       $('#submitfax').attr("disabled", false);
164
+                       $('#filestotsize').css('color', '#18bf6e');
165
+                     }
166
+
167
+
168
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
169
+                   n++;
170
+
171
+                   // Preview the file when you click on its name
172
+                   $("div:visible[id*='indfilediv']").each(function() {
173
+                        $(this).on("click", function(eventclck) {
174
+                           var faxfilenameinit = $(this).text();
175
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
176
+                           var faxfilename = faxfilenamesec.replace("X","");
177
+                           var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
178
+                           var extenlst = faxfilename.replace(/^.*\./, '');
179
+
180
+                           if (extenlst == faxfilename) {
181
+                               extenlst = "";
182
+                           } else {
183
+                               extenlst = extenlst.toLowerCase();
184
+                           }
185
+
186
+                           if (extenlst == 'pdf') {
187
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
188
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
189
+                                  $("#faxdocpreview").empty();
190
+                                  $("#faxdocpreview").append($iframe);
191
+                           } else if (extenlst == 'txt') {
192
+                                  $("#faxdocpreview").empty();
193
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
194
+                           } else if (extenlst == 'html') {
195
+                                  $("#faxdocpreview").empty();
196
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
197
+                           } else if (extenlst == 'jpg') {
198
+                                  $("#faxdocpreview").empty();
199
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
200
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
201
+                           } else if (extenlst == 'png') {
202
+                                  $("#faxdocpreview").empty();
203
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
204
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
205
+                           } else if (extenlst == 'odt') {
206
+                                  $("#faxdocpreview").empty();
207
+                                  function odfInit() {
208
+                                     var odfelement = document.getElementById("faxdocpreview");
209
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
210
+                                     odfcanvas.load(baseUrl);
211
+                                  }
212
+                                  window.setTimeout(odfInit, 0);
213
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
214
+                                  var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
215
+                                  var xhr = new XMLHttpRequest();
216
+                                  xhr.responseType = 'arraybuffer';
217
+                                  xhr.open('GET', tiffile);
218
+                                  xhr.onload = function (evnt) {
219
+                                      var tiff = new Tiff({buffer: xhr.response});
220
+                                      var tifcanvas = tiff.toCanvas();
221
+                                      $("#faxdocpreview").empty();
222
+                                      $("#faxdocpreview").append(tifcanvas);
223
+                                  };
224
+                                  xhr.send();
225
+                           }
226
+
227
+                           $("#faxdocpreview").show();
228
+                           $("#faxfoldersview").hide();
229
+                        });
230
+                   });
231
+
232
+                   // Remove uploaded files
233
+                   $('[class*="indupfldl"]').last().click(function() {
234
+
235
+                           var userid = "<?php p($userId); ?>";
236
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
237
+
238
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
239
+
240
+                           var removedfilesplit = removedfilenameinit.split(") ");
241
+                           var removedflnb = parseInt(removedfilesplit[0]);
242
+
243
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
244
+                           $(this).hide();
245
+
246
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
247
+
248
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
249
+                                           return value != removedfilename;
250
+                           });
251
+
252
+                           $.ajax({
253
+                                   url: baseUrl + '/' + userid,
254
+                                   type: "POST",
255
+                                   data: {removedfilename: removedfilename},
256
+                                   success: function(totalflsize) {
257
+
258
+                                      $('#filessizetext').text(totalflsize);
259
+
260
+                                      // Check file size
261
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
262
+
263
+                                      if (rectotfilesz > 20.00) {
264
+                                          $('#filestotsize').css('color', '#ba3555');
265
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
266
+                                          $('#submitfax').attr("disabled", true);
267
+                                      } else {
268
+                                          $('#submitfax').attr("disabled", false);
269
+                                          $('#filestotsize').css('color', '#18bf6e');
270
+                                        }
271
+
272
+                                      // Rewrite order numbers for files that follow
273
+                                      --n;
274
+                                      $("div:visible[id*='indfilediv']").each(function() {
275
+
276
+                                          var getdivtext =  $(this).text();
277
+                                          var splitdivtext = getdivtext.split(") ");
278
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
279
+                                          var newnbvalue = currentnbvalue - 1;
280
+
281
+                                          if (currentnbvalue > removedflnb) {
282
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
283
+                                              $(this).text(replacedstr);
284
+                                          }
285
+                                      });
286
+
287
+                                      $("div:visible[id*='indflpicked']").each(function() {
288
+
289
+                                          var getdivtext =  $(this).text();
290
+                                          var splitdivtext = getdivtext.split(") ");
291
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
292
+                                          var newnbvalue = currentnbvalue - 1;
293
+
294
+                                          if (currentnbvalue > removedflnb) {
295
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
296
+                                              $(this).text(replacedstr);
297
+                                          }
298
+                                      });
299
+
300
+                                   },
301
+                                   error: function() {
302
+                                          alert('Error !');
303
+                                   }
304
+                           });
305
+
306
+                           $('#faxdocpreview').removeClass('icon-loading');
307
+                           $("#faxdocpreview").empty();
308
+                   });
309
+
310
+                   // Preview the uploaded file
311
+                   var faxfilename = e.target.files[0].name;
312
+                   var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
313
+
314
+                   if (extension == 'pdf') {
315
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
316
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
317
+                              $("#faxdocpreview").empty();
318
+                              $("#faxdocpreview").append($iframe);
319
+                   } else if (extension == 'txt') {
320
+                              var reader = new FileReader();
321
+                              reader.readAsText(e.target.files[0]);
322
+                              reader.onload = function(e) {
323
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
324
+                                  $("#faxdocpreview").empty();
325
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
326
+                              };
327
+                   } else if (extension == 'html') {
328
+                              var reader = new FileReader();
329
+                              reader.readAsText(e.target.files[0]);
330
+                              reader.onload = function(e) {
331
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
332
+                                  $("#faxdocpreview").empty();
333
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
334
+                              };
335
+                   } else if (extension == 'jpg') {
336
+                              $("#faxdocpreview").empty();
337
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
338
+
339
+                              var reader = new FileReader();
340
+                              reader.onload = function (e) {
341
+                                  readjpg[faxfilename] = e.target.result;
342
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
343
+                              }
344
+                              reader.readAsDataURL(e.target.files[0]);
345
+                   } else if (extension == 'png') {
346
+                              $("#faxdocpreview").empty();
347
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
348
+
349
+                              var reader = new FileReader();
350
+                              reader.onload = function (e) {
351
+                                  readpng[faxfilename] = e.target.result;
352
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
353
+                              }
354
+                              reader.readAsDataURL(e.target.files[0]);
355
+                   } else if (extension == 'odt') {
356
+                              $("#faxdocpreview").empty();
357
+                              function odfInit() {
358
+                                 var odfelement = document.getElementById("faxdocpreview");
359
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
360
+                                 odfcanvas.load(baseUrl);
361
+                              }
362
+                              window.setTimeout(odfInit, 0);
363
+                   } else if (extension == 'tif' || extension == 'tiff') {
364
+                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
365
+                              var xhr = new XMLHttpRequest();
366
+                              xhr.responseType = 'arraybuffer';
367
+                              xhr.open('GET', tiffile);
368
+                              xhr.onload = function (e) {
369
+                                  var tiff = new Tiff({buffer: xhr.response});
370
+                                  var tifcanvas = tiff.toCanvas();
371
+                                  $("#faxdocpreview").empty();
372
+                                  $("#faxdocpreview").append(tifcanvas);
373
+                              };
374
+                              xhr.send();
375
+                   }
376
+
377
+                   $("#faxdocpreview").show();
378
+                   $('#pf_upload_msg').hide();
379
+                   $('#faxdocpreview').removeClass('icon-loading');
380
+                   $("#faxfoldersview").hide();
381
+                 },
382
+                 error: function(data){
383
+                     alert('Error!');
384
+                 }
385
+               });
386
+
387
+            } else {
388
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
389
+                  $('#pf_upload_msg').hide();
390
+                  $('#faxdocpreview').removeClass('icon-loading');
391
+              }
392
+         } else {
393
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
394
+              $('#pf_upload_msg').hide();
395
+              $('#faxdocpreview').removeClass('icon-loading');
396
+           }
397
+       } else {
398
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
399
+            $('#pf_upload_msg').hide();
400
+            $('#faxdocpreview').removeClass('icon-loading');
401
+         }
402
+
403
+     } else {
404
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
405
+          $('#pf_upload_msg').hide();
406
+          $('#faxdocpreview').removeClass('icon-loading');
407
+       }
408
+  });
409
+
410
+
411
+  // Pick file to fax, from Nextcloud
412
+  var faxfilename = null;
413
+
414
+  $("#choosefilen").on("click", function(evn) {
415
+
416
+                OC.dialogs.filepicker(
417
+                        t('settings', "Select a file to send as fax."),
418
+                        function (path) {
419
+
420
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
421
+                              $('#faxdocpreview').addClass('icon-loading');
422
+                              $('#filestotsize').show();
423
+
424
+                              var userid = "<?php p($userId); ?>";
425
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
426
+
427
+                              faxfilename = path.split('/').pop();
428
+
429
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
430
+                                  var duplicatescheck = 1;
431
+                              } else var duplicatescheck = 0;
432
+
433
+                              var extension = faxfilename.replace(/^.*\./, '');
434
+
435
+                              if (extension == faxfilename) {
436
+                                  extension = "";
437
+                              } else {
438
+                                  extension = extension.toLowerCase();
439
+                              }
440
+
441
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
442
+
443
+                              if ($.inArray(extension, validExtensions) != -1) {
444
+
445
+                                 if (duplicatescheck == 0) {
446
+
447
+                                    if (n < 21) {
448
+
449
+                                       uploadedtofax.push(faxfilename);
450
+
451
+                                       $.ajax({
452
+                                          url: baseUrl + '/' + userid,
453
+                                          type: "POST",
454
+                                          data: {path: path},
455
+                                          success: function(totalflsize) {
456
+
457
+                                                $('#filessizetext').text(totalflsize);
458
+
459
+                                                // Check if the total file size is over 20 MB
460
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
461
+
462
+                                                if (rectotfilesz > 20.00) {
463
+                                                    $('#filestotsize').css('color', '#ba3555');
464
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
465
+                                                    $('#submitfax').attr("disabled", true);
466
+                                                } else {
467
+                                                    $('#submitfax').attr("disabled", false);
468
+                                                    $('#filestotsize').css('color', '#18bf6e');
469
+                                                }
470
+
471
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
472
+                                                n++;
473
+
474
+                                                $("div:visible[id*='indflpicked']").each(function() {
475
+                                                   $(this).on("click", function(event) {
476
+                                                      var faxfilenameinit = $(this).text();
477
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
478
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
479
+                                                      var baseUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp;
480
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
481
+
482
+                                                      if (extenlst == faxfilenamesp) {
483
+                                                           extenlst = "";
484
+                                                      } else {
485
+                                                           extenlst = extenlst.toLowerCase();
486
+                                                      }
487
+
488
+                                                      if (extenlst == 'pdf') {
489
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
490
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
491
+                                                           $("#faxdocpreview").empty();
492
+                                                           $("#faxdocpreview").append($iframe);
493
+                                                      } else if (extenlst == 'txt') {
494
+                                                              $("#faxdocpreview").empty();
495
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
496
+                                                      } else if (extenlst == 'html') {
497
+                                                              $("#faxdocpreview").empty();
498
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
499
+                                                      } else if (extenlst == 'jpg') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
502
+                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
503
+                                                      } else if (extenlst == 'png') {
504
+                                                              $("#faxdocpreview").empty();
505
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
506
+                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
507
+                                                      } else if (extenlst == 'odt') {
508
+                                                              $("#faxdocpreview").empty();
509
+                                                              function odfInit() {
510
+                                                                 var odfelement = document.getElementById("faxdocpreview");
511
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
512
+                                                                 odfcanvas.load(baseUrl);
513
+                                                              }
514
+                                                              window.setTimeout(odfInit, 0);
515
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
516
+                                                              var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp;
517
+                                                              var xhr = new XMLHttpRequest();
518
+                                                              xhr.responseType = 'arraybuffer';
519
+                                                              xhr.open('GET', tiffile);
520
+                                                              xhr.onload = function (evnt) {
521
+                                                                  var tiff = new Tiff({buffer: xhr.response});
522
+                                                                  var tifcanvas = tiff.toCanvas();
523
+                                                                  $("#faxdocpreview").empty();
524
+                                                                  $("#faxdocpreview").append(tifcanvas);
525
+                                                              };
526
+                                                              xhr.send();
527
+                                                      }
528
+
529
+                                                      $("#faxdocpreview").show();
530
+                                                      $("#faxfoldersview").hide();
531
+                                                   });
532
+                                                });
533
+
534
+                                                // Remove picked files
535
+                                                $('[class*="indpckfldl"]').last().click(function() {
536
+                                                    var userid = "<?php p($userId); ?>";
537
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
538
+
539
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
540
+
541
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
542
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
543
+
544
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
545
+                                                    $(this).hide();
546
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
547
+
548
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
549
+                                                             return value != removedfilename;
550
+                                                    });
551
+
552
+                                                    $.ajax({
553
+                                                        url: baseUrl + '/' + userid,
554
+                                                        type: "POST",
555
+                                                        data: {removedfilename: removedfilename},
556
+                                                        success: function(totalflsize) {
557
+
558
+                                                             $('#filessizetext').text(totalflsize);
559
+
560
+                                                             // Check file size
561
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
562
+
563
+                                                             if (rectotfilesz > 20.00) {
564
+                                                                 $('#filestotsize').css('color', '#ba3555');
565
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
566
+                                                                 $('#submitfax').attr("disabled", true);
567
+                                                             } else {
568
+                                                                 $('#submitfax').attr("disabled", false);
569
+                                                                 $('#filestotsize').css('color', '#18bf6e');
570
+                                                               }
571
+
572
+                                                             // Rewrite order numbers for files that follow
573
+                                                             --n;
574
+                                                             $("div:visible[id*='indflpicked']").each(function() {
575
+
576
+                                                                  var getdivtext =  $(this).text();
577
+                                                                  var splitdivtext = getdivtext.split(") ");
578
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
579
+                                                                  var newnbvalue = currentnbvalue - 1;
580
+
581
+                                                                  if (currentnbvalue > removedflnb) {
582
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
583
+                                                                      $(this).text(replacedstr);
584
+                                                                  }
585
+                                                             });
586
+                                                        },
587
+                                                        error: function() {
588
+                                                             alert('Error !');
589
+                                                        }
590
+                                                    });
591
+
592
+                                                    $('#faxdocpreview').removeClass('icon-loading');
593
+                                                    $("#faxdocpreview").empty();
594
+                                                });
595
+
596
+                                          // Preview the picked file
597
+                                          var flUrl = "/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename;
598
+                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
599
+
600
+                                          if (extension == 'pdf') {
601
+                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
602
+                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"></iframe>');
603
+                                              $("#faxdocpreview").empty();
604
+                                              $("#faxdocpreview").append($iframe);
605
+                                          } else if (extension == 'txt') {
606
+
607
+                                              $.ajax({
608
+                                                  url: pickUrl + '/' + userid,
609
+                                                  type: "POST",
610
+                                                  data: {pickedfilename: faxfilename},
611
+                                                  success: function(getpickedfile) {
612
+                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
613
+                                                      $("#faxdocpreview").empty();
614
+                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
615
+                                                  },
616
+                                                  error: function() {
617
+                                                      alert('Unexpected error !');
618
+                                                  }
619
+                                              });
620
+
621
+                                          } else if (extension == 'html') {
622
+
623
+                                              $.ajax({
624
+                                                  url: pickUrl + '/' + userid,
625
+                                                  type: "POST",
626
+                                                  data: {pickedfilename: faxfilename},
627
+                                                  success: function(getpickedfile) {
628
+                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
629
+                                                      $("#faxdocpreview").empty();
630
+                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
631
+                                                  },
632
+                                                  error: function() {
633
+                                                      alert('Unexpected error !');
634
+                                                  }
635
+                                              });
636
+
637
+                                          } else if (extension == 'jpg') {
638
+
639
+                                              $.ajax({
640
+                                                  url: pickUrl + '/' + userid,
641
+                                                  type: "POST",
642
+                                                  data: {pickedfilename: faxfilename},
643
+                                                  success: function(getpickedfile) {
644
+                                                      $("#faxdocpreview").empty();
645
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
646
+                                                      readjpg[faxfilename] = getpickedfile;
647
+                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
648
+                                                  },
649
+                                                  error: function() {
650
+                                                      alert('Unexpected error !');
651
+                                                  }
652
+                                              });
653
+
654
+                                          } else if (extension == 'png') {
655
+
656
+                                              $.ajax({
657
+                                                  url: pickUrl + '/' + userid,
658
+                                                  type: "POST",
659
+                                                  data: {pickedfilename: faxfilename},
660
+                                                  success: function(getpickedfile) {
661
+                                                      $("#faxdocpreview").empty();
662
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
663
+                                                      readpng[faxfilename] = getpickedfile;
664
+                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
665
+                                                  },
666
+                                                  error: function() {
667
+                                                      alert('Unexpected error !');
668
+                                                  }
669
+                                              });
670
+
671
+                                          } else if (extension == 'odt') {
672
+                                              $("#faxdocpreview").empty();
673
+                                              function odfInit() {
674
+                                                  var odfelement = document.getElementById("faxdocpreview");
675
+                                                  odfcanvas = new odf.OdfCanvas(odfelement);
676
+                                                  odfcanvas.load(flUrl);
677
+                                               }
678
+                                               window.setTimeout(odfInit, 0);
679
+
680
+                                          } else if (extension == 'tif' || extension == 'tiff') {
681
+                                               var tiffile = '/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename;
682
+                                               var xhr = new XMLHttpRequest();
683
+                                               xhr.responseType = 'arraybuffer';
684
+                                               xhr.open('GET', tiffile);
685
+                                               xhr.onload = function (event) {
686
+                                                   var tiff = new Tiff({buffer: xhr.response});
687
+                                                   var tifcanvas = tiff.toCanvas();
688
+                                                   $("#faxdocpreview").empty();
689
+                                                   $("#faxdocpreview").append(tifcanvas);
690
+                                               };
691
+                                               xhr.send();
692
+                                          }
693
+
694
+                                          $("#faxdocpreview").show();
695
+
696
+                                          $('#pf_choose_msg').hide();
697
+                                          $('#faxdocpreview').removeClass('icon-loading');
698
+                                          $("#faxfoldersview").hide();
699
+
700
+                                          },
701
+
702
+                                          error: function(data){
703
+                                             alert('Error!');
704
+                                          }
705
+
706
+                                       });
707
+
708
+                                    } else {
709
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
710
+                                        $('#pf_choose_msg').hide();
711
+                                        $('#faxdocpreview').removeClass('icon-loading');
712
+                                      }
713
+                                 } else {
714
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
715
+                                      $('#pf_choose_msg').hide();
716
+                                      $('#faxdocpreview').removeClass('icon-loading');
717
+                                   }
718
+
719
+                              } else {
720
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
721
+                                   $('#pf_choose_msg').hide();
722
+                                   $('#faxdocpreview').removeClass('icon-loading');
723
+                                }
724
+
725
+                        }
726
+                );
727
+  });
728
+
729
+
730
+  // Submit the fax
731
+  $("#submitfax").on("click", function(event){
732
+
733
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
734
+
735
+     var toNumberinit = $('#faxto').val();
736
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
737
+     var toNumber = toNumbersec.split(",");
738
+
739
+     for(var v = 0; v < toNumber.length; v++) {
740
+         toNumber[v] = "+" + toNumber[v];
741
+     }
742
+
743
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
744
+     $('#faxdocpreview').addClass('icon-loading');
745
+
746
+     var userid = "<?php p($userId); ?>";
747
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
748
+
749
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
750
+
751
+         if (uploadedtofax.length != 0) {
752
+
753
+           if (toNumberwc != '') {
754
+
755
+             $.ajax({
756
+                url: baseUrl + '/' + userid,
757
+                type: "POST",
758
+                data: {uploadedtofax: uploadedtofax,
759
+                       selectedcid: selectedcid,
760
+                       toNumber: toNumber
761
+                      },
762
+                success: function(phaxioresult) {
763
+
764
+                   if (phaxioresult.success == true) {
765
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
766
+                   } else {
767
+                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
768
+                   }
769
+
770
+                   $("div:visible[id*='indfilediv']").hide();
771
+                   $("div:visible[id*='indflpicked']").hide();
772
+                   $('[class*="indupfldl"]').hide();
773
+                   $('[class*="indpckfldl"]').hide();
774
+
775
+                   $('#faxdocpreview').hide();
776
+
777
+                   $('#filestotsize').hide();
778
+                   $('#submitfax').attr("disabled", true);
779
+                   $("#receivedfaxdir").attr("disabled", true);
780
+                   $("#sentfaxdir").attr("disabled", true);
781
+                   $("#receivedfaileddir").attr("disabled", true);
782
+                   $("#sentfaileddir").attr("disabled", true);
783
+
784
+                   location.reload(true);
785
+
786
+                },
787
+
788
+                error: function(phaxioresult) {
789
+
790
+                   alert('Error ! Please check your settings !');
791
+
792
+                   $("div:visible[id*='indfilediv']").hide();
793
+                   $("div:visible[id*='indflpicked']").hide();
794
+                   $('[class*="indupfldl"]').hide();
795
+                   $('[class*="indpckfldl"]').hide();
796
+
797
+                   $('#pf_submit_msg').hide();
798
+                   $('#filestotsize').hide();
799
+                   $('#faxdocpreview').hide();
800
+                   $('#submitfax').attr("disabled", true);
801
+
802
+
803
+                   $("#receivedfaxdir").attr("disabled", true);
804
+                   $("#sentfaxdir").attr("disabled", true);
805
+                   $("#receivedfaileddir").attr("disabled", true);
806
+                   $("#sentfaileddir").attr("disabled", true);
807
+
808
+                          location.reload(true);
809
+                }
810
+             });
811
+           } else { 
812
+              $('#pf_submit_msg').hide();
813
+              $('#faxdocpreview').removeClass('icon-loading');
814
+              alert("Please enter the fax number of the recipient !");
815
+             }  
816
+         } else {
817
+              $('#pf_submit_msg').hide();
818
+              $('#faxdocpreview').removeClass('icon-loading');
819
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
820
+           }
821
+  });
822
+
823
+  $("#receivedfaxdir").on("click", function(event){
824
+     $("#faxdocpreview").hide();
825
+     $("#faxfoldersview").show();
826
+     $("#faxfoldersview").addClass("icon-loading");
827
+     $("#faxfoldersview :last-child").remove();
828
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received' width='100%' height='100%'></iframe>");
829
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
830
+  });
831
+
832
+  $("#sentfaxdir").on("click", function(event){
833
+     $("#faxdocpreview").hide();
834
+     $("#faxfoldersview").show();
835
+     $("#faxfoldersview").addClass("icon-loading");
836
+     $("#faxfoldersview :last-child").remove();
837
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent' width='100%' height='100%'></iframe>");
838
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
839
+  });
840
+
841
+  $("#receivedfaileddir").on("click", function(event){
842
+     $("#faxdocpreview").hide();
843
+     $("#faxfoldersview").show();
844
+     $("#faxfoldersview").addClass("icon-loading");
845
+     $("#faxfoldersview :last-child").remove();
846
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received_failed' width='100%' height='100%'></iframe>");
847
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
848
+  });
849
+
850
+  $("#sentfaileddir").on("click", function(event){
851
+     $("#faxdocpreview").hide();
852
+     $("#faxfoldersview").show();
853
+     $("#faxfoldersview").addClass("icon-loading");
854
+     $("#faxfoldersview :last-child").remove();
855
+     $("#faxfoldersview").append("<iframe id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent_failed' width='100%' height='100%'></iframe>");
856
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
857
+  });
858
+
859
+  $(".indivflpckd").click(function(event){
860
+     $("#faxfoldersview").hide();
861
+  });
862
+
863
+  $(".indivflcls").on("click", function(event){
864
+     $("#faxfoldersview").hide();
865
+  });
866
+
867
+});
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendfax.js lib/Controller/PaxfaxController.php

DoubleBastionAdmin authored on 10/04/2022 21:48:49
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,873 +0,0 @@
1
-/**
2
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
- *
4
- * @author Double Bastion LLC
5
- *
6
- * @license GNU AGPL version 3 or any later version
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
- * License as published by the Free Software Foundation; either
11
- * version 3 of the License, or any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
- *
18
- * You should have received a copy of the GNU Affero General Public
19
- * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-
23
-$(document).ready(function() {
24
-
25
-  var userid = "<?php p($userId); ?>";
26
-  var readtxtfile = [];
27
-  var readhtmlfile = [];
28
-  var readjpg = [];
29
-  var readpng = [];
30
-
31
-  // Check the available balance
32
-  $("#checkbalance").on("click", function(event) {
33
-
34
-     $('#checkbalance').addClass('icon-loading');
35
-
36
-     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
37
-
38
-     $.ajax({
39
-          url: getbalanceUrl + '/' + userid,
40
-          type: "POST",
41
-          data: {userid: userid},
42
-          cache: false,
43
-          processData: false,
44
-          contentType: false,
45
-          success: function(phaxiobalance) {
46
-                 var balanceindlrs = phaxiobalance / 100;
47
-                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
48
-                 $('#currentbalance').text(balanceproc);
49
-
50
-                 $('#checkbalance').removeClass('icon-loading');
51
-          }
52
-     });
53
-  });
54
-
55
-  // Select the Caller ID
56
-  $("#selectcalleridbttn").on("click", function(event) {
57
-
58
-     $('#selectcalleridbttn').addClass('icon-loading');
59
-
60
-     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
61
-     var selectednmbr = null;
62
-
63
-     $.ajax({
64
-          url: getfaxnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: {userid: userid},
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(phaxionmbrs) {
71
-
72
-                    $('#currentfaxnmbrs').empty();
73
-                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
74
-                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
75
-
76
-                    $.each(phaxionmbrs, function(key, indfxnmb) {
77
-                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
78
-                    });
79
-
80
-                    $('#selectcalleridbttn').removeClass('icon-loading');
81
-
82
-          }
83
-     });
84
-  });
85
-
86
-  // Clean the Pax_Fax/temp_files directory
87
-  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
88
-
89
-  $.ajax({
90
-          url: cleanflUrl + '/' + userid,
91
-          type: "POST",
92
-          data: {userid: userid},
93
-          cache: false,
94
-          processData: false,
95
-          contentType: false
96
-  });
97
-
98
-  var n = 1;
99
-  var uploadedtofax = [];
100
-  var ordernmbrs = [];
101
-
102
-  // Upload files to be faxed
103
-  $("#uploadfileforfax").change(function(e){
104
-
105
-     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
106
-     $('#faxdocpreview').addClass('icon-loading');
107
-     $('#filestotsize').show();
108
-
109
-     var userid = "<?php p($userId); ?>";
110
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
111
-
112
-     var formData = new FormData();
113
-     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
114
-
115
-     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
116
-
117
-     var fileup = $('#uploadfileforfax').val();
118
-     var fileuptrim = fileup.split('\\').pop();
119
-
120
-     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
121
-         var duplicatescheck = 1;
122
-     } else var duplicatescheck = 0;
123
-
124
-     var extension = fileup.replace(/^.*\./, '');
125
-
126
-     if (extension == fileup) {
127
-         extension = "";
128
-     } else {
129
-         extension = extension.toLowerCase();
130
-     }
131
-
132
-     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
133
-
134
-     if ($.inArray(extension, validExtensions) != -1) {
135
-
136
-       if (duplicatescheck == 0) {
137
-
138
-         if (currentflsize < 20971520) {
139
-
140
-            if (n < 21) {
141
-
142
-               uploadedtofax.push(fileuptrim);
143
-
144
-               $.ajax({
145
-                 url: baseUrl + '/' + userid,
146
-                 type: "POST",
147
-                 data: formData,
148
-                 cache: false,
149
-                 processData: false,
150
-                 contentType: false,
151
-                 success: function(totalflsize) {
152
-
153
-                   $('#filessizetext').text(totalflsize);
154
-
155
-                   // Check if the total file size is over 20 MB
156
-                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
157
-
158
-                   if (rectotfilesz > 20.00) {
159
-                       $('#filestotsize').css('color', '#ba3555');
160
-                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
161
-                       $('#submitfax').attr("disabled", true);
162
-                   } else {
163
-                       $('#submitfax').attr("disabled", false);
164
-                       $('#filestotsize').css('color', '#18bf6e');
165
-                     }
166
-
167
-
168
-                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
169
-                   n++;
170
-
171
-                   // Preview the file
172
-                   $("div:visible[id*='indfilediv']").each(function() {
173
-                        $(this).on("click", function(eventclck) {
174
-                           var faxfilenameinit = $(this).text();
175
-                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
176
-                           var faxfilename = faxfilenamesec.replace("X","");
177
-                           var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
178
-
179
-                           var extenlst = faxfilename.replace(/^.*\./, '');
180
-
181
-                           if (extenlst == faxfilename) {
182
-                               extenlst = "";
183
-                           } else {
184
-                               extenlst = extenlst.toLowerCase();
185
-                           }
186
-
187
-                           if (extenlst == 'pdf') {
188
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
189
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
190
-                                  $("#faxdocpreview").empty();
191
-                                  $("#faxdocpreview").append($iframe);
192
-                           } else if (extenlst == 'txt') {
193
-                                  $("#faxdocpreview").empty();
194
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
195
-                           } else if (extenlst == 'html') {
196
-                                  $("#faxdocpreview").empty();
197
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
198
-                           } else if (extenlst == 'jpg') {
199
-                                  $("#faxdocpreview").empty();
200
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
201
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
202
-                           } else if (extenlst == 'png') {
203
-                                  $("#faxdocpreview").empty();
204
-                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
205
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
206
-                           } else if (extenlst == 'odt') {
207
-                                  $("#faxdocpreview").empty();
208
-                                  function odfInit() {
209
-                                     var odfelement = document.getElementById("faxdocpreview");
210
-                                     odfcanvas = new odf.OdfCanvas(odfelement);
211
-                                     odfcanvas.load(baseUrl);
212
-                                  }
213
-                                  window.setTimeout(odfInit, 0);
214
-                           } else if (extenlst == 'docx') {
215
-                                  $("#faxdocpreview").empty();
216
-                                  var viewerclick = OC.generateUrl("/apps/files?dir=/Pax_Fax/temp_files&openfile="+fileid);
217
-                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
218
-                                  $("#faxdocpreview").append($iframe);
219
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
220
-                                  var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
221
-                                  var xhr = new XMLHttpRequest();
222
-                                  xhr.responseType = 'arraybuffer';
223
-                                  xhr.open('GET', tiffile);
224
-                                  xhr.onload = function (evnt) {
225
-                                      var tiff = new Tiff({buffer: xhr.response});
226
-                                      var tifcanvas = tiff.toCanvas();
227
-                                      $("#faxdocpreview").empty();
228
-                                      $("#faxdocpreview").append(tifcanvas);
229
-                                  };
230
-                                  xhr.send();
231
-                           }
232
-
233
-                           $("#faxdocpreview").show();
234
-                           $("#faxfoldersview").hide();
235
-                        });
236
-                   });
237
-
238
-                   // Remove uploaded files
239
-                   $('[class*="indupfldl"]').last().click(function() {
240
-
241
-                           var userid = "<?php p($userId); ?>";
242
-                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
243
-
244
-                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
245
-
246
-                           var removedfilesplit = removedfilenameinit.split(") ");
247
-                           var removedflnb = parseInt(removedfilesplit[0]);
248
-
249
-                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
250
-                           $(this).hide();
251
-
252
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
253
-
254
-                           uploadedtofax = $.grep(uploadedtofax, function(value) {
255
-                                           return value != removedfilename;
256
-                           });
257
-
258
-                           $.ajax({
259
-                                   url: baseUrl + '/' + userid,
260
-                                   type: "POST",
261
-                                   data: {removedfilename: removedfilename},
262
-                                   success: function(totalflsize) {
263
-
264
-                                      $('#filessizetext').text(totalflsize);
265
-
266
-                                      // Check file size
267
-                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
268
-
269
-                                      if (rectotfilesz > 20.00) {
270
-                                          $('#filestotsize').css('color', '#ba3555');
271
-                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
272
-                                          $('#submitfax').attr("disabled", true);
273
-                                      } else {
274
-                                          $('#submitfax').attr("disabled", false);
275
-                                          $('#filestotsize').css('color', '#18bf6e');
276
-                                        }
277
-
278
-                                      // Rewrite order numbers for files that follow
279
-                                      --n;
280
-                                      $("div:visible[id*='indfilediv']").each(function() {
281
-
282
-                                          var getdivtext =  $(this).text();
283
-                                          var splitdivtext = getdivtext.split(") ");
284
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
285
-                                          var newnbvalue = currentnbvalue - 1;
286
-
287
-                                          if (currentnbvalue > removedflnb) {
288
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
289
-                                              $(this).text(replacedstr);
290
-                                          }
291
-                                      });
292
-
293
-                                      $("div:visible[id*='indflpicked']").each(function() {
294
-
295
-                                          var getdivtext =  $(this).text();
296
-                                          var splitdivtext = getdivtext.split(") ");
297
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
298
-                                          var newnbvalue = currentnbvalue - 1;
299
-
300
-                                          if (currentnbvalue > removedflnb) {
301
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
302
-                                              $(this).text(replacedstr);
303
-                                          }
304
-                                      });
305
-
306
-                                   },
307
-                                   error: function() {
308
-                                          alert('Error !');
309
-                                   }
310
-                           });
311
-
312
-                           $('#faxdocpreview').removeClass('icon-loading');
313
-                           $("#faxdocpreview").empty();
314
-                   });
315
-
316
-                   // Preview the uploaded file
317
-                   var faxfilename = e.target.files[0].name;
318
-                   var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
319
-
320
-                   if (extension == 'pdf') {
321
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
322
-                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
323
-                              $("#faxdocpreview").empty();
324
-                              $("#faxdocpreview").append($iframe);
325
-                   } else if (extension == 'txt') {
326
-                              var reader = new FileReader();
327
-                              reader.readAsText(e.target.files[0]);
328
-                              reader.onload = function(e) {
329
-                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
330
-                                  $("#faxdocpreview").empty();
331
-                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
332
-                              };
333
-                   } else if (extension == 'html') {
334
-                              var reader = new FileReader();
335
-                              reader.readAsText(e.target.files[0]);
336
-                              reader.onload = function(e) {
337
-                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
338
-                                  $("#faxdocpreview").empty();
339
-                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
340
-                              };
341
-                   } else if (extension == 'jpg') {
342
-                              $("#faxdocpreview").empty();
343
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
344
-
345
-                              var reader = new FileReader();
346
-                              reader.onload = function (e) {
347
-                                  readjpg[faxfilename] = e.target.result;
348
-                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
349
-                              }
350
-                              reader.readAsDataURL(e.target.files[0]);
351
-                   } else if (extension == 'png') {
352
-                              $("#faxdocpreview").empty();
353
-                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
354
-
355
-                              var reader = new FileReader();
356
-                              reader.onload = function (e) {
357
-                                  readpng[faxfilename] = e.target.result;
358
-                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
359
-                              }
360
-                              reader.readAsDataURL(e.target.files[0]);
361
-                   } else if (extension == 'odt') {
362
-                              $("#faxdocpreview").empty();
363
-                              function odfInit() {
364
-                                 var odfelement = document.getElementById("faxdocpreview");
365
-                                 odfcanvas = new odf.OdfCanvas(odfelement);
366
-                                 odfcanvas.load(baseUrl);
367
-                              }
368
-                              window.setTimeout(odfInit, 0);
369
-                   } else if (extension == 'tif' || extension == 'tiff') {
370
-                              var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
371
-                              var xhr = new XMLHttpRequest();
372
-                              xhr.responseType = 'arraybuffer';
373
-                              xhr.open('GET', tiffile);
374
-                              xhr.onload = function (e) {
375
-                                  var tiff = new Tiff({buffer: xhr.response});
376
-                                  var tifcanvas = tiff.toCanvas();
377
-                                  $("#faxdocpreview").empty();
378
-                                  $("#faxdocpreview").append(tifcanvas);
379
-                              };
380
-                              xhr.send();
381
-                   }
382
-
383
-                   $("#faxdocpreview").show();
384
-                   $('#pf_upload_msg').hide();
385
-                   $('#faxdocpreview').removeClass('icon-loading');
386
-                   $("#faxfoldersview").hide();
387
-                 },
388
-                 error: function(data){
389
-                     alert('Error!');
390
-                 }
391
-               });
392
-
393
-            } else {
394
-                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
395
-                  $('#pf_upload_msg').hide();
396
-                  $('#faxdocpreview').removeClass('icon-loading');
397
-              }
398
-         } else {
399
-              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
400
-              $('#pf_upload_msg').hide();
401
-              $('#faxdocpreview').removeClass('icon-loading');
402
-           }
403
-       } else {
404
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
405
-            $('#pf_upload_msg').hide();
406
-            $('#faxdocpreview').removeClass('icon-loading');
407
-         }
408
-
409
-     } else {
410
-          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
411
-          $('#pf_upload_msg').hide();
412
-          $('#faxdocpreview').removeClass('icon-loading');
413
-       }
414
-  });
415
-
416
-
417
-  // Pick file to fax, from Nextcloud
418
-  var faxfilename = null;
419
-
420
-  $("#choosefilen").on("click", function(evn) {
421
-
422
-                OC.dialogs.filepicker(
423
-                        t('settings', "Select a file to send as fax."),
424
-                        function (path) {
425
-
426
-                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
427
-                              $('#faxdocpreview').addClass('icon-loading');
428
-                              $('#filestotsize').show();
429
-
430
-                              var userid = "<?php p($userId); ?>";
431
-                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
432
-
433
-                              faxfilename = path.split('/').pop();
434
-
435
-                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
436
-                                  var duplicatescheck = 1;
437
-                              } else var duplicatescheck = 0;
438
-
439
-                              var extension = faxfilename.replace(/^.*\./, '');
440
-
441
-                              if (extension == faxfilename) {
442
-                                  extension = "";
443
-                              } else {
444
-                                  extension = extension.toLowerCase();
445
-                              }
446
-
447
-                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
448
-
449
-                              if ($.inArray(extension, validExtensions) != -1) {
450
-
451
-                                 if (duplicatescheck == 0) {
452
-
453
-                                    if (n < 21) {
454
-
455
-                                       uploadedtofax.push(faxfilename);
456
-
457
-                                       $.ajax({
458
-                                          url: baseUrl + '/' + userid,
459
-                                          type: "POST",
460
-                                          data: {path: path},
461
-                                          success: function(totalflsize) {
462
-
463
-                                                $('#filessizetext').text(totalflsize);
464
-
465
-                                                // Check if the total file size is over 20 MB
466
-                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
467
-
468
-                                                if (rectotfilesz > 20.00) {
469
-                                                    $('#filestotsize').css('color', '#ba3555');
470
-                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
471
-                                                    $('#submitfax').attr("disabled", true);
472
-                                                } else {
473
-                                                    $('#submitfax').attr("disabled", false);
474
-                                                    $('#filestotsize').css('color', '#18bf6e');
475
-                                                }
476
-
477
-                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
478
-                                                n++;
479
-
480
-                                                $("div:visible[id*='indflpicked']").each(function() {
481
-                                                   $(this).on("click", function(event) {
482
-                                                      var faxfilenameinit = $(this).text();
483
-                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
-                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
-                                                      var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp);
486
-                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
-
488
-                                                      if (extenlst == faxfilenamesp) {
489
-                                                           extenlst = "";
490
-                                                      } else {
491
-                                                           extenlst = extenlst.toLowerCase();
492
-                                                      }
493
-
494
-                                                      if (extenlst == 'pdf') {
495
-                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
-                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
497
-                                                           $("#faxdocpreview").empty();
498
-                                                           $("#faxdocpreview").append($iframe);
499
-                                                      } else if (extenlst == 'txt') {
500
-                                                              $("#faxdocpreview").empty();
501
-                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
-                                                      } else if (extenlst == 'html') {
503
-                                                              $("#faxdocpreview").empty();
504
-                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
-                                                      } else if (extenlst == 'jpg') {
506
-                                                              $("#faxdocpreview").empty();
507
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
508
-                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
-                                                      } else if (extenlst == 'png') {
510
-                                                              $("#faxdocpreview").empty();
511
-                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
512
-                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
-                                                      } else if (extenlst == 'odt') {
514
-                                                              $("#faxdocpreview").empty();
515
-                                                              function odfInit() {
516
-                                                                 var odfelement = document.getElementById("faxdocpreview");
517
-                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
-                                                                 odfcanvas.load(baseUrl);
519
-                                                              }
520
-                                                              window.setTimeout(odfInit, 0);
521
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
-                                                              var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp);
523
-                                                              var xhr = new XMLHttpRequest();
524
-                                                              xhr.responseType = 'arraybuffer';
525
-                                                              xhr.open('GET', tiffile);
526
-                                                              xhr.onload = function (evnt) {
527
-                                                                  var tiff = new Tiff({buffer: xhr.response});
528
-                                                                  var tifcanvas = tiff.toCanvas();
529
-                                                                  $("#faxdocpreview").empty();
530
-                                                                  $("#faxdocpreview").append(tifcanvas);
531
-                                                              };
532
-                                                              xhr.send();
533
-                                                      }
534
-
535
-                                                      $("#faxdocpreview").show();
536
-                                                      $("#faxfoldersview").hide();
537
-                                                   });
538
-                                                });
539
-
540
-                                                // Remove picked files
541
-                                                $('[class*="indpckfldl"]').last().click(function() {
542
-                                                    var userid = "<?php p($userId); ?>";
543
-                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
-
545
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
-
547
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
-
550
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
-                                                    $(this).hide();
552
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
-
554
-                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
-                                                             return value != removedfilename;
556
-                                                    });
557
-
558
-                                                    $.ajax({
559
-                                                        url: baseUrl + '/' + userid,
560
-                                                        type: "POST",
561
-                                                        data: {removedfilename: removedfilename},
562
-                                                        success: function(totalflsize) {
563
-
564
-                                                             $('#filessizetext').text(totalflsize);
565
-
566
-                                                             // Check file size
567
-                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
-
569
-                                                             if (rectotfilesz > 20.00) {
570
-                                                                 $('#filestotsize').css('color', '#ba3555');
571
-                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
-                                                                 $('#submitfax').attr("disabled", true);
573
-                                                             } else {
574
-                                                                 $('#submitfax').attr("disabled", false);
575
-                                                                 $('#filestotsize').css('color', '#18bf6e');
576
-                                                               }
577
-
578
-                                                             // Rewrite order numbers for files that follow
579
-                                                             --n;
580
-                                                             $("div:visible[id*='indflpicked']").each(function() {
581
-
582
-                                                                  var getdivtext =  $(this).text();
583
-                                                                  var splitdivtext = getdivtext.split(") ");
584
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
-                                                                  var newnbvalue = currentnbvalue - 1;
586
-
587
-                                                                  if (currentnbvalue > removedflnb) {
588
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
-                                                                      $(this).text(replacedstr);
590
-                                                                  }
591
-                                                             });
592
-                                                        },
593
-                                                        error: function() {
594
-                                                             alert('Error !');
595
-                                                        }
596
-                                                    });
597
-
598
-                                                    $('#faxdocpreview').removeClass('icon-loading');
599
-                                                    $("#faxdocpreview").empty();
600
-                                                });
601
-
602
-                                          // Preview the picked file
603
-                                          var flUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
604
-                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
605
-
606
-                                          if (extension == 'pdf') {
607
-                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
608
-                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
609
-                                              $("#faxdocpreview").empty();
610
-                                              $("#faxdocpreview").append($iframe);
611
-                                          } else if (extension == 'txt') {
612
-
613
-                                              $.ajax({
614
-                                                  url: pickUrl + '/' + userid,
615
-                                                  type: "POST",
616
-                                                  data: {pickedfilename: faxfilename},
617
-                                                  success: function(getpickedfile) {
618
-                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
-                                                      $("#faxdocpreview").empty();
620
-                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
621
-                                                  },
622
-                                                  error: function() {
623
-                                                      alert('Unexpected error !');
624
-                                                  }
625
-                                              });
626
-
627
-                                          } else if (extension == 'html') {
628
-
629
-                                              $.ajax({
630
-                                                  url: pickUrl + '/' + userid,
631
-                                                  type: "POST",
632
-                                                  data: {pickedfilename: faxfilename},
633
-                                                  success: function(getpickedfile) {
634
-                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
635
-                                                      $("#faxdocpreview").empty();
636
-                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
637
-                                                  },
638
-                                                  error: function() {
639
-                                                      alert('Unexpected error !');
640
-                                                  }
641
-                                              });
642
-
643
-                                          } else if (extension == 'jpg') {
644
-
645
-                                              $.ajax({
646
-                                                  url: pickUrl + '/' + userid,
647
-                                                  type: "POST",
648
-                                                  data: {pickedfilename: faxfilename},
649
-                                                  success: function(getpickedfile) {
650
-                                                      $("#faxdocpreview").empty();
651
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
652
-                                                      readjpg[faxfilename] = getpickedfile;
653
-                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
654
-                                                  },
655
-                                                  error: function() {
656
-                                                      alert('Unexpected error !');
657
-                                                  }
658
-                                              });
659
-
660
-                                          } else if (extension == 'png') {
661
-
662
-                                              $.ajax({
663
-                                                  url: pickUrl + '/' + userid,
664
-                                                  type: "POST",
665
-                                                  data: {pickedfilename: faxfilename},
666
-                                                  success: function(getpickedfile) {
667
-                                                      $("#faxdocpreview").empty();
668
-                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
669
-                                                      readpng[faxfilename] = getpickedfile;
670
-                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
671
-                                                  },
672
-                                                  error: function() {
673
-                                                      alert('Unexpected error !');
674
-                                                  }
675
-                                              });
676
-
677
-                                          } else if (extension == 'odt') {
678
-                                              $("#faxdocpreview").empty();
679
-                                              function odfInit() {
680
-                                                  var odfelement = document.getElementById("faxdocpreview");
681
-                                                  odfcanvas = new odf.OdfCanvas(odfelement);
682
-                                                  odfcanvas.load(flUrl);
683
-                                               }
684
-                                               window.setTimeout(odfInit, 0);
685
-
686
-                                          } else if (extension == 'tif' || extension == 'tiff') {
687
-                                               var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
688
-                                               var xhr = new XMLHttpRequest();
689
-                                               xhr.responseType = 'arraybuffer';
690
-                                               xhr.open('GET', tiffile);
691
-                                               xhr.onload = function (event) {
692
-                                                   var tiff = new Tiff({buffer: xhr.response});
693
-                                                   var tifcanvas = tiff.toCanvas();
694
-                                                   $("#faxdocpreview").empty();
695
-                                                   $("#faxdocpreview").append(tifcanvas);
696
-                                               };
697
-                                               xhr.send();
698
-                                          }
699
-
700
-                                          $("#faxdocpreview").show();
701
-
702
-                                          $('#pf_choose_msg').hide();
703
-                                          $('#faxdocpreview').removeClass('icon-loading');
704
-                                          $("#faxfoldersview").hide();
705
-
706
-                                          },
707
-
708
-                                          error: function(data){
709
-                                             alert('Error!');
710
-                                          }
711
-
712
-                                       });
713
-
714
-                                    } else {
715
-                                        alert("Error ! You can't fax more than 20 files in one fax call !");
716
-                                        $('#pf_choose_msg').hide();
717
-                                        $('#faxdocpreview').removeClass('icon-loading');
718
-                                      }
719
-                                 } else {
720
-                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
721
-                                      $('#pf_choose_msg').hide();
722
-                                      $('#faxdocpreview').removeClass('icon-loading');
723
-                                   }
724
-
725
-                              } else {
726
-                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
727
-                                   $('#pf_choose_msg').hide();
728
-                                   $('#faxdocpreview').removeClass('icon-loading');
729
-                                }
730
-
731
-                        }
732
-                );
733
-  });
734
-
735
-
736
-  // Submit the fax
737
-  $("#submitfax").on("click", function(event){
738
-
739
-     var selectedcid = $('#currentfaxnmbrs :selected').text();
740
-
741
-     var toNumberinit = $('#faxto').val();
742
-     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
743
-     var toNumber = toNumbersec.split(",");
744
-
745
-     for(var v = 0; v < toNumber.length; v++) {
746
-         toNumber[v] = "+" + toNumber[v];
747
-     }
748
-
749
-     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
750
-     $('#faxdocpreview').addClass('icon-loading');
751
-
752
-     var userid = "<?php p($userId); ?>";
753
-     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
754
-
755
-     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
756
-
757
-         if (uploadedtofax.length != 0) {
758
-
759
-           if (toNumberwc != '') {
760
-
761
-             $.ajax({
762
-                url: baseUrl + '/' + userid,
763
-                type: "POST",
764
-                data: {uploadedtofax: uploadedtofax,
765
-                       selectedcid: selectedcid,
766
-                       toNumber: toNumber
767
-                      },
768
-                success: function(phaxioresult) {
769
-
770
-                   if (phaxioresult.success == true) {
771
-                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
772
-                   } else {
773
-                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
774
-                   }
775
-
776
-                   $("div:visible[id*='indfilediv']").hide();
777
-                   $("div:visible[id*='indflpicked']").hide();
778
-                   $('[class*="indupfldl"]').hide();
779
-                   $('[class*="indpckfldl"]').hide();
780
-
781
-                   $('#faxdocpreview').hide();
782
-
783
-                   $('#filestotsize').hide();
784
-                   $('#submitfax').attr("disabled", true);
785
-                   $("#receivedfaxdir").attr("disabled", true);
786
-                   $("#sentfaxdir").attr("disabled", true);
787
-                   $("#receivedfaileddir").attr("disabled", true);
788
-                   $("#sentfaileddir").attr("disabled", true);
789
-
790
-                   location.reload(true);
791
-
792
-                },
793
-
794
-                error: function(phaxioresult) {
795
-
796
-                   alert('Error ! Please check your settings !');
797
-
798
-                   $("div:visible[id*='indfilediv']").hide();
799
-                   $("div:visible[id*='indflpicked']").hide();
800
-                   $('[class*="indupfldl"]').hide();
801
-                   $('[class*="indpckfldl"]').hide();
802
-
803
-                   $('#pf_submit_msg').hide();
804
-                   $('#filestotsize').hide();
805
-                   $('#faxdocpreview').hide();
806
-                   $('#submitfax').attr("disabled", true);
807
-
808
-
809
-                   $("#receivedfaxdir").attr("disabled", true);
810
-                   $("#sentfaxdir").attr("disabled", true);
811
-                   $("#receivedfaileddir").attr("disabled", true);
812
-                   $("#sentfaileddir").attr("disabled", true);
813
-
814
-                          location.reload(true);
815
-                }
816
-             });
817
-           } else { 
818
-              $('#pf_submit_msg').hide();
819
-              $('#faxdocpreview').removeClass('icon-loading');
820
-              alert("Please enter the fax number of the recipient !");
821
-             }  
822
-         } else {
823
-              $('#pf_submit_msg').hide();
824
-              $('#faxdocpreview').removeClass('icon-loading');
825
-              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
826
-           }
827
-  });
828
-
829
-  $("#receivedfaxdir").on("click", function(event){
830
-     $("#faxdocpreview").hide();
831
-     $("#faxfoldersview").show();
832
-     $("#faxfoldersview").addClass("icon-loading");
833
-     $("#faxfoldersview :last-child").remove();
834
-     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received' width='100%' height='100%' />");
835
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
836
-  });
837
-
838
-  $("#sentfaxdir").on("click", function(event){
839
-     $("#faxdocpreview").hide();
840
-     $("#faxfoldersview").show();
841
-     $("#faxfoldersview").addClass("icon-loading");
842
-     $("#faxfoldersview :last-child").remove();
843
-     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent' width='100%' height='100%' />");
844
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
845
-  });
846
-
847
-  $("#receivedfaileddir").on("click", function(event){
848
-     $("#faxdocpreview").hide();
849
-     $("#faxfoldersview").show();
850
-     $("#faxfoldersview").addClass("icon-loading");
851
-     $("#faxfoldersview :last-child").remove();
852
-     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received_failed' width='100%' height='100%' />");
853
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
854
-  });
855
-
856
-  $("#sentfaileddir").on("click", function(event){
857
-     $("#faxdocpreview").hide();
858
-     $("#faxfoldersview").show();
859
-     $("#faxfoldersview").addClass("icon-loading");
860
-     $("#faxfoldersview :last-child").remove();
861
-     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent_failed' width='100%' height='100%' />");
862
-     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
863
-  });
864
-
865
-  $(".indivflpckd").click(function(event){
866
-     $("#faxfoldersview").hide();
867
-  });
868
-
869
-  $(".indivflcls").on("click", function(event){
870
-     $("#faxfoldersview").hide();
871
-  });
872
-
873
-});
Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:31:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,873 @@
1
+/**
2
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
3
+ *
4
+ * @author Double Bastion LLC
5
+ *
6
+ * @license GNU AGPL version 3 or any later version
7
+ *
8
+ * This program is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
+ * License as published by the Free Software Foundation; either
11
+ * version 3 of the License, or any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public
19
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+$(document).ready(function() {
24
+
25
+  var userid = "<?php p($userId); ?>";
26
+  var readtxtfile = [];
27
+  var readhtmlfile = [];
28
+  var readjpg = [];
29
+  var readpng = [];
30
+
31
+  // Check the available balance
32
+  $("#checkbalance").on("click", function(event) {
33
+
34
+     $('#checkbalance').addClass('icon-loading');
35
+
36
+     var getbalanceUrl = OC.generateUrl("/apps/pax_fax/user/getbalance");
37
+
38
+     $.ajax({
39
+          url: getbalanceUrl + '/' + userid,
40
+          type: "POST",
41
+          data: {userid: userid},
42
+          cache: false,
43
+          processData: false,
44
+          contentType: false,
45
+          success: function(phaxiobalance) {
46
+                 var balanceindlrs = phaxiobalance / 100;
47
+                 var balanceproc = "$ " + balanceindlrs.toFixed(2);
48
+                 $('#currentbalance').text(balanceproc);
49
+
50
+                 $('#checkbalance').removeClass('icon-loading');
51
+          }
52
+     });
53
+  });
54
+
55
+  // Select the Caller ID
56
+  $("#selectcalleridbttn").on("click", function(event) {
57
+
58
+     $('#selectcalleridbttn').addClass('icon-loading');
59
+
60
+     var getfaxnumbersUrl = OC.generateUrl("/apps/pax_fax/user/getfaxnumbers");
61
+     var selectednmbr = null;
62
+
63
+     $.ajax({
64
+          url: getfaxnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: {userid: userid},
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(phaxionmbrs) {
71
+
72
+                    $('#currentfaxnmbrs').empty();
73
+                    $('#currentfaxnmbrs').append("<option value='' selected='selected' disabled class='optselectfxnb'>Choose an ID</option>");
74
+                    $('#currentfaxnmbrs').append("<option value='' class='optselectfxnb'></option>");
75
+
76
+                    $.each(phaxionmbrs, function(key, indfxnmb) {
77
+                           $('#currentfaxnmbrs').append("<option value='"+indfxnmb+"' class='optselectfxnb'>"+indfxnmb+"</option>");
78
+                    });
79
+
80
+                    $('#selectcalleridbttn').removeClass('icon-loading');
81
+
82
+          }
83
+     });
84
+  });
85
+
86
+  // Clean the Pax_Fax/temp_files directory
87
+  var cleanflUrl = OC.generateUrl("/apps/pax_fax/user/cleantempdir");
88
+
89
+  $.ajax({
90
+          url: cleanflUrl + '/' + userid,
91
+          type: "POST",
92
+          data: {userid: userid},
93
+          cache: false,
94
+          processData: false,
95
+          contentType: false
96
+  });
97
+
98
+  var n = 1;
99
+  var uploadedtofax = [];
100
+  var ordernmbrs = [];
101
+
102
+  // Upload files to be faxed
103
+  $("#uploadfileforfax").change(function(e){
104
+
105
+     OC.msg.startAction("#pf_upload_msg", t("pax_fax", "Uploading ..."));
106
+     $('#faxdocpreview').addClass('icon-loading');
107
+     $('#filestotsize').show();
108
+
109
+     var userid = "<?php p($userId); ?>";
110
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/uploadfile");
111
+
112
+     var formData = new FormData();
113
+     formData.append('uploadfileforfax', $('#uploadfileforfax')[0].files[0]);
114
+
115
+     var currentflsize = $('#uploadfileforfax')[0].files[0].size;
116
+
117
+     var fileup = $('#uploadfileforfax').val();
118
+     var fileuptrim = fileup.split('\\').pop();
119
+
120
+     if ($.inArray(fileuptrim, uploadedtofax) != -1) {
121
+         var duplicatescheck = 1;
122
+     } else var duplicatescheck = 0;
123
+
124
+     var extension = fileup.replace(/^.*\./, '');
125
+
126
+     if (extension == fileup) {
127
+         extension = "";
128
+     } else {
129
+         extension = extension.toLowerCase();
130
+     }
131
+
132
+     var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
133
+
134
+     if ($.inArray(extension, validExtensions) != -1) {
135
+
136
+       if (duplicatescheck == 0) {
137
+
138
+         if (currentflsize < 20971520) {
139
+
140
+            if (n < 21) {
141
+
142
+               uploadedtofax.push(fileuptrim);
143
+
144
+               $.ajax({
145
+                 url: baseUrl + '/' + userid,
146
+                 type: "POST",
147
+                 data: formData,
148
+                 cache: false,
149
+                 processData: false,
150
+                 contentType: false,
151
+                 success: function(totalflsize) {
152
+
153
+                   $('#filessizetext').text(totalflsize);
154
+
155
+                   // Check if the total file size is over 20 MB
156
+                   var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
157
+
158
+                   if (rectotfilesz > 20.00) {
159
+                       $('#filestotsize').css('color', '#ba3555');
160
+                       alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
161
+                       $('#submitfax').attr("disabled", true);
162
+                   } else {
163
+                       $('#submitfax').attr("disabled", false);
164
+                       $('#filestotsize').css('color', '#18bf6e');
165
+                     }
166
+
167
+
168
+                   $('#fileuploadednm').append("<div class='indgenflcls'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div><br>");
169
+                   n++;
170
+
171
+                   // Preview the file
172
+                   $("div:visible[id*='indfilediv']").each(function() {
173
+                        $(this).on("click", function(eventclck) {
174
+                           var faxfilenameinit = $(this).text();
175
+                           var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
176
+                           var faxfilename = faxfilenamesec.replace("X","");
177
+                           var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
178
+
179
+                           var extenlst = faxfilename.replace(/^.*\./, '');
180
+
181
+                           if (extenlst == faxfilename) {
182
+                               extenlst = "";
183
+                           } else {
184
+                               extenlst = extenlst.toLowerCase();
185
+                           }
186
+
187
+                           if (extenlst == 'pdf') {
188
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
189
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
190
+                                  $("#faxdocpreview").empty();
191
+                                  $("#faxdocpreview").append($iframe);
192
+                           } else if (extenlst == 'txt') {
193
+                                  $("#faxdocpreview").empty();
194
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
195
+                           } else if (extenlst == 'html') {
196
+                                  $("#faxdocpreview").empty();
197
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
198
+                           } else if (extenlst == 'jpg') {
199
+                                  $("#faxdocpreview").empty();
200
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
201
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
202
+                           } else if (extenlst == 'png') {
203
+                                  $("#faxdocpreview").empty();
204
+                                  $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
205
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
206
+                           } else if (extenlst == 'odt') {
207
+                                  $("#faxdocpreview").empty();
208
+                                  function odfInit() {
209
+                                     var odfelement = document.getElementById("faxdocpreview");
210
+                                     odfcanvas = new odf.OdfCanvas(odfelement);
211
+                                     odfcanvas.load(baseUrl);
212
+                                  }
213
+                                  window.setTimeout(odfInit, 0);
214
+                           } else if (extenlst == 'docx') {
215
+                                  $("#faxdocpreview").empty();
216
+                                  var viewerclick = OC.generateUrl("/apps/files?dir=/Pax_Fax/temp_files&openfile="+fileid);
217
+                                  var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
218
+                                  $("#faxdocpreview").append($iframe);
219
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
220
+                                  var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
221
+                                  var xhr = new XMLHttpRequest();
222
+                                  xhr.responseType = 'arraybuffer';
223
+                                  xhr.open('GET', tiffile);
224
+                                  xhr.onload = function (evnt) {
225
+                                      var tiff = new Tiff({buffer: xhr.response});
226
+                                      var tifcanvas = tiff.toCanvas();
227
+                                      $("#faxdocpreview").empty();
228
+                                      $("#faxdocpreview").append(tifcanvas);
229
+                                  };
230
+                                  xhr.send();
231
+                           }
232
+
233
+                           $("#faxdocpreview").show();
234
+                           $("#faxfoldersview").hide();
235
+                        });
236
+                   });
237
+
238
+                   // Remove uploaded files
239
+                   $('[class*="indupfldl"]').last().click(function() {
240
+
241
+                           var userid = "<?php p($userId); ?>";
242
+                           var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
243
+
244
+                           var removedfilenameinit = $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').text();
245
+
246
+                           var removedfilesplit = removedfilenameinit.split(") ");
247
+                           var removedflnb = parseInt(removedfilesplit[0]);
248
+
249
+                           $(this).closest('[class*="indgenflcls"]').find('[class*="indivflcls"]').hide();
250
+                           $(this).hide();
251
+
252
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
253
+
254
+                           uploadedtofax = $.grep(uploadedtofax, function(value) {
255
+                                           return value != removedfilename;
256
+                           });
257
+
258
+                           $.ajax({
259
+                                   url: baseUrl + '/' + userid,
260
+                                   type: "POST",
261
+                                   data: {removedfilename: removedfilename},
262
+                                   success: function(totalflsize) {
263
+
264
+                                      $('#filessizetext').text(totalflsize);
265
+
266
+                                      // Check file size
267
+                                      var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
268
+
269
+                                      if (rectotfilesz > 20.00) {
270
+                                          $('#filestotsize').css('color', '#ba3555');
271
+                                             alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
272
+                                          $('#submitfax').attr("disabled", true);
273
+                                      } else {
274
+                                          $('#submitfax').attr("disabled", false);
275
+                                          $('#filestotsize').css('color', '#18bf6e');
276
+                                        }
277
+
278
+                                      // Rewrite order numbers for files that follow
279
+                                      --n;
280
+                                      $("div:visible[id*='indfilediv']").each(function() {
281
+
282
+                                          var getdivtext =  $(this).text();
283
+                                          var splitdivtext = getdivtext.split(") ");
284
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
285
+                                          var newnbvalue = currentnbvalue - 1;
286
+
287
+                                          if (currentnbvalue > removedflnb) {
288
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
289
+                                              $(this).text(replacedstr);
290
+                                          }
291
+                                      });
292
+
293
+                                      $("div:visible[id*='indflpicked']").each(function() {
294
+
295
+                                          var getdivtext =  $(this).text();
296
+                                          var splitdivtext = getdivtext.split(") ");
297
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
298
+                                          var newnbvalue = currentnbvalue - 1;
299
+
300
+                                          if (currentnbvalue > removedflnb) {
301
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
302
+                                              $(this).text(replacedstr);
303
+                                          }
304
+                                      });
305
+
306
+                                   },
307
+                                   error: function() {
308
+                                          alert('Error !');
309
+                                   }
310
+                           });
311
+
312
+                           $('#faxdocpreview').removeClass('icon-loading');
313
+                           $("#faxdocpreview").empty();
314
+                   });
315
+
316
+                   // Preview the uploaded file
317
+                   var faxfilename = e.target.files[0].name;
318
+                   var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
319
+
320
+                   if (extension == 'pdf') {
321
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
322
+                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
323
+                              $("#faxdocpreview").empty();
324
+                              $("#faxdocpreview").append($iframe);
325
+                   } else if (extension == 'txt') {
326
+                              var reader = new FileReader();
327
+                              reader.readAsText(e.target.files[0]);
328
+                              reader.onload = function(e) {
329
+                                  readtxtfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
330
+                                  $("#faxdocpreview").empty();
331
+                                  $("#faxdocpreview").append(readtxtfile[faxfilename]);
332
+                              };
333
+                   } else if (extension == 'html') {
334
+                              var reader = new FileReader();
335
+                              reader.readAsText(e.target.files[0]);
336
+                              reader.onload = function(e) {
337
+                                  readhtmlfile[faxfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
338
+                                  $("#faxdocpreview").empty();
339
+                                  $("#faxdocpreview").append(readhtmlfile[faxfilename]);
340
+                              };
341
+                   } else if (extension == 'jpg') {
342
+                              $("#faxdocpreview").empty();
343
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
344
+
345
+                              var reader = new FileReader();
346
+                              reader.onload = function (e) {
347
+                                  readjpg[faxfilename] = e.target.result;
348
+                                  $("#uploadedjpg").attr('src', readjpg[faxfilename]);
349
+                              }
350
+                              reader.readAsDataURL(e.target.files[0]);
351
+                   } else if (extension == 'png') {
352
+                              $("#faxdocpreview").empty();
353
+                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
354
+
355
+                              var reader = new FileReader();
356
+                              reader.onload = function (e) {
357
+                                  readpng[faxfilename] = e.target.result;
358
+                                  $("#uploadedpng").attr('src', readpng[faxfilename]);
359
+                              }
360
+                              reader.readAsDataURL(e.target.files[0]);
361
+                   } else if (extension == 'odt') {
362
+                              $("#faxdocpreview").empty();
363
+                              function odfInit() {
364
+                                 var odfelement = document.getElementById("faxdocpreview");
365
+                                 odfcanvas = new odf.OdfCanvas(odfelement);
366
+                                 odfcanvas.load(baseUrl);
367
+                              }
368
+                              window.setTimeout(odfInit, 0);
369
+                   } else if (extension == 'tif' || extension == 'tiff') {
370
+                              var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
371
+                              var xhr = new XMLHttpRequest();
372
+                              xhr.responseType = 'arraybuffer';
373
+                              xhr.open('GET', tiffile);
374
+                              xhr.onload = function (e) {
375
+                                  var tiff = new Tiff({buffer: xhr.response});
376
+                                  var tifcanvas = tiff.toCanvas();
377
+                                  $("#faxdocpreview").empty();
378
+                                  $("#faxdocpreview").append(tifcanvas);
379
+                              };
380
+                              xhr.send();
381
+                   }
382
+
383
+                   $("#faxdocpreview").show();
384
+                   $('#pf_upload_msg').hide();
385
+                   $('#faxdocpreview').removeClass('icon-loading');
386
+                   $("#faxfoldersview").hide();
387
+                 },
388
+                 error: function(data){
389
+                     alert('Error!');
390
+                 }
391
+               });
392
+
393
+            } else {
394
+                  alert("Error ! You can't send as fax more than 20 files in one fax call !");
395
+                  $('#pf_upload_msg').hide();
396
+                  $('#faxdocpreview').removeClass('icon-loading');
397
+              }
398
+         } else {
399
+              alert("Error ! You can't send files having a total size of more than 20 MB in one fax call !");
400
+              $('#pf_upload_msg').hide();
401
+              $('#faxdocpreview').removeClass('icon-loading');
402
+           }
403
+       } else {
404
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'Pax_Fax/temp_files' folder !");
405
+            $('#pf_upload_msg').hide();
406
+            $('#faxdocpreview').removeClass('icon-loading');
407
+         }
408
+
409
+     } else {
410
+          alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
411
+          $('#pf_upload_msg').hide();
412
+          $('#faxdocpreview').removeClass('icon-loading');
413
+       }
414
+  });
415
+
416
+
417
+  // Pick file to fax, from Nextcloud
418
+  var faxfilename = null;
419
+
420
+  $("#choosefilen").on("click", function(evn) {
421
+
422
+                OC.dialogs.filepicker(
423
+                        t('settings', "Select a file to send as fax."),
424
+                        function (path) {
425
+
426
+                              OC.msg.startAction("#pf_choose_msg", t("pax_fax", "Please wait ..."));
427
+                              $('#faxdocpreview').addClass('icon-loading');
428
+                              $('#filestotsize').show();
429
+
430
+                              var userid = "<?php p($userId); ?>";
431
+                              var baseUrl = OC.generateUrl("/apps/pax_fax/user/pickfile");
432
+
433
+                              faxfilename = path.split('/').pop();
434
+
435
+                              if ($.inArray(faxfilename, uploadedtofax) != -1) {
436
+                                  var duplicatescheck = 1;
437
+                              } else var duplicatescheck = 0;
438
+
439
+                              var extension = faxfilename.replace(/^.*\./, '');
440
+
441
+                              if (extension == faxfilename) {
442
+                                  extension = "";
443
+                              } else {
444
+                                  extension = extension.toLowerCase();
445
+                              }
446
+
447
+                              var validExtensions = ["pdf", "doc", "docx", "tif", "tiff", "jpg", "odt", "txt", "html", "png"];
448
+
449
+                              if ($.inArray(extension, validExtensions) != -1) {
450
+
451
+                                 if (duplicatescheck == 0) {
452
+
453
+                                    if (n < 21) {
454
+
455
+                                       uploadedtofax.push(faxfilename);
456
+
457
+                                       $.ajax({
458
+                                          url: baseUrl + '/' + userid,
459
+                                          type: "POST",
460
+                                          data: {path: path},
461
+                                          success: function(totalflsize) {
462
+
463
+                                                $('#filessizetext').text(totalflsize);
464
+
465
+                                                // Check if the total file size is over 20 MB
466
+                                                var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
467
+
468
+                                                if (rectotfilesz > 20.00) {
469
+                                                    $('#filestotsize').css('color', '#ba3555');
470
+                                                    alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop to or below 20 MB");
471
+                                                    $('#submitfax').attr("disabled", true);
472
+                                                } else {
473
+                                                    $('#submitfax').attr("disabled", false);
474
+                                                    $('#filestotsize').css('color', '#18bf6e');
475
+                                                }
476
+
477
+                                                $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + faxfilename + "</div><div class='indpckfldl'>X</div></div><br>");
478
+                                                n++;
479
+
480
+                                                $("div:visible[id*='indflpicked']").each(function() {
481
+                                                   $(this).on("click", function(event) {
482
+                                                      var faxfilenameinit = $(this).text();
483
+                                                      var faxfilenamesec = faxfilenameinit.substring(faxfilenameinit.indexOf(" ") + 1);
484
+                                                      var faxfilenamesp = faxfilenamesec.replace("X","");
485
+                                                      var baseUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilenamesp);
486
+                                                      var extenlst = faxfilenamesp.replace(/^.*\./, '');
487
+
488
+                                                      if (extenlst == faxfilenamesp) {
489
+                                                           extenlst = "";
490
+                                                      } else {
491
+                                                           extenlst = extenlst.toLowerCase();
492
+                                                      }
493
+
494
+                                                      if (extenlst == 'pdf') {
495
+                                                           var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
496
+                                                           var $iframe = $('<iframe id="docclickview" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewerclick + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
497
+                                                           $("#faxdocpreview").empty();
498
+                                                           $("#faxdocpreview").append($iframe);
499
+                                                      } else if (extenlst == 'txt') {
500
+                                                              $("#faxdocpreview").empty();
501
+                                                              $("#faxdocpreview").append(readtxtfile[faxfilenamesp]);
502
+                                                      } else if (extenlst == 'html') {
503
+                                                              $("#faxdocpreview").empty();
504
+                                                              $("#faxdocpreview").append(readhtmlfile[faxfilenamesp]);
505
+                                                      } else if (extenlst == 'jpg') {
506
+                                                              $("#faxdocpreview").empty();
507
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
508
+                                                              $("#uploadedjpg").attr('src', readjpg[faxfilenamesp]);
509
+                                                      } else if (extenlst == 'png') {
510
+                                                              $("#faxdocpreview").empty();
511
+                                                              $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
512
+                                                              $("#uploadedpng").attr('src', readpng[faxfilenamesp]);
513
+                                                      } else if (extenlst == 'odt') {
514
+                                                              $("#faxdocpreview").empty();
515
+                                                              function odfInit() {
516
+                                                                 var odfelement = document.getElementById("faxdocpreview");
517
+                                                                 odfcanvas = new odf.OdfCanvas(odfelement);
518
+                                                                 odfcanvas.load(baseUrl);
519
+                                                              }
520
+                                                              window.setTimeout(odfInit, 0);
521
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
522
+                                                              var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilenamesp);
523
+                                                              var xhr = new XMLHttpRequest();
524
+                                                              xhr.responseType = 'arraybuffer';
525
+                                                              xhr.open('GET', tiffile);
526
+                                                              xhr.onload = function (evnt) {
527
+                                                                  var tiff = new Tiff({buffer: xhr.response});
528
+                                                                  var tifcanvas = tiff.toCanvas();
529
+                                                                  $("#faxdocpreview").empty();
530
+                                                                  $("#faxdocpreview").append(tifcanvas);
531
+                                                              };
532
+                                                              xhr.send();
533
+                                                      }
534
+
535
+                                                      $("#faxdocpreview").show();
536
+                                                      $("#faxfoldersview").hide();
537
+                                                   });
538
+                                                });
539
+
540
+                                                // Remove picked files
541
+                                                $('[class*="indpckfldl"]').last().click(function() {
542
+                                                    var userid = "<?php p($userId); ?>";
543
+                                                    var baseUrl = OC.generateUrl("/apps/pax_fax/user/removeupfile");
544
+
545
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
546
+
547
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
548
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
549
+
550
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
551
+                                                    $(this).hide();
552
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
553
+
554
+                                                    uploadedtofax = $.grep(uploadedtofax, function(value) {
555
+                                                             return value != removedfilename;
556
+                                                    });
557
+
558
+                                                    $.ajax({
559
+                                                        url: baseUrl + '/' + userid,
560
+                                                        type: "POST",
561
+                                                        data: {removedfilename: removedfilename},
562
+                                                        success: function(totalflsize) {
563
+
564
+                                                             $('#filessizetext').text(totalflsize);
565
+
566
+                                                             // Check file size
567
+                                                             var rectotfilesz = parseFloat(totalflsize.replace(" MB", ""));
568
+
569
+                                                             if (rectotfilesz > 20.00) {
570
+                                                                 $('#filestotsize').css('color', '#ba3555');
571
+                                                                 alert("Error ! You can't send files having a total size of more than 20 MB in one fax call ! Please consider removing files so that the total files size would drop at or below 20 MB");
572
+                                                                 $('#submitfax').attr("disabled", true);
573
+                                                             } else {
574
+                                                                 $('#submitfax').attr("disabled", false);
575
+                                                                 $('#filestotsize').css('color', '#18bf6e');
576
+                                                               }
577
+
578
+                                                             // Rewrite order numbers for files that follow
579
+                                                             --n;
580
+                                                             $("div:visible[id*='indflpicked']").each(function() {
581
+
582
+                                                                  var getdivtext =  $(this).text();
583
+                                                                  var splitdivtext = getdivtext.split(") ");
584
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
585
+                                                                  var newnbvalue = currentnbvalue - 1;
586
+
587
+                                                                  if (currentnbvalue > removedflnb) {
588
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
589
+                                                                      $(this).text(replacedstr);
590
+                                                                  }
591
+                                                             });
592
+                                                        },
593
+                                                        error: function() {
594
+                                                             alert('Error !');
595
+                                                        }
596
+                                                    });
597
+
598
+                                                    $('#faxdocpreview').removeClass('icon-loading');
599
+                                                    $("#faxdocpreview").empty();
600
+                                                });
601
+
602
+                                          // Preview the picked file
603
+                                          var flUrl = OC.generateUrl("/remote.php/webdav/Pax_Fax/temp_files/"+faxfilename);
604
+                                          var pickUrl = OC.generateUrl("/apps/pax_fax/user/getpickedfile");
605
+
606
+                                          if (extension == 'pdf') {
607
+                                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
608
+                                              var $iframe = $('<iframe id="docviewer" style="width:100%;height:100%;display:block;position:absolute;top:0;left:0;z-index:1041;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals" />');
609
+                                              $("#faxdocpreview").empty();
610
+                                              $("#faxdocpreview").append($iframe);
611
+                                          } else if (extension == 'txt') {
612
+
613
+                                              $.ajax({
614
+                                                  url: pickUrl + '/' + userid,
615
+                                                  type: "POST",
616
+                                                  data: {pickedfilename: faxfilename},
617
+                                                  success: function(getpickedfile) {
618
+                                                      readtxtfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
619
+                                                      $("#faxdocpreview").empty();
620
+                                                      $("#faxdocpreview").append(readtxtfile[faxfilename]);
621
+                                                  },
622
+                                                  error: function() {
623
+                                                      alert('Unexpected error !');
624
+                                                  }
625
+                                              });
626
+
627
+                                          } else if (extension == 'html') {
628
+
629
+                                              $.ajax({
630
+                                                  url: pickUrl + '/' + userid,
631
+                                                  type: "POST",
632
+                                                  data: {pickedfilename: faxfilename},
633
+                                                  success: function(getpickedfile) {
634
+                                                      readhtmlfile[faxfilename] = getpickedfile.replace(/(?:\r\n|\r|\n)/g, '<br>');
635
+                                                      $("#faxdocpreview").empty();
636
+                                                      $("#faxdocpreview").append(readhtmlfile[faxfilename]);
637
+                                                  },
638
+                                                  error: function() {
639
+                                                      alert('Unexpected error !');
640
+                                                  }
641
+                                              });
642
+
643
+                                          } else if (extension == 'jpg') {
644
+
645
+                                              $.ajax({
646
+                                                  url: pickUrl + '/' + userid,
647
+                                                  type: "POST",
648
+                                                  data: {pickedfilename: faxfilename},
649
+                                                  success: function(getpickedfile) {
650
+                                                      $("#faxdocpreview").empty();
651
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedjpg" src="#" />');
652
+                                                      readjpg[faxfilename] = getpickedfile;
653
+                                                      $("#uploadedjpg").attr('src', readjpg[faxfilename]);
654
+                                                  },
655
+                                                  error: function() {
656
+                                                      alert('Unexpected error !');
657
+                                                  }
658
+                                              });
659
+
660
+                                          } else if (extension == 'png') {
661
+
662
+                                              $.ajax({
663
+                                                  url: pickUrl + '/' + userid,
664
+                                                  type: "POST",
665
+                                                  data: {pickedfilename: faxfilename},
666
+                                                  success: function(getpickedfile) {
667
+                                                      $("#faxdocpreview").empty();
668
+                                                      $("#faxdocpreview").append('<img style="width:100%;height:100%" id="uploadedpng" src="#" />');
669
+                                                      readpng[faxfilename] = getpickedfile;
670
+                                                      $("#uploadedpng").attr('src', readpng[faxfilename]);
671
+                                                  },
672
+                                                  error: function() {
673
+                                                      alert('Unexpected error !');
674
+                                                  }
675
+                                              });
676
+
677
+                                          } else if (extension == 'odt') {
678
+                                              $("#faxdocpreview").empty();
679
+                                              function odfInit() {
680
+                                                  var odfelement = document.getElementById("faxdocpreview");
681
+                                                  odfcanvas = new odf.OdfCanvas(odfelement);
682
+                                                  odfcanvas.load(flUrl);
683
+                                               }
684
+                                               window.setTimeout(odfInit, 0);
685
+
686
+                                          } else if (extension == 'tif' || extension == 'tiff') {
687
+                                               var tiffile = OC.generateUrl('/remote.php/webdav/Pax_Fax/temp_files/'+faxfilename);
688
+                                               var xhr = new XMLHttpRequest();
689
+                                               xhr.responseType = 'arraybuffer';
690
+                                               xhr.open('GET', tiffile);
691
+                                               xhr.onload = function (event) {
692
+                                                   var tiff = new Tiff({buffer: xhr.response});
693
+                                                   var tifcanvas = tiff.toCanvas();
694
+                                                   $("#faxdocpreview").empty();
695
+                                                   $("#faxdocpreview").append(tifcanvas);
696
+                                               };
697
+                                               xhr.send();
698
+                                          }
699
+
700
+                                          $("#faxdocpreview").show();
701
+
702
+                                          $('#pf_choose_msg').hide();
703
+                                          $('#faxdocpreview').removeClass('icon-loading');
704
+                                          $("#faxfoldersview").hide();
705
+
706
+                                          },
707
+
708
+                                          error: function(data){
709
+                                             alert('Error!');
710
+                                          }
711
+
712
+                                       });
713
+
714
+                                    } else {
715
+                                        alert("Error ! You can't fax more than 20 files in one fax call !");
716
+                                        $('#pf_choose_msg').hide();
717
+                                        $('#faxdocpreview').removeClass('icon-loading');
718
+                                      }
719
+                                 } else {
720
+                                      alert("Error ! There is already a file named '"+faxfilename+"' in the 'Pax_Fax/temp_files' folder !");
721
+                                      $('#pf_choose_msg').hide();
722
+                                      $('#faxdocpreview').removeClass('icon-loading');
723
+                                   }
724
+
725
+                              } else {
726
+                                   alert('The file type is not supported ! Supported formats are: pdf, doc, docx, tif, tiff, jpg, odt, txt, html, png.');
727
+                                   $('#pf_choose_msg').hide();
728
+                                   $('#faxdocpreview').removeClass('icon-loading');
729
+                                }
730
+
731
+                        }
732
+                );
733
+  });
734
+
735
+
736
+  // Submit the fax
737
+  $("#submitfax").on("click", function(event){
738
+
739
+     var selectedcid = $('#currentfaxnmbrs :selected').text();
740
+
741
+     var toNumberinit = $('#faxto').val();
742
+     var toNumbersec = toNumberinit.replace(/[^0-9,]/g, "");
743
+     var toNumber = toNumbersec.split(",");
744
+
745
+     for(var v = 0; v < toNumber.length; v++) {
746
+         toNumber[v] = "+" + toNumber[v];
747
+     }
748
+
749
+     OC.msg.startAction("#pf_submit_msg", t("pax_fax", "Sending fax ... Please wait !"));
750
+     $('#faxdocpreview').addClass('icon-loading');
751
+
752
+     var userid = "<?php p($userId); ?>";
753
+     var baseUrl = OC.generateUrl("/apps/pax_fax/user/sendfax");
754
+
755
+     var toNumberwc = toNumberinit.replace(/[^0-9]/g, "");
756
+
757
+         if (uploadedtofax.length != 0) {
758
+
759
+           if (toNumberwc != '') {
760
+
761
+             $.ajax({
762
+                url: baseUrl + '/' + userid,
763
+                type: "POST",
764
+                data: {uploadedtofax: uploadedtofax,
765
+                       selectedcid: selectedcid,
766
+                       toNumber: toNumber
767
+                      },
768
+                success: function(phaxioresult) {
769
+
770
+                   if (phaxioresult.success == true) {
771
+                       alert("The fax has been sent successfully ! You can see the sent fax by clicking on the 'Sent Faxes' button.");
772
+                   } else {
773
+                       alert("Error ! The fax couldn't be sent because of the following error: "+phaxioresult.errortype+" You can see the failed fax by clicking on the 'Failed Sent Faxes' button.");
774
+                   }
775
+
776
+                   $("div:visible[id*='indfilediv']").hide();
777
+                   $("div:visible[id*='indflpicked']").hide();
778
+                   $('[class*="indupfldl"]').hide();
779
+                   $('[class*="indpckfldl"]').hide();
780
+
781
+                   $('#faxdocpreview').hide();
782
+
783
+                   $('#filestotsize').hide();
784
+                   $('#submitfax').attr("disabled", true);
785
+                   $("#receivedfaxdir").attr("disabled", true);
786
+                   $("#sentfaxdir").attr("disabled", true);
787
+                   $("#receivedfaileddir").attr("disabled", true);
788
+                   $("#sentfaileddir").attr("disabled", true);
789
+
790
+                   location.reload(true);
791
+
792
+                },
793
+
794
+                error: function(phaxioresult) {
795
+
796
+                   alert('Error ! Please check your settings !');
797
+
798
+                   $("div:visible[id*='indfilediv']").hide();
799
+                   $("div:visible[id*='indflpicked']").hide();
800
+                   $('[class*="indupfldl"]').hide();
801
+                   $('[class*="indpckfldl"]').hide();
802
+
803
+                   $('#pf_submit_msg').hide();
804
+                   $('#filestotsize').hide();
805
+                   $('#faxdocpreview').hide();
806
+                   $('#submitfax').attr("disabled", true);
807
+
808
+
809
+                   $("#receivedfaxdir").attr("disabled", true);
810
+                   $("#sentfaxdir").attr("disabled", true);
811
+                   $("#receivedfaileddir").attr("disabled", true);
812
+                   $("#sentfaileddir").attr("disabled", true);
813
+
814
+                          location.reload(true);
815
+                }
816
+             });
817
+           } else { 
818
+              $('#pf_submit_msg').hide();
819
+              $('#faxdocpreview').removeClass('icon-loading');
820
+              alert("Please enter the fax number of the recipient !");
821
+             }  
822
+         } else {
823
+              $('#pf_submit_msg').hide();
824
+              $('#faxdocpreview').removeClass('icon-loading');
825
+              alert("Please upload a file or pick a file from Nextcloud to send as fax !");
826
+           }
827
+  });
828
+
829
+  $("#receivedfaxdir").on("click", function(event){
830
+     $("#faxdocpreview").hide();
831
+     $("#faxfoldersview").show();
832
+     $("#faxfoldersview").addClass("icon-loading");
833
+     $("#faxfoldersview :last-child").remove();
834
+     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received' width='100%' height='100%' />");
835
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
836
+  });
837
+
838
+  $("#sentfaxdir").on("click", function(event){
839
+     $("#faxdocpreview").hide();
840
+     $("#faxfoldersview").show();
841
+     $("#faxfoldersview").addClass("icon-loading");
842
+     $("#faxfoldersview :last-child").remove();
843
+     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent' width='100%' height='100%' />");
844
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
845
+  });
846
+
847
+  $("#receivedfaileddir").on("click", function(event){
848
+     $("#faxdocpreview").hide();
849
+     $("#faxfoldersview").show();
850
+     $("#faxfoldersview").addClass("icon-loading");
851
+     $("#faxfoldersview :last-child").remove();
852
+     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_received_failed' width='100%' height='100%' />");
853
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
854
+  });
855
+
856
+  $("#sentfaileddir").on("click", function(event){
857
+     $("#faxdocpreview").hide();
858
+     $("#faxfoldersview").show();
859
+     $("#faxfoldersview").addClass("icon-loading");
860
+     $("#faxfoldersview :last-child").remove();
861
+     $("#faxfoldersview").append("<embed id='embeddedView' src='/apps/files/?dir=/Pax_Fax/faxes_sent_failed' width='100%' height='100%' />");
862
+     setTimeout(function() { $("#faxfoldersview").removeClass("icon-loading"); }, 1000);
863
+  });
864
+
865
+  $(".indivflpckd").click(function(event){
866
+     $("#faxfoldersview").hide();
867
+  });
868
+
869
+  $(".indivflcls").on("click", function(event){
870
+     $("#faxfoldersview").hide();
871
+  });
872
+
873
+});