Browse code

added Conversations page and improved mobile compatibility

DoubleBastionAdmin authored on 02/04/2024 00:47:37
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1642 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option class='optselectsmsnb' value='' selected='selected' disabled='' hidden=''>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  function cleanTempDirectory() {
235
+
236
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
+
238
+     $.ajax({
239
+          url: cleanflUrl + '/' + userid,
240
+          type: "POST",
241
+          data: { userid: userid },
242
+          cache: false,
243
+          processData: false,
244
+          contentType: false
245
+     });
246
+  }
247
+  cleanTempDirectory();
248
+
249
+  // Clean the SMS_Relentless/multiple_recipients directory
250
+  function cleanMultRecDirectory() {
251
+
252
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
+
254
+     $.ajax({
255
+          url: cleanflUrl + '/' + userid,
256
+          type: "POST",
257
+          data: { userid: userid },
258
+          cache: false,
259
+          processData: false,
260
+          contentType: false
261
+     });
262
+  }
263
+  cleanMultRecDirectory();
264
+
265
+  // Check the available balance
266
+  $("#smsprovider").on("change", function () {
267
+
268
+     var provider = $('#smsprovider :selected').val();
269
+
270
+     if (provider == "Telnyx") {
271
+
272
+        var gettelbalance = function() {
273
+
274
+          $('#currentbalance').addClass('icon-loading');
275
+
276
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
+
278
+          $.ajax({
279
+              url: gettelbalanceUrl + '/' + userid,
280
+              type: "POST",
281
+              data: { userid: userid },
282
+              cache: false,
283
+              processData: false,
284
+              contentType: false,
285
+              success: function(currentbalancetel) {
286
+
287
+                     $('#currentbalance').empty();
288
+                     $('#currentbalance').text(currentbalancetel);
289
+                     $('#currentbalance').removeClass('icon-loading');
290
+              }
291
+          });
292
+        }
293
+
294
+        gettelbalance();
295
+
296
+     } else if (provider == "Plivo") {
297
+
298
+          var getnexbalance = function() {
299
+
300
+            $('#currentbalance').addClass('icon-loading');
301
+
302
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
+
304
+            $.ajax({
305
+                url: getnexbalanceUrl + '/' + userid,
306
+                type: "POST",
307
+                data: { userid: userid },
308
+                cache: false,
309
+                processData: false,
310
+                contentType: false,
311
+                success: function(currentbalancenex) {
312
+
313
+                     $('#currentbalance').empty();
314
+                     $('#currentbalance').text(currentbalancenex);
315
+                     $('#currentbalance').removeClass('icon-loading');
316
+                }
317
+            });
318
+          }
319
+
320
+          getnexbalance();
321
+
322
+     } else if (provider == "Twilio") {
323
+
324
+          var gettwilbalance = function() {
325
+
326
+            $('#currentbalance').addClass('icon-loading');
327
+
328
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
+
330
+            $.ajax({
331
+                url: gettwilbalanceUrl + '/' + userid,
332
+                type: "POST",
333
+                data: { userid: userid },
334
+                cache: false,
335
+                processData: false,
336
+                contentType: false,
337
+                success: function(currentbalancetwil) {
338
+
339
+                     $('#currentbalance').empty();
340
+                     $('#currentbalance').text(currentbalancetwil);
341
+                     $('#currentbalance').removeClass('icon-loading');
342
+                }
343
+            });
344
+          }
345
+
346
+          gettwilbalance();
347
+
348
+     } else if (provider == "Flowroute") {
349
+
350
+          var getflowbalance = function() {
351
+
352
+            $('#currentbalance').addClass('icon-loading');
353
+
354
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
+
356
+            $.ajax({
357
+                url: getflowbalanceUrl + '/' + userid,
358
+                type: "POST",
359
+                data: { userid: userid },
360
+                cache: false,
361
+                processData: false,
362
+                contentType: false,
363
+                success: function(currentbalanceflow) {
364
+
365
+                     $('#currentbalance').empty();
366
+                     $('#currentbalance').text(currentbalanceflow);
367
+                     $('#currentbalance').removeClass('icon-loading');
368
+                }
369
+            });
370
+          }
371
+
372
+          getflowbalance();
373
+
374
+       } else if (provider == "") {
375
+                $('#currentbalance').text("");
376
+                $('#currentbalance').removeClass('icon-loading');
377
+       }
378
+  });
379
+
380
+
381
+  // Refresh the list of Sender IDs
382
+  $("#refreshSenderIDs").on("click", function(event) {
383
+
384
+     $('#refreshSenderIDs').addClass('icon-loading');
385
+
386
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/refreshavailablenumbers");
387
+     var selectednmbr = null;
388
+
389
+     $.ajax({
390
+          url: getsmsnumbersUrl + '/' + userid,
391
+          type: "POST",
392
+          data: { userid: userid },
393
+          cache: false,
394
+          processData: false,
395
+          contentType: false,
396
+          success: function(smsnmbrs) {
397
+
398
+                    $('#currentsmsnmbrs').empty();
399
+                    $('#currentsmsnmbrs').append("<option class='optselectsmsnb' value='' selected='selected' disabled='' hidden=''>Choose an ID</option>");
400
+
401
+                    $.each(smsnmbrs, function(key, indsmsnmb) {
402
+                           $('#currentsmsnmbrs').append("<option value='"+ indsmsnmb +"' class='optselectsmsnb'>"+ indsmsnmb +"</option>");
403
+                    });
404
+
405
+                    $('#refreshSenderIDs').removeClass('icon-loading');
406
+          }
407
+     });
408
+  });
409
+
410
+
411
+  // If a Sender ID is selected
412
+  $("#currentsmsnmbrs").on("change", function () {
413
+
414
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
415
+
416
+              selectedid = $('#currentsmsnmbrs :selected').val();
417
+              var setIdsplit = selectedid.split(":");
418
+	      chosenProvider = setIdsplit[0];
419
+
420
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
421
+	      if (chosenProvider == "Tx") {
422
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
423
+		  // Maximum size of message text + files in KB
424
+		  maximumsize = 1024;
425
+                  maximumsizeinit = 1024;
426
+		  maxsizenonimage = 600;
427
+		  maximumfilenumber = 10;
428
+                  chosenProvFullName = "Telnyx";
429
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
430
+                                     or gif files, the size of all the files plus the size of the text should be \
431
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
432
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
433
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
434
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
435
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
436
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
437
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
438
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
439
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
440
+                  $("#tooltiptextfourth").html(infonotecontent);
441
+	      } else if (chosenProvider == "Pl") {
442
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
443
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
444
+		  // Maximum size of message text + files in KB
445
+		  maximumsize = 5120;
446
+                  maximumsizeinit = 5120;
447
+		  maxsizenonimage = 600;
448
+		  maximumfilenumber = 10;
449
+                  chosenProvFullName = "Plivo";
450
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
451
+                                     or gif files, the size of all the files plus the size of the text should be \
452
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
453
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
454
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
455
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
456
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
457
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
458
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
459
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
460
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
461
+                  $("#tooltiptextfourth").html(infonotecontent);
462
+	      } else if (chosenProvider == "Tw") {
463
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
464
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
465
+                                     "icalendar", "directory", "pdf", "pkpass"];
466
+		  // Maximum size of message text + files in KB
467
+		  maximumsize = 5120;
468
+                  maximumsizeinit = 5120;
469
+		  maxsizenonimage = 600;
470
+		  maximumfilenumber = 10;
471
+                  chosenProvFullName = "Twilio";
472
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
473
+                                     or gif files, the size of all the files plus the size of the text should be \
474
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
475
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
476
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
477
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
478
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
479
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
480
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
481
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
482
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
483
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
484
+                                     previewed in the adjoining pane."
485
+                  $("#tooltiptextfourth").html(infonotecontent);
486
+	      } else if (chosenProvider == "Fl") {
487
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
488
+		  // Maximum size of message text + files in KB
489
+		  maximumsize = 750;
490
+                  maximumsizeinit = 750;
491
+		  maxsizenonimage = 600;
492
+		  maximumfilenumber = 10;
493
+                  chosenProvFullName = "Flowroute";
494
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
495
+                                     png or gif files, the size of all the files plus the size of the text should be \
496
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
497
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
498
+                                     size of the files plus the size of the text should be 600 KB or less. \
499
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
500
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
501
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
502
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
503
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
504
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
505
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
506
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
507
+                  $("#tooltiptextfourth").html(infonotecontent);
508
+	      }
509
+
510
+          } else { selectedid = ''; }
511
+  });
512
+
513
+  // Check the checkbox to send SMS message to multiple recipients
514
+  $('#tomultchckbx').change(function() {
515
+      if ($(this).is(':checked')) {
516
+          $("#multiplerecivers").css("display", "block");
517
+          $("#smstodiv").css("visibility", "hidden");
518
+          $("#smsto").val("");
519
+
520
+          receiversNumbers.length = 0;
521
+
522
+      } else {
523
+          $("#multiplerecivers").css("display", "none");
524
+          $("#smstodiv").css("visibility", "visible");
525
+
526
+          // Remove the uploaded files' names if any
527
+          $("#induploadfile").remove();
528
+
529
+          // Remove all the files from the SMS_Relentless/multiple_recipients directory
530
+          cleanMultRecDirectory();
531
+
532
+          $("#smstables").empty();
533
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
534
+
535
+          receiversNumbers.length = 0;
536
+      }
537
+  });
538
+
539
+  // Upload the file with the recipients' phone numbers
540
+  $("#uploadfileforsms").change(function(e) {
541
+
542
+     $("#fileuploadednm").empty();
543
+
544
+     receiversNumbers.length = 0;
545
+
546
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
547
+
548
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
549
+
550
+     var formData = new FormData();
551
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
552
+
553
+     var fileup = $('#uploadfileforsms').val();
554
+     var fileuptrim = fileup.split('\\').pop();
555
+
556
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
557
+
558
+     var extension = fileup.replace(/^.*\./, '');
559
+
560
+     if (extension == fileup) {
561
+         extension = "";
562
+     } else {
563
+         extension = extension.toLowerCase();
564
+     }
565
+
566
+     var validExtensionsmrec = ["txt", "csv"];
567
+
568
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
569
+
570
+       if (selectedid != '') {
571
+
572
+               $.ajax({
573
+                 url: baseUrl + '/' + userid,
574
+                 type: "POST",
575
+                 data: formData,
576
+                 cache: false,
577
+                 processData: false,
578
+                 contentType: false,
579
+                 success: function(numberarray) {
580
+
581
+		    if (numberarray.length > 0) {
582
+
583
+		        // Get the array of the receivers' phone numbers
584
+		        if (chosenProvider == "Tx") {
585
+
586
+		             for(key in numberarray) {
587
+		                 receiversNumbers.push("+"+numberarray[key]);
588
+		             }
589
+
590
+		        } else if (chosenProvider == "Pl") {
591
+
592
+		             for(key in numberarray) {
593
+		                 receiversNumbers.push(numberarray[key]);
594
+		             }
595
+
596
+		          } else if (chosenProvider == "Tw") {
597
+
598
+		             for(key in numberarray) {
599
+		                 receiversNumbers.push(numberarray[key]);
600
+		             }
601
+		          } else if (chosenProvider == "Fl") {
602
+
603
+		             for(key in numberarray) {
604
+		                 receiversNumbers.push(numberarray[key]);
605
+		             }
606
+		          }
607
+
608
+		    } else {
609
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
610
+		    }
611
+                            
612
+                    // Preview the uploaded file
613
+                    var smsfilename = e.target.files[0].name;
614
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
615
+
616
+                    var reader = new FileReader();
617
+                    reader.readAsText(e.target.files[0]);
618
+                    reader.onload = function(e) {
619
+                          $("#smstables").empty();
620
+                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
621
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
622
+                    };
623
+
624
+                    $("#smstables").show();
625
+
626
+                    $('#sms_upload_msg').hide();
627
+                    $('#smstables').removeClass('icon-loading');
628
+
629
+                  },
630
+                  error: function() {
631
+                             showAlert("Error while uploading the file.");
632
+                  }
633
+               });
634
+
635
+        } else {
636
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
637
+               $("#induploadfile").remove();
638
+               $('#sms_upload_msg').hide();
639
+               $('#smstables').removeClass('icon-loading');
640
+        }
641
+
642
+     } else {
643
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
644
+          $('#pf_upload_msg').hide();
645
+          $('#smstables').removeClass('icon-loading');
646
+
647
+          $("#induploadfile").remove();
648
+          $("#sms_upload_msg").hide();
649
+     }
650
+
651
+     // Preview uploaded file when clicked
652
+     $("#indfilediv").on("click", function() {
653
+
654
+          var smsfilename = e.target.files[0].name;
655
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
656
+
657
+          var reader = new FileReader();
658
+          reader.readAsText(e.target.files[0]);
659
+          reader.onload = function(e) {
660
+                  $("#smstables").empty();
661
+                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
662
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
663
+          };
664
+
665
+          $("#smstables").show();
666
+          $('#sms_upload_msg').hide();
667
+          $('#smstables').removeClass('icon-loading');
668
+     });
669
+
670
+     // Remove selected file
671
+     $("#indivflremove").on("click", function() {
672
+
673
+          $("#induploadfile").remove();
674
+          $("#sms_upload_msg").hide();
675
+
676
+          receiversNumbers.length = 0;
677
+
678
+          cleanMultRecDirectory();
679
+     });
680
+
681
+  });
682
+
683
+  // Show the number of characters entered in the SMS textarea and the text size in KB
684
+  $("#smstext").on('input', function() {
685
+
686
+     $("#char_count").css("display", "inline");
687
+
688
+     $("#mtextSize").css("display", "inline");
689
+
690
+     $(".maxmessagelength").css("display", "inline-block");
691
+
692
+     $("#countchnb").text($(this).val().length);
693
+
694
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
695
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
696
+     $("#textsizeinkb").text(textsizekb);
697
+
698
+     if ($(this).val().length > charcolorthr) {
699
+         $("#char_count").css("color", "#BB2E4B");
700
+     } else {
701
+         $("#char_count").css("color", "#4cbc86;");
702
+     }
703
+
704
+  });
705
+
706
+
707
+  // Check the checkbox to send file(s) as MMS
708
+  $('#mediafilechckbx').change(function() {
709
+
710
+      if ($(this).is(':checked')) {
711
+
712
+          isMMS = 1;
713
+          if (selectedid == '') {
714
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
715
+              $(this).prop("checked", false);
716
+              isMMS = 0;
717
+              return;
718
+          }
719
+          $("#upmediafiles").css("display", "block");
720
+          $("#submitsms").prop("value", "Send MMS");
721
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send MMS'.");
722
+
723
+      } else {
724
+
725
+          isMMS = 0;
726
+          $("#upmediafiles").css("display", "none");
727
+          $("#submitsms").prop("value", "Send SMS");
728
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send SMS'.");
729
+
730
+          // Remove the uploaded files' names if any
731
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
732
+          $(".indgenpckfls").each(function() { $(this).remove(); });
733
+
734
+          // Remove all the files from the SMS_Relentless/temp_files directory
735
+          cleanTempDirectory();
736
+
737
+          $("#smstables").empty();
738
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
739
+
740
+          uploadedtomms = [];
741
+          n = 1;
742
+
743
+          msgtotalflsize = 0;
744
+
745
+          $("#filestotsize").hide();
746
+      }
747
+  });
748
+
749
+
750
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
751
+  function adjustMaximumSize(uploadedtomms) {
752
+				      
753
+      var nonimgcheck = 0;
754
+      for (var u = 0; u < uploadedtomms.length; u++) {
755
+	   var crupfl = uploadedtomms[u];
756
+	   var extensionup = crupfl.replace(/^.*\./, '');
757
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
758
+	       nonimgcheck = 1;
759
+	   }
760
+      }
761
+
762
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
763
+  }
764
+
765
+  // Upload files to be sent as MMS
766
+  $("#uploadfileformms").change(function(e) {
767
+
768
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
769
+     $('#smstables').addClass('icon-loading');
770
+     $('#filestotsize').show();
771
+
772
+     var userid = "<?php p($userId); ?>";
773
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
774
+
775
+     var formData = new FormData();
776
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
777
+
778
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
779
+
780
+     // Add the size of the current file to the total size of all the files
781
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
782
+
783
+     var fileup = $('#uploadfileformms').val();
784
+     var fileuptrim = fileup.split('\\').pop();
785
+
786
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
787
+         var duplicatescheck = 1;
788
+     } else { 
789
+         var duplicatescheck = 0;
790
+     }
791
+
792
+     var extension = fileup.replace(/^.*\./, '');
793
+
794
+     if (extension == fileup) {
795
+         extension = "";
796
+     } else {
797
+         extension = extension.toLowerCase();
798
+     }
799
+
800
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
801
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
802
+         maximumsize = maxsizenonimage;
803
+     }
804
+
805
+     if ($.inArray(extension, validExtensions) != -1) {
806
+
807
+       if (duplicatescheck == 0) {
808
+
809
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
810
+
811
+            if (n <= maximumfilenumber) {
812
+
813
+               $.ajax({
814
+                 url: baseUrl + '/' + userid,
815
+                 type: "POST",
816
+                 data: formData,
817
+                 cache: false,
818
+                 processData: false,
819
+                 contentType: false,
820
+                 success: function(totalflsize) {
821
+
822
+                   uploadedtomms.push(fileuptrim);
823
+
824
+                   $('#filessizetext').text(totalflsize);
825
+
826
+                   var rectotfilesz = parseFloat(totalflsize);
827
+
828
+                   if (rectotfilesz <= maximumsize) {
829
+                       $('#submitsms').attr("disabled", false);
830
+                       $('#filestotsize').css('color', '#189558');
831
+                   } else {
832
+                       $('#filestotsize').css('color', '#ba3555');
833
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
834
+                       $('#submitsms').attr("disabled", true);
835
+                       $('#smstables').removeClass('icon-loading');
836
+                       $('#pf_upload_msg').hide();
837
+                   }
838
+
839
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
840
+                   n++;
841
+
842
+                   // Preview the file when you click on its name
843
+                   $("div:visible[id*='indfilediv']").each(function() {
844
+
845
+                        $(this).on("click", function(eventclck) {
846
+
847
+                           $("#mmsfoldersview").css("display", "inline-block");
848
+                           var mmsfilenameinit = $(this).text();
849
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
850
+                           var mmsfilename = mmsfilenamesec.replace("X","");
851
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
852
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
853
+
854
+                           if (extenlst == mmsfilename) {
855
+                               extenlst = "";
856
+                           } else {
857
+                               extenlst = extenlst.toLowerCase();
858
+                           }
859
+
860
+                           $("#smstables").empty();
861
+                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
862
+
863
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
864
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
865
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
866
+                           } else if (extenlst == 'png') {
867
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
868
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
869
+                           } else if (extenlst == 'gif') {
870
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
871
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
872
+                           } else if (extenlst == 'bmp') {
873
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
874
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
875
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
876
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
877
+                                  var xhr = new XMLHttpRequest();
878
+                                  xhr.responseType = 'arraybuffer';
879
+                                  xhr.open('GET', tiffile);
880
+                                  xhr.onload = function (evnt) {
881
+                                      var tiff = new Tiff({buffer: xhr.response});
882
+                                      var tifcanvas = tiff.toCanvas();
883
+                                      $("#smstables").append(tifcanvas);
884
+                                  };
885
+                                  xhr.send();
886
+                           } else if (extenlst == 'pdf') {
887
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
888
+                                  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>');
889
+                                  $("#smstables").append($iframe);
890
+                           } else if (extenlst == 'txt') {
891
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
892
+                           } else if (extension == 'mp4') {
893
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
894
+		           } else if (extension == 'ogg') {
895
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
896
+		           } else if (extension == 'avi') {
897
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
898
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
899
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
900
+		           } else if (extension == 'wav' || extension == 'wave') {
901
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
902
+		           } else if (extension == 'mp3') {
903
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
904
+		           } else if (extension == 'midi') {
905
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
906
+		           }
907
+
908
+                           $("#smstables").show();
909
+                           $("#mmsfoldersview").hide();
910
+                        });
911
+                   });
912
+
913
+                   // Remove uploaded files
914
+                   $('[class*="indupfldl"]').last().click(function() {
915
+
916
+                           var userid = "<?php p($userId); ?>";
917
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
918
+
919
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
920
+
921
+                           var removedfilesplit = removedfilenameinit.split(") ");
922
+                           var removedflnb = parseInt(removedfilesplit[0]);
923
+
924
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
925
+                           $(this).hide();
926
+
927
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
928
+
929
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
930
+                                           return value != removedfilename;
931
+                           });
932
+
933
+                           $.ajax({
934
+                                   url: baseUrl + '/' + userid,
935
+                                   type: "POST",
936
+                                   data: {removedfilename: removedfilename},
937
+                                   success: function(totalflsize) {
938
+
939
+                                      msgtotalflsize = totalflsize;
940
+                                      $('#filessizetext').text(totalflsize);
941
+
942
+                                      adjustMaximumSize(uploadedtomms);
943
+
944
+                                      // Check message size
945
+                                      var rectotfilesz = parseFloat(totalflsize);
946
+
947
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
948
+                                          $('#submitsms').attr("disabled", false);
949
+                                          $('#filestotsize').css('color', '#189558');
950
+                                      } else {
951
+                                          $('#filestotsize').css('color', '#ba3555');
952
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
953
+                                          $('#submitsms').attr("disabled", true);
954
+                                      }
955
+
956
+                                      // Rewrite order numbers for files that follow
957
+                                      --n;
958
+                                      $("div:visible[id*='indfilediv']").each(function() {
959
+
960
+                                          var getdivtext =  $(this).text();
961
+                                          var splitdivtext = getdivtext.split(") ");
962
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
963
+                                          var newnbvalue = currentnbvalue - 1;
964
+
965
+                                          if (currentnbvalue > removedflnb) {
966
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
967
+                                              $(this).text(replacedstr);
968
+                                          }
969
+                                      });
970
+
971
+                                      $("div:visible[id*='indflpicked']").each(function() {
972
+
973
+                                          var getdivtext =  $(this).text();
974
+                                          var splitdivtext = getdivtext.split(") ");
975
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
976
+                                          var newnbvalue = currentnbvalue - 1;
977
+
978
+                                          if (currentnbvalue > removedflnb) {
979
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
980
+                                              $(this).text(replacedstr);
981
+                                          }
982
+                                      });
983
+
984
+                                   },
985
+                                   error: function() {
986
+                                              showAlert("Error while removing the file(s).");
987
+                                   }
988
+                           });
989
+
990
+                           $('#smstables').removeClass('icon-loading');
991
+                           $("#smstables").empty();
992
+                   });
993
+
994
+                   // Preview the uploaded file
995
+                   $("#mmsfoldersview").css("display", "inline-block");
996
+                   var mmsfilename = e.target.files[0].name;
997
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
998
+
999
+                   $("#smstables").empty();
1000
+                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1001
+
1002
+                   if (extension == 'jpg' || extension == 'jpeg') {
1003
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
1004
+
1005
+                              var reader = new FileReader();
1006
+                              reader.onload = function (e) {
1007
+                                  readjpg[mmsfilename] = e.target.result;
1008
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
1009
+                              }
1010
+                              reader.readAsDataURL(e.target.files[0]);
1011
+                   } else if (extension == 'png') {
1012
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
1013
+
1014
+                              var reader = new FileReader();
1015
+                              reader.onload = function (e) {
1016
+                                  readpng[mmsfilename] = e.target.result;
1017
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
1018
+                              }
1019
+                              reader.readAsDataURL(e.target.files[0]);
1020
+
1021
+                   } else if (extension == 'gif') {
1022
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
1023
+
1024
+                              var reader = new FileReader();
1025
+                              reader.onload = function (e) {
1026
+                                  readgif[mmsfilename] = e.target.result;
1027
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
1028
+                              }
1029
+                              reader.readAsDataURL(e.target.files[0]);
1030
+
1031
+                   } else if (extension == 'bmp') {
1032
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1033
+
1034
+                              var reader = new FileReader();
1035
+                              reader.onload = function (e) {
1036
+                                  readbmp[mmsfilename] = e.target.result;
1037
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1038
+                              }
1039
+                              reader.readAsDataURL(e.target.files[0]);
1040
+
1041
+                   } else if (extension == 'tif' || extension == 'tiff') {
1042
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1043
+                              var xhr = new XMLHttpRequest();
1044
+                              xhr.responseType = 'arraybuffer';
1045
+                              xhr.open('GET', tiffile);
1046
+                              xhr.onload = function (e) {
1047
+                                  var tiff = new Tiff({buffer: xhr.response});
1048
+                                  var tifcanvas = tiff.toCanvas();
1049
+                                  $("#smstables").append(tifcanvas);
1050
+                              };
1051
+                              xhr.send();
1052
+
1053
+                   } else if (extension == 'pdf') {
1054
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1055
+                              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>');
1056
+                              $("#smstables").append($iframe);
1057
+
1058
+                   } else if (extension == 'txt') {
1059
+                              var reader = new FileReader();
1060
+                              reader.readAsText(e.target.files[0]);
1061
+                              reader.onload = function(e) {
1062
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1063
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1064
+                              };
1065
+                   } else if (extension == 'mp4') {
1066
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1067
+                   } else if (extension == 'ogg') {
1068
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1069
+                   } else if (extension == 'avi') {
1070
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1071
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1072
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1073
+                   } else if (extension == 'wav' || extension == 'wave') {
1074
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1075
+                   } else if (extension == 'mp3') {
1076
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1077
+                   } else if (extension == 'midi') {
1078
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1079
+                   }
1080
+
1081
+                   $("#smstables").show();
1082
+                   $('#pf_upload_msg').hide();
1083
+                   $('#smstables').removeClass('icon-loading');
1084
+                   $("#mmsfoldersview").hide();
1085
+                 },
1086
+                 error: function() {
1087
+                              showAlert("Error while uploading the file.");
1088
+                 }
1089
+               });
1090
+
1091
+            } else {
1092
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1093
+                  adjustMaximumSize(uploadedtomms);
1094
+
1095
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1096
+                  $('#pf_upload_msg').hide();
1097
+                  $('#smstables').removeClass('icon-loading');
1098
+            }
1099
+         } else {
1100
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1101
+              adjustMaximumSize(uploadedtomms);
1102
+
1103
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1104
+              $('#pf_upload_msg').hide();
1105
+              $('#smstables').removeClass('icon-loading');
1106
+         }
1107
+       } else {
1108
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1109
+            adjustMaximumSize(uploadedtomms);
1110
+
1111
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1112
+            $('#pf_upload_msg').hide();
1113
+            $('#smstables').removeClass('icon-loading');
1114
+       }
1115
+
1116
+     } else {
1117
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1118
+          adjustMaximumSize(uploadedtomms);
1119
+
1120
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1121
+          $('#pf_upload_msg').hide();
1122
+          $('#smstables').removeClass('icon-loading');
1123
+     }
1124
+  });
1125
+
1126
+
1127
+  // Pick file(s) from Nextcloud, to send as MMS
1128
+  var mmsfilename = null;
1129
+
1130
+  $("#choosefilen").on("click", function(evn) {
1131
+
1132
+                OC.dialogs.filepicker(
1133
+                        t('settings', "Select a file to send as MMS."),
1134
+                        function (path) {
1135
+
1136
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1137
+                              $('#smstables').addClass('icon-loading');
1138
+                              $('#filestotsize').show();
1139
+
1140
+                              var userid = "<?php p($userId); ?>";
1141
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1142
+
1143
+                              mmsfilename = path.split('/').pop();
1144
+
1145
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1146
+                                  var duplicatescheck = 1;
1147
+                              } else var duplicatescheck = 0;
1148
+
1149
+                              var extension = mmsfilename.replace(/^.*\./, '');
1150
+
1151
+                              if (extension == mmsfilename) {
1152
+                                  extension = "";
1153
+                              } else {
1154
+                                  extension = extension.toLowerCase();
1155
+                              }
1156
+
1157
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1158
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1159
+				   maximumsize = maxsizenonimage;
1160
+			      }
1161
+
1162
+                              if ($.inArray(extension, validExtensions) != -1) {
1163
+
1164
+                                 if (duplicatescheck == 0) {
1165
+
1166
+                                    if (n <= maximumfilenumber) {
1167
+
1168
+                                       $.ajax({
1169
+                                          url: baseUrl + '/' + userid,
1170
+                                          type: "POST",
1171
+                                          data: { path: path },
1172
+                                          success: function(pickresult) {
1173
+
1174
+                                                uploadedtomms.push(mmsfilename);
1175
+
1176
+                                                var totalflsize = pickresult[0];
1177
+                                                var pickedflsize = pickresult[1];
1178
+
1179
+                                                // Check message size
1180
+                                                var rectotfilesz = parseFloat(totalflsize);
1181
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1182
+
1183
+                                                if (filesplustextsize <= maximumsize) {
1184
+
1185
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1186
+
1187
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1188
+                                                    n++;
1189
+
1190
+                                                    msgtotalflsize = totalflsize;
1191
+                                                    $('#filessizetext').text(totalflsize);
1192
+                                                    $('#filestotsize').css('color', '#189558');
1193
+
1194
+                                                } else {
1195
+
1196
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1197
+                                                    $('#filestotsize').css('color', '#ba3555');
1198
+                                                    msgtotalflsize -= pickedflsize;
1199
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1200
+
1201
+                                                    $.ajax({
1202
+                                                        url: baseUrlindrm + '/' + userid,
1203
+                                                        type: "POST",
1204
+                                                        data: {removedfilename: mmsfilename},
1205
+                                                        success: function(totalflsize) {
1206
+
1207
+                                                                          $('#filessizetext').text(totalflsize);
1208
+                                                                          $('#filestotsize').css('color', '#189558');
1209
+                                                                          adjustMaximumSize(uploadedtomms);
1210
+
1211
+                                                        },
1212
+                                                        error: function(totalflsize) {
1213
+                                                                          $('#filessizetext').text(totalflsize);
1214
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1215
+                                                                              $('#filestotsize').css('color', '#ba3555');
1216
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1217
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1218
+                                                        }
1219
+                                                    });
1220
+
1221
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1222
+                                                }
1223
+
1224
+
1225
+                                                // Preview each file when you click on its name
1226
+                                                $("div:visible[id*='indflpicked']").each(function() {
1227
+                                                   $(this).on("click", function(event) {
1228
+
1229
+                                                      var mmsfilenameinit = $(this).text();
1230
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1231
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1232
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1233
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1234
+
1235
+                                                      if (extenlst == mmsfilenamesp) {
1236
+                                                           extenlst = "";
1237
+                                                      } else {
1238
+                                                           extenlst = extenlst.toLowerCase();
1239
+                                                      }
1240
+
1241
+                                                      $("#smstables").empty();
1242
+                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1243
+
1244
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1245
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1246
+                                                      } else if (extenlst == 'png') {
1247
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1248
+                                                      } else if (extenlst == 'gif') {
1249
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1250
+                                                      } else if (extenlst == 'bmp') {
1251
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1252
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1253
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1254
+                                                              var xhr = new XMLHttpRequest();
1255
+                                                              xhr.responseType = 'arraybuffer';
1256
+                                                              xhr.open('GET', tiffile);
1257
+                                                              xhr.onload = function (evnt) {
1258
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1259
+                                                                  var tifcanvas = tiff.toCanvas();
1260
+                                                                  $("#smstables").append(tifcanvas);
1261
+                                                              };
1262
+                                                              xhr.send();
1263
+                                                      } else if (extenlst == 'pdf') {
1264
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1265
+                                                              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>');
1266
+                                                              $("#smstables").append($iframe);
1267
+                                                      } else if (extenlst == 'txt') {
1268
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1269
+                                                      } else if (extension == 'mp4') {
1270
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1271
+						      } else if (extension == 'ogg') {
1272
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1273
+						      } else if (extension == 'avi') {
1274
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1275
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1276
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1277
+						      } else if (extension == 'wav' || extension == 'wave') {
1278
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1279
+						      } else if (extension == 'mp3') {
1280
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1281
+						      } else if (extension == 'midi') {
1282
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1283
+						      }
1284
+
1285
+                                                      $("#smstables").show();
1286
+                                                      $("#mmsfoldersview").hide();
1287
+                                                   });
1288
+                                                });
1289
+
1290
+
1291
+                                                // Remove picked files
1292
+                                                $('[class*="indpckfldl"]').last().click(function() {
1293
+                                                    var userid = "<?php p($userId); ?>";
1294
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1295
+
1296
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1297
+
1298
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1299
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1300
+
1301
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1302
+                                                    $(this).hide();
1303
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1304
+
1305
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1306
+                                                             return value != removedfilename;
1307
+                                                    });
1308
+
1309
+                                                    $.ajax({
1310
+                                                        url: baseUrl + '/' + userid,
1311
+                                                        type: "POST",
1312
+                                                        data: {removedfilename: removedfilename},
1313
+                                                        success: function(totalflsize) {
1314
+
1315
+                                                             msgtotalflsize = totalflsize;
1316
+                                                             $('#filessizetext').text(totalflsize);
1317
+                                                             adjustMaximumSize(uploadedtomms);
1318
+
1319
+                                                             // Check message size
1320
+                                                             var rectotfilesz = parseFloat(totalflsize);
1321
+
1322
+                                                             if (rectotfilesz > maximumsize) {
1323
+                                                                 $('#filestotsize').css('color', '#ba3555');
1324
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1325
+                                                                 $('#submitsms').attr("disabled", true);
1326
+                                                             } else {
1327
+                                                                 $('#submitsms').attr("disabled", false);
1328
+                                                                 $('#filestotsize').css('color', '#189558');
1329
+                                                               }
1330
+
1331
+                                                             // Rewrite order numbers for files that follow
1332
+                                                             --n;
1333
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1334
+
1335
+                                                                  var getdivtext =  $(this).text();
1336
+                                                                  var splitdivtext = getdivtext.split(") ");
1337
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1338
+                                                                  var newnbvalue = currentnbvalue - 1;
1339
+
1340
+                                                                  if (currentnbvalue > removedflnb) {
1341
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1342
+                                                                      $(this).text(replacedstr);
1343
+                                                                  }
1344
+                                                             });
1345
+                                                        },
1346
+                                                        error: function() {
1347
+                                                                  showAlert("Error while removing the file.");
1348
+                                                        }
1349
+                                                    });
1350
+
1351
+                                                    $('#smstables').removeClass('icon-loading');
1352
+                                                    $("#smstables").empty();
1353
+                                                });
1354
+
1355
+
1356
+		                                // Preview the picked file
1357
+		                                $("#mmsfoldersview").css("display", "inline-block");
1358
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1359
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1360
+
1361
+                                                $("#smstables").empty();
1362
+                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1363
+
1364
+						if (extension == 'jpg' || extension == 'jpeg') {
1365
+
1366
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1367
+
1368
+		                                } else if (extension == 'png') {
1369
+
1370
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1371
+
1372
+		                                } else if (extension == 'gif') {
1373
+
1374
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1375
+
1376
+		                                } else if (extension == 'bmp') {
1377
+
1378
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1379
+
1380
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1381
+
1382
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1383
+		                                       var xhr = new XMLHttpRequest();
1384
+		                                       xhr.responseType = 'arraybuffer';
1385
+		                                       xhr.open('GET', tiffile);
1386
+		                                       xhr.onload = function (event) {
1387
+		                                           var tiff = new Tiff({buffer: xhr.response});
1388
+		                                           var tifcanvas = tiff.toCanvas();
1389
+		                                           $("#smstables").append(tifcanvas);
1390
+		                                       };
1391
+		                                       xhr.send();
1392
+
1393
+		                                } else if (extension == 'pdf') {
1394
+
1395
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1396
+		                                       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>');
1397
+		                                       $("#smstables").append($iframe);
1398
+
1399
+		                                } else if (extension == 'txt') {
1400
+
1401
+							     $.get(flUrl, function(textdata) {
1402
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1403
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1404
+							     });
1405
+
1406
+		                                } else if (extension == 'mp4') {
1407
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1408
+						} else if (extension == 'ogg') {
1409
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1410
+						} else if (extension == 'avi') {
1411
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1412
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1413
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1414
+						} else if (extension == 'wav' || extension == 'wave') {
1415
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1416
+						} else if (extension == 'mp3') {
1417
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1418
+						} else if (extension == 'midi') {
1419
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1420
+						}
1421
+
1422
+
1423
+		                                $("#smstables").show();
1424
+
1425
+		                                $('#pf_choose_msg').hide();
1426
+		                                $('#smstables').removeClass('icon-loading');
1427
+		                                $("#mmsfoldersview").hide();
1428
+
1429
+                                          },
1430
+
1431
+                                          error: function(data){
1432
+                                                      showAlert("Error while getting the file.");
1433
+                                          }
1434
+
1435
+                                       });
1436
+
1437
+                                    } else {
1438
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1439
+                                        $('#pf_choose_msg').hide();
1440
+                                        $('#smstables').removeClass('icon-loading');
1441
+                                      }
1442
+                                 } else {
1443
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1444
+                                      $('#pf_choose_msg').hide();
1445
+                                      $('#smstables').removeClass('icon-loading');
1446
+                                   }
1447
+
1448
+                              } else {
1449
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1450
+                                   $('#pf_choose_msg').hide();
1451
+                                   $('#smstables').removeClass('icon-loading');
1452
+                                }
1453
+
1454
+                        }
1455
+                );
1456
+  });
1457
+
1458
+
1459
+
1460
+  // Send the SMS/MMS message
1461
+  $("#submitsms").on("click", function(event) {
1462
+
1463
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1464
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1465
+     $("#sms_submit_msg").css("display", "inline-block");
1466
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1467
+
1468
+     if (selectedid != '') { 
1469
+
1470
+         var sendersplit = selectedid.split(":");
1471
+         var providercap = sendersplit[0];
1472
+         var provsec = sendersplit[1];
1473
+
1474
+         if (/[a-zA-Z]/.test(provsec)) {
1475
+             var alphanumcheck = true;
1476
+         } else { var alphanumcheck = false; }
1477
+
1478
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1479
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1480
+             var selectedsender = "+" + senderproc;
1481
+             var providerUsed = "telnyx";
1482
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1483
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1484
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1485
+             var providerUsed = "plivo";
1486
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1487
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1488
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1489
+             var selectedsender = "+" + senderproc;
1490
+             var providerUsed = "twilio";
1491
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1492
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1493
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1494
+             var selectedsender = "+" + senderproc;
1495
+             var providerUsed = "flowroute";
1496
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1497
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1498
+             var selectedsender = provsec;
1499
+             var providerUsed = "telnyx";
1500
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1501
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1502
+             var selectedsender = provsec;
1503
+             var providerUsed = "plivo";
1504
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1505
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1506
+             var selectedsender = provsec;
1507
+             var providerUsed = "twilio";
1508
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1509
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1510
+             var selectedsender = provsec;
1511
+             var providerUsed = "flowroute";
1512
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1513
+         }
1514
+
1515
+         // Get the interval between message consecutive sending requests, if it's the case
1516
+         if ($('#tomultchckbx').is(':checked')) {
1517
+
1518
+             var numbersfile = 1;
1519
+             var initinterval = $("#multsmsinterval").val();
1520
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1521
+
1522
+             if (secinterval != '') {
1523
+                 var tertinterval = parseInt(secinterval);
1524
+                     waittime = tertinterval;
1525
+             }
1526
+
1527
+         } else {
1528
+
1529
+             var numbersfile = 0;
1530
+             var toNumberinit = $('#smsto').val();
1531
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1532
+             var toNumbersec = toNumber.split(",");
1533
+
1534
+                 for (var i = 0; i < toNumbersec.length; i++) {
1535
+                      toNumbersec[i] = "+" + toNumbersec[i];
1536
+                 }
1537
+
1538
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1539
+         }
1540
+
1541
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1542
+
1543
+         var smstext = $("#smstext").val();
1544
+
1545
+         if (receiversNumbers.length != 0) {
1546
+
1547
+              if (smstext != '') {
1548
+                  $.ajax({
1549
+                     url: relbaseUrl + '/' + userid,
1550
+                     type: "POST",
1551
+                     data: {
1552
+                           receiversPhoneNbs: receiversNumbers,
1553
+                           fromsender: selectedsender,
1554
+                           waitinterval: waittime,
1555
+                           sentsmstext: smstext,
1556
+                           ismms: isMMS,
1557
+                           mmsfiles: uploadedtomms
1558
+                         },
1559
+                     success: function() {
1560
+
1561
+                           if (receiversNumbers.length == 1) {
1562
+                                   showAlert("The message has been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1563
+                           } else {
1564
+                                   showAlert("The messages have been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1565
+                           }
1566
+
1567
+                           $('#sms_submit_msg').hide();
1568
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
+                     },
1570
+                     error: function() {
1571
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1572
+                           $('#sms_submit_msg').hide();
1573
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1574
+                     }
1575
+                  });
1576
+              } else {
1577
+                     showAlert("Please enter a message in the text box !");
1578
+
1579
+                     $('#sms_submit_msg').hide();
1580
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1581
+              }
1582
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1583
+                 showAlert("Please enter the recipient's phone number !");
1584
+                 $('#sms_submit_msg').hide();
1585
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1586
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1587
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1588
+                 $('#sms_submit_msg').hide();
1589
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1590
+         }
1591
+     } else {
1592
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1593
+           $("#induploadfile").remove();
1594
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1595
+           $('#sms_submit_msg').hide();
1596
+     }
1597
+
1598
+  });
1599
+
1600
+  // Check the checkbox to delete old messages from the database
1601
+  $('#deleteoldchckbox').change(function() {
1602
+     if ($(this).is(':checked')) {
1603
+         $("#deleteoldsms").css("display", "block");
1604
+     } else {
1605
+         $("#deleteoldsms").css("display", "none");
1606
+     }
1607
+  });
1608
+
1609
+  // Set the height of info notes
1610
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1611
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1612
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1613
+
1614
+  $(window).resize(function() { 
1615
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1616
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1617
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1618
+  });
1619
+
1620
+
1621
+  function showAlert(alertText) {
1622
+
1623
+     $("#alertMsgOverlay").remove();
1624
+     $("#alertMessage").remove();
1625
+
1626
+     let alertwnd = "<div id='alertMessage'>";
1627
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1628
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1629
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1630
+     alertwnd += "</div>";
1631
+
1632
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1633
+     $("#content").append(alertwnd);
1634
+
1635
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1636
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1637
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1638
+
1639
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1640
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1641
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1642
+  }
Browse code

removed appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/showsmstables.js js/settings.js js/sendsms.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings/personal.php img/arrow-top.svg

DoubleBastionAdmin authored on 02/04/2024 00:07:07
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1642 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  function cleanTempDirectory() {
235
-
236
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
-
238
-     $.ajax({
239
-          url: cleanflUrl + '/' + userid,
240
-          type: "POST",
241
-          data: { userid: userid },
242
-          cache: false,
243
-          processData: false,
244
-          contentType: false
245
-     });
246
-  }
247
-  cleanTempDirectory();
248
-
249
-  // Clean the SMS_Relentless/multiple_recipients directory
250
-  function cleanMultRecDirectory() {
251
-
252
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
-
254
-     $.ajax({
255
-          url: cleanflUrl + '/' + userid,
256
-          type: "POST",
257
-          data: { userid: userid },
258
-          cache: false,
259
-          processData: false,
260
-          contentType: false
261
-     });
262
-  }
263
-  cleanMultRecDirectory();
264
-
265
-  // Check the available balance
266
-  $("#smsprovider").on("change", function () {
267
-
268
-     var provider = $('#smsprovider :selected').val();
269
-
270
-     if (provider == "Telnyx") {
271
-
272
-        var gettelbalance = function() {
273
-
274
-          $('#currentbalance').addClass('icon-loading');
275
-
276
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
-
278
-          $.ajax({
279
-              url: gettelbalanceUrl + '/' + userid,
280
-              type: "POST",
281
-              data: { userid: userid },
282
-              cache: false,
283
-              processData: false,
284
-              contentType: false,
285
-              success: function(currentbalancetel) {
286
-
287
-                     $('#currentbalance').empty();
288
-                     $('#currentbalance').text(currentbalancetel);
289
-                     $('#currentbalance').removeClass('icon-loading');
290
-              }
291
-          });
292
-        }
293
-
294
-        gettelbalance();
295
-
296
-     } else if (provider == "Plivo") {
297
-
298
-          var getnexbalance = function() {
299
-
300
-            $('#currentbalance').addClass('icon-loading');
301
-
302
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
-
304
-            $.ajax({
305
-                url: getnexbalanceUrl + '/' + userid,
306
-                type: "POST",
307
-                data: { userid: userid },
308
-                cache: false,
309
-                processData: false,
310
-                contentType: false,
311
-                success: function(currentbalancenex) {
312
-
313
-                     $('#currentbalance').empty();
314
-                     $('#currentbalance').text(currentbalancenex);
315
-                     $('#currentbalance').removeClass('icon-loading');
316
-                }
317
-            });
318
-          }
319
-
320
-          getnexbalance();
321
-
322
-     } else if (provider == "Twilio") {
323
-
324
-          var gettwilbalance = function() {
325
-
326
-            $('#currentbalance').addClass('icon-loading');
327
-
328
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
-
330
-            $.ajax({
331
-                url: gettwilbalanceUrl + '/' + userid,
332
-                type: "POST",
333
-                data: { userid: userid },
334
-                cache: false,
335
-                processData: false,
336
-                contentType: false,
337
-                success: function(currentbalancetwil) {
338
-
339
-                     $('#currentbalance').empty();
340
-                     $('#currentbalance').text(currentbalancetwil);
341
-                     $('#currentbalance').removeClass('icon-loading');
342
-                }
343
-            });
344
-          }
345
-
346
-          gettwilbalance();
347
-
348
-     } else if (provider == "Flowroute") {
349
-
350
-          var getflowbalance = function() {
351
-
352
-            $('#currentbalance').addClass('icon-loading');
353
-
354
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
-
356
-            $.ajax({
357
-                url: getflowbalanceUrl + '/' + userid,
358
-                type: "POST",
359
-                data: { userid: userid },
360
-                cache: false,
361
-                processData: false,
362
-                contentType: false,
363
-                success: function(currentbalanceflow) {
364
-
365
-                     $('#currentbalance').empty();
366
-                     $('#currentbalance').text(currentbalanceflow);
367
-                     $('#currentbalance').removeClass('icon-loading');
368
-                }
369
-            });
370
-          }
371
-
372
-          getflowbalance();
373
-
374
-       } else if (provider == "") {
375
-                $('#currentbalance').text("");
376
-                $('#currentbalance').removeClass('icon-loading');
377
-       }
378
-  });
379
-
380
-
381
-  // Refresh the list of Sender IDs
382
-  $("#refreshSenderIDs").on("click", function(event) {
383
-
384
-     $('#refreshSenderIDs').addClass('icon-loading');
385
-
386
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/refreshavailablenumbers");
387
-     var selectednmbr = null;
388
-
389
-     $.ajax({
390
-          url: getsmsnumbersUrl + '/' + userid,
391
-          type: "POST",
392
-          data: { userid: userid },
393
-          cache: false,
394
-          processData: false,
395
-          contentType: false,
396
-          success: function(smsnmbrs) {
397
-
398
-                    $('#currentsmsnmbrs').empty();
399
-                    $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
400
-
401
-                    $.each(smsnmbrs, function(key, indsmsnmb) {
402
-                           $('#currentsmsnmbrs').append("<option value='"+ indsmsnmb +"' class='optselectsmsnb'>"+ indsmsnmb +"</option>");
403
-                    });
404
-
405
-                    $('#refreshSenderIDs').removeClass('icon-loading');
406
-          }
407
-     });
408
-  });
409
-
410
-
411
-  // If a Sender ID is selected
412
-  $("#currentsmsnmbrs").on("change", function () {
413
-
414
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
415
-
416
-              selectedid = $('#currentsmsnmbrs :selected').val();
417
-              var setIdsplit = selectedid.split(":");
418
-	      chosenProvider = setIdsplit[0];
419
-
420
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
421
-	      if (chosenProvider == "Tx") {
422
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
423
-		  // Maximum size of message text + files in KB
424
-		  maximumsize = 1024;
425
-                  maximumsizeinit = 1024;
426
-		  maxsizenonimage = 600;
427
-		  maximumfilenumber = 10;
428
-                  chosenProvFullName = "Telnyx";
429
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
430
-                                     or gif files, the size of all the files plus the size of the text should be \
431
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
432
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
433
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
434
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
435
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
436
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
437
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
438
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
439
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
440
-                  $("#tooltiptextfourth").html(infonotecontent);
441
-	      } else if (chosenProvider == "Pl") {
442
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
443
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
444
-		  // Maximum size of message text + files in KB
445
-		  maximumsize = 5120;
446
-                  maximumsizeinit = 5120;
447
-		  maxsizenonimage = 600;
448
-		  maximumfilenumber = 10;
449
-                  chosenProvFullName = "Plivo";
450
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
451
-                                     or gif files, the size of all the files plus the size of the text should be \
452
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
453
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
454
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
455
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
456
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
457
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
458
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
459
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
460
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
461
-                  $("#tooltiptextfourth").html(infonotecontent);
462
-	      } else if (chosenProvider == "Tw") {
463
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
464
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
465
-                                     "icalendar", "directory", "pdf", "pkpass"];
466
-		  // Maximum size of message text + files in KB
467
-		  maximumsize = 5120;
468
-                  maximumsizeinit = 5120;
469
-		  maxsizenonimage = 600;
470
-		  maximumfilenumber = 10;
471
-                  chosenProvFullName = "Twilio";
472
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
473
-                                     or gif files, the size of all the files plus the size of the text should be \
474
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
475
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
476
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
477
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
478
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
479
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
480
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
481
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
482
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
483
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
484
-                                     previewed in the adjoining pane."
485
-                  $("#tooltiptextfourth").html(infonotecontent);
486
-	      } else if (chosenProvider == "Fl") {
487
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
488
-		  // Maximum size of message text + files in KB
489
-		  maximumsize = 750;
490
-                  maximumsizeinit = 750;
491
-		  maxsizenonimage = 600;
492
-		  maximumfilenumber = 10;
493
-                  chosenProvFullName = "Flowroute";
494
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
495
-                                     png or gif files, the size of all the files plus the size of the text should be \
496
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
497
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
498
-                                     size of the files plus the size of the text should be 600 KB or less. \
499
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
500
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
501
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
502
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
503
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
504
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
505
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
506
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
507
-                  $("#tooltiptextfourth").html(infonotecontent);
508
-	      }
509
-
510
-          } else { selectedid = ''; }
511
-  });
512
-
513
-  // Check the checkbox to send SMS message to multiple recipients
514
-  $('#tomultchckbx').change(function() {
515
-      if ($(this).is(':checked')) {
516
-          $("#multiplerecivers").css("display", "block");
517
-          $("#smstodiv").css("visibility", "hidden");
518
-          $("#smsto").val("");
519
-
520
-          receiversNumbers.length = 0;
521
-
522
-      } else {
523
-          $("#multiplerecivers").css("display", "none");
524
-          $("#smstodiv").css("visibility", "visible");
525
-
526
-          // Remove the uploaded files' names if any
527
-          $("#induploadfile").remove();
528
-
529
-          // Remove all the files from the SMS_Relentless/multiple_recipients directory
530
-          cleanMultRecDirectory();
531
-
532
-          $("#smstables").empty();
533
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
534
-
535
-          receiversNumbers.length = 0;
536
-      }
537
-  });
538
-
539
-  // Upload the file with the recipients' phone numbers
540
-  $("#uploadfileforsms").change(function(e) {
541
-
542
-     $("#fileuploadednm").empty();
543
-
544
-     receiversNumbers.length = 0;
545
-
546
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
547
-
548
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
549
-
550
-     var formData = new FormData();
551
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
552
-
553
-     var fileup = $('#uploadfileforsms').val();
554
-     var fileuptrim = fileup.split('\\').pop();
555
-
556
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
557
-
558
-     var extension = fileup.replace(/^.*\./, '');
559
-
560
-     if (extension == fileup) {
561
-         extension = "";
562
-     } else {
563
-         extension = extension.toLowerCase();
564
-     }
565
-
566
-     var validExtensionsmrec = ["txt", "csv"];
567
-
568
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
569
-
570
-       if (selectedid != '') {
571
-
572
-               $.ajax({
573
-                 url: baseUrl + '/' + userid,
574
-                 type: "POST",
575
-                 data: formData,
576
-                 cache: false,
577
-                 processData: false,
578
-                 contentType: false,
579
-                 success: function(numberarray) {
580
-
581
-		    if (numberarray.length > 0) {
582
-
583
-		        // Get the array of the receivers' phone numbers
584
-		        if (chosenProvider == "Tx") {
585
-
586
-		             for(key in numberarray) {
587
-		                 receiversNumbers.push("+"+numberarray[key]);
588
-		             }
589
-
590
-		        } else if (chosenProvider == "Pl") {
591
-
592
-		             for(key in numberarray) {
593
-		                 receiversNumbers.push(numberarray[key]);
594
-		             }
595
-
596
-		          } else if (chosenProvider == "Tw") {
597
-
598
-		             for(key in numberarray) {
599
-		                 receiversNumbers.push(numberarray[key]);
600
-		             }
601
-		          } else if (chosenProvider == "Fl") {
602
-
603
-		             for(key in numberarray) {
604
-		                 receiversNumbers.push(numberarray[key]);
605
-		             }
606
-		          }
607
-
608
-		    } else {
609
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
610
-		    }
611
-                            
612
-                    // Preview the uploaded file
613
-                    var smsfilename = e.target.files[0].name;
614
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
615
-
616
-                    var reader = new FileReader();
617
-                    reader.readAsText(e.target.files[0]);
618
-                    reader.onload = function(e) {
619
-                          $("#smstables").empty();
620
-                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
621
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
622
-                    };
623
-
624
-                    $("#smstables").show();
625
-
626
-                    $('#sms_upload_msg').hide();
627
-                    $('#smstables').removeClass('icon-loading');
628
-
629
-                  },
630
-                  error: function() {
631
-                             showAlert("Error while uploading the file.");
632
-                  }
633
-               });
634
-
635
-        } else {
636
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
637
-               $("#induploadfile").remove();
638
-               $('#sms_upload_msg').hide();
639
-               $('#smstables').removeClass('icon-loading');
640
-        }
641
-
642
-     } else {
643
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
644
-          $('#pf_upload_msg').hide();
645
-          $('#smstables').removeClass('icon-loading');
646
-
647
-          $("#induploadfile").remove();
648
-          $("#sms_upload_msg").hide();
649
-     }
650
-
651
-     // Preview uploaded file when clicked
652
-     $("#indfilediv").on("click", function() {
653
-
654
-          var smsfilename = e.target.files[0].name;
655
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
656
-
657
-          var reader = new FileReader();
658
-          reader.readAsText(e.target.files[0]);
659
-          reader.onload = function(e) {
660
-                  $("#smstables").empty();
661
-                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
662
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
663
-          };
664
-
665
-          $("#smstables").show();
666
-          $('#sms_upload_msg').hide();
667
-          $('#smstables').removeClass('icon-loading');
668
-     });
669
-
670
-     // Remove selected file
671
-     $("#indivflremove").on("click", function() {
672
-
673
-          $("#induploadfile").remove();
674
-          $("#sms_upload_msg").hide();
675
-
676
-          receiversNumbers.length = 0;
677
-
678
-          cleanMultRecDirectory();
679
-     });
680
-
681
-  });
682
-
683
-  // Show the number of characters entered in the SMS textarea and the text size in KB
684
-  $("#smstext").on('input', function() {
685
-
686
-     $("#char_count").css("display", "inline");
687
-
688
-     $("#mtextSize").css("display", "inline");
689
-
690
-     $(".maxmessagelength").css("display", "inline-block");
691
-
692
-     $("#countchnb").text($(this).val().length);
693
-
694
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
695
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
696
-     $("#textsizeinkb").text(textsizekb);
697
-
698
-     if ($(this).val().length > charcolorthr) {
699
-         $("#char_count").css("color", "#BB2E4B");
700
-     } else {
701
-         $("#char_count").css("color", "#4cbc86;");
702
-     }
703
-
704
-  });
705
-
706
-
707
-  // Check the checkbox to send file(s) as MMS
708
-  $('#mediafilechckbx').change(function() {
709
-
710
-      if ($(this).is(':checked')) {
711
-
712
-          isMMS = 1;
713
-          if (selectedid == '') {
714
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
715
-              $(this).prop("checked", false);
716
-              isMMS = 0;
717
-              return;
718
-          }
719
-          $("#upmediafiles").css("display", "block");
720
-          $("#submitsms").prop("value", "Send MMS");
721
-          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send MMS'.");
722
-
723
-      } else {
724
-
725
-          isMMS = 0;
726
-          $("#upmediafiles").css("display", "none");
727
-          $("#submitsms").prop("value", "Send SMS");
728
-          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send SMS'.");
729
-
730
-          // Remove the uploaded files' names if any
731
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
732
-          $(".indgenpckfls").each(function() { $(this).remove(); });
733
-
734
-          // Remove all the files from the SMS_Relentless/temp_files directory
735
-          cleanTempDirectory();
736
-
737
-          $("#smstables").empty();
738
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
739
-
740
-          uploadedtomms = [];
741
-          n = 1;
742
-
743
-          msgtotalflsize = 0;
744
-
745
-          $("#filestotsize").hide();
746
-      }
747
-  });
748
-
749
-
750
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
751
-  function adjustMaximumSize(uploadedtomms) {
752
-				      
753
-      var nonimgcheck = 0;
754
-      for (var u = 0; u < uploadedtomms.length; u++) {
755
-	   var crupfl = uploadedtomms[u];
756
-	   var extensionup = crupfl.replace(/^.*\./, '');
757
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
758
-	       nonimgcheck = 1;
759
-	   }
760
-      }
761
-
762
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
763
-  }
764
-
765
-  // Upload files to be sent as MMS
766
-  $("#uploadfileformms").change(function(e) {
767
-
768
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
769
-     $('#smstables').addClass('icon-loading');
770
-     $('#filestotsize').show();
771
-
772
-     var userid = "<?php p($userId); ?>";
773
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
774
-
775
-     var formData = new FormData();
776
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
777
-
778
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
779
-
780
-     // Add the size of the current file to the total size of all the files
781
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
782
-
783
-     var fileup = $('#uploadfileformms').val();
784
-     var fileuptrim = fileup.split('\\').pop();
785
-
786
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
787
-         var duplicatescheck = 1;
788
-     } else { 
789
-         var duplicatescheck = 0;
790
-     }
791
-
792
-     var extension = fileup.replace(/^.*\./, '');
793
-
794
-     if (extension == fileup) {
795
-         extension = "";
796
-     } else {
797
-         extension = extension.toLowerCase();
798
-     }
799
-
800
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
801
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
802
-         maximumsize = maxsizenonimage;
803
-     }
804
-
805
-     if ($.inArray(extension, validExtensions) != -1) {
806
-
807
-       if (duplicatescheck == 0) {
808
-
809
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
810
-
811
-            if (n <= maximumfilenumber) {
812
-
813
-               $.ajax({
814
-                 url: baseUrl + '/' + userid,
815
-                 type: "POST",
816
-                 data: formData,
817
-                 cache: false,
818
-                 processData: false,
819
-                 contentType: false,
820
-                 success: function(totalflsize) {
821
-
822
-                   uploadedtomms.push(fileuptrim);
823
-
824
-                   $('#filessizetext').text(totalflsize);
825
-
826
-                   var rectotfilesz = parseFloat(totalflsize);
827
-
828
-                   if (rectotfilesz <= maximumsize) {
829
-                       $('#submitsms').attr("disabled", false);
830
-                       $('#filestotsize').css('color', '#189558');
831
-                   } else {
832
-                       $('#filestotsize').css('color', '#ba3555');
833
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
834
-                       $('#submitsms').attr("disabled", true);
835
-                       $('#smstables').removeClass('icon-loading');
836
-                       $('#pf_upload_msg').hide();
837
-                   }
838
-
839
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
840
-                   n++;
841
-
842
-                   // Preview the file when you click on its name
843
-                   $("div:visible[id*='indfilediv']").each(function() {
844
-
845
-                        $(this).on("click", function(eventclck) {
846
-
847
-                           $("#mmsfoldersview").css("display", "inline-block");
848
-                           var mmsfilenameinit = $(this).text();
849
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
850
-                           var mmsfilename = mmsfilenamesec.replace("X","");
851
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
852
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
853
-
854
-                           if (extenlst == mmsfilename) {
855
-                               extenlst = "";
856
-                           } else {
857
-                               extenlst = extenlst.toLowerCase();
858
-                           }
859
-
860
-                           $("#smstables").empty();
861
-                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
862
-
863
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
864
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
865
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
866
-                           } else if (extenlst == 'png') {
867
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
868
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
869
-                           } else if (extenlst == 'gif') {
870
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
871
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
872
-                           } else if (extenlst == 'bmp') {
873
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
874
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
875
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
876
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
877
-                                  var xhr = new XMLHttpRequest();
878
-                                  xhr.responseType = 'arraybuffer';
879
-                                  xhr.open('GET', tiffile);
880
-                                  xhr.onload = function (evnt) {
881
-                                      var tiff = new Tiff({buffer: xhr.response});
882
-                                      var tifcanvas = tiff.toCanvas();
883
-                                      $("#smstables").append(tifcanvas);
884
-                                  };
885
-                                  xhr.send();
886
-                           } else if (extenlst == 'pdf') {
887
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
888
-                                  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>');
889
-                                  $("#smstables").append($iframe);
890
-                           } else if (extenlst == 'txt') {
891
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
892
-                           } else if (extension == 'mp4') {
893
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
894
-		           } else if (extension == 'ogg') {
895
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
896
-		           } else if (extension == 'avi') {
897
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
898
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
899
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
900
-		           } else if (extension == 'wav' || extension == 'wave') {
901
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
902
-		           } else if (extension == 'mp3') {
903
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
904
-		           } else if (extension == 'midi') {
905
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
906
-		           }
907
-
908
-                           $("#smstables").show();
909
-                           $("#mmsfoldersview").hide();
910
-                        });
911
-                   });
912
-
913
-                   // Remove uploaded files
914
-                   $('[class*="indupfldl"]').last().click(function() {
915
-
916
-                           var userid = "<?php p($userId); ?>";
917
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
918
-
919
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
920
-
921
-                           var removedfilesplit = removedfilenameinit.split(") ");
922
-                           var removedflnb = parseInt(removedfilesplit[0]);
923
-
924
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
925
-                           $(this).hide();
926
-
927
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
928
-
929
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
930
-                                           return value != removedfilename;
931
-                           });
932
-
933
-                           $.ajax({
934
-                                   url: baseUrl + '/' + userid,
935
-                                   type: "POST",
936
-                                   data: {removedfilename: removedfilename},
937
-                                   success: function(totalflsize) {
938
-
939
-                                      msgtotalflsize = totalflsize;
940
-                                      $('#filessizetext').text(totalflsize);
941
-
942
-                                      adjustMaximumSize(uploadedtomms);
943
-
944
-                                      // Check message size
945
-                                      var rectotfilesz = parseFloat(totalflsize);
946
-
947
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
948
-                                          $('#submitsms').attr("disabled", false);
949
-                                          $('#filestotsize').css('color', '#189558');
950
-                                      } else {
951
-                                          $('#filestotsize').css('color', '#ba3555');
952
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
953
-                                          $('#submitsms').attr("disabled", true);
954
-                                      }
955
-
956
-                                      // Rewrite order numbers for files that follow
957
-                                      --n;
958
-                                      $("div:visible[id*='indfilediv']").each(function() {
959
-
960
-                                          var getdivtext =  $(this).text();
961
-                                          var splitdivtext = getdivtext.split(") ");
962
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
963
-                                          var newnbvalue = currentnbvalue - 1;
964
-
965
-                                          if (currentnbvalue > removedflnb) {
966
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
967
-                                              $(this).text(replacedstr);
968
-                                          }
969
-                                      });
970
-
971
-                                      $("div:visible[id*='indflpicked']").each(function() {
972
-
973
-                                          var getdivtext =  $(this).text();
974
-                                          var splitdivtext = getdivtext.split(") ");
975
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
976
-                                          var newnbvalue = currentnbvalue - 1;
977
-
978
-                                          if (currentnbvalue > removedflnb) {
979
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
980
-                                              $(this).text(replacedstr);
981
-                                          }
982
-                                      });
983
-
984
-                                   },
985
-                                   error: function() {
986
-                                              showAlert("Error while removing the file(s).");
987
-                                   }
988
-                           });
989
-
990
-                           $('#smstables').removeClass('icon-loading');
991
-                           $("#smstables").empty();
992
-                   });
993
-
994
-                   // Preview the uploaded file
995
-                   $("#mmsfoldersview").css("display", "inline-block");
996
-                   var mmsfilename = e.target.files[0].name;
997
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
998
-
999
-                   $("#smstables").empty();
1000
-                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1001
-
1002
-                   if (extension == 'jpg' || extension == 'jpeg') {
1003
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
1004
-
1005
-                              var reader = new FileReader();
1006
-                              reader.onload = function (e) {
1007
-                                  readjpg[mmsfilename] = e.target.result;
1008
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
1009
-                              }
1010
-                              reader.readAsDataURL(e.target.files[0]);
1011
-                   } else if (extension == 'png') {
1012
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
1013
-
1014
-                              var reader = new FileReader();
1015
-                              reader.onload = function (e) {
1016
-                                  readpng[mmsfilename] = e.target.result;
1017
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
1018
-                              }
1019
-                              reader.readAsDataURL(e.target.files[0]);
1020
-
1021
-                   } else if (extension == 'gif') {
1022
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
1023
-
1024
-                              var reader = new FileReader();
1025
-                              reader.onload = function (e) {
1026
-                                  readgif[mmsfilename] = e.target.result;
1027
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
1028
-                              }
1029
-                              reader.readAsDataURL(e.target.files[0]);
1030
-
1031
-                   } else if (extension == 'bmp') {
1032
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1033
-
1034
-                              var reader = new FileReader();
1035
-                              reader.onload = function (e) {
1036
-                                  readbmp[mmsfilename] = e.target.result;
1037
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1038
-                              }
1039
-                              reader.readAsDataURL(e.target.files[0]);
1040
-
1041
-                   } else if (extension == 'tif' || extension == 'tiff') {
1042
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1043
-                              var xhr = new XMLHttpRequest();
1044
-                              xhr.responseType = 'arraybuffer';
1045
-                              xhr.open('GET', tiffile);
1046
-                              xhr.onload = function (e) {
1047
-                                  var tiff = new Tiff({buffer: xhr.response});
1048
-                                  var tifcanvas = tiff.toCanvas();
1049
-                                  $("#smstables").append(tifcanvas);
1050
-                              };
1051
-                              xhr.send();
1052
-
1053
-                   } else if (extension == 'pdf') {
1054
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1055
-                              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>');
1056
-                              $("#smstables").append($iframe);
1057
-
1058
-                   } else if (extension == 'txt') {
1059
-                              var reader = new FileReader();
1060
-                              reader.readAsText(e.target.files[0]);
1061
-                              reader.onload = function(e) {
1062
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1063
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1064
-                              };
1065
-                   } else if (extension == 'mp4') {
1066
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1067
-                   } else if (extension == 'ogg') {
1068
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1069
-                   } else if (extension == 'avi') {
1070
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1071
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1072
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1073
-                   } else if (extension == 'wav' || extension == 'wave') {
1074
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1075
-                   } else if (extension == 'mp3') {
1076
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1077
-                   } else if (extension == 'midi') {
1078
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1079
-                   }
1080
-
1081
-                   $("#smstables").show();
1082
-                   $('#pf_upload_msg').hide();
1083
-                   $('#smstables').removeClass('icon-loading');
1084
-                   $("#mmsfoldersview").hide();
1085
-                 },
1086
-                 error: function() {
1087
-                              showAlert("Error while uploading the file.");
1088
-                 }
1089
-               });
1090
-
1091
-            } else {
1092
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1093
-                  adjustMaximumSize(uploadedtomms);
1094
-
1095
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1096
-                  $('#pf_upload_msg').hide();
1097
-                  $('#smstables').removeClass('icon-loading');
1098
-            }
1099
-         } else {
1100
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1101
-              adjustMaximumSize(uploadedtomms);
1102
-
1103
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1104
-              $('#pf_upload_msg').hide();
1105
-              $('#smstables').removeClass('icon-loading');
1106
-         }
1107
-       } else {
1108
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1109
-            adjustMaximumSize(uploadedtomms);
1110
-
1111
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1112
-            $('#pf_upload_msg').hide();
1113
-            $('#smstables').removeClass('icon-loading');
1114
-       }
1115
-
1116
-     } else {
1117
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1118
-          adjustMaximumSize(uploadedtomms);
1119
-
1120
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1121
-          $('#pf_upload_msg').hide();
1122
-          $('#smstables').removeClass('icon-loading');
1123
-     }
1124
-  });
1125
-
1126
-
1127
-  // Pick file(s) from Nextcloud, to send as MMS
1128
-  var mmsfilename = null;
1129
-
1130
-  $("#choosefilen").on("click", function(evn) {
1131
-
1132
-                OC.dialogs.filepicker(
1133
-                        t('settings', "Select a file to send as MMS."),
1134
-                        function (path) {
1135
-
1136
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1137
-                              $('#smstables').addClass('icon-loading');
1138
-                              $('#filestotsize').show();
1139
-
1140
-                              var userid = "<?php p($userId); ?>";
1141
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1142
-
1143
-                              mmsfilename = path.split('/').pop();
1144
-
1145
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1146
-                                  var duplicatescheck = 1;
1147
-                              } else var duplicatescheck = 0;
1148
-
1149
-                              var extension = mmsfilename.replace(/^.*\./, '');
1150
-
1151
-                              if (extension == mmsfilename) {
1152
-                                  extension = "";
1153
-                              } else {
1154
-                                  extension = extension.toLowerCase();
1155
-                              }
1156
-
1157
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1158
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1159
-				   maximumsize = maxsizenonimage;
1160
-			      }
1161
-
1162
-                              if ($.inArray(extension, validExtensions) != -1) {
1163
-
1164
-                                 if (duplicatescheck == 0) {
1165
-
1166
-                                    if (n <= maximumfilenumber) {
1167
-
1168
-                                       $.ajax({
1169
-                                          url: baseUrl + '/' + userid,
1170
-                                          type: "POST",
1171
-                                          data: { path: path },
1172
-                                          success: function(pickresult) {
1173
-
1174
-                                                uploadedtomms.push(mmsfilename);
1175
-
1176
-                                                var totalflsize = pickresult[0];
1177
-                                                var pickedflsize = pickresult[1];
1178
-
1179
-                                                // Check message size
1180
-                                                var rectotfilesz = parseFloat(totalflsize);
1181
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1182
-
1183
-                                                if (filesplustextsize <= maximumsize) {
1184
-
1185
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1186
-
1187
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1188
-                                                    n++;
1189
-
1190
-                                                    msgtotalflsize = totalflsize;
1191
-                                                    $('#filessizetext').text(totalflsize);
1192
-                                                    $('#filestotsize').css('color', '#189558');
1193
-
1194
-                                                } else {
1195
-
1196
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1197
-                                                    $('#filestotsize').css('color', '#ba3555');
1198
-                                                    msgtotalflsize -= pickedflsize;
1199
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1200
-
1201
-                                                    $.ajax({
1202
-                                                        url: baseUrlindrm + '/' + userid,
1203
-                                                        type: "POST",
1204
-                                                        data: {removedfilename: mmsfilename},
1205
-                                                        success: function(totalflsize) {
1206
-
1207
-                                                                          $('#filessizetext').text(totalflsize);
1208
-                                                                          $('#filestotsize').css('color', '#189558');
1209
-                                                                          adjustMaximumSize(uploadedtomms);
1210
-
1211
-                                                        },
1212
-                                                        error: function(totalflsize) {
1213
-                                                                          $('#filessizetext').text(totalflsize);
1214
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1215
-                                                                              $('#filestotsize').css('color', '#ba3555');
1216
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1217
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1218
-                                                        }
1219
-                                                    });
1220
-
1221
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1222
-                                                }
1223
-
1224
-
1225
-                                                // Preview each file when you click on its name
1226
-                                                $("div:visible[id*='indflpicked']").each(function() {
1227
-                                                   $(this).on("click", function(event) {
1228
-
1229
-                                                      var mmsfilenameinit = $(this).text();
1230
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1231
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1232
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1233
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1234
-
1235
-                                                      if (extenlst == mmsfilenamesp) {
1236
-                                                           extenlst = "";
1237
-                                                      } else {
1238
-                                                           extenlst = extenlst.toLowerCase();
1239
-                                                      }
1240
-
1241
-                                                      $("#smstables").empty();
1242
-                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1243
-
1244
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1245
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1246
-                                                      } else if (extenlst == 'png') {
1247
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1248
-                                                      } else if (extenlst == 'gif') {
1249
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1250
-                                                      } else if (extenlst == 'bmp') {
1251
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1252
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1253
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1254
-                                                              var xhr = new XMLHttpRequest();
1255
-                                                              xhr.responseType = 'arraybuffer';
1256
-                                                              xhr.open('GET', tiffile);
1257
-                                                              xhr.onload = function (evnt) {
1258
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1259
-                                                                  var tifcanvas = tiff.toCanvas();
1260
-                                                                  $("#smstables").append(tifcanvas);
1261
-                                                              };
1262
-                                                              xhr.send();
1263
-                                                      } else if (extenlst == 'pdf') {
1264
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1265
-                                                              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>');
1266
-                                                              $("#smstables").append($iframe);
1267
-                                                      } else if (extenlst == 'txt') {
1268
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1269
-                                                      } else if (extension == 'mp4') {
1270
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1271
-						      } else if (extension == 'ogg') {
1272
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1273
-						      } else if (extension == 'avi') {
1274
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1275
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1276
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1277
-						      } else if (extension == 'wav' || extension == 'wave') {
1278
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1279
-						      } else if (extension == 'mp3') {
1280
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1281
-						      } else if (extension == 'midi') {
1282
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1283
-						      }
1284
-
1285
-                                                      $("#smstables").show();
1286
-                                                      $("#mmsfoldersview").hide();
1287
-                                                   });
1288
-                                                });
1289
-
1290
-
1291
-                                                // Remove picked files
1292
-                                                $('[class*="indpckfldl"]').last().click(function() {
1293
-                                                    var userid = "<?php p($userId); ?>";
1294
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1295
-
1296
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1297
-
1298
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1299
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1300
-
1301
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1302
-                                                    $(this).hide();
1303
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1304
-
1305
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1306
-                                                             return value != removedfilename;
1307
-                                                    });
1308
-
1309
-                                                    $.ajax({
1310
-                                                        url: baseUrl + '/' + userid,
1311
-                                                        type: "POST",
1312
-                                                        data: {removedfilename: removedfilename},
1313
-                                                        success: function(totalflsize) {
1314
-
1315
-                                                             msgtotalflsize = totalflsize;
1316
-                                                             $('#filessizetext').text(totalflsize);
1317
-                                                             adjustMaximumSize(uploadedtomms);
1318
-
1319
-                                                             // Check message size
1320
-                                                             var rectotfilesz = parseFloat(totalflsize);
1321
-
1322
-                                                             if (rectotfilesz > maximumsize) {
1323
-                                                                 $('#filestotsize').css('color', '#ba3555');
1324
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1325
-                                                                 $('#submitsms').attr("disabled", true);
1326
-                                                             } else {
1327
-                                                                 $('#submitsms').attr("disabled", false);
1328
-                                                                 $('#filestotsize').css('color', '#189558');
1329
-                                                               }
1330
-
1331
-                                                             // Rewrite order numbers for files that follow
1332
-                                                             --n;
1333
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1334
-
1335
-                                                                  var getdivtext =  $(this).text();
1336
-                                                                  var splitdivtext = getdivtext.split(") ");
1337
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1338
-                                                                  var newnbvalue = currentnbvalue - 1;
1339
-
1340
-                                                                  if (currentnbvalue > removedflnb) {
1341
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1342
-                                                                      $(this).text(replacedstr);
1343
-                                                                  }
1344
-                                                             });
1345
-                                                        },
1346
-                                                        error: function() {
1347
-                                                                  showAlert("Error while removing the file.");
1348
-                                                        }
1349
-                                                    });
1350
-
1351
-                                                    $('#smstables').removeClass('icon-loading');
1352
-                                                    $("#smstables").empty();
1353
-                                                });
1354
-
1355
-
1356
-		                                // Preview the picked file
1357
-		                                $("#mmsfoldersview").css("display", "inline-block");
1358
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1359
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1360
-
1361
-                                                $("#smstables").empty();
1362
-                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1363
-
1364
-						if (extension == 'jpg' || extension == 'jpeg') {
1365
-
1366
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1367
-
1368
-		                                } else if (extension == 'png') {
1369
-
1370
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1371
-
1372
-		                                } else if (extension == 'gif') {
1373
-
1374
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1375
-
1376
-		                                } else if (extension == 'bmp') {
1377
-
1378
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1379
-
1380
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1381
-
1382
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1383
-		                                       var xhr = new XMLHttpRequest();
1384
-		                                       xhr.responseType = 'arraybuffer';
1385
-		                                       xhr.open('GET', tiffile);
1386
-		                                       xhr.onload = function (event) {
1387
-		                                           var tiff = new Tiff({buffer: xhr.response});
1388
-		                                           var tifcanvas = tiff.toCanvas();
1389
-		                                           $("#smstables").append(tifcanvas);
1390
-		                                       };
1391
-		                                       xhr.send();
1392
-
1393
-		                                } else if (extension == 'pdf') {
1394
-
1395
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1396
-		                                       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>');
1397
-		                                       $("#smstables").append($iframe);
1398
-
1399
-		                                } else if (extension == 'txt') {
1400
-
1401
-							     $.get(flUrl, function(textdata) {
1402
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1403
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1404
-							     });
1405
-
1406
-		                                } else if (extension == 'mp4') {
1407
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1408
-						} else if (extension == 'ogg') {
1409
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1410
-						} else if (extension == 'avi') {
1411
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1412
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1413
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1414
-						} else if (extension == 'wav' || extension == 'wave') {
1415
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1416
-						} else if (extension == 'mp3') {
1417
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1418
-						} else if (extension == 'midi') {
1419
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1420
-						}
1421
-
1422
-
1423
-		                                $("#smstables").show();
1424
-
1425
-		                                $('#pf_choose_msg').hide();
1426
-		                                $('#smstables').removeClass('icon-loading');
1427
-		                                $("#mmsfoldersview").hide();
1428
-
1429
-                                          },
1430
-
1431
-                                          error: function(data){
1432
-                                                      showAlert("Error while getting the file.");
1433
-                                          }
1434
-
1435
-                                       });
1436
-
1437
-                                    } else {
1438
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1439
-                                        $('#pf_choose_msg').hide();
1440
-                                        $('#smstables').removeClass('icon-loading');
1441
-                                      }
1442
-                                 } else {
1443
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1444
-                                      $('#pf_choose_msg').hide();
1445
-                                      $('#smstables').removeClass('icon-loading');
1446
-                                   }
1447
-
1448
-                              } else {
1449
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1450
-                                   $('#pf_choose_msg').hide();
1451
-                                   $('#smstables').removeClass('icon-loading');
1452
-                                }
1453
-
1454
-                        }
1455
-                );
1456
-  });
1457
-
1458
-
1459
-
1460
-  // Send the SMS/MMS message
1461
-  $("#submitsms").on("click", function(event) {
1462
-
1463
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1464
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1465
-     $("#sms_submit_msg").css("display", "inline-block");
1466
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1467
-
1468
-     if (selectedid != '') { 
1469
-
1470
-         var sendersplit = selectedid.split(":");
1471
-         var providercap = sendersplit[0];
1472
-         var provsec = sendersplit[1];
1473
-
1474
-         if (/[a-zA-Z]/.test(provsec)) {
1475
-             var alphanumcheck = true;
1476
-         } else { var alphanumcheck = false; }
1477
-
1478
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1479
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1480
-             var selectedsender = "+" + senderproc;
1481
-             var providerUsed = "telnyx";
1482
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1483
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1484
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1485
-             var providerUsed = "plivo";
1486
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1487
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1488
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1489
-             var selectedsender = "+" + senderproc;
1490
-             var providerUsed = "twilio";
1491
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1492
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1493
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1494
-             var selectedsender = "+" + senderproc;
1495
-             var providerUsed = "flowroute";
1496
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1497
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1498
-             var selectedsender = provsec;
1499
-             var providerUsed = "telnyx";
1500
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1501
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1502
-             var selectedsender = provsec;
1503
-             var providerUsed = "plivo";
1504
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1505
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1506
-             var selectedsender = provsec;
1507
-             var providerUsed = "twilio";
1508
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1509
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1510
-             var selectedsender = provsec;
1511
-             var providerUsed = "flowroute";
1512
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1513
-         }
1514
-
1515
-         // Get the interval between message consecutive sending requests, if it's the case
1516
-         if ($('#tomultchckbx').is(':checked')) {
1517
-
1518
-             var numbersfile = 1;
1519
-             var initinterval = $("#multsmsinterval").val();
1520
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1521
-
1522
-             if (secinterval != '') {
1523
-                 var tertinterval = parseInt(secinterval);
1524
-                     waittime = tertinterval;
1525
-             }
1526
-
1527
-         } else {
1528
-
1529
-             var numbersfile = 0;
1530
-             var toNumberinit = $('#smsto').val();
1531
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1532
-             var toNumbersec = toNumber.split(",");
1533
-
1534
-                 for (var i = 0; i < toNumbersec.length; i++) {
1535
-                      toNumbersec[i] = "+" + toNumbersec[i];
1536
-                 }
1537
-
1538
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1539
-         }
1540
-
1541
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1542
-
1543
-         var smstext = $("#smstext").val();
1544
-
1545
-         if (receiversNumbers.length != 0) {
1546
-
1547
-              if (smstext != '') {
1548
-                  $.ajax({
1549
-                     url: relbaseUrl + '/' + userid,
1550
-                     type: "POST",
1551
-                     data: {
1552
-                           receiversPhoneNbs: receiversNumbers,
1553
-                           fromsender: selectedsender,
1554
-                           waitinterval: waittime,
1555
-                           sentsmstext: smstext,
1556
-                           ismms: isMMS,
1557
-                           mmsfiles: uploadedtomms
1558
-                         },
1559
-                     success: function() {
1560
-
1561
-                           if (receiversNumbers.length == 1) {
1562
-                                   showAlert("The message has been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1563
-                           } else {
1564
-                                   showAlert("The messages have been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1565
-                           }
1566
-
1567
-                           $('#sms_submit_msg').hide();
1568
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
-                     },
1570
-                     error: function() {
1571
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1572
-                           $('#sms_submit_msg').hide();
1573
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1574
-                     }
1575
-                  });
1576
-              } else {
1577
-                     showAlert("Please enter a message in the text box !");
1578
-
1579
-                     $('#sms_submit_msg').hide();
1580
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1581
-              }
1582
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1583
-                 showAlert("Please enter the recipient's phone number !");
1584
-                 $('#sms_submit_msg').hide();
1585
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1586
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1587
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1588
-                 $('#sms_submit_msg').hide();
1589
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1590
-         }
1591
-     } else {
1592
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1593
-           $("#induploadfile").remove();
1594
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1595
-           $('#sms_submit_msg').hide();
1596
-     }
1597
-
1598
-  });
1599
-
1600
-  // Check the checkbox to delete old messages from the database
1601
-  $('#deleteoldchckbox').change(function() {
1602
-     if ($(this).is(':checked')) {
1603
-         $("#deleteoldsms").css("display", "block");
1604
-     } else {
1605
-         $("#deleteoldsms").css("display", "none");
1606
-     }
1607
-  });
1608
-
1609
-  // Set the height of info notes
1610
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1611
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1612
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1613
-
1614
-  $(window).resize(function() { 
1615
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1616
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1617
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1618
-  });
1619
-
1620
-
1621
-  function showAlert(alertText) {
1622
-
1623
-     $("#alertMsgOverlay").remove();
1624
-     $("#alertMessage").remove();
1625
-
1626
-     let alertwnd = "<div id='alertMessage'>";
1627
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1628
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1629
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1630
-     alertwnd += "</div>";
1631
-
1632
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1633
-     $("#content").append(alertwnd);
1634
-
1635
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1636
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1637
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1638
-
1639
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1640
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1641
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1642
-  }
Browse code

added appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/settings.js js/sendsms.js js/adminsettings.js js/showsmstables.js templates/settings/admin.php templates/settings/personal.php templates/navigation/index.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php l10n/en_GB.js l10n/en_GB.json l10n/en_US.js l10n/en_US.json lib/Migration/Version133Date20240215094712.php

DoubleBastionAdmin authored on 14/02/2024 22:47:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1642 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  function cleanTempDirectory() {
235
+
236
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
+
238
+     $.ajax({
239
+          url: cleanflUrl + '/' + userid,
240
+          type: "POST",
241
+          data: { userid: userid },
242
+          cache: false,
243
+          processData: false,
244
+          contentType: false
245
+     });
246
+  }
247
+  cleanTempDirectory();
248
+
249
+  // Clean the SMS_Relentless/multiple_recipients directory
250
+  function cleanMultRecDirectory() {
251
+
252
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
+
254
+     $.ajax({
255
+          url: cleanflUrl + '/' + userid,
256
+          type: "POST",
257
+          data: { userid: userid },
258
+          cache: false,
259
+          processData: false,
260
+          contentType: false
261
+     });
262
+  }
263
+  cleanMultRecDirectory();
264
+
265
+  // Check the available balance
266
+  $("#smsprovider").on("change", function () {
267
+
268
+     var provider = $('#smsprovider :selected').val();
269
+
270
+     if (provider == "Telnyx") {
271
+
272
+        var gettelbalance = function() {
273
+
274
+          $('#currentbalance').addClass('icon-loading');
275
+
276
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
+
278
+          $.ajax({
279
+              url: gettelbalanceUrl + '/' + userid,
280
+              type: "POST",
281
+              data: { userid: userid },
282
+              cache: false,
283
+              processData: false,
284
+              contentType: false,
285
+              success: function(currentbalancetel) {
286
+
287
+                     $('#currentbalance').empty();
288
+                     $('#currentbalance').text(currentbalancetel);
289
+                     $('#currentbalance').removeClass('icon-loading');
290
+              }
291
+          });
292
+        }
293
+
294
+        gettelbalance();
295
+
296
+     } else if (provider == "Plivo") {
297
+
298
+          var getnexbalance = function() {
299
+
300
+            $('#currentbalance').addClass('icon-loading');
301
+
302
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
+
304
+            $.ajax({
305
+                url: getnexbalanceUrl + '/' + userid,
306
+                type: "POST",
307
+                data: { userid: userid },
308
+                cache: false,
309
+                processData: false,
310
+                contentType: false,
311
+                success: function(currentbalancenex) {
312
+
313
+                     $('#currentbalance').empty();
314
+                     $('#currentbalance').text(currentbalancenex);
315
+                     $('#currentbalance').removeClass('icon-loading');
316
+                }
317
+            });
318
+          }
319
+
320
+          getnexbalance();
321
+
322
+     } else if (provider == "Twilio") {
323
+
324
+          var gettwilbalance = function() {
325
+
326
+            $('#currentbalance').addClass('icon-loading');
327
+
328
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
+
330
+            $.ajax({
331
+                url: gettwilbalanceUrl + '/' + userid,
332
+                type: "POST",
333
+                data: { userid: userid },
334
+                cache: false,
335
+                processData: false,
336
+                contentType: false,
337
+                success: function(currentbalancetwil) {
338
+
339
+                     $('#currentbalance').empty();
340
+                     $('#currentbalance').text(currentbalancetwil);
341
+                     $('#currentbalance').removeClass('icon-loading');
342
+                }
343
+            });
344
+          }
345
+
346
+          gettwilbalance();
347
+
348
+     } else if (provider == "Flowroute") {
349
+
350
+          var getflowbalance = function() {
351
+
352
+            $('#currentbalance').addClass('icon-loading');
353
+
354
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
+
356
+            $.ajax({
357
+                url: getflowbalanceUrl + '/' + userid,
358
+                type: "POST",
359
+                data: { userid: userid },
360
+                cache: false,
361
+                processData: false,
362
+                contentType: false,
363
+                success: function(currentbalanceflow) {
364
+
365
+                     $('#currentbalance').empty();
366
+                     $('#currentbalance').text(currentbalanceflow);
367
+                     $('#currentbalance').removeClass('icon-loading');
368
+                }
369
+            });
370
+          }
371
+
372
+          getflowbalance();
373
+
374
+       } else if (provider == "") {
375
+                $('#currentbalance').text("");
376
+                $('#currentbalance').removeClass('icon-loading');
377
+       }
378
+  });
379
+
380
+
381
+  // Refresh the list of Sender IDs
382
+  $("#refreshSenderIDs").on("click", function(event) {
383
+
384
+     $('#refreshSenderIDs').addClass('icon-loading');
385
+
386
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/refreshavailablenumbers");
387
+     var selectednmbr = null;
388
+
389
+     $.ajax({
390
+          url: getsmsnumbersUrl + '/' + userid,
391
+          type: "POST",
392
+          data: { userid: userid },
393
+          cache: false,
394
+          processData: false,
395
+          contentType: false,
396
+          success: function(smsnmbrs) {
397
+
398
+                    $('#currentsmsnmbrs').empty();
399
+                    $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
400
+
401
+                    $.each(smsnmbrs, function(key, indsmsnmb) {
402
+                           $('#currentsmsnmbrs').append("<option value='"+ indsmsnmb +"' class='optselectsmsnb'>"+ indsmsnmb +"</option>");
403
+                    });
404
+
405
+                    $('#refreshSenderIDs').removeClass('icon-loading');
406
+          }
407
+     });
408
+  });
409
+
410
+
411
+  // If a Sender ID is selected
412
+  $("#currentsmsnmbrs").on("change", function () {
413
+
414
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
415
+
416
+              selectedid = $('#currentsmsnmbrs :selected').val();
417
+              var setIdsplit = selectedid.split(":");
418
+	      chosenProvider = setIdsplit[0];
419
+
420
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
421
+	      if (chosenProvider == "Tx") {
422
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
423
+		  // Maximum size of message text + files in KB
424
+		  maximumsize = 1024;
425
+                  maximumsizeinit = 1024;
426
+		  maxsizenonimage = 600;
427
+		  maximumfilenumber = 10;
428
+                  chosenProvFullName = "Telnyx";
429
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
430
+                                     or gif files, the size of all the files plus the size of the text should be \
431
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
432
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
433
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
434
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
435
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
436
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
437
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
438
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
439
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
440
+                  $("#tooltiptextfourth").html(infonotecontent);
441
+	      } else if (chosenProvider == "Pl") {
442
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
443
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
444
+		  // Maximum size of message text + files in KB
445
+		  maximumsize = 5120;
446
+                  maximumsizeinit = 5120;
447
+		  maxsizenonimage = 600;
448
+		  maximumfilenumber = 10;
449
+                  chosenProvFullName = "Plivo";
450
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
451
+                                     or gif files, the size of all the files plus the size of the text should be \
452
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
453
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
454
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
455
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
456
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
457
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
458
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
459
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
460
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
461
+                  $("#tooltiptextfourth").html(infonotecontent);
462
+	      } else if (chosenProvider == "Tw") {
463
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
464
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
465
+                                     "icalendar", "directory", "pdf", "pkpass"];
466
+		  // Maximum size of message text + files in KB
467
+		  maximumsize = 5120;
468
+                  maximumsizeinit = 5120;
469
+		  maxsizenonimage = 600;
470
+		  maximumfilenumber = 10;
471
+                  chosenProvFullName = "Twilio";
472
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
473
+                                     or gif files, the size of all the files plus the size of the text should be \
474
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
475
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
476
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
477
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
478
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
479
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
480
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
481
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
482
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
483
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
484
+                                     previewed in the adjoining pane."
485
+                  $("#tooltiptextfourth").html(infonotecontent);
486
+	      } else if (chosenProvider == "Fl") {
487
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
488
+		  // Maximum size of message text + files in KB
489
+		  maximumsize = 750;
490
+                  maximumsizeinit = 750;
491
+		  maxsizenonimage = 600;
492
+		  maximumfilenumber = 10;
493
+                  chosenProvFullName = "Flowroute";
494
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
495
+                                     png or gif files, the size of all the files plus the size of the text should be \
496
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
497
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
498
+                                     size of the files plus the size of the text should be 600 KB or less. \
499
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
500
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
501
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
502
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
503
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
504
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
505
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
506
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
507
+                  $("#tooltiptextfourth").html(infonotecontent);
508
+	      }
509
+
510
+          } else { selectedid = ''; }
511
+  });
512
+
513
+  // Check the checkbox to send SMS message to multiple recipients
514
+  $('#tomultchckbx').change(function() {
515
+      if ($(this).is(':checked')) {
516
+          $("#multiplerecivers").css("display", "block");
517
+          $("#smstodiv").css("visibility", "hidden");
518
+          $("#smsto").val("");
519
+
520
+          receiversNumbers.length = 0;
521
+
522
+      } else {
523
+          $("#multiplerecivers").css("display", "none");
524
+          $("#smstodiv").css("visibility", "visible");
525
+
526
+          // Remove the uploaded files' names if any
527
+          $("#induploadfile").remove();
528
+
529
+          // Remove all the files from the SMS_Relentless/multiple_recipients directory
530
+          cleanMultRecDirectory();
531
+
532
+          $("#smstables").empty();
533
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
534
+
535
+          receiversNumbers.length = 0;
536
+      }
537
+  });
538
+
539
+  // Upload the file with the recipients' phone numbers
540
+  $("#uploadfileforsms").change(function(e) {
541
+
542
+     $("#fileuploadednm").empty();
543
+
544
+     receiversNumbers.length = 0;
545
+
546
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
547
+
548
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
549
+
550
+     var formData = new FormData();
551
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
552
+
553
+     var fileup = $('#uploadfileforsms').val();
554
+     var fileuptrim = fileup.split('\\').pop();
555
+
556
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
557
+
558
+     var extension = fileup.replace(/^.*\./, '');
559
+
560
+     if (extension == fileup) {
561
+         extension = "";
562
+     } else {
563
+         extension = extension.toLowerCase();
564
+     }
565
+
566
+     var validExtensionsmrec = ["txt", "csv"];
567
+
568
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
569
+
570
+       if (selectedid != '') {
571
+
572
+               $.ajax({
573
+                 url: baseUrl + '/' + userid,
574
+                 type: "POST",
575
+                 data: formData,
576
+                 cache: false,
577
+                 processData: false,
578
+                 contentType: false,
579
+                 success: function(numberarray) {
580
+
581
+		    if (numberarray.length > 0) {
582
+
583
+		        // Get the array of the receivers' phone numbers
584
+		        if (chosenProvider == "Tx") {
585
+
586
+		             for(key in numberarray) {
587
+		                 receiversNumbers.push("+"+numberarray[key]);
588
+		             }
589
+
590
+		        } else if (chosenProvider == "Pl") {
591
+
592
+		             for(key in numberarray) {
593
+		                 receiversNumbers.push(numberarray[key]);
594
+		             }
595
+
596
+		          } else if (chosenProvider == "Tw") {
597
+
598
+		             for(key in numberarray) {
599
+		                 receiversNumbers.push(numberarray[key]);
600
+		             }
601
+		          } else if (chosenProvider == "Fl") {
602
+
603
+		             for(key in numberarray) {
604
+		                 receiversNumbers.push(numberarray[key]);
605
+		             }
606
+		          }
607
+
608
+		    } else {
609
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
610
+		    }
611
+                            
612
+                    // Preview the uploaded file
613
+                    var smsfilename = e.target.files[0].name;
614
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
615
+
616
+                    var reader = new FileReader();
617
+                    reader.readAsText(e.target.files[0]);
618
+                    reader.onload = function(e) {
619
+                          $("#smstables").empty();
620
+                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
621
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
622
+                    };
623
+
624
+                    $("#smstables").show();
625
+
626
+                    $('#sms_upload_msg').hide();
627
+                    $('#smstables').removeClass('icon-loading');
628
+
629
+                  },
630
+                  error: function() {
631
+                             showAlert("Error while uploading the file.");
632
+                  }
633
+               });
634
+
635
+        } else {
636
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
637
+               $("#induploadfile").remove();
638
+               $('#sms_upload_msg').hide();
639
+               $('#smstables').removeClass('icon-loading');
640
+        }
641
+
642
+     } else {
643
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
644
+          $('#pf_upload_msg').hide();
645
+          $('#smstables').removeClass('icon-loading');
646
+
647
+          $("#induploadfile").remove();
648
+          $("#sms_upload_msg").hide();
649
+     }
650
+
651
+     // Preview uploaded file when clicked
652
+     $("#indfilediv").on("click", function() {
653
+
654
+          var smsfilename = e.target.files[0].name;
655
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
656
+
657
+          var reader = new FileReader();
658
+          reader.readAsText(e.target.files[0]);
659
+          reader.onload = function(e) {
660
+                  $("#smstables").empty();
661
+                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
662
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
663
+          };
664
+
665
+          $("#smstables").show();
666
+          $('#sms_upload_msg').hide();
667
+          $('#smstables').removeClass('icon-loading');
668
+     });
669
+
670
+     // Remove selected file
671
+     $("#indivflremove").on("click", function() {
672
+
673
+          $("#induploadfile").remove();
674
+          $("#sms_upload_msg").hide();
675
+
676
+          receiversNumbers.length = 0;
677
+
678
+          cleanMultRecDirectory();
679
+     });
680
+
681
+  });
682
+
683
+  // Show the number of characters entered in the SMS textarea and the text size in KB
684
+  $("#smstext").on('input', function() {
685
+
686
+     $("#char_count").css("display", "inline");
687
+
688
+     $("#mtextSize").css("display", "inline");
689
+
690
+     $(".maxmessagelength").css("display", "inline-block");
691
+
692
+     $("#countchnb").text($(this).val().length);
693
+
694
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
695
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
696
+     $("#textsizeinkb").text(textsizekb);
697
+
698
+     if ($(this).val().length > charcolorthr) {
699
+         $("#char_count").css("color", "#BB2E4B");
700
+     } else {
701
+         $("#char_count").css("color", "#4cbc86;");
702
+     }
703
+
704
+  });
705
+
706
+
707
+  // Check the checkbox to send file(s) as MMS
708
+  $('#mediafilechckbx').change(function() {
709
+
710
+      if ($(this).is(':checked')) {
711
+
712
+          isMMS = 1;
713
+          if (selectedid == '') {
714
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
715
+              $(this).prop("checked", false);
716
+              isMMS = 0;
717
+              return;
718
+          }
719
+          $("#upmediafiles").css("display", "block");
720
+          $("#submitsms").prop("value", "Send MMS");
721
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send MMS'.");
722
+
723
+      } else {
724
+
725
+          isMMS = 0;
726
+          $("#upmediafiles").css("display", "none");
727
+          $("#submitsms").prop("value", "Send SMS");
728
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send SMS'.");
729
+
730
+          // Remove the uploaded files' names if any
731
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
732
+          $(".indgenpckfls").each(function() { $(this).remove(); });
733
+
734
+          // Remove all the files from the SMS_Relentless/temp_files directory
735
+          cleanTempDirectory();
736
+
737
+          $("#smstables").empty();
738
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
739
+
740
+          uploadedtomms = [];
741
+          n = 1;
742
+
743
+          msgtotalflsize = 0;
744
+
745
+          $("#filestotsize").hide();
746
+      }
747
+  });
748
+
749
+
750
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
751
+  function adjustMaximumSize(uploadedtomms) {
752
+				      
753
+      var nonimgcheck = 0;
754
+      for (var u = 0; u < uploadedtomms.length; u++) {
755
+	   var crupfl = uploadedtomms[u];
756
+	   var extensionup = crupfl.replace(/^.*\./, '');
757
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
758
+	       nonimgcheck = 1;
759
+	   }
760
+      }
761
+
762
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
763
+  }
764
+
765
+  // Upload files to be sent as MMS
766
+  $("#uploadfileformms").change(function(e) {
767
+
768
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
769
+     $('#smstables').addClass('icon-loading');
770
+     $('#filestotsize').show();
771
+
772
+     var userid = "<?php p($userId); ?>";
773
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
774
+
775
+     var formData = new FormData();
776
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
777
+
778
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
779
+
780
+     // Add the size of the current file to the total size of all the files
781
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
782
+
783
+     var fileup = $('#uploadfileformms').val();
784
+     var fileuptrim = fileup.split('\\').pop();
785
+
786
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
787
+         var duplicatescheck = 1;
788
+     } else { 
789
+         var duplicatescheck = 0;
790
+     }
791
+
792
+     var extension = fileup.replace(/^.*\./, '');
793
+
794
+     if (extension == fileup) {
795
+         extension = "";
796
+     } else {
797
+         extension = extension.toLowerCase();
798
+     }
799
+
800
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
801
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
802
+         maximumsize = maxsizenonimage;
803
+     }
804
+
805
+     if ($.inArray(extension, validExtensions) != -1) {
806
+
807
+       if (duplicatescheck == 0) {
808
+
809
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
810
+
811
+            if (n <= maximumfilenumber) {
812
+
813
+               $.ajax({
814
+                 url: baseUrl + '/' + userid,
815
+                 type: "POST",
816
+                 data: formData,
817
+                 cache: false,
818
+                 processData: false,
819
+                 contentType: false,
820
+                 success: function(totalflsize) {
821
+
822
+                   uploadedtomms.push(fileuptrim);
823
+
824
+                   $('#filessizetext').text(totalflsize);
825
+
826
+                   var rectotfilesz = parseFloat(totalflsize);
827
+
828
+                   if (rectotfilesz <= maximumsize) {
829
+                       $('#submitsms').attr("disabled", false);
830
+                       $('#filestotsize').css('color', '#189558');
831
+                   } else {
832
+                       $('#filestotsize').css('color', '#ba3555');
833
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
834
+                       $('#submitsms').attr("disabled", true);
835
+                       $('#smstables').removeClass('icon-loading');
836
+                       $('#pf_upload_msg').hide();
837
+                   }
838
+
839
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
840
+                   n++;
841
+
842
+                   // Preview the file when you click on its name
843
+                   $("div:visible[id*='indfilediv']").each(function() {
844
+
845
+                        $(this).on("click", function(eventclck) {
846
+
847
+                           $("#mmsfoldersview").css("display", "inline-block");
848
+                           var mmsfilenameinit = $(this).text();
849
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
850
+                           var mmsfilename = mmsfilenamesec.replace("X","");
851
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
852
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
853
+
854
+                           if (extenlst == mmsfilename) {
855
+                               extenlst = "";
856
+                           } else {
857
+                               extenlst = extenlst.toLowerCase();
858
+                           }
859
+
860
+                           $("#smstables").empty();
861
+                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
862
+
863
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
864
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
865
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
866
+                           } else if (extenlst == 'png') {
867
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
868
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
869
+                           } else if (extenlst == 'gif') {
870
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
871
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
872
+                           } else if (extenlst == 'bmp') {
873
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
874
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
875
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
876
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
877
+                                  var xhr = new XMLHttpRequest();
878
+                                  xhr.responseType = 'arraybuffer';
879
+                                  xhr.open('GET', tiffile);
880
+                                  xhr.onload = function (evnt) {
881
+                                      var tiff = new Tiff({buffer: xhr.response});
882
+                                      var tifcanvas = tiff.toCanvas();
883
+                                      $("#smstables").append(tifcanvas);
884
+                                  };
885
+                                  xhr.send();
886
+                           } else if (extenlst == 'pdf') {
887
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
888
+                                  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>');
889
+                                  $("#smstables").append($iframe);
890
+                           } else if (extenlst == 'txt') {
891
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
892
+                           } else if (extension == 'mp4') {
893
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
894
+		           } else if (extension == 'ogg') {
895
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
896
+		           } else if (extension == 'avi') {
897
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
898
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
899
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
900
+		           } else if (extension == 'wav' || extension == 'wave') {
901
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
902
+		           } else if (extension == 'mp3') {
903
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
904
+		           } else if (extension == 'midi') {
905
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
906
+		           }
907
+
908
+                           $("#smstables").show();
909
+                           $("#mmsfoldersview").hide();
910
+                        });
911
+                   });
912
+
913
+                   // Remove uploaded files
914
+                   $('[class*="indupfldl"]').last().click(function() {
915
+
916
+                           var userid = "<?php p($userId); ?>";
917
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
918
+
919
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
920
+
921
+                           var removedfilesplit = removedfilenameinit.split(") ");
922
+                           var removedflnb = parseInt(removedfilesplit[0]);
923
+
924
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
925
+                           $(this).hide();
926
+
927
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
928
+
929
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
930
+                                           return value != removedfilename;
931
+                           });
932
+
933
+                           $.ajax({
934
+                                   url: baseUrl + '/' + userid,
935
+                                   type: "POST",
936
+                                   data: {removedfilename: removedfilename},
937
+                                   success: function(totalflsize) {
938
+
939
+                                      msgtotalflsize = totalflsize;
940
+                                      $('#filessizetext').text(totalflsize);
941
+
942
+                                      adjustMaximumSize(uploadedtomms);
943
+
944
+                                      // Check message size
945
+                                      var rectotfilesz = parseFloat(totalflsize);
946
+
947
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
948
+                                          $('#submitsms').attr("disabled", false);
949
+                                          $('#filestotsize').css('color', '#189558');
950
+                                      } else {
951
+                                          $('#filestotsize').css('color', '#ba3555');
952
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
953
+                                          $('#submitsms').attr("disabled", true);
954
+                                      }
955
+
956
+                                      // Rewrite order numbers for files that follow
957
+                                      --n;
958
+                                      $("div:visible[id*='indfilediv']").each(function() {
959
+
960
+                                          var getdivtext =  $(this).text();
961
+                                          var splitdivtext = getdivtext.split(") ");
962
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
963
+                                          var newnbvalue = currentnbvalue - 1;
964
+
965
+                                          if (currentnbvalue > removedflnb) {
966
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
967
+                                              $(this).text(replacedstr);
968
+                                          }
969
+                                      });
970
+
971
+                                      $("div:visible[id*='indflpicked']").each(function() {
972
+
973
+                                          var getdivtext =  $(this).text();
974
+                                          var splitdivtext = getdivtext.split(") ");
975
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
976
+                                          var newnbvalue = currentnbvalue - 1;
977
+
978
+                                          if (currentnbvalue > removedflnb) {
979
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
980
+                                              $(this).text(replacedstr);
981
+                                          }
982
+                                      });
983
+
984
+                                   },
985
+                                   error: function() {
986
+                                              showAlert("Error while removing the file(s).");
987
+                                   }
988
+                           });
989
+
990
+                           $('#smstables').removeClass('icon-loading');
991
+                           $("#smstables").empty();
992
+                   });
993
+
994
+                   // Preview the uploaded file
995
+                   $("#mmsfoldersview").css("display", "inline-block");
996
+                   var mmsfilename = e.target.files[0].name;
997
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
998
+
999
+                   $("#smstables").empty();
1000
+                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1001
+
1002
+                   if (extension == 'jpg' || extension == 'jpeg') {
1003
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
1004
+
1005
+                              var reader = new FileReader();
1006
+                              reader.onload = function (e) {
1007
+                                  readjpg[mmsfilename] = e.target.result;
1008
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
1009
+                              }
1010
+                              reader.readAsDataURL(e.target.files[0]);
1011
+                   } else if (extension == 'png') {
1012
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
1013
+
1014
+                              var reader = new FileReader();
1015
+                              reader.onload = function (e) {
1016
+                                  readpng[mmsfilename] = e.target.result;
1017
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
1018
+                              }
1019
+                              reader.readAsDataURL(e.target.files[0]);
1020
+
1021
+                   } else if (extension == 'gif') {
1022
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
1023
+
1024
+                              var reader = new FileReader();
1025
+                              reader.onload = function (e) {
1026
+                                  readgif[mmsfilename] = e.target.result;
1027
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
1028
+                              }
1029
+                              reader.readAsDataURL(e.target.files[0]);
1030
+
1031
+                   } else if (extension == 'bmp') {
1032
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1033
+
1034
+                              var reader = new FileReader();
1035
+                              reader.onload = function (e) {
1036
+                                  readbmp[mmsfilename] = e.target.result;
1037
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1038
+                              }
1039
+                              reader.readAsDataURL(e.target.files[0]);
1040
+
1041
+                   } else if (extension == 'tif' || extension == 'tiff') {
1042
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1043
+                              var xhr = new XMLHttpRequest();
1044
+                              xhr.responseType = 'arraybuffer';
1045
+                              xhr.open('GET', tiffile);
1046
+                              xhr.onload = function (e) {
1047
+                                  var tiff = new Tiff({buffer: xhr.response});
1048
+                                  var tifcanvas = tiff.toCanvas();
1049
+                                  $("#smstables").append(tifcanvas);
1050
+                              };
1051
+                              xhr.send();
1052
+
1053
+                   } else if (extension == 'pdf') {
1054
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1055
+                              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>');
1056
+                              $("#smstables").append($iframe);
1057
+
1058
+                   } else if (extension == 'txt') {
1059
+                              var reader = new FileReader();
1060
+                              reader.readAsText(e.target.files[0]);
1061
+                              reader.onload = function(e) {
1062
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1063
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1064
+                              };
1065
+                   } else if (extension == 'mp4') {
1066
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1067
+                   } else if (extension == 'ogg') {
1068
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1069
+                   } else if (extension == 'avi') {
1070
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1071
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1072
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1073
+                   } else if (extension == 'wav' || extension == 'wave') {
1074
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1075
+                   } else if (extension == 'mp3') {
1076
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1077
+                   } else if (extension == 'midi') {
1078
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1079
+                   }
1080
+
1081
+                   $("#smstables").show();
1082
+                   $('#pf_upload_msg').hide();
1083
+                   $('#smstables').removeClass('icon-loading');
1084
+                   $("#mmsfoldersview").hide();
1085
+                 },
1086
+                 error: function() {
1087
+                              showAlert("Error while uploading the file.");
1088
+                 }
1089
+               });
1090
+
1091
+            } else {
1092
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1093
+                  adjustMaximumSize(uploadedtomms);
1094
+
1095
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1096
+                  $('#pf_upload_msg').hide();
1097
+                  $('#smstables').removeClass('icon-loading');
1098
+            }
1099
+         } else {
1100
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1101
+              adjustMaximumSize(uploadedtomms);
1102
+
1103
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1104
+              $('#pf_upload_msg').hide();
1105
+              $('#smstables').removeClass('icon-loading');
1106
+         }
1107
+       } else {
1108
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1109
+            adjustMaximumSize(uploadedtomms);
1110
+
1111
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1112
+            $('#pf_upload_msg').hide();
1113
+            $('#smstables').removeClass('icon-loading');
1114
+       }
1115
+
1116
+     } else {
1117
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1118
+          adjustMaximumSize(uploadedtomms);
1119
+
1120
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1121
+          $('#pf_upload_msg').hide();
1122
+          $('#smstables').removeClass('icon-loading');
1123
+     }
1124
+  });
1125
+
1126
+
1127
+  // Pick file(s) from Nextcloud, to send as MMS
1128
+  var mmsfilename = null;
1129
+
1130
+  $("#choosefilen").on("click", function(evn) {
1131
+
1132
+                OC.dialogs.filepicker(
1133
+                        t('settings', "Select a file to send as MMS."),
1134
+                        function (path) {
1135
+
1136
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1137
+                              $('#smstables').addClass('icon-loading');
1138
+                              $('#filestotsize').show();
1139
+
1140
+                              var userid = "<?php p($userId); ?>";
1141
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1142
+
1143
+                              mmsfilename = path.split('/').pop();
1144
+
1145
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1146
+                                  var duplicatescheck = 1;
1147
+                              } else var duplicatescheck = 0;
1148
+
1149
+                              var extension = mmsfilename.replace(/^.*\./, '');
1150
+
1151
+                              if (extension == mmsfilename) {
1152
+                                  extension = "";
1153
+                              } else {
1154
+                                  extension = extension.toLowerCase();
1155
+                              }
1156
+
1157
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1158
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1159
+				   maximumsize = maxsizenonimage;
1160
+			      }
1161
+
1162
+                              if ($.inArray(extension, validExtensions) != -1) {
1163
+
1164
+                                 if (duplicatescheck == 0) {
1165
+
1166
+                                    if (n <= maximumfilenumber) {
1167
+
1168
+                                       $.ajax({
1169
+                                          url: baseUrl + '/' + userid,
1170
+                                          type: "POST",
1171
+                                          data: { path: path },
1172
+                                          success: function(pickresult) {
1173
+
1174
+                                                uploadedtomms.push(mmsfilename);
1175
+
1176
+                                                var totalflsize = pickresult[0];
1177
+                                                var pickedflsize = pickresult[1];
1178
+
1179
+                                                // Check message size
1180
+                                                var rectotfilesz = parseFloat(totalflsize);
1181
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1182
+
1183
+                                                if (filesplustextsize <= maximumsize) {
1184
+
1185
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1186
+
1187
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1188
+                                                    n++;
1189
+
1190
+                                                    msgtotalflsize = totalflsize;
1191
+                                                    $('#filessizetext').text(totalflsize);
1192
+                                                    $('#filestotsize').css('color', '#189558');
1193
+
1194
+                                                } else {
1195
+
1196
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1197
+                                                    $('#filestotsize').css('color', '#ba3555');
1198
+                                                    msgtotalflsize -= pickedflsize;
1199
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1200
+
1201
+                                                    $.ajax({
1202
+                                                        url: baseUrlindrm + '/' + userid,
1203
+                                                        type: "POST",
1204
+                                                        data: {removedfilename: mmsfilename},
1205
+                                                        success: function(totalflsize) {
1206
+
1207
+                                                                          $('#filessizetext').text(totalflsize);
1208
+                                                                          $('#filestotsize').css('color', '#189558');
1209
+                                                                          adjustMaximumSize(uploadedtomms);
1210
+
1211
+                                                        },
1212
+                                                        error: function(totalflsize) {
1213
+                                                                          $('#filessizetext').text(totalflsize);
1214
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1215
+                                                                              $('#filestotsize').css('color', '#ba3555');
1216
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1217
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1218
+                                                        }
1219
+                                                    });
1220
+
1221
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1222
+                                                }
1223
+
1224
+
1225
+                                                // Preview each file when you click on its name
1226
+                                                $("div:visible[id*='indflpicked']").each(function() {
1227
+                                                   $(this).on("click", function(event) {
1228
+
1229
+                                                      var mmsfilenameinit = $(this).text();
1230
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1231
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1232
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1233
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1234
+
1235
+                                                      if (extenlst == mmsfilenamesp) {
1236
+                                                           extenlst = "";
1237
+                                                      } else {
1238
+                                                           extenlst = extenlst.toLowerCase();
1239
+                                                      }
1240
+
1241
+                                                      $("#smstables").empty();
1242
+                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1243
+
1244
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1245
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1246
+                                                      } else if (extenlst == 'png') {
1247
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1248
+                                                      } else if (extenlst == 'gif') {
1249
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1250
+                                                      } else if (extenlst == 'bmp') {
1251
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1252
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1253
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1254
+                                                              var xhr = new XMLHttpRequest();
1255
+                                                              xhr.responseType = 'arraybuffer';
1256
+                                                              xhr.open('GET', tiffile);
1257
+                                                              xhr.onload = function (evnt) {
1258
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1259
+                                                                  var tifcanvas = tiff.toCanvas();
1260
+                                                                  $("#smstables").append(tifcanvas);
1261
+                                                              };
1262
+                                                              xhr.send();
1263
+                                                      } else if (extenlst == 'pdf') {
1264
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1265
+                                                              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>');
1266
+                                                              $("#smstables").append($iframe);
1267
+                                                      } else if (extenlst == 'txt') {
1268
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1269
+                                                      } else if (extension == 'mp4') {
1270
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1271
+						      } else if (extension == 'ogg') {
1272
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1273
+						      } else if (extension == 'avi') {
1274
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1275
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1276
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1277
+						      } else if (extension == 'wav' || extension == 'wave') {
1278
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1279
+						      } else if (extension == 'mp3') {
1280
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1281
+						      } else if (extension == 'midi') {
1282
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1283
+						      }
1284
+
1285
+                                                      $("#smstables").show();
1286
+                                                      $("#mmsfoldersview").hide();
1287
+                                                   });
1288
+                                                });
1289
+
1290
+
1291
+                                                // Remove picked files
1292
+                                                $('[class*="indpckfldl"]').last().click(function() {
1293
+                                                    var userid = "<?php p($userId); ?>";
1294
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1295
+
1296
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1297
+
1298
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1299
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1300
+
1301
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1302
+                                                    $(this).hide();
1303
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1304
+
1305
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1306
+                                                             return value != removedfilename;
1307
+                                                    });
1308
+
1309
+                                                    $.ajax({
1310
+                                                        url: baseUrl + '/' + userid,
1311
+                                                        type: "POST",
1312
+                                                        data: {removedfilename: removedfilename},
1313
+                                                        success: function(totalflsize) {
1314
+
1315
+                                                             msgtotalflsize = totalflsize;
1316
+                                                             $('#filessizetext').text(totalflsize);
1317
+                                                             adjustMaximumSize(uploadedtomms);
1318
+
1319
+                                                             // Check message size
1320
+                                                             var rectotfilesz = parseFloat(totalflsize);
1321
+
1322
+                                                             if (rectotfilesz > maximumsize) {
1323
+                                                                 $('#filestotsize').css('color', '#ba3555');
1324
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1325
+                                                                 $('#submitsms').attr("disabled", true);
1326
+                                                             } else {
1327
+                                                                 $('#submitsms').attr("disabled", false);
1328
+                                                                 $('#filestotsize').css('color', '#189558');
1329
+                                                               }
1330
+
1331
+                                                             // Rewrite order numbers for files that follow
1332
+                                                             --n;
1333
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1334
+
1335
+                                                                  var getdivtext =  $(this).text();
1336
+                                                                  var splitdivtext = getdivtext.split(") ");
1337
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1338
+                                                                  var newnbvalue = currentnbvalue - 1;
1339
+
1340
+                                                                  if (currentnbvalue > removedflnb) {
1341
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1342
+                                                                      $(this).text(replacedstr);
1343
+                                                                  }
1344
+                                                             });
1345
+                                                        },
1346
+                                                        error: function() {
1347
+                                                                  showAlert("Error while removing the file.");
1348
+                                                        }
1349
+                                                    });
1350
+
1351
+                                                    $('#smstables').removeClass('icon-loading');
1352
+                                                    $("#smstables").empty();
1353
+                                                });
1354
+
1355
+
1356
+		                                // Preview the picked file
1357
+		                                $("#mmsfoldersview").css("display", "inline-block");
1358
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1359
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1360
+
1361
+                                                $("#smstables").empty();
1362
+                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1363
+
1364
+						if (extension == 'jpg' || extension == 'jpeg') {
1365
+
1366
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1367
+
1368
+		                                } else if (extension == 'png') {
1369
+
1370
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1371
+
1372
+		                                } else if (extension == 'gif') {
1373
+
1374
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1375
+
1376
+		                                } else if (extension == 'bmp') {
1377
+
1378
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1379
+
1380
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1381
+
1382
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1383
+		                                       var xhr = new XMLHttpRequest();
1384
+		                                       xhr.responseType = 'arraybuffer';
1385
+		                                       xhr.open('GET', tiffile);
1386
+		                                       xhr.onload = function (event) {
1387
+		                                           var tiff = new Tiff({buffer: xhr.response});
1388
+		                                           var tifcanvas = tiff.toCanvas();
1389
+		                                           $("#smstables").append(tifcanvas);
1390
+		                                       };
1391
+		                                       xhr.send();
1392
+
1393
+		                                } else if (extension == 'pdf') {
1394
+
1395
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1396
+		                                       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>');
1397
+		                                       $("#smstables").append($iframe);
1398
+
1399
+		                                } else if (extension == 'txt') {
1400
+
1401
+							     $.get(flUrl, function(textdata) {
1402
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1403
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1404
+							     });
1405
+
1406
+		                                } else if (extension == 'mp4') {
1407
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1408
+						} else if (extension == 'ogg') {
1409
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1410
+						} else if (extension == 'avi') {
1411
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1412
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1413
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1414
+						} else if (extension == 'wav' || extension == 'wave') {
1415
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1416
+						} else if (extension == 'mp3') {
1417
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1418
+						} else if (extension == 'midi') {
1419
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1420
+						}
1421
+
1422
+
1423
+		                                $("#smstables").show();
1424
+
1425
+		                                $('#pf_choose_msg').hide();
1426
+		                                $('#smstables').removeClass('icon-loading');
1427
+		                                $("#mmsfoldersview").hide();
1428
+
1429
+                                          },
1430
+
1431
+                                          error: function(data){
1432
+                                                      showAlert("Error while getting the file.");
1433
+                                          }
1434
+
1435
+                                       });
1436
+
1437
+                                    } else {
1438
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1439
+                                        $('#pf_choose_msg').hide();
1440
+                                        $('#smstables').removeClass('icon-loading');
1441
+                                      }
1442
+                                 } else {
1443
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1444
+                                      $('#pf_choose_msg').hide();
1445
+                                      $('#smstables').removeClass('icon-loading');
1446
+                                   }
1447
+
1448
+                              } else {
1449
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1450
+                                   $('#pf_choose_msg').hide();
1451
+                                   $('#smstables').removeClass('icon-loading');
1452
+                                }
1453
+
1454
+                        }
1455
+                );
1456
+  });
1457
+
1458
+
1459
+
1460
+  // Send the SMS/MMS message
1461
+  $("#submitsms").on("click", function(event) {
1462
+
1463
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1464
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1465
+     $("#sms_submit_msg").css("display", "inline-block");
1466
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1467
+
1468
+     if (selectedid != '') { 
1469
+
1470
+         var sendersplit = selectedid.split(":");
1471
+         var providercap = sendersplit[0];
1472
+         var provsec = sendersplit[1];
1473
+
1474
+         if (/[a-zA-Z]/.test(provsec)) {
1475
+             var alphanumcheck = true;
1476
+         } else { var alphanumcheck = false; }
1477
+
1478
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1479
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1480
+             var selectedsender = "+" + senderproc;
1481
+             var providerUsed = "telnyx";
1482
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1483
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1484
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1485
+             var providerUsed = "plivo";
1486
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1487
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1488
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1489
+             var selectedsender = "+" + senderproc;
1490
+             var providerUsed = "twilio";
1491
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1492
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1493
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1494
+             var selectedsender = "+" + senderproc;
1495
+             var providerUsed = "flowroute";
1496
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1497
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1498
+             var selectedsender = provsec;
1499
+             var providerUsed = "telnyx";
1500
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1501
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1502
+             var selectedsender = provsec;
1503
+             var providerUsed = "plivo";
1504
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1505
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1506
+             var selectedsender = provsec;
1507
+             var providerUsed = "twilio";
1508
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1509
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1510
+             var selectedsender = provsec;
1511
+             var providerUsed = "flowroute";
1512
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1513
+         }
1514
+
1515
+         // Get the interval between message consecutive sending requests, if it's the case
1516
+         if ($('#tomultchckbx').is(':checked')) {
1517
+
1518
+             var numbersfile = 1;
1519
+             var initinterval = $("#multsmsinterval").val();
1520
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1521
+
1522
+             if (secinterval != '') {
1523
+                 var tertinterval = parseInt(secinterval);
1524
+                     waittime = tertinterval;
1525
+             }
1526
+
1527
+         } else {
1528
+
1529
+             var numbersfile = 0;
1530
+             var toNumberinit = $('#smsto').val();
1531
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1532
+             var toNumbersec = toNumber.split(",");
1533
+
1534
+                 for (var i = 0; i < toNumbersec.length; i++) {
1535
+                      toNumbersec[i] = "+" + toNumbersec[i];
1536
+                 }
1537
+
1538
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1539
+         }
1540
+
1541
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1542
+
1543
+         var smstext = $("#smstext").val();
1544
+
1545
+         if (receiversNumbers.length != 0) {
1546
+
1547
+              if (smstext != '') {
1548
+                  $.ajax({
1549
+                     url: relbaseUrl + '/' + userid,
1550
+                     type: "POST",
1551
+                     data: {
1552
+                           receiversPhoneNbs: receiversNumbers,
1553
+                           fromsender: selectedsender,
1554
+                           waitinterval: waittime,
1555
+                           sentsmstext: smstext,
1556
+                           ismms: isMMS,
1557
+                           mmsfiles: uploadedtomms
1558
+                         },
1559
+                     success: function() {
1560
+
1561
+                           if (receiversNumbers.length == 1) {
1562
+                                   showAlert("The message has been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1563
+                           } else {
1564
+                                   showAlert("The messages have been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1565
+                           }
1566
+
1567
+                           $('#sms_submit_msg').hide();
1568
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
+                     },
1570
+                     error: function() {
1571
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1572
+                           $('#sms_submit_msg').hide();
1573
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1574
+                     }
1575
+                  });
1576
+              } else {
1577
+                     showAlert("Please enter a message in the text box !");
1578
+
1579
+                     $('#sms_submit_msg').hide();
1580
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1581
+              }
1582
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1583
+                 showAlert("Please enter the recipient's phone number !");
1584
+                 $('#sms_submit_msg').hide();
1585
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1586
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1587
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1588
+                 $('#sms_submit_msg').hide();
1589
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1590
+         }
1591
+     } else {
1592
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1593
+           $("#induploadfile").remove();
1594
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1595
+           $('#sms_submit_msg').hide();
1596
+     }
1597
+
1598
+  });
1599
+
1600
+  // Check the checkbox to delete old messages from the database
1601
+  $('#deleteoldchckbox').change(function() {
1602
+     if ($(this).is(':checked')) {
1603
+         $("#deleteoldsms").css("display", "block");
1604
+     } else {
1605
+         $("#deleteoldsms").css("display", "none");
1606
+     }
1607
+  });
1608
+
1609
+  // Set the height of info notes
1610
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1611
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1612
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1613
+
1614
+  $(window).resize(function() { 
1615
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1616
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1617
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1618
+  });
1619
+
1620
+
1621
+  function showAlert(alertText) {
1622
+
1623
+     $("#alertMsgOverlay").remove();
1624
+     $("#alertMessage").remove();
1625
+
1626
+     let alertwnd = "<div id='alertMessage'>";
1627
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1628
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1629
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1630
+     alertwnd += "</div>";
1631
+
1632
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1633
+     $("#content").append(alertwnd);
1634
+
1635
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1636
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1637
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1638
+
1639
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1640
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1641
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1642
+  }
Browse code

removed appinfo/info.xml appinfo/signature.json appinfo/routes.php CHANGELOG.txt README.md css/style.css js/settings.js js/sendsms.js js/adminsettings.js js/showsmstables.js templates/settings/admin.php templates/settings/personal.php templates/navigation/index.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php l10n/en_GB.js l10n/en_GB.json l10n/en_US.js l10n/en_US.json

DoubleBastionAdmin authored on 14/02/2024 22:37:16
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1612 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  function cleanTempDirectory() {
235
-
236
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
-
238
-     $.ajax({
239
-          url: cleanflUrl + '/' + userid,
240
-          type: "POST",
241
-          data: { userid: userid },
242
-          cache: false,
243
-          processData: false,
244
-          contentType: false
245
-     });
246
-  }
247
-  cleanTempDirectory();
248
-
249
-  // Clean the SMS_Relentless/multiple_recipients directory
250
-  function cleanMultRecDirectory() {
251
-
252
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
-
254
-     $.ajax({
255
-          url: cleanflUrl + '/' + userid,
256
-          type: "POST",
257
-          data: { userid: userid },
258
-          cache: false,
259
-          processData: false,
260
-          contentType: false
261
-     });
262
-  }
263
-  cleanMultRecDirectory();
264
-
265
-  // Check the available balance
266
-  $("#smsprovider").on("change", function () {
267
-
268
-     var provider = $('#smsprovider :selected').val();
269
-
270
-     if (provider == "Telnyx") {
271
-
272
-        var gettelbalance = function() {
273
-
274
-          $('#currentbalance').addClass('icon-loading');
275
-
276
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
-
278
-          $.ajax({
279
-              url: gettelbalanceUrl + '/' + userid,
280
-              type: "POST",
281
-              data: { userid: userid },
282
-              cache: false,
283
-              processData: false,
284
-              contentType: false,
285
-              success: function(currentbalancetel) {
286
-
287
-                     $('#currentbalance').empty();
288
-                     $('#currentbalance').text(currentbalancetel);
289
-                     $('#currentbalance').removeClass('icon-loading');
290
-              }
291
-          });
292
-        }
293
-
294
-        gettelbalance();
295
-
296
-     } else if (provider == "Plivo") {
297
-
298
-          var getnexbalance = function() {
299
-
300
-            $('#currentbalance').addClass('icon-loading');
301
-
302
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
-
304
-            $.ajax({
305
-                url: getnexbalanceUrl + '/' + userid,
306
-                type: "POST",
307
-                data: { userid: userid },
308
-                cache: false,
309
-                processData: false,
310
-                contentType: false,
311
-                success: function(currentbalancenex) {
312
-
313
-                     $('#currentbalance').empty();
314
-                     $('#currentbalance').text(currentbalancenex);
315
-                     $('#currentbalance').removeClass('icon-loading');
316
-                }
317
-            });
318
-          }
319
-
320
-          getnexbalance();
321
-
322
-     } else if (provider == "Twilio") {
323
-
324
-          var gettwilbalance = function() {
325
-
326
-            $('#currentbalance').addClass('icon-loading');
327
-
328
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
-
330
-            $.ajax({
331
-                url: gettwilbalanceUrl + '/' + userid,
332
-                type: "POST",
333
-                data: { userid: userid },
334
-                cache: false,
335
-                processData: false,
336
-                contentType: false,
337
-                success: function(currentbalancetwil) {
338
-
339
-                     $('#currentbalance').empty();
340
-                     $('#currentbalance').text(currentbalancetwil);
341
-                     $('#currentbalance').removeClass('icon-loading');
342
-                }
343
-            });
344
-          }
345
-
346
-          gettwilbalance();
347
-
348
-     } else if (provider == "Flowroute") {
349
-
350
-          var getflowbalance = function() {
351
-
352
-            $('#currentbalance').addClass('icon-loading');
353
-
354
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
-
356
-            $.ajax({
357
-                url: getflowbalanceUrl + '/' + userid,
358
-                type: "POST",
359
-                data: { userid: userid },
360
-                cache: false,
361
-                processData: false,
362
-                contentType: false,
363
-                success: function(currentbalanceflow) {
364
-
365
-                     $('#currentbalance').empty();
366
-                     $('#currentbalance').text(currentbalanceflow);
367
-                     $('#currentbalance').removeClass('icon-loading');
368
-                }
369
-            });
370
-          }
371
-
372
-          getflowbalance();
373
-
374
-       } else if (provider == "") {
375
-                $('#currentbalance').text("");
376
-                $('#currentbalance').removeClass('icon-loading');
377
-       }
378
-  });
379
-
380
-
381
-  // If a Sender ID is selected
382
-  $("#currentsmsnmbrs").on("change", function () {
383
-
384
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
-
386
-              selectedid = $('#currentsmsnmbrs :selected').val();
387
-              var setIdsplit = selectedid.split(":");
388
-	      chosenProvider = setIdsplit[0];
389
-
390
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
391
-	      if (chosenProvider == "Tx") {
392
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
393
-		  // Maximum size of message text + files in KB
394
-		  maximumsize = 1024;
395
-                  maximumsizeinit = 1024;
396
-		  maxsizenonimage = 600;
397
-		  maximumfilenumber = 10;
398
-                  chosenProvFullName = "Telnyx";
399
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
400
-                                     or gif files, the size of all the files plus the size of the text should be \
401
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
402
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
403
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
404
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
405
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
406
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
407
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
408
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
409
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
410
-                  $("#tooltiptextfourth").html(infonotecontent);
411
-	      } else if (chosenProvider == "Pl") {
412
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
413
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
414
-		  // Maximum size of message text + files in KB
415
-		  maximumsize = 5120;
416
-                  maximumsizeinit = 5120;
417
-		  maxsizenonimage = 600;
418
-		  maximumfilenumber = 10;
419
-                  chosenProvFullName = "Plivo";
420
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
421
-                                     or gif files, the size of all the files plus the size of the text should be \
422
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
423
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
424
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
425
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
426
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
427
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
428
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
429
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
430
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
431
-                  $("#tooltiptextfourth").html(infonotecontent);
432
-	      } else if (chosenProvider == "Tw") {
433
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
434
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
435
-                                     "icalendar", "directory", "pdf", "pkpass"];
436
-		  // Maximum size of message text + files in KB
437
-		  maximumsize = 5120;
438
-                  maximumsizeinit = 5120;
439
-		  maxsizenonimage = 600;
440
-		  maximumfilenumber = 10;
441
-                  chosenProvFullName = "Twilio";
442
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
443
-                                     or gif files, the size of all the files plus the size of the text should be \
444
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
445
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
446
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
447
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
448
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
449
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
450
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
451
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
452
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
453
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
454
-                                     previewed in the adjoining pane."
455
-                  $("#tooltiptextfourth").html(infonotecontent);
456
-	      } else if (chosenProvider == "Fl") {
457
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
458
-		  // Maximum size of message text + files in KB
459
-		  maximumsize = 750;
460
-                  maximumsizeinit = 750;
461
-		  maxsizenonimage = 600;
462
-		  maximumfilenumber = 10;
463
-                  chosenProvFullName = "Flowroute";
464
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
465
-                                     png or gif files, the size of all the files plus the size of the text should be \
466
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
467
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
468
-                                     size of the files plus the size of the text should be 600 KB or less. \
469
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
470
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
471
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
472
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
473
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
474
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
475
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
476
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
477
-                  $("#tooltiptextfourth").html(infonotecontent);
478
-	      }
479
-
480
-          } else { selectedid = ''; }
481
-  });
482
-
483
-  // Check the checkbox to send SMS message to multiple recipients
484
-  $('#tomultchckbx').change(function() {
485
-      if ($(this).is(':checked')) {
486
-          $("#multiplerecivers").css("display", "block");
487
-          $("#smstodiv").css("visibility", "hidden");
488
-          $("#smsto").val("");
489
-
490
-          receiversNumbers.length = 0;
491
-
492
-      } else {
493
-          $("#multiplerecivers").css("display", "none");
494
-          $("#smstodiv").css("visibility", "visible");
495
-
496
-          // Remove the uploaded files' names if any
497
-          $("#induploadfile").remove();
498
-
499
-          // Remove all the files from the SMS_Relentless/multiple_recipients directory
500
-          cleanMultRecDirectory();
501
-
502
-          $("#smstables").empty();
503
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
504
-
505
-          receiversNumbers.length = 0;
506
-      }
507
-  });
508
-
509
-  // Upload the file with the recipients' phone numbers
510
-  $("#uploadfileforsms").change(function(e) {
511
-
512
-     $("#fileuploadednm").empty();
513
-
514
-     receiversNumbers.length = 0;
515
-
516
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
517
-
518
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
519
-
520
-     var formData = new FormData();
521
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
522
-
523
-     var fileup = $('#uploadfileforsms').val();
524
-     var fileuptrim = fileup.split('\\').pop();
525
-
526
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
527
-
528
-     var extension = fileup.replace(/^.*\./, '');
529
-
530
-     if (extension == fileup) {
531
-         extension = "";
532
-     } else {
533
-         extension = extension.toLowerCase();
534
-     }
535
-
536
-     var validExtensionsmrec = ["txt", "csv"];
537
-
538
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
539
-
540
-       if (selectedid != '') {
541
-
542
-               $.ajax({
543
-                 url: baseUrl + '/' + userid,
544
-                 type: "POST",
545
-                 data: formData,
546
-                 cache: false,
547
-                 processData: false,
548
-                 contentType: false,
549
-                 success: function(numberarray) {
550
-
551
-		    if (numberarray.length > 0) {
552
-
553
-		        // Get the array of the receivers' phone numbers
554
-		        if (chosenProvider == "Tx") {
555
-
556
-		             for(key in numberarray) {
557
-		                 receiversNumbers.push("+"+numberarray[key]);
558
-		             }
559
-
560
-		        } else if (chosenProvider == "Pl") {
561
-
562
-		             for(key in numberarray) {
563
-		                 receiversNumbers.push(numberarray[key]);
564
-		             }
565
-
566
-		          } else if (chosenProvider == "Tw") {
567
-
568
-		             for(key in numberarray) {
569
-		                 receiversNumbers.push(numberarray[key]);
570
-		             }
571
-		          } else if (chosenProvider == "Fl") {
572
-
573
-		             for(key in numberarray) {
574
-		                 receiversNumbers.push(numberarray[key]);
575
-		             }
576
-		          }
577
-
578
-		    } else {
579
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
580
-		    }
581
-                            
582
-                    // Preview the uploaded file
583
-                    var smsfilename = e.target.files[0].name;
584
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
585
-
586
-                    var reader = new FileReader();
587
-                    reader.readAsText(e.target.files[0]);
588
-                    reader.onload = function(e) {
589
-                          $("#smstables").empty();
590
-                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
591
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
592
-                    };
593
-
594
-                    $("#smstables").show();
595
-
596
-                    $('#sms_upload_msg').hide();
597
-                    $('#smstables').removeClass('icon-loading');
598
-
599
-                  },
600
-                  error: function() {
601
-                             showAlert("Error while uploading the file.");
602
-                  }
603
-               });
604
-
605
-        } else {
606
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
607
-               $("#induploadfile").remove();
608
-               $('#sms_upload_msg').hide();
609
-               $('#smstables').removeClass('icon-loading');
610
-        }
611
-
612
-     } else {
613
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
614
-          $('#pf_upload_msg').hide();
615
-          $('#smstables').removeClass('icon-loading');
616
-
617
-          $("#induploadfile").remove();
618
-          $("#sms_upload_msg").hide();
619
-     }
620
-
621
-     // Preview uploaded file when clicked
622
-     $("#indfilediv").on("click", function() {
623
-
624
-          var smsfilename = e.target.files[0].name;
625
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
626
-
627
-          var reader = new FileReader();
628
-          reader.readAsText(e.target.files[0]);
629
-          reader.onload = function(e) {
630
-                  $("#smstables").empty();
631
-                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
632
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
633
-          };
634
-
635
-          $("#smstables").show();
636
-          $('#sms_upload_msg').hide();
637
-          $('#smstables').removeClass('icon-loading');
638
-     });
639
-
640
-     // Remove selected file
641
-     $("#indivflremove").on("click", function() {
642
-
643
-          $("#induploadfile").remove();
644
-          $("#sms_upload_msg").hide();
645
-
646
-          receiversNumbers.length = 0;
647
-
648
-          cleanMultRecDirectory();
649
-     });
650
-
651
-  });
652
-
653
-  // Show the number of characters entered in the SMS textarea and the text size in KB
654
-  $("#smstext").on('input', function() {
655
-
656
-     $("#char_count").css("display", "inline");
657
-
658
-     $("#mtextSize").css("display", "inline");
659
-
660
-     $(".maxmessagelength").css("display", "inline-block");
661
-
662
-     $("#countchnb").text($(this).val().length);
663
-
664
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
665
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
666
-     $("#textsizeinkb").text(textsizekb);
667
-
668
-     if ($(this).val().length > charcolorthr) {
669
-         $("#char_count").css("color", "#BB2E4B");
670
-     } else {
671
-         $("#char_count").css("color", "#4cbc86;");
672
-     }
673
-
674
-  });
675
-
676
-
677
-  // Check the checkbox to send file(s) as MMS
678
-  $('#mediafilechckbx').change(function() {
679
-
680
-      if ($(this).is(':checked')) {
681
-
682
-          isMMS = 1;
683
-          if (selectedid == '') {
684
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
685
-              $(this).prop("checked", false);
686
-              isMMS = 0;
687
-              return;
688
-          }
689
-          $("#upmediafiles").css("display", "block");
690
-          $("#submitsms").prop("value", "Send MMS");
691
-          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send MMS'.");
692
-
693
-      } else {
694
-
695
-          isMMS = 0;
696
-          $("#upmediafiles").css("display", "none");
697
-          $("#submitsms").prop("value", "Send SMS");
698
-          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send SMS'.");
699
-
700
-          // Remove the uploaded files' names if any
701
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
702
-          $(".indgenpckfls").each(function() { $(this).remove(); });
703
-
704
-          // Remove all the files from the SMS_Relentless/temp_files directory
705
-          cleanTempDirectory();
706
-
707
-          $("#smstables").empty();
708
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
709
-
710
-          uploadedtomms = [];
711
-          n = 1;
712
-
713
-          msgtotalflsize = 0;
714
-
715
-          $("#filestotsize").hide();
716
-      }
717
-  });
718
-
719
-
720
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
721
-  function adjustMaximumSize(uploadedtomms) {
722
-				      
723
-      var nonimgcheck = 0;
724
-      for (var u = 0; u < uploadedtomms.length; u++) {
725
-	   var crupfl = uploadedtomms[u];
726
-	   var extensionup = crupfl.replace(/^.*\./, '');
727
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
728
-	       nonimgcheck = 1;
729
-	   }
730
-      }
731
-
732
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
733
-  }
734
-
735
-  // Upload files to be sent as MMS
736
-  $("#uploadfileformms").change(function(e) {
737
-
738
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
739
-     $('#smstables').addClass('icon-loading');
740
-     $('#filestotsize').show();
741
-
742
-     var userid = "<?php p($userId); ?>";
743
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
744
-
745
-     var formData = new FormData();
746
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
747
-
748
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
749
-
750
-     // Add the size of the current file to the total size of all the files
751
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
752
-
753
-     var fileup = $('#uploadfileformms').val();
754
-     var fileuptrim = fileup.split('\\').pop();
755
-
756
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
757
-         var duplicatescheck = 1;
758
-     } else { 
759
-         var duplicatescheck = 0;
760
-     }
761
-
762
-     var extension = fileup.replace(/^.*\./, '');
763
-
764
-     if (extension == fileup) {
765
-         extension = "";
766
-     } else {
767
-         extension = extension.toLowerCase();
768
-     }
769
-
770
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
771
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
772
-         maximumsize = maxsizenonimage;
773
-     }
774
-
775
-     if ($.inArray(extension, validExtensions) != -1) {
776
-
777
-       if (duplicatescheck == 0) {
778
-
779
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
780
-
781
-            if (n <= maximumfilenumber) {
782
-
783
-               $.ajax({
784
-                 url: baseUrl + '/' + userid,
785
-                 type: "POST",
786
-                 data: formData,
787
-                 cache: false,
788
-                 processData: false,
789
-                 contentType: false,
790
-                 success: function(totalflsize) {
791
-
792
-                   uploadedtomms.push(fileuptrim);
793
-
794
-                   $('#filessizetext').text(totalflsize);
795
-
796
-                   var rectotfilesz = parseFloat(totalflsize);
797
-
798
-                   if (rectotfilesz <= maximumsize) {
799
-                       $('#submitsms').attr("disabled", false);
800
-                       $('#filestotsize').css('color', '#189558');
801
-                   } else {
802
-                       $('#filestotsize').css('color', '#ba3555');
803
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
804
-                       $('#submitsms').attr("disabled", true);
805
-                       $('#smstables').removeClass('icon-loading');
806
-                       $('#pf_upload_msg').hide();
807
-                   }
808
-
809
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
810
-                   n++;
811
-
812
-                   // Preview the file when you click on its name
813
-                   $("div:visible[id*='indfilediv']").each(function() {
814
-
815
-                        $(this).on("click", function(eventclck) {
816
-
817
-                           $("#mmsfoldersview").css("display", "inline-block");
818
-                           var mmsfilenameinit = $(this).text();
819
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
820
-                           var mmsfilename = mmsfilenamesec.replace("X","");
821
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
822
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
823
-
824
-                           if (extenlst == mmsfilename) {
825
-                               extenlst = "";
826
-                           } else {
827
-                               extenlst = extenlst.toLowerCase();
828
-                           }
829
-
830
-                           $("#smstables").empty();
831
-                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
832
-
833
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
834
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
835
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
836
-                           } else if (extenlst == 'png') {
837
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
838
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
839
-                           } else if (extenlst == 'gif') {
840
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
841
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
842
-                           } else if (extenlst == 'bmp') {
843
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
844
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
845
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
846
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
847
-                                  var xhr = new XMLHttpRequest();
848
-                                  xhr.responseType = 'arraybuffer';
849
-                                  xhr.open('GET', tiffile);
850
-                                  xhr.onload = function (evnt) {
851
-                                      var tiff = new Tiff({buffer: xhr.response});
852
-                                      var tifcanvas = tiff.toCanvas();
853
-                                      $("#smstables").append(tifcanvas);
854
-                                  };
855
-                                  xhr.send();
856
-                           } else if (extenlst == 'pdf') {
857
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
-                                  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>');
859
-                                  $("#smstables").append($iframe);
860
-                           } else if (extenlst == 'txt') {
861
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
862
-                           } else if (extension == 'mp4') {
863
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
864
-		           } else if (extension == 'ogg') {
865
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
866
-		           } else if (extension == 'avi') {
867
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
868
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
869
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
870
-		           } else if (extension == 'wav' || extension == 'wave') {
871
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
872
-		           } else if (extension == 'mp3') {
873
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
874
-		           } else if (extension == 'midi') {
875
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
876
-		           }
877
-
878
-                           $("#smstables").show();
879
-                           $("#mmsfoldersview").hide();
880
-                        });
881
-                   });
882
-
883
-                   // Remove uploaded files
884
-                   $('[class*="indupfldl"]').last().click(function() {
885
-
886
-                           var userid = "<?php p($userId); ?>";
887
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
888
-
889
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
890
-
891
-                           var removedfilesplit = removedfilenameinit.split(") ");
892
-                           var removedflnb = parseInt(removedfilesplit[0]);
893
-
894
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
895
-                           $(this).hide();
896
-
897
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
898
-
899
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
900
-                                           return value != removedfilename;
901
-                           });
902
-
903
-                           $.ajax({
904
-                                   url: baseUrl + '/' + userid,
905
-                                   type: "POST",
906
-                                   data: {removedfilename: removedfilename},
907
-                                   success: function(totalflsize) {
908
-
909
-                                      msgtotalflsize = totalflsize;
910
-                                      $('#filessizetext').text(totalflsize);
911
-
912
-                                      adjustMaximumSize(uploadedtomms);
913
-
914
-                                      // Check message size
915
-                                      var rectotfilesz = parseFloat(totalflsize);
916
-
917
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
918
-                                          $('#submitsms').attr("disabled", false);
919
-                                          $('#filestotsize').css('color', '#189558');
920
-                                      } else {
921
-                                          $('#filestotsize').css('color', '#ba3555');
922
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
923
-                                          $('#submitsms').attr("disabled", true);
924
-                                      }
925
-
926
-                                      // Rewrite order numbers for files that follow
927
-                                      --n;
928
-                                      $("div:visible[id*='indfilediv']").each(function() {
929
-
930
-                                          var getdivtext =  $(this).text();
931
-                                          var splitdivtext = getdivtext.split(") ");
932
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
933
-                                          var newnbvalue = currentnbvalue - 1;
934
-
935
-                                          if (currentnbvalue > removedflnb) {
936
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
937
-                                              $(this).text(replacedstr);
938
-                                          }
939
-                                      });
940
-
941
-                                      $("div:visible[id*='indflpicked']").each(function() {
942
-
943
-                                          var getdivtext =  $(this).text();
944
-                                          var splitdivtext = getdivtext.split(") ");
945
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
946
-                                          var newnbvalue = currentnbvalue - 1;
947
-
948
-                                          if (currentnbvalue > removedflnb) {
949
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
950
-                                              $(this).text(replacedstr);
951
-                                          }
952
-                                      });
953
-
954
-                                   },
955
-                                   error: function() {
956
-                                              showAlert("Error while removing the file(s).");
957
-                                   }
958
-                           });
959
-
960
-                           $('#smstables').removeClass('icon-loading');
961
-                           $("#smstables").empty();
962
-                   });
963
-
964
-                   // Preview the uploaded file
965
-                   $("#mmsfoldersview").css("display", "inline-block");
966
-                   var mmsfilename = e.target.files[0].name;
967
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
968
-
969
-                   $("#smstables").empty();
970
-                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
971
-
972
-                   if (extension == 'jpg' || extension == 'jpeg') {
973
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
974
-
975
-                              var reader = new FileReader();
976
-                              reader.onload = function (e) {
977
-                                  readjpg[mmsfilename] = e.target.result;
978
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
979
-                              }
980
-                              reader.readAsDataURL(e.target.files[0]);
981
-                   } else if (extension == 'png') {
982
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
983
-
984
-                              var reader = new FileReader();
985
-                              reader.onload = function (e) {
986
-                                  readpng[mmsfilename] = e.target.result;
987
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
988
-                              }
989
-                              reader.readAsDataURL(e.target.files[0]);
990
-
991
-                   } else if (extension == 'gif') {
992
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
993
-
994
-                              var reader = new FileReader();
995
-                              reader.onload = function (e) {
996
-                                  readgif[mmsfilename] = e.target.result;
997
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
998
-                              }
999
-                              reader.readAsDataURL(e.target.files[0]);
1000
-
1001
-                   } else if (extension == 'bmp') {
1002
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1003
-
1004
-                              var reader = new FileReader();
1005
-                              reader.onload = function (e) {
1006
-                                  readbmp[mmsfilename] = e.target.result;
1007
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1008
-                              }
1009
-                              reader.readAsDataURL(e.target.files[0]);
1010
-
1011
-                   } else if (extension == 'tif' || extension == 'tiff') {
1012
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1013
-                              var xhr = new XMLHttpRequest();
1014
-                              xhr.responseType = 'arraybuffer';
1015
-                              xhr.open('GET', tiffile);
1016
-                              xhr.onload = function (e) {
1017
-                                  var tiff = new Tiff({buffer: xhr.response});
1018
-                                  var tifcanvas = tiff.toCanvas();
1019
-                                  $("#smstables").append(tifcanvas);
1020
-                              };
1021
-                              xhr.send();
1022
-
1023
-                   } else if (extension == 'pdf') {
1024
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1025
-                              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>');
1026
-                              $("#smstables").append($iframe);
1027
-
1028
-                   } else if (extension == 'txt') {
1029
-                              var reader = new FileReader();
1030
-                              reader.readAsText(e.target.files[0]);
1031
-                              reader.onload = function(e) {
1032
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1033
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1034
-                              };
1035
-                   } else if (extension == 'mp4') {
1036
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1037
-                   } else if (extension == 'ogg') {
1038
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1039
-                   } else if (extension == 'avi') {
1040
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1041
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1042
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1043
-                   } else if (extension == 'wav' || extension == 'wave') {
1044
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1045
-                   } else if (extension == 'mp3') {
1046
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1047
-                   } else if (extension == 'midi') {
1048
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1049
-                   }
1050
-
1051
-                   $("#smstables").show();
1052
-                   $('#pf_upload_msg').hide();
1053
-                   $('#smstables').removeClass('icon-loading');
1054
-                   $("#mmsfoldersview").hide();
1055
-                 },
1056
-                 error: function() {
1057
-                              showAlert("Error while uploading the file.");
1058
-                 }
1059
-               });
1060
-
1061
-            } else {
1062
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1063
-                  adjustMaximumSize(uploadedtomms);
1064
-
1065
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1066
-                  $('#pf_upload_msg').hide();
1067
-                  $('#smstables').removeClass('icon-loading');
1068
-            }
1069
-         } else {
1070
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1071
-              adjustMaximumSize(uploadedtomms);
1072
-
1073
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1074
-              $('#pf_upload_msg').hide();
1075
-              $('#smstables').removeClass('icon-loading');
1076
-         }
1077
-       } else {
1078
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1079
-            adjustMaximumSize(uploadedtomms);
1080
-
1081
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1082
-            $('#pf_upload_msg').hide();
1083
-            $('#smstables').removeClass('icon-loading');
1084
-       }
1085
-
1086
-     } else {
1087
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1088
-          adjustMaximumSize(uploadedtomms);
1089
-
1090
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1091
-          $('#pf_upload_msg').hide();
1092
-          $('#smstables').removeClass('icon-loading');
1093
-     }
1094
-  });
1095
-
1096
-
1097
-  // Pick file(s) from Nextcloud, to send as MMS
1098
-  var mmsfilename = null;
1099
-
1100
-  $("#choosefilen").on("click", function(evn) {
1101
-
1102
-                OC.dialogs.filepicker(
1103
-                        t('settings', "Select a file to send as MMS."),
1104
-                        function (path) {
1105
-
1106
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1107
-                              $('#smstables').addClass('icon-loading');
1108
-                              $('#filestotsize').show();
1109
-
1110
-                              var userid = "<?php p($userId); ?>";
1111
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1112
-
1113
-                              mmsfilename = path.split('/').pop();
1114
-
1115
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1116
-                                  var duplicatescheck = 1;
1117
-                              } else var duplicatescheck = 0;
1118
-
1119
-                              var extension = mmsfilename.replace(/^.*\./, '');
1120
-
1121
-                              if (extension == mmsfilename) {
1122
-                                  extension = "";
1123
-                              } else {
1124
-                                  extension = extension.toLowerCase();
1125
-                              }
1126
-
1127
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1128
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1129
-				   maximumsize = maxsizenonimage;
1130
-			      }
1131
-
1132
-                              if ($.inArray(extension, validExtensions) != -1) {
1133
-
1134
-                                 if (duplicatescheck == 0) {
1135
-
1136
-                                    if (n <= maximumfilenumber) {
1137
-
1138
-                                       $.ajax({
1139
-                                          url: baseUrl + '/' + userid,
1140
-                                          type: "POST",
1141
-                                          data: { path: path },
1142
-                                          success: function(pickresult) {
1143
-
1144
-                                                uploadedtomms.push(mmsfilename);
1145
-
1146
-                                                var totalflsize = pickresult[0];
1147
-                                                var pickedflsize = pickresult[1];
1148
-
1149
-                                                // Check message size
1150
-                                                var rectotfilesz = parseFloat(totalflsize);
1151
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1152
-
1153
-                                                if (filesplustextsize <= maximumsize) {
1154
-
1155
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1156
-
1157
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1158
-                                                    n++;
1159
-
1160
-                                                    msgtotalflsize = totalflsize;
1161
-                                                    $('#filessizetext').text(totalflsize);
1162
-                                                    $('#filestotsize').css('color', '#189558');
1163
-
1164
-                                                } else {
1165
-
1166
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1167
-                                                    $('#filestotsize').css('color', '#ba3555');
1168
-                                                    msgtotalflsize -= pickedflsize;
1169
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1170
-
1171
-                                                    $.ajax({
1172
-                                                        url: baseUrlindrm + '/' + userid,
1173
-                                                        type: "POST",
1174
-                                                        data: {removedfilename: mmsfilename},
1175
-                                                        success: function(totalflsize) {
1176
-
1177
-                                                                          $('#filessizetext').text(totalflsize);
1178
-                                                                          $('#filestotsize').css('color', '#189558');
1179
-                                                                          adjustMaximumSize(uploadedtomms);
1180
-
1181
-                                                        },
1182
-                                                        error: function(totalflsize) {
1183
-                                                                          $('#filessizetext').text(totalflsize);
1184
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1185
-                                                                              $('#filestotsize').css('color', '#ba3555');
1186
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1187
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1188
-                                                        }
1189
-                                                    });
1190
-
1191
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1192
-                                                }
1193
-
1194
-
1195
-                                                // Preview each file when you click on its name
1196
-                                                $("div:visible[id*='indflpicked']").each(function() {
1197
-                                                   $(this).on("click", function(event) {
1198
-
1199
-                                                      var mmsfilenameinit = $(this).text();
1200
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1201
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1202
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1203
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1204
-
1205
-                                                      if (extenlst == mmsfilenamesp) {
1206
-                                                           extenlst = "";
1207
-                                                      } else {
1208
-                                                           extenlst = extenlst.toLowerCase();
1209
-                                                      }
1210
-
1211
-                                                      $("#smstables").empty();
1212
-                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1213
-
1214
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1215
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1216
-                                                      } else if (extenlst == 'png') {
1217
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1218
-                                                      } else if (extenlst == 'gif') {
1219
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1220
-                                                      } else if (extenlst == 'bmp') {
1221
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1222
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1223
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1224
-                                                              var xhr = new XMLHttpRequest();
1225
-                                                              xhr.responseType = 'arraybuffer';
1226
-                                                              xhr.open('GET', tiffile);
1227
-                                                              xhr.onload = function (evnt) {
1228
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1229
-                                                                  var tifcanvas = tiff.toCanvas();
1230
-                                                                  $("#smstables").append(tifcanvas);
1231
-                                                              };
1232
-                                                              xhr.send();
1233
-                                                      } else if (extenlst == 'pdf') {
1234
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1235
-                                                              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>');
1236
-                                                              $("#smstables").append($iframe);
1237
-                                                      } else if (extenlst == 'txt') {
1238
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1239
-                                                      } else if (extension == 'mp4') {
1240
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1241
-						      } else if (extension == 'ogg') {
1242
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
-						      } else if (extension == 'avi') {
1244
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1245
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1246
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1247
-						      } else if (extension == 'wav' || extension == 'wave') {
1248
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1249
-						      } else if (extension == 'mp3') {
1250
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1251
-						      } else if (extension == 'midi') {
1252
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1253
-						      }
1254
-
1255
-                                                      $("#smstables").show();
1256
-                                                      $("#mmsfoldersview").hide();
1257
-                                                   });
1258
-                                                });
1259
-
1260
-
1261
-                                                // Remove picked files
1262
-                                                $('[class*="indpckfldl"]').last().click(function() {
1263
-                                                    var userid = "<?php p($userId); ?>";
1264
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1265
-
1266
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1267
-
1268
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1269
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1270
-
1271
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1272
-                                                    $(this).hide();
1273
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1274
-
1275
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1276
-                                                             return value != removedfilename;
1277
-                                                    });
1278
-
1279
-                                                    $.ajax({
1280
-                                                        url: baseUrl + '/' + userid,
1281
-                                                        type: "POST",
1282
-                                                        data: {removedfilename: removedfilename},
1283
-                                                        success: function(totalflsize) {
1284
-
1285
-                                                             msgtotalflsize = totalflsize;
1286
-                                                             $('#filessizetext').text(totalflsize);
1287
-                                                             adjustMaximumSize(uploadedtomms);
1288
-
1289
-                                                             // Check message size
1290
-                                                             var rectotfilesz = parseFloat(totalflsize);
1291
-
1292
-                                                             if (rectotfilesz > maximumsize) {
1293
-                                                                 $('#filestotsize').css('color', '#ba3555');
1294
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1295
-                                                                 $('#submitsms').attr("disabled", true);
1296
-                                                             } else {
1297
-                                                                 $('#submitsms').attr("disabled", false);
1298
-                                                                 $('#filestotsize').css('color', '#189558');
1299
-                                                               }
1300
-
1301
-                                                             // Rewrite order numbers for files that follow
1302
-                                                             --n;
1303
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1304
-
1305
-                                                                  var getdivtext =  $(this).text();
1306
-                                                                  var splitdivtext = getdivtext.split(") ");
1307
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1308
-                                                                  var newnbvalue = currentnbvalue - 1;
1309
-
1310
-                                                                  if (currentnbvalue > removedflnb) {
1311
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1312
-                                                                      $(this).text(replacedstr);
1313
-                                                                  }
1314
-                                                             });
1315
-                                                        },
1316
-                                                        error: function() {
1317
-                                                                  showAlert("Error while removing the file.");
1318
-                                                        }
1319
-                                                    });
1320
-
1321
-                                                    $('#smstables').removeClass('icon-loading');
1322
-                                                    $("#smstables").empty();
1323
-                                                });
1324
-
1325
-
1326
-		                                // Preview the picked file
1327
-		                                $("#mmsfoldersview").css("display", "inline-block");
1328
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1329
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1330
-
1331
-                                                $("#smstables").empty();
1332
-                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1333
-
1334
-						if (extension == 'jpg' || extension == 'jpeg') {
1335
-
1336
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1337
-
1338
-		                                } else if (extension == 'png') {
1339
-
1340
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1341
-
1342
-		                                } else if (extension == 'gif') {
1343
-
1344
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1345
-
1346
-		                                } else if (extension == 'bmp') {
1347
-
1348
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1349
-
1350
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1351
-
1352
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1353
-		                                       var xhr = new XMLHttpRequest();
1354
-		                                       xhr.responseType = 'arraybuffer';
1355
-		                                       xhr.open('GET', tiffile);
1356
-		                                       xhr.onload = function (event) {
1357
-		                                           var tiff = new Tiff({buffer: xhr.response});
1358
-		                                           var tifcanvas = tiff.toCanvas();
1359
-		                                           $("#smstables").append(tifcanvas);
1360
-		                                       };
1361
-		                                       xhr.send();
1362
-
1363
-		                                } else if (extension == 'pdf') {
1364
-
1365
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
-		                                       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>');
1367
-		                                       $("#smstables").append($iframe);
1368
-
1369
-		                                } else if (extension == 'txt') {
1370
-
1371
-							     $.get(flUrl, function(textdata) {
1372
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1373
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1374
-							     });
1375
-
1376
-		                                } else if (extension == 'mp4') {
1377
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1378
-						} else if (extension == 'ogg') {
1379
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1380
-						} else if (extension == 'avi') {
1381
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1382
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1383
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1384
-						} else if (extension == 'wav' || extension == 'wave') {
1385
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1386
-						} else if (extension == 'mp3') {
1387
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1388
-						} else if (extension == 'midi') {
1389
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1390
-						}
1391
-
1392
-
1393
-		                                $("#smstables").show();
1394
-
1395
-		                                $('#pf_choose_msg').hide();
1396
-		                                $('#smstables').removeClass('icon-loading');
1397
-		                                $("#mmsfoldersview").hide();
1398
-
1399
-                                          },
1400
-
1401
-                                          error: function(data){
1402
-                                                      showAlert("Error while getting the file.");
1403
-                                          }
1404
-
1405
-                                       });
1406
-
1407
-                                    } else {
1408
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1409
-                                        $('#pf_choose_msg').hide();
1410
-                                        $('#smstables').removeClass('icon-loading');
1411
-                                      }
1412
-                                 } else {
1413
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1414
-                                      $('#pf_choose_msg').hide();
1415
-                                      $('#smstables').removeClass('icon-loading');
1416
-                                   }
1417
-
1418
-                              } else {
1419
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1420
-                                   $('#pf_choose_msg').hide();
1421
-                                   $('#smstables').removeClass('icon-loading');
1422
-                                }
1423
-
1424
-                        }
1425
-                );
1426
-  });
1427
-
1428
-
1429
-
1430
-  // Send the SMS/MMS message
1431
-  $("#submitsms").on("click", function(event) {
1432
-
1433
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1434
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1435
-     $("#sms_submit_msg").css("display", "inline-block");
1436
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1437
-
1438
-     if (selectedid != '') { 
1439
-
1440
-         var sendersplit = selectedid.split(":");
1441
-         var providercap = sendersplit[0];
1442
-         var provsec = sendersplit[1];
1443
-
1444
-         if (/[a-zA-Z]/.test(provsec)) {
1445
-             var alphanumcheck = true;
1446
-         } else { var alphanumcheck = false; }
1447
-
1448
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1449
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1450
-             var selectedsender = "+" + senderproc;
1451
-             var providerUsed = "telnyx";
1452
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1453
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1454
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1455
-             var providerUsed = "plivo";
1456
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1457
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1458
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
-             var selectedsender = "+" + senderproc;
1460
-             var providerUsed = "twilio";
1461
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1462
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1463
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1464
-             var selectedsender = "+" + senderproc;
1465
-             var providerUsed = "flowroute";
1466
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1467
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1468
-             var selectedsender = provsec;
1469
-             var providerUsed = "telnyx";
1470
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1471
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1472
-             var selectedsender = provsec;
1473
-             var providerUsed = "plivo";
1474
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1475
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1476
-             var selectedsender = provsec;
1477
-             var providerUsed = "twilio";
1478
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1479
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1480
-             var selectedsender = provsec;
1481
-             var providerUsed = "flowroute";
1482
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1483
-         }
1484
-
1485
-         // Get the interval between message consecutive sending requests, if it's the case
1486
-         if ($('#tomultchckbx').is(':checked')) {
1487
-
1488
-             var numbersfile = 1;
1489
-             var initinterval = $("#multsmsinterval").val();
1490
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1491
-
1492
-             if (secinterval != '') {
1493
-                 var tertinterval = parseInt(secinterval);
1494
-                     waittime = tertinterval;
1495
-             }
1496
-
1497
-         } else {
1498
-
1499
-             var numbersfile = 0;
1500
-             var toNumberinit = $('#smsto').val();
1501
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1502
-             var toNumbersec = toNumber.split(",");
1503
-
1504
-                 for (var i = 0; i < toNumbersec.length; i++) {
1505
-                      toNumbersec[i] = "+" + toNumbersec[i];
1506
-                 }
1507
-
1508
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1509
-         }
1510
-
1511
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1512
-
1513
-         var smstext = $("#smstext").val();
1514
-
1515
-         if (receiversNumbers.length != 0) {
1516
-
1517
-              if (smstext != '') {
1518
-                  $.ajax({
1519
-                     url: relbaseUrl + '/' + userid,
1520
-                     type: "POST",
1521
-                     data: {
1522
-                           receiversPhoneNbs: receiversNumbers,
1523
-                           fromsender: selectedsender,
1524
-                           waitinterval: waittime,
1525
-                           sentsmstext: smstext,
1526
-                           ismms: isMMS,
1527
-                           mmsfiles: uploadedtomms
1528
-                         },
1529
-                     success: function() {
1530
-
1531
-                           if (receiversNumbers.length == 1) {
1532
-                                   showAlert("The message has been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1533
-                           } else {
1534
-                                   showAlert("The messages have been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1535
-                           }
1536
-
1537
-                           $('#sms_submit_msg').hide();
1538
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1539
-                     },
1540
-                     error: function() {
1541
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1542
-                           $('#sms_submit_msg').hide();
1543
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1544
-                     }
1545
-                  });
1546
-              } else {
1547
-                     showAlert("Please enter a message in the text box !");
1548
-
1549
-                     $('#sms_submit_msg').hide();
1550
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1551
-              }
1552
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1553
-                 showAlert("Please enter the recipient's phone number !");
1554
-                 $('#sms_submit_msg').hide();
1555
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1556
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1557
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1558
-                 $('#sms_submit_msg').hide();
1559
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
-         }
1561
-     } else {
1562
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1563
-           $("#induploadfile").remove();
1564
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
-           $('#sms_submit_msg').hide();
1566
-     }
1567
-
1568
-  });
1569
-
1570
-  // Check the checkbox to delete old messages from the database
1571
-  $('#deleteoldchckbox').change(function() {
1572
-     if ($(this).is(':checked')) {
1573
-         $("#deleteoldsms").css("display", "block");
1574
-     } else {
1575
-         $("#deleteoldsms").css("display", "none");
1576
-     }
1577
-  });
1578
-
1579
-  // Set the height of info notes
1580
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1581
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1582
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1583
-
1584
-  $(window).resize(function() { 
1585
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1586
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1587
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1588
-  });
1589
-
1590
-
1591
-  function showAlert(alertText) {
1592
-
1593
-     $("#alertMsgOverlay").remove();
1594
-     $("#alertMessage").remove();
1595
-
1596
-     let alertwnd = "<div id='alertMessage'>";
1597
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1598
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1599
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1600
-     alertwnd += "</div>";
1601
-
1602
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1603
-     $("#content").append(alertwnd);
1604
-
1605
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1606
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1607
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1608
-
1609
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1610
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1611
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1612
-  }
Browse code

added files to implement CSS changes required by Nextcloud 28

DoubleBastionAdmin authored on 17/12/2023 01:12:45
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1612 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  function cleanTempDirectory() {
235
+
236
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
+
238
+     $.ajax({
239
+          url: cleanflUrl + '/' + userid,
240
+          type: "POST",
241
+          data: { userid: userid },
242
+          cache: false,
243
+          processData: false,
244
+          contentType: false
245
+     });
246
+  }
247
+  cleanTempDirectory();
248
+
249
+  // Clean the SMS_Relentless/multiple_recipients directory
250
+  function cleanMultRecDirectory() {
251
+
252
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
+
254
+     $.ajax({
255
+          url: cleanflUrl + '/' + userid,
256
+          type: "POST",
257
+          data: { userid: userid },
258
+          cache: false,
259
+          processData: false,
260
+          contentType: false
261
+     });
262
+  }
263
+  cleanMultRecDirectory();
264
+
265
+  // Check the available balance
266
+  $("#smsprovider").on("change", function () {
267
+
268
+     var provider = $('#smsprovider :selected').val();
269
+
270
+     if (provider == "Telnyx") {
271
+
272
+        var gettelbalance = function() {
273
+
274
+          $('#currentbalance').addClass('icon-loading');
275
+
276
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
+
278
+          $.ajax({
279
+              url: gettelbalanceUrl + '/' + userid,
280
+              type: "POST",
281
+              data: { userid: userid },
282
+              cache: false,
283
+              processData: false,
284
+              contentType: false,
285
+              success: function(currentbalancetel) {
286
+
287
+                     $('#currentbalance').empty();
288
+                     $('#currentbalance').text(currentbalancetel);
289
+                     $('#currentbalance').removeClass('icon-loading');
290
+              }
291
+          });
292
+        }
293
+
294
+        gettelbalance();
295
+
296
+     } else if (provider == "Plivo") {
297
+
298
+          var getnexbalance = function() {
299
+
300
+            $('#currentbalance').addClass('icon-loading');
301
+
302
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
+
304
+            $.ajax({
305
+                url: getnexbalanceUrl + '/' + userid,
306
+                type: "POST",
307
+                data: { userid: userid },
308
+                cache: false,
309
+                processData: false,
310
+                contentType: false,
311
+                success: function(currentbalancenex) {
312
+
313
+                     $('#currentbalance').empty();
314
+                     $('#currentbalance').text(currentbalancenex);
315
+                     $('#currentbalance').removeClass('icon-loading');
316
+                }
317
+            });
318
+          }
319
+
320
+          getnexbalance();
321
+
322
+     } else if (provider == "Twilio") {
323
+
324
+          var gettwilbalance = function() {
325
+
326
+            $('#currentbalance').addClass('icon-loading');
327
+
328
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
+
330
+            $.ajax({
331
+                url: gettwilbalanceUrl + '/' + userid,
332
+                type: "POST",
333
+                data: { userid: userid },
334
+                cache: false,
335
+                processData: false,
336
+                contentType: false,
337
+                success: function(currentbalancetwil) {
338
+
339
+                     $('#currentbalance').empty();
340
+                     $('#currentbalance').text(currentbalancetwil);
341
+                     $('#currentbalance').removeClass('icon-loading');
342
+                }
343
+            });
344
+          }
345
+
346
+          gettwilbalance();
347
+
348
+     } else if (provider == "Flowroute") {
349
+
350
+          var getflowbalance = function() {
351
+
352
+            $('#currentbalance').addClass('icon-loading');
353
+
354
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
+
356
+            $.ajax({
357
+                url: getflowbalanceUrl + '/' + userid,
358
+                type: "POST",
359
+                data: { userid: userid },
360
+                cache: false,
361
+                processData: false,
362
+                contentType: false,
363
+                success: function(currentbalanceflow) {
364
+
365
+                     $('#currentbalance').empty();
366
+                     $('#currentbalance').text(currentbalanceflow);
367
+                     $('#currentbalance').removeClass('icon-loading');
368
+                }
369
+            });
370
+          }
371
+
372
+          getflowbalance();
373
+
374
+       } else if (provider == "") {
375
+                $('#currentbalance').text("");
376
+                $('#currentbalance').removeClass('icon-loading');
377
+       }
378
+  });
379
+
380
+
381
+  // If a Sender ID is selected
382
+  $("#currentsmsnmbrs").on("change", function () {
383
+
384
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
+
386
+              selectedid = $('#currentsmsnmbrs :selected').val();
387
+              var setIdsplit = selectedid.split(":");
388
+	      chosenProvider = setIdsplit[0];
389
+
390
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
391
+	      if (chosenProvider == "Tx") {
392
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
393
+		  // Maximum size of message text + files in KB
394
+		  maximumsize = 1024;
395
+                  maximumsizeinit = 1024;
396
+		  maxsizenonimage = 600;
397
+		  maximumfilenumber = 10;
398
+                  chosenProvFullName = "Telnyx";
399
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
400
+                                     or gif files, the size of all the files plus the size of the text should be \
401
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
402
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
403
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
404
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
405
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
406
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
407
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
408
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
409
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
410
+                  $("#tooltiptextfourth").html(infonotecontent);
411
+	      } else if (chosenProvider == "Pl") {
412
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
413
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
414
+		  // Maximum size of message text + files in KB
415
+		  maximumsize = 5120;
416
+                  maximumsizeinit = 5120;
417
+		  maxsizenonimage = 600;
418
+		  maximumfilenumber = 10;
419
+                  chosenProvFullName = "Plivo";
420
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
421
+                                     or gif files, the size of all the files plus the size of the text should be \
422
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
423
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
424
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
425
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
426
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
427
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
428
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
429
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
430
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
431
+                  $("#tooltiptextfourth").html(infonotecontent);
432
+	      } else if (chosenProvider == "Tw") {
433
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
434
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
435
+                                     "icalendar", "directory", "pdf", "pkpass"];
436
+		  // Maximum size of message text + files in KB
437
+		  maximumsize = 5120;
438
+                  maximumsizeinit = 5120;
439
+		  maxsizenonimage = 600;
440
+		  maximumfilenumber = 10;
441
+                  chosenProvFullName = "Twilio";
442
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
443
+                                     or gif files, the size of all the files plus the size of the text should be \
444
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
445
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
446
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
447
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
448
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
449
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
450
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
451
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
452
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
453
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
454
+                                     previewed in the adjoining pane."
455
+                  $("#tooltiptextfourth").html(infonotecontent);
456
+	      } else if (chosenProvider == "Fl") {
457
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
458
+		  // Maximum size of message text + files in KB
459
+		  maximumsize = 750;
460
+                  maximumsizeinit = 750;
461
+		  maxsizenonimage = 600;
462
+		  maximumfilenumber = 10;
463
+                  chosenProvFullName = "Flowroute";
464
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
465
+                                     png or gif files, the size of all the files plus the size of the text should be \
466
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
467
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
468
+                                     size of the files plus the size of the text should be 600 KB or less. \
469
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
470
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
471
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
472
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
473
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
474
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
475
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
476
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
477
+                  $("#tooltiptextfourth").html(infonotecontent);
478
+	      }
479
+
480
+          } else { selectedid = ''; }
481
+  });
482
+
483
+  // Check the checkbox to send SMS message to multiple recipients
484
+  $('#tomultchckbx').change(function() {
485
+      if ($(this).is(':checked')) {
486
+          $("#multiplerecivers").css("display", "block");
487
+          $("#smstodiv").css("visibility", "hidden");
488
+          $("#smsto").val("");
489
+
490
+          receiversNumbers.length = 0;
491
+
492
+      } else {
493
+          $("#multiplerecivers").css("display", "none");
494
+          $("#smstodiv").css("visibility", "visible");
495
+
496
+          // Remove the uploaded files' names if any
497
+          $("#induploadfile").remove();
498
+
499
+          // Remove all the files from the SMS_Relentless/multiple_recipients directory
500
+          cleanMultRecDirectory();
501
+
502
+          $("#smstables").empty();
503
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
504
+
505
+          receiversNumbers.length = 0;
506
+      }
507
+  });
508
+
509
+  // Upload the file with the recipients' phone numbers
510
+  $("#uploadfileforsms").change(function(e) {
511
+
512
+     $("#fileuploadednm").empty();
513
+
514
+     receiversNumbers.length = 0;
515
+
516
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
517
+
518
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
519
+
520
+     var formData = new FormData();
521
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
522
+
523
+     var fileup = $('#uploadfileforsms').val();
524
+     var fileuptrim = fileup.split('\\').pop();
525
+
526
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
527
+
528
+     var extension = fileup.replace(/^.*\./, '');
529
+
530
+     if (extension == fileup) {
531
+         extension = "";
532
+     } else {
533
+         extension = extension.toLowerCase();
534
+     }
535
+
536
+     var validExtensionsmrec = ["txt", "csv"];
537
+
538
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
539
+
540
+       if (selectedid != '') {
541
+
542
+               $.ajax({
543
+                 url: baseUrl + '/' + userid,
544
+                 type: "POST",
545
+                 data: formData,
546
+                 cache: false,
547
+                 processData: false,
548
+                 contentType: false,
549
+                 success: function(numberarray) {
550
+
551
+		    if (numberarray.length > 0) {
552
+
553
+		        // Get the array of the receivers' phone numbers
554
+		        if (chosenProvider == "Tx") {
555
+
556
+		             for(key in numberarray) {
557
+		                 receiversNumbers.push("+"+numberarray[key]);
558
+		             }
559
+
560
+		        } else if (chosenProvider == "Pl") {
561
+
562
+		             for(key in numberarray) {
563
+		                 receiversNumbers.push(numberarray[key]);
564
+		             }
565
+
566
+		          } else if (chosenProvider == "Tw") {
567
+
568
+		             for(key in numberarray) {
569
+		                 receiversNumbers.push(numberarray[key]);
570
+		             }
571
+		          } else if (chosenProvider == "Fl") {
572
+
573
+		             for(key in numberarray) {
574
+		                 receiversNumbers.push(numberarray[key]);
575
+		             }
576
+		          }
577
+
578
+		    } else {
579
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
580
+		    }
581
+                            
582
+                    // Preview the uploaded file
583
+                    var smsfilename = e.target.files[0].name;
584
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
585
+
586
+                    var reader = new FileReader();
587
+                    reader.readAsText(e.target.files[0]);
588
+                    reader.onload = function(e) {
589
+                          $("#smstables").empty();
590
+                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
591
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
592
+                    };
593
+
594
+                    $("#smstables").show();
595
+
596
+                    $('#sms_upload_msg').hide();
597
+                    $('#smstables').removeClass('icon-loading');
598
+
599
+                  },
600
+                  error: function() {
601
+                             showAlert("Error while uploading the file.");
602
+                  }
603
+               });
604
+
605
+        } else {
606
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
607
+               $("#induploadfile").remove();
608
+               $('#sms_upload_msg').hide();
609
+               $('#smstables').removeClass('icon-loading');
610
+        }
611
+
612
+     } else {
613
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
614
+          $('#pf_upload_msg').hide();
615
+          $('#smstables').removeClass('icon-loading');
616
+
617
+          $("#induploadfile").remove();
618
+          $("#sms_upload_msg").hide();
619
+     }
620
+
621
+     // Preview uploaded file when clicked
622
+     $("#indfilediv").on("click", function() {
623
+
624
+          var smsfilename = e.target.files[0].name;
625
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
626
+
627
+          var reader = new FileReader();
628
+          reader.readAsText(e.target.files[0]);
629
+          reader.onload = function(e) {
630
+                  $("#smstables").empty();
631
+                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
632
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
633
+          };
634
+
635
+          $("#smstables").show();
636
+          $('#sms_upload_msg').hide();
637
+          $('#smstables').removeClass('icon-loading');
638
+     });
639
+
640
+     // Remove selected file
641
+     $("#indivflremove").on("click", function() {
642
+
643
+          $("#induploadfile").remove();
644
+          $("#sms_upload_msg").hide();
645
+
646
+          receiversNumbers.length = 0;
647
+
648
+          cleanMultRecDirectory();
649
+     });
650
+
651
+  });
652
+
653
+  // Show the number of characters entered in the SMS textarea and the text size in KB
654
+  $("#smstext").on('input', function() {
655
+
656
+     $("#char_count").css("display", "inline");
657
+
658
+     $("#mtextSize").css("display", "inline");
659
+
660
+     $(".maxmessagelength").css("display", "inline-block");
661
+
662
+     $("#countchnb").text($(this).val().length);
663
+
664
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
665
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
666
+     $("#textsizeinkb").text(textsizekb);
667
+
668
+     if ($(this).val().length > charcolorthr) {
669
+         $("#char_count").css("color", "#BB2E4B");
670
+     } else {
671
+         $("#char_count").css("color", "#4cbc86;");
672
+     }
673
+
674
+  });
675
+
676
+
677
+  // Check the checkbox to send file(s) as MMS
678
+  $('#mediafilechckbx').change(function() {
679
+
680
+      if ($(this).is(':checked')) {
681
+
682
+          isMMS = 1;
683
+          if (selectedid == '') {
684
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
685
+              $(this).prop("checked", false);
686
+              isMMS = 0;
687
+              return;
688
+          }
689
+          $("#upmediafiles").css("display", "block");
690
+          $("#submitsms").prop("value", "Send MMS");
691
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send MMS'.");
692
+
693
+      } else {
694
+
695
+          isMMS = 0;
696
+          $("#upmediafiles").css("display", "none");
697
+          $("#submitsms").prop("value", "Send SMS");
698
+          $("#smstext").prop("placeholder", "Enter a message here, then press 'Send SMS'.");
699
+
700
+          // Remove the uploaded files' names if any
701
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
702
+          $(".indgenpckfls").each(function() { $(this).remove(); });
703
+
704
+          // Remove all the files from the SMS_Relentless/temp_files directory
705
+          cleanTempDirectory();
706
+
707
+          $("#smstables").empty();
708
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
709
+
710
+          uploadedtomms = [];
711
+          n = 1;
712
+
713
+          msgtotalflsize = 0;
714
+
715
+          $("#filestotsize").hide();
716
+      }
717
+  });
718
+
719
+
720
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
721
+  function adjustMaximumSize(uploadedtomms) {
722
+				      
723
+      var nonimgcheck = 0;
724
+      for (var u = 0; u < uploadedtomms.length; u++) {
725
+	   var crupfl = uploadedtomms[u];
726
+	   var extensionup = crupfl.replace(/^.*\./, '');
727
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
728
+	       nonimgcheck = 1;
729
+	   }
730
+      }
731
+
732
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
733
+  }
734
+
735
+  // Upload files to be sent as MMS
736
+  $("#uploadfileformms").change(function(e) {
737
+
738
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
739
+     $('#smstables').addClass('icon-loading');
740
+     $('#filestotsize').show();
741
+
742
+     var userid = "<?php p($userId); ?>";
743
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
744
+
745
+     var formData = new FormData();
746
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
747
+
748
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
749
+
750
+     // Add the size of the current file to the total size of all the files
751
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
752
+
753
+     var fileup = $('#uploadfileformms').val();
754
+     var fileuptrim = fileup.split('\\').pop();
755
+
756
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
757
+         var duplicatescheck = 1;
758
+     } else { 
759
+         var duplicatescheck = 0;
760
+     }
761
+
762
+     var extension = fileup.replace(/^.*\./, '');
763
+
764
+     if (extension == fileup) {
765
+         extension = "";
766
+     } else {
767
+         extension = extension.toLowerCase();
768
+     }
769
+
770
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
771
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
772
+         maximumsize = maxsizenonimage;
773
+     }
774
+
775
+     if ($.inArray(extension, validExtensions) != -1) {
776
+
777
+       if (duplicatescheck == 0) {
778
+
779
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
780
+
781
+            if (n <= maximumfilenumber) {
782
+
783
+               $.ajax({
784
+                 url: baseUrl + '/' + userid,
785
+                 type: "POST",
786
+                 data: formData,
787
+                 cache: false,
788
+                 processData: false,
789
+                 contentType: false,
790
+                 success: function(totalflsize) {
791
+
792
+                   uploadedtomms.push(fileuptrim);
793
+
794
+                   $('#filessizetext').text(totalflsize);
795
+
796
+                   var rectotfilesz = parseFloat(totalflsize);
797
+
798
+                   if (rectotfilesz <= maximumsize) {
799
+                       $('#submitsms').attr("disabled", false);
800
+                       $('#filestotsize').css('color', '#189558');
801
+                   } else {
802
+                       $('#filestotsize').css('color', '#ba3555');
803
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
804
+                       $('#submitsms').attr("disabled", true);
805
+                       $('#smstables').removeClass('icon-loading');
806
+                       $('#pf_upload_msg').hide();
807
+                   }
808
+
809
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
810
+                   n++;
811
+
812
+                   // Preview the file when you click on its name
813
+                   $("div:visible[id*='indfilediv']").each(function() {
814
+
815
+                        $(this).on("click", function(eventclck) {
816
+
817
+                           $("#mmsfoldersview").css("display", "inline-block");
818
+                           var mmsfilenameinit = $(this).text();
819
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
820
+                           var mmsfilename = mmsfilenamesec.replace("X","");
821
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
822
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
823
+
824
+                           if (extenlst == mmsfilename) {
825
+                               extenlst = "";
826
+                           } else {
827
+                               extenlst = extenlst.toLowerCase();
828
+                           }
829
+
830
+                           $("#smstables").empty();
831
+                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
832
+
833
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
834
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
835
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
836
+                           } else if (extenlst == 'png') {
837
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
838
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
839
+                           } else if (extenlst == 'gif') {
840
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
841
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
842
+                           } else if (extenlst == 'bmp') {
843
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
844
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
845
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
846
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
847
+                                  var xhr = new XMLHttpRequest();
848
+                                  xhr.responseType = 'arraybuffer';
849
+                                  xhr.open('GET', tiffile);
850
+                                  xhr.onload = function (evnt) {
851
+                                      var tiff = new Tiff({buffer: xhr.response});
852
+                                      var tifcanvas = tiff.toCanvas();
853
+                                      $("#smstables").append(tifcanvas);
854
+                                  };
855
+                                  xhr.send();
856
+                           } else if (extenlst == 'pdf') {
857
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
+                                  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>');
859
+                                  $("#smstables").append($iframe);
860
+                           } else if (extenlst == 'txt') {
861
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
862
+                           } else if (extension == 'mp4') {
863
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
864
+		           } else if (extension == 'ogg') {
865
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
866
+		           } else if (extension == 'avi') {
867
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
868
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
869
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
870
+		           } else if (extension == 'wav' || extension == 'wave') {
871
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
872
+		           } else if (extension == 'mp3') {
873
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
874
+		           } else if (extension == 'midi') {
875
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
876
+		           }
877
+
878
+                           $("#smstables").show();
879
+                           $("#mmsfoldersview").hide();
880
+                        });
881
+                   });
882
+
883
+                   // Remove uploaded files
884
+                   $('[class*="indupfldl"]').last().click(function() {
885
+
886
+                           var userid = "<?php p($userId); ?>";
887
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
888
+
889
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
890
+
891
+                           var removedfilesplit = removedfilenameinit.split(") ");
892
+                           var removedflnb = parseInt(removedfilesplit[0]);
893
+
894
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
895
+                           $(this).hide();
896
+
897
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
898
+
899
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
900
+                                           return value != removedfilename;
901
+                           });
902
+
903
+                           $.ajax({
904
+                                   url: baseUrl + '/' + userid,
905
+                                   type: "POST",
906
+                                   data: {removedfilename: removedfilename},
907
+                                   success: function(totalflsize) {
908
+
909
+                                      msgtotalflsize = totalflsize;
910
+                                      $('#filessizetext').text(totalflsize);
911
+
912
+                                      adjustMaximumSize(uploadedtomms);
913
+
914
+                                      // Check message size
915
+                                      var rectotfilesz = parseFloat(totalflsize);
916
+
917
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
918
+                                          $('#submitsms').attr("disabled", false);
919
+                                          $('#filestotsize').css('color', '#189558');
920
+                                      } else {
921
+                                          $('#filestotsize').css('color', '#ba3555');
922
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
923
+                                          $('#submitsms').attr("disabled", true);
924
+                                      }
925
+
926
+                                      // Rewrite order numbers for files that follow
927
+                                      --n;
928
+                                      $("div:visible[id*='indfilediv']").each(function() {
929
+
930
+                                          var getdivtext =  $(this).text();
931
+                                          var splitdivtext = getdivtext.split(") ");
932
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
933
+                                          var newnbvalue = currentnbvalue - 1;
934
+
935
+                                          if (currentnbvalue > removedflnb) {
936
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
937
+                                              $(this).text(replacedstr);
938
+                                          }
939
+                                      });
940
+
941
+                                      $("div:visible[id*='indflpicked']").each(function() {
942
+
943
+                                          var getdivtext =  $(this).text();
944
+                                          var splitdivtext = getdivtext.split(") ");
945
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
946
+                                          var newnbvalue = currentnbvalue - 1;
947
+
948
+                                          if (currentnbvalue > removedflnb) {
949
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
950
+                                              $(this).text(replacedstr);
951
+                                          }
952
+                                      });
953
+
954
+                                   },
955
+                                   error: function() {
956
+                                              showAlert("Error while removing the file(s).");
957
+                                   }
958
+                           });
959
+
960
+                           $('#smstables').removeClass('icon-loading');
961
+                           $("#smstables").empty();
962
+                   });
963
+
964
+                   // Preview the uploaded file
965
+                   $("#mmsfoldersview").css("display", "inline-block");
966
+                   var mmsfilename = e.target.files[0].name;
967
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
968
+
969
+                   $("#smstables").empty();
970
+                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
971
+
972
+                   if (extension == 'jpg' || extension == 'jpeg') {
973
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
974
+
975
+                              var reader = new FileReader();
976
+                              reader.onload = function (e) {
977
+                                  readjpg[mmsfilename] = e.target.result;
978
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
979
+                              }
980
+                              reader.readAsDataURL(e.target.files[0]);
981
+                   } else if (extension == 'png') {
982
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
983
+
984
+                              var reader = new FileReader();
985
+                              reader.onload = function (e) {
986
+                                  readpng[mmsfilename] = e.target.result;
987
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
988
+                              }
989
+                              reader.readAsDataURL(e.target.files[0]);
990
+
991
+                   } else if (extension == 'gif') {
992
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
993
+
994
+                              var reader = new FileReader();
995
+                              reader.onload = function (e) {
996
+                                  readgif[mmsfilename] = e.target.result;
997
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
998
+                              }
999
+                              reader.readAsDataURL(e.target.files[0]);
1000
+
1001
+                   } else if (extension == 'bmp') {
1002
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1003
+
1004
+                              var reader = new FileReader();
1005
+                              reader.onload = function (e) {
1006
+                                  readbmp[mmsfilename] = e.target.result;
1007
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1008
+                              }
1009
+                              reader.readAsDataURL(e.target.files[0]);
1010
+
1011
+                   } else if (extension == 'tif' || extension == 'tiff') {
1012
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1013
+                              var xhr = new XMLHttpRequest();
1014
+                              xhr.responseType = 'arraybuffer';
1015
+                              xhr.open('GET', tiffile);
1016
+                              xhr.onload = function (e) {
1017
+                                  var tiff = new Tiff({buffer: xhr.response});
1018
+                                  var tifcanvas = tiff.toCanvas();
1019
+                                  $("#smstables").append(tifcanvas);
1020
+                              };
1021
+                              xhr.send();
1022
+
1023
+                   } else if (extension == 'pdf') {
1024
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1025
+                              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>');
1026
+                              $("#smstables").append($iframe);
1027
+
1028
+                   } else if (extension == 'txt') {
1029
+                              var reader = new FileReader();
1030
+                              reader.readAsText(e.target.files[0]);
1031
+                              reader.onload = function(e) {
1032
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1033
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1034
+                              };
1035
+                   } else if (extension == 'mp4') {
1036
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1037
+                   } else if (extension == 'ogg') {
1038
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1039
+                   } else if (extension == 'avi') {
1040
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1041
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1042
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1043
+                   } else if (extension == 'wav' || extension == 'wave') {
1044
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1045
+                   } else if (extension == 'mp3') {
1046
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1047
+                   } else if (extension == 'midi') {
1048
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1049
+                   }
1050
+
1051
+                   $("#smstables").show();
1052
+                   $('#pf_upload_msg').hide();
1053
+                   $('#smstables').removeClass('icon-loading');
1054
+                   $("#mmsfoldersview").hide();
1055
+                 },
1056
+                 error: function() {
1057
+                              showAlert("Error while uploading the file.");
1058
+                 }
1059
+               });
1060
+
1061
+            } else {
1062
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1063
+                  adjustMaximumSize(uploadedtomms);
1064
+
1065
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1066
+                  $('#pf_upload_msg').hide();
1067
+                  $('#smstables').removeClass('icon-loading');
1068
+            }
1069
+         } else {
1070
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1071
+              adjustMaximumSize(uploadedtomms);
1072
+
1073
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1074
+              $('#pf_upload_msg').hide();
1075
+              $('#smstables').removeClass('icon-loading');
1076
+         }
1077
+       } else {
1078
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1079
+            adjustMaximumSize(uploadedtomms);
1080
+
1081
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1082
+            $('#pf_upload_msg').hide();
1083
+            $('#smstables').removeClass('icon-loading');
1084
+       }
1085
+
1086
+     } else {
1087
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1088
+          adjustMaximumSize(uploadedtomms);
1089
+
1090
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1091
+          $('#pf_upload_msg').hide();
1092
+          $('#smstables').removeClass('icon-loading');
1093
+     }
1094
+  });
1095
+
1096
+
1097
+  // Pick file(s) from Nextcloud, to send as MMS
1098
+  var mmsfilename = null;
1099
+
1100
+  $("#choosefilen").on("click", function(evn) {
1101
+
1102
+                OC.dialogs.filepicker(
1103
+                        t('settings', "Select a file to send as MMS."),
1104
+                        function (path) {
1105
+
1106
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1107
+                              $('#smstables').addClass('icon-loading');
1108
+                              $('#filestotsize').show();
1109
+
1110
+                              var userid = "<?php p($userId); ?>";
1111
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1112
+
1113
+                              mmsfilename = path.split('/').pop();
1114
+
1115
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1116
+                                  var duplicatescheck = 1;
1117
+                              } else var duplicatescheck = 0;
1118
+
1119
+                              var extension = mmsfilename.replace(/^.*\./, '');
1120
+
1121
+                              if (extension == mmsfilename) {
1122
+                                  extension = "";
1123
+                              } else {
1124
+                                  extension = extension.toLowerCase();
1125
+                              }
1126
+
1127
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1128
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1129
+				   maximumsize = maxsizenonimage;
1130
+			      }
1131
+
1132
+                              if ($.inArray(extension, validExtensions) != -1) {
1133
+
1134
+                                 if (duplicatescheck == 0) {
1135
+
1136
+                                    if (n <= maximumfilenumber) {
1137
+
1138
+                                       $.ajax({
1139
+                                          url: baseUrl + '/' + userid,
1140
+                                          type: "POST",
1141
+                                          data: { path: path },
1142
+                                          success: function(pickresult) {
1143
+
1144
+                                                uploadedtomms.push(mmsfilename);
1145
+
1146
+                                                var totalflsize = pickresult[0];
1147
+                                                var pickedflsize = pickresult[1];
1148
+
1149
+                                                // Check message size
1150
+                                                var rectotfilesz = parseFloat(totalflsize);
1151
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1152
+
1153
+                                                if (filesplustextsize <= maximumsize) {
1154
+
1155
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1156
+
1157
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1158
+                                                    n++;
1159
+
1160
+                                                    msgtotalflsize = totalflsize;
1161
+                                                    $('#filessizetext').text(totalflsize);
1162
+                                                    $('#filestotsize').css('color', '#189558');
1163
+
1164
+                                                } else {
1165
+
1166
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1167
+                                                    $('#filestotsize').css('color', '#ba3555');
1168
+                                                    msgtotalflsize -= pickedflsize;
1169
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1170
+
1171
+                                                    $.ajax({
1172
+                                                        url: baseUrlindrm + '/' + userid,
1173
+                                                        type: "POST",
1174
+                                                        data: {removedfilename: mmsfilename},
1175
+                                                        success: function(totalflsize) {
1176
+
1177
+                                                                          $('#filessizetext').text(totalflsize);
1178
+                                                                          $('#filestotsize').css('color', '#189558');
1179
+                                                                          adjustMaximumSize(uploadedtomms);
1180
+
1181
+                                                        },
1182
+                                                        error: function(totalflsize) {
1183
+                                                                          $('#filessizetext').text(totalflsize);
1184
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1185
+                                                                              $('#filestotsize').css('color', '#ba3555');
1186
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1187
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1188
+                                                        }
1189
+                                                    });
1190
+
1191
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1192
+                                                }
1193
+
1194
+
1195
+                                                // Preview each file when you click on its name
1196
+                                                $("div:visible[id*='indflpicked']").each(function() {
1197
+                                                   $(this).on("click", function(event) {
1198
+
1199
+                                                      var mmsfilenameinit = $(this).text();
1200
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1201
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1202
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1203
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1204
+
1205
+                                                      if (extenlst == mmsfilenamesp) {
1206
+                                                           extenlst = "";
1207
+                                                      } else {
1208
+                                                           extenlst = extenlst.toLowerCase();
1209
+                                                      }
1210
+
1211
+                                                      $("#smstables").empty();
1212
+                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1213
+
1214
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1215
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1216
+                                                      } else if (extenlst == 'png') {
1217
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1218
+                                                      } else if (extenlst == 'gif') {
1219
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1220
+                                                      } else if (extenlst == 'bmp') {
1221
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1222
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1223
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1224
+                                                              var xhr = new XMLHttpRequest();
1225
+                                                              xhr.responseType = 'arraybuffer';
1226
+                                                              xhr.open('GET', tiffile);
1227
+                                                              xhr.onload = function (evnt) {
1228
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1229
+                                                                  var tifcanvas = tiff.toCanvas();
1230
+                                                                  $("#smstables").append(tifcanvas);
1231
+                                                              };
1232
+                                                              xhr.send();
1233
+                                                      } else if (extenlst == 'pdf') {
1234
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1235
+                                                              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>');
1236
+                                                              $("#smstables").append($iframe);
1237
+                                                      } else if (extenlst == 'txt') {
1238
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1239
+                                                      } else if (extension == 'mp4') {
1240
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1241
+						      } else if (extension == 'ogg') {
1242
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
+						      } else if (extension == 'avi') {
1244
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1245
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1246
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1247
+						      } else if (extension == 'wav' || extension == 'wave') {
1248
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1249
+						      } else if (extension == 'mp3') {
1250
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1251
+						      } else if (extension == 'midi') {
1252
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1253
+						      }
1254
+
1255
+                                                      $("#smstables").show();
1256
+                                                      $("#mmsfoldersview").hide();
1257
+                                                   });
1258
+                                                });
1259
+
1260
+
1261
+                                                // Remove picked files
1262
+                                                $('[class*="indpckfldl"]').last().click(function() {
1263
+                                                    var userid = "<?php p($userId); ?>";
1264
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1265
+
1266
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1267
+
1268
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1269
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1270
+
1271
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1272
+                                                    $(this).hide();
1273
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1274
+
1275
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1276
+                                                             return value != removedfilename;
1277
+                                                    });
1278
+
1279
+                                                    $.ajax({
1280
+                                                        url: baseUrl + '/' + userid,
1281
+                                                        type: "POST",
1282
+                                                        data: {removedfilename: removedfilename},
1283
+                                                        success: function(totalflsize) {
1284
+
1285
+                                                             msgtotalflsize = totalflsize;
1286
+                                                             $('#filessizetext').text(totalflsize);
1287
+                                                             adjustMaximumSize(uploadedtomms);
1288
+
1289
+                                                             // Check message size
1290
+                                                             var rectotfilesz = parseFloat(totalflsize);
1291
+
1292
+                                                             if (rectotfilesz > maximumsize) {
1293
+                                                                 $('#filestotsize').css('color', '#ba3555');
1294
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1295
+                                                                 $('#submitsms').attr("disabled", true);
1296
+                                                             } else {
1297
+                                                                 $('#submitsms').attr("disabled", false);
1298
+                                                                 $('#filestotsize').css('color', '#189558');
1299
+                                                               }
1300
+
1301
+                                                             // Rewrite order numbers for files that follow
1302
+                                                             --n;
1303
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1304
+
1305
+                                                                  var getdivtext =  $(this).text();
1306
+                                                                  var splitdivtext = getdivtext.split(") ");
1307
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1308
+                                                                  var newnbvalue = currentnbvalue - 1;
1309
+
1310
+                                                                  if (currentnbvalue > removedflnb) {
1311
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1312
+                                                                      $(this).text(replacedstr);
1313
+                                                                  }
1314
+                                                             });
1315
+                                                        },
1316
+                                                        error: function() {
1317
+                                                                  showAlert("Error while removing the file.");
1318
+                                                        }
1319
+                                                    });
1320
+
1321
+                                                    $('#smstables').removeClass('icon-loading');
1322
+                                                    $("#smstables").empty();
1323
+                                                });
1324
+
1325
+
1326
+		                                // Preview the picked file
1327
+		                                $("#mmsfoldersview").css("display", "inline-block");
1328
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1329
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1330
+
1331
+                                                $("#smstables").empty();
1332
+                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1333
+
1334
+						if (extension == 'jpg' || extension == 'jpeg') {
1335
+
1336
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1337
+
1338
+		                                } else if (extension == 'png') {
1339
+
1340
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1341
+
1342
+		                                } else if (extension == 'gif') {
1343
+
1344
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1345
+
1346
+		                                } else if (extension == 'bmp') {
1347
+
1348
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1349
+
1350
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1351
+
1352
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1353
+		                                       var xhr = new XMLHttpRequest();
1354
+		                                       xhr.responseType = 'arraybuffer';
1355
+		                                       xhr.open('GET', tiffile);
1356
+		                                       xhr.onload = function (event) {
1357
+		                                           var tiff = new Tiff({buffer: xhr.response});
1358
+		                                           var tifcanvas = tiff.toCanvas();
1359
+		                                           $("#smstables").append(tifcanvas);
1360
+		                                       };
1361
+		                                       xhr.send();
1362
+
1363
+		                                } else if (extension == 'pdf') {
1364
+
1365
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
+		                                       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>');
1367
+		                                       $("#smstables").append($iframe);
1368
+
1369
+		                                } else if (extension == 'txt') {
1370
+
1371
+							     $.get(flUrl, function(textdata) {
1372
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1373
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1374
+							     });
1375
+
1376
+		                                } else if (extension == 'mp4') {
1377
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1378
+						} else if (extension == 'ogg') {
1379
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1380
+						} else if (extension == 'avi') {
1381
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1382
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1383
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1384
+						} else if (extension == 'wav' || extension == 'wave') {
1385
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1386
+						} else if (extension == 'mp3') {
1387
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1388
+						} else if (extension == 'midi') {
1389
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1390
+						}
1391
+
1392
+
1393
+		                                $("#smstables").show();
1394
+
1395
+		                                $('#pf_choose_msg').hide();
1396
+		                                $('#smstables').removeClass('icon-loading');
1397
+		                                $("#mmsfoldersview").hide();
1398
+
1399
+                                          },
1400
+
1401
+                                          error: function(data){
1402
+                                                      showAlert("Error while getting the file.");
1403
+                                          }
1404
+
1405
+                                       });
1406
+
1407
+                                    } else {
1408
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1409
+                                        $('#pf_choose_msg').hide();
1410
+                                        $('#smstables').removeClass('icon-loading');
1411
+                                      }
1412
+                                 } else {
1413
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1414
+                                      $('#pf_choose_msg').hide();
1415
+                                      $('#smstables').removeClass('icon-loading');
1416
+                                   }
1417
+
1418
+                              } else {
1419
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1420
+                                   $('#pf_choose_msg').hide();
1421
+                                   $('#smstables').removeClass('icon-loading');
1422
+                                }
1423
+
1424
+                        }
1425
+                );
1426
+  });
1427
+
1428
+
1429
+
1430
+  // Send the SMS/MMS message
1431
+  $("#submitsms").on("click", function(event) {
1432
+
1433
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1434
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1435
+     $("#sms_submit_msg").css("display", "inline-block");
1436
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1437
+
1438
+     if (selectedid != '') { 
1439
+
1440
+         var sendersplit = selectedid.split(":");
1441
+         var providercap = sendersplit[0];
1442
+         var provsec = sendersplit[1];
1443
+
1444
+         if (/[a-zA-Z]/.test(provsec)) {
1445
+             var alphanumcheck = true;
1446
+         } else { var alphanumcheck = false; }
1447
+
1448
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1449
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1450
+             var selectedsender = "+" + senderproc;
1451
+             var providerUsed = "telnyx";
1452
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1453
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1454
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1455
+             var providerUsed = "plivo";
1456
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1457
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1458
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
+             var selectedsender = "+" + senderproc;
1460
+             var providerUsed = "twilio";
1461
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1462
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1463
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1464
+             var selectedsender = "+" + senderproc;
1465
+             var providerUsed = "flowroute";
1466
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1467
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1468
+             var selectedsender = provsec;
1469
+             var providerUsed = "telnyx";
1470
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1471
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1472
+             var selectedsender = provsec;
1473
+             var providerUsed = "plivo";
1474
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1475
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1476
+             var selectedsender = provsec;
1477
+             var providerUsed = "twilio";
1478
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1479
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1480
+             var selectedsender = provsec;
1481
+             var providerUsed = "flowroute";
1482
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1483
+         }
1484
+
1485
+         // Get the interval between message consecutive sending requests, if it's the case
1486
+         if ($('#tomultchckbx').is(':checked')) {
1487
+
1488
+             var numbersfile = 1;
1489
+             var initinterval = $("#multsmsinterval").val();
1490
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1491
+
1492
+             if (secinterval != '') {
1493
+                 var tertinterval = parseInt(secinterval);
1494
+                     waittime = tertinterval;
1495
+             }
1496
+
1497
+         } else {
1498
+
1499
+             var numbersfile = 0;
1500
+             var toNumberinit = $('#smsto').val();
1501
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1502
+             var toNumbersec = toNumber.split(",");
1503
+
1504
+                 for (var i = 0; i < toNumbersec.length; i++) {
1505
+                      toNumbersec[i] = "+" + toNumbersec[i];
1506
+                 }
1507
+
1508
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1509
+         }
1510
+
1511
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1512
+
1513
+         var smstext = $("#smstext").val();
1514
+
1515
+         if (receiversNumbers.length != 0) {
1516
+
1517
+              if (smstext != '') {
1518
+                  $.ajax({
1519
+                     url: relbaseUrl + '/' + userid,
1520
+                     type: "POST",
1521
+                     data: {
1522
+                           receiversPhoneNbs: receiversNumbers,
1523
+                           fromsender: selectedsender,
1524
+                           waitinterval: waittime,
1525
+                           sentsmstext: smstext,
1526
+                           ismms: isMMS,
1527
+                           mmsfiles: uploadedtomms
1528
+                         },
1529
+                     success: function() {
1530
+
1531
+                           if (receiversNumbers.length == 1) {
1532
+                                   showAlert("The message has been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1533
+                           } else {
1534
+                                   showAlert("The messages have been sent ! You can press the 'Sent Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1535
+                           }
1536
+
1537
+                           $('#sms_submit_msg').hide();
1538
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1539
+                     },
1540
+                     error: function() {
1541
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1542
+                           $('#sms_submit_msg').hide();
1543
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1544
+                     }
1545
+                  });
1546
+              } else {
1547
+                     showAlert("Please enter a message in the text box !");
1548
+
1549
+                     $('#sms_submit_msg').hide();
1550
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1551
+              }
1552
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1553
+                 showAlert("Please enter the recipient's phone number !");
1554
+                 $('#sms_submit_msg').hide();
1555
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1556
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1557
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1558
+                 $('#sms_submit_msg').hide();
1559
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
+         }
1561
+     } else {
1562
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1563
+           $("#induploadfile").remove();
1564
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
+           $('#sms_submit_msg').hide();
1566
+     }
1567
+
1568
+  });
1569
+
1570
+  // Check the checkbox to delete old messages from the database
1571
+  $('#deleteoldchckbox').change(function() {
1572
+     if ($(this).is(':checked')) {
1573
+         $("#deleteoldsms").css("display", "block");
1574
+     } else {
1575
+         $("#deleteoldsms").css("display", "none");
1576
+     }
1577
+  });
1578
+
1579
+  // Set the height of info notes
1580
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1581
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1582
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1583
+
1584
+  $(window).resize(function() { 
1585
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1586
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1587
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1588
+  });
1589
+
1590
+
1591
+  function showAlert(alertText) {
1592
+
1593
+     $("#alertMsgOverlay").remove();
1594
+     $("#alertMessage").remove();
1595
+
1596
+     let alertwnd = "<div id='alertMessage'>";
1597
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1598
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1599
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1600
+     alertwnd += "</div>";
1601
+
1602
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1603
+     $("#content").append(alertwnd);
1604
+
1605
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1606
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1607
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1608
+
1609
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1610
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1611
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1612
+  }
Browse code

removed files to implement CSS changes required by Nextcloud 28

DoubleBastionAdmin authored on 17/12/2023 00:56:54
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1610 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  function cleanTempDirectory() {
235
-
236
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
-
238
-     $.ajax({
239
-          url: cleanflUrl + '/' + userid,
240
-          type: "POST",
241
-          data: { userid: userid },
242
-          cache: false,
243
-          processData: false,
244
-          contentType: false
245
-     });
246
-  }
247
-  cleanTempDirectory();
248
-
249
-  // Clean the SMS_Relentless/multiple_recipients directory
250
-  function cleanMultRecDirectory() {
251
-
252
-     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
-
254
-     $.ajax({
255
-          url: cleanflUrl + '/' + userid,
256
-          type: "POST",
257
-          data: { userid: userid },
258
-          cache: false,
259
-          processData: false,
260
-          contentType: false
261
-     });
262
-  }
263
-  cleanMultRecDirectory();
264
-
265
-  // Check the available balance
266
-  $("#smsprovider").on("change", function () {
267
-
268
-     var provider = $('#smsprovider :selected').val();
269
-
270
-     if (provider == "Telnyx") {
271
-
272
-        var gettelbalance = function() {
273
-
274
-          $('#currentbalance').addClass('icon-loading');
275
-
276
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
-
278
-          $.ajax({
279
-              url: gettelbalanceUrl + '/' + userid,
280
-              type: "POST",
281
-              data: { userid: userid },
282
-              cache: false,
283
-              processData: false,
284
-              contentType: false,
285
-              success: function(currentbalancetel) {
286
-
287
-                     $('#currentbalance').empty();
288
-                     $('#currentbalance').text(currentbalancetel);
289
-                     $('#currentbalance').removeClass('icon-loading');
290
-              }
291
-          });
292
-        }
293
-
294
-        gettelbalance();
295
-
296
-     } else if (provider == "Plivo") {
297
-
298
-          var getnexbalance = function() {
299
-
300
-            $('#currentbalance').addClass('icon-loading');
301
-
302
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
-
304
-            $.ajax({
305
-                url: getnexbalanceUrl + '/' + userid,
306
-                type: "POST",
307
-                data: { userid: userid },
308
-                cache: false,
309
-                processData: false,
310
-                contentType: false,
311
-                success: function(currentbalancenex) {
312
-
313
-                     $('#currentbalance').empty();
314
-                     $('#currentbalance').text(currentbalancenex);
315
-                     $('#currentbalance').removeClass('icon-loading');
316
-                }
317
-            });
318
-          }
319
-
320
-          getnexbalance();
321
-
322
-     } else if (provider == "Twilio") {
323
-
324
-          var gettwilbalance = function() {
325
-
326
-            $('#currentbalance').addClass('icon-loading');
327
-
328
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
-
330
-            $.ajax({
331
-                url: gettwilbalanceUrl + '/' + userid,
332
-                type: "POST",
333
-                data: { userid: userid },
334
-                cache: false,
335
-                processData: false,
336
-                contentType: false,
337
-                success: function(currentbalancetwil) {
338
-
339
-                     $('#currentbalance').empty();
340
-                     $('#currentbalance').text(currentbalancetwil);
341
-                     $('#currentbalance').removeClass('icon-loading');
342
-                }
343
-            });
344
-          }
345
-
346
-          gettwilbalance();
347
-
348
-     } else if (provider == "Flowroute") {
349
-
350
-          var getflowbalance = function() {
351
-
352
-            $('#currentbalance').addClass('icon-loading');
353
-
354
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
-
356
-            $.ajax({
357
-                url: getflowbalanceUrl + '/' + userid,
358
-                type: "POST",
359
-                data: { userid: userid },
360
-                cache: false,
361
-                processData: false,
362
-                contentType: false,
363
-                success: function(currentbalanceflow) {
364
-
365
-                     $('#currentbalance').empty();
366
-                     $('#currentbalance').text(currentbalanceflow);
367
-                     $('#currentbalance').removeClass('icon-loading');
368
-                }
369
-            });
370
-          }
371
-
372
-          getflowbalance();
373
-
374
-       } else if (provider == "") {
375
-                $('#currentbalance').text("");
376
-                $('#currentbalance').removeClass('icon-loading');
377
-       }
378
-  });
379
-
380
-
381
-  // If a Sender ID is selected
382
-  $("#currentsmsnmbrs").on("change", function () {
383
-
384
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
-
386
-              selectedid = $('#currentsmsnmbrs :selected').val();
387
-              var setIdsplit = selectedid.split(":");
388
-	      chosenProvider = setIdsplit[0];
389
-
390
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
391
-	      if (chosenProvider == "Tx") {
392
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
393
-		  // Maximum size of message text + files in KB
394
-		  maximumsize = 1024;
395
-                  maximumsizeinit = 1024;
396
-		  maxsizenonimage = 600;
397
-		  maximumfilenumber = 10;
398
-                  chosenProvFullName = "Telnyx";
399
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
400
-                                     or gif files, the size of all the files plus the size of the text should be \
401
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
402
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
403
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
404
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
405
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
406
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
407
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
408
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
409
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
410
-                  $("#tooltiptextfourth").html(infonotecontent);
411
-	      } else if (chosenProvider == "Pl") {
412
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
413
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
414
-		  // Maximum size of message text + files in KB
415
-		  maximumsize = 5120;
416
-                  maximumsizeinit = 5120;
417
-		  maxsizenonimage = 600;
418
-		  maximumfilenumber = 10;
419
-                  chosenProvFullName = "Plivo";
420
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
421
-                                     or gif files, the size of all the files plus the size of the text should be \
422
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
423
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
424
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
425
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
426
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
427
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
428
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
429
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
430
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
431
-                  $("#tooltiptextfourth").html(infonotecontent);
432
-	      } else if (chosenProvider == "Tw") {
433
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
434
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
435
-                                     "icalendar", "directory", "pdf", "pkpass"];
436
-		  // Maximum size of message text + files in KB
437
-		  maximumsize = 5120;
438
-                  maximumsizeinit = 5120;
439
-		  maxsizenonimage = 600;
440
-		  maximumfilenumber = 10;
441
-                  chosenProvFullName = "Twilio";
442
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
443
-                                     or gif files, the size of all the files plus the size of the text should be \
444
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
445
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
446
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
447
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
448
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
449
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
450
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
451
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
452
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
453
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
454
-                                     previewed in the adjoining pane."
455
-                  $("#tooltiptextfourth").html(infonotecontent);
456
-	      } else if (chosenProvider == "Fl") {
457
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
458
-		  // Maximum size of message text + files in KB
459
-		  maximumsize = 750;
460
-                  maximumsizeinit = 750;
461
-		  maxsizenonimage = 600;
462
-		  maximumfilenumber = 10;
463
-                  chosenProvFullName = "Flowroute";
464
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
465
-                                     png or gif files, the size of all the files plus the size of the text should be \
466
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
467
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
468
-                                     size of the files plus the size of the text should be 600 KB or less. \
469
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
470
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
471
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
472
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
473
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
474
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
475
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
476
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
477
-                  $("#tooltiptextfourth").html(infonotecontent);
478
-	      }
479
-
480
-          } else { selectedid = ''; }
481
-  });
482
-
483
-  // Check the checkbox to send SMS message to multiple recipients
484
-  $('#tomultchckbx').change(function() {
485
-      if ($(this).is(':checked')) {
486
-          $("#multiplerecivers").css("display", "block");
487
-          $("#smstodiv").css("visibility", "hidden");
488
-          $("#smsto").val("");
489
-
490
-          receiversNumbers.length = 0;
491
-
492
-      } else {
493
-          $("#multiplerecivers").css("display", "none");
494
-          $("#smstodiv").css("visibility", "visible");
495
-
496
-          // Remove the uploaded files' names if any
497
-          $("#induploadfile").remove();
498
-
499
-          // Remove all the files from the SMS_Relentless/multiple_recipients directory
500
-          cleanMultRecDirectory();
501
-
502
-          $("#smstables").empty();
503
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
504
-
505
-          receiversNumbers.length = 0;
506
-      }
507
-  });
508
-
509
-  // Upload the file with the recipients' phone numbers
510
-  $("#uploadfileforsms").change(function(e) {
511
-
512
-     $("#fileuploadednm").empty();
513
-
514
-     receiversNumbers.length = 0;
515
-
516
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
517
-
518
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
519
-
520
-     var formData = new FormData();
521
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
522
-
523
-     var fileup = $('#uploadfileforsms').val();
524
-     var fileuptrim = fileup.split('\\').pop();
525
-
526
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
527
-
528
-     var extension = fileup.replace(/^.*\./, '');
529
-
530
-     if (extension == fileup) {
531
-         extension = "";
532
-     } else {
533
-         extension = extension.toLowerCase();
534
-     }
535
-
536
-     var validExtensionsmrec = ["txt", "csv"];
537
-
538
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
539
-
540
-       if (selectedid != '') {
541
-
542
-               $.ajax({
543
-                 url: baseUrl + '/' + userid,
544
-                 type: "POST",
545
-                 data: formData,
546
-                 cache: false,
547
-                 processData: false,
548
-                 contentType: false,
549
-                 success: function(numberarray) {
550
-
551
-		    if (numberarray.length > 0) {
552
-
553
-		        // Get the array of the receivers' phone numbers
554
-		        if (chosenProvider == "Tx") {
555
-
556
-		             for(key in numberarray) {
557
-		                 receiversNumbers.push("+"+numberarray[key]);
558
-		             }
559
-
560
-		        } else if (chosenProvider == "Pl") {
561
-
562
-		             for(key in numberarray) {
563
-		                 receiversNumbers.push(numberarray[key]);
564
-		             }
565
-
566
-		          } else if (chosenProvider == "Tw") {
567
-
568
-		             for(key in numberarray) {
569
-		                 receiversNumbers.push(numberarray[key]);
570
-		             }
571
-		          } else if (chosenProvider == "Fl") {
572
-
573
-		             for(key in numberarray) {
574
-		                 receiversNumbers.push(numberarray[key]);
575
-		             }
576
-		          }
577
-
578
-		    } else {
579
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
580
-		    }
581
-                            
582
-                    // Preview the uploaded file
583
-                    var smsfilename = e.target.files[0].name;
584
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
585
-
586
-                    var reader = new FileReader();
587
-                    reader.readAsText(e.target.files[0]);
588
-                    reader.onload = function(e) {
589
-                          $("#smstables").empty();
590
-                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
591
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
592
-                    };
593
-
594
-                    $("#smstables").show();
595
-
596
-                    $('#sms_upload_msg').hide();
597
-                    $('#smstables').removeClass('icon-loading');
598
-
599
-                  },
600
-                  error: function() {
601
-                             showAlert("Error while uploading the file.");
602
-                  }
603
-               });
604
-
605
-        } else {
606
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
607
-               $("#induploadfile").remove();
608
-               $('#sms_upload_msg').hide();
609
-               $('#smstables').removeClass('icon-loading');
610
-        }
611
-
612
-     } else {
613
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
614
-          $('#pf_upload_msg').hide();
615
-          $('#smstables').removeClass('icon-loading');
616
-
617
-          $("#induploadfile").remove();
618
-          $("#sms_upload_msg").hide();
619
-     }
620
-
621
-     // Preview uploaded file when clicked
622
-     $("#indfilediv").on("click", function() {
623
-
624
-          var smsfilename = e.target.files[0].name;
625
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
626
-
627
-          var reader = new FileReader();
628
-          reader.readAsText(e.target.files[0]);
629
-          reader.onload = function(e) {
630
-                  $("#smstables").empty();
631
-                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
632
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
633
-          };
634
-
635
-          $("#smstables").show();
636
-          $('#sms_upload_msg').hide();
637
-          $('#smstables').removeClass('icon-loading');
638
-     });
639
-
640
-     // Remove selected file
641
-     $("#indivflremove").on("click", function() {
642
-
643
-          $("#induploadfile").remove();
644
-          $("#sms_upload_msg").hide();
645
-
646
-          receiversNumbers.length = 0;
647
-
648
-          cleanMultRecDirectory();
649
-     });
650
-
651
-  });
652
-
653
-  // Show the number of characters entered in the SMS textarea and the text size in KB
654
-  $("#smstext").on('input', function() {
655
-
656
-     $("#char_count").css("display", "inline");
657
-
658
-     $("#mtextSize").css("display", "inline");
659
-
660
-     $(".maxmessagelength").css("display", "inline-block");
661
-
662
-     $("#countchnb").text($(this).val().length);
663
-
664
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
665
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
666
-     $("#textsizeinkb").text(textsizekb);
667
-
668
-     if ($(this).val().length > charcolorthr) {
669
-         $("#char_count").css("color", "#BB2E4B");
670
-     } else {
671
-         $("#char_count").css("color", "#4cbc86;");
672
-     }
673
-
674
-  });
675
-
676
-
677
-  // Check the checkbox to send file(s) as MMS
678
-  $('#mediafilechckbx').change(function() {
679
-
680
-      if ($(this).is(':checked')) {
681
-
682
-          isMMS = 1;
683
-          if (selectedid == '') {
684
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
685
-              $(this).prop("checked", false);
686
-              isMMS = 0;
687
-              return;
688
-          }
689
-          $("#upmediafiles").css("display", "block");
690
-          $("#submitsms").prop("value", "Send MMS");
691
-
692
-      } else {
693
-
694
-          isMMS = 0;
695
-          $("#upmediafiles").css("display", "none");
696
-          $("#submitsms").prop("value", "Send SMS");
697
-
698
-          // Remove the uploaded files' names if any
699
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
700
-          $(".indgenpckfls").each(function() { $(this).remove(); });
701
-
702
-          // Remove all the files from the SMS_Relentless/temp_files directory
703
-          cleanTempDirectory();
704
-
705
-          $("#smstables").empty();
706
-          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
707
-
708
-          uploadedtomms = [];
709
-          n = 1;
710
-
711
-          msgtotalflsize = 0;
712
-
713
-          $("#filestotsize").hide();
714
-      }
715
-  });
716
-
717
-
718
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
719
-  function adjustMaximumSize(uploadedtomms) {
720
-				      
721
-      var nonimgcheck = 0;
722
-      for (var u = 0; u < uploadedtomms.length; u++) {
723
-	   var crupfl = uploadedtomms[u];
724
-	   var extensionup = crupfl.replace(/^.*\./, '');
725
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
726
-	       nonimgcheck = 1;
727
-	   }
728
-      }
729
-
730
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
731
-  }
732
-
733
-  // Upload files to be sent as MMS
734
-  $("#uploadfileformms").change(function(e) {
735
-
736
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
737
-     $('#smstables').addClass('icon-loading');
738
-     $('#filestotsize').show();
739
-
740
-     var userid = "<?php p($userId); ?>";
741
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
742
-
743
-     var formData = new FormData();
744
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
745
-
746
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
747
-
748
-     // Add the size of the current file to the total size of all the files
749
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
750
-
751
-     var fileup = $('#uploadfileformms').val();
752
-     var fileuptrim = fileup.split('\\').pop();
753
-
754
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
755
-         var duplicatescheck = 1;
756
-     } else { 
757
-         var duplicatescheck = 0;
758
-     }
759
-
760
-     var extension = fileup.replace(/^.*\./, '');
761
-
762
-     if (extension == fileup) {
763
-         extension = "";
764
-     } else {
765
-         extension = extension.toLowerCase();
766
-     }
767
-
768
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
769
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
770
-         maximumsize = maxsizenonimage;
771
-     }
772
-
773
-     if ($.inArray(extension, validExtensions) != -1) {
774
-
775
-       if (duplicatescheck == 0) {
776
-
777
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
778
-
779
-            if (n <= maximumfilenumber) {
780
-
781
-               $.ajax({
782
-                 url: baseUrl + '/' + userid,
783
-                 type: "POST",
784
-                 data: formData,
785
-                 cache: false,
786
-                 processData: false,
787
-                 contentType: false,
788
-                 success: function(totalflsize) {
789
-
790
-                   uploadedtomms.push(fileuptrim);
791
-
792
-                   $('#filessizetext').text(totalflsize);
793
-
794
-                   var rectotfilesz = parseFloat(totalflsize);
795
-
796
-                   if (rectotfilesz <= maximumsize) {
797
-                       $('#submitsms').attr("disabled", false);
798
-                       $('#filestotsize').css('color', '#189558');
799
-                   } else {
800
-                       $('#filestotsize').css('color', '#ba3555');
801
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
802
-                       $('#submitsms').attr("disabled", true);
803
-                       $('#smstables').removeClass('icon-loading');
804
-                       $('#pf_upload_msg').hide();
805
-                   }
806
-
807
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
808
-                   n++;
809
-
810
-                   // Preview the file when you click on its name
811
-                   $("div:visible[id*='indfilediv']").each(function() {
812
-
813
-                        $(this).on("click", function(eventclck) {
814
-
815
-                           $("#mmsfoldersview").css("display", "inline-block");
816
-                           var mmsfilenameinit = $(this).text();
817
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
818
-                           var mmsfilename = mmsfilenamesec.replace("X","");
819
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
820
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
821
-
822
-                           if (extenlst == mmsfilename) {
823
-                               extenlst = "";
824
-                           } else {
825
-                               extenlst = extenlst.toLowerCase();
826
-                           }
827
-
828
-                           $("#smstables").empty();
829
-                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
830
-
831
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
832
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
833
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
834
-                           } else if (extenlst == 'png') {
835
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
836
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
837
-                           } else if (extenlst == 'gif') {
838
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
839
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
840
-                           } else if (extenlst == 'bmp') {
841
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
842
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
843
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
844
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
-                                  var xhr = new XMLHttpRequest();
846
-                                  xhr.responseType = 'arraybuffer';
847
-                                  xhr.open('GET', tiffile);
848
-                                  xhr.onload = function (evnt) {
849
-                                      var tiff = new Tiff({buffer: xhr.response});
850
-                                      var tifcanvas = tiff.toCanvas();
851
-                                      $("#smstables").append(tifcanvas);
852
-                                  };
853
-                                  xhr.send();
854
-                           } else if (extenlst == 'pdf') {
855
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
856
-                                  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>');
857
-                                  $("#smstables").append($iframe);
858
-                           } else if (extenlst == 'txt') {
859
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
860
-                           } else if (extension == 'mp4') {
861
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
862
-		           } else if (extension == 'ogg') {
863
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
864
-		           } else if (extension == 'avi') {
865
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
866
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
867
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
868
-		           } else if (extension == 'wav' || extension == 'wave') {
869
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
870
-		           } else if (extension == 'mp3') {
871
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
872
-		           } else if (extension == 'midi') {
873
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
874
-		           }
875
-
876
-                           $("#smstables").show();
877
-                           $("#mmsfoldersview").hide();
878
-                        });
879
-                   });
880
-
881
-                   // Remove uploaded files
882
-                   $('[class*="indupfldl"]').last().click(function() {
883
-
884
-                           var userid = "<?php p($userId); ?>";
885
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
886
-
887
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
888
-
889
-                           var removedfilesplit = removedfilenameinit.split(") ");
890
-                           var removedflnb = parseInt(removedfilesplit[0]);
891
-
892
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
893
-                           $(this).hide();
894
-
895
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
896
-
897
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
898
-                                           return value != removedfilename;
899
-                           });
900
-
901
-                           $.ajax({
902
-                                   url: baseUrl + '/' + userid,
903
-                                   type: "POST",
904
-                                   data: {removedfilename: removedfilename},
905
-                                   success: function(totalflsize) {
906
-
907
-                                      msgtotalflsize = totalflsize;
908
-                                      $('#filessizetext').text(totalflsize);
909
-
910
-                                      adjustMaximumSize(uploadedtomms);
911
-
912
-                                      // Check message size
913
-                                      var rectotfilesz = parseFloat(totalflsize);
914
-
915
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
916
-                                          $('#submitsms').attr("disabled", false);
917
-                                          $('#filestotsize').css('color', '#189558');
918
-                                      } else {
919
-                                          $('#filestotsize').css('color', '#ba3555');
920
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
921
-                                          $('#submitsms').attr("disabled", true);
922
-                                      }
923
-
924
-                                      // Rewrite order numbers for files that follow
925
-                                      --n;
926
-                                      $("div:visible[id*='indfilediv']").each(function() {
927
-
928
-                                          var getdivtext =  $(this).text();
929
-                                          var splitdivtext = getdivtext.split(") ");
930
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
931
-                                          var newnbvalue = currentnbvalue - 1;
932
-
933
-                                          if (currentnbvalue > removedflnb) {
934
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
935
-                                              $(this).text(replacedstr);
936
-                                          }
937
-                                      });
938
-
939
-                                      $("div:visible[id*='indflpicked']").each(function() {
940
-
941
-                                          var getdivtext =  $(this).text();
942
-                                          var splitdivtext = getdivtext.split(") ");
943
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
944
-                                          var newnbvalue = currentnbvalue - 1;
945
-
946
-                                          if (currentnbvalue > removedflnb) {
947
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
948
-                                              $(this).text(replacedstr);
949
-                                          }
950
-                                      });
951
-
952
-                                   },
953
-                                   error: function() {
954
-                                              showAlert("Error while removing the file(s).");
955
-                                   }
956
-                           });
957
-
958
-                           $('#smstables').removeClass('icon-loading');
959
-                           $("#smstables").empty();
960
-                   });
961
-
962
-                   // Preview the uploaded file
963
-                   $("#mmsfoldersview").css("display", "inline-block");
964
-                   var mmsfilename = e.target.files[0].name;
965
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
966
-
967
-                   $("#smstables").empty();
968
-                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
969
-
970
-                   if (extension == 'jpg' || extension == 'jpeg') {
971
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
972
-
973
-                              var reader = new FileReader();
974
-                              reader.onload = function (e) {
975
-                                  readjpg[mmsfilename] = e.target.result;
976
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
977
-                              }
978
-                              reader.readAsDataURL(e.target.files[0]);
979
-                   } else if (extension == 'png') {
980
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
981
-
982
-                              var reader = new FileReader();
983
-                              reader.onload = function (e) {
984
-                                  readpng[mmsfilename] = e.target.result;
985
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
986
-                              }
987
-                              reader.readAsDataURL(e.target.files[0]);
988
-
989
-                   } else if (extension == 'gif') {
990
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
991
-
992
-                              var reader = new FileReader();
993
-                              reader.onload = function (e) {
994
-                                  readgif[mmsfilename] = e.target.result;
995
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
996
-                              }
997
-                              reader.readAsDataURL(e.target.files[0]);
998
-
999
-                   } else if (extension == 'bmp') {
1000
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1001
-
1002
-                              var reader = new FileReader();
1003
-                              reader.onload = function (e) {
1004
-                                  readbmp[mmsfilename] = e.target.result;
1005
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1006
-                              }
1007
-                              reader.readAsDataURL(e.target.files[0]);
1008
-
1009
-                   } else if (extension == 'tif' || extension == 'tiff') {
1010
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1011
-                              var xhr = new XMLHttpRequest();
1012
-                              xhr.responseType = 'arraybuffer';
1013
-                              xhr.open('GET', tiffile);
1014
-                              xhr.onload = function (e) {
1015
-                                  var tiff = new Tiff({buffer: xhr.response});
1016
-                                  var tifcanvas = tiff.toCanvas();
1017
-                                  $("#smstables").append(tifcanvas);
1018
-                              };
1019
-                              xhr.send();
1020
-
1021
-                   } else if (extension == 'pdf') {
1022
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1023
-                              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>');
1024
-                              $("#smstables").append($iframe);
1025
-
1026
-                   } else if (extension == 'txt') {
1027
-                              var reader = new FileReader();
1028
-                              reader.readAsText(e.target.files[0]);
1029
-                              reader.onload = function(e) {
1030
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1031
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1032
-                              };
1033
-                   } else if (extension == 'mp4') {
1034
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1035
-                   } else if (extension == 'ogg') {
1036
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1037
-                   } else if (extension == 'avi') {
1038
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1039
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1040
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1041
-                   } else if (extension == 'wav' || extension == 'wave') {
1042
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1043
-                   } else if (extension == 'mp3') {
1044
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1045
-                   } else if (extension == 'midi') {
1046
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1047
-                   }
1048
-
1049
-                   $("#smstables").show();
1050
-                   $('#pf_upload_msg').hide();
1051
-                   $('#smstables').removeClass('icon-loading');
1052
-                   $("#mmsfoldersview").hide();
1053
-                 },
1054
-                 error: function() {
1055
-                              showAlert("Error while uploading the file.");
1056
-                 }
1057
-               });
1058
-
1059
-            } else {
1060
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1061
-                  adjustMaximumSize(uploadedtomms);
1062
-
1063
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1064
-                  $('#pf_upload_msg').hide();
1065
-                  $('#smstables').removeClass('icon-loading');
1066
-            }
1067
-         } else {
1068
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1069
-              adjustMaximumSize(uploadedtomms);
1070
-
1071
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1072
-              $('#pf_upload_msg').hide();
1073
-              $('#smstables').removeClass('icon-loading');
1074
-         }
1075
-       } else {
1076
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1077
-            adjustMaximumSize(uploadedtomms);
1078
-
1079
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1080
-            $('#pf_upload_msg').hide();
1081
-            $('#smstables').removeClass('icon-loading');
1082
-       }
1083
-
1084
-     } else {
1085
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1086
-          adjustMaximumSize(uploadedtomms);
1087
-
1088
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1089
-          $('#pf_upload_msg').hide();
1090
-          $('#smstables').removeClass('icon-loading');
1091
-     }
1092
-  });
1093
-
1094
-
1095
-  // Pick file(s) from Nextcloud, to send as MMS
1096
-  var mmsfilename = null;
1097
-
1098
-  $("#choosefilen").on("click", function(evn) {
1099
-
1100
-                OC.dialogs.filepicker(
1101
-                        t('settings', "Select a file to send as MMS."),
1102
-                        function (path) {
1103
-
1104
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1105
-                              $('#smstables').addClass('icon-loading');
1106
-                              $('#filestotsize').show();
1107
-
1108
-                              var userid = "<?php p($userId); ?>";
1109
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1110
-
1111
-                              mmsfilename = path.split('/').pop();
1112
-
1113
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1114
-                                  var duplicatescheck = 1;
1115
-                              } else var duplicatescheck = 0;
1116
-
1117
-                              var extension = mmsfilename.replace(/^.*\./, '');
1118
-
1119
-                              if (extension == mmsfilename) {
1120
-                                  extension = "";
1121
-                              } else {
1122
-                                  extension = extension.toLowerCase();
1123
-                              }
1124
-
1125
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1126
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1127
-				   maximumsize = maxsizenonimage;
1128
-			      }
1129
-
1130
-                              if ($.inArray(extension, validExtensions) != -1) {
1131
-
1132
-                                 if (duplicatescheck == 0) {
1133
-
1134
-                                    if (n <= maximumfilenumber) {
1135
-
1136
-                                       $.ajax({
1137
-                                          url: baseUrl + '/' + userid,
1138
-                                          type: "POST",
1139
-                                          data: { path: path },
1140
-                                          success: function(pickresult) {
1141
-
1142
-                                                uploadedtomms.push(mmsfilename);
1143
-
1144
-                                                var totalflsize = pickresult[0];
1145
-                                                var pickedflsize = pickresult[1];
1146
-
1147
-                                                // Check message size
1148
-                                                var rectotfilesz = parseFloat(totalflsize);
1149
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1150
-
1151
-                                                if (filesplustextsize <= maximumsize) {
1152
-
1153
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1154
-
1155
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1156
-                                                    n++;
1157
-
1158
-                                                    msgtotalflsize = totalflsize;
1159
-                                                    $('#filessizetext').text(totalflsize);
1160
-                                                    $('#filestotsize').css('color', '#189558');
1161
-
1162
-                                                } else {
1163
-
1164
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1165
-                                                    $('#filestotsize').css('color', '#ba3555');
1166
-                                                    msgtotalflsize -= pickedflsize;
1167
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1168
-
1169
-                                                    $.ajax({
1170
-                                                        url: baseUrlindrm + '/' + userid,
1171
-                                                        type: "POST",
1172
-                                                        data: {removedfilename: mmsfilename},
1173
-                                                        success: function(totalflsize) {
1174
-
1175
-                                                                          $('#filessizetext').text(totalflsize);
1176
-                                                                          $('#filestotsize').css('color', '#189558');
1177
-                                                                          adjustMaximumSize(uploadedtomms);
1178
-
1179
-                                                        },
1180
-                                                        error: function(totalflsize) {
1181
-                                                                          $('#filessizetext').text(totalflsize);
1182
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1183
-                                                                              $('#filestotsize').css('color', '#ba3555');
1184
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1185
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1186
-                                                        }
1187
-                                                    });
1188
-
1189
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1190
-                                                }
1191
-
1192
-
1193
-                                                // Preview each file when you click on its name
1194
-                                                $("div:visible[id*='indflpicked']").each(function() {
1195
-                                                   $(this).on("click", function(event) {
1196
-
1197
-                                                      var mmsfilenameinit = $(this).text();
1198
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1199
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1200
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1201
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1202
-
1203
-                                                      if (extenlst == mmsfilenamesp) {
1204
-                                                           extenlst = "";
1205
-                                                      } else {
1206
-                                                           extenlst = extenlst.toLowerCase();
1207
-                                                      }
1208
-
1209
-                                                      $("#smstables").empty();
1210
-                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1211
-
1212
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1213
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1214
-                                                      } else if (extenlst == 'png') {
1215
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1216
-                                                      } else if (extenlst == 'gif') {
1217
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1218
-                                                      } else if (extenlst == 'bmp') {
1219
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1220
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1221
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1222
-                                                              var xhr = new XMLHttpRequest();
1223
-                                                              xhr.responseType = 'arraybuffer';
1224
-                                                              xhr.open('GET', tiffile);
1225
-                                                              xhr.onload = function (evnt) {
1226
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1227
-                                                                  var tifcanvas = tiff.toCanvas();
1228
-                                                                  $("#smstables").append(tifcanvas);
1229
-                                                              };
1230
-                                                              xhr.send();
1231
-                                                      } else if (extenlst == 'pdf') {
1232
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1233
-                                                              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>');
1234
-                                                              $("#smstables").append($iframe);
1235
-                                                      } else if (extenlst == 'txt') {
1236
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1237
-                                                      } else if (extension == 'mp4') {
1238
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1239
-						      } else if (extension == 'ogg') {
1240
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1241
-						      } else if (extension == 'avi') {
1242
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1243
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1244
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1245
-						      } else if (extension == 'wav' || extension == 'wave') {
1246
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1247
-						      } else if (extension == 'mp3') {
1248
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1249
-						      } else if (extension == 'midi') {
1250
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1251
-						      }
1252
-
1253
-                                                      $("#smstables").show();
1254
-                                                      $("#mmsfoldersview").hide();
1255
-                                                   });
1256
-                                                });
1257
-
1258
-
1259
-                                                // Remove picked files
1260
-                                                $('[class*="indpckfldl"]').last().click(function() {
1261
-                                                    var userid = "<?php p($userId); ?>";
1262
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1263
-
1264
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1265
-
1266
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1267
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1268
-
1269
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1270
-                                                    $(this).hide();
1271
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1272
-
1273
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1274
-                                                             return value != removedfilename;
1275
-                                                    });
1276
-
1277
-                                                    $.ajax({
1278
-                                                        url: baseUrl + '/' + userid,
1279
-                                                        type: "POST",
1280
-                                                        data: {removedfilename: removedfilename},
1281
-                                                        success: function(totalflsize) {
1282
-
1283
-                                                             msgtotalflsize = totalflsize;
1284
-                                                             $('#filessizetext').text(totalflsize);
1285
-                                                             adjustMaximumSize(uploadedtomms);
1286
-
1287
-                                                             // Check message size
1288
-                                                             var rectotfilesz = parseFloat(totalflsize);
1289
-
1290
-                                                             if (rectotfilesz > maximumsize) {
1291
-                                                                 $('#filestotsize').css('color', '#ba3555');
1292
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1293
-                                                                 $('#submitsms').attr("disabled", true);
1294
-                                                             } else {
1295
-                                                                 $('#submitsms').attr("disabled", false);
1296
-                                                                 $('#filestotsize').css('color', '#189558');
1297
-                                                               }
1298
-
1299
-                                                             // Rewrite order numbers for files that follow
1300
-                                                             --n;
1301
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1302
-
1303
-                                                                  var getdivtext =  $(this).text();
1304
-                                                                  var splitdivtext = getdivtext.split(") ");
1305
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1306
-                                                                  var newnbvalue = currentnbvalue - 1;
1307
-
1308
-                                                                  if (currentnbvalue > removedflnb) {
1309
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1310
-                                                                      $(this).text(replacedstr);
1311
-                                                                  }
1312
-                                                             });
1313
-                                                        },
1314
-                                                        error: function() {
1315
-                                                                  showAlert("Error while removing the file.");
1316
-                                                        }
1317
-                                                    });
1318
-
1319
-                                                    $('#smstables').removeClass('icon-loading');
1320
-                                                    $("#smstables").empty();
1321
-                                                });
1322
-
1323
-
1324
-		                                // Preview the picked file
1325
-		                                $("#mmsfoldersview").css("display", "inline-block");
1326
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1327
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1328
-
1329
-                                                $("#smstables").empty();
1330
-                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1331
-
1332
-						if (extension == 'jpg' || extension == 'jpeg') {
1333
-
1334
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1335
-
1336
-		                                } else if (extension == 'png') {
1337
-
1338
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1339
-
1340
-		                                } else if (extension == 'gif') {
1341
-
1342
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
-
1344
-		                                } else if (extension == 'bmp') {
1345
-
1346
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1347
-
1348
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1349
-
1350
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1351
-		                                       var xhr = new XMLHttpRequest();
1352
-		                                       xhr.responseType = 'arraybuffer';
1353
-		                                       xhr.open('GET', tiffile);
1354
-		                                       xhr.onload = function (event) {
1355
-		                                           var tiff = new Tiff({buffer: xhr.response});
1356
-		                                           var tifcanvas = tiff.toCanvas();
1357
-		                                           $("#smstables").append(tifcanvas);
1358
-		                                       };
1359
-		                                       xhr.send();
1360
-
1361
-		                                } else if (extension == 'pdf') {
1362
-
1363
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1364
-		                                       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>');
1365
-		                                       $("#smstables").append($iframe);
1366
-
1367
-		                                } else if (extension == 'txt') {
1368
-
1369
-							     $.get(flUrl, function(textdata) {
1370
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1371
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1372
-							     });
1373
-
1374
-		                                } else if (extension == 'mp4') {
1375
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1376
-						} else if (extension == 'ogg') {
1377
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1378
-						} else if (extension == 'avi') {
1379
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1380
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1381
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1382
-						} else if (extension == 'wav' || extension == 'wave') {
1383
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1384
-						} else if (extension == 'mp3') {
1385
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1386
-						} else if (extension == 'midi') {
1387
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1388
-						}
1389
-
1390
-
1391
-		                                $("#smstables").show();
1392
-
1393
-		                                $('#pf_choose_msg').hide();
1394
-		                                $('#smstables').removeClass('icon-loading');
1395
-		                                $("#mmsfoldersview").hide();
1396
-
1397
-                                          },
1398
-
1399
-                                          error: function(data){
1400
-                                                      showAlert("Error while getting the file.");
1401
-                                          }
1402
-
1403
-                                       });
1404
-
1405
-                                    } else {
1406
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1407
-                                        $('#pf_choose_msg').hide();
1408
-                                        $('#smstables').removeClass('icon-loading');
1409
-                                      }
1410
-                                 } else {
1411
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1412
-                                      $('#pf_choose_msg').hide();
1413
-                                      $('#smstables').removeClass('icon-loading');
1414
-                                   }
1415
-
1416
-                              } else {
1417
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1418
-                                   $('#pf_choose_msg').hide();
1419
-                                   $('#smstables').removeClass('icon-loading');
1420
-                                }
1421
-
1422
-                        }
1423
-                );
1424
-  });
1425
-
1426
-
1427
-
1428
-  // Send the SMS/MMS message
1429
-  $("#submitsms").on("click", function(event) {
1430
-
1431
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1432
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1433
-     $("#sms_submit_msg").css("display", "inline-block");
1434
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1435
-
1436
-     if (selectedid != '') { 
1437
-
1438
-         var sendersplit = selectedid.split(":");
1439
-         var providercap = sendersplit[0];
1440
-         var provsec = sendersplit[1];
1441
-
1442
-         if (/[a-zA-Z]/.test(provsec)) {
1443
-             var alphanumcheck = true;
1444
-         } else { var alphanumcheck = false; }
1445
-
1446
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1447
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1448
-             var selectedsender = "+" + senderproc;
1449
-             var providerUsed = "telnyx";
1450
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1451
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1452
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1453
-             var providerUsed = "plivo";
1454
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1455
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1456
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1457
-             var selectedsender = "+" + senderproc;
1458
-             var providerUsed = "twilio";
1459
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1460
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1461
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1462
-             var selectedsender = "+" + senderproc;
1463
-             var providerUsed = "flowroute";
1464
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1465
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1466
-             var selectedsender = provsec;
1467
-             var providerUsed = "telnyx";
1468
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1469
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1470
-             var selectedsender = provsec;
1471
-             var providerUsed = "plivo";
1472
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1473
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1474
-             var selectedsender = provsec;
1475
-             var providerUsed = "twilio";
1476
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1477
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1478
-             var selectedsender = provsec;
1479
-             var providerUsed = "flowroute";
1480
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1481
-         }
1482
-
1483
-         // Get the interval between message consecutive sending requests, if it's the case
1484
-         if ($('#tomultchckbx').is(':checked')) {
1485
-
1486
-             var numbersfile = 1;
1487
-             var initinterval = $("#multsmsinterval").val();
1488
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1489
-
1490
-             if (secinterval != '') {
1491
-                 var tertinterval = parseInt(secinterval);
1492
-                     waittime = tertinterval;
1493
-             }
1494
-
1495
-         } else {
1496
-
1497
-             var numbersfile = 0;
1498
-             var toNumberinit = $('#smsto').val();
1499
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1500
-             var toNumbersec = toNumber.split(",");
1501
-
1502
-                 for (var i = 0; i < toNumbersec.length; i++) {
1503
-                      toNumbersec[i] = "+" + toNumbersec[i];
1504
-                 }
1505
-
1506
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1507
-         }
1508
-
1509
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1510
-
1511
-         var smstext = $("#smstext").val();
1512
-
1513
-         if (receiversNumbers.length != 0) {
1514
-
1515
-              if (smstext != '') {
1516
-                  $.ajax({
1517
-                     url: relbaseUrl + '/' + userid,
1518
-                     type: "POST",
1519
-                     data: {
1520
-                           receiversPhoneNbs: receiversNumbers,
1521
-                           fromsender: selectedsender,
1522
-                           waitinterval: waittime,
1523
-                           sentsmstext: smstext,
1524
-                           ismms: isMMS,
1525
-                           mmsfiles: uploadedtomms
1526
-                         },
1527
-                     success: function() {
1528
-
1529
-                           if (receiversNumbers.length == 1) {
1530
-                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1531
-                           } else {
1532
-                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1533
-                           }
1534
-
1535
-                           $('#sms_submit_msg').hide();
1536
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1537
-                     },
1538
-                     error: function() {
1539
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1540
-                           $('#sms_submit_msg').hide();
1541
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1542
-                     }
1543
-                  });
1544
-              } else {
1545
-                     showAlert("Please enter a message in the text box !");
1546
-
1547
-                     $('#sms_submit_msg').hide();
1548
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1549
-              }
1550
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1551
-                 showAlert("Please enter the recipient's phone number !");
1552
-                 $('#sms_submit_msg').hide();
1553
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1554
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1555
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1556
-                 $('#sms_submit_msg').hide();
1557
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1558
-         }
1559
-     } else {
1560
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1561
-           $("#induploadfile").remove();
1562
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1563
-           $('#sms_submit_msg').hide();
1564
-     }
1565
-
1566
-  });
1567
-
1568
-  // Check the checkbox to delete old messages from the database
1569
-  $('#deleteoldchckbox').change(function() {
1570
-     if ($(this).is(':checked')) {
1571
-         $("#deleteoldsms").css("display", "block");
1572
-     } else {
1573
-         $("#deleteoldsms").css("display", "none");
1574
-     }
1575
-  });
1576
-
1577
-  // Set the height of info notes
1578
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1579
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1580
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1581
-
1582
-  $(window).resize(function() { 
1583
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1584
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1585
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1586
-  });
1587
-
1588
-
1589
-  function showAlert(alertText) {
1590
-
1591
-     $("#alertMsgOverlay").remove();
1592
-     $("#alertMessage").remove();
1593
-
1594
-     let alertwnd = "<div id='alertMessage'>";
1595
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1596
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1597
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1598
-     alertwnd += "</div>";
1599
-
1600
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1601
-     $("#content").append(alertwnd);
1602
-
1603
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1604
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1605
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1606
-
1607
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1608
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1609
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1610
-  }
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json appinfo/routes.php css/style.css js/adminsettings.js js/deleteoldsms.js js/sendsms.js js/settings.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php providers/Telnyx/lib/ApiResource.php

DoubleBastionAdmin authored on 15/07/2023 22:05:06
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1610 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  function cleanTempDirectory() {
235
+
236
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
237
+
238
+     $.ajax({
239
+          url: cleanflUrl + '/' + userid,
240
+          type: "POST",
241
+          data: { userid: userid },
242
+          cache: false,
243
+          processData: false,
244
+          contentType: false
245
+     });
246
+  }
247
+  cleanTempDirectory();
248
+
249
+  // Clean the SMS_Relentless/multiple_recipients directory
250
+  function cleanMultRecDirectory() {
251
+
252
+     var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleanmultrecdir");
253
+
254
+     $.ajax({
255
+          url: cleanflUrl + '/' + userid,
256
+          type: "POST",
257
+          data: { userid: userid },
258
+          cache: false,
259
+          processData: false,
260
+          contentType: false
261
+     });
262
+  }
263
+  cleanMultRecDirectory();
264
+
265
+  // Check the available balance
266
+  $("#smsprovider").on("change", function () {
267
+
268
+     var provider = $('#smsprovider :selected').val();
269
+
270
+     if (provider == "Telnyx") {
271
+
272
+        var gettelbalance = function() {
273
+
274
+          $('#currentbalance').addClass('icon-loading');
275
+
276
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
277
+
278
+          $.ajax({
279
+              url: gettelbalanceUrl + '/' + userid,
280
+              type: "POST",
281
+              data: { userid: userid },
282
+              cache: false,
283
+              processData: false,
284
+              contentType: false,
285
+              success: function(currentbalancetel) {
286
+
287
+                     $('#currentbalance').empty();
288
+                     $('#currentbalance').text(currentbalancetel);
289
+                     $('#currentbalance').removeClass('icon-loading');
290
+              }
291
+          });
292
+        }
293
+
294
+        gettelbalance();
295
+
296
+     } else if (provider == "Plivo") {
297
+
298
+          var getnexbalance = function() {
299
+
300
+            $('#currentbalance').addClass('icon-loading');
301
+
302
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
303
+
304
+            $.ajax({
305
+                url: getnexbalanceUrl + '/' + userid,
306
+                type: "POST",
307
+                data: { userid: userid },
308
+                cache: false,
309
+                processData: false,
310
+                contentType: false,
311
+                success: function(currentbalancenex) {
312
+
313
+                     $('#currentbalance').empty();
314
+                     $('#currentbalance').text(currentbalancenex);
315
+                     $('#currentbalance').removeClass('icon-loading');
316
+                }
317
+            });
318
+          }
319
+
320
+          getnexbalance();
321
+
322
+     } else if (provider == "Twilio") {
323
+
324
+          var gettwilbalance = function() {
325
+
326
+            $('#currentbalance').addClass('icon-loading');
327
+
328
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
329
+
330
+            $.ajax({
331
+                url: gettwilbalanceUrl + '/' + userid,
332
+                type: "POST",
333
+                data: { userid: userid },
334
+                cache: false,
335
+                processData: false,
336
+                contentType: false,
337
+                success: function(currentbalancetwil) {
338
+
339
+                     $('#currentbalance').empty();
340
+                     $('#currentbalance').text(currentbalancetwil);
341
+                     $('#currentbalance').removeClass('icon-loading');
342
+                }
343
+            });
344
+          }
345
+
346
+          gettwilbalance();
347
+
348
+     } else if (provider == "Flowroute") {
349
+
350
+          var getflowbalance = function() {
351
+
352
+            $('#currentbalance').addClass('icon-loading');
353
+
354
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
355
+
356
+            $.ajax({
357
+                url: getflowbalanceUrl + '/' + userid,
358
+                type: "POST",
359
+                data: { userid: userid },
360
+                cache: false,
361
+                processData: false,
362
+                contentType: false,
363
+                success: function(currentbalanceflow) {
364
+
365
+                     $('#currentbalance').empty();
366
+                     $('#currentbalance').text(currentbalanceflow);
367
+                     $('#currentbalance').removeClass('icon-loading');
368
+                }
369
+            });
370
+          }
371
+
372
+          getflowbalance();
373
+
374
+       } else if (provider == "") {
375
+                $('#currentbalance').text("");
376
+                $('#currentbalance').removeClass('icon-loading');
377
+       }
378
+  });
379
+
380
+
381
+  // If a Sender ID is selected
382
+  $("#currentsmsnmbrs").on("change", function () {
383
+
384
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
+
386
+              selectedid = $('#currentsmsnmbrs :selected').val();
387
+              var setIdsplit = selectedid.split(":");
388
+	      chosenProvider = setIdsplit[0];
389
+
390
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
391
+	      if (chosenProvider == "Tx") {
392
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
393
+		  // Maximum size of message text + files in KB
394
+		  maximumsize = 1024;
395
+                  maximumsizeinit = 1024;
396
+		  maxsizenonimage = 600;
397
+		  maximumfilenumber = 10;
398
+                  chosenProvFullName = "Telnyx";
399
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
400
+                                     or gif files, the size of all the files plus the size of the text should be \
401
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
402
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
403
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
404
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
405
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
406
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
407
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
408
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
409
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
410
+                  $("#tooltiptextfourth").html(infonotecontent);
411
+	      } else if (chosenProvider == "Pl") {
412
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
413
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
414
+		  // Maximum size of message text + files in KB
415
+		  maximumsize = 5120;
416
+                  maximumsizeinit = 5120;
417
+		  maxsizenonimage = 600;
418
+		  maximumfilenumber = 10;
419
+                  chosenProvFullName = "Plivo";
420
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
421
+                                     or gif files, the size of all the files plus the size of the text should be \
422
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
423
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
424
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
425
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
426
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
427
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
428
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
429
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
430
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
431
+                  $("#tooltiptextfourth").html(infonotecontent);
432
+	      } else if (chosenProvider == "Tw") {
433
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
434
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
435
+                                     "icalendar", "directory", "pdf", "pkpass"];
436
+		  // Maximum size of message text + files in KB
437
+		  maximumsize = 5120;
438
+                  maximumsizeinit = 5120;
439
+		  maxsizenonimage = 600;
440
+		  maximumfilenumber = 10;
441
+                  chosenProvFullName = "Twilio";
442
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
443
+                                     or gif files, the size of all the files plus the size of the text should be \
444
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
445
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
446
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
447
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
448
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
449
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
450
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
451
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
452
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
453
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
454
+                                     previewed in the adjoining pane."
455
+                  $("#tooltiptextfourth").html(infonotecontent);
456
+	      } else if (chosenProvider == "Fl") {
457
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
458
+		  // Maximum size of message text + files in KB
459
+		  maximumsize = 750;
460
+                  maximumsizeinit = 750;
461
+		  maxsizenonimage = 600;
462
+		  maximumfilenumber = 10;
463
+                  chosenProvFullName = "Flowroute";
464
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
465
+                                     png or gif files, the size of all the files plus the size of the text should be \
466
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
467
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
468
+                                     size of the files plus the size of the text should be 600 KB or less. \
469
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
470
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
471
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
472
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
473
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
474
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
475
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
476
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
477
+                  $("#tooltiptextfourth").html(infonotecontent);
478
+	      }
479
+
480
+          } else { selectedid = ''; }
481
+  });
482
+
483
+  // Check the checkbox to send SMS message to multiple recipients
484
+  $('#tomultchckbx').change(function() {
485
+      if ($(this).is(':checked')) {
486
+          $("#multiplerecivers").css("display", "block");
487
+          $("#smstodiv").css("visibility", "hidden");
488
+          $("#smsto").val("");
489
+
490
+          receiversNumbers.length = 0;
491
+
492
+      } else {
493
+          $("#multiplerecivers").css("display", "none");
494
+          $("#smstodiv").css("visibility", "visible");
495
+
496
+          // Remove the uploaded files' names if any
497
+          $("#induploadfile").remove();
498
+
499
+          // Remove all the files from the SMS_Relentless/multiple_recipients directory
500
+          cleanMultRecDirectory();
501
+
502
+          $("#smstables").empty();
503
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
504
+
505
+          receiversNumbers.length = 0;
506
+      }
507
+  });
508
+
509
+  // Upload the file with the recipients' phone numbers
510
+  $("#uploadfileforsms").change(function(e) {
511
+
512
+     $("#fileuploadednm").empty();
513
+
514
+     receiversNumbers.length = 0;
515
+
516
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
517
+
518
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
519
+
520
+     var formData = new FormData();
521
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
522
+
523
+     var fileup = $('#uploadfileforsms').val();
524
+     var fileuptrim = fileup.split('\\').pop();
525
+
526
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
527
+
528
+     var extension = fileup.replace(/^.*\./, '');
529
+
530
+     if (extension == fileup) {
531
+         extension = "";
532
+     } else {
533
+         extension = extension.toLowerCase();
534
+     }
535
+
536
+     var validExtensionsmrec = ["txt", "csv"];
537
+
538
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
539
+
540
+       if (selectedid != '') {
541
+
542
+               $.ajax({
543
+                 url: baseUrl + '/' + userid,
544
+                 type: "POST",
545
+                 data: formData,
546
+                 cache: false,
547
+                 processData: false,
548
+                 contentType: false,
549
+                 success: function(numberarray) {
550
+
551
+		    if (numberarray.length > 0) {
552
+
553
+		        // Get the array of the receivers' phone numbers
554
+		        if (chosenProvider == "Tx") {
555
+
556
+		             for(key in numberarray) {
557
+		                 receiversNumbers.push("+"+numberarray[key]);
558
+		             }
559
+
560
+		        } else if (chosenProvider == "Pl") {
561
+
562
+		             for(key in numberarray) {
563
+		                 receiversNumbers.push(numberarray[key]);
564
+		             }
565
+
566
+		          } else if (chosenProvider == "Tw") {
567
+
568
+		             for(key in numberarray) {
569
+		                 receiversNumbers.push(numberarray[key]);
570
+		             }
571
+		          } else if (chosenProvider == "Fl") {
572
+
573
+		             for(key in numberarray) {
574
+		                 receiversNumbers.push(numberarray[key]);
575
+		             }
576
+		          }
577
+
578
+		    } else {
579
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
580
+		    }
581
+                            
582
+                    // Preview the uploaded file
583
+                    var smsfilename = e.target.files[0].name;
584
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
585
+
586
+                    var reader = new FileReader();
587
+                    reader.readAsText(e.target.files[0]);
588
+                    reader.onload = function(e) {
589
+                          $("#smstables").empty();
590
+                          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
591
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
592
+                    };
593
+
594
+                    $("#smstables").show();
595
+
596
+                    $('#sms_upload_msg').hide();
597
+                    $('#smstables').removeClass('icon-loading');
598
+
599
+                  },
600
+                  error: function() {
601
+                             showAlert("Error while uploading the file.");
602
+                  }
603
+               });
604
+
605
+        } else {
606
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
607
+               $("#induploadfile").remove();
608
+               $('#sms_upload_msg').hide();
609
+               $('#smstables').removeClass('icon-loading');
610
+        }
611
+
612
+     } else {
613
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
614
+          $('#pf_upload_msg').hide();
615
+          $('#smstables').removeClass('icon-loading');
616
+
617
+          $("#induploadfile").remove();
618
+          $("#sms_upload_msg").hide();
619
+     }
620
+
621
+     // Preview uploaded file when clicked
622
+     $("#indfilediv").on("click", function() {
623
+
624
+          var smsfilename = e.target.files[0].name;
625
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
626
+
627
+          var reader = new FileReader();
628
+          reader.readAsText(e.target.files[0]);
629
+          reader.onload = function(e) {
630
+                  $("#smstables").empty();
631
+                  $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
632
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
633
+          };
634
+
635
+          $("#smstables").show();
636
+          $('#sms_upload_msg').hide();
637
+          $('#smstables').removeClass('icon-loading');
638
+     });
639
+
640
+     // Remove selected file
641
+     $("#indivflremove").on("click", function() {
642
+
643
+          $("#induploadfile").remove();
644
+          $("#sms_upload_msg").hide();
645
+
646
+          receiversNumbers.length = 0;
647
+
648
+          cleanMultRecDirectory();
649
+     });
650
+
651
+  });
652
+
653
+  // Show the number of characters entered in the SMS textarea and the text size in KB
654
+  $("#smstext").on('input', function() {
655
+
656
+     $("#char_count").css("display", "inline");
657
+
658
+     $("#mtextSize").css("display", "inline");
659
+
660
+     $(".maxmessagelength").css("display", "inline-block");
661
+
662
+     $("#countchnb").text($(this).val().length);
663
+
664
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
665
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
666
+     $("#textsizeinkb").text(textsizekb);
667
+
668
+     if ($(this).val().length > charcolorthr) {
669
+         $("#char_count").css("color", "#BB2E4B");
670
+     } else {
671
+         $("#char_count").css("color", "#4cbc86;");
672
+     }
673
+
674
+  });
675
+
676
+
677
+  // Check the checkbox to send file(s) as MMS
678
+  $('#mediafilechckbx').change(function() {
679
+
680
+      if ($(this).is(':checked')) {
681
+
682
+          isMMS = 1;
683
+          if (selectedid == '') {
684
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
685
+              $(this).prop("checked", false);
686
+              isMMS = 0;
687
+              return;
688
+          }
689
+          $("#upmediafiles").css("display", "block");
690
+          $("#submitsms").prop("value", "Send MMS");
691
+
692
+      } else {
693
+
694
+          isMMS = 0;
695
+          $("#upmediafiles").css("display", "none");
696
+          $("#submitsms").prop("value", "Send SMS");
697
+
698
+          // Remove the uploaded files' names if any
699
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
700
+          $(".indgenpckfls").each(function() { $(this).remove(); });
701
+
702
+          // Remove all the files from the SMS_Relentless/temp_files directory
703
+          cleanTempDirectory();
704
+
705
+          $("#smstables").empty();
706
+          $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
707
+
708
+          uploadedtomms = [];
709
+          n = 1;
710
+
711
+          msgtotalflsize = 0;
712
+
713
+          $("#filestotsize").hide();
714
+      }
715
+  });
716
+
717
+
718
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
719
+  function adjustMaximumSize(uploadedtomms) {
720
+				      
721
+      var nonimgcheck = 0;
722
+      for (var u = 0; u < uploadedtomms.length; u++) {
723
+	   var crupfl = uploadedtomms[u];
724
+	   var extensionup = crupfl.replace(/^.*\./, '');
725
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
726
+	       nonimgcheck = 1;
727
+	   }
728
+      }
729
+
730
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
731
+  }
732
+
733
+  // Upload files to be sent as MMS
734
+  $("#uploadfileformms").change(function(e) {
735
+
736
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
737
+     $('#smstables').addClass('icon-loading');
738
+     $('#filestotsize').show();
739
+
740
+     var userid = "<?php p($userId); ?>";
741
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
742
+
743
+     var formData = new FormData();
744
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
745
+
746
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
747
+
748
+     // Add the size of the current file to the total size of all the files
749
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
750
+
751
+     var fileup = $('#uploadfileformms').val();
752
+     var fileuptrim = fileup.split('\\').pop();
753
+
754
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
755
+         var duplicatescheck = 1;
756
+     } else { 
757
+         var duplicatescheck = 0;
758
+     }
759
+
760
+     var extension = fileup.replace(/^.*\./, '');
761
+
762
+     if (extension == fileup) {
763
+         extension = "";
764
+     } else {
765
+         extension = extension.toLowerCase();
766
+     }
767
+
768
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
769
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
770
+         maximumsize = maxsizenonimage;
771
+     }
772
+
773
+     if ($.inArray(extension, validExtensions) != -1) {
774
+
775
+       if (duplicatescheck == 0) {
776
+
777
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
778
+
779
+            if (n <= maximumfilenumber) {
780
+
781
+               $.ajax({
782
+                 url: baseUrl + '/' + userid,
783
+                 type: "POST",
784
+                 data: formData,
785
+                 cache: false,
786
+                 processData: false,
787
+                 contentType: false,
788
+                 success: function(totalflsize) {
789
+
790
+                   uploadedtomms.push(fileuptrim);
791
+
792
+                   $('#filessizetext').text(totalflsize);
793
+
794
+                   var rectotfilesz = parseFloat(totalflsize);
795
+
796
+                   if (rectotfilesz <= maximumsize) {
797
+                       $('#submitsms').attr("disabled", false);
798
+                       $('#filestotsize').css('color', '#189558');
799
+                   } else {
800
+                       $('#filestotsize').css('color', '#ba3555');
801
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
802
+                       $('#submitsms').attr("disabled", true);
803
+                       $('#smstables').removeClass('icon-loading');
804
+                       $('#pf_upload_msg').hide();
805
+                   }
806
+
807
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
808
+                   n++;
809
+
810
+                   // Preview the file when you click on its name
811
+                   $("div:visible[id*='indfilediv']").each(function() {
812
+
813
+                        $(this).on("click", function(eventclck) {
814
+
815
+                           $("#mmsfoldersview").css("display", "inline-block");
816
+                           var mmsfilenameinit = $(this).text();
817
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
818
+                           var mmsfilename = mmsfilenamesec.replace("X","");
819
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
820
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
821
+
822
+                           if (extenlst == mmsfilename) {
823
+                               extenlst = "";
824
+                           } else {
825
+                               extenlst = extenlst.toLowerCase();
826
+                           }
827
+
828
+                           $("#smstables").empty();
829
+                           $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
830
+
831
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
832
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
833
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
834
+                           } else if (extenlst == 'png') {
835
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
836
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
837
+                           } else if (extenlst == 'gif') {
838
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
839
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
840
+                           } else if (extenlst == 'bmp') {
841
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
842
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
843
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
844
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
+                                  var xhr = new XMLHttpRequest();
846
+                                  xhr.responseType = 'arraybuffer';
847
+                                  xhr.open('GET', tiffile);
848
+                                  xhr.onload = function (evnt) {
849
+                                      var tiff = new Tiff({buffer: xhr.response});
850
+                                      var tifcanvas = tiff.toCanvas();
851
+                                      $("#smstables").append(tifcanvas);
852
+                                  };
853
+                                  xhr.send();
854
+                           } else if (extenlst == 'pdf') {
855
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
856
+                                  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>');
857
+                                  $("#smstables").append($iframe);
858
+                           } else if (extenlst == 'txt') {
859
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
860
+                           } else if (extension == 'mp4') {
861
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
862
+		           } else if (extension == 'ogg') {
863
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
864
+		           } else if (extension == 'avi') {
865
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
866
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
867
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
868
+		           } else if (extension == 'wav' || extension == 'wave') {
869
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
870
+		           } else if (extension == 'mp3') {
871
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
872
+		           } else if (extension == 'midi') {
873
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
874
+		           }
875
+
876
+                           $("#smstables").show();
877
+                           $("#mmsfoldersview").hide();
878
+                        });
879
+                   });
880
+
881
+                   // Remove uploaded files
882
+                   $('[class*="indupfldl"]').last().click(function() {
883
+
884
+                           var userid = "<?php p($userId); ?>";
885
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
886
+
887
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
888
+
889
+                           var removedfilesplit = removedfilenameinit.split(") ");
890
+                           var removedflnb = parseInt(removedfilesplit[0]);
891
+
892
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
893
+                           $(this).hide();
894
+
895
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
896
+
897
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
898
+                                           return value != removedfilename;
899
+                           });
900
+
901
+                           $.ajax({
902
+                                   url: baseUrl + '/' + userid,
903
+                                   type: "POST",
904
+                                   data: {removedfilename: removedfilename},
905
+                                   success: function(totalflsize) {
906
+
907
+                                      msgtotalflsize = totalflsize;
908
+                                      $('#filessizetext').text(totalflsize);
909
+
910
+                                      adjustMaximumSize(uploadedtomms);
911
+
912
+                                      // Check message size
913
+                                      var rectotfilesz = parseFloat(totalflsize);
914
+
915
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
916
+                                          $('#submitsms').attr("disabled", false);
917
+                                          $('#filestotsize').css('color', '#189558');
918
+                                      } else {
919
+                                          $('#filestotsize').css('color', '#ba3555');
920
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
921
+                                          $('#submitsms').attr("disabled", true);
922
+                                      }
923
+
924
+                                      // Rewrite order numbers for files that follow
925
+                                      --n;
926
+                                      $("div:visible[id*='indfilediv']").each(function() {
927
+
928
+                                          var getdivtext =  $(this).text();
929
+                                          var splitdivtext = getdivtext.split(") ");
930
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
931
+                                          var newnbvalue = currentnbvalue - 1;
932
+
933
+                                          if (currentnbvalue > removedflnb) {
934
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
935
+                                              $(this).text(replacedstr);
936
+                                          }
937
+                                      });
938
+
939
+                                      $("div:visible[id*='indflpicked']").each(function() {
940
+
941
+                                          var getdivtext =  $(this).text();
942
+                                          var splitdivtext = getdivtext.split(") ");
943
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
944
+                                          var newnbvalue = currentnbvalue - 1;
945
+
946
+                                          if (currentnbvalue > removedflnb) {
947
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
948
+                                              $(this).text(replacedstr);
949
+                                          }
950
+                                      });
951
+
952
+                                   },
953
+                                   error: function() {
954
+                                              showAlert("Error while removing the file(s).");
955
+                                   }
956
+                           });
957
+
958
+                           $('#smstables').removeClass('icon-loading');
959
+                           $("#smstables").empty();
960
+                   });
961
+
962
+                   // Preview the uploaded file
963
+                   $("#mmsfoldersview").css("display", "inline-block");
964
+                   var mmsfilename = e.target.files[0].name;
965
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
966
+
967
+                   $("#smstables").empty();
968
+                   $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
969
+
970
+                   if (extension == 'jpg' || extension == 'jpeg') {
971
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
972
+
973
+                              var reader = new FileReader();
974
+                              reader.onload = function (e) {
975
+                                  readjpg[mmsfilename] = e.target.result;
976
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
977
+                              }
978
+                              reader.readAsDataURL(e.target.files[0]);
979
+                   } else if (extension == 'png') {
980
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
981
+
982
+                              var reader = new FileReader();
983
+                              reader.onload = function (e) {
984
+                                  readpng[mmsfilename] = e.target.result;
985
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
986
+                              }
987
+                              reader.readAsDataURL(e.target.files[0]);
988
+
989
+                   } else if (extension == 'gif') {
990
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
991
+
992
+                              var reader = new FileReader();
993
+                              reader.onload = function (e) {
994
+                                  readgif[mmsfilename] = e.target.result;
995
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
996
+                              }
997
+                              reader.readAsDataURL(e.target.files[0]);
998
+
999
+                   } else if (extension == 'bmp') {
1000
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1001
+
1002
+                              var reader = new FileReader();
1003
+                              reader.onload = function (e) {
1004
+                                  readbmp[mmsfilename] = e.target.result;
1005
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
1006
+                              }
1007
+                              reader.readAsDataURL(e.target.files[0]);
1008
+
1009
+                   } else if (extension == 'tif' || extension == 'tiff') {
1010
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1011
+                              var xhr = new XMLHttpRequest();
1012
+                              xhr.responseType = 'arraybuffer';
1013
+                              xhr.open('GET', tiffile);
1014
+                              xhr.onload = function (e) {
1015
+                                  var tiff = new Tiff({buffer: xhr.response});
1016
+                                  var tifcanvas = tiff.toCanvas();
1017
+                                  $("#smstables").append(tifcanvas);
1018
+                              };
1019
+                              xhr.send();
1020
+
1021
+                   } else if (extension == 'pdf') {
1022
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1023
+                              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>');
1024
+                              $("#smstables").append($iframe);
1025
+
1026
+                   } else if (extension == 'txt') {
1027
+                              var reader = new FileReader();
1028
+                              reader.readAsText(e.target.files[0]);
1029
+                              reader.onload = function(e) {
1030
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1031
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1032
+                              };
1033
+                   } else if (extension == 'mp4') {
1034
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1035
+                   } else if (extension == 'ogg') {
1036
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1037
+                   } else if (extension == 'avi') {
1038
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1039
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1040
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1041
+                   } else if (extension == 'wav' || extension == 'wave') {
1042
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1043
+                   } else if (extension == 'mp3') {
1044
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1045
+                   } else if (extension == 'midi') {
1046
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1047
+                   }
1048
+
1049
+                   $("#smstables").show();
1050
+                   $('#pf_upload_msg').hide();
1051
+                   $('#smstables').removeClass('icon-loading');
1052
+                   $("#mmsfoldersview").hide();
1053
+                 },
1054
+                 error: function() {
1055
+                              showAlert("Error while uploading the file.");
1056
+                 }
1057
+               });
1058
+
1059
+            } else {
1060
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1061
+                  adjustMaximumSize(uploadedtomms);
1062
+
1063
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1064
+                  $('#pf_upload_msg').hide();
1065
+                  $('#smstables').removeClass('icon-loading');
1066
+            }
1067
+         } else {
1068
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1069
+              adjustMaximumSize(uploadedtomms);
1070
+
1071
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1072
+              $('#pf_upload_msg').hide();
1073
+              $('#smstables').removeClass('icon-loading');
1074
+         }
1075
+       } else {
1076
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1077
+            adjustMaximumSize(uploadedtomms);
1078
+
1079
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1080
+            $('#pf_upload_msg').hide();
1081
+            $('#smstables').removeClass('icon-loading');
1082
+       }
1083
+
1084
+     } else {
1085
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1086
+          adjustMaximumSize(uploadedtomms);
1087
+
1088
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1089
+          $('#pf_upload_msg').hide();
1090
+          $('#smstables').removeClass('icon-loading');
1091
+     }
1092
+  });
1093
+
1094
+
1095
+  // Pick file(s) from Nextcloud, to send as MMS
1096
+  var mmsfilename = null;
1097
+
1098
+  $("#choosefilen").on("click", function(evn) {
1099
+
1100
+                OC.dialogs.filepicker(
1101
+                        t('settings', "Select a file to send as MMS."),
1102
+                        function (path) {
1103
+
1104
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1105
+                              $('#smstables').addClass('icon-loading');
1106
+                              $('#filestotsize').show();
1107
+
1108
+                              var userid = "<?php p($userId); ?>";
1109
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1110
+
1111
+                              mmsfilename = path.split('/').pop();
1112
+
1113
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1114
+                                  var duplicatescheck = 1;
1115
+                              } else var duplicatescheck = 0;
1116
+
1117
+                              var extension = mmsfilename.replace(/^.*\./, '');
1118
+
1119
+                              if (extension == mmsfilename) {
1120
+                                  extension = "";
1121
+                              } else {
1122
+                                  extension = extension.toLowerCase();
1123
+                              }
1124
+
1125
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1126
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1127
+				   maximumsize = maxsizenonimage;
1128
+			      }
1129
+
1130
+                              if ($.inArray(extension, validExtensions) != -1) {
1131
+
1132
+                                 if (duplicatescheck == 0) {
1133
+
1134
+                                    if (n <= maximumfilenumber) {
1135
+
1136
+                                       $.ajax({
1137
+                                          url: baseUrl + '/' + userid,
1138
+                                          type: "POST",
1139
+                                          data: { path: path },
1140
+                                          success: function(pickresult) {
1141
+
1142
+                                                uploadedtomms.push(mmsfilename);
1143
+
1144
+                                                var totalflsize = pickresult[0];
1145
+                                                var pickedflsize = pickresult[1];
1146
+
1147
+                                                // Check message size
1148
+                                                var rectotfilesz = parseFloat(totalflsize);
1149
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1150
+
1151
+                                                if (filesplustextsize <= maximumsize) {
1152
+
1153
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1154
+
1155
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1156
+                                                    n++;
1157
+
1158
+                                                    msgtotalflsize = totalflsize;
1159
+                                                    $('#filessizetext').text(totalflsize);
1160
+                                                    $('#filestotsize').css('color', '#189558');
1161
+
1162
+                                                } else {
1163
+
1164
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1165
+                                                    $('#filestotsize').css('color', '#ba3555');
1166
+                                                    msgtotalflsize -= pickedflsize;
1167
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1168
+
1169
+                                                    $.ajax({
1170
+                                                        url: baseUrlindrm + '/' + userid,
1171
+                                                        type: "POST",
1172
+                                                        data: {removedfilename: mmsfilename},
1173
+                                                        success: function(totalflsize) {
1174
+
1175
+                                                                          $('#filessizetext').text(totalflsize);
1176
+                                                                          $('#filestotsize').css('color', '#189558');
1177
+                                                                          adjustMaximumSize(uploadedtomms);
1178
+
1179
+                                                        },
1180
+                                                        error: function(totalflsize) {
1181
+                                                                          $('#filessizetext').text(totalflsize);
1182
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1183
+                                                                              $('#filestotsize').css('color', '#ba3555');
1184
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1185
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1186
+                                                        }
1187
+                                                    });
1188
+
1189
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1190
+                                                }
1191
+
1192
+
1193
+                                                // Preview each file when you click on its name
1194
+                                                $("div:visible[id*='indflpicked']").each(function() {
1195
+                                                   $(this).on("click", function(event) {
1196
+
1197
+                                                      var mmsfilenameinit = $(this).text();
1198
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1199
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1200
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1201
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1202
+
1203
+                                                      if (extenlst == mmsfilenamesp) {
1204
+                                                           extenlst = "";
1205
+                                                      } else {
1206
+                                                           extenlst = extenlst.toLowerCase();
1207
+                                                      }
1208
+
1209
+                                                      $("#smstables").empty();
1210
+                                                      $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1211
+
1212
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1213
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1214
+                                                      } else if (extenlst == 'png') {
1215
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1216
+                                                      } else if (extenlst == 'gif') {
1217
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1218
+                                                      } else if (extenlst == 'bmp') {
1219
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1220
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1221
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1222
+                                                              var xhr = new XMLHttpRequest();
1223
+                                                              xhr.responseType = 'arraybuffer';
1224
+                                                              xhr.open('GET', tiffile);
1225
+                                                              xhr.onload = function (evnt) {
1226
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1227
+                                                                  var tifcanvas = tiff.toCanvas();
1228
+                                                                  $("#smstables").append(tifcanvas);
1229
+                                                              };
1230
+                                                              xhr.send();
1231
+                                                      } else if (extenlst == 'pdf') {
1232
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1233
+                                                              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>');
1234
+                                                              $("#smstables").append($iframe);
1235
+                                                      } else if (extenlst == 'txt') {
1236
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1237
+                                                      } else if (extension == 'mp4') {
1238
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1239
+						      } else if (extension == 'ogg') {
1240
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1241
+						      } else if (extension == 'avi') {
1242
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1243
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1244
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1245
+						      } else if (extension == 'wav' || extension == 'wave') {
1246
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1247
+						      } else if (extension == 'mp3') {
1248
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1249
+						      } else if (extension == 'midi') {
1250
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1251
+						      }
1252
+
1253
+                                                      $("#smstables").show();
1254
+                                                      $("#mmsfoldersview").hide();
1255
+                                                   });
1256
+                                                });
1257
+
1258
+
1259
+                                                // Remove picked files
1260
+                                                $('[class*="indpckfldl"]').last().click(function() {
1261
+                                                    var userid = "<?php p($userId); ?>";
1262
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1263
+
1264
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1265
+
1266
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1267
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1268
+
1269
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1270
+                                                    $(this).hide();
1271
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1272
+
1273
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1274
+                                                             return value != removedfilename;
1275
+                                                    });
1276
+
1277
+                                                    $.ajax({
1278
+                                                        url: baseUrl + '/' + userid,
1279
+                                                        type: "POST",
1280
+                                                        data: {removedfilename: removedfilename},
1281
+                                                        success: function(totalflsize) {
1282
+
1283
+                                                             msgtotalflsize = totalflsize;
1284
+                                                             $('#filessizetext').text(totalflsize);
1285
+                                                             adjustMaximumSize(uploadedtomms);
1286
+
1287
+                                                             // Check message size
1288
+                                                             var rectotfilesz = parseFloat(totalflsize);
1289
+
1290
+                                                             if (rectotfilesz > maximumsize) {
1291
+                                                                 $('#filestotsize').css('color', '#ba3555');
1292
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1293
+                                                                 $('#submitsms').attr("disabled", true);
1294
+                                                             } else {
1295
+                                                                 $('#submitsms').attr("disabled", false);
1296
+                                                                 $('#filestotsize').css('color', '#189558');
1297
+                                                               }
1298
+
1299
+                                                             // Rewrite order numbers for files that follow
1300
+                                                             --n;
1301
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1302
+
1303
+                                                                  var getdivtext =  $(this).text();
1304
+                                                                  var splitdivtext = getdivtext.split(") ");
1305
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1306
+                                                                  var newnbvalue = currentnbvalue - 1;
1307
+
1308
+                                                                  if (currentnbvalue > removedflnb) {
1309
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1310
+                                                                      $(this).text(replacedstr);
1311
+                                                                  }
1312
+                                                             });
1313
+                                                        },
1314
+                                                        error: function() {
1315
+                                                                  showAlert("Error while removing the file.");
1316
+                                                        }
1317
+                                                    });
1318
+
1319
+                                                    $('#smstables').removeClass('icon-loading');
1320
+                                                    $("#smstables").empty();
1321
+                                                });
1322
+
1323
+
1324
+		                                // Preview the picked file
1325
+		                                $("#mmsfoldersview").css("display", "inline-block");
1326
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1327
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1328
+
1329
+                                                $("#smstables").empty();
1330
+                                                $("#stopAutoRefreshRec,#stopAutoRefreshSent").css("display", "none");
1331
+
1332
+						if (extension == 'jpg' || extension == 'jpeg') {
1333
+
1334
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1335
+
1336
+		                                } else if (extension == 'png') {
1337
+
1338
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1339
+
1340
+		                                } else if (extension == 'gif') {
1341
+
1342
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
+
1344
+		                                } else if (extension == 'bmp') {
1345
+
1346
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1347
+
1348
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1349
+
1350
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1351
+		                                       var xhr = new XMLHttpRequest();
1352
+		                                       xhr.responseType = 'arraybuffer';
1353
+		                                       xhr.open('GET', tiffile);
1354
+		                                       xhr.onload = function (event) {
1355
+		                                           var tiff = new Tiff({buffer: xhr.response});
1356
+		                                           var tifcanvas = tiff.toCanvas();
1357
+		                                           $("#smstables").append(tifcanvas);
1358
+		                                       };
1359
+		                                       xhr.send();
1360
+
1361
+		                                } else if (extension == 'pdf') {
1362
+
1363
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1364
+		                                       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>');
1365
+		                                       $("#smstables").append($iframe);
1366
+
1367
+		                                } else if (extension == 'txt') {
1368
+
1369
+							     $.get(flUrl, function(textdata) {
1370
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1371
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1372
+							     });
1373
+
1374
+		                                } else if (extension == 'mp4') {
1375
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1376
+						} else if (extension == 'ogg') {
1377
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1378
+						} else if (extension == 'avi') {
1379
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1380
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1381
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1382
+						} else if (extension == 'wav' || extension == 'wave') {
1383
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1384
+						} else if (extension == 'mp3') {
1385
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1386
+						} else if (extension == 'midi') {
1387
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1388
+						}
1389
+
1390
+
1391
+		                                $("#smstables").show();
1392
+
1393
+		                                $('#pf_choose_msg').hide();
1394
+		                                $('#smstables').removeClass('icon-loading');
1395
+		                                $("#mmsfoldersview").hide();
1396
+
1397
+                                          },
1398
+
1399
+                                          error: function(data){
1400
+                                                      showAlert("Error while getting the file.");
1401
+                                          }
1402
+
1403
+                                       });
1404
+
1405
+                                    } else {
1406
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1407
+                                        $('#pf_choose_msg').hide();
1408
+                                        $('#smstables').removeClass('icon-loading');
1409
+                                      }
1410
+                                 } else {
1411
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1412
+                                      $('#pf_choose_msg').hide();
1413
+                                      $('#smstables').removeClass('icon-loading');
1414
+                                   }
1415
+
1416
+                              } else {
1417
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1418
+                                   $('#pf_choose_msg').hide();
1419
+                                   $('#smstables').removeClass('icon-loading');
1420
+                                }
1421
+
1422
+                        }
1423
+                );
1424
+  });
1425
+
1426
+
1427
+
1428
+  // Send the SMS/MMS message
1429
+  $("#submitsms").on("click", function(event) {
1430
+
1431
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1432
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1433
+     $("#sms_submit_msg").css("display", "inline-block");
1434
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1435
+
1436
+     if (selectedid != '') { 
1437
+
1438
+         var sendersplit = selectedid.split(":");
1439
+         var providercap = sendersplit[0];
1440
+         var provsec = sendersplit[1];
1441
+
1442
+         if (/[a-zA-Z]/.test(provsec)) {
1443
+             var alphanumcheck = true;
1444
+         } else { var alphanumcheck = false; }
1445
+
1446
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1447
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1448
+             var selectedsender = "+" + senderproc;
1449
+             var providerUsed = "telnyx";
1450
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1451
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1452
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1453
+             var providerUsed = "plivo";
1454
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1455
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1456
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1457
+             var selectedsender = "+" + senderproc;
1458
+             var providerUsed = "twilio";
1459
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1460
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1461
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1462
+             var selectedsender = "+" + senderproc;
1463
+             var providerUsed = "flowroute";
1464
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1465
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1466
+             var selectedsender = provsec;
1467
+             var providerUsed = "telnyx";
1468
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1469
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1470
+             var selectedsender = provsec;
1471
+             var providerUsed = "plivo";
1472
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1473
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1474
+             var selectedsender = provsec;
1475
+             var providerUsed = "twilio";
1476
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1477
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1478
+             var selectedsender = provsec;
1479
+             var providerUsed = "flowroute";
1480
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1481
+         }
1482
+
1483
+         // Get the interval between message consecutive sending requests, if it's the case
1484
+         if ($('#tomultchckbx').is(':checked')) {
1485
+
1486
+             var numbersfile = 1;
1487
+             var initinterval = $("#multsmsinterval").val();
1488
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1489
+
1490
+             if (secinterval != '') {
1491
+                 var tertinterval = parseInt(secinterval);
1492
+                     waittime = tertinterval;
1493
+             }
1494
+
1495
+         } else {
1496
+
1497
+             var numbersfile = 0;
1498
+             var toNumberinit = $('#smsto').val();
1499
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1500
+             var toNumbersec = toNumber.split(",");
1501
+
1502
+                 for (var i = 0; i < toNumbersec.length; i++) {
1503
+                      toNumbersec[i] = "+" + toNumbersec[i];
1504
+                 }
1505
+
1506
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1507
+         }
1508
+
1509
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1510
+
1511
+         var smstext = $("#smstext").val();
1512
+
1513
+         if (receiversNumbers.length != 0) {
1514
+
1515
+              if (smstext != '') {
1516
+                  $.ajax({
1517
+                     url: relbaseUrl + '/' + userid,
1518
+                     type: "POST",
1519
+                     data: {
1520
+                           receiversPhoneNbs: receiversNumbers,
1521
+                           fromsender: selectedsender,
1522
+                           waitinterval: waittime,
1523
+                           sentsmstext: smstext,
1524
+                           ismms: isMMS,
1525
+                           mmsfiles: uploadedtomms
1526
+                         },
1527
+                     success: function() {
1528
+
1529
+                           if (receiversNumbers.length == 1) {
1530
+                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1531
+                           } else {
1532
+                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1533
+                           }
1534
+
1535
+                           $('#sms_submit_msg').hide();
1536
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1537
+                     },
1538
+                     error: function() {
1539
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1540
+                           $('#sms_submit_msg').hide();
1541
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1542
+                     }
1543
+                  });
1544
+              } else {
1545
+                     showAlert("Please enter a message in the text box !");
1546
+
1547
+                     $('#sms_submit_msg').hide();
1548
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1549
+              }
1550
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1551
+                 showAlert("Please enter the recipient's phone number !");
1552
+                 $('#sms_submit_msg').hide();
1553
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1554
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1555
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1556
+                 $('#sms_submit_msg').hide();
1557
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1558
+         }
1559
+     } else {
1560
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1561
+           $("#induploadfile").remove();
1562
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1563
+           $('#sms_submit_msg').hide();
1564
+     }
1565
+
1566
+  });
1567
+
1568
+  // Check the checkbox to delete old messages from the database
1569
+  $('#deleteoldchckbox').change(function() {
1570
+     if ($(this).is(':checked')) {
1571
+         $("#deleteoldsms").css("display", "block");
1572
+     } else {
1573
+         $("#deleteoldsms").css("display", "none");
1574
+     }
1575
+  });
1576
+
1577
+  // Set the height of info notes
1578
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1579
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1580
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1581
+
1582
+  $(window).resize(function() { 
1583
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1584
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1585
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1586
+  });
1587
+
1588
+
1589
+  function showAlert(alertText) {
1590
+
1591
+     $("#alertMsgOverlay").remove();
1592
+     $("#alertMessage").remove();
1593
+
1594
+     let alertwnd = "<div id='alertMessage'>";
1595
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1596
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1597
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1598
+     alertwnd += "</div>";
1599
+
1600
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1601
+     $("#content").append(alertwnd);
1602
+
1603
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1604
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1605
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1606
+
1607
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1608
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1609
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1610
+  }
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json appinfo/routes.php css/style.css js/adminsettings.js js/deleteoldsms.js js/sendsms.js js/settings.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php providers/Telnyx/lib/ApiResource.php

DoubleBastionAdmin authored on 15/07/2023 21:56:42
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1617 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
-
236
-  $.ajax({
237
-          url: cleanflUrl + '/' + userid,
238
-          type: "POST",
239
-          data: { userid: userid },
240
-          cache: false,
241
-          processData: false,
242
-          contentType: false
243
-  });
244
-  
245
-  // Check the available balance
246
-  $("#smsprovider").on("change", function () {
247
-
248
-     var provider = $('#smsprovider :selected').val();
249
-
250
-     if (provider == "Telnyx") {
251
-
252
-        var gettelbalance = function() {
253
-
254
-          $('#currentbalance').addClass('icon-loading');
255
-
256
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
-
258
-          $.ajax({
259
-              url: gettelbalanceUrl + '/' + userid,
260
-              type: "POST",
261
-              data: { userid: userid },
262
-              cache: false,
263
-              processData: false,
264
-              contentType: false,
265
-              success: function(currentbalancetel) {
266
-
267
-                     $('#currentbalance').empty();
268
-                     $('#currentbalance').text(currentbalancetel);
269
-                     $('#currentbalance').removeClass('icon-loading');
270
-              }
271
-          });
272
-        }
273
-
274
-        gettelbalance();
275
-
276
-     } else if (provider == "Plivo") {
277
-
278
-          var getnexbalance = function() {
279
-
280
-            $('#currentbalance').addClass('icon-loading');
281
-
282
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
-
284
-            $.ajax({
285
-                url: getnexbalanceUrl + '/' + userid,
286
-                type: "POST",
287
-                data: { userid: userid },
288
-                cache: false,
289
-                processData: false,
290
-                contentType: false,
291
-                success: function(currentbalancenex) {
292
-
293
-                     $('#currentbalance').empty();
294
-                     $('#currentbalance').text(currentbalancenex);
295
-                     $('#currentbalance').removeClass('icon-loading');
296
-                }
297
-            });
298
-          }
299
-
300
-          getnexbalance();
301
-
302
-     } else if (provider == "Twilio") {
303
-
304
-          var gettwilbalance = function() {
305
-
306
-            $('#currentbalance').addClass('icon-loading');
307
-
308
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
-
310
-            $.ajax({
311
-                url: gettwilbalanceUrl + '/' + userid,
312
-                type: "POST",
313
-                data: { userid: userid },
314
-                cache: false,
315
-                processData: false,
316
-                contentType: false,
317
-                success: function(currentbalancetwil) {
318
-
319
-                     $('#currentbalance').empty();
320
-                     $('#currentbalance').text(currentbalancetwil);
321
-                     $('#currentbalance').removeClass('icon-loading');
322
-                }
323
-            });
324
-          }
325
-
326
-          gettwilbalance();
327
-
328
-     } else if (provider == "Flowroute") {
329
-
330
-          var getflowbalance = function() {
331
-
332
-            $('#currentbalance').addClass('icon-loading');
333
-
334
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
-
336
-            $.ajax({
337
-                url: getflowbalanceUrl + '/' + userid,
338
-                type: "POST",
339
-                data: { userid: userid },
340
-                cache: false,
341
-                processData: false,
342
-                contentType: false,
343
-                success: function(currentbalanceflow) {
344
-
345
-                     $('#currentbalance').empty();
346
-                     $('#currentbalance').text(currentbalanceflow);
347
-                     $('#currentbalance').removeClass('icon-loading');
348
-                }
349
-            });
350
-          }
351
-
352
-          getflowbalance();
353
-
354
-       } else if (provider == "") {
355
-                $('#currentbalance').text("");
356
-                $('#currentbalance').removeClass('icon-loading');
357
-       }
358
-  });
359
-
360
-
361
-  // If a Sender ID is selected
362
-  $("#currentsmsnmbrs").on("change", function () {
363
-
364
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
-
366
-              selectedid = $('#currentsmsnmbrs :selected').val();
367
-              var setIdsplit = selectedid.split(":");
368
-	      chosenProvider = setIdsplit[0];
369
-
370
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
-	      if (chosenProvider == "Tx") {
372
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
-		  // Maximum size of message text + files in KB
374
-		  maximumsize = 1024;
375
-                  maximumsizeinit = 1024;
376
-		  maxsizenonimage = 600;
377
-		  maximumfilenumber = 10;
378
-                  chosenProvFullName = "Telnyx";
379
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
-                                     or gif files, the size of all the files plus the size of the text should be \
381
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
-                  $("#tooltiptextfourth").html(infonotecontent);
391
-	      } else if (chosenProvider == "Pl") {
392
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
-		  // Maximum size of message text + files in KB
395
-		  maximumsize = 5120;
396
-                  maximumsizeinit = 5120;
397
-		  maxsizenonimage = 600;
398
-		  maximumfilenumber = 10;
399
-                  chosenProvFullName = "Plivo";
400
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
-                                     or gif files, the size of all the files plus the size of the text should be \
402
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
-                  $("#tooltiptextfourth").html(infonotecontent);
412
-	      } else if (chosenProvider == "Tw") {
413
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
-                                     "icalendar", "directory", "pdf", "pkpass"];
416
-		  // Maximum size of message text + files in KB
417
-		  maximumsize = 5120;
418
-                  maximumsizeinit = 5120;
419
-		  maxsizenonimage = 600;
420
-		  maximumfilenumber = 10;
421
-                  chosenProvFullName = "Twilio";
422
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
-                                     or gif files, the size of all the files plus the size of the text should be \
424
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
-                                     previewed in the adjoining pane."
435
-                  $("#tooltiptextfourth").html(infonotecontent);
436
-	      } else if (chosenProvider == "Fl") {
437
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
-		  // Maximum size of message text + files in KB
439
-		  maximumsize = 750;
440
-                  maximumsizeinit = 750;
441
-		  maxsizenonimage = 600;
442
-		  maximumfilenumber = 10;
443
-                  chosenProvFullName = "Flowroute";
444
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
-                                     png or gif files, the size of all the files plus the size of the text should be \
446
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
-                                     size of the files plus the size of the text should be 600 KB or less. \
449
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
-                  $("#tooltiptextfourth").html(infonotecontent);
458
-	      }
459
-
460
-          } else { selectedid = ''; }
461
-  });
462
-
463
-  // Check the checkbox to send SMS message to multiple recipients
464
-  $('#tomultchckbx').change(function() {
465
-      if ($(this).is(':checked')) {
466
-          $("#multiplerecivers").css("display", "block");
467
-          $("#smstodiv").css("visibility", "hidden");
468
-          $("#smsto").val("");
469
-
470
-          receiversNumbers.length = 0;
471
-
472
-      } else {
473
-          $("#multiplerecivers").css("display", "none");
474
-          $("#smstodiv").css("visibility", "visible");
475
-
476
-          // Remove the uploaded file(s) if any
477
-          $("#induploadfile").remove();
478
-
479
-          receiversNumbers.length = 0;
480
-      }
481
-  });
482
-
483
-  // Upload the file with the recipients' phone numbers
484
-  $("#uploadfileforsms").change(function(e) {
485
-
486
-     $("#fileuploadednm").empty();
487
-
488
-     receiversNumbers.length = 0;
489
-
490
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
-
492
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
-
494
-     var formData = new FormData();
495
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
-
497
-     var fileup = $('#uploadfileforsms').val();
498
-     var fileuptrim = fileup.split('\\').pop();
499
-
500
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
-
502
-     var extension = fileup.replace(/^.*\./, '');
503
-
504
-     if (extension == fileup) {
505
-         extension = "";
506
-     } else {
507
-         extension = extension.toLowerCase();
508
-     }
509
-
510
-     var validExtensionsmrec = ["txt", "csv"];
511
-
512
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
-
514
-       if (selectedid != '') {
515
-
516
-               $.ajax({
517
-                 url: baseUrl + '/' + userid,
518
-                 type: "POST",
519
-                 data: formData,
520
-                 cache: false,
521
-                 processData: false,
522
-                 contentType: false,
523
-                 success: function(numberarray) {
524
-
525
-		    if (numberarray.length > 0) {
526
-
527
-		        // Get the array of the receivers' phone numbers
528
-		        if (chosenProvider == "Tx") {
529
-
530
-		             for(key in numberarray) {
531
-		                 receiversNumbers.push("+"+numberarray[key]);
532
-		             }
533
-
534
-		        } else if (chosenProvider == "Pl") {
535
-
536
-		             for(key in numberarray) {
537
-		                 receiversNumbers.push(numberarray[key]);
538
-		             }
539
-
540
-		          } else if (chosenProvider == "Tw") {
541
-
542
-		             for(key in numberarray) {
543
-		                 receiversNumbers.push(numberarray[key]);
544
-		             }
545
-		          } else if (chosenProvider == "Fl") {
546
-
547
-		             for(key in numberarray) {
548
-		                 receiversNumbers.push(numberarray[key]);
549
-		             }
550
-		          }
551
-
552
-		    } else {
553
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
-		    }
555
-                            
556
-                    // Preview the uploaded file
557
-                    var smsfilename = e.target.files[0].name;
558
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
-
560
-                    var reader = new FileReader();
561
-                    reader.readAsText(e.target.files[0]);
562
-                    reader.onload = function(e) {
563
-                          $("#smstables").empty();
564
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
-                    };
566
-
567
-                    $("#smstables").show();
568
-
569
-                    $('#sms_upload_msg').hide();
570
-                    $('#smstables').removeClass('icon-loading');
571
-
572
-                  },
573
-                  error: function() {
574
-                             showAlert("Error while uploading the file.");
575
-                  }
576
-               });
577
-
578
-        } else {
579
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
-               $('#sms_upload_msg').hide();
581
-               $('#smstables').removeClass('icon-loading');
582
-        }
583
-
584
-     } else {
585
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
-          $('#pf_upload_msg').hide();
587
-          $('#smstables').removeClass('icon-loading');
588
-
589
-          $("#induploadfile").remove();
590
-          $("#sms_upload_msg").hide();
591
-     }
592
-
593
-     // Preview uploaded file when clicked
594
-     $("#indfilediv").on("click", function() {
595
-
596
-          var smsfilename = e.target.files[0].name;
597
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
-
599
-          var reader = new FileReader();
600
-          reader.readAsText(e.target.files[0]);
601
-          reader.onload = function(e) {
602
-                  $("#smstables").empty();
603
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
-          };
605
-
606
-          $("#smstables").show();
607
-          $('#sms_upload_msg').hide();
608
-          $('#smstables').removeClass('icon-loading');
609
-     });
610
-
611
-     // Remove selected file
612
-     $("#indivflremove").on("click", function() {
613
-
614
-          $("#induploadfile").remove();
615
-          $("#sms_upload_msg").hide();
616
-
617
-          receiversNumbers.length = 0;
618
-
619
-     });
620
-
621
-  });
622
-
623
-  // Show the number of characters entered in the SMS textarea and the text size in KB
624
-  $("#smstext").on('input', function() {
625
-
626
-     $("#char_count").css("display", "inline");
627
-
628
-     $("#mtextSize").css("display", "inline");
629
-
630
-     $(".maxmessagelength").css("display", "inline-block");
631
-
632
-     $("#countchnb").text($(this).val().length);
633
-
634
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
-     $("#textsizeinkb").text(textsizekb);
637
-
638
-     if ($(this).val().length > charcolorthr) {
639
-         $("#char_count").css("color", "#BB2E4B");
640
-     } else {
641
-         $("#char_count").css("color", "#4cbc86;");
642
-     }
643
-
644
-  });
645
-
646
-
647
-  // Check the checkbox to send file(s) as MMS
648
-  $('#mediafilechckbx').change(function() {
649
-
650
-      if ($(this).is(':checked')) {
651
-
652
-          isMMS = 1;
653
-          if (selectedid == '') {
654
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
-              $(this).prop("checked", false);
656
-              isMMS = 0;
657
-              return;
658
-          }
659
-          $("#upmediafiles").css("display", "block");
660
-          $("#submitsms").prop("value", "Send MMS");
661
-
662
-      } else {
663
-
664
-          isMMS = 0;
665
-          $("#upmediafiles").css("display", "none");
666
-          $("#submitsms").prop("value", "Send SMS");
667
-
668
-          // Remove the uploaded file(s) if any
669
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
-          $(".indgenpckfls").each(function() { $(this).remove(); });
671
-
672
-          uploadedtomms = [];
673
-          n = 1;
674
-
675
-          msgtotalflsize = 0;
676
-
677
-          $("#filestotsize").hide();
678
-      }
679
-  });
680
-
681
-
682
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
-  function adjustMaximumSize(uploadedtomms) {
684
-				      
685
-      var nonimgcheck = 0;
686
-      for (var u = 0; u < uploadedtomms.length; u++) {
687
-	   var crupfl = uploadedtomms[u];
688
-	   var extensionup = crupfl.replace(/^.*\./, '');
689
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
-	       nonimgcheck = 1;
691
-	   }
692
-      }
693
-
694
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
-  }
696
-
697
-  // Upload files to be sent as MMS
698
-  $("#uploadfileformms").change(function(e) {
699
-
700
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
-     $('#smstables').addClass('icon-loading');
702
-     $('#filestotsize').show();
703
-
704
-     var userid = "<?php p($userId); ?>";
705
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
-
707
-     var formData = new FormData();
708
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
-
710
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
-
712
-     // Add the size of the current file to the total size of all the files
713
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
-
715
-     var fileup = $('#uploadfileformms').val();
716
-     var fileuptrim = fileup.split('\\').pop();
717
-
718
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
-         var duplicatescheck = 1;
720
-     } else { 
721
-         var duplicatescheck = 0;
722
-     }
723
-
724
-     var extension = fileup.replace(/^.*\./, '');
725
-
726
-     if (extension == fileup) {
727
-         extension = "";
728
-     } else {
729
-         extension = extension.toLowerCase();
730
-     }
731
-
732
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
-         maximumsize = maxsizenonimage;
735
-     }
736
-
737
-     if ($.inArray(extension, validExtensions) != -1) {
738
-
739
-       if (duplicatescheck == 0) {
740
-
741
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
-
743
-            if (n <= maximumfilenumber) {
744
-
745
-               $.ajax({
746
-                 url: baseUrl + '/' + userid,
747
-                 type: "POST",
748
-                 data: formData,
749
-                 cache: false,
750
-                 processData: false,
751
-                 contentType: false,
752
-                 success: function(totalflsize) {
753
-
754
-                   uploadedtomms.push(fileuptrim);
755
-
756
-                   $('#filessizetext').text(totalflsize);
757
-
758
-                   var rectotfilesz = parseFloat(totalflsize);
759
-
760
-                   if (rectotfilesz <= maximumsize) {
761
-                       $('#submitsms').attr("disabled", false);
762
-                       $('#filestotsize').css('color', '#189558');
763
-                   } else {
764
-                       $('#filestotsize').css('color', '#ba3555');
765
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
-                       $('#submitsms').attr("disabled", true);
767
-                       $('#smstables').removeClass('icon-loading');
768
-                       $('#pf_upload_msg').hide();
769
-                   }
770
-
771
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
-                   n++;
773
-
774
-                   // Preview the file when you click on its name
775
-                   $("div:visible[id*='indfilediv']").each(function() {
776
-
777
-                        $(this).on("click", function(eventclck) {
778
-
779
-                           $("#mmsfoldersview").css("display", "inline-block");
780
-                           var mmsfilenameinit = $(this).text();
781
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
-                           var mmsfilename = mmsfilenamesec.replace("X","");
783
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
-
786
-                           if (extenlst == mmsfilename) {
787
-                               extenlst = "";
788
-                           } else {
789
-                               extenlst = extenlst.toLowerCase();
790
-                           }
791
-
792
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
-                                  $("#smstables").empty();
794
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
-                           } else if (extenlst == 'png') {
797
-                                  $("#smstables").empty();
798
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
-                           } else if (extenlst == 'gif') {
801
-                                  $("#smstables").empty();
802
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
-                           } else if (extenlst == 'bmp') {
805
-                                  $("#smstables").empty();
806
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
-                                  var xhr = new XMLHttpRequest();
811
-                                  xhr.responseType = 'arraybuffer';
812
-                                  xhr.open('GET', tiffile);
813
-                                  xhr.onload = function (evnt) {
814
-                                      var tiff = new Tiff({buffer: xhr.response});
815
-                                      var tifcanvas = tiff.toCanvas();
816
-                                      $("#smstables").empty();
817
-                                      $("#smstables").append(tifcanvas);
818
-                                  };
819
-                                  xhr.send();
820
-                           } else if (extenlst == 'pdf') {
821
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
-                                  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>');
823
-                                  $("#smstables").empty();
824
-                                  $("#smstables").append($iframe);
825
-                           } else if (extenlst == 'txt') {
826
-                                  $("#smstables").empty();
827
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
-                           } else if (extension == 'mp4') {
829
-                                  $("#smstables").empty();
830
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
-		           } else if (extension == 'ogg') {
832
-		                  $("#smstables").empty();
833
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
-		           } else if (extension == 'avi') {
835
-		                  $("#smstables").empty();
836
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
-		                  $("#smstables").empty();
839
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
-		           } else if (extension == 'wav' || extension == 'wave') {
841
-		                  $("#smstables").empty();
842
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
-		           } else if (extension == 'mp3') {
844
-		                  $("#smstables").empty();
845
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
-		           } else if (extension == 'midi') {
847
-		                  $("#smstables").empty();
848
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
-		           }
850
-
851
-                           $("#smstables").show();
852
-                           $("#mmsfoldersview").hide();
853
-                        });
854
-                   });
855
-
856
-                   // Remove uploaded files
857
-                   $('[class*="indupfldl"]').last().click(function() {
858
-
859
-                           var userid = "<?php p($userId); ?>";
860
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
-
862
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
-
864
-                           var removedfilesplit = removedfilenameinit.split(") ");
865
-                           var removedflnb = parseInt(removedfilesplit[0]);
866
-
867
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
-                           $(this).hide();
869
-
870
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
-
872
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
-                                           return value != removedfilename;
874
-                           });
875
-
876
-                           $.ajax({
877
-                                   url: baseUrl + '/' + userid,
878
-                                   type: "POST",
879
-                                   data: {removedfilename: removedfilename},
880
-                                   success: function(totalflsize) {
881
-
882
-                                      msgtotalflsize = totalflsize;
883
-                                      $('#filessizetext').text(totalflsize);
884
-
885
-                                      adjustMaximumSize(uploadedtomms);
886
-
887
-                                      // Check message size
888
-                                      var rectotfilesz = parseFloat(totalflsize);
889
-
890
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
-                                          $('#submitsms').attr("disabled", false);
892
-                                          $('#filestotsize').css('color', '#189558');
893
-                                      } else {
894
-                                          $('#filestotsize').css('color', '#ba3555');
895
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
-                                          $('#submitsms').attr("disabled", true);
897
-                                      }
898
-
899
-                                      // Rewrite order numbers for files that follow
900
-                                      --n;
901
-                                      $("div:visible[id*='indfilediv']").each(function() {
902
-
903
-                                          var getdivtext =  $(this).text();
904
-                                          var splitdivtext = getdivtext.split(") ");
905
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
-                                          var newnbvalue = currentnbvalue - 1;
907
-
908
-                                          if (currentnbvalue > removedflnb) {
909
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
-                                              $(this).text(replacedstr);
911
-                                          }
912
-                                      });
913
-
914
-                                      $("div:visible[id*='indflpicked']").each(function() {
915
-
916
-                                          var getdivtext =  $(this).text();
917
-                                          var splitdivtext = getdivtext.split(") ");
918
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
-                                          var newnbvalue = currentnbvalue - 1;
920
-
921
-                                          if (currentnbvalue > removedflnb) {
922
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
-                                              $(this).text(replacedstr);
924
-                                          }
925
-                                      });
926
-
927
-                                   },
928
-                                   error: function() {
929
-                                              showAlert("Error while removing the file(s).");
930
-                                   }
931
-                           });
932
-
933
-                           $('#smstables').removeClass('icon-loading');
934
-                           $("#smstables").empty();
935
-                   });
936
-
937
-                   // Preview the uploaded file
938
-                   $("#mmsfoldersview").css("display", "inline-block");
939
-                   var mmsfilename = e.target.files[0].name;
940
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
-
942
-
943
-                   if (extension == 'jpg' || extension == 'jpeg') {
944
-                              $("#smstables").empty();
945
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
-
947
-                              var reader = new FileReader();
948
-                              reader.onload = function (e) {
949
-                                  readjpg[mmsfilename] = e.target.result;
950
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
-                              }
952
-                              reader.readAsDataURL(e.target.files[0]);
953
-                   } else if (extension == 'png') {
954
-                              $("#smstables").empty();
955
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
-
957
-                              var reader = new FileReader();
958
-                              reader.onload = function (e) {
959
-                                  readpng[mmsfilename] = e.target.result;
960
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
-                              }
962
-                              reader.readAsDataURL(e.target.files[0]);
963
-
964
-                   } else if (extension == 'gif') {
965
-                              $("#smstables").empty();
966
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
-
968
-                              var reader = new FileReader();
969
-                              reader.onload = function (e) {
970
-                                  readgif[mmsfilename] = e.target.result;
971
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
-                              }
973
-                              reader.readAsDataURL(e.target.files[0]);
974
-
975
-                   } else if (extension == 'bmp') {
976
-                              $("#smstables").empty();
977
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
-
979
-                              var reader = new FileReader();
980
-                              reader.onload = function (e) {
981
-                                  readbmp[mmsfilename] = e.target.result;
982
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
-                              }
984
-                              reader.readAsDataURL(e.target.files[0]);
985
-
986
-                   } else if (extension == 'tif' || extension == 'tiff') {
987
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
-                              var xhr = new XMLHttpRequest();
989
-                              xhr.responseType = 'arraybuffer';
990
-                              xhr.open('GET', tiffile);
991
-                              xhr.onload = function (e) {
992
-                                  var tiff = new Tiff({buffer: xhr.response});
993
-                                  var tifcanvas = tiff.toCanvas();
994
-                                  $("#smstables").empty();
995
-                                  $("#smstables").append(tifcanvas);
996
-                              };
997
-                              xhr.send();
998
-
999
-                   } else if (extension == 'pdf') {
1000
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
-                              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>');
1002
-                              $("#smstables").empty();
1003
-                              $("#smstables").append($iframe);
1004
-
1005
-                   } else if (extension == 'txt') {
1006
-                              var reader = new FileReader();
1007
-                              reader.readAsText(e.target.files[0]);
1008
-                              reader.onload = function(e) {
1009
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
-                                  $("#smstables").empty();
1011
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
-                              };
1013
-                   } else if (extension == 'mp4') {
1014
-                              $("#smstables").empty();
1015
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
-                   } else if (extension == 'ogg') {
1017
-                              $("#smstables").empty();
1018
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
-                   } else if (extension == 'avi') {
1020
-                              $("#smstables").empty();
1021
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
-                              $("#smstables").empty();
1024
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
-                   } else if (extension == 'wav' || extension == 'wave') {
1026
-                              $("#smstables").empty();
1027
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
-                   } else if (extension == 'mp3') {
1029
-                              $("#smstables").empty();
1030
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
-                   } else if (extension == 'midi') {
1032
-                              $("#smstables").empty();
1033
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
-                   }
1035
-
1036
-                   $("#smstables").show();
1037
-                   $('#pf_upload_msg').hide();
1038
-                   $('#smstables').removeClass('icon-loading');
1039
-                   $("#mmsfoldersview").hide();
1040
-                 },
1041
-                 error: function() {
1042
-                              showAlert("Error while uploading the file.");
1043
-                 }
1044
-               });
1045
-
1046
-            } else {
1047
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
-                  adjustMaximumSize(uploadedtomms);
1049
-
1050
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
-                  $('#pf_upload_msg').hide();
1052
-                  $('#smstables').removeClass('icon-loading');
1053
-            }
1054
-         } else {
1055
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
-              adjustMaximumSize(uploadedtomms);
1057
-
1058
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
-              $('#pf_upload_msg').hide();
1060
-              $('#smstables').removeClass('icon-loading');
1061
-         }
1062
-       } else {
1063
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
-            adjustMaximumSize(uploadedtomms);
1065
-
1066
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
-            $('#pf_upload_msg').hide();
1068
-            $('#smstables').removeClass('icon-loading');
1069
-       }
1070
-
1071
-     } else {
1072
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
-          adjustMaximumSize(uploadedtomms);
1074
-
1075
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
-          $('#pf_upload_msg').hide();
1077
-          $('#smstables').removeClass('icon-loading');
1078
-     }
1079
-  });
1080
-
1081
-
1082
-  // Pick file(s) from Nextcloud, to send as MMS
1083
-  var mmsfilename = null;
1084
-
1085
-  $("#choosefilen").on("click", function(evn) {
1086
-
1087
-                OC.dialogs.filepicker(
1088
-                        t('settings', "Select a file to send as MMS."),
1089
-                        function (path) {
1090
-
1091
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
-                              $('#smstables').addClass('icon-loading');
1093
-                              $('#filestotsize').show();
1094
-
1095
-                              var userid = "<?php p($userId); ?>";
1096
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
-
1098
-                              mmsfilename = path.split('/').pop();
1099
-
1100
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
-                                  var duplicatescheck = 1;
1102
-                              } else var duplicatescheck = 0;
1103
-
1104
-                              var extension = mmsfilename.replace(/^.*\./, '');
1105
-
1106
-                              if (extension == mmsfilename) {
1107
-                                  extension = "";
1108
-                              } else {
1109
-                                  extension = extension.toLowerCase();
1110
-                              }
1111
-
1112
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
-				   maximumsize = maxsizenonimage;
1115
-			      }
1116
-
1117
-                              if ($.inArray(extension, validExtensions) != -1) {
1118
-
1119
-                                 if (duplicatescheck == 0) {
1120
-
1121
-                                    if (n <= maximumfilenumber) {
1122
-
1123
-                                       $.ajax({
1124
-                                          url: baseUrl + '/' + userid,
1125
-                                          type: "POST",
1126
-                                          data: { path: path },
1127
-                                          success: function(pickresult) {
1128
-
1129
-                                                uploadedtomms.push(mmsfilename);
1130
-
1131
-                                                var totalflsize = pickresult[0];
1132
-                                                var pickedflsize = pickresult[1];
1133
-
1134
-                                                // Check message size
1135
-                                                var rectotfilesz = parseFloat(totalflsize);
1136
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
-
1138
-                                                if (filesplustextsize <= maximumsize) {
1139
-
1140
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
-
1142
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
-                                                    n++;
1144
-
1145
-                                                    msgtotalflsize = totalflsize;
1146
-                                                    $('#filessizetext').text(totalflsize);
1147
-                                                    $('#filestotsize').css('color', '#189558');
1148
-
1149
-                                                } else {
1150
-
1151
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
-                                                    $('#filestotsize').css('color', '#ba3555');
1153
-                                                    msgtotalflsize -= pickedflsize;
1154
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
-
1156
-                                                    $.ajax({
1157
-                                                        url: baseUrlindrm + '/' + userid,
1158
-                                                        type: "POST",
1159
-                                                        data: {removedfilename: mmsfilename},
1160
-                                                        success: function(totalflsize) {
1161
-
1162
-                                                                          $('#filessizetext').text(totalflsize);
1163
-                                                                          $('#filestotsize').css('color', '#189558');
1164
-                                                                          adjustMaximumSize(uploadedtomms);
1165
-
1166
-                                                        },
1167
-                                                        error: function(totalflsize) {
1168
-                                                                          $('#filessizetext').text(totalflsize);
1169
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
-                                                                              $('#filestotsize').css('color', '#ba3555');
1171
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
-                                                        }
1174
-                                                    });
1175
-
1176
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
-                                                }
1178
-
1179
-
1180
-                                                // Preview each file when you click on its name
1181
-                                                $("div:visible[id*='indflpicked']").each(function() {
1182
-                                                   $(this).on("click", function(event) {
1183
-
1184
-                                                      var mmsfilenameinit = $(this).text();
1185
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
-
1190
-                                                      if (extenlst == mmsfilenamesp) {
1191
-                                                           extenlst = "";
1192
-                                                      } else {
1193
-                                                           extenlst = extenlst.toLowerCase();
1194
-                                                      }
1195
-
1196
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
-                                                              $("#smstables").empty();
1198
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
-                                                      } else if (extenlst == 'png') {
1200
-                                                              $("#smstables").empty();
1201
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
-                                                      } else if (extenlst == 'gif') {
1203
-                                                              $("#smstables").empty();
1204
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
-                                                      } else if (extenlst == 'bmp') {
1206
-                                                              $("#smstables").empty();
1207
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
-                                                              var xhr = new XMLHttpRequest();
1211
-                                                              xhr.responseType = 'arraybuffer';
1212
-                                                              xhr.open('GET', tiffile);
1213
-                                                              xhr.onload = function (evnt) {
1214
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
-                                                                  var tifcanvas = tiff.toCanvas();
1216
-                                                                  $("#smstables").empty();
1217
-                                                                  $("#smstables").append(tifcanvas);
1218
-                                                              };
1219
-                                                              xhr.send();
1220
-                                                      } else if (extenlst == 'pdf') {
1221
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
-                                                              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>');
1223
-                                                              $("#smstables").empty();
1224
-                                                              $("#smstables").append($iframe);
1225
-                                                      } else if (extenlst == 'txt') {
1226
-                                                              $("#smstables").empty();
1227
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
-                                                      } else if (extension == 'mp4') {
1229
-							      $("#smstables").empty();
1230
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
-						      } else if (extension == 'ogg') {
1232
-							      $("#smstables").empty();
1233
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
-						      } else if (extension == 'avi') {
1235
-							      $("#smstables").empty();
1236
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
-							      $("#smstables").empty();
1239
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
-						      } else if (extension == 'wav' || extension == 'wave') {
1241
-							      $("#smstables").empty();
1242
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
-						      } else if (extension == 'mp3') {
1244
-							      $("#smstables").empty();
1245
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
-						      } else if (extension == 'midi') {
1247
-							      $("#smstables").empty();
1248
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
-						      }
1250
-
1251
-
1252
-                                                      $("#smstables").show();
1253
-                                                      $("#mmsfoldersview").hide();
1254
-                                                   });
1255
-                                                });
1256
-
1257
-
1258
-                                                // Remove picked files
1259
-                                                $('[class*="indpckfldl"]').last().click(function() {
1260
-                                                    var userid = "<?php p($userId); ?>";
1261
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
-
1263
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
-
1265
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
-
1268
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
-                                                    $(this).hide();
1270
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
-
1272
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
-                                                             return value != removedfilename;
1274
-                                                    });
1275
-
1276
-                                                    $.ajax({
1277
-                                                        url: baseUrl + '/' + userid,
1278
-                                                        type: "POST",
1279
-                                                        data: {removedfilename: removedfilename},
1280
-                                                        success: function(totalflsize) {
1281
-
1282
-                                                             msgtotalflsize = totalflsize;
1283
-                                                             $('#filessizetext').text(totalflsize);
1284
-                                                             adjustMaximumSize(uploadedtomms);
1285
-
1286
-                                                             // Check message size
1287
-                                                             var rectotfilesz = parseFloat(totalflsize);
1288
-
1289
-                                                             if (rectotfilesz > maximumsize) {
1290
-                                                                 $('#filestotsize').css('color', '#ba3555');
1291
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
-                                                                 $('#submitsms').attr("disabled", true);
1293
-                                                             } else {
1294
-                                                                 $('#submitsms').attr("disabled", false);
1295
-                                                                 $('#filestotsize').css('color', '#189558');
1296
-                                                               }
1297
-
1298
-                                                             // Rewrite order numbers for files that follow
1299
-                                                             --n;
1300
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
-
1302
-                                                                  var getdivtext =  $(this).text();
1303
-                                                                  var splitdivtext = getdivtext.split(") ");
1304
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
-                                                                  var newnbvalue = currentnbvalue - 1;
1306
-
1307
-                                                                  if (currentnbvalue > removedflnb) {
1308
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
-                                                                      $(this).text(replacedstr);
1310
-                                                                  }
1311
-                                                             });
1312
-                                                        },
1313
-                                                        error: function() {
1314
-                                                                  showAlert("Error while removing the file.");
1315
-                                                        }
1316
-                                                    });
1317
-
1318
-                                                    $('#smstables').removeClass('icon-loading');
1319
-                                                    $("#smstables").empty();
1320
-                                                });
1321
-
1322
-
1323
-		                                // Preview the picked file
1324
-		                                $("#mmsfoldersview").css("display", "inline-block");
1325
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
-
1328
-
1329
-						if (extension == 'jpg' || extension == 'jpeg') {
1330
-
1331
-		                                            $("#smstables").empty();
1332
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
-
1334
-		                                } else if (extension == 'png') {
1335
-
1336
-		                                            $("#smstables").empty();
1337
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
-
1339
-		                                } else if (extension == 'gif') {
1340
-
1341
-		                                            $("#smstables").empty();
1342
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
-
1344
-		                                } else if (extension == 'bmp') {
1345
-
1346
-	                                                    $("#smstables").empty();
1347
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
-
1349
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
-
1351
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
-		                                       var xhr = new XMLHttpRequest();
1353
-		                                       xhr.responseType = 'arraybuffer';
1354
-		                                       xhr.open('GET', tiffile);
1355
-		                                       xhr.onload = function (event) {
1356
-		                                           var tiff = new Tiff({buffer: xhr.response});
1357
-		                                           var tifcanvas = tiff.toCanvas();
1358
-		                                           $("#smstables").empty();
1359
-		                                           $("#smstables").append(tifcanvas);
1360
-		                                       };
1361
-		                                       xhr.send();
1362
-
1363
-		                                } else if (extension == 'pdf') {
1364
-
1365
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
-		                                       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>');
1367
-		                                       $("#smstables").empty();
1368
-		                                       $("#smstables").append($iframe);
1369
-
1370
-		                                } else if (extension == 'txt') {
1371
-
1372
-							     $.get(flUrl, function(textdata) {
1373
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
-		                                               $("#smstables").empty();
1375
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
-							     });
1377
-
1378
-		                                } else if (extension == 'mp4') {
1379
-						       $("#smstables").empty();
1380
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
-						} else if (extension == 'ogg') {
1382
-						       $("#smstables").empty();
1383
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
-						} else if (extension == 'avi') {
1385
-						       $("#smstables").empty();
1386
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
-						       $("#smstables").empty();
1389
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
-						} else if (extension == 'wav' || extension == 'wave') {
1391
-						       $("#smstables").empty();
1392
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
-						} else if (extension == 'mp3') {
1394
-						       $("#smstables").empty();
1395
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
-						} else if (extension == 'midi') {
1397
-						       $("#smstables").empty();
1398
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
-						}
1400
-
1401
-
1402
-		                                $("#smstables").show();
1403
-
1404
-		                                $('#pf_choose_msg').hide();
1405
-		                                $('#smstables').removeClass('icon-loading');
1406
-		                                $("#mmsfoldersview").hide();
1407
-
1408
-                                          },
1409
-
1410
-                                          error: function(data){
1411
-                                                      showAlert("Error while getting the file.");
1412
-                                          }
1413
-
1414
-                                       });
1415
-
1416
-                                    } else {
1417
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
-                                        $('#pf_choose_msg').hide();
1419
-                                        $('#smstables').removeClass('icon-loading');
1420
-                                      }
1421
-                                 } else {
1422
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
-                                      $('#pf_choose_msg').hide();
1424
-                                      $('#smstables').removeClass('icon-loading');
1425
-                                   }
1426
-
1427
-                              } else {
1428
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
-                                   $('#pf_choose_msg').hide();
1430
-                                   $('#smstables').removeClass('icon-loading');
1431
-                                }
1432
-
1433
-                        }
1434
-                );
1435
-  });
1436
-
1437
-
1438
-
1439
-  // Send the SMS/MMS message
1440
-  $("#submitsms").on("click", function(event) {
1441
-
1442
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
-     $("#sms_submit_msg").css("display", "inline-block");
1445
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
-
1447
-     if (selectedid != '') { 
1448
-
1449
-         var sendersplit = selectedid.split(":");
1450
-         var providercap = sendersplit[0];
1451
-         var provsec = sendersplit[1];
1452
-
1453
-         if (/[a-zA-Z]/.test(provsec)) {
1454
-             var alphanumcheck = true;
1455
-         } else { var alphanumcheck = false; }
1456
-
1457
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
-             var selectedsender = "+" + senderproc;
1460
-             var providerUsed = "telnyx";
1461
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
-             var providerUsed = "plivo";
1465
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
-             var selectedsender = "+" + senderproc;
1469
-             var providerUsed = "twilio";
1470
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
-             var selectedsender = "+" + senderproc;
1474
-             var providerUsed = "flowroute";
1475
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
-             var selectedsender = provsec;
1478
-             var providerUsed = "telnyx";
1479
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
-             var selectedsender = provsec;
1482
-             var providerUsed = "plivo";
1483
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
-             var selectedsender = provsec;
1486
-             var providerUsed = "twilio";
1487
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
-             var selectedsender = provsec;
1490
-             var providerUsed = "flowroute";
1491
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
-         }
1493
-
1494
-         // Get the interval between message consecutive sending requests, if it's the case
1495
-         if ($('#tomultchckbx').is(':checked')) {
1496
-
1497
-             var numbersfile = 1;
1498
-             var initinterval = $("#multsmsinterval").val();
1499
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
-
1501
-             if (secinterval != '') {
1502
-                 var tertinterval = parseInt(secinterval);
1503
-                     waittime = tertinterval;
1504
-             }
1505
-
1506
-         } else {
1507
-
1508
-             var numbersfile = 0;
1509
-             var toNumberinit = $('#smsto').val();
1510
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
-             var toNumbersec = toNumber.split(",");
1512
-
1513
-                 for (var i = 0; i < toNumbersec.length; i++) {
1514
-                      toNumbersec[i] = "+" + toNumbersec[i];
1515
-                 }
1516
-
1517
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
-         }
1519
-
1520
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
-
1522
-         var smstext = $("#smstext").val();
1523
-
1524
-         if (receiversNumbers.length != 0) {
1525
-
1526
-              if (smstext != '') {
1527
-                  $.ajax({
1528
-                     url: relbaseUrl + '/' + userid,
1529
-                     type: "POST",
1530
-                     data: {
1531
-                           receiversPhoneNbs: receiversNumbers,
1532
-                           fromsender: selectedsender,
1533
-                           waitinterval: waittime,
1534
-                           sentsmstext: smstext,
1535
-                           ismms: isMMS,
1536
-                           mmsfiles: uploadedtomms
1537
-                         },
1538
-                     success: function() {
1539
-
1540
-                           if (receiversNumbers.length == 1) {
1541
-                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
-                           } else {
1543
-                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
-                           }
1545
-
1546
-                           $('#sms_submit_msg').hide();
1547
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
-                     },
1549
-                     error: function() {
1550
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
-                           $('#sms_submit_msg').hide();
1552
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
-                     }
1554
-                  });
1555
-              } else {
1556
-                     showAlert("Please enter a message in the text box !");
1557
-
1558
-                     $('#sms_submit_msg').hide();
1559
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
-              }
1561
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
-                 showAlert("Please enter the recipient's phone number !");
1563
-                 $('#sms_submit_msg').hide();
1564
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
-                 $('#sms_submit_msg').hide();
1568
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
-         }
1570
-     } else {
1571
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
-           $('#sms_submit_msg').hide();
1574
-     }
1575
-
1576
-  });
1577
-
1578
-  // Check the checkbox to delete old messages from the database
1579
-  $('#deleteoldchckbox').change(function() {
1580
-     if ($(this).is(':checked')) {
1581
-         $("#deleteoldsms").css("display", "block");
1582
-     } else {
1583
-         $("#deleteoldsms").css("display", "none");
1584
-     }
1585
-  });
1586
-
1587
-  // Set the height of info notes
1588
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
-
1592
-  $(window).resize(function() { 
1593
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
-  });
1597
-
1598
-
1599
-  function showAlert(alertText) {
1600
-
1601
-     let alertwnd = "<div id='alertMessage'>";
1602
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
-     alertwnd += "</div>";
1606
-
1607
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
-     $("#content").append(alertwnd);
1609
-
1610
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
-
1614
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
-  }
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js js/showsmstables.js js/sendsms.js lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php lib/Migration/Version125Date20230603224815.php

DoubleBastionAdmin authored on 04/06/2023 00:54:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1617 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
+
236
+  $.ajax({
237
+          url: cleanflUrl + '/' + userid,
238
+          type: "POST",
239
+          data: { userid: userid },
240
+          cache: false,
241
+          processData: false,
242
+          contentType: false
243
+  });
244
+  
245
+  // Check the available balance
246
+  $("#smsprovider").on("change", function () {
247
+
248
+     var provider = $('#smsprovider :selected').val();
249
+
250
+     if (provider == "Telnyx") {
251
+
252
+        var gettelbalance = function() {
253
+
254
+          $('#currentbalance').addClass('icon-loading');
255
+
256
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
+
258
+          $.ajax({
259
+              url: gettelbalanceUrl + '/' + userid,
260
+              type: "POST",
261
+              data: { userid: userid },
262
+              cache: false,
263
+              processData: false,
264
+              contentType: false,
265
+              success: function(currentbalancetel) {
266
+
267
+                     $('#currentbalance').empty();
268
+                     $('#currentbalance').text(currentbalancetel);
269
+                     $('#currentbalance').removeClass('icon-loading');
270
+              }
271
+          });
272
+        }
273
+
274
+        gettelbalance();
275
+
276
+     } else if (provider == "Plivo") {
277
+
278
+          var getnexbalance = function() {
279
+
280
+            $('#currentbalance').addClass('icon-loading');
281
+
282
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
+
284
+            $.ajax({
285
+                url: getnexbalanceUrl + '/' + userid,
286
+                type: "POST",
287
+                data: { userid: userid },
288
+                cache: false,
289
+                processData: false,
290
+                contentType: false,
291
+                success: function(currentbalancenex) {
292
+
293
+                     $('#currentbalance').empty();
294
+                     $('#currentbalance').text(currentbalancenex);
295
+                     $('#currentbalance').removeClass('icon-loading');
296
+                }
297
+            });
298
+          }
299
+
300
+          getnexbalance();
301
+
302
+     } else if (provider == "Twilio") {
303
+
304
+          var gettwilbalance = function() {
305
+
306
+            $('#currentbalance').addClass('icon-loading');
307
+
308
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
+
310
+            $.ajax({
311
+                url: gettwilbalanceUrl + '/' + userid,
312
+                type: "POST",
313
+                data: { userid: userid },
314
+                cache: false,
315
+                processData: false,
316
+                contentType: false,
317
+                success: function(currentbalancetwil) {
318
+
319
+                     $('#currentbalance').empty();
320
+                     $('#currentbalance').text(currentbalancetwil);
321
+                     $('#currentbalance').removeClass('icon-loading');
322
+                }
323
+            });
324
+          }
325
+
326
+          gettwilbalance();
327
+
328
+     } else if (provider == "Flowroute") {
329
+
330
+          var getflowbalance = function() {
331
+
332
+            $('#currentbalance').addClass('icon-loading');
333
+
334
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
+
336
+            $.ajax({
337
+                url: getflowbalanceUrl + '/' + userid,
338
+                type: "POST",
339
+                data: { userid: userid },
340
+                cache: false,
341
+                processData: false,
342
+                contentType: false,
343
+                success: function(currentbalanceflow) {
344
+
345
+                     $('#currentbalance').empty();
346
+                     $('#currentbalance').text(currentbalanceflow);
347
+                     $('#currentbalance').removeClass('icon-loading');
348
+                }
349
+            });
350
+          }
351
+
352
+          getflowbalance();
353
+
354
+       } else if (provider == "") {
355
+                $('#currentbalance').text("");
356
+                $('#currentbalance').removeClass('icon-loading');
357
+       }
358
+  });
359
+
360
+
361
+  // If a Sender ID is selected
362
+  $("#currentsmsnmbrs").on("change", function () {
363
+
364
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
+
366
+              selectedid = $('#currentsmsnmbrs :selected').val();
367
+              var setIdsplit = selectedid.split(":");
368
+	      chosenProvider = setIdsplit[0];
369
+
370
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
+	      if (chosenProvider == "Tx") {
372
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
+		  // Maximum size of message text + files in KB
374
+		  maximumsize = 1024;
375
+                  maximumsizeinit = 1024;
376
+		  maxsizenonimage = 600;
377
+		  maximumfilenumber = 10;
378
+                  chosenProvFullName = "Telnyx";
379
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
+                                     or gif files, the size of all the files plus the size of the text should be \
381
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
+                  $("#tooltiptextfourth").html(infonotecontent);
391
+	      } else if (chosenProvider == "Pl") {
392
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
+		  // Maximum size of message text + files in KB
395
+		  maximumsize = 5120;
396
+                  maximumsizeinit = 5120;
397
+		  maxsizenonimage = 600;
398
+		  maximumfilenumber = 10;
399
+                  chosenProvFullName = "Plivo";
400
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
+                                     or gif files, the size of all the files plus the size of the text should be \
402
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
+                  $("#tooltiptextfourth").html(infonotecontent);
412
+	      } else if (chosenProvider == "Tw") {
413
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
+                                     "icalendar", "directory", "pdf", "pkpass"];
416
+		  // Maximum size of message text + files in KB
417
+		  maximumsize = 5120;
418
+                  maximumsizeinit = 5120;
419
+		  maxsizenonimage = 600;
420
+		  maximumfilenumber = 10;
421
+                  chosenProvFullName = "Twilio";
422
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
+                                     or gif files, the size of all the files plus the size of the text should be \
424
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
+                                     previewed in the adjoining pane."
435
+                  $("#tooltiptextfourth").html(infonotecontent);
436
+	      } else if (chosenProvider == "Fl") {
437
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
+		  // Maximum size of message text + files in KB
439
+		  maximumsize = 750;
440
+                  maximumsizeinit = 750;
441
+		  maxsizenonimage = 600;
442
+		  maximumfilenumber = 10;
443
+                  chosenProvFullName = "Flowroute";
444
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
+                                     png or gif files, the size of all the files plus the size of the text should be \
446
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
+                                     size of the files plus the size of the text should be 600 KB or less. \
449
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
+                  $("#tooltiptextfourth").html(infonotecontent);
458
+	      }
459
+
460
+          } else { selectedid = ''; }
461
+  });
462
+
463
+  // Check the checkbox to send SMS message to multiple recipients
464
+  $('#tomultchckbx').change(function() {
465
+      if ($(this).is(':checked')) {
466
+          $("#multiplerecivers").css("display", "block");
467
+          $("#smstodiv").css("visibility", "hidden");
468
+          $("#smsto").val("");
469
+
470
+          receiversNumbers.length = 0;
471
+
472
+      } else {
473
+          $("#multiplerecivers").css("display", "none");
474
+          $("#smstodiv").css("visibility", "visible");
475
+
476
+          // Remove the uploaded file(s) if any
477
+          $("#induploadfile").remove();
478
+
479
+          receiversNumbers.length = 0;
480
+      }
481
+  });
482
+
483
+  // Upload the file with the recipients' phone numbers
484
+  $("#uploadfileforsms").change(function(e) {
485
+
486
+     $("#fileuploadednm").empty();
487
+
488
+     receiversNumbers.length = 0;
489
+
490
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
+
492
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
+
494
+     var formData = new FormData();
495
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
+
497
+     var fileup = $('#uploadfileforsms').val();
498
+     var fileuptrim = fileup.split('\\').pop();
499
+
500
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
+
502
+     var extension = fileup.replace(/^.*\./, '');
503
+
504
+     if (extension == fileup) {
505
+         extension = "";
506
+     } else {
507
+         extension = extension.toLowerCase();
508
+     }
509
+
510
+     var validExtensionsmrec = ["txt", "csv"];
511
+
512
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
+
514
+       if (selectedid != '') {
515
+
516
+               $.ajax({
517
+                 url: baseUrl + '/' + userid,
518
+                 type: "POST",
519
+                 data: formData,
520
+                 cache: false,
521
+                 processData: false,
522
+                 contentType: false,
523
+                 success: function(numberarray) {
524
+
525
+		    if (numberarray.length > 0) {
526
+
527
+		        // Get the array of the receivers' phone numbers
528
+		        if (chosenProvider == "Tx") {
529
+
530
+		             for(key in numberarray) {
531
+		                 receiversNumbers.push("+"+numberarray[key]);
532
+		             }
533
+
534
+		        } else if (chosenProvider == "Pl") {
535
+
536
+		             for(key in numberarray) {
537
+		                 receiversNumbers.push(numberarray[key]);
538
+		             }
539
+
540
+		          } else if (chosenProvider == "Tw") {
541
+
542
+		             for(key in numberarray) {
543
+		                 receiversNumbers.push(numberarray[key]);
544
+		             }
545
+		          } else if (chosenProvider == "Fl") {
546
+
547
+		             for(key in numberarray) {
548
+		                 receiversNumbers.push(numberarray[key]);
549
+		             }
550
+		          }
551
+
552
+		    } else {
553
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
+		    }
555
+                            
556
+                    // Preview the uploaded file
557
+                    var smsfilename = e.target.files[0].name;
558
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
+
560
+                    var reader = new FileReader();
561
+                    reader.readAsText(e.target.files[0]);
562
+                    reader.onload = function(e) {
563
+                          $("#smstables").empty();
564
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
+                    };
566
+
567
+                    $("#smstables").show();
568
+
569
+                    $('#sms_upload_msg').hide();
570
+                    $('#smstables').removeClass('icon-loading');
571
+
572
+                  },
573
+                  error: function() {
574
+                             showAlert("Error while uploading the file.");
575
+                  }
576
+               });
577
+
578
+        } else {
579
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
+               $('#sms_upload_msg').hide();
581
+               $('#smstables').removeClass('icon-loading');
582
+        }
583
+
584
+     } else {
585
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
+          $('#pf_upload_msg').hide();
587
+          $('#smstables').removeClass('icon-loading');
588
+
589
+          $("#induploadfile").remove();
590
+          $("#sms_upload_msg").hide();
591
+     }
592
+
593
+     // Preview uploaded file when clicked
594
+     $("#indfilediv").on("click", function() {
595
+
596
+          var smsfilename = e.target.files[0].name;
597
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
+
599
+          var reader = new FileReader();
600
+          reader.readAsText(e.target.files[0]);
601
+          reader.onload = function(e) {
602
+                  $("#smstables").empty();
603
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
+          };
605
+
606
+          $("#smstables").show();
607
+          $('#sms_upload_msg').hide();
608
+          $('#smstables').removeClass('icon-loading');
609
+     });
610
+
611
+     // Remove selected file
612
+     $("#indivflremove").on("click", function() {
613
+
614
+          $("#induploadfile").remove();
615
+          $("#sms_upload_msg").hide();
616
+
617
+          receiversNumbers.length = 0;
618
+
619
+     });
620
+
621
+  });
622
+
623
+  // Show the number of characters entered in the SMS textarea and the text size in KB
624
+  $("#smstext").on('input', function() {
625
+
626
+     $("#char_count").css("display", "inline");
627
+
628
+     $("#mtextSize").css("display", "inline");
629
+
630
+     $(".maxmessagelength").css("display", "inline-block");
631
+
632
+     $("#countchnb").text($(this).val().length);
633
+
634
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
+     $("#textsizeinkb").text(textsizekb);
637
+
638
+     if ($(this).val().length > charcolorthr) {
639
+         $("#char_count").css("color", "#BB2E4B");
640
+     } else {
641
+         $("#char_count").css("color", "#4cbc86;");
642
+     }
643
+
644
+  });
645
+
646
+
647
+  // Check the checkbox to send file(s) as MMS
648
+  $('#mediafilechckbx').change(function() {
649
+
650
+      if ($(this).is(':checked')) {
651
+
652
+          isMMS = 1;
653
+          if (selectedid == '') {
654
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
+              $(this).prop("checked", false);
656
+              isMMS = 0;
657
+              return;
658
+          }
659
+          $("#upmediafiles").css("display", "block");
660
+          $("#submitsms").prop("value", "Send MMS");
661
+
662
+      } else {
663
+
664
+          isMMS = 0;
665
+          $("#upmediafiles").css("display", "none");
666
+          $("#submitsms").prop("value", "Send SMS");
667
+
668
+          // Remove the uploaded file(s) if any
669
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
+          $(".indgenpckfls").each(function() { $(this).remove(); });
671
+
672
+          uploadedtomms = [];
673
+          n = 1;
674
+
675
+          msgtotalflsize = 0;
676
+
677
+          $("#filestotsize").hide();
678
+      }
679
+  });
680
+
681
+
682
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
+  function adjustMaximumSize(uploadedtomms) {
684
+				      
685
+      var nonimgcheck = 0;
686
+      for (var u = 0; u < uploadedtomms.length; u++) {
687
+	   var crupfl = uploadedtomms[u];
688
+	   var extensionup = crupfl.replace(/^.*\./, '');
689
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
+	       nonimgcheck = 1;
691
+	   }
692
+      }
693
+
694
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
+  }
696
+
697
+  // Upload files to be sent as MMS
698
+  $("#uploadfileformms").change(function(e) {
699
+
700
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
+     $('#smstables').addClass('icon-loading');
702
+     $('#filestotsize').show();
703
+
704
+     var userid = "<?php p($userId); ?>";
705
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
+
707
+     var formData = new FormData();
708
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
+
710
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
+
712
+     // Add the size of the current file to the total size of all the files
713
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
+
715
+     var fileup = $('#uploadfileformms').val();
716
+     var fileuptrim = fileup.split('\\').pop();
717
+
718
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
+         var duplicatescheck = 1;
720
+     } else { 
721
+         var duplicatescheck = 0;
722
+     }
723
+
724
+     var extension = fileup.replace(/^.*\./, '');
725
+
726
+     if (extension == fileup) {
727
+         extension = "";
728
+     } else {
729
+         extension = extension.toLowerCase();
730
+     }
731
+
732
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
+         maximumsize = maxsizenonimage;
735
+     }
736
+
737
+     if ($.inArray(extension, validExtensions) != -1) {
738
+
739
+       if (duplicatescheck == 0) {
740
+
741
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
+
743
+            if (n <= maximumfilenumber) {
744
+
745
+               $.ajax({
746
+                 url: baseUrl + '/' + userid,
747
+                 type: "POST",
748
+                 data: formData,
749
+                 cache: false,
750
+                 processData: false,
751
+                 contentType: false,
752
+                 success: function(totalflsize) {
753
+
754
+                   uploadedtomms.push(fileuptrim);
755
+
756
+                   $('#filessizetext').text(totalflsize);
757
+
758
+                   var rectotfilesz = parseFloat(totalflsize);
759
+
760
+                   if (rectotfilesz <= maximumsize) {
761
+                       $('#submitsms').attr("disabled", false);
762
+                       $('#filestotsize').css('color', '#189558');
763
+                   } else {
764
+                       $('#filestotsize').css('color', '#ba3555');
765
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
+                       $('#submitsms').attr("disabled", true);
767
+                       $('#smstables').removeClass('icon-loading');
768
+                       $('#pf_upload_msg').hide();
769
+                   }
770
+
771
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
+                   n++;
773
+
774
+                   // Preview the file when you click on its name
775
+                   $("div:visible[id*='indfilediv']").each(function() {
776
+
777
+                        $(this).on("click", function(eventclck) {
778
+
779
+                           $("#mmsfoldersview").css("display", "inline-block");
780
+                           var mmsfilenameinit = $(this).text();
781
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
+                           var mmsfilename = mmsfilenamesec.replace("X","");
783
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
+
786
+                           if (extenlst == mmsfilename) {
787
+                               extenlst = "";
788
+                           } else {
789
+                               extenlst = extenlst.toLowerCase();
790
+                           }
791
+
792
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
+                                  $("#smstables").empty();
794
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
+                           } else if (extenlst == 'png') {
797
+                                  $("#smstables").empty();
798
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
+                           } else if (extenlst == 'gif') {
801
+                                  $("#smstables").empty();
802
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
+                           } else if (extenlst == 'bmp') {
805
+                                  $("#smstables").empty();
806
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
+                                  var xhr = new XMLHttpRequest();
811
+                                  xhr.responseType = 'arraybuffer';
812
+                                  xhr.open('GET', tiffile);
813
+                                  xhr.onload = function (evnt) {
814
+                                      var tiff = new Tiff({buffer: xhr.response});
815
+                                      var tifcanvas = tiff.toCanvas();
816
+                                      $("#smstables").empty();
817
+                                      $("#smstables").append(tifcanvas);
818
+                                  };
819
+                                  xhr.send();
820
+                           } else if (extenlst == 'pdf') {
821
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
+                                  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>');
823
+                                  $("#smstables").empty();
824
+                                  $("#smstables").append($iframe);
825
+                           } else if (extenlst == 'txt') {
826
+                                  $("#smstables").empty();
827
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
+                           } else if (extension == 'mp4') {
829
+                                  $("#smstables").empty();
830
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
+		           } else if (extension == 'ogg') {
832
+		                  $("#smstables").empty();
833
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
+		           } else if (extension == 'avi') {
835
+		                  $("#smstables").empty();
836
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
+		                  $("#smstables").empty();
839
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
+		           } else if (extension == 'wav' || extension == 'wave') {
841
+		                  $("#smstables").empty();
842
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
+		           } else if (extension == 'mp3') {
844
+		                  $("#smstables").empty();
845
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
+		           } else if (extension == 'midi') {
847
+		                  $("#smstables").empty();
848
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
+		           }
850
+
851
+                           $("#smstables").show();
852
+                           $("#mmsfoldersview").hide();
853
+                        });
854
+                   });
855
+
856
+                   // Remove uploaded files
857
+                   $('[class*="indupfldl"]').last().click(function() {
858
+
859
+                           var userid = "<?php p($userId); ?>";
860
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
+
862
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
+
864
+                           var removedfilesplit = removedfilenameinit.split(") ");
865
+                           var removedflnb = parseInt(removedfilesplit[0]);
866
+
867
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
+                           $(this).hide();
869
+
870
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
+
872
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
+                                           return value != removedfilename;
874
+                           });
875
+
876
+                           $.ajax({
877
+                                   url: baseUrl + '/' + userid,
878
+                                   type: "POST",
879
+                                   data: {removedfilename: removedfilename},
880
+                                   success: function(totalflsize) {
881
+
882
+                                      msgtotalflsize = totalflsize;
883
+                                      $('#filessizetext').text(totalflsize);
884
+
885
+                                      adjustMaximumSize(uploadedtomms);
886
+
887
+                                      // Check message size
888
+                                      var rectotfilesz = parseFloat(totalflsize);
889
+
890
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
+                                          $('#submitsms').attr("disabled", false);
892
+                                          $('#filestotsize').css('color', '#189558');
893
+                                      } else {
894
+                                          $('#filestotsize').css('color', '#ba3555');
895
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
+                                          $('#submitsms').attr("disabled", true);
897
+                                      }
898
+
899
+                                      // Rewrite order numbers for files that follow
900
+                                      --n;
901
+                                      $("div:visible[id*='indfilediv']").each(function() {
902
+
903
+                                          var getdivtext =  $(this).text();
904
+                                          var splitdivtext = getdivtext.split(") ");
905
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
+                                          var newnbvalue = currentnbvalue - 1;
907
+
908
+                                          if (currentnbvalue > removedflnb) {
909
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
+                                              $(this).text(replacedstr);
911
+                                          }
912
+                                      });
913
+
914
+                                      $("div:visible[id*='indflpicked']").each(function() {
915
+
916
+                                          var getdivtext =  $(this).text();
917
+                                          var splitdivtext = getdivtext.split(") ");
918
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
+                                          var newnbvalue = currentnbvalue - 1;
920
+
921
+                                          if (currentnbvalue > removedflnb) {
922
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
+                                              $(this).text(replacedstr);
924
+                                          }
925
+                                      });
926
+
927
+                                   },
928
+                                   error: function() {
929
+                                              showAlert("Error while removing the file(s).");
930
+                                   }
931
+                           });
932
+
933
+                           $('#smstables').removeClass('icon-loading');
934
+                           $("#smstables").empty();
935
+                   });
936
+
937
+                   // Preview the uploaded file
938
+                   $("#mmsfoldersview").css("display", "inline-block");
939
+                   var mmsfilename = e.target.files[0].name;
940
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
+
942
+
943
+                   if (extension == 'jpg' || extension == 'jpeg') {
944
+                              $("#smstables").empty();
945
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
+
947
+                              var reader = new FileReader();
948
+                              reader.onload = function (e) {
949
+                                  readjpg[mmsfilename] = e.target.result;
950
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
+                              }
952
+                              reader.readAsDataURL(e.target.files[0]);
953
+                   } else if (extension == 'png') {
954
+                              $("#smstables").empty();
955
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
+
957
+                              var reader = new FileReader();
958
+                              reader.onload = function (e) {
959
+                                  readpng[mmsfilename] = e.target.result;
960
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
+                              }
962
+                              reader.readAsDataURL(e.target.files[0]);
963
+
964
+                   } else if (extension == 'gif') {
965
+                              $("#smstables").empty();
966
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
+
968
+                              var reader = new FileReader();
969
+                              reader.onload = function (e) {
970
+                                  readgif[mmsfilename] = e.target.result;
971
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
+                              }
973
+                              reader.readAsDataURL(e.target.files[0]);
974
+
975
+                   } else if (extension == 'bmp') {
976
+                              $("#smstables").empty();
977
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
+
979
+                              var reader = new FileReader();
980
+                              reader.onload = function (e) {
981
+                                  readbmp[mmsfilename] = e.target.result;
982
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
+                              }
984
+                              reader.readAsDataURL(e.target.files[0]);
985
+
986
+                   } else if (extension == 'tif' || extension == 'tiff') {
987
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
+                              var xhr = new XMLHttpRequest();
989
+                              xhr.responseType = 'arraybuffer';
990
+                              xhr.open('GET', tiffile);
991
+                              xhr.onload = function (e) {
992
+                                  var tiff = new Tiff({buffer: xhr.response});
993
+                                  var tifcanvas = tiff.toCanvas();
994
+                                  $("#smstables").empty();
995
+                                  $("#smstables").append(tifcanvas);
996
+                              };
997
+                              xhr.send();
998
+
999
+                   } else if (extension == 'pdf') {
1000
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
+                              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>');
1002
+                              $("#smstables").empty();
1003
+                              $("#smstables").append($iframe);
1004
+
1005
+                   } else if (extension == 'txt') {
1006
+                              var reader = new FileReader();
1007
+                              reader.readAsText(e.target.files[0]);
1008
+                              reader.onload = function(e) {
1009
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
+                                  $("#smstables").empty();
1011
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
+                              };
1013
+                   } else if (extension == 'mp4') {
1014
+                              $("#smstables").empty();
1015
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
+                   } else if (extension == 'ogg') {
1017
+                              $("#smstables").empty();
1018
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
+                   } else if (extension == 'avi') {
1020
+                              $("#smstables").empty();
1021
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
+                              $("#smstables").empty();
1024
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
+                   } else if (extension == 'wav' || extension == 'wave') {
1026
+                              $("#smstables").empty();
1027
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
+                   } else if (extension == 'mp3') {
1029
+                              $("#smstables").empty();
1030
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
+                   } else if (extension == 'midi') {
1032
+                              $("#smstables").empty();
1033
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
+                   }
1035
+
1036
+                   $("#smstables").show();
1037
+                   $('#pf_upload_msg').hide();
1038
+                   $('#smstables').removeClass('icon-loading');
1039
+                   $("#mmsfoldersview").hide();
1040
+                 },
1041
+                 error: function() {
1042
+                              showAlert("Error while uploading the file.");
1043
+                 }
1044
+               });
1045
+
1046
+            } else {
1047
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
+                  adjustMaximumSize(uploadedtomms);
1049
+
1050
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
+                  $('#pf_upload_msg').hide();
1052
+                  $('#smstables').removeClass('icon-loading');
1053
+            }
1054
+         } else {
1055
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
+              adjustMaximumSize(uploadedtomms);
1057
+
1058
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
+              $('#pf_upload_msg').hide();
1060
+              $('#smstables').removeClass('icon-loading');
1061
+         }
1062
+       } else {
1063
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
+            adjustMaximumSize(uploadedtomms);
1065
+
1066
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
+            $('#pf_upload_msg').hide();
1068
+            $('#smstables').removeClass('icon-loading');
1069
+       }
1070
+
1071
+     } else {
1072
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
+          adjustMaximumSize(uploadedtomms);
1074
+
1075
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
+          $('#pf_upload_msg').hide();
1077
+          $('#smstables').removeClass('icon-loading');
1078
+     }
1079
+  });
1080
+
1081
+
1082
+  // Pick file(s) from Nextcloud, to send as MMS
1083
+  var mmsfilename = null;
1084
+
1085
+  $("#choosefilen").on("click", function(evn) {
1086
+
1087
+                OC.dialogs.filepicker(
1088
+                        t('settings', "Select a file to send as MMS."),
1089
+                        function (path) {
1090
+
1091
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
+                              $('#smstables').addClass('icon-loading');
1093
+                              $('#filestotsize').show();
1094
+
1095
+                              var userid = "<?php p($userId); ?>";
1096
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
+
1098
+                              mmsfilename = path.split('/').pop();
1099
+
1100
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
+                                  var duplicatescheck = 1;
1102
+                              } else var duplicatescheck = 0;
1103
+
1104
+                              var extension = mmsfilename.replace(/^.*\./, '');
1105
+
1106
+                              if (extension == mmsfilename) {
1107
+                                  extension = "";
1108
+                              } else {
1109
+                                  extension = extension.toLowerCase();
1110
+                              }
1111
+
1112
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
+				   maximumsize = maxsizenonimage;
1115
+			      }
1116
+
1117
+                              if ($.inArray(extension, validExtensions) != -1) {
1118
+
1119
+                                 if (duplicatescheck == 0) {
1120
+
1121
+                                    if (n <= maximumfilenumber) {
1122
+
1123
+                                       $.ajax({
1124
+                                          url: baseUrl + '/' + userid,
1125
+                                          type: "POST",
1126
+                                          data: { path: path },
1127
+                                          success: function(pickresult) {
1128
+
1129
+                                                uploadedtomms.push(mmsfilename);
1130
+
1131
+                                                var totalflsize = pickresult[0];
1132
+                                                var pickedflsize = pickresult[1];
1133
+
1134
+                                                // Check message size
1135
+                                                var rectotfilesz = parseFloat(totalflsize);
1136
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
+
1138
+                                                if (filesplustextsize <= maximumsize) {
1139
+
1140
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
+
1142
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
+                                                    n++;
1144
+
1145
+                                                    msgtotalflsize = totalflsize;
1146
+                                                    $('#filessizetext').text(totalflsize);
1147
+                                                    $('#filestotsize').css('color', '#189558');
1148
+
1149
+                                                } else {
1150
+
1151
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
+                                                    $('#filestotsize').css('color', '#ba3555');
1153
+                                                    msgtotalflsize -= pickedflsize;
1154
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
+
1156
+                                                    $.ajax({
1157
+                                                        url: baseUrlindrm + '/' + userid,
1158
+                                                        type: "POST",
1159
+                                                        data: {removedfilename: mmsfilename},
1160
+                                                        success: function(totalflsize) {
1161
+
1162
+                                                                          $('#filessizetext').text(totalflsize);
1163
+                                                                          $('#filestotsize').css('color', '#189558');
1164
+                                                                          adjustMaximumSize(uploadedtomms);
1165
+
1166
+                                                        },
1167
+                                                        error: function(totalflsize) {
1168
+                                                                          $('#filessizetext').text(totalflsize);
1169
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
+                                                                              $('#filestotsize').css('color', '#ba3555');
1171
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
+                                                        }
1174
+                                                    });
1175
+
1176
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
+                                                }
1178
+
1179
+
1180
+                                                // Preview each file when you click on its name
1181
+                                                $("div:visible[id*='indflpicked']").each(function() {
1182
+                                                   $(this).on("click", function(event) {
1183
+
1184
+                                                      var mmsfilenameinit = $(this).text();
1185
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
+
1190
+                                                      if (extenlst == mmsfilenamesp) {
1191
+                                                           extenlst = "";
1192
+                                                      } else {
1193
+                                                           extenlst = extenlst.toLowerCase();
1194
+                                                      }
1195
+
1196
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
+                                                              $("#smstables").empty();
1198
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
+                                                      } else if (extenlst == 'png') {
1200
+                                                              $("#smstables").empty();
1201
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
+                                                      } else if (extenlst == 'gif') {
1203
+                                                              $("#smstables").empty();
1204
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
+                                                      } else if (extenlst == 'bmp') {
1206
+                                                              $("#smstables").empty();
1207
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
+                                                              var xhr = new XMLHttpRequest();
1211
+                                                              xhr.responseType = 'arraybuffer';
1212
+                                                              xhr.open('GET', tiffile);
1213
+                                                              xhr.onload = function (evnt) {
1214
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
+                                                                  var tifcanvas = tiff.toCanvas();
1216
+                                                                  $("#smstables").empty();
1217
+                                                                  $("#smstables").append(tifcanvas);
1218
+                                                              };
1219
+                                                              xhr.send();
1220
+                                                      } else if (extenlst == 'pdf') {
1221
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
+                                                              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>');
1223
+                                                              $("#smstables").empty();
1224
+                                                              $("#smstables").append($iframe);
1225
+                                                      } else if (extenlst == 'txt') {
1226
+                                                              $("#smstables").empty();
1227
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
+                                                      } else if (extension == 'mp4') {
1229
+							      $("#smstables").empty();
1230
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
+						      } else if (extension == 'ogg') {
1232
+							      $("#smstables").empty();
1233
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
+						      } else if (extension == 'avi') {
1235
+							      $("#smstables").empty();
1236
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
+							      $("#smstables").empty();
1239
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
+						      } else if (extension == 'wav' || extension == 'wave') {
1241
+							      $("#smstables").empty();
1242
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
+						      } else if (extension == 'mp3') {
1244
+							      $("#smstables").empty();
1245
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
+						      } else if (extension == 'midi') {
1247
+							      $("#smstables").empty();
1248
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
+						      }
1250
+
1251
+
1252
+                                                      $("#smstables").show();
1253
+                                                      $("#mmsfoldersview").hide();
1254
+                                                   });
1255
+                                                });
1256
+
1257
+
1258
+                                                // Remove picked files
1259
+                                                $('[class*="indpckfldl"]').last().click(function() {
1260
+                                                    var userid = "<?php p($userId); ?>";
1261
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
+
1263
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
+
1265
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
+
1268
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
+                                                    $(this).hide();
1270
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
+
1272
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
+                                                             return value != removedfilename;
1274
+                                                    });
1275
+
1276
+                                                    $.ajax({
1277
+                                                        url: baseUrl + '/' + userid,
1278
+                                                        type: "POST",
1279
+                                                        data: {removedfilename: removedfilename},
1280
+                                                        success: function(totalflsize) {
1281
+
1282
+                                                             msgtotalflsize = totalflsize;
1283
+                                                             $('#filessizetext').text(totalflsize);
1284
+                                                             adjustMaximumSize(uploadedtomms);
1285
+
1286
+                                                             // Check message size
1287
+                                                             var rectotfilesz = parseFloat(totalflsize);
1288
+
1289
+                                                             if (rectotfilesz > maximumsize) {
1290
+                                                                 $('#filestotsize').css('color', '#ba3555');
1291
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
+                                                                 $('#submitsms').attr("disabled", true);
1293
+                                                             } else {
1294
+                                                                 $('#submitsms').attr("disabled", false);
1295
+                                                                 $('#filestotsize').css('color', '#189558');
1296
+                                                               }
1297
+
1298
+                                                             // Rewrite order numbers for files that follow
1299
+                                                             --n;
1300
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
+
1302
+                                                                  var getdivtext =  $(this).text();
1303
+                                                                  var splitdivtext = getdivtext.split(") ");
1304
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
+                                                                  var newnbvalue = currentnbvalue - 1;
1306
+
1307
+                                                                  if (currentnbvalue > removedflnb) {
1308
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
+                                                                      $(this).text(replacedstr);
1310
+                                                                  }
1311
+                                                             });
1312
+                                                        },
1313
+                                                        error: function() {
1314
+                                                                  showAlert("Error while removing the file.");
1315
+                                                        }
1316
+                                                    });
1317
+
1318
+                                                    $('#smstables').removeClass('icon-loading');
1319
+                                                    $("#smstables").empty();
1320
+                                                });
1321
+
1322
+
1323
+		                                // Preview the picked file
1324
+		                                $("#mmsfoldersview").css("display", "inline-block");
1325
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
+
1328
+
1329
+						if (extension == 'jpg' || extension == 'jpeg') {
1330
+
1331
+		                                            $("#smstables").empty();
1332
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
+
1334
+		                                } else if (extension == 'png') {
1335
+
1336
+		                                            $("#smstables").empty();
1337
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
+
1339
+		                                } else if (extension == 'gif') {
1340
+
1341
+		                                            $("#smstables").empty();
1342
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
+
1344
+		                                } else if (extension == 'bmp') {
1345
+
1346
+	                                                    $("#smstables").empty();
1347
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
+
1349
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
+
1351
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
+		                                       var xhr = new XMLHttpRequest();
1353
+		                                       xhr.responseType = 'arraybuffer';
1354
+		                                       xhr.open('GET', tiffile);
1355
+		                                       xhr.onload = function (event) {
1356
+		                                           var tiff = new Tiff({buffer: xhr.response});
1357
+		                                           var tifcanvas = tiff.toCanvas();
1358
+		                                           $("#smstables").empty();
1359
+		                                           $("#smstables").append(tifcanvas);
1360
+		                                       };
1361
+		                                       xhr.send();
1362
+
1363
+		                                } else if (extension == 'pdf') {
1364
+
1365
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
+		                                       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>');
1367
+		                                       $("#smstables").empty();
1368
+		                                       $("#smstables").append($iframe);
1369
+
1370
+		                                } else if (extension == 'txt') {
1371
+
1372
+							     $.get(flUrl, function(textdata) {
1373
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
+		                                               $("#smstables").empty();
1375
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
+							     });
1377
+
1378
+		                                } else if (extension == 'mp4') {
1379
+						       $("#smstables").empty();
1380
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
+						} else if (extension == 'ogg') {
1382
+						       $("#smstables").empty();
1383
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
+						} else if (extension == 'avi') {
1385
+						       $("#smstables").empty();
1386
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
+						       $("#smstables").empty();
1389
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
+						} else if (extension == 'wav' || extension == 'wave') {
1391
+						       $("#smstables").empty();
1392
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
+						} else if (extension == 'mp3') {
1394
+						       $("#smstables").empty();
1395
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
+						} else if (extension == 'midi') {
1397
+						       $("#smstables").empty();
1398
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
+						}
1400
+
1401
+
1402
+		                                $("#smstables").show();
1403
+
1404
+		                                $('#pf_choose_msg').hide();
1405
+		                                $('#smstables').removeClass('icon-loading');
1406
+		                                $("#mmsfoldersview").hide();
1407
+
1408
+                                          },
1409
+
1410
+                                          error: function(data){
1411
+                                                      showAlert("Error while getting the file.");
1412
+                                          }
1413
+
1414
+                                       });
1415
+
1416
+                                    } else {
1417
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
+                                        $('#pf_choose_msg').hide();
1419
+                                        $('#smstables').removeClass('icon-loading');
1420
+                                      }
1421
+                                 } else {
1422
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
+                                      $('#pf_choose_msg').hide();
1424
+                                      $('#smstables').removeClass('icon-loading');
1425
+                                   }
1426
+
1427
+                              } else {
1428
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
+                                   $('#pf_choose_msg').hide();
1430
+                                   $('#smstables').removeClass('icon-loading');
1431
+                                }
1432
+
1433
+                        }
1434
+                );
1435
+  });
1436
+
1437
+
1438
+
1439
+  // Send the SMS/MMS message
1440
+  $("#submitsms").on("click", function(event) {
1441
+
1442
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
+     $("#sms_submit_msg").css("display", "inline-block");
1445
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
+
1447
+     if (selectedid != '') { 
1448
+
1449
+         var sendersplit = selectedid.split(":");
1450
+         var providercap = sendersplit[0];
1451
+         var provsec = sendersplit[1];
1452
+
1453
+         if (/[a-zA-Z]/.test(provsec)) {
1454
+             var alphanumcheck = true;
1455
+         } else { var alphanumcheck = false; }
1456
+
1457
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
+             var selectedsender = "+" + senderproc;
1460
+             var providerUsed = "telnyx";
1461
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
+             var providerUsed = "plivo";
1465
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
+             var selectedsender = "+" + senderproc;
1469
+             var providerUsed = "twilio";
1470
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
+             var selectedsender = "+" + senderproc;
1474
+             var providerUsed = "flowroute";
1475
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
+             var selectedsender = provsec;
1478
+             var providerUsed = "telnyx";
1479
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
+             var selectedsender = provsec;
1482
+             var providerUsed = "plivo";
1483
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
+             var selectedsender = provsec;
1486
+             var providerUsed = "twilio";
1487
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
+             var selectedsender = provsec;
1490
+             var providerUsed = "flowroute";
1491
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
+         }
1493
+
1494
+         // Get the interval between message consecutive sending requests, if it's the case
1495
+         if ($('#tomultchckbx').is(':checked')) {
1496
+
1497
+             var numbersfile = 1;
1498
+             var initinterval = $("#multsmsinterval").val();
1499
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
+
1501
+             if (secinterval != '') {
1502
+                 var tertinterval = parseInt(secinterval);
1503
+                     waittime = tertinterval;
1504
+             }
1505
+
1506
+         } else {
1507
+
1508
+             var numbersfile = 0;
1509
+             var toNumberinit = $('#smsto').val();
1510
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
+             var toNumbersec = toNumber.split(",");
1512
+
1513
+                 for (var i = 0; i < toNumbersec.length; i++) {
1514
+                      toNumbersec[i] = "+" + toNumbersec[i];
1515
+                 }
1516
+
1517
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
+         }
1519
+
1520
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
+
1522
+         var smstext = $("#smstext").val();
1523
+
1524
+         if (receiversNumbers.length != 0) {
1525
+
1526
+              if (smstext != '') {
1527
+                  $.ajax({
1528
+                     url: relbaseUrl + '/' + userid,
1529
+                     type: "POST",
1530
+                     data: {
1531
+                           receiversPhoneNbs: receiversNumbers,
1532
+                           fromsender: selectedsender,
1533
+                           waitinterval: waittime,
1534
+                           sentsmstext: smstext,
1535
+                           ismms: isMMS,
1536
+                           mmsfiles: uploadedtomms
1537
+                         },
1538
+                     success: function() {
1539
+
1540
+                           if (receiversNumbers.length == 1) {
1541
+                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
+                           } else {
1543
+                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
+                           }
1545
+
1546
+                           $('#sms_submit_msg').hide();
1547
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
+                     },
1549
+                     error: function() {
1550
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
+                           $('#sms_submit_msg').hide();
1552
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
+                     }
1554
+                  });
1555
+              } else {
1556
+                     showAlert("Please enter a message in the text box !");
1557
+
1558
+                     $('#sms_submit_msg').hide();
1559
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
+              }
1561
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
+                 showAlert("Please enter the recipient's phone number !");
1563
+                 $('#sms_submit_msg').hide();
1564
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
+                 $('#sms_submit_msg').hide();
1568
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
+         }
1570
+     } else {
1571
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
+           $('#sms_submit_msg').hide();
1574
+     }
1575
+
1576
+  });
1577
+
1578
+  // Check the checkbox to delete old messages from the database
1579
+  $('#deleteoldchckbox').change(function() {
1580
+     if ($(this).is(':checked')) {
1581
+         $("#deleteoldsms").css("display", "block");
1582
+     } else {
1583
+         $("#deleteoldsms").css("display", "none");
1584
+     }
1585
+  });
1586
+
1587
+  // Set the height of info notes
1588
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
+
1592
+  $(window).resize(function() { 
1593
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
+  });
1597
+
1598
+
1599
+  function showAlert(alertText) {
1600
+
1601
+     let alertwnd = "<div id='alertMessage'>";
1602
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
+     alertwnd += "</div>";
1606
+
1607
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
+     $("#content").append(alertwnd);
1609
+
1610
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
+
1614
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
+  }
Browse code

CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/settings.js js/showsmstables.js js/sendsms.js lib/Controller/SmsrelentlessController.php lib/Controller/AuthorApiController.php lib/Service/SmsrelentlessService.php templates/settings/personal.php

DoubleBastionAdmin authored on 04/06/2023 00:49:12
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1617 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
-
236
-  $.ajax({
237
-          url: cleanflUrl + '/' + userid,
238
-          type: "POST",
239
-          data: { userid: userid },
240
-          cache: false,
241
-          processData: false,
242
-          contentType: false
243
-  });
244
-  
245
-  // Check the available balance
246
-  $("#smsprovider").on("change", function () {
247
-
248
-     var provider = $('#smsprovider :selected').val();
249
-
250
-     if (provider == "Telnyx") {
251
-
252
-        var gettelbalance = function() {
253
-
254
-          $('#currentbalance').addClass('icon-loading');
255
-
256
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
-
258
-          $.ajax({
259
-              url: gettelbalanceUrl + '/' + userid,
260
-              type: "POST",
261
-              data: { userid: userid },
262
-              cache: false,
263
-              processData: false,
264
-              contentType: false,
265
-              success: function(currentbalancetel) {
266
-
267
-                     $('#currentbalance').empty();
268
-                     $('#currentbalance').text(currentbalancetel);
269
-                     $('#currentbalance').removeClass('icon-loading');
270
-              }
271
-          });
272
-        }
273
-
274
-        gettelbalance();
275
-
276
-     } else if (provider == "Plivo") {
277
-
278
-          var getnexbalance = function() {
279
-
280
-            $('#currentbalance').addClass('icon-loading');
281
-
282
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
-
284
-            $.ajax({
285
-                url: getnexbalanceUrl + '/' + userid,
286
-                type: "POST",
287
-                data: { userid: userid },
288
-                cache: false,
289
-                processData: false,
290
-                contentType: false,
291
-                success: function(currentbalancenex) {
292
-
293
-                     $('#currentbalance').empty();
294
-                     $('#currentbalance').text(currentbalancenex);
295
-                     $('#currentbalance').removeClass('icon-loading');
296
-                }
297
-            });
298
-          }
299
-
300
-          getnexbalance();
301
-
302
-     } else if (provider == "Twilio") {
303
-
304
-          var gettwilbalance = function() {
305
-
306
-            $('#currentbalance').addClass('icon-loading');
307
-
308
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
-
310
-            $.ajax({
311
-                url: gettwilbalanceUrl + '/' + userid,
312
-                type: "POST",
313
-                data: { userid: userid },
314
-                cache: false,
315
-                processData: false,
316
-                contentType: false,
317
-                success: function(currentbalancetwil) {
318
-
319
-                     $('#currentbalance').empty();
320
-                     $('#currentbalance').text(currentbalancetwil);
321
-                     $('#currentbalance').removeClass('icon-loading');
322
-                }
323
-            });
324
-          }
325
-
326
-          gettwilbalance();
327
-
328
-     } else if (provider == "Flowroute") {
329
-
330
-          var getflowbalance = function() {
331
-
332
-            $('#currentbalance').addClass('icon-loading');
333
-
334
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
-
336
-            $.ajax({
337
-                url: getflowbalanceUrl + '/' + userid,
338
-                type: "POST",
339
-                data: { userid: userid },
340
-                cache: false,
341
-                processData: false,
342
-                contentType: false,
343
-                success: function(currentbalanceflow) {
344
-
345
-                     $('#currentbalance').empty();
346
-                     $('#currentbalance').text(currentbalanceflow);
347
-                     $('#currentbalance').removeClass('icon-loading');
348
-                }
349
-            });
350
-          }
351
-
352
-          getflowbalance();
353
-
354
-       } else if (provider == "") {
355
-                $('#currentbalance').text("");
356
-                $('#currentbalance').removeClass('icon-loading');
357
-       }
358
-  });
359
-
360
-
361
-  // If a Sender ID is selected
362
-  $("#currentsmsnmbrs").on("change", function () {
363
-
364
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
-
366
-              selectedid = $('#currentsmsnmbrs :selected').val();
367
-              var setIdsplit = selectedid.split(":");
368
-	      chosenProvider = setIdsplit[0];
369
-
370
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
-	      if (chosenProvider == "Tx") {
372
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
-		  // Maximum size of message text + files in KB
374
-		  maximumsize = 1024;
375
-                  maximumsizeinit = 1024;
376
-		  maxsizenonimage = 600;
377
-		  maximumfilenumber = 10;
378
-                  chosenProvFullName = "Telnyx";
379
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
-                                     or gif files, the size of all the files plus the size of the text should be \
381
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
-                  $("#tooltiptextfourth").html(infonotecontent);
391
-	      } else if (chosenProvider == "Pl") {
392
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
-		  // Maximum size of message text + files in KB
395
-		  maximumsize = 5120;
396
-                  maximumsizeinit = 5120;
397
-		  maxsizenonimage = 600;
398
-		  maximumfilenumber = 10;
399
-                  chosenProvFullName = "Plivo";
400
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
-                                     or gif files, the size of all the files plus the size of the text should be \
402
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
-                  $("#tooltiptextfourth").html(infonotecontent);
412
-	      } else if (chosenProvider == "Tw") {
413
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
-                                     "icalendar", "directory", "pdf", "pkpass"];
416
-		  // Maximum size of message text + files in KB
417
-		  maximumsize = 5120;
418
-                  maximumsizeinit = 5120;
419
-		  maxsizenonimage = 600;
420
-		  maximumfilenumber = 10;
421
-                  chosenProvFullName = "Twilio";
422
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
-                                     or gif files, the size of all the files plus the size of the text should be \
424
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
-                                     previewed in the adjoining pane."
435
-                  $("#tooltiptextfourth").html(infonotecontent);
436
-	      } else if (chosenProvider == "Fl") {
437
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
-		  // Maximum size of message text + files in KB
439
-		  maximumsize = 750;
440
-                  maximumsizeinit = 750;
441
-		  maxsizenonimage = 600;
442
-		  maximumfilenumber = 10;
443
-                  chosenProvFullName = "Flowroute";
444
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
-                                     png or gif files, the size of all the files plus the size of the text should be \
446
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
-                                     size of the files plus the size of the text should be 600 KB or less. \
449
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
-                  $("#tooltiptextfourth").html(infonotecontent);
458
-	      }
459
-
460
-          } else { selectedid = ''; }
461
-  });
462
-
463
-  // Check the checkbox to send SMS message to multiple recipients
464
-  $('#tomultchckbx').change(function() {
465
-      if ($(this).is(':checked')) {
466
-          $("#multiplerecivers").css("display", "block");
467
-          $("#smstodiv").css("visibility", "hidden");
468
-          $("#smsto").val("");
469
-
470
-          receiversNumbers.length = 0;
471
-
472
-      } else {
473
-          $("#multiplerecivers").css("display", "none");
474
-          $("#smstodiv").css("visibility", "visible");
475
-
476
-          // Remove the uploaded file(s) if any
477
-          $("#induploadfile").remove();
478
-
479
-          receiversNumbers.length = 0;
480
-      }
481
-  });
482
-
483
-  // Upload the file with the recipients' phone numbers
484
-  $("#uploadfileforsms").change(function(e) {
485
-
486
-     $("#fileuploadednm").empty();
487
-
488
-     receiversNumbers.length = 0;
489
-
490
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
-
492
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
-
494
-     var formData = new FormData();
495
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
-
497
-     var fileup = $('#uploadfileforsms').val();
498
-     var fileuptrim = fileup.split('\\').pop();
499
-
500
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
-
502
-     var extension = fileup.replace(/^.*\./, '');
503
-
504
-     if (extension == fileup) {
505
-         extension = "";
506
-     } else {
507
-         extension = extension.toLowerCase();
508
-     }
509
-
510
-     var validExtensionsmrec = ["txt", "csv"];
511
-
512
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
-
514
-       if (selectedid != '') {
515
-
516
-               $.ajax({
517
-                 url: baseUrl + '/' + userid,
518
-                 type: "POST",
519
-                 data: formData,
520
-                 cache: false,
521
-                 processData: false,
522
-                 contentType: false,
523
-                 success: function(numberarray) {
524
-
525
-		    if (numberarray.length > 0) {
526
-
527
-		        // Get the array of the receivers' phone numbers
528
-		        if (chosenProvider == "Tx") {
529
-
530
-		             for(key in numberarray) {
531
-		                 receiversNumbers.push("+"+numberarray[key]);
532
-		             }
533
-
534
-		        } else if (chosenProvider == "Pl") {
535
-
536
-		             for(key in numberarray) {
537
-		                 receiversNumbers.push(numberarray[key]);
538
-		             }
539
-
540
-		          } else if (chosenProvider == "Tw") {
541
-
542
-		             for(key in numberarray) {
543
-		                 receiversNumbers.push(numberarray[key]);
544
-		             }
545
-		          } else if (chosenProvider == "Fl") {
546
-
547
-		             for(key in numberarray) {
548
-		                 receiversNumbers.push(numberarray[key]);
549
-		             }
550
-		          }
551
-
552
-		    } else {
553
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
-		    }
555
-                            
556
-                    // Preview the uploaded file
557
-                    var smsfilename = e.target.files[0].name;
558
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
-
560
-                    var reader = new FileReader();
561
-                    reader.readAsText(e.target.files[0]);
562
-                    reader.onload = function(e) {
563
-                          $("#smstables").empty();
564
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
-                    };
566
-
567
-                    $("#smstables").show();
568
-
569
-                    $('#sms_upload_msg').hide();
570
-                    $('#smstables').removeClass('icon-loading');
571
-
572
-                  },
573
-                  error: function() {
574
-                             showAlert("Error while uploading the file.");
575
-                  }
576
-               });
577
-
578
-        } else {
579
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
-               $('#sms_upload_msg').hide();
581
-               $('#smstables').removeClass('icon-loading');
582
-        }
583
-
584
-     } else {
585
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
-          $('#pf_upload_msg').hide();
587
-          $('#smstables').removeClass('icon-loading');
588
-
589
-          $("#induploadfile").remove();
590
-          $("#sms_upload_msg").hide();
591
-     }
592
-
593
-     // Preview uploaded file when clicked
594
-     $("#indfilediv").on("click", function() {
595
-
596
-          var smsfilename = e.target.files[0].name;
597
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
-
599
-          var reader = new FileReader();
600
-          reader.readAsText(e.target.files[0]);
601
-          reader.onload = function(e) {
602
-                  $("#smstables").empty();
603
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
-          };
605
-
606
-          $("#smstables").show();
607
-          $('#sms_upload_msg').hide();
608
-          $('#smstables').removeClass('icon-loading');
609
-     });
610
-
611
-     // Remove selected file
612
-     $("#indivflremove").on("click", function() {
613
-
614
-          $("#induploadfile").remove();
615
-          $("#sms_upload_msg").hide();
616
-
617
-          receiversNumbers.length = 0;
618
-
619
-     });
620
-
621
-  });
622
-
623
-  // Show the number of characters entered in the SMS textarea and the text size in KB
624
-  $("#smstext").on('input', function() {
625
-
626
-     $("#char_count").css("display", "inline");
627
-
628
-     $("#mtextSize").css("display", "inline");
629
-
630
-     $(".maxmessagelength").css("display", "inline-block");
631
-
632
-     $("#countchnb").text($(this).val().length);
633
-
634
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
-     $("#textsizeinkb").text(textsizekb);
637
-
638
-     if ($(this).val().length > charcolorthr) {
639
-         $("#char_count").css("color", "#BB2E4B");
640
-     } else {
641
-         $("#char_count").css("color", "#4cbc86;");
642
-     }
643
-
644
-  });
645
-
646
-
647
-  // Check the checkbox to send file(s) as MMS
648
-  $('#mediafilechckbx').change(function() {
649
-
650
-      if ($(this).is(':checked')) {
651
-
652
-          isMMS = 1;
653
-          if (selectedid == '') {
654
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
-              $(this).prop("checked", false);
656
-              isMMS = 0;
657
-              return;
658
-          }
659
-          $("#upmediafiles").css("display", "block");
660
-          $("#submitsms").prop("value", "Send MMS");
661
-
662
-      } else {
663
-
664
-          isMMS = 0;
665
-          $("#upmediafiles").css("display", "none");
666
-          $("#submitsms").prop("value", "Send SMS");
667
-
668
-          // Remove the uploaded file(s) if any
669
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
-          $(".indgenpckfls").each(function() { $(this).remove(); });
671
-
672
-          uploadedtomms = [];
673
-          n = 1;
674
-
675
-          msgtotalflsize = 0;
676
-
677
-          $("#filestotsize").hide();
678
-      }
679
-  });
680
-
681
-
682
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
-  function adjustMaximumSize(uploadedtomms) {
684
-				      
685
-      var nonimgcheck = 0;
686
-      for (var u = 0; u < uploadedtomms.length; u++) {
687
-	   var crupfl = uploadedtomms[u];
688
-	   var extensionup = crupfl.replace(/^.*\./, '');
689
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
-	       nonimgcheck = 1;
691
-	   }
692
-      }
693
-
694
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
-  }
696
-
697
-  // Upload files to be sent as MMS
698
-  $("#uploadfileformms").change(function(e) {
699
-
700
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
-     $('#smstables').addClass('icon-loading');
702
-     $('#filestotsize').show();
703
-
704
-     var userid = "<?php p($userId); ?>";
705
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
-
707
-     var formData = new FormData();
708
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
-
710
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
-
712
-     // Add the size of the current file to the total size of all the files
713
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
-
715
-     var fileup = $('#uploadfileformms').val();
716
-     var fileuptrim = fileup.split('\\').pop();
717
-
718
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
-         var duplicatescheck = 1;
720
-     } else { 
721
-         var duplicatescheck = 0;
722
-     }
723
-
724
-     var extension = fileup.replace(/^.*\./, '');
725
-
726
-     if (extension == fileup) {
727
-         extension = "";
728
-     } else {
729
-         extension = extension.toLowerCase();
730
-     }
731
-
732
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
-         maximumsize = maxsizenonimage;
735
-     }
736
-
737
-     if ($.inArray(extension, validExtensions) != -1) {
738
-
739
-       if (duplicatescheck == 0) {
740
-
741
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
-
743
-            if (n <= maximumfilenumber) {
744
-
745
-               $.ajax({
746
-                 url: baseUrl + '/' + userid,
747
-                 type: "POST",
748
-                 data: formData,
749
-                 cache: false,
750
-                 processData: false,
751
-                 contentType: false,
752
-                 success: function(totalflsize) {
753
-
754
-                   uploadedtomms.push(fileuptrim);
755
-
756
-                   $('#filessizetext').text(totalflsize);
757
-
758
-                   var rectotfilesz = parseFloat(totalflsize);
759
-
760
-                   if (rectotfilesz <= maximumsize) {
761
-                       $('#submitsms').attr("disabled", false);
762
-                       $('#filestotsize').css('color', '#189558');
763
-                   } else {
764
-                       $('#filestotsize').css('color', '#ba3555');
765
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
-                       $('#submitsms').attr("disabled", true);
767
-                       $('#smstables').removeClass('icon-loading');
768
-                       $('#pf_upload_msg').hide();
769
-                   }
770
-
771
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
-                   n++;
773
-
774
-                   // Preview the file when you click on its name
775
-                   $("div:visible[id*='indfilediv']").each(function() {
776
-
777
-                        $(this).on("click", function(eventclck) {
778
-
779
-                           $("#mmsfoldersview").css("display", "inline-block");
780
-                           var mmsfilenameinit = $(this).text();
781
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
-                           var mmsfilename = mmsfilenamesec.replace("X","");
783
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
-
786
-                           if (extenlst == mmsfilename) {
787
-                               extenlst = "";
788
-                           } else {
789
-                               extenlst = extenlst.toLowerCase();
790
-                           }
791
-
792
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
-                                  $("#smstables").empty();
794
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
-                           } else if (extenlst == 'png') {
797
-                                  $("#smstables").empty();
798
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
-                           } else if (extenlst == 'gif') {
801
-                                  $("#smstables").empty();
802
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
-                           } else if (extenlst == 'bmp') {
805
-                                  $("#smstables").empty();
806
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
-                                  var xhr = new XMLHttpRequest();
811
-                                  xhr.responseType = 'arraybuffer';
812
-                                  xhr.open('GET', tiffile);
813
-                                  xhr.onload = function (evnt) {
814
-                                      var tiff = new Tiff({buffer: xhr.response});
815
-                                      var tifcanvas = tiff.toCanvas();
816
-                                      $("#smstables").empty();
817
-                                      $("#smstables").append(tifcanvas);
818
-                                  };
819
-                                  xhr.send();
820
-                           } else if (extenlst == 'pdf') {
821
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
-                                  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>');
823
-                                  $("#smstables").empty();
824
-                                  $("#smstables").append($iframe);
825
-                           } else if (extenlst == 'txt') {
826
-                                  $("#smstables").empty();
827
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
-                           } else if (extension == 'mp4') {
829
-                                  $("#smstables").empty();
830
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
-		           } else if (extension == 'ogg') {
832
-		                  $("#smstables").empty();
833
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
-		           } else if (extension == 'avi') {
835
-		                  $("#smstables").empty();
836
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
-		                  $("#smstables").empty();
839
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
-		           } else if (extension == 'wav' || extension == 'wave') {
841
-		                  $("#smstables").empty();
842
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
-		           } else if (extension == 'mp3') {
844
-		                  $("#smstables").empty();
845
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
-		           } else if (extension == 'midi') {
847
-		                  $("#smstables").empty();
848
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
-		           }
850
-
851
-                           $("#smstables").show();
852
-                           $("#mmsfoldersview").hide();
853
-                        });
854
-                   });
855
-
856
-                   // Remove uploaded files
857
-                   $('[class*="indupfldl"]').last().click(function() {
858
-
859
-                           var userid = "<?php p($userId); ?>";
860
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
-
862
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
-
864
-                           var removedfilesplit = removedfilenameinit.split(") ");
865
-                           var removedflnb = parseInt(removedfilesplit[0]);
866
-
867
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
-                           $(this).hide();
869
-
870
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
-
872
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
-                                           return value != removedfilename;
874
-                           });
875
-
876
-                           $.ajax({
877
-                                   url: baseUrl + '/' + userid,
878
-                                   type: "POST",
879
-                                   data: {removedfilename: removedfilename},
880
-                                   success: function(totalflsize) {
881
-
882
-                                      msgtotalflsize = totalflsize;
883
-                                      $('#filessizetext').text(totalflsize);
884
-
885
-                                      adjustMaximumSize(uploadedtomms);
886
-
887
-                                      // Check message size
888
-                                      var rectotfilesz = parseFloat(totalflsize);
889
-
890
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
-                                          $('#submitsms').attr("disabled", false);
892
-                                          $('#filestotsize').css('color', '#189558');
893
-                                      } else {
894
-                                          $('#filestotsize').css('color', '#ba3555');
895
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
-                                          $('#submitsms').attr("disabled", true);
897
-                                      }
898
-
899
-                                      // Rewrite order numbers for files that follow
900
-                                      --n;
901
-                                      $("div:visible[id*='indfilediv']").each(function() {
902
-
903
-                                          var getdivtext =  $(this).text();
904
-                                          var splitdivtext = getdivtext.split(") ");
905
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
-                                          var newnbvalue = currentnbvalue - 1;
907
-
908
-                                          if (currentnbvalue > removedflnb) {
909
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
-                                              $(this).text(replacedstr);
911
-                                          }
912
-                                      });
913
-
914
-                                      $("div:visible[id*='indflpicked']").each(function() {
915
-
916
-                                          var getdivtext =  $(this).text();
917
-                                          var splitdivtext = getdivtext.split(") ");
918
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
-                                          var newnbvalue = currentnbvalue - 1;
920
-
921
-                                          if (currentnbvalue > removedflnb) {
922
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
-                                              $(this).text(replacedstr);
924
-                                          }
925
-                                      });
926
-
927
-                                   },
928
-                                   error: function() {
929
-                                              showAlert("Error while removing the file(s).");
930
-                                   }
931
-                           });
932
-
933
-                           $('#smstables').removeClass('icon-loading');
934
-                           $("#smstables").empty();
935
-                   });
936
-
937
-                   // Preview the uploaded file
938
-                   $("#mmsfoldersview").css("display", "inline-block");
939
-                   var mmsfilename = e.target.files[0].name;
940
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
-
942
-
943
-                   if (extension == 'jpg' || extension == 'jpeg') {
944
-                              $("#smstables").empty();
945
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
-
947
-                              var reader = new FileReader();
948
-                              reader.onload = function (e) {
949
-                                  readjpg[mmsfilename] = e.target.result;
950
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
-                              }
952
-                              reader.readAsDataURL(e.target.files[0]);
953
-                   } else if (extension == 'png') {
954
-                              $("#smstables").empty();
955
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
-
957
-                              var reader = new FileReader();
958
-                              reader.onload = function (e) {
959
-                                  readpng[mmsfilename] = e.target.result;
960
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
-                              }
962
-                              reader.readAsDataURL(e.target.files[0]);
963
-
964
-                   } else if (extension == 'gif') {
965
-                              $("#smstables").empty();
966
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
-
968
-                              var reader = new FileReader();
969
-                              reader.onload = function (e) {
970
-                                  readgif[mmsfilename] = e.target.result;
971
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
-                              }
973
-                              reader.readAsDataURL(e.target.files[0]);
974
-
975
-                   } else if (extension == 'bmp') {
976
-                              $("#smstables").empty();
977
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
-
979
-                              var reader = new FileReader();
980
-                              reader.onload = function (e) {
981
-                                  readbmp[mmsfilename] = e.target.result;
982
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
-                              }
984
-                              reader.readAsDataURL(e.target.files[0]);
985
-
986
-                   } else if (extension == 'tif' || extension == 'tiff') {
987
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
-                              var xhr = new XMLHttpRequest();
989
-                              xhr.responseType = 'arraybuffer';
990
-                              xhr.open('GET', tiffile);
991
-                              xhr.onload = function (e) {
992
-                                  var tiff = new Tiff({buffer: xhr.response});
993
-                                  var tifcanvas = tiff.toCanvas();
994
-                                  $("#smstables").empty();
995
-                                  $("#smstables").append(tifcanvas);
996
-                              };
997
-                              xhr.send();
998
-
999
-                   } else if (extension == 'pdf') {
1000
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
-                              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>');
1002
-                              $("#smstables").empty();
1003
-                              $("#smstables").append($iframe);
1004
-
1005
-                   } else if (extension == 'txt') {
1006
-                              var reader = new FileReader();
1007
-                              reader.readAsText(e.target.files[0]);
1008
-                              reader.onload = function(e) {
1009
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
-                                  $("#smstables").empty();
1011
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
-                              };
1013
-                   } else if (extension == 'mp4') {
1014
-                              $("#smstables").empty();
1015
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
-                   } else if (extension == 'ogg') {
1017
-                              $("#smstables").empty();
1018
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
-                   } else if (extension == 'avi') {
1020
-                              $("#smstables").empty();
1021
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
-                              $("#smstables").empty();
1024
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
-                   } else if (extension == 'wav' || extension == 'wave') {
1026
-                              $("#smstables").empty();
1027
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
-                   } else if (extension == 'mp3') {
1029
-                              $("#smstables").empty();
1030
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
-                   } else if (extension == 'midi') {
1032
-                              $("#smstables").empty();
1033
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
-                   }
1035
-
1036
-                   $("#smstables").show();
1037
-                   $('#pf_upload_msg').hide();
1038
-                   $('#smstables').removeClass('icon-loading');
1039
-                   $("#mmsfoldersview").hide();
1040
-                 },
1041
-                 error: function() {
1042
-                              showAlert("Error while uploading the file.");
1043
-                 }
1044
-               });
1045
-
1046
-            } else {
1047
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
-                  adjustMaximumSize(uploadedtomms);
1049
-
1050
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
-                  $('#pf_upload_msg').hide();
1052
-                  $('#smstables').removeClass('icon-loading');
1053
-            }
1054
-         } else {
1055
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
-              adjustMaximumSize(uploadedtomms);
1057
-
1058
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
-              $('#pf_upload_msg').hide();
1060
-              $('#smstables').removeClass('icon-loading');
1061
-         }
1062
-       } else {
1063
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
-            adjustMaximumSize(uploadedtomms);
1065
-
1066
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
-            $('#pf_upload_msg').hide();
1068
-            $('#smstables').removeClass('icon-loading');
1069
-       }
1070
-
1071
-     } else {
1072
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
-          adjustMaximumSize(uploadedtomms);
1074
-
1075
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
-          $('#pf_upload_msg').hide();
1077
-          $('#smstables').removeClass('icon-loading');
1078
-     }
1079
-  });
1080
-
1081
-
1082
-  // Pick file(s) from Nextcloud, to send as MMS
1083
-  var mmsfilename = null;
1084
-
1085
-  $("#choosefilen").on("click", function(evn) {
1086
-
1087
-                OC.dialogs.filepicker(
1088
-                        t('settings', "Select a file to send as MMS."),
1089
-                        function (path) {
1090
-
1091
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
-                              $('#smstables').addClass('icon-loading');
1093
-                              $('#filestotsize').show();
1094
-
1095
-                              var userid = "<?php p($userId); ?>";
1096
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
-
1098
-                              mmsfilename = path.split('/').pop();
1099
-
1100
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
-                                  var duplicatescheck = 1;
1102
-                              } else var duplicatescheck = 0;
1103
-
1104
-                              var extension = mmsfilename.replace(/^.*\./, '');
1105
-
1106
-                              if (extension == mmsfilename) {
1107
-                                  extension = "";
1108
-                              } else {
1109
-                                  extension = extension.toLowerCase();
1110
-                              }
1111
-
1112
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
-				   maximumsize = maxsizenonimage;
1115
-			      }
1116
-
1117
-                              if ($.inArray(extension, validExtensions) != -1) {
1118
-
1119
-                                 if (duplicatescheck == 0) {
1120
-
1121
-                                    if (n <= maximumfilenumber) {
1122
-
1123
-                                       $.ajax({
1124
-                                          url: baseUrl + '/' + userid,
1125
-                                          type: "POST",
1126
-                                          data: { path: path },
1127
-                                          success: function(pickresult) {
1128
-
1129
-                                                uploadedtomms.push(mmsfilename);
1130
-
1131
-                                                var totalflsize = pickresult[0];
1132
-                                                var pickedflsize = pickresult[1];
1133
-
1134
-                                                // Check message size
1135
-                                                var rectotfilesz = parseFloat(totalflsize);
1136
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
-
1138
-                                                if (filesplustextsize <= maximumsize) {
1139
-
1140
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
-
1142
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
-                                                    n++;
1144
-
1145
-                                                    msgtotalflsize = totalflsize;
1146
-                                                    $('#filessizetext').text(totalflsize);
1147
-                                                    $('#filestotsize').css('color', '#189558');
1148
-
1149
-                                                } else {
1150
-
1151
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
-                                                    $('#filestotsize').css('color', '#ba3555');
1153
-                                                    msgtotalflsize -= pickedflsize;
1154
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
-
1156
-                                                    $.ajax({
1157
-                                                        url: baseUrlindrm + '/' + userid,
1158
-                                                        type: "POST",
1159
-                                                        data: {removedfilename: mmsfilename},
1160
-                                                        success: function(totalflsize) {
1161
-
1162
-                                                                          $('#filessizetext').text(totalflsize);
1163
-                                                                          $('#filestotsize').css('color', '#189558');
1164
-                                                                          adjustMaximumSize(uploadedtomms);
1165
-
1166
-                                                        },
1167
-                                                        error: function(totalflsize) {
1168
-                                                                          $('#filessizetext').text(totalflsize);
1169
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
-                                                                              $('#filestotsize').css('color', '#ba3555');
1171
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
-                                                        }
1174
-                                                    });
1175
-
1176
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
-                                                }
1178
-
1179
-
1180
-                                                // Preview each file when you click on its name
1181
-                                                $("div:visible[id*='indflpicked']").each(function() {
1182
-                                                   $(this).on("click", function(event) {
1183
-
1184
-                                                      var mmsfilenameinit = $(this).text();
1185
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
-
1190
-                                                      if (extenlst == mmsfilenamesp) {
1191
-                                                           extenlst = "";
1192
-                                                      } else {
1193
-                                                           extenlst = extenlst.toLowerCase();
1194
-                                                      }
1195
-
1196
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
-                                                              $("#smstables").empty();
1198
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
-                                                      } else if (extenlst == 'png') {
1200
-                                                              $("#smstables").empty();
1201
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
-                                                      } else if (extenlst == 'gif') {
1203
-                                                              $("#smstables").empty();
1204
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
-                                                      } else if (extenlst == 'bmp') {
1206
-                                                              $("#smstables").empty();
1207
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
-                                                              var xhr = new XMLHttpRequest();
1211
-                                                              xhr.responseType = 'arraybuffer';
1212
-                                                              xhr.open('GET', tiffile);
1213
-                                                              xhr.onload = function (evnt) {
1214
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
-                                                                  var tifcanvas = tiff.toCanvas();
1216
-                                                                  $("#smstables").empty();
1217
-                                                                  $("#smstables").append(tifcanvas);
1218
-                                                              };
1219
-                                                              xhr.send();
1220
-                                                      } else if (extenlst == 'pdf') {
1221
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
-                                                              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>');
1223
-                                                              $("#smstables").empty();
1224
-                                                              $("#smstables").append($iframe);
1225
-                                                      } else if (extenlst == 'txt') {
1226
-                                                              $("#smstables").empty();
1227
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
-                                                      } else if (extension == 'mp4') {
1229
-							      $("#smstables").empty();
1230
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
-						      } else if (extension == 'ogg') {
1232
-							      $("#smstables").empty();
1233
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
-						      } else if (extension == 'avi') {
1235
-							      $("#smstables").empty();
1236
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
-							      $("#smstables").empty();
1239
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
-						      } else if (extension == 'wav' || extension == 'wave') {
1241
-							      $("#smstables").empty();
1242
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
-						      } else if (extension == 'mp3') {
1244
-							      $("#smstables").empty();
1245
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
-						      } else if (extension == 'midi') {
1247
-							      $("#smstables").empty();
1248
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
-						      }
1250
-
1251
-
1252
-                                                      $("#smstables").show();
1253
-                                                      $("#mmsfoldersview").hide();
1254
-                                                   });
1255
-                                                });
1256
-
1257
-
1258
-                                                // Remove picked files
1259
-                                                $('[class*="indpckfldl"]').last().click(function() {
1260
-                                                    var userid = "<?php p($userId); ?>";
1261
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
-
1263
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
-
1265
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
-
1268
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
-                                                    $(this).hide();
1270
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
-
1272
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
-                                                             return value != removedfilename;
1274
-                                                    });
1275
-
1276
-                                                    $.ajax({
1277
-                                                        url: baseUrl + '/' + userid,
1278
-                                                        type: "POST",
1279
-                                                        data: {removedfilename: removedfilename},
1280
-                                                        success: function(totalflsize) {
1281
-
1282
-                                                             msgtotalflsize = totalflsize;
1283
-                                                             $('#filessizetext').text(totalflsize);
1284
-                                                             adjustMaximumSize(uploadedtomms);
1285
-
1286
-                                                             // Check message size
1287
-                                                             var rectotfilesz = parseFloat(totalflsize);
1288
-
1289
-                                                             if (rectotfilesz > maximumsize) {
1290
-                                                                 $('#filestotsize').css('color', '#ba3555');
1291
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
-                                                                 $('#submitsms').attr("disabled", true);
1293
-                                                             } else {
1294
-                                                                 $('#submitsms').attr("disabled", false);
1295
-                                                                 $('#filestotsize').css('color', '#189558');
1296
-                                                               }
1297
-
1298
-                                                             // Rewrite order numbers for files that follow
1299
-                                                             --n;
1300
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
-
1302
-                                                                  var getdivtext =  $(this).text();
1303
-                                                                  var splitdivtext = getdivtext.split(") ");
1304
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
-                                                                  var newnbvalue = currentnbvalue - 1;
1306
-
1307
-                                                                  if (currentnbvalue > removedflnb) {
1308
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
-                                                                      $(this).text(replacedstr);
1310
-                                                                  }
1311
-                                                             });
1312
-                                                        },
1313
-                                                        error: function() {
1314
-                                                                  showAlert("Error while removing the file.");
1315
-                                                        }
1316
-                                                    });
1317
-
1318
-                                                    $('#smstables').removeClass('icon-loading');
1319
-                                                    $("#smstables").empty();
1320
-                                                });
1321
-
1322
-
1323
-		                                // Preview the picked file
1324
-		                                $("#mmsfoldersview").css("display", "inline-block");
1325
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
-
1328
-
1329
-						if (extension == 'jpg' || extension == 'jpeg') {
1330
-
1331
-		                                            $("#smstables").empty();
1332
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
-
1334
-		                                } else if (extension == 'png') {
1335
-
1336
-		                                            $("#smstables").empty();
1337
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
-
1339
-		                                } else if (extension == 'gif') {
1340
-
1341
-		                                            $("#smstables").empty();
1342
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
-
1344
-		                                } else if (extension == 'bmp') {
1345
-
1346
-	                                                    $("#smstables").empty();
1347
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
-
1349
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
-
1351
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
-		                                       var xhr = new XMLHttpRequest();
1353
-		                                       xhr.responseType = 'arraybuffer';
1354
-		                                       xhr.open('GET', tiffile);
1355
-		                                       xhr.onload = function (event) {
1356
-		                                           var tiff = new Tiff({buffer: xhr.response});
1357
-		                                           var tifcanvas = tiff.toCanvas();
1358
-		                                           $("#smstables").empty();
1359
-		                                           $("#smstables").append(tifcanvas);
1360
-		                                       };
1361
-		                                       xhr.send();
1362
-
1363
-		                                } else if (extension == 'pdf') {
1364
-
1365
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
-		                                       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>');
1367
-		                                       $("#smstables").empty();
1368
-		                                       $("#smstables").append($iframe);
1369
-
1370
-		                                } else if (extension == 'txt') {
1371
-
1372
-							     $.get(flUrl, function(textdata) {
1373
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
-		                                               $("#smstables").empty();
1375
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
-							     });
1377
-
1378
-		                                } else if (extension == 'mp4') {
1379
-						       $("#smstables").empty();
1380
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
-						} else if (extension == 'ogg') {
1382
-						       $("#smstables").empty();
1383
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
-						} else if (extension == 'avi') {
1385
-						       $("#smstables").empty();
1386
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
-						       $("#smstables").empty();
1389
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
-						} else if (extension == 'wav' || extension == 'wave') {
1391
-						       $("#smstables").empty();
1392
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
-						} else if (extension == 'mp3') {
1394
-						       $("#smstables").empty();
1395
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
-						} else if (extension == 'midi') {
1397
-						       $("#smstables").empty();
1398
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
-						}
1400
-
1401
-
1402
-		                                $("#smstables").show();
1403
-
1404
-		                                $('#pf_choose_msg').hide();
1405
-		                                $('#smstables').removeClass('icon-loading');
1406
-		                                $("#mmsfoldersview").hide();
1407
-
1408
-                                          },
1409
-
1410
-                                          error: function(data){
1411
-                                                      showAlert("Error while getting the file.");
1412
-                                          }
1413
-
1414
-                                       });
1415
-
1416
-                                    } else {
1417
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
-                                        $('#pf_choose_msg').hide();
1419
-                                        $('#smstables').removeClass('icon-loading');
1420
-                                      }
1421
-                                 } else {
1422
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
-                                      $('#pf_choose_msg').hide();
1424
-                                      $('#smstables').removeClass('icon-loading');
1425
-                                   }
1426
-
1427
-                              } else {
1428
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
-                                   $('#pf_choose_msg').hide();
1430
-                                   $('#smstables').removeClass('icon-loading');
1431
-                                }
1432
-
1433
-                        }
1434
-                );
1435
-  });
1436
-
1437
-
1438
-
1439
-  // Send the SMS/MMS message
1440
-  $("#submitsms").on("click", function(event) {
1441
-
1442
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
-     $("#sms_submit_msg").css("display", "inline-block");
1445
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
-
1447
-     if (selectedid != '') { 
1448
-
1449
-         var sendersplit = selectedid.split(":");
1450
-         var providercap = sendersplit[0];
1451
-         var provsec = sendersplit[1];
1452
-
1453
-         if (/[a-zA-Z]/.test(provsec)) {
1454
-             var alphanumcheck = true;
1455
-         } else { var alphanumcheck = false; }
1456
-
1457
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
-             var selectedsender = "+" + senderproc;
1460
-             var providerUsed = "telnyx";
1461
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
-             var providerUsed = "plivo";
1465
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
-             var selectedsender = "+" + senderproc;
1469
-             var providerUsed = "twilio";
1470
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
-             var selectedsender = "+" + senderproc;
1474
-             var providerUsed = "flowroute";
1475
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
-             var selectedsender = provsec;
1478
-             var providerUsed = "telnyx";
1479
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
-             var selectedsender = provsec;
1482
-             var providerUsed = "plivo";
1483
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
-             var selectedsender = provsec;
1486
-             var providerUsed = "twilio";
1487
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
-             var selectedsender = provsec;
1490
-             var providerUsed = "flowroute";
1491
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
-         }
1493
-
1494
-         // Get the interval between message consecutive sending requests, if it's the case
1495
-         if ($('#tomultchckbx').is(':checked')) {
1496
-
1497
-             var numbersfile = 1;
1498
-             var initinterval = $("#multsmsinterval").val();
1499
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
-
1501
-             if (secinterval != '') {
1502
-                 var tertinterval = parseInt(secinterval);
1503
-                     waittime = tertinterval;
1504
-             }
1505
-
1506
-         } else {
1507
-
1508
-             var numbersfile = 0;
1509
-             var toNumberinit = $('#smsto').val();
1510
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
-             var toNumbersec = toNumber.split(",");
1512
-
1513
-                 for (var i = 0; i < toNumbersec.length; i++) {
1514
-                      toNumbersec[i] = "+" + toNumbersec[i];
1515
-                 }
1516
-
1517
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
-         }
1519
-
1520
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
-
1522
-         var smstext = $("#smstext").val();
1523
-
1524
-         if (receiversNumbers.length != 0) {
1525
-
1526
-              if (smstext != '') {
1527
-                  $.ajax({
1528
-                     url: relbaseUrl + '/' + userid,
1529
-                     type: "POST",
1530
-                     data: {
1531
-                           receiversPhoneNbs: receiversNumbers,
1532
-                           fromsender: selectedsender,
1533
-                           waitinterval: waittime,
1534
-                           sentsmstext: smstext,
1535
-                           ismms: isMMS,
1536
-                           mmsfiles: uploadedtomms
1537
-                         },
1538
-                     success: function() {
1539
-
1540
-                           if (receiversNumbers.length == 1) {
1541
-                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
-                           } else {
1543
-                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
-                           }
1545
-
1546
-                           $('#sms_submit_msg').hide();
1547
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
-                     },
1549
-                     error: function() {
1550
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
-                           $('#sms_submit_msg').hide();
1552
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
-                     }
1554
-                  });
1555
-              } else {
1556
-                     showAlert("Please enter a message in the text box !");
1557
-
1558
-                     $('#sms_submit_msg').hide();
1559
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
-              }
1561
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
-                 showAlert("Please enter the recipient's phone number !");
1563
-                 $('#sms_submit_msg').hide();
1564
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
-                 $('#sms_submit_msg').hide();
1568
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
-         }
1570
-     } else {
1571
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
-           $('#sms_submit_msg').hide();
1574
-     }
1575
-
1576
-  });
1577
-
1578
-  // Check the checkbox to delete old messages from the database
1579
-  $('#deleteoldchckbox').change(function() {
1580
-     if ($(this).is(':checked')) {
1581
-         $("#deleteoldsms").css("display", "block");
1582
-     } else {
1583
-         $("#deleteoldsms").css("display", "none");
1584
-     }
1585
-  });
1586
-
1587
-  // Set the height of info notes
1588
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
-
1592
-  $(window).resize(function() { 
1593
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
-  });
1597
-
1598
-
1599
-  function showAlert(alertText) {
1600
-
1601
-     let alertwnd = "<div id='alertMessage'>";
1602
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
-     alertwnd += "</div>";
1606
-
1607
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
-     $("#content").append(alertwnd);
1609
-
1610
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
-
1614
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
-  }
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php js/sendsms.js

DoubleBastionAdmin authored on 30/05/2023 15:51:12
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1617 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
+
236
+  $.ajax({
237
+          url: cleanflUrl + '/' + userid,
238
+          type: "POST",
239
+          data: { userid: userid },
240
+          cache: false,
241
+          processData: false,
242
+          contentType: false
243
+  });
244
+  
245
+  // Check the available balance
246
+  $("#smsprovider").on("change", function () {
247
+
248
+     var provider = $('#smsprovider :selected').val();
249
+
250
+     if (provider == "Telnyx") {
251
+
252
+        var gettelbalance = function() {
253
+
254
+          $('#currentbalance').addClass('icon-loading');
255
+
256
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
+
258
+          $.ajax({
259
+              url: gettelbalanceUrl + '/' + userid,
260
+              type: "POST",
261
+              data: { userid: userid },
262
+              cache: false,
263
+              processData: false,
264
+              contentType: false,
265
+              success: function(currentbalancetel) {
266
+
267
+                     $('#currentbalance').empty();
268
+                     $('#currentbalance').text(currentbalancetel);
269
+                     $('#currentbalance').removeClass('icon-loading');
270
+              }
271
+          });
272
+        }
273
+
274
+        gettelbalance();
275
+
276
+     } else if (provider == "Plivo") {
277
+
278
+          var getnexbalance = function() {
279
+
280
+            $('#currentbalance').addClass('icon-loading');
281
+
282
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
+
284
+            $.ajax({
285
+                url: getnexbalanceUrl + '/' + userid,
286
+                type: "POST",
287
+                data: { userid: userid },
288
+                cache: false,
289
+                processData: false,
290
+                contentType: false,
291
+                success: function(currentbalancenex) {
292
+
293
+                     $('#currentbalance').empty();
294
+                     $('#currentbalance').text(currentbalancenex);
295
+                     $('#currentbalance').removeClass('icon-loading');
296
+                }
297
+            });
298
+          }
299
+
300
+          getnexbalance();
301
+
302
+     } else if (provider == "Twilio") {
303
+
304
+          var gettwilbalance = function() {
305
+
306
+            $('#currentbalance').addClass('icon-loading');
307
+
308
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
+
310
+            $.ajax({
311
+                url: gettwilbalanceUrl + '/' + userid,
312
+                type: "POST",
313
+                data: { userid: userid },
314
+                cache: false,
315
+                processData: false,
316
+                contentType: false,
317
+                success: function(currentbalancetwil) {
318
+
319
+                     $('#currentbalance').empty();
320
+                     $('#currentbalance').text(currentbalancetwil);
321
+                     $('#currentbalance').removeClass('icon-loading');
322
+                }
323
+            });
324
+          }
325
+
326
+          gettwilbalance();
327
+
328
+     } else if (provider == "Flowroute") {
329
+
330
+          var getflowbalance = function() {
331
+
332
+            $('#currentbalance').addClass('icon-loading');
333
+
334
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
+
336
+            $.ajax({
337
+                url: getflowbalanceUrl + '/' + userid,
338
+                type: "POST",
339
+                data: { userid: userid },
340
+                cache: false,
341
+                processData: false,
342
+                contentType: false,
343
+                success: function(currentbalanceflow) {
344
+
345
+                     $('#currentbalance').empty();
346
+                     $('#currentbalance').text(currentbalanceflow);
347
+                     $('#currentbalance').removeClass('icon-loading');
348
+                }
349
+            });
350
+          }
351
+
352
+          getflowbalance();
353
+
354
+       } else if (provider == "") {
355
+                $('#currentbalance').text("");
356
+                $('#currentbalance').removeClass('icon-loading');
357
+       }
358
+  });
359
+
360
+
361
+  // If a Sender ID is selected
362
+  $("#currentsmsnmbrs").on("change", function () {
363
+
364
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
+
366
+              selectedid = $('#currentsmsnmbrs :selected').val();
367
+              var setIdsplit = selectedid.split(":");
368
+	      chosenProvider = setIdsplit[0];
369
+
370
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
+	      if (chosenProvider == "Tx") {
372
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
+		  // Maximum size of message text + files in KB
374
+		  maximumsize = 1024;
375
+                  maximumsizeinit = 1024;
376
+		  maxsizenonimage = 600;
377
+		  maximumfilenumber = 10;
378
+                  chosenProvFullName = "Telnyx";
379
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
+                                     or gif files, the size of all the files plus the size of the text should be \
381
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
+                  $("#tooltiptextfourth").html(infonotecontent);
391
+	      } else if (chosenProvider == "Pl") {
392
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
+		  // Maximum size of message text + files in KB
395
+		  maximumsize = 5120;
396
+                  maximumsizeinit = 5120;
397
+		  maxsizenonimage = 600;
398
+		  maximumfilenumber = 10;
399
+                  chosenProvFullName = "Plivo";
400
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
+                                     or gif files, the size of all the files plus the size of the text should be \
402
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
+                  $("#tooltiptextfourth").html(infonotecontent);
412
+	      } else if (chosenProvider == "Tw") {
413
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
+                                     "icalendar", "directory", "pdf", "pkpass"];
416
+		  // Maximum size of message text + files in KB
417
+		  maximumsize = 5120;
418
+                  maximumsizeinit = 5120;
419
+		  maxsizenonimage = 600;
420
+		  maximumfilenumber = 10;
421
+                  chosenProvFullName = "Twilio";
422
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
+                                     or gif files, the size of all the files plus the size of the text should be \
424
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
+                                     previewed in the adjoining pane."
435
+                  $("#tooltiptextfourth").html(infonotecontent);
436
+	      } else if (chosenProvider == "Fl") {
437
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
+		  // Maximum size of message text + files in KB
439
+		  maximumsize = 750;
440
+                  maximumsizeinit = 750;
441
+		  maxsizenonimage = 600;
442
+		  maximumfilenumber = 10;
443
+                  chosenProvFullName = "Flowroute";
444
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
+                                     png or gif files, the size of all the files plus the size of the text should be \
446
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
+                                     size of the files plus the size of the text should be 600 KB or less. \
449
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
+                  $("#tooltiptextfourth").html(infonotecontent);
458
+	      }
459
+
460
+          } else { selectedid = ''; }
461
+  });
462
+
463
+  // Check the checkbox to send SMS message to multiple recipients
464
+  $('#tomultchckbx').change(function() {
465
+      if ($(this).is(':checked')) {
466
+          $("#multiplerecivers").css("display", "block");
467
+          $("#smstodiv").css("visibility", "hidden");
468
+          $("#smsto").val("");
469
+
470
+          receiversNumbers.length = 0;
471
+
472
+      } else {
473
+          $("#multiplerecivers").css("display", "none");
474
+          $("#smstodiv").css("visibility", "visible");
475
+
476
+          // Remove the uploaded file(s) if any
477
+          $("#induploadfile").remove();
478
+
479
+          receiversNumbers.length = 0;
480
+      }
481
+  });
482
+
483
+  // Upload the file with the recipients' phone numbers
484
+  $("#uploadfileforsms").change(function(e) {
485
+
486
+     $("#fileuploadednm").empty();
487
+
488
+     receiversNumbers.length = 0;
489
+
490
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
+
492
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
+
494
+     var formData = new FormData();
495
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
+
497
+     var fileup = $('#uploadfileforsms').val();
498
+     var fileuptrim = fileup.split('\\').pop();
499
+
500
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
+
502
+     var extension = fileup.replace(/^.*\./, '');
503
+
504
+     if (extension == fileup) {
505
+         extension = "";
506
+     } else {
507
+         extension = extension.toLowerCase();
508
+     }
509
+
510
+     var validExtensionsmrec = ["txt", "csv"];
511
+
512
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
+
514
+       if (selectedid != '') {
515
+
516
+               $.ajax({
517
+                 url: baseUrl + '/' + userid,
518
+                 type: "POST",
519
+                 data: formData,
520
+                 cache: false,
521
+                 processData: false,
522
+                 contentType: false,
523
+                 success: function(numberarray) {
524
+
525
+		    if (numberarray.length > 0) {
526
+
527
+		        // Get the array of the receivers' phone numbers
528
+		        if (chosenProvider == "Tx") {
529
+
530
+		             for(key in numberarray) {
531
+		                 receiversNumbers.push("+"+numberarray[key]);
532
+		             }
533
+
534
+		        } else if (chosenProvider == "Pl") {
535
+
536
+		             for(key in numberarray) {
537
+		                 receiversNumbers.push(numberarray[key]);
538
+		             }
539
+
540
+		          } else if (chosenProvider == "Tw") {
541
+
542
+		             for(key in numberarray) {
543
+		                 receiversNumbers.push(numberarray[key]);
544
+		             }
545
+		          } else if (chosenProvider == "Fl") {
546
+
547
+		             for(key in numberarray) {
548
+		                 receiversNumbers.push(numberarray[key]);
549
+		             }
550
+		          }
551
+
552
+		    } else {
553
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
+		    }
555
+                            
556
+                    // Preview the uploaded file
557
+                    var smsfilename = e.target.files[0].name;
558
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
+
560
+                    var reader = new FileReader();
561
+                    reader.readAsText(e.target.files[0]);
562
+                    reader.onload = function(e) {
563
+                          $("#smstables").empty();
564
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
+                    };
566
+
567
+                    $("#smstables").show();
568
+
569
+                    $('#sms_upload_msg').hide();
570
+                    $('#smstables').removeClass('icon-loading');
571
+
572
+                  },
573
+                  error: function() {
574
+                             showAlert("Error while uploading the file.");
575
+                  }
576
+               });
577
+
578
+        } else {
579
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
+               $('#sms_upload_msg').hide();
581
+               $('#smstables').removeClass('icon-loading');
582
+        }
583
+
584
+     } else {
585
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
+          $('#pf_upload_msg').hide();
587
+          $('#smstables').removeClass('icon-loading');
588
+
589
+          $("#induploadfile").remove();
590
+          $("#sms_upload_msg").hide();
591
+     }
592
+
593
+     // Preview uploaded file when clicked
594
+     $("#indfilediv").on("click", function() {
595
+
596
+          var smsfilename = e.target.files[0].name;
597
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
+
599
+          var reader = new FileReader();
600
+          reader.readAsText(e.target.files[0]);
601
+          reader.onload = function(e) {
602
+                  $("#smstables").empty();
603
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
+          };
605
+
606
+          $("#smstables").show();
607
+          $('#sms_upload_msg').hide();
608
+          $('#smstables').removeClass('icon-loading');
609
+     });
610
+
611
+     // Remove selected file
612
+     $("#indivflremove").on("click", function() {
613
+
614
+          $("#induploadfile").remove();
615
+          $("#sms_upload_msg").hide();
616
+
617
+          receiversNumbers.length = 0;
618
+
619
+     });
620
+
621
+  });
622
+
623
+  // Show the number of characters entered in the SMS textarea and the text size in KB
624
+  $("#smstext").on('input', function() {
625
+
626
+     $("#char_count").css("display", "inline");
627
+
628
+     $("#mtextSize").css("display", "inline");
629
+
630
+     $(".maxmessagelength").css("display", "inline-block");
631
+
632
+     $("#countchnb").text($(this).val().length);
633
+
634
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
+     $("#textsizeinkb").text(textsizekb);
637
+
638
+     if ($(this).val().length > charcolorthr) {
639
+         $("#char_count").css("color", "#BB2E4B");
640
+     } else {
641
+         $("#char_count").css("color", "#4cbc86;");
642
+     }
643
+
644
+  });
645
+
646
+
647
+  // Check the checkbox to send file(s) as MMS
648
+  $('#mediafilechckbx').change(function() {
649
+
650
+      if ($(this).is(':checked')) {
651
+
652
+          isMMS = 1;
653
+          if (selectedid == '') {
654
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
+              $(this).prop("checked", false);
656
+              isMMS = 0;
657
+              return;
658
+          }
659
+          $("#upmediafiles").css("display", "block");
660
+          $("#submitsms").prop("value", "Send MMS");
661
+
662
+      } else {
663
+
664
+          isMMS = 0;
665
+          $("#upmediafiles").css("display", "none");
666
+          $("#submitsms").prop("value", "Send SMS");
667
+
668
+          // Remove the uploaded file(s) if any
669
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
+          $(".indgenpckfls").each(function() { $(this).remove(); });
671
+
672
+          uploadedtomms = [];
673
+          n = 1;
674
+
675
+          msgtotalflsize = 0;
676
+
677
+          $("#filestotsize").hide();
678
+      }
679
+  });
680
+
681
+
682
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
+  function adjustMaximumSize(uploadedtomms) {
684
+				      
685
+      var nonimgcheck = 0;
686
+      for (var u = 0; u < uploadedtomms.length; u++) {
687
+	   var crupfl = uploadedtomms[u];
688
+	   var extensionup = crupfl.replace(/^.*\./, '');
689
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
+	       nonimgcheck = 1;
691
+	   }
692
+      }
693
+
694
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
+  }
696
+
697
+  // Upload files to be sent as MMS
698
+  $("#uploadfileformms").change(function(e) {
699
+
700
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
+     $('#smstables').addClass('icon-loading');
702
+     $('#filestotsize').show();
703
+
704
+     var userid = "<?php p($userId); ?>";
705
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
+
707
+     var formData = new FormData();
708
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
+
710
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
+
712
+     // Add the size of the current file to the total size of all the files
713
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
+
715
+     var fileup = $('#uploadfileformms').val();
716
+     var fileuptrim = fileup.split('\\').pop();
717
+
718
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
+         var duplicatescheck = 1;
720
+     } else { 
721
+         var duplicatescheck = 0;
722
+     }
723
+
724
+     var extension = fileup.replace(/^.*\./, '');
725
+
726
+     if (extension == fileup) {
727
+         extension = "";
728
+     } else {
729
+         extension = extension.toLowerCase();
730
+     }
731
+
732
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
+         maximumsize = maxsizenonimage;
735
+     }
736
+
737
+     if ($.inArray(extension, validExtensions) != -1) {
738
+
739
+       if (duplicatescheck == 0) {
740
+
741
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
+
743
+            if (n <= maximumfilenumber) {
744
+
745
+               $.ajax({
746
+                 url: baseUrl + '/' + userid,
747
+                 type: "POST",
748
+                 data: formData,
749
+                 cache: false,
750
+                 processData: false,
751
+                 contentType: false,
752
+                 success: function(totalflsize) {
753
+
754
+                   uploadedtomms.push(fileuptrim);
755
+
756
+                   $('#filessizetext').text(totalflsize);
757
+
758
+                   var rectotfilesz = parseFloat(totalflsize);
759
+
760
+                   if (rectotfilesz <= maximumsize) {
761
+                       $('#submitsms').attr("disabled", false);
762
+                       $('#filestotsize').css('color', '#189558');
763
+                   } else {
764
+                       $('#filestotsize').css('color', '#ba3555');
765
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
+                       $('#submitsms').attr("disabled", true);
767
+                       $('#smstables').removeClass('icon-loading');
768
+                       $('#pf_upload_msg').hide();
769
+                   }
770
+
771
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
+                   n++;
773
+
774
+                   // Preview the file when you click on its name
775
+                   $("div:visible[id*='indfilediv']").each(function() {
776
+
777
+                        $(this).on("click", function(eventclck) {
778
+
779
+                           $("#mmsfoldersview").css("display", "inline-block");
780
+                           var mmsfilenameinit = $(this).text();
781
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
+                           var mmsfilename = mmsfilenamesec.replace("X","");
783
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
+
786
+                           if (extenlst == mmsfilename) {
787
+                               extenlst = "";
788
+                           } else {
789
+                               extenlst = extenlst.toLowerCase();
790
+                           }
791
+
792
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
+                                  $("#smstables").empty();
794
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
+                           } else if (extenlst == 'png') {
797
+                                  $("#smstables").empty();
798
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
+                           } else if (extenlst == 'gif') {
801
+                                  $("#smstables").empty();
802
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
+                           } else if (extenlst == 'bmp') {
805
+                                  $("#smstables").empty();
806
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
+                                  var xhr = new XMLHttpRequest();
811
+                                  xhr.responseType = 'arraybuffer';
812
+                                  xhr.open('GET', tiffile);
813
+                                  xhr.onload = function (evnt) {
814
+                                      var tiff = new Tiff({buffer: xhr.response});
815
+                                      var tifcanvas = tiff.toCanvas();
816
+                                      $("#smstables").empty();
817
+                                      $("#smstables").append(tifcanvas);
818
+                                  };
819
+                                  xhr.send();
820
+                           } else if (extenlst == 'pdf') {
821
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
+                                  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>');
823
+                                  $("#smstables").empty();
824
+                                  $("#smstables").append($iframe);
825
+                           } else if (extenlst == 'txt') {
826
+                                  $("#smstables").empty();
827
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
+                           } else if (extension == 'mp4') {
829
+                                  $("#smstables").empty();
830
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
+		           } else if (extension == 'ogg') {
832
+		                  $("#smstables").empty();
833
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
+		           } else if (extension == 'avi') {
835
+		                  $("#smstables").empty();
836
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
+		                  $("#smstables").empty();
839
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
+		           } else if (extension == 'wav' || extension == 'wave') {
841
+		                  $("#smstables").empty();
842
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
+		           } else if (extension == 'mp3') {
844
+		                  $("#smstables").empty();
845
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
+		           } else if (extension == 'midi') {
847
+		                  $("#smstables").empty();
848
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
+		           }
850
+
851
+                           $("#smstables").show();
852
+                           $("#mmsfoldersview").hide();
853
+                        });
854
+                   });
855
+
856
+                   // Remove uploaded files
857
+                   $('[class*="indupfldl"]').last().click(function() {
858
+
859
+                           var userid = "<?php p($userId); ?>";
860
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
+
862
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
+
864
+                           var removedfilesplit = removedfilenameinit.split(") ");
865
+                           var removedflnb = parseInt(removedfilesplit[0]);
866
+
867
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
+                           $(this).hide();
869
+
870
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
+
872
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
+                                           return value != removedfilename;
874
+                           });
875
+
876
+                           $.ajax({
877
+                                   url: baseUrl + '/' + userid,
878
+                                   type: "POST",
879
+                                   data: {removedfilename: removedfilename},
880
+                                   success: function(totalflsize) {
881
+
882
+                                      msgtotalflsize = totalflsize;
883
+                                      $('#filessizetext').text(totalflsize);
884
+
885
+                                      adjustMaximumSize(uploadedtomms);
886
+
887
+                                      // Check message size
888
+                                      var rectotfilesz = parseFloat(totalflsize);
889
+
890
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
+                                          $('#submitsms').attr("disabled", false);
892
+                                          $('#filestotsize').css('color', '#189558');
893
+                                      } else {
894
+                                          $('#filestotsize').css('color', '#ba3555');
895
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
+                                          $('#submitsms').attr("disabled", true);
897
+                                      }
898
+
899
+                                      // Rewrite order numbers for files that follow
900
+                                      --n;
901
+                                      $("div:visible[id*='indfilediv']").each(function() {
902
+
903
+                                          var getdivtext =  $(this).text();
904
+                                          var splitdivtext = getdivtext.split(") ");
905
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
+                                          var newnbvalue = currentnbvalue - 1;
907
+
908
+                                          if (currentnbvalue > removedflnb) {
909
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
+                                              $(this).text(replacedstr);
911
+                                          }
912
+                                      });
913
+
914
+                                      $("div:visible[id*='indflpicked']").each(function() {
915
+
916
+                                          var getdivtext =  $(this).text();
917
+                                          var splitdivtext = getdivtext.split(") ");
918
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
+                                          var newnbvalue = currentnbvalue - 1;
920
+
921
+                                          if (currentnbvalue > removedflnb) {
922
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
+                                              $(this).text(replacedstr);
924
+                                          }
925
+                                      });
926
+
927
+                                   },
928
+                                   error: function() {
929
+                                              showAlert("Error while removing the file(s).");
930
+                                   }
931
+                           });
932
+
933
+                           $('#smstables').removeClass('icon-loading');
934
+                           $("#smstables").empty();
935
+                   });
936
+
937
+                   // Preview the uploaded file
938
+                   $("#mmsfoldersview").css("display", "inline-block");
939
+                   var mmsfilename = e.target.files[0].name;
940
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
+
942
+
943
+                   if (extension == 'jpg' || extension == 'jpeg') {
944
+                              $("#smstables").empty();
945
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
+
947
+                              var reader = new FileReader();
948
+                              reader.onload = function (e) {
949
+                                  readjpg[mmsfilename] = e.target.result;
950
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
+                              }
952
+                              reader.readAsDataURL(e.target.files[0]);
953
+                   } else if (extension == 'png') {
954
+                              $("#smstables").empty();
955
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
+
957
+                              var reader = new FileReader();
958
+                              reader.onload = function (e) {
959
+                                  readpng[mmsfilename] = e.target.result;
960
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
+                              }
962
+                              reader.readAsDataURL(e.target.files[0]);
963
+
964
+                   } else if (extension == 'gif') {
965
+                              $("#smstables").empty();
966
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
+
968
+                              var reader = new FileReader();
969
+                              reader.onload = function (e) {
970
+                                  readgif[mmsfilename] = e.target.result;
971
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
+                              }
973
+                              reader.readAsDataURL(e.target.files[0]);
974
+
975
+                   } else if (extension == 'bmp') {
976
+                              $("#smstables").empty();
977
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
+
979
+                              var reader = new FileReader();
980
+                              reader.onload = function (e) {
981
+                                  readbmp[mmsfilename] = e.target.result;
982
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
+                              }
984
+                              reader.readAsDataURL(e.target.files[0]);
985
+
986
+                   } else if (extension == 'tif' || extension == 'tiff') {
987
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
+                              var xhr = new XMLHttpRequest();
989
+                              xhr.responseType = 'arraybuffer';
990
+                              xhr.open('GET', tiffile);
991
+                              xhr.onload = function (e) {
992
+                                  var tiff = new Tiff({buffer: xhr.response});
993
+                                  var tifcanvas = tiff.toCanvas();
994
+                                  $("#smstables").empty();
995
+                                  $("#smstables").append(tifcanvas);
996
+                              };
997
+                              xhr.send();
998
+
999
+                   } else if (extension == 'pdf') {
1000
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
+                              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>');
1002
+                              $("#smstables").empty();
1003
+                              $("#smstables").append($iframe);
1004
+
1005
+                   } else if (extension == 'txt') {
1006
+                              var reader = new FileReader();
1007
+                              reader.readAsText(e.target.files[0]);
1008
+                              reader.onload = function(e) {
1009
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
+                                  $("#smstables").empty();
1011
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
+                              };
1013
+                   } else if (extension == 'mp4') {
1014
+                              $("#smstables").empty();
1015
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
+                   } else if (extension == 'ogg') {
1017
+                              $("#smstables").empty();
1018
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
+                   } else if (extension == 'avi') {
1020
+                              $("#smstables").empty();
1021
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
+                              $("#smstables").empty();
1024
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
+                   } else if (extension == 'wav' || extension == 'wave') {
1026
+                              $("#smstables").empty();
1027
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
+                   } else if (extension == 'mp3') {
1029
+                              $("#smstables").empty();
1030
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
+                   } else if (extension == 'midi') {
1032
+                              $("#smstables").empty();
1033
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
+                   }
1035
+
1036
+                   $("#smstables").show();
1037
+                   $('#pf_upload_msg').hide();
1038
+                   $('#smstables').removeClass('icon-loading');
1039
+                   $("#mmsfoldersview").hide();
1040
+                 },
1041
+                 error: function() {
1042
+                              showAlert("Error while uploading the file.");
1043
+                 }
1044
+               });
1045
+
1046
+            } else {
1047
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
+                  adjustMaximumSize(uploadedtomms);
1049
+
1050
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
+                  $('#pf_upload_msg').hide();
1052
+                  $('#smstables').removeClass('icon-loading');
1053
+            }
1054
+         } else {
1055
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
+              adjustMaximumSize(uploadedtomms);
1057
+
1058
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
+              $('#pf_upload_msg').hide();
1060
+              $('#smstables').removeClass('icon-loading');
1061
+         }
1062
+       } else {
1063
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
+            adjustMaximumSize(uploadedtomms);
1065
+
1066
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
+            $('#pf_upload_msg').hide();
1068
+            $('#smstables').removeClass('icon-loading');
1069
+       }
1070
+
1071
+     } else {
1072
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
+          adjustMaximumSize(uploadedtomms);
1074
+
1075
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
+          $('#pf_upload_msg').hide();
1077
+          $('#smstables').removeClass('icon-loading');
1078
+     }
1079
+  });
1080
+
1081
+
1082
+  // Pick file(s) from Nextcloud, to send as MMS
1083
+  var mmsfilename = null;
1084
+
1085
+  $("#choosefilen").on("click", function(evn) {
1086
+
1087
+                OC.dialogs.filepicker(
1088
+                        t('settings', "Select a file to send as MMS."),
1089
+                        function (path) {
1090
+
1091
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
+                              $('#smstables').addClass('icon-loading');
1093
+                              $('#filestotsize').show();
1094
+
1095
+                              var userid = "<?php p($userId); ?>";
1096
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
+
1098
+                              mmsfilename = path.split('/').pop();
1099
+
1100
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
+                                  var duplicatescheck = 1;
1102
+                              } else var duplicatescheck = 0;
1103
+
1104
+                              var extension = mmsfilename.replace(/^.*\./, '');
1105
+
1106
+                              if (extension == mmsfilename) {
1107
+                                  extension = "";
1108
+                              } else {
1109
+                                  extension = extension.toLowerCase();
1110
+                              }
1111
+
1112
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
+				   maximumsize = maxsizenonimage;
1115
+			      }
1116
+
1117
+                              if ($.inArray(extension, validExtensions) != -1) {
1118
+
1119
+                                 if (duplicatescheck == 0) {
1120
+
1121
+                                    if (n <= maximumfilenumber) {
1122
+
1123
+                                       $.ajax({
1124
+                                          url: baseUrl + '/' + userid,
1125
+                                          type: "POST",
1126
+                                          data: { path: path },
1127
+                                          success: function(pickresult) {
1128
+
1129
+                                                uploadedtomms.push(mmsfilename);
1130
+
1131
+                                                var totalflsize = pickresult[0];
1132
+                                                var pickedflsize = pickresult[1];
1133
+
1134
+                                                // Check message size
1135
+                                                var rectotfilesz = parseFloat(totalflsize);
1136
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
+
1138
+                                                if (filesplustextsize <= maximumsize) {
1139
+
1140
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
+
1142
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
+                                                    n++;
1144
+
1145
+                                                    msgtotalflsize = totalflsize;
1146
+                                                    $('#filessizetext').text(totalflsize);
1147
+                                                    $('#filestotsize').css('color', '#189558');
1148
+
1149
+                                                } else {
1150
+
1151
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
+                                                    $('#filestotsize').css('color', '#ba3555');
1153
+                                                    msgtotalflsize -= pickedflsize;
1154
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
+
1156
+                                                    $.ajax({
1157
+                                                        url: baseUrlindrm + '/' + userid,
1158
+                                                        type: "POST",
1159
+                                                        data: {removedfilename: mmsfilename},
1160
+                                                        success: function(totalflsize) {
1161
+
1162
+                                                                          $('#filessizetext').text(totalflsize);
1163
+                                                                          $('#filestotsize').css('color', '#189558');
1164
+                                                                          adjustMaximumSize(uploadedtomms);
1165
+
1166
+                                                        },
1167
+                                                        error: function(totalflsize) {
1168
+                                                                          $('#filessizetext').text(totalflsize);
1169
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
+                                                                              $('#filestotsize').css('color', '#ba3555');
1171
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
+                                                        }
1174
+                                                    });
1175
+
1176
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
+                                                }
1178
+
1179
+
1180
+                                                // Preview each file when you click on its name
1181
+                                                $("div:visible[id*='indflpicked']").each(function() {
1182
+                                                   $(this).on("click", function(event) {
1183
+
1184
+                                                      var mmsfilenameinit = $(this).text();
1185
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
+
1190
+                                                      if (extenlst == mmsfilenamesp) {
1191
+                                                           extenlst = "";
1192
+                                                      } else {
1193
+                                                           extenlst = extenlst.toLowerCase();
1194
+                                                      }
1195
+
1196
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
+                                                              $("#smstables").empty();
1198
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
+                                                      } else if (extenlst == 'png') {
1200
+                                                              $("#smstables").empty();
1201
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
+                                                      } else if (extenlst == 'gif') {
1203
+                                                              $("#smstables").empty();
1204
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
+                                                      } else if (extenlst == 'bmp') {
1206
+                                                              $("#smstables").empty();
1207
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
+                                                              var xhr = new XMLHttpRequest();
1211
+                                                              xhr.responseType = 'arraybuffer';
1212
+                                                              xhr.open('GET', tiffile);
1213
+                                                              xhr.onload = function (evnt) {
1214
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
+                                                                  var tifcanvas = tiff.toCanvas();
1216
+                                                                  $("#smstables").empty();
1217
+                                                                  $("#smstables").append(tifcanvas);
1218
+                                                              };
1219
+                                                              xhr.send();
1220
+                                                      } else if (extenlst == 'pdf') {
1221
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
+                                                              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>');
1223
+                                                              $("#smstables").empty();
1224
+                                                              $("#smstables").append($iframe);
1225
+                                                      } else if (extenlst == 'txt') {
1226
+                                                              $("#smstables").empty();
1227
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
+                                                      } else if (extension == 'mp4') {
1229
+							      $("#smstables").empty();
1230
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
+						      } else if (extension == 'ogg') {
1232
+							      $("#smstables").empty();
1233
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
+						      } else if (extension == 'avi') {
1235
+							      $("#smstables").empty();
1236
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
+							      $("#smstables").empty();
1239
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
+						      } else if (extension == 'wav' || extension == 'wave') {
1241
+							      $("#smstables").empty();
1242
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
+						      } else if (extension == 'mp3') {
1244
+							      $("#smstables").empty();
1245
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
+						      } else if (extension == 'midi') {
1247
+							      $("#smstables").empty();
1248
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
+						      }
1250
+
1251
+
1252
+                                                      $("#smstables").show();
1253
+                                                      $("#mmsfoldersview").hide();
1254
+                                                   });
1255
+                                                });
1256
+
1257
+
1258
+                                                // Remove picked files
1259
+                                                $('[class*="indpckfldl"]').last().click(function() {
1260
+                                                    var userid = "<?php p($userId); ?>";
1261
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
+
1263
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
+
1265
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
+
1268
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
+                                                    $(this).hide();
1270
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
+
1272
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
+                                                             return value != removedfilename;
1274
+                                                    });
1275
+
1276
+                                                    $.ajax({
1277
+                                                        url: baseUrl + '/' + userid,
1278
+                                                        type: "POST",
1279
+                                                        data: {removedfilename: removedfilename},
1280
+                                                        success: function(totalflsize) {
1281
+
1282
+                                                             msgtotalflsize = totalflsize;
1283
+                                                             $('#filessizetext').text(totalflsize);
1284
+                                                             adjustMaximumSize(uploadedtomms);
1285
+
1286
+                                                             // Check message size
1287
+                                                             var rectotfilesz = parseFloat(totalflsize);
1288
+
1289
+                                                             if (rectotfilesz > maximumsize) {
1290
+                                                                 $('#filestotsize').css('color', '#ba3555');
1291
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
+                                                                 $('#submitsms').attr("disabled", true);
1293
+                                                             } else {
1294
+                                                                 $('#submitsms').attr("disabled", false);
1295
+                                                                 $('#filestotsize').css('color', '#189558');
1296
+                                                               }
1297
+
1298
+                                                             // Rewrite order numbers for files that follow
1299
+                                                             --n;
1300
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
+
1302
+                                                                  var getdivtext =  $(this).text();
1303
+                                                                  var splitdivtext = getdivtext.split(") ");
1304
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
+                                                                  var newnbvalue = currentnbvalue - 1;
1306
+
1307
+                                                                  if (currentnbvalue > removedflnb) {
1308
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
+                                                                      $(this).text(replacedstr);
1310
+                                                                  }
1311
+                                                             });
1312
+                                                        },
1313
+                                                        error: function() {
1314
+                                                                  showAlert("Error while removing the file.");
1315
+                                                        }
1316
+                                                    });
1317
+
1318
+                                                    $('#smstables').removeClass('icon-loading');
1319
+                                                    $("#smstables").empty();
1320
+                                                });
1321
+
1322
+
1323
+		                                // Preview the picked file
1324
+		                                $("#mmsfoldersview").css("display", "inline-block");
1325
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
+
1328
+
1329
+						if (extension == 'jpg' || extension == 'jpeg') {
1330
+
1331
+		                                            $("#smstables").empty();
1332
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
+
1334
+		                                } else if (extension == 'png') {
1335
+
1336
+		                                            $("#smstables").empty();
1337
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
+
1339
+		                                } else if (extension == 'gif') {
1340
+
1341
+		                                            $("#smstables").empty();
1342
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
+
1344
+		                                } else if (extension == 'bmp') {
1345
+
1346
+	                                                    $("#smstables").empty();
1347
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
+
1349
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
+
1351
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
+		                                       var xhr = new XMLHttpRequest();
1353
+		                                       xhr.responseType = 'arraybuffer';
1354
+		                                       xhr.open('GET', tiffile);
1355
+		                                       xhr.onload = function (event) {
1356
+		                                           var tiff = new Tiff({buffer: xhr.response});
1357
+		                                           var tifcanvas = tiff.toCanvas();
1358
+		                                           $("#smstables").empty();
1359
+		                                           $("#smstables").append(tifcanvas);
1360
+		                                       };
1361
+		                                       xhr.send();
1362
+
1363
+		                                } else if (extension == 'pdf') {
1364
+
1365
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
+		                                       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>');
1367
+		                                       $("#smstables").empty();
1368
+		                                       $("#smstables").append($iframe);
1369
+
1370
+		                                } else if (extension == 'txt') {
1371
+
1372
+							     $.get(flUrl, function(textdata) {
1373
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
+		                                               $("#smstables").empty();
1375
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
+							     });
1377
+
1378
+		                                } else if (extension == 'mp4') {
1379
+						       $("#smstables").empty();
1380
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
+						} else if (extension == 'ogg') {
1382
+						       $("#smstables").empty();
1383
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
+						} else if (extension == 'avi') {
1385
+						       $("#smstables").empty();
1386
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
+						       $("#smstables").empty();
1389
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
+						} else if (extension == 'wav' || extension == 'wave') {
1391
+						       $("#smstables").empty();
1392
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
+						} else if (extension == 'mp3') {
1394
+						       $("#smstables").empty();
1395
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
+						} else if (extension == 'midi') {
1397
+						       $("#smstables").empty();
1398
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
+						}
1400
+
1401
+
1402
+		                                $("#smstables").show();
1403
+
1404
+		                                $('#pf_choose_msg').hide();
1405
+		                                $('#smstables').removeClass('icon-loading');
1406
+		                                $("#mmsfoldersview").hide();
1407
+
1408
+                                          },
1409
+
1410
+                                          error: function(data){
1411
+                                                      showAlert("Error while getting the file.");
1412
+                                          }
1413
+
1414
+                                       });
1415
+
1416
+                                    } else {
1417
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
+                                        $('#pf_choose_msg').hide();
1419
+                                        $('#smstables').removeClass('icon-loading');
1420
+                                      }
1421
+                                 } else {
1422
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
+                                      $('#pf_choose_msg').hide();
1424
+                                      $('#smstables').removeClass('icon-loading');
1425
+                                   }
1426
+
1427
+                              } else {
1428
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
+                                   $('#pf_choose_msg').hide();
1430
+                                   $('#smstables').removeClass('icon-loading');
1431
+                                }
1432
+
1433
+                        }
1434
+                );
1435
+  });
1436
+
1437
+
1438
+
1439
+  // Send the SMS/MMS message
1440
+  $("#submitsms").on("click", function(event) {
1441
+
1442
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
+     $("#sms_submit_msg").css("display", "inline-block");
1445
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
+
1447
+     if (selectedid != '') { 
1448
+
1449
+         var sendersplit = selectedid.split(":");
1450
+         var providercap = sendersplit[0];
1451
+         var provsec = sendersplit[1];
1452
+
1453
+         if (/[a-zA-Z]/.test(provsec)) {
1454
+             var alphanumcheck = true;
1455
+         } else { var alphanumcheck = false; }
1456
+
1457
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
+             var selectedsender = "+" + senderproc;
1460
+             var providerUsed = "telnyx";
1461
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
+             var providerUsed = "plivo";
1465
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
+             var selectedsender = "+" + senderproc;
1469
+             var providerUsed = "twilio";
1470
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
+             var selectedsender = "+" + senderproc;
1474
+             var providerUsed = "flowroute";
1475
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
+             var selectedsender = provsec;
1478
+             var providerUsed = "telnyx";
1479
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
+             var selectedsender = provsec;
1482
+             var providerUsed = "plivo";
1483
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
+             var selectedsender = provsec;
1486
+             var providerUsed = "twilio";
1487
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
+             var selectedsender = provsec;
1490
+             var providerUsed = "flowroute";
1491
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
+         }
1493
+
1494
+         // Get the interval between message consecutive sending requests, if it's the case
1495
+         if ($('#tomultchckbx').is(':checked')) {
1496
+
1497
+             var numbersfile = 1;
1498
+             var initinterval = $("#multsmsinterval").val();
1499
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
+
1501
+             if (secinterval != '') {
1502
+                 var tertinterval = parseInt(secinterval);
1503
+                     waittime = tertinterval;
1504
+             }
1505
+
1506
+         } else {
1507
+
1508
+             var numbersfile = 0;
1509
+             var toNumberinit = $('#smsto').val();
1510
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
+             var toNumbersec = toNumber.split(",");
1512
+
1513
+                 for (var i = 0; i < toNumbersec.length; i++) {
1514
+                      toNumbersec[i] = "+" + toNumbersec[i];
1515
+                 }
1516
+
1517
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
+         }
1519
+
1520
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
+
1522
+         var smstext = $("#smstext").val();
1523
+
1524
+         if (receiversNumbers.length != 0) {
1525
+
1526
+              if (smstext != '') {
1527
+                  $.ajax({
1528
+                     url: relbaseUrl + '/' + userid,
1529
+                     type: "POST",
1530
+                     data: {
1531
+                           receiversPhoneNbs: receiversNumbers,
1532
+                           fromsender: selectedsender,
1533
+                           waitinterval: waittime,
1534
+                           sentsmstext: smstext,
1535
+                           ismms: isMMS,
1536
+                           mmsfiles: uploadedtomms
1537
+                         },
1538
+                     success: function() {
1539
+
1540
+                           if (receiversNumbers.length == 1) {
1541
+                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
+                           } else {
1543
+                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
+                           }
1545
+
1546
+                           $('#sms_submit_msg').hide();
1547
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
+                     },
1549
+                     error: function() {
1550
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
+                           $('#sms_submit_msg').hide();
1552
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
+                     }
1554
+                  });
1555
+              } else {
1556
+                     showAlert("Please enter a message in the text box !");
1557
+
1558
+                     $('#sms_submit_msg').hide();
1559
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
+              }
1561
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
+                 showAlert("Please enter the recipient's phone number !");
1563
+                 $('#sms_submit_msg').hide();
1564
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
+                 $('#sms_submit_msg').hide();
1568
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
+         }
1570
+     } else {
1571
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
+           $('#sms_submit_msg').hide();
1574
+     }
1575
+
1576
+  });
1577
+
1578
+  // Check the checkbox to delete old messages from the database
1579
+  $('#deleteoldchckbox').change(function() {
1580
+     if ($(this).is(':checked')) {
1581
+         $("#deleteoldsms").css("display", "block");
1582
+     } else {
1583
+         $("#deleteoldsms").css("display", "none");
1584
+     }
1585
+  });
1586
+
1587
+  // Set the height of info notes
1588
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
+
1592
+  $(window).resize(function() { 
1593
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
+  });
1597
+
1598
+
1599
+  function showAlert(alertText) {
1600
+
1601
+     let alertwnd = "<div id='alertMessage'>";
1602
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
+     alertwnd += "</div>";
1606
+
1607
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
+     $("#content").append(alertwnd);
1609
+
1610
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
+
1614
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
+  }
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php js/sendsms.js

DoubleBastionAdmin authored on 30/05/2023 15:47:20
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1617 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-                     } else if (currentnmbrs.length == 1) {
111
-
112
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
-
114
-                                selectedid = currentnmbrs[0];
115
-
116
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
-
118
-                                if (unqprovider == 'Tx') {
119
-
120
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
-					  // Maximum size of message text + files in KB
122
-					  maximumsize = 1024;
123
-					  maximumsizeinit = 1024;
124
-					  maxsizenonimage = 600;
125
-					  maximumfilenumber = 10;
126
-					  chosenProvFullName = "Telnyx";
127
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
-						             or gif files, the size of all the files plus the size of the text should be \
129
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
-					  $("#tooltiptextfourth").html(infonotecontent);
139
-
140
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
-
143
-                                } else if (unqprovider == 'Pl') {
144
-
145
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
-						             "icalendar", "csv", "txt", "pdf", "xls"];
147
-					  // Maximum size of message text + files in KB
148
-					  maximumsize = 5120;
149
-					  maximumsizeinit = 5120;
150
-					  maxsizenonimage = 600;
151
-					  maximumfilenumber = 10;
152
-					  chosenProvFullName = "Plivo";
153
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
-						             or gif files, the size of all the files plus the size of the text should be \
155
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
-					  $("#tooltiptextfourth").html(infonotecontent);
165
-
166
-                                          // Append 'Plivo' to the 'see balance' drop-down list
167
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
-
169
-                                } else if (unqprovider == 'Tw') {
170
-
171
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
-						             "icalendar", "directory", "pdf", "pkpass"];
174
-					  // Maximum size of message text + files in KB
175
-					  maximumsize = 5120;
176
-					  maximumsizeinit = 5120;
177
-					  maxsizenonimage = 600;
178
-					  maximumfilenumber = 10;
179
-					  chosenProvFullName = "Twilio";
180
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
-						             or gif files, the size of all the files plus the size of the text should be \
182
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
-						             previewed in the adjoining pane."
193
-					  $("#tooltiptextfourth").html(infonotecontent);
194
-
195
-                                          // Append 'Twilio' to the 'see balance' drop-down list
196
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
-
198
-                                } else if (unqprovider == 'Fl') {
199
-
200
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
-					  // Maximum size of message text + files in KB
202
-					  maximumsize = 750;
203
-					  maximumsizeinit = 750;
204
-					  maxsizenonimage = 600;
205
-					  maximumfilenumber = 10;
206
-					  chosenProvFullName = "Flowroute";
207
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
-							     png or gif files, the size of all the files plus the size of the text should be \
209
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
-							     size of the files plus the size of the text should be 600 KB or less. \
212
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
-					  $("#tooltiptextfourth").html(infonotecontent);
221
-
222
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
-                                }
225
-                     } else {
226
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
-                     }
228
-
229
-                     $("#smsnumbersdiv").removeClass('icon-loading');
230
-          }
231
-  });
232
-
233
-  // Clean the SMS_Relentless/temp_files directory
234
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
-
236
-  $.ajax({
237
-          url: cleanflUrl + '/' + userid,
238
-          type: "POST",
239
-          data: { userid: userid },
240
-          cache: false,
241
-          processData: false,
242
-          contentType: false
243
-  });
244
-  
245
-  // Check the available balance
246
-  $("#smsprovider").on("change", function () {
247
-
248
-     var provider = $('#smsprovider :selected').val();
249
-
250
-     if (provider == "Telnyx") {
251
-
252
-        var gettelbalance = function() {
253
-
254
-          $('#currentbalance').addClass('icon-loading');
255
-
256
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
-
258
-          $.ajax({
259
-              url: gettelbalanceUrl + '/' + userid,
260
-              type: "POST",
261
-              data: { userid: userid },
262
-              cache: false,
263
-              processData: false,
264
-              contentType: false,
265
-              success: function(currentbalancetel) {
266
-
267
-                     $('#currentbalance').empty();
268
-                     $('#currentbalance').text(currentbalancetel);
269
-                     $('#currentbalance').removeClass('icon-loading');
270
-              }
271
-          });
272
-        }
273
-
274
-        gettelbalance();
275
-
276
-     } else if (provider == "Plivo") {
277
-
278
-          var getnexbalance = function() {
279
-
280
-            $('#currentbalance').addClass('icon-loading');
281
-
282
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
-
284
-            $.ajax({
285
-                url: getnexbalanceUrl + '/' + userid,
286
-                type: "POST",
287
-                data: { userid: userid },
288
-                cache: false,
289
-                processData: false,
290
-                contentType: false,
291
-                success: function(currentbalancenex) {
292
-
293
-                     $('#currentbalance').empty();
294
-                     $('#currentbalance').text(currentbalancenex);
295
-                     $('#currentbalance').removeClass('icon-loading');
296
-                }
297
-            });
298
-          }
299
-
300
-          getnexbalance();
301
-
302
-     } else if (provider == "Twilio") {
303
-
304
-          var gettwilbalance = function() {
305
-
306
-            $('#currentbalance').addClass('icon-loading');
307
-
308
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
-
310
-            $.ajax({
311
-                url: gettwilbalanceUrl + '/' + userid,
312
-                type: "POST",
313
-                data: { userid: userid },
314
-                cache: false,
315
-                processData: false,
316
-                contentType: false,
317
-                success: function(currentbalancetwil) {
318
-
319
-                     $('#currentbalance').empty();
320
-                     $('#currentbalance').text(currentbalancetwil);
321
-                     $('#currentbalance').removeClass('icon-loading');
322
-                }
323
-            });
324
-          }
325
-
326
-          gettwilbalance();
327
-
328
-     } else if (provider == "Flowroute") {
329
-
330
-          var getflowbalance = function() {
331
-
332
-            $('#currentbalance').addClass('icon-loading');
333
-
334
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
-
336
-            $.ajax({
337
-                url: getflowbalanceUrl + '/' + userid,
338
-                type: "POST",
339
-                data: { userid: userid },
340
-                cache: false,
341
-                processData: false,
342
-                contentType: false,
343
-                success: function(currentbalanceflow) {
344
-
345
-                     $('#currentbalance').empty();
346
-                     $('#currentbalance').text(currentbalanceflow);
347
-                     $('#currentbalance').removeClass('icon-loading');
348
-                }
349
-            });
350
-          }
351
-
352
-          getflowbalance();
353
-
354
-       } else if (provider == "") {
355
-                $('#currentbalance').text("");
356
-                $('#currentbalance').removeClass('icon-loading');
357
-       }
358
-  });
359
-
360
-
361
-  // If a Sender ID is selected
362
-  $("#currentsmsnmbrs").on("change", function () {
363
-
364
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
-
366
-              selectedid = $('#currentsmsnmbrs :selected').val();
367
-              var setIdsplit = selectedid.split(":");
368
-	      chosenProvider = setIdsplit[0];
369
-
370
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
-	      if (chosenProvider == "Tx") {
372
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
-		  // Maximum size of message text + files in KB
374
-		  maximumsize = 1024;
375
-                  maximumsizeinit = 1024;
376
-		  maxsizenonimage = 600;
377
-		  maximumfilenumber = 10;
378
-                  chosenProvFullName = "Telnyx";
379
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
-                                     or gif files, the size of all the files plus the size of the text should be \
381
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
-                  $("#tooltiptextfourth").html(infonotecontent);
391
-	      } else if (chosenProvider == "Pl") {
392
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
-		  // Maximum size of message text + files in KB
395
-		  maximumsize = 5120;
396
-                  maximumsizeinit = 5120;
397
-		  maxsizenonimage = 600;
398
-		  maximumfilenumber = 10;
399
-                  chosenProvFullName = "Plivo";
400
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
-                                     or gif files, the size of all the files plus the size of the text should be \
402
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
-                  $("#tooltiptextfourth").html(infonotecontent);
412
-	      } else if (chosenProvider == "Tw") {
413
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
-                                     "icalendar", "directory", "pdf", "pkpass"];
416
-		  // Maximum size of message text + files in KB
417
-		  maximumsize = 5120;
418
-                  maximumsizeinit = 5120;
419
-		  maxsizenonimage = 600;
420
-		  maximumfilenumber = 10;
421
-                  chosenProvFullName = "Twilio";
422
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
-                                     or gif files, the size of all the files plus the size of the text should be \
424
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
-                                     previewed in the adjoining pane."
435
-                  $("#tooltiptextfourth").html(infonotecontent);
436
-	      } else if (chosenProvider == "Fl") {
437
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
-		  // Maximum size of message text + files in KB
439
-		  maximumsize = 750;
440
-                  maximumsizeinit = 750;
441
-		  maxsizenonimage = 600;
442
-		  maximumfilenumber = 10;
443
-                  chosenProvFullName = "Flowroute";
444
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
-                                     png or gif files, the size of all the files plus the size of the text should be \
446
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
-                                     size of the files plus the size of the text should be 600 KB or less. \
449
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
-                  $("#tooltiptextfourth").html(infonotecontent);
458
-	      }
459
-
460
-          } else { selectedid = ''; }
461
-  });
462
-
463
-  // Check the checkbox to send SMS message to multiple recipients
464
-  $('#tomultchckbx').change(function() {
465
-      if ($(this).is(':checked')) {
466
-          $("#multiplerecivers").css("display", "block");
467
-          $("#smstodiv").css("visibility", "hidden");
468
-          $("#smsto").val("");
469
-
470
-          receiversNumbers.length = 0;
471
-
472
-      } else {
473
-          $("#multiplerecivers").css("display", "none");
474
-          $("#smstodiv").css("visibility", "visible");
475
-
476
-          // Remove the uploaded file(s) if any
477
-          $("#induploadfile").remove();
478
-
479
-          receiversNumbers.length = 0;
480
-      }
481
-  });
482
-
483
-  // Upload the file with the recipients' phone numbers
484
-  $("#uploadfileforsms").change(function(e) {
485
-
486
-     $("#fileuploadednm").empty();
487
-
488
-     receiversNumbers.length = 0;
489
-
490
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
-
492
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
-
494
-     var formData = new FormData();
495
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
-
497
-     var fileup = $('#uploadfileforsms').val();
498
-     var fileuptrim = fileup.split('\\').pop();
499
-
500
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
-
502
-     var extension = fileup.replace(/^.*\./, '');
503
-
504
-     if (extension == fileup) {
505
-         extension = "";
506
-     } else {
507
-         extension = extension.toLowerCase();
508
-     }
509
-
510
-     var validExtensionsmrec = ["txt", "csv"];
511
-
512
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
-
514
-       if (selectedid != '') {
515
-
516
-               $.ajax({
517
-                 url: baseUrl + '/' + userid,
518
-                 type: "POST",
519
-                 data: formData,
520
-                 cache: false,
521
-                 processData: false,
522
-                 contentType: false,
523
-                 success: function(numberarray) {
524
-
525
-		    if (numberarray.length > 0) {
526
-
527
-		        // Get the array of the receivers' phone numbers
528
-		        if (chosenProvider == "Tx") {
529
-
530
-		             for(key in numberarray) {
531
-		                 receiversNumbers.push("+"+numberarray[key]);
532
-		             }
533
-
534
-		        } else if (chosenProvider == "Pl") {
535
-
536
-		             for(key in numberarray) {
537
-		                 receiversNumbers.push(numberarray[key]);
538
-		             }
539
-
540
-		          } else if (chosenProvider == "Tw") {
541
-
542
-		             for(key in numberarray) {
543
-		                 receiversNumbers.push(numberarray[key]);
544
-		             }
545
-		          } else if (chosenProvider == "Fl") {
546
-
547
-		             for(key in numberarray) {
548
-		                 receiversNumbers.push(numberarray[key]);
549
-		             }
550
-		          }
551
-
552
-		    } else {
553
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
-		    }
555
-                            
556
-                    // Preview the uploaded file
557
-                    var smsfilename = e.target.files[0].name;
558
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
-
560
-                    var reader = new FileReader();
561
-                    reader.readAsText(e.target.files[0]);
562
-                    reader.onload = function(e) {
563
-                          $("#smstables").empty();
564
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
-                    };
566
-
567
-                    $("#smstables").show();
568
-
569
-                    $('#sms_upload_msg').hide();
570
-                    $('#smstables').removeClass('icon-loading');
571
-
572
-                  },
573
-                  error: function() {
574
-                             showAlert("Error while uploading the file.");
575
-                  }
576
-               });
577
-
578
-        } else {
579
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
-               $('#sms_upload_msg').hide();
581
-               $('#smstables').removeClass('icon-loading');
582
-        }
583
-
584
-     } else {
585
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
-          $('#pf_upload_msg').hide();
587
-          $('#smstables').removeClass('icon-loading');
588
-
589
-          $("#induploadfile").remove();
590
-          $("#sms_upload_msg").hide();
591
-     }
592
-
593
-     // Preview uploaded file when clicked
594
-     $("#indfilediv").on("click", function() {
595
-
596
-          var smsfilename = e.target.files[0].name;
597
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
-
599
-          var reader = new FileReader();
600
-          reader.readAsText(e.target.files[0]);
601
-          reader.onload = function(e) {
602
-                  $("#smstables").empty();
603
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
-          };
605
-
606
-          $("#smstables").show();
607
-          $('#sms_upload_msg').hide();
608
-          $('#smstables').removeClass('icon-loading');
609
-     });
610
-
611
-     // Remove selected file
612
-     $("#indivflremove").on("click", function() {
613
-
614
-          $("#induploadfile").remove();
615
-          $("#sms_upload_msg").hide();
616
-
617
-          receiversNumbers.length = 0;
618
-
619
-     });
620
-
621
-  });
622
-
623
-  // Show the number of characters entered in the SMS textarea and the text size in KB
624
-  $("#smstext").on('input', function() {
625
-
626
-     $("#char_count").css("display", "inline");
627
-
628
-     $("#mtextSize").css("display", "inline");
629
-
630
-     $(".maxmessagelength").css("display", "inline-block");
631
-
632
-     $("#countchnb").text($(this).val().length);
633
-
634
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
-     $("#textsizeinkb").text(textsizekb);
637
-
638
-     if ($(this).val().length > charcolorthr) {
639
-         $("#char_count").css("color", "#BB2E4B");
640
-     } else {
641
-         $("#char_count").css("color", "#4cbc86;");
642
-     }
643
-
644
-  });
645
-
646
-
647
-  // Check the checkbox to send file(s) as MMS
648
-  $('#mediafilechckbx').change(function() {
649
-
650
-      if ($(this).is(':checked')) {
651
-
652
-          isMMS = 1;
653
-          if (selectedid == '') {
654
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
-              $(this).prop("checked", false);
656
-              isMMS = 0;
657
-              return;
658
-          }
659
-          $("#upmediafiles").css("display", "block");
660
-          $("#submitsms").prop("value", "Send MMS");
661
-
662
-      } else {
663
-
664
-          isMMS = 0;
665
-          $("#upmediafiles").css("display", "none");
666
-          $("#submitsms").prop("value", "Send SMS");
667
-
668
-          // Remove the uploaded file(s) if any
669
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
-          $(".indgenpckfls").each(function() { $(this).remove(); });
671
-
672
-          uploadedtomms = [];
673
-          n = 1;
674
-
675
-          msgtotalflsize = 0;
676
-
677
-          $("#filestotsize").hide();
678
-      }
679
-  });
680
-
681
-
682
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
-  function adjustMaximumSize(uploadedtomms) {
684
-				      
685
-      var nonimgcheck = 0;
686
-      for (var u = 0; u < uploadedtomms.length; u++) {
687
-	   var crupfl = uploadedtomms[u];
688
-	   var extensionup = crupfl.replace(/^.*\./, '');
689
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
-	       nonimgcheck = 1;
691
-	   }
692
-      }
693
-
694
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
-  }
696
-
697
-  // Upload files to be sent as MMS
698
-  $("#uploadfileformms").change(function(e) {
699
-
700
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
-     $('#smstables').addClass('icon-loading');
702
-     $('#filestotsize').show();
703
-
704
-     var userid = "<?php p($userId); ?>";
705
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
-
707
-     var formData = new FormData();
708
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
-
710
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
-
712
-     // Add the size of the current file to the total size of all the files
713
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
-
715
-     var fileup = $('#uploadfileformms').val();
716
-     var fileuptrim = fileup.split('\\').pop();
717
-
718
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
-         var duplicatescheck = 1;
720
-     } else { 
721
-         var duplicatescheck = 0;
722
-     }
723
-
724
-     var extension = fileup.replace(/^.*\./, '');
725
-
726
-     if (extension == fileup) {
727
-         extension = "";
728
-     } else {
729
-         extension = extension.toLowerCase();
730
-     }
731
-
732
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
-         maximumsize = maxsizenonimage;
735
-     }
736
-
737
-     if ($.inArray(extension, validExtensions) != -1) {
738
-
739
-       if (duplicatescheck == 0) {
740
-
741
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
-
743
-            if (n <= maximumfilenumber) {
744
-
745
-               $.ajax({
746
-                 url: baseUrl + '/' + userid,
747
-                 type: "POST",
748
-                 data: formData,
749
-                 cache: false,
750
-                 processData: false,
751
-                 contentType: false,
752
-                 success: function(totalflsize) {
753
-
754
-                   uploadedtomms.push(fileuptrim);
755
-
756
-                   $('#filessizetext').text(totalflsize);
757
-
758
-                   var rectotfilesz = parseFloat(totalflsize);
759
-
760
-                   if (rectotfilesz <= maximumsize) {
761
-                       $('#submitsms').attr("disabled", false);
762
-                       $('#filestotsize').css('color', '#189558');
763
-                   } else {
764
-                       $('#filestotsize').css('color', '#ba3555');
765
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
-                       $('#submitsms').attr("disabled", true);
767
-                       $('#smstables').removeClass('icon-loading');
768
-                       $('#pf_upload_msg').hide();
769
-                   }
770
-
771
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
-                   n++;
773
-
774
-                   // Preview the file when you click on its name
775
-                   $("div:visible[id*='indfilediv']").each(function() {
776
-
777
-                        $(this).on("click", function(eventclck) {
778
-
779
-                           $("#mmsfoldersview").css("display", "inline-block");
780
-                           var mmsfilenameinit = $(this).text();
781
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
-                           var mmsfilename = mmsfilenamesec.replace("X","");
783
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
-
786
-                           if (extenlst == mmsfilename) {
787
-                               extenlst = "";
788
-                           } else {
789
-                               extenlst = extenlst.toLowerCase();
790
-                           }
791
-
792
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
-                                  $("#smstables").empty();
794
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
-                           } else if (extenlst == 'png') {
797
-                                  $("#smstables").empty();
798
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
-                           } else if (extenlst == 'gif') {
801
-                                  $("#smstables").empty();
802
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
-                           } else if (extenlst == 'bmp') {
805
-                                  $("#smstables").empty();
806
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
-                                  var xhr = new XMLHttpRequest();
811
-                                  xhr.responseType = 'arraybuffer';
812
-                                  xhr.open('GET', tiffile);
813
-                                  xhr.onload = function (evnt) {
814
-                                      var tiff = new Tiff({buffer: xhr.response});
815
-                                      var tifcanvas = tiff.toCanvas();
816
-                                      $("#smstables").empty();
817
-                                      $("#smstables").append(tifcanvas);
818
-                                  };
819
-                                  xhr.send();
820
-                           } else if (extenlst == 'pdf') {
821
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
-                                  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>');
823
-                                  $("#smstables").empty();
824
-                                  $("#smstables").append($iframe);
825
-                           } else if (extenlst == 'txt') {
826
-                                  $("#smstables").empty();
827
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
-                           } else if (extension == 'mp4') {
829
-                                  $("#smstables").empty();
830
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
-		           } else if (extension == 'ogg') {
832
-		                  $("#smstables").empty();
833
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
-		           } else if (extension == 'avi') {
835
-		                  $("#smstables").empty();
836
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
-		                  $("#smstables").empty();
839
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
-		           } else if (extension == 'wav' || extension == 'wave') {
841
-		                  $("#smstables").empty();
842
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
-		           } else if (extension == 'mp3') {
844
-		                  $("#smstables").empty();
845
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
-		           } else if (extension == 'midi') {
847
-		                  $("#smstables").empty();
848
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
-		           }
850
-
851
-                           $("#smstables").show();
852
-                           $("#mmsfoldersview").hide();
853
-                        });
854
-                   });
855
-
856
-                   // Remove uploaded files
857
-                   $('[class*="indupfldl"]').last().click(function() {
858
-
859
-                           var userid = "<?php p($userId); ?>";
860
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
-
862
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
-
864
-                           var removedfilesplit = removedfilenameinit.split(") ");
865
-                           var removedflnb = parseInt(removedfilesplit[0]);
866
-
867
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
-                           $(this).hide();
869
-
870
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
-
872
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
-                                           return value != removedfilename;
874
-                           });
875
-
876
-                           $.ajax({
877
-                                   url: baseUrl + '/' + userid,
878
-                                   type: "POST",
879
-                                   data: {removedfilename: removedfilename},
880
-                                   success: function(totalflsize) {
881
-
882
-                                      msgtotalflsize = totalflsize;
883
-                                      $('#filessizetext').text(totalflsize);
884
-
885
-                                      adjustMaximumSize(uploadedtomms);
886
-
887
-                                      // Check message size
888
-                                      var rectotfilesz = parseFloat(totalflsize);
889
-
890
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
-                                          $('#submitsms').attr("disabled", false);
892
-                                          $('#filestotsize').css('color', '#189558');
893
-                                      } else {
894
-                                          $('#filestotsize').css('color', '#ba3555');
895
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
-                                          $('#submitsms').attr("disabled", true);
897
-                                      }
898
-
899
-                                      // Rewrite order numbers for files that follow
900
-                                      --n;
901
-                                      $("div:visible[id*='indfilediv']").each(function() {
902
-
903
-                                          var getdivtext =  $(this).text();
904
-                                          var splitdivtext = getdivtext.split(") ");
905
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
-                                          var newnbvalue = currentnbvalue - 1;
907
-
908
-                                          if (currentnbvalue > removedflnb) {
909
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
-                                              $(this).text(replacedstr);
911
-                                          }
912
-                                      });
913
-
914
-                                      $("div:visible[id*='indflpicked']").each(function() {
915
-
916
-                                          var getdivtext =  $(this).text();
917
-                                          var splitdivtext = getdivtext.split(") ");
918
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
-                                          var newnbvalue = currentnbvalue - 1;
920
-
921
-                                          if (currentnbvalue > removedflnb) {
922
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
-                                              $(this).text(replacedstr);
924
-                                          }
925
-                                      });
926
-
927
-                                   },
928
-                                   error: function() {
929
-                                              showAlert("Error while removing the file(s).");
930
-                                   }
931
-                           });
932
-
933
-                           $('#smstables').removeClass('icon-loading');
934
-                           $("#smstables").empty();
935
-                   });
936
-
937
-                   // Preview the uploaded file
938
-                   $("#mmsfoldersview").css("display", "inline-block");
939
-                   var mmsfilename = e.target.files[0].name;
940
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
-
942
-
943
-                   if (extension == 'jpg' || extension == 'jpeg') {
944
-                              $("#smstables").empty();
945
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
-
947
-                              var reader = new FileReader();
948
-                              reader.onload = function (e) {
949
-                                  readjpg[mmsfilename] = e.target.result;
950
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
-                              }
952
-                              reader.readAsDataURL(e.target.files[0]);
953
-                   } else if (extension == 'png') {
954
-                              $("#smstables").empty();
955
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
-
957
-                              var reader = new FileReader();
958
-                              reader.onload = function (e) {
959
-                                  readpng[mmsfilename] = e.target.result;
960
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
-                              }
962
-                              reader.readAsDataURL(e.target.files[0]);
963
-
964
-                   } else if (extension == 'gif') {
965
-                              $("#smstables").empty();
966
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
-
968
-                              var reader = new FileReader();
969
-                              reader.onload = function (e) {
970
-                                  readgif[mmsfilename] = e.target.result;
971
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
-                              }
973
-                              reader.readAsDataURL(e.target.files[0]);
974
-
975
-                   } else if (extension == 'bmp') {
976
-                              $("#smstables").empty();
977
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
-
979
-                              var reader = new FileReader();
980
-                              reader.onload = function (e) {
981
-                                  readbmp[mmsfilename] = e.target.result;
982
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
-                              }
984
-                              reader.readAsDataURL(e.target.files[0]);
985
-
986
-                   } else if (extension == 'tif' || extension == 'tiff') {
987
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
-                              var xhr = new XMLHttpRequest();
989
-                              xhr.responseType = 'arraybuffer';
990
-                              xhr.open('GET', tiffile);
991
-                              xhr.onload = function (e) {
992
-                                  var tiff = new Tiff({buffer: xhr.response});
993
-                                  var tifcanvas = tiff.toCanvas();
994
-                                  $("#smstables").empty();
995
-                                  $("#smstables").append(tifcanvas);
996
-                              };
997
-                              xhr.send();
998
-
999
-                   } else if (extension == 'pdf') {
1000
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
-                              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>');
1002
-                              $("#smstables").empty();
1003
-                              $("#smstables").append($iframe);
1004
-
1005
-                   } else if (extension == 'txt') {
1006
-                              var reader = new FileReader();
1007
-                              reader.readAsText(e.target.files[0]);
1008
-                              reader.onload = function(e) {
1009
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
-                                  $("#smstables").empty();
1011
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
-                              };
1013
-                   } else if (extension == 'mp4') {
1014
-                              $("#smstables").empty();
1015
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
-                   } else if (extension == 'ogg') {
1017
-                              $("#smstables").empty();
1018
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
-                   } else if (extension == 'avi') {
1020
-                              $("#smstables").empty();
1021
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
-                              $("#smstables").empty();
1024
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
-                   } else if (extension == 'wav' || extension == 'wave') {
1026
-                              $("#smstables").empty();
1027
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
-                   } else if (extension == 'mp3') {
1029
-                              $("#smstables").empty();
1030
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
-                   } else if (extension == 'midi') {
1032
-                              $("#smstables").empty();
1033
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
-                   }
1035
-
1036
-                   $("#smstables").show();
1037
-                   $('#pf_upload_msg').hide();
1038
-                   $('#smstables').removeClass('icon-loading');
1039
-                   $("#mmsfoldersview").hide();
1040
-                 },
1041
-                 error: function() {
1042
-                              showAlert("Error while uploading the file.");
1043
-                 }
1044
-               });
1045
-
1046
-            } else {
1047
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
-                  adjustMaximumSize(uploadedtomms);
1049
-
1050
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
-                  $('#pf_upload_msg').hide();
1052
-                  $('#smstables').removeClass('icon-loading');
1053
-            }
1054
-         } else {
1055
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
-              adjustMaximumSize(uploadedtomms);
1057
-
1058
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
-              $('#pf_upload_msg').hide();
1060
-              $('#smstables').removeClass('icon-loading');
1061
-         }
1062
-       } else {
1063
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
-            adjustMaximumSize(uploadedtomms);
1065
-
1066
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
-            $('#pf_upload_msg').hide();
1068
-            $('#smstables').removeClass('icon-loading');
1069
-       }
1070
-
1071
-     } else {
1072
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
-          adjustMaximumSize(uploadedtomms);
1074
-
1075
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
-          $('#pf_upload_msg').hide();
1077
-          $('#smstables').removeClass('icon-loading');
1078
-     }
1079
-  });
1080
-
1081
-
1082
-  // Pick file(s) from Nextcloud, to send as MMS
1083
-  var mmsfilename = null;
1084
-
1085
-  $("#choosefilen").on("click", function(evn) {
1086
-
1087
-                OC.dialogs.filepicker(
1088
-                        t('settings', "Select a file to send as MMS."),
1089
-                        function (path) {
1090
-
1091
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
-                              $('#smstables').addClass('icon-loading');
1093
-                              $('#filestotsize').show();
1094
-
1095
-                              var userid = "<?php p($userId); ?>";
1096
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
-
1098
-                              mmsfilename = path.split('/').pop();
1099
-
1100
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
-                                  var duplicatescheck = 1;
1102
-                              } else var duplicatescheck = 0;
1103
-
1104
-                              var extension = mmsfilename.replace(/^.*\./, '');
1105
-
1106
-                              if (extension == mmsfilename) {
1107
-                                  extension = "";
1108
-                              } else {
1109
-                                  extension = extension.toLowerCase();
1110
-                              }
1111
-
1112
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
-				   maximumsize = maxsizenonimage;
1115
-			      }
1116
-
1117
-                              if ($.inArray(extension, validExtensions) != -1) {
1118
-
1119
-                                 if (duplicatescheck == 0) {
1120
-
1121
-                                    if (n <= maximumfilenumber) {
1122
-
1123
-                                       $.ajax({
1124
-                                          url: baseUrl + '/' + userid,
1125
-                                          type: "POST",
1126
-                                          data: { path: path },
1127
-                                          success: function(pickresult) {
1128
-
1129
-                                                uploadedtomms.push(mmsfilename);
1130
-
1131
-                                                var totalflsize = pickresult[0];
1132
-                                                var pickedflsize = pickresult[1];
1133
-
1134
-                                                // Check message size
1135
-                                                var rectotfilesz = parseFloat(totalflsize);
1136
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
-
1138
-                                                if (filesplustextsize <= maximumsize) {
1139
-
1140
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
-
1142
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
-                                                    n++;
1144
-
1145
-                                                    msgtotalflsize = totalflsize;
1146
-                                                    $('#filessizetext').text(totalflsize);
1147
-                                                    $('#filestotsize').css('color', '#189558');
1148
-
1149
-                                                } else {
1150
-
1151
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
-                                                    $('#filestotsize').css('color', '#ba3555');
1153
-                                                    msgtotalflsize -= pickedflsize;
1154
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
-
1156
-                                                    $.ajax({
1157
-                                                        url: baseUrlindrm + '/' + userid,
1158
-                                                        type: "POST",
1159
-                                                        data: {removedfilename: mmsfilename},
1160
-                                                        success: function(totalflsize) {
1161
-
1162
-                                                                          $('#filessizetext').text(totalflsize);
1163
-                                                                          $('#filestotsize').css('color', '#189558');
1164
-                                                                          adjustMaximumSize(uploadedtomms);
1165
-
1166
-                                                        },
1167
-                                                        error: function(totalflsize) {
1168
-                                                                          $('#filessizetext').text(totalflsize);
1169
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
-                                                                              $('#filestotsize').css('color', '#ba3555');
1171
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
-                                                        }
1174
-                                                    });
1175
-
1176
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
-                                                }
1178
-
1179
-
1180
-                                                // Preview each file when you click on its name
1181
-                                                $("div:visible[id*='indflpicked']").each(function() {
1182
-                                                   $(this).on("click", function(event) {
1183
-
1184
-                                                      var mmsfilenameinit = $(this).text();
1185
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
-
1190
-                                                      if (extenlst == mmsfilenamesp) {
1191
-                                                           extenlst = "";
1192
-                                                      } else {
1193
-                                                           extenlst = extenlst.toLowerCase();
1194
-                                                      }
1195
-
1196
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
-                                                              $("#smstables").empty();
1198
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
-                                                      } else if (extenlst == 'png') {
1200
-                                                              $("#smstables").empty();
1201
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
-                                                      } else if (extenlst == 'gif') {
1203
-                                                              $("#smstables").empty();
1204
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
-                                                      } else if (extenlst == 'bmp') {
1206
-                                                              $("#smstables").empty();
1207
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
-                                                              var xhr = new XMLHttpRequest();
1211
-                                                              xhr.responseType = 'arraybuffer';
1212
-                                                              xhr.open('GET', tiffile);
1213
-                                                              xhr.onload = function (evnt) {
1214
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
-                                                                  var tifcanvas = tiff.toCanvas();
1216
-                                                                  $("#smstables").empty();
1217
-                                                                  $("#smstables").append(tifcanvas);
1218
-                                                              };
1219
-                                                              xhr.send();
1220
-                                                      } else if (extenlst == 'pdf') {
1221
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
-                                                              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>');
1223
-                                                              $("#smstables").empty();
1224
-                                                              $("#smstables").append($iframe);
1225
-                                                      } else if (extenlst == 'txt') {
1226
-                                                              $("#smstables").empty();
1227
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
-                                                      } else if (extension == 'mp4') {
1229
-							      $("#smstables").empty();
1230
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
-						      } else if (extension == 'ogg') {
1232
-							      $("#smstables").empty();
1233
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
-						      } else if (extension == 'avi') {
1235
-							      $("#smstables").empty();
1236
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
-							      $("#smstables").empty();
1239
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
-						      } else if (extension == 'wav' || extension == 'wave') {
1241
-							      $("#smstables").empty();
1242
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
-						      } else if (extension == 'mp3') {
1244
-							      $("#smstables").empty();
1245
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
-						      } else if (extension == 'midi') {
1247
-							      $("#smstables").empty();
1248
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
-						      }
1250
-
1251
-
1252
-                                                      $("#smstables").show();
1253
-                                                      $("#mmsfoldersview").hide();
1254
-                                                   });
1255
-                                                });
1256
-
1257
-
1258
-                                                // Remove picked files
1259
-                                                $('[class*="indpckfldl"]').last().click(function() {
1260
-                                                    var userid = "<?php p($userId); ?>";
1261
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
-
1263
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
-
1265
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
-
1268
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
-                                                    $(this).hide();
1270
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
-
1272
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
-                                                             return value != removedfilename;
1274
-                                                    });
1275
-
1276
-                                                    $.ajax({
1277
-                                                        url: baseUrl + '/' + userid,
1278
-                                                        type: "POST",
1279
-                                                        data: {removedfilename: removedfilename},
1280
-                                                        success: function(totalflsize) {
1281
-
1282
-                                                             msgtotalflsize = totalflsize;
1283
-                                                             $('#filessizetext').text(totalflsize);
1284
-                                                             adjustMaximumSize(uploadedtomms);
1285
-
1286
-                                                             // Check message size
1287
-                                                             var rectotfilesz = parseFloat(totalflsize);
1288
-
1289
-                                                             if (rectotfilesz > maximumsize) {
1290
-                                                                 $('#filestotsize').css('color', '#ba3555');
1291
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
-                                                                 $('#submitsms').attr("disabled", true);
1293
-                                                             } else {
1294
-                                                                 $('#submitsms').attr("disabled", false);
1295
-                                                                 $('#filestotsize').css('color', '#189558');
1296
-                                                               }
1297
-
1298
-                                                             // Rewrite order numbers for files that follow
1299
-                                                             --n;
1300
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
-
1302
-                                                                  var getdivtext =  $(this).text();
1303
-                                                                  var splitdivtext = getdivtext.split(") ");
1304
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
-                                                                  var newnbvalue = currentnbvalue - 1;
1306
-
1307
-                                                                  if (currentnbvalue > removedflnb) {
1308
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
-                                                                      $(this).text(replacedstr);
1310
-                                                                  }
1311
-                                                             });
1312
-                                                        },
1313
-                                                        error: function() {
1314
-                                                                  showAlert("Error while removing the file.");
1315
-                                                        }
1316
-                                                    });
1317
-
1318
-                                                    $('#smstables').removeClass('icon-loading');
1319
-                                                    $("#smstables").empty();
1320
-                                                });
1321
-
1322
-
1323
-		                                // Preview the picked file
1324
-		                                $("#mmsfoldersview").css("display", "inline-block");
1325
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
-
1328
-
1329
-						if (extension == 'jpg' || extension == 'jpeg') {
1330
-
1331
-		                                            $("#smstables").empty();
1332
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
-
1334
-		                                } else if (extension == 'png') {
1335
-
1336
-		                                            $("#smstables").empty();
1337
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
-
1339
-		                                } else if (extension == 'gif') {
1340
-
1341
-		                                            $("#smstables").empty();
1342
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
-
1344
-		                                } else if (extension == 'bmp') {
1345
-
1346
-	                                                    $("#smstables").empty();
1347
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
-
1349
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
-
1351
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
-		                                       var xhr = new XMLHttpRequest();
1353
-		                                       xhr.responseType = 'arraybuffer';
1354
-		                                       xhr.open('GET', tiffile);
1355
-		                                       xhr.onload = function (event) {
1356
-		                                           var tiff = new Tiff({buffer: xhr.response});
1357
-		                                           var tifcanvas = tiff.toCanvas();
1358
-		                                           $("#smstables").empty();
1359
-		                                           $("#smstables").append(tifcanvas);
1360
-		                                       };
1361
-		                                       xhr.send();
1362
-
1363
-		                                } else if (extension == 'pdf') {
1364
-
1365
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
-		                                       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>');
1367
-		                                       $("#smstables").empty();
1368
-		                                       $("#smstables").append($iframe);
1369
-
1370
-		                                } else if (extension == 'txt') {
1371
-
1372
-							     $.get(flUrl, function(textdata) {
1373
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
-		                                               $("#smstables").empty();
1375
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
-							     });
1377
-
1378
-		                                } else if (extension == 'mp4') {
1379
-						       $("#smstables").empty();
1380
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
-						} else if (extension == 'ogg') {
1382
-						       $("#smstables").empty();
1383
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
-						} else if (extension == 'avi') {
1385
-						       $("#smstables").empty();
1386
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
-						       $("#smstables").empty();
1389
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
-						} else if (extension == 'wav' || extension == 'wave') {
1391
-						       $("#smstables").empty();
1392
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
-						} else if (extension == 'mp3') {
1394
-						       $("#smstables").empty();
1395
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
-						} else if (extension == 'midi') {
1397
-						       $("#smstables").empty();
1398
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
-						}
1400
-
1401
-
1402
-		                                $("#smstables").show();
1403
-
1404
-		                                $('#pf_choose_msg').hide();
1405
-		                                $('#smstables').removeClass('icon-loading');
1406
-		                                $("#mmsfoldersview").hide();
1407
-
1408
-                                          },
1409
-
1410
-                                          error: function(data){
1411
-                                                      showAlert("Error while getting the file.");
1412
-                                          }
1413
-
1414
-                                       });
1415
-
1416
-                                    } else {
1417
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
-                                        $('#pf_choose_msg').hide();
1419
-                                        $('#smstables').removeClass('icon-loading');
1420
-                                      }
1421
-                                 } else {
1422
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
-                                      $('#pf_choose_msg').hide();
1424
-                                      $('#smstables').removeClass('icon-loading');
1425
-                                   }
1426
-
1427
-                              } else {
1428
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
-                                   $('#pf_choose_msg').hide();
1430
-                                   $('#smstables').removeClass('icon-loading');
1431
-                                }
1432
-
1433
-                        }
1434
-                );
1435
-  });
1436
-
1437
-
1438
-
1439
-  // Send the SMS/MMS message
1440
-  $("#submitsms").on("click", function(event) {
1441
-
1442
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
-     $("#sms_submit_msg").css("display", "inline-block");
1445
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
-
1447
-     if (selectedid != '') { 
1448
-
1449
-         var sendersplit = selectedid.split(":");
1450
-         var providercap = sendersplit[0];
1451
-         var provsec = sendersplit[1];
1452
-
1453
-         if (/[a-zA-Z]/.test(provsec)) {
1454
-             var alphanumcheck = true;
1455
-         } else { var alphanumcheck = false; }
1456
-
1457
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
-             var selectedsender = "+" + senderproc;
1460
-             var providerUsed = "telnyx";
1461
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
-             var providerUsed = "plivo";
1465
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
-             var selectedsender = "+" + senderproc;
1469
-             var providerUsed = "twilio";
1470
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
-             var selectedsender = "+" + senderproc;
1474
-             var providerUsed = "flowroute";
1475
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
-             var selectedsender = provsec;
1478
-             var providerUsed = "telnyx";
1479
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
-             var selectedsender = provsec;
1482
-             var providerUsed = "plivo";
1483
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
-             var selectedsender = provsec;
1486
-             var providerUsed = "twilio";
1487
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
-             var selectedsender = provsec;
1490
-             var providerUsed = "flowroute";
1491
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
-         }
1493
-
1494
-         // Get the interval between message consecutive sending requests, if it's the case
1495
-         if ($('#tomultchckbx').is(':checked')) {
1496
-
1497
-             var numbersfile = 1;
1498
-             var initinterval = $("#multsmsinterval").val();
1499
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
-
1501
-             if (secinterval != '') {
1502
-                 var tertinterval = parseInt(secinterval);
1503
-                     waittime = tertinterval;
1504
-             }
1505
-
1506
-         } else {
1507
-
1508
-             var numbersfile = 0;
1509
-             var toNumberinit = $('#smsto').val();
1510
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
-             var toNumbersec = toNumber.split(",");
1512
-
1513
-                 for (var i = 0; i < toNumbersec.length; i++) {
1514
-                      toNumbersec[i] = "+" + toNumbersec[i];
1515
-                 }
1516
-
1517
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
-         }
1519
-
1520
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
-
1522
-         var smstext = $("#smstext").val();
1523
-
1524
-         if (receiversNumbers.length != 0) {
1525
-
1526
-              if (smstext != '') {
1527
-                  $.ajax({
1528
-                     url: relbaseUrl + '/' + userid,
1529
-                     type: "POST",
1530
-                     data: {
1531
-                           receiversPhoneNbs: receiversNumbers,
1532
-                           fromsender: selectedsender,
1533
-                           waitinterval: waittime,
1534
-                           sentsmstext: smstext,
1535
-                           ismms: isMMS,
1536
-                           mmsfiles: uploadedtomms
1537
-                         },
1538
-                     success: function() {
1539
-
1540
-                           if (receiversNumbers.length == 1) {
1541
-                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
-                           } else {
1543
-                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
-                           }
1545
-
1546
-                           $('#sms_submit_msg').hide();
1547
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
-                     },
1549
-                     error: function() {
1550
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
-                           $('#sms_submit_msg').hide();
1552
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
-                     }
1554
-                  });
1555
-              } else {
1556
-                     showAlert("Please enter a message in the text box !");
1557
-
1558
-                     $('#sms_submit_msg').hide();
1559
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
-              }
1561
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
-                 showAlert("Please enter the recipient's phone number !");
1563
-                 $('#sms_submit_msg').hide();
1564
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
-                 $('#sms_submit_msg').hide();
1568
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
-         }
1570
-     } else {
1571
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
-           $('#sms_submit_msg').hide();
1574
-     }
1575
-
1576
-  });
1577
-
1578
-  // Check the checkbox to delete old messages from the database
1579
-  $('#deleteoldchckbox').change(function() {
1580
-     if ($(this).is(':checked')) {
1581
-         $("#deleteoldsms").css("display", "block");
1582
-     } else {
1583
-         $("#deleteoldsms").css("display", "none");
1584
-     }
1585
-  });
1586
-
1587
-  // Set the height of info notes
1588
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
-
1592
-  $(window).resize(function() { 
1593
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
-  });
1597
-
1598
-
1599
-  function showAlert(alertText) {
1600
-
1601
-     let alertwnd = "<div id='alertMessage'>";
1602
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
-     alertwnd += "</div>";
1606
-
1607
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
-     $("#content").append(alertwnd);
1609
-
1610
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
-
1614
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
-  }
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css img/closewnd.svg js/adminsettings.js js/deleteoldsms.js ...

DoubleBastionAdmin authored on 23/05/2023 19:00:54
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1617 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+                     } else if (currentnmbrs.length == 1) {
111
+
112
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
113
+
114
+                                selectedid = currentnmbrs[0];
115
+
116
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
117
+
118
+                                if (unqprovider == 'Tx') {
119
+
120
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
121
+					  // Maximum size of message text + files in KB
122
+					  maximumsize = 1024;
123
+					  maximumsizeinit = 1024;
124
+					  maxsizenonimage = 600;
125
+					  maximumfilenumber = 10;
126
+					  chosenProvFullName = "Telnyx";
127
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
128
+						             or gif files, the size of all the files plus the size of the text should be \
129
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
130
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
131
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
132
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
133
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
134
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
135
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
136
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
137
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
138
+					  $("#tooltiptextfourth").html(infonotecontent);
139
+
140
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
141
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
142
+
143
+                                } else if (unqprovider == 'Pl') {
144
+
145
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
146
+						             "icalendar", "csv", "txt", "pdf", "xls"];
147
+					  // Maximum size of message text + files in KB
148
+					  maximumsize = 5120;
149
+					  maximumsizeinit = 5120;
150
+					  maxsizenonimage = 600;
151
+					  maximumfilenumber = 10;
152
+					  chosenProvFullName = "Plivo";
153
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
154
+						             or gif files, the size of all the files plus the size of the text should be \
155
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
156
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
157
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
158
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
159
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
160
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
161
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
162
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
163
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
164
+					  $("#tooltiptextfourth").html(infonotecontent);
165
+
166
+                                          // Append 'Plivo' to the 'see balance' drop-down list
167
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
168
+
169
+                                } else if (unqprovider == 'Tw') {
170
+
171
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
172
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
173
+						             "icalendar", "directory", "pdf", "pkpass"];
174
+					  // Maximum size of message text + files in KB
175
+					  maximumsize = 5120;
176
+					  maximumsizeinit = 5120;
177
+					  maxsizenonimage = 600;
178
+					  maximumfilenumber = 10;
179
+					  chosenProvFullName = "Twilio";
180
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
181
+						             or gif files, the size of all the files plus the size of the text should be \
182
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
183
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
184
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
185
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
186
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
187
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
188
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
189
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
190
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
191
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
192
+						             previewed in the adjoining pane."
193
+					  $("#tooltiptextfourth").html(infonotecontent);
194
+
195
+                                          // Append 'Twilio' to the 'see balance' drop-down list
196
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
197
+
198
+                                } else if (unqprovider == 'Fl') {
199
+
200
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
201
+					  // Maximum size of message text + files in KB
202
+					  maximumsize = 750;
203
+					  maximumsizeinit = 750;
204
+					  maxsizenonimage = 600;
205
+					  maximumfilenumber = 10;
206
+					  chosenProvFullName = "Flowroute";
207
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
208
+							     png or gif files, the size of all the files plus the size of the text should be \
209
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
210
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
211
+							     size of the files plus the size of the text should be 600 KB or less. \
212
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
213
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
214
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
215
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
216
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
217
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
218
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
219
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
220
+					  $("#tooltiptextfourth").html(infonotecontent);
221
+
222
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
223
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
224
+                                }
225
+                     } else {
226
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
227
+                     }
228
+
229
+                     $("#smsnumbersdiv").removeClass('icon-loading');
230
+          }
231
+  });
232
+
233
+  // Clean the SMS_Relentless/temp_files directory
234
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
235
+
236
+  $.ajax({
237
+          url: cleanflUrl + '/' + userid,
238
+          type: "POST",
239
+          data: { userid: userid },
240
+          cache: false,
241
+          processData: false,
242
+          contentType: false
243
+  });
244
+  
245
+  // Check the available balance
246
+  $("#smsprovider").on("change", function () {
247
+
248
+     var provider = $('#smsprovider :selected').val();
249
+
250
+     if (provider == "Telnyx") {
251
+
252
+        var gettelbalance = function() {
253
+
254
+          $('#currentbalance').addClass('icon-loading');
255
+
256
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
257
+
258
+          $.ajax({
259
+              url: gettelbalanceUrl + '/' + userid,
260
+              type: "POST",
261
+              data: { userid: userid },
262
+              cache: false,
263
+              processData: false,
264
+              contentType: false,
265
+              success: function(currentbalancetel) {
266
+
267
+                     $('#currentbalance').empty();
268
+                     $('#currentbalance').text(currentbalancetel);
269
+                     $('#currentbalance').removeClass('icon-loading');
270
+              }
271
+          });
272
+        }
273
+
274
+        gettelbalance();
275
+
276
+     } else if (provider == "Plivo") {
277
+
278
+          var getnexbalance = function() {
279
+
280
+            $('#currentbalance').addClass('icon-loading');
281
+
282
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
283
+
284
+            $.ajax({
285
+                url: getnexbalanceUrl + '/' + userid,
286
+                type: "POST",
287
+                data: { userid: userid },
288
+                cache: false,
289
+                processData: false,
290
+                contentType: false,
291
+                success: function(currentbalancenex) {
292
+
293
+                     $('#currentbalance').empty();
294
+                     $('#currentbalance').text(currentbalancenex);
295
+                     $('#currentbalance').removeClass('icon-loading');
296
+                }
297
+            });
298
+          }
299
+
300
+          getnexbalance();
301
+
302
+     } else if (provider == "Twilio") {
303
+
304
+          var gettwilbalance = function() {
305
+
306
+            $('#currentbalance').addClass('icon-loading');
307
+
308
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
309
+
310
+            $.ajax({
311
+                url: gettwilbalanceUrl + '/' + userid,
312
+                type: "POST",
313
+                data: { userid: userid },
314
+                cache: false,
315
+                processData: false,
316
+                contentType: false,
317
+                success: function(currentbalancetwil) {
318
+
319
+                     $('#currentbalance').empty();
320
+                     $('#currentbalance').text(currentbalancetwil);
321
+                     $('#currentbalance').removeClass('icon-loading');
322
+                }
323
+            });
324
+          }
325
+
326
+          gettwilbalance();
327
+
328
+     } else if (provider == "Flowroute") {
329
+
330
+          var getflowbalance = function() {
331
+
332
+            $('#currentbalance').addClass('icon-loading');
333
+
334
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
335
+
336
+            $.ajax({
337
+                url: getflowbalanceUrl + '/' + userid,
338
+                type: "POST",
339
+                data: { userid: userid },
340
+                cache: false,
341
+                processData: false,
342
+                contentType: false,
343
+                success: function(currentbalanceflow) {
344
+
345
+                     $('#currentbalance').empty();
346
+                     $('#currentbalance').text(currentbalanceflow);
347
+                     $('#currentbalance').removeClass('icon-loading');
348
+                }
349
+            });
350
+          }
351
+
352
+          getflowbalance();
353
+
354
+       } else if (provider == "") {
355
+                $('#currentbalance').text("");
356
+                $('#currentbalance').removeClass('icon-loading');
357
+       }
358
+  });
359
+
360
+
361
+  // If a Sender ID is selected
362
+  $("#currentsmsnmbrs").on("change", function () {
363
+
364
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
365
+
366
+              selectedid = $('#currentsmsnmbrs :selected').val();
367
+              var setIdsplit = selectedid.split(":");
368
+	      chosenProvider = setIdsplit[0];
369
+
370
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
371
+	      if (chosenProvider == "Tx") {
372
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
373
+		  // Maximum size of message text + files in KB
374
+		  maximumsize = 1024;
375
+                  maximumsizeinit = 1024;
376
+		  maxsizenonimage = 600;
377
+		  maximumfilenumber = 10;
378
+                  chosenProvFullName = "Telnyx";
379
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
380
+                                     or gif files, the size of all the files plus the size of the text should be \
381
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
382
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
383
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
384
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
385
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
386
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
387
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
388
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
389
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
390
+                  $("#tooltiptextfourth").html(infonotecontent);
391
+	      } else if (chosenProvider == "Pl") {
392
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
393
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
394
+		  // Maximum size of message text + files in KB
395
+		  maximumsize = 5120;
396
+                  maximumsizeinit = 5120;
397
+		  maxsizenonimage = 600;
398
+		  maximumfilenumber = 10;
399
+                  chosenProvFullName = "Plivo";
400
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
401
+                                     or gif files, the size of all the files plus the size of the text should be \
402
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
403
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
404
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
405
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
406
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
407
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
408
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
409
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
410
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
411
+                  $("#tooltiptextfourth").html(infonotecontent);
412
+	      } else if (chosenProvider == "Tw") {
413
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
414
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
415
+                                     "icalendar", "directory", "pdf", "pkpass"];
416
+		  // Maximum size of message text + files in KB
417
+		  maximumsize = 5120;
418
+                  maximumsizeinit = 5120;
419
+		  maxsizenonimage = 600;
420
+		  maximumfilenumber = 10;
421
+                  chosenProvFullName = "Twilio";
422
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
423
+                                     or gif files, the size of all the files plus the size of the text should be \
424
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
425
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
426
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
427
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
428
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
429
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
430
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
431
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
432
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
433
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
434
+                                     previewed in the adjoining pane."
435
+                  $("#tooltiptextfourth").html(infonotecontent);
436
+	      } else if (chosenProvider == "Fl") {
437
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
438
+		  // Maximum size of message text + files in KB
439
+		  maximumsize = 750;
440
+                  maximumsizeinit = 750;
441
+		  maxsizenonimage = 600;
442
+		  maximumfilenumber = 10;
443
+                  chosenProvFullName = "Flowroute";
444
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
445
+                                     png or gif files, the size of all the files plus the size of the text should be \
446
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
447
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
448
+                                     size of the files plus the size of the text should be 600 KB or less. \
449
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
450
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
451
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
452
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
453
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
454
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
455
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
456
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
457
+                  $("#tooltiptextfourth").html(infonotecontent);
458
+	      }
459
+
460
+          } else { selectedid = ''; }
461
+  });
462
+
463
+  // Check the checkbox to send SMS message to multiple recipients
464
+  $('#tomultchckbx').change(function() {
465
+      if ($(this).is(':checked')) {
466
+          $("#multiplerecivers").css("display", "block");
467
+          $("#smstodiv").css("visibility", "hidden");
468
+          $("#smsto").val("");
469
+
470
+          receiversNumbers.length = 0;
471
+
472
+      } else {
473
+          $("#multiplerecivers").css("display", "none");
474
+          $("#smstodiv").css("visibility", "visible");
475
+
476
+          // Remove the uploaded file(s) if any
477
+          $("#induploadfile").remove();
478
+
479
+          receiversNumbers.length = 0;
480
+      }
481
+  });
482
+
483
+  // Upload the file with the recipients' phone numbers
484
+  $("#uploadfileforsms").change(function(e) {
485
+
486
+     $("#fileuploadednm").empty();
487
+
488
+     receiversNumbers.length = 0;
489
+
490
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
491
+
492
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
493
+
494
+     var formData = new FormData();
495
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
496
+
497
+     var fileup = $('#uploadfileforsms').val();
498
+     var fileuptrim = fileup.split('\\').pop();
499
+
500
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
501
+
502
+     var extension = fileup.replace(/^.*\./, '');
503
+
504
+     if (extension == fileup) {
505
+         extension = "";
506
+     } else {
507
+         extension = extension.toLowerCase();
508
+     }
509
+
510
+     var validExtensionsmrec = ["txt", "csv"];
511
+
512
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
513
+
514
+       if (selectedid != '') {
515
+
516
+               $.ajax({
517
+                 url: baseUrl + '/' + userid,
518
+                 type: "POST",
519
+                 data: formData,
520
+                 cache: false,
521
+                 processData: false,
522
+                 contentType: false,
523
+                 success: function(numberarray) {
524
+
525
+		    if (numberarray.length > 0) {
526
+
527
+		        // Get the array of the receivers' phone numbers
528
+		        if (chosenProvider == "Tx") {
529
+
530
+		             for(key in numberarray) {
531
+		                 receiversNumbers.push("+"+numberarray[key]);
532
+		             }
533
+
534
+		        } else if (chosenProvider == "Pl") {
535
+
536
+		             for(key in numberarray) {
537
+		                 receiversNumbers.push(numberarray[key]);
538
+		             }
539
+
540
+		          } else if (chosenProvider == "Tw") {
541
+
542
+		             for(key in numberarray) {
543
+		                 receiversNumbers.push(numberarray[key]);
544
+		             }
545
+		          } else if (chosenProvider == "Fl") {
546
+
547
+		             for(key in numberarray) {
548
+		                 receiversNumbers.push(numberarray[key]);
549
+		             }
550
+		          }
551
+
552
+		    } else {
553
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
554
+		    }
555
+                            
556
+                    // Preview the uploaded file
557
+                    var smsfilename = e.target.files[0].name;
558
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
559
+
560
+                    var reader = new FileReader();
561
+                    reader.readAsText(e.target.files[0]);
562
+                    reader.onload = function(e) {
563
+                          $("#smstables").empty();
564
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
565
+                    };
566
+
567
+                    $("#smstables").show();
568
+
569
+                    $('#sms_upload_msg').hide();
570
+                    $('#smstables').removeClass('icon-loading');
571
+
572
+                  },
573
+                  error: function() {
574
+                             showAlert("Error while uploading the file.");
575
+                  }
576
+               });
577
+
578
+        } else {
579
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
580
+               $('#sms_upload_msg').hide();
581
+               $('#smstables').removeClass('icon-loading');
582
+        }
583
+
584
+     } else {
585
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
586
+          $('#pf_upload_msg').hide();
587
+          $('#smstables').removeClass('icon-loading');
588
+
589
+          $("#induploadfile").remove();
590
+          $("#sms_upload_msg").hide();
591
+     }
592
+
593
+     // Preview uploaded file when clicked
594
+     $("#indfilediv").on("click", function() {
595
+
596
+          var smsfilename = e.target.files[0].name;
597
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
598
+
599
+          var reader = new FileReader();
600
+          reader.readAsText(e.target.files[0]);
601
+          reader.onload = function(e) {
602
+                  $("#smstables").empty();
603
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
604
+          };
605
+
606
+          $("#smstables").show();
607
+          $('#sms_upload_msg').hide();
608
+          $('#smstables').removeClass('icon-loading');
609
+     });
610
+
611
+     // Remove selected file
612
+     $("#indivflremove").on("click", function() {
613
+
614
+          $("#induploadfile").remove();
615
+          $("#sms_upload_msg").hide();
616
+
617
+          receiversNumbers.length = 0;
618
+
619
+     });
620
+
621
+  });
622
+
623
+  // Show the number of characters entered in the SMS textarea and the text size in KB
624
+  $("#smstext").on('input', function() {
625
+
626
+     $("#char_count").css("display", "inline");
627
+
628
+     $("#mtextSize").css("display", "inline");
629
+
630
+     $(".maxmessagelength").css("display", "inline-block");
631
+
632
+     $("#countchnb").text($(this).val().length);
633
+
634
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
635
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
636
+     $("#textsizeinkb").text(textsizekb);
637
+
638
+     if ($(this).val().length > charcolorthr) {
639
+         $("#char_count").css("color", "#BB2E4B");
640
+     } else {
641
+         $("#char_count").css("color", "#4cbc86;");
642
+     }
643
+
644
+  });
645
+
646
+
647
+  // Check the checkbox to send file(s) as MMS
648
+  $('#mediafilechckbx').change(function() {
649
+
650
+      if ($(this).is(':checked')) {
651
+
652
+          isMMS = 1;
653
+          if (selectedid == '') {
654
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
655
+              $(this).prop("checked", false);
656
+              isMMS = 0;
657
+              return;
658
+          }
659
+          $("#upmediafiles").css("display", "block");
660
+          $("#submitsms").prop("value", "Send MMS");
661
+
662
+      } else {
663
+
664
+          isMMS = 0;
665
+          $("#upmediafiles").css("display", "none");
666
+          $("#submitsms").prop("value", "Send SMS");
667
+
668
+          // Remove the uploaded file(s) if any
669
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
670
+          $(".indgenpckfls").each(function() { $(this).remove(); });
671
+
672
+          uploadedtomms = [];
673
+          n = 1;
674
+
675
+          msgtotalflsize = 0;
676
+
677
+          $("#filestotsize").hide();
678
+      }
679
+  });
680
+
681
+
682
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
683
+  function adjustMaximumSize(uploadedtomms) {
684
+				      
685
+      var nonimgcheck = 0;
686
+      for (var u = 0; u < uploadedtomms.length; u++) {
687
+	   var crupfl = uploadedtomms[u];
688
+	   var extensionup = crupfl.replace(/^.*\./, '');
689
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
690
+	       nonimgcheck = 1;
691
+	   }
692
+      }
693
+
694
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
695
+  }
696
+
697
+  // Upload files to be sent as MMS
698
+  $("#uploadfileformms").change(function(e) {
699
+
700
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
701
+     $('#smstables').addClass('icon-loading');
702
+     $('#filestotsize').show();
703
+
704
+     var userid = "<?php p($userId); ?>";
705
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
706
+
707
+     var formData = new FormData();
708
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
709
+
710
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
711
+
712
+     // Add the size of the current file to the total size of all the files
713
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
714
+
715
+     var fileup = $('#uploadfileformms').val();
716
+     var fileuptrim = fileup.split('\\').pop();
717
+
718
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
719
+         var duplicatescheck = 1;
720
+     } else { 
721
+         var duplicatescheck = 0;
722
+     }
723
+
724
+     var extension = fileup.replace(/^.*\./, '');
725
+
726
+     if (extension == fileup) {
727
+         extension = "";
728
+     } else {
729
+         extension = extension.toLowerCase();
730
+     }
731
+
732
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
733
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
734
+         maximumsize = maxsizenonimage;
735
+     }
736
+
737
+     if ($.inArray(extension, validExtensions) != -1) {
738
+
739
+       if (duplicatescheck == 0) {
740
+
741
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
742
+
743
+            if (n <= maximumfilenumber) {
744
+
745
+               $.ajax({
746
+                 url: baseUrl + '/' + userid,
747
+                 type: "POST",
748
+                 data: formData,
749
+                 cache: false,
750
+                 processData: false,
751
+                 contentType: false,
752
+                 success: function(totalflsize) {
753
+
754
+                   uploadedtomms.push(fileuptrim);
755
+
756
+                   $('#filessizetext').text(totalflsize);
757
+
758
+                   var rectotfilesz = parseFloat(totalflsize);
759
+
760
+                   if (rectotfilesz <= maximumsize) {
761
+                       $('#submitsms').attr("disabled", false);
762
+                       $('#filestotsize').css('color', '#189558');
763
+                   } else {
764
+                       $('#filestotsize').css('color', '#ba3555');
765
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
766
+                       $('#submitsms').attr("disabled", true);
767
+                       $('#smstables').removeClass('icon-loading');
768
+                       $('#pf_upload_msg').hide();
769
+                   }
770
+
771
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
772
+                   n++;
773
+
774
+                   // Preview the file when you click on its name
775
+                   $("div:visible[id*='indfilediv']").each(function() {
776
+
777
+                        $(this).on("click", function(eventclck) {
778
+
779
+                           $("#mmsfoldersview").css("display", "inline-block");
780
+                           var mmsfilenameinit = $(this).text();
781
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
782
+                           var mmsfilename = mmsfilenamesec.replace("X","");
783
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
784
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
785
+
786
+                           if (extenlst == mmsfilename) {
787
+                               extenlst = "";
788
+                           } else {
789
+                               extenlst = extenlst.toLowerCase();
790
+                           }
791
+
792
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
793
+                                  $("#smstables").empty();
794
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
795
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
796
+                           } else if (extenlst == 'png') {
797
+                                  $("#smstables").empty();
798
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
799
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
800
+                           } else if (extenlst == 'gif') {
801
+                                  $("#smstables").empty();
802
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
803
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
804
+                           } else if (extenlst == 'bmp') {
805
+                                  $("#smstables").empty();
806
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
807
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
808
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
809
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
810
+                                  var xhr = new XMLHttpRequest();
811
+                                  xhr.responseType = 'arraybuffer';
812
+                                  xhr.open('GET', tiffile);
813
+                                  xhr.onload = function (evnt) {
814
+                                      var tiff = new Tiff({buffer: xhr.response});
815
+                                      var tifcanvas = tiff.toCanvas();
816
+                                      $("#smstables").empty();
817
+                                      $("#smstables").append(tifcanvas);
818
+                                  };
819
+                                  xhr.send();
820
+                           } else if (extenlst == 'pdf') {
821
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
822
+                                  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>');
823
+                                  $("#smstables").empty();
824
+                                  $("#smstables").append($iframe);
825
+                           } else if (extenlst == 'txt') {
826
+                                  $("#smstables").empty();
827
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
828
+                           } else if (extension == 'mp4') {
829
+                                  $("#smstables").empty();
830
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
831
+		           } else if (extension == 'ogg') {
832
+		                  $("#smstables").empty();
833
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
834
+		           } else if (extension == 'avi') {
835
+		                  $("#smstables").empty();
836
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
837
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
838
+		                  $("#smstables").empty();
839
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
840
+		           } else if (extension == 'wav' || extension == 'wave') {
841
+		                  $("#smstables").empty();
842
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
843
+		           } else if (extension == 'mp3') {
844
+		                  $("#smstables").empty();
845
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
846
+		           } else if (extension == 'midi') {
847
+		                  $("#smstables").empty();
848
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
849
+		           }
850
+
851
+                           $("#smstables").show();
852
+                           $("#mmsfoldersview").hide();
853
+                        });
854
+                   });
855
+
856
+                   // Remove uploaded files
857
+                   $('[class*="indupfldl"]').last().click(function() {
858
+
859
+                           var userid = "<?php p($userId); ?>";
860
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
861
+
862
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
863
+
864
+                           var removedfilesplit = removedfilenameinit.split(") ");
865
+                           var removedflnb = parseInt(removedfilesplit[0]);
866
+
867
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
868
+                           $(this).hide();
869
+
870
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
871
+
872
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
873
+                                           return value != removedfilename;
874
+                           });
875
+
876
+                           $.ajax({
877
+                                   url: baseUrl + '/' + userid,
878
+                                   type: "POST",
879
+                                   data: {removedfilename: removedfilename},
880
+                                   success: function(totalflsize) {
881
+
882
+                                      msgtotalflsize = totalflsize;
883
+                                      $('#filessizetext').text(totalflsize);
884
+
885
+                                      adjustMaximumSize(uploadedtomms);
886
+
887
+                                      // Check message size
888
+                                      var rectotfilesz = parseFloat(totalflsize);
889
+
890
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
891
+                                          $('#submitsms').attr("disabled", false);
892
+                                          $('#filestotsize').css('color', '#189558');
893
+                                      } else {
894
+                                          $('#filestotsize').css('color', '#ba3555');
895
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
896
+                                          $('#submitsms').attr("disabled", true);
897
+                                      }
898
+
899
+                                      // Rewrite order numbers for files that follow
900
+                                      --n;
901
+                                      $("div:visible[id*='indfilediv']").each(function() {
902
+
903
+                                          var getdivtext =  $(this).text();
904
+                                          var splitdivtext = getdivtext.split(") ");
905
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
906
+                                          var newnbvalue = currentnbvalue - 1;
907
+
908
+                                          if (currentnbvalue > removedflnb) {
909
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
910
+                                              $(this).text(replacedstr);
911
+                                          }
912
+                                      });
913
+
914
+                                      $("div:visible[id*='indflpicked']").each(function() {
915
+
916
+                                          var getdivtext =  $(this).text();
917
+                                          var splitdivtext = getdivtext.split(") ");
918
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
+                                          var newnbvalue = currentnbvalue - 1;
920
+
921
+                                          if (currentnbvalue > removedflnb) {
922
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
+                                              $(this).text(replacedstr);
924
+                                          }
925
+                                      });
926
+
927
+                                   },
928
+                                   error: function() {
929
+                                              showAlert("Error while removing the file(s).");
930
+                                   }
931
+                           });
932
+
933
+                           $('#smstables').removeClass('icon-loading');
934
+                           $("#smstables").empty();
935
+                   });
936
+
937
+                   // Preview the uploaded file
938
+                   $("#mmsfoldersview").css("display", "inline-block");
939
+                   var mmsfilename = e.target.files[0].name;
940
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
941
+
942
+
943
+                   if (extension == 'jpg' || extension == 'jpeg') {
944
+                              $("#smstables").empty();
945
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
946
+
947
+                              var reader = new FileReader();
948
+                              reader.onload = function (e) {
949
+                                  readjpg[mmsfilename] = e.target.result;
950
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
951
+                              }
952
+                              reader.readAsDataURL(e.target.files[0]);
953
+                   } else if (extension == 'png') {
954
+                              $("#smstables").empty();
955
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
956
+
957
+                              var reader = new FileReader();
958
+                              reader.onload = function (e) {
959
+                                  readpng[mmsfilename] = e.target.result;
960
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
961
+                              }
962
+                              reader.readAsDataURL(e.target.files[0]);
963
+
964
+                   } else if (extension == 'gif') {
965
+                              $("#smstables").empty();
966
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
967
+
968
+                              var reader = new FileReader();
969
+                              reader.onload = function (e) {
970
+                                  readgif[mmsfilename] = e.target.result;
971
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
972
+                              }
973
+                              reader.readAsDataURL(e.target.files[0]);
974
+
975
+                   } else if (extension == 'bmp') {
976
+                              $("#smstables").empty();
977
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
978
+
979
+                              var reader = new FileReader();
980
+                              reader.onload = function (e) {
981
+                                  readbmp[mmsfilename] = e.target.result;
982
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
983
+                              }
984
+                              reader.readAsDataURL(e.target.files[0]);
985
+
986
+                   } else if (extension == 'tif' || extension == 'tiff') {
987
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
988
+                              var xhr = new XMLHttpRequest();
989
+                              xhr.responseType = 'arraybuffer';
990
+                              xhr.open('GET', tiffile);
991
+                              xhr.onload = function (e) {
992
+                                  var tiff = new Tiff({buffer: xhr.response});
993
+                                  var tifcanvas = tiff.toCanvas();
994
+                                  $("#smstables").empty();
995
+                                  $("#smstables").append(tifcanvas);
996
+                              };
997
+                              xhr.send();
998
+
999
+                   } else if (extension == 'pdf') {
1000
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1001
+                              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>');
1002
+                              $("#smstables").empty();
1003
+                              $("#smstables").append($iframe);
1004
+
1005
+                   } else if (extension == 'txt') {
1006
+                              var reader = new FileReader();
1007
+                              reader.readAsText(e.target.files[0]);
1008
+                              reader.onload = function(e) {
1009
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1010
+                                  $("#smstables").empty();
1011
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1012
+                              };
1013
+                   } else if (extension == 'mp4') {
1014
+                              $("#smstables").empty();
1015
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1016
+                   } else if (extension == 'ogg') {
1017
+                              $("#smstables").empty();
1018
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1019
+                   } else if (extension == 'avi') {
1020
+                              $("#smstables").empty();
1021
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1022
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1023
+                              $("#smstables").empty();
1024
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1025
+                   } else if (extension == 'wav' || extension == 'wave') {
1026
+                              $("#smstables").empty();
1027
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1028
+                   } else if (extension == 'mp3') {
1029
+                              $("#smstables").empty();
1030
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1031
+                   } else if (extension == 'midi') {
1032
+                              $("#smstables").empty();
1033
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1034
+                   }
1035
+
1036
+                   $("#smstables").show();
1037
+                   $('#pf_upload_msg').hide();
1038
+                   $('#smstables').removeClass('icon-loading');
1039
+                   $("#mmsfoldersview").hide();
1040
+                 },
1041
+                 error: function() {
1042
+                              showAlert("Error while uploading the file.");
1043
+                 }
1044
+               });
1045
+
1046
+            } else {
1047
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1048
+                  adjustMaximumSize(uploadedtomms);
1049
+
1050
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1051
+                  $('#pf_upload_msg').hide();
1052
+                  $('#smstables').removeClass('icon-loading');
1053
+            }
1054
+         } else {
1055
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1056
+              adjustMaximumSize(uploadedtomms);
1057
+
1058
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1059
+              $('#pf_upload_msg').hide();
1060
+              $('#smstables').removeClass('icon-loading');
1061
+         }
1062
+       } else {
1063
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1064
+            adjustMaximumSize(uploadedtomms);
1065
+
1066
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1067
+            $('#pf_upload_msg').hide();
1068
+            $('#smstables').removeClass('icon-loading');
1069
+       }
1070
+
1071
+     } else {
1072
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1073
+          adjustMaximumSize(uploadedtomms);
1074
+
1075
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1076
+          $('#pf_upload_msg').hide();
1077
+          $('#smstables').removeClass('icon-loading');
1078
+     }
1079
+  });
1080
+
1081
+
1082
+  // Pick file(s) from Nextcloud, to send as MMS
1083
+  var mmsfilename = null;
1084
+
1085
+  $("#choosefilen").on("click", function(evn) {
1086
+
1087
+                OC.dialogs.filepicker(
1088
+                        t('settings', "Select a file to send as MMS."),
1089
+                        function (path) {
1090
+
1091
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1092
+                              $('#smstables').addClass('icon-loading');
1093
+                              $('#filestotsize').show();
1094
+
1095
+                              var userid = "<?php p($userId); ?>";
1096
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1097
+
1098
+                              mmsfilename = path.split('/').pop();
1099
+
1100
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1101
+                                  var duplicatescheck = 1;
1102
+                              } else var duplicatescheck = 0;
1103
+
1104
+                              var extension = mmsfilename.replace(/^.*\./, '');
1105
+
1106
+                              if (extension == mmsfilename) {
1107
+                                  extension = "";
1108
+                              } else {
1109
+                                  extension = extension.toLowerCase();
1110
+                              }
1111
+
1112
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1113
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1114
+				   maximumsize = maxsizenonimage;
1115
+			      }
1116
+
1117
+                              if ($.inArray(extension, validExtensions) != -1) {
1118
+
1119
+                                 if (duplicatescheck == 0) {
1120
+
1121
+                                    if (n <= maximumfilenumber) {
1122
+
1123
+                                       $.ajax({
1124
+                                          url: baseUrl + '/' + userid,
1125
+                                          type: "POST",
1126
+                                          data: { path: path },
1127
+                                          success: function(pickresult) {
1128
+
1129
+                                                uploadedtomms.push(mmsfilename);
1130
+
1131
+                                                var totalflsize = pickresult[0];
1132
+                                                var pickedflsize = pickresult[1];
1133
+
1134
+                                                // Check message size
1135
+                                                var rectotfilesz = parseFloat(totalflsize);
1136
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1137
+
1138
+                                                if (filesplustextsize <= maximumsize) {
1139
+
1140
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1141
+
1142
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1143
+                                                    n++;
1144
+
1145
+                                                    msgtotalflsize = totalflsize;
1146
+                                                    $('#filessizetext').text(totalflsize);
1147
+                                                    $('#filestotsize').css('color', '#189558');
1148
+
1149
+                                                } else {
1150
+
1151
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1152
+                                                    $('#filestotsize').css('color', '#ba3555');
1153
+                                                    msgtotalflsize -= pickedflsize;
1154
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1155
+
1156
+                                                    $.ajax({
1157
+                                                        url: baseUrlindrm + '/' + userid,
1158
+                                                        type: "POST",
1159
+                                                        data: {removedfilename: mmsfilename},
1160
+                                                        success: function(totalflsize) {
1161
+
1162
+                                                                          $('#filessizetext').text(totalflsize);
1163
+                                                                          $('#filestotsize').css('color', '#189558');
1164
+                                                                          adjustMaximumSize(uploadedtomms);
1165
+
1166
+                                                        },
1167
+                                                        error: function(totalflsize) {
1168
+                                                                          $('#filessizetext').text(totalflsize);
1169
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1170
+                                                                              $('#filestotsize').css('color', '#ba3555');
1171
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1172
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1173
+                                                        }
1174
+                                                    });
1175
+
1176
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1177
+                                                }
1178
+
1179
+
1180
+                                                // Preview each file when you click on its name
1181
+                                                $("div:visible[id*='indflpicked']").each(function() {
1182
+                                                   $(this).on("click", function(event) {
1183
+
1184
+                                                      var mmsfilenameinit = $(this).text();
1185
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1186
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1187
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1188
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1189
+
1190
+                                                      if (extenlst == mmsfilenamesp) {
1191
+                                                           extenlst = "";
1192
+                                                      } else {
1193
+                                                           extenlst = extenlst.toLowerCase();
1194
+                                                      }
1195
+
1196
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1197
+                                                              $("#smstables").empty();
1198
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1199
+                                                      } else if (extenlst == 'png') {
1200
+                                                              $("#smstables").empty();
1201
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1202
+                                                      } else if (extenlst == 'gif') {
1203
+                                                              $("#smstables").empty();
1204
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1205
+                                                      } else if (extenlst == 'bmp') {
1206
+                                                              $("#smstables").empty();
1207
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1208
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1209
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1210
+                                                              var xhr = new XMLHttpRequest();
1211
+                                                              xhr.responseType = 'arraybuffer';
1212
+                                                              xhr.open('GET', tiffile);
1213
+                                                              xhr.onload = function (evnt) {
1214
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1215
+                                                                  var tifcanvas = tiff.toCanvas();
1216
+                                                                  $("#smstables").empty();
1217
+                                                                  $("#smstables").append(tifcanvas);
1218
+                                                              };
1219
+                                                              xhr.send();
1220
+                                                      } else if (extenlst == 'pdf') {
1221
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1222
+                                                              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>');
1223
+                                                              $("#smstables").empty();
1224
+                                                              $("#smstables").append($iframe);
1225
+                                                      } else if (extenlst == 'txt') {
1226
+                                                              $("#smstables").empty();
1227
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1228
+                                                      } else if (extension == 'mp4') {
1229
+							      $("#smstables").empty();
1230
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1231
+						      } else if (extension == 'ogg') {
1232
+							      $("#smstables").empty();
1233
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1234
+						      } else if (extension == 'avi') {
1235
+							      $("#smstables").empty();
1236
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1237
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1238
+							      $("#smstables").empty();
1239
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1240
+						      } else if (extension == 'wav' || extension == 'wave') {
1241
+							      $("#smstables").empty();
1242
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1243
+						      } else if (extension == 'mp3') {
1244
+							      $("#smstables").empty();
1245
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1246
+						      } else if (extension == 'midi') {
1247
+							      $("#smstables").empty();
1248
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1249
+						      }
1250
+
1251
+
1252
+                                                      $("#smstables").show();
1253
+                                                      $("#mmsfoldersview").hide();
1254
+                                                   });
1255
+                                                });
1256
+
1257
+
1258
+                                                // Remove picked files
1259
+                                                $('[class*="indpckfldl"]').last().click(function() {
1260
+                                                    var userid = "<?php p($userId); ?>";
1261
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1262
+
1263
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1264
+
1265
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1266
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1267
+
1268
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1269
+                                                    $(this).hide();
1270
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1271
+
1272
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1273
+                                                             return value != removedfilename;
1274
+                                                    });
1275
+
1276
+                                                    $.ajax({
1277
+                                                        url: baseUrl + '/' + userid,
1278
+                                                        type: "POST",
1279
+                                                        data: {removedfilename: removedfilename},
1280
+                                                        success: function(totalflsize) {
1281
+
1282
+                                                             msgtotalflsize = totalflsize;
1283
+                                                             $('#filessizetext').text(totalflsize);
1284
+                                                             adjustMaximumSize(uploadedtomms);
1285
+
1286
+                                                             // Check message size
1287
+                                                             var rectotfilesz = parseFloat(totalflsize);
1288
+
1289
+                                                             if (rectotfilesz > maximumsize) {
1290
+                                                                 $('#filestotsize').css('color', '#ba3555');
1291
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1292
+                                                                 $('#submitsms').attr("disabled", true);
1293
+                                                             } else {
1294
+                                                                 $('#submitsms').attr("disabled", false);
1295
+                                                                 $('#filestotsize').css('color', '#189558');
1296
+                                                               }
1297
+
1298
+                                                             // Rewrite order numbers for files that follow
1299
+                                                             --n;
1300
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1301
+
1302
+                                                                  var getdivtext =  $(this).text();
1303
+                                                                  var splitdivtext = getdivtext.split(") ");
1304
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1305
+                                                                  var newnbvalue = currentnbvalue - 1;
1306
+
1307
+                                                                  if (currentnbvalue > removedflnb) {
1308
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1309
+                                                                      $(this).text(replacedstr);
1310
+                                                                  }
1311
+                                                             });
1312
+                                                        },
1313
+                                                        error: function() {
1314
+                                                                  showAlert("Error while removing the file.");
1315
+                                                        }
1316
+                                                    });
1317
+
1318
+                                                    $('#smstables').removeClass('icon-loading');
1319
+                                                    $("#smstables").empty();
1320
+                                                });
1321
+
1322
+
1323
+		                                // Preview the picked file
1324
+		                                $("#mmsfoldersview").css("display", "inline-block");
1325
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1326
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1327
+
1328
+
1329
+						if (extension == 'jpg' || extension == 'jpeg') {
1330
+
1331
+		                                            $("#smstables").empty();
1332
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1333
+
1334
+		                                } else if (extension == 'png') {
1335
+
1336
+		                                            $("#smstables").empty();
1337
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1338
+
1339
+		                                } else if (extension == 'gif') {
1340
+
1341
+		                                            $("#smstables").empty();
1342
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1343
+
1344
+		                                } else if (extension == 'bmp') {
1345
+
1346
+	                                                    $("#smstables").empty();
1347
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1348
+
1349
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1350
+
1351
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1352
+		                                       var xhr = new XMLHttpRequest();
1353
+		                                       xhr.responseType = 'arraybuffer';
1354
+		                                       xhr.open('GET', tiffile);
1355
+		                                       xhr.onload = function (event) {
1356
+		                                           var tiff = new Tiff({buffer: xhr.response});
1357
+		                                           var tifcanvas = tiff.toCanvas();
1358
+		                                           $("#smstables").empty();
1359
+		                                           $("#smstables").append(tifcanvas);
1360
+		                                       };
1361
+		                                       xhr.send();
1362
+
1363
+		                                } else if (extension == 'pdf') {
1364
+
1365
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1366
+		                                       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>');
1367
+		                                       $("#smstables").empty();
1368
+		                                       $("#smstables").append($iframe);
1369
+
1370
+		                                } else if (extension == 'txt') {
1371
+
1372
+							     $.get(flUrl, function(textdata) {
1373
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1374
+		                                               $("#smstables").empty();
1375
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1376
+							     });
1377
+
1378
+		                                } else if (extension == 'mp4') {
1379
+						       $("#smstables").empty();
1380
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1381
+						} else if (extension == 'ogg') {
1382
+						       $("#smstables").empty();
1383
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1384
+						} else if (extension == 'avi') {
1385
+						       $("#smstables").empty();
1386
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1387
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1388
+						       $("#smstables").empty();
1389
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1390
+						} else if (extension == 'wav' || extension == 'wave') {
1391
+						       $("#smstables").empty();
1392
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1393
+						} else if (extension == 'mp3') {
1394
+						       $("#smstables").empty();
1395
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1396
+						} else if (extension == 'midi') {
1397
+						       $("#smstables").empty();
1398
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1399
+						}
1400
+
1401
+
1402
+		                                $("#smstables").show();
1403
+
1404
+		                                $('#pf_choose_msg').hide();
1405
+		                                $('#smstables').removeClass('icon-loading');
1406
+		                                $("#mmsfoldersview").hide();
1407
+
1408
+                                          },
1409
+
1410
+                                          error: function(data){
1411
+                                                      showAlert("Error while getting the file.");
1412
+                                          }
1413
+
1414
+                                       });
1415
+
1416
+                                    } else {
1417
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1418
+                                        $('#pf_choose_msg').hide();
1419
+                                        $('#smstables').removeClass('icon-loading');
1420
+                                      }
1421
+                                 } else {
1422
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1423
+                                      $('#pf_choose_msg').hide();
1424
+                                      $('#smstables').removeClass('icon-loading');
1425
+                                   }
1426
+
1427
+                              } else {
1428
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1429
+                                   $('#pf_choose_msg').hide();
1430
+                                   $('#smstables').removeClass('icon-loading');
1431
+                                }
1432
+
1433
+                        }
1434
+                );
1435
+  });
1436
+
1437
+
1438
+
1439
+  // Send the SMS/MMS message
1440
+  $("#submitsms").on("click", function(event) {
1441
+
1442
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1443
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1444
+     $("#sms_submit_msg").css("display", "inline-block");
1445
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1446
+
1447
+     if (selectedid != '') { 
1448
+
1449
+         var sendersplit = selectedid.split(":");
1450
+         var providercap = sendersplit[0];
1451
+         var provsec = sendersplit[1];
1452
+
1453
+         if (/[a-zA-Z]/.test(provsec)) {
1454
+             var alphanumcheck = true;
1455
+         } else { var alphanumcheck = false; }
1456
+
1457
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1458
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1459
+             var selectedsender = "+" + senderproc;
1460
+             var providerUsed = "telnyx";
1461
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1462
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1463
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1464
+             var providerUsed = "plivo";
1465
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1466
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1467
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1468
+             var selectedsender = "+" + senderproc;
1469
+             var providerUsed = "twilio";
1470
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1471
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1472
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1473
+             var selectedsender = "+" + senderproc;
1474
+             var providerUsed = "flowroute";
1475
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1476
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1477
+             var selectedsender = provsec;
1478
+             var providerUsed = "telnyx";
1479
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1480
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1481
+             var selectedsender = provsec;
1482
+             var providerUsed = "plivo";
1483
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1484
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1485
+             var selectedsender = provsec;
1486
+             var providerUsed = "twilio";
1487
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1488
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1489
+             var selectedsender = provsec;
1490
+             var providerUsed = "flowroute";
1491
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1492
+         }
1493
+
1494
+         // Get the interval between message consecutive sending requests, if it's the case
1495
+         if ($('#tomultchckbx').is(':checked')) {
1496
+
1497
+             var numbersfile = 1;
1498
+             var initinterval = $("#multsmsinterval").val();
1499
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1500
+
1501
+             if (secinterval != '') {
1502
+                 var tertinterval = parseInt(secinterval);
1503
+                     waittime = tertinterval;
1504
+             }
1505
+
1506
+         } else {
1507
+
1508
+             var numbersfile = 0;
1509
+             var toNumberinit = $('#smsto').val();
1510
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1511
+             var toNumbersec = toNumber.split(",");
1512
+
1513
+                 for (var i = 0; i < toNumbersec.length; i++) {
1514
+                      toNumbersec[i] = "+" + toNumbersec[i];
1515
+                 }
1516
+
1517
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1518
+         }
1519
+
1520
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1521
+
1522
+         var smstext = $("#smstext").val();
1523
+
1524
+         if (receiversNumbers.length != 0) {
1525
+
1526
+              if (smstext != '') {
1527
+                  $.ajax({
1528
+                     url: relbaseUrl + '/' + userid,
1529
+                     type: "POST",
1530
+                     data: {
1531
+                           receiversPhoneNbs: receiversNumbers,
1532
+                           fromsender: selectedsender,
1533
+                           waitinterval: waittime,
1534
+                           sentsmstext: smstext,
1535
+                           ismms: isMMS,
1536
+                           mmsfiles: uploadedtomms
1537
+                         },
1538
+                     success: function() {
1539
+
1540
+                           if (receiversNumbers.length == 1) {
1541
+                                   showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1542
+                           } else {
1543
+                                   showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1544
+                           }
1545
+
1546
+                           $('#sms_submit_msg').hide();
1547
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1548
+                     },
1549
+                     error: function() {
1550
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1551
+                           $('#sms_submit_msg').hide();
1552
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1553
+                     }
1554
+                  });
1555
+              } else {
1556
+                     showAlert("Please enter a message in the text box !");
1557
+
1558
+                     $('#sms_submit_msg').hide();
1559
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1560
+              }
1561
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1562
+                 showAlert("Please enter the recipient's phone number !");
1563
+                 $('#sms_submit_msg').hide();
1564
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1565
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1566
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1567
+                 $('#sms_submit_msg').hide();
1568
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1569
+         }
1570
+     } else {
1571
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1572
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1573
+           $('#sms_submit_msg').hide();
1574
+     }
1575
+
1576
+  });
1577
+
1578
+  // Check the checkbox to delete old messages from the database
1579
+  $('#deleteoldchckbox').change(function() {
1580
+     if ($(this).is(':checked')) {
1581
+         $("#deleteoldsms").css("display", "block");
1582
+     } else {
1583
+         $("#deleteoldsms").css("display", "none");
1584
+     }
1585
+  });
1586
+
1587
+  // Set the height of info notes
1588
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1589
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1590
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1591
+
1592
+  $(window).resize(function() { 
1593
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1594
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1595
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1596
+  });
1597
+
1598
+
1599
+  function showAlert(alertText) {
1600
+
1601
+     let alertwnd = "<div id='alertMessage'>";
1602
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1603
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1604
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1605
+     alertwnd += "</div>";
1606
+
1607
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1608
+     $("#content").append(alertwnd);
1609
+
1610
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1611
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1612
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1613
+
1614
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1615
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1616
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1617
+  }
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css img/closewnd.svg ...

DoubleBastionAdmin authored on 23/05/2023 18:50:19
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1652 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-
58
-  // Get the available phone numbers associated with the API keys saved on the Settings page
59
-  $("#smsnumbersdiv").addClass('icon-loading');
60
-
61
-  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
-
63
-  $.ajax({
64
-          url: getsmsnumbersUrl + '/' + userid,
65
-          type: "POST",
66
-          data: { userid: userid },
67
-          cache: false,
68
-          processData: false,
69
-          contentType: false,
70
-          success: function(currentnmbrs) {
71
-
72
-                     $('#currentsmsnmbrs').empty();
73
-
74
-                     if (currentnmbrs.length > 1) {
75
-
76
-                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
-
78
-                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
-                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
-                         });
81
-
82
-                         // Append the available providers to the 'see balance' drop-down list
83
-                         var providerNm = [];
84
-                         for (var n = 0; n < currentnmbrs.length; n++) {
85
-
86
-                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
-                              if (provfirstchr == "Tx") {
88
-                                  if (providerNm.indexOf("Telnyx") === -1) {
89
-                                      providerNm.push("Telnyx");
90
-                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
-                                  }
92
-                              } else if (provfirstchr == "Pl") {
93
-                                  if (providerNm.indexOf("Plivo") === -1) {
94
-                                      providerNm.push("Plivo");
95
-                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
-                                  }
97
-                              } else if (provfirstchr == "Tw") {
98
-                                  if (providerNm.indexOf("Twilio") === -1) {
99
-                                      providerNm.push("Twilio");
100
-                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
-                                  }
102
-                              } else if (provfirstchr == "Fl") {
103
-                                  if (providerNm.indexOf("Flowroute") === -1) {
104
-                                      providerNm.push("Flowroute");
105
-                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
-                                  }
107
-                              }
108
-                         }
109
-
110
-//                         for (var b = 0; b < providerNm.length; b++) {
111
-//                              $("#smsprovider").append("<option value='"+ providerNm[b] +"' class='selectsmsprov'>"+ providerNm[b] +"</option>");
112
-//                         }
113
-
114
-                     } else if (currentnmbrs.length == 1) {
115
-
116
-                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
117
-
118
-                                selectedid = currentnmbrs[0];
119
-
120
-                                var unqprovider = currentnmbrs[0].split(": ")[0];
121
-
122
-                                if (unqprovider == 'Tx') {
123
-
124
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
125
-					  // Maximum size of message text + files in KB
126
-					  maximumsize = 1024;
127
-					  maximumsizeinit = 1024;
128
-					  maxsizenonimage = 600;
129
-					  maximumfilenumber = 10;
130
-					  chosenProvFullName = "Telnyx";
131
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
132
-						             or gif files, the size of all the files plus the size of the text should be \
133
-						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
134
-						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
135
-						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
136
-						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
137
-						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
138
-						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
139
-						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
140
-						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
141
-						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
142
-					  $("#tooltiptextfourth").html(infonotecontent);
143
-
144
-                                          // Append 'Telnyx' to the 'see balance' drop-down list
145
-                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
146
-
147
-                                } else if (unqprovider == 'Pl') {
148
-
149
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
150
-						             "icalendar", "csv", "txt", "pdf", "xls"];
151
-					  // Maximum size of message text + files in KB
152
-					  maximumsize = 5120;
153
-					  maximumsizeinit = 5120;
154
-					  maxsizenonimage = 600;
155
-					  maximumfilenumber = 10;
156
-					  chosenProvFullName = "Plivo";
157
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
158
-						             or gif files, the size of all the files plus the size of the text should be \
159
-						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
160
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
161
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
162
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
163
-						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
164
-						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
165
-						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
166
-						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
167
-						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
168
-					  $("#tooltiptextfourth").html(infonotecontent);
169
-
170
-                                          // Append 'Plivo' to the 'see balance' drop-down list
171
-                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
172
-
173
-                                } else if (unqprovider == 'Tw') {
174
-
175
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
176
-						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
177
-						             "icalendar", "directory", "pdf", "pkpass"];
178
-					  // Maximum size of message text + files in KB
179
-					  maximumsize = 5120;
180
-					  maximumsizeinit = 5120;
181
-					  maxsizenonimage = 600;
182
-					  maximumfilenumber = 10;
183
-					  chosenProvFullName = "Twilio";
184
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
185
-						             or gif files, the size of all the files plus the size of the text should be \
186
-						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
187
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
188
-						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
189
-						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
190
-						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
191
-						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
192
-						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
193
-						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
194
-						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
195
-						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
196
-						             previewed in the adjoining pane."
197
-					  $("#tooltiptextfourth").html(infonotecontent);
198
-
199
-                                          // Append 'Twilio' to the 'see balance' drop-down list
200
-                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
201
-
202
-                                } else if (unqprovider == 'Fl') {
203
-
204
-					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
205
-					  // Maximum size of message text + files in KB
206
-					  maximumsize = 750;
207
-					  maximumsizeinit = 750;
208
-					  maxsizenonimage = 600;
209
-					  maximumfilenumber = 10;
210
-					  chosenProvFullName = "Flowroute";
211
-					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
212
-							     png or gif files, the size of all the files plus the size of the text should be \
213
-							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
214
-							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
215
-							     size of the files plus the size of the text should be 600 KB or less. \
216
-							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
217
-							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
218
-							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
219
-							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
220
-							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
221
-							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
222
-							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
223
-							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
224
-					  $("#tooltiptextfourth").html(infonotecontent);
225
-
226
-                                          // Append 'Flowroute' to the 'see balance' drop-down list
227
-                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
228
-                                }
229
-                     } else {
230
-                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
231
-                     }
232
-
233
-                     $("#smsnumbersdiv").removeClass('icon-loading');
234
-          }
235
-  });
236
-     //  });
237
-
238
-
239
-  // Clean the SMS_Relentless/temp_files directory
240
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
241
-
242
-  $.ajax({
243
-          url: cleanflUrl + '/' + userid,
244
-          type: "POST",
245
-          data: { userid: userid },
246
-          cache: false,
247
-          processData: false,
248
-          contentType: false
249
-  });
250
-  
251
-  // Check the available balance
252
-  $("#smsprovider").on("change", function () {
253
-
254
-     var provider = $('#smsprovider :selected').val();
255
-
256
-     if (provider == "Telnyx") {
257
-
258
-        var gettelbalance = function() {
259
-
260
-          $('#currentbalance').addClass('icon-loading');
261
-
262
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
263
-
264
-          $.ajax({
265
-              url: gettelbalanceUrl + '/' + userid,
266
-              type: "POST",
267
-              data: { userid: userid },
268
-              cache: false,
269
-              processData: false,
270
-              contentType: false,
271
-              success: function(currentbalancetel) {
272
-
273
-                     $('#currentbalance').empty();
274
-                     $('#currentbalance').text(currentbalancetel);
275
-                     $('#currentbalance').removeClass('icon-loading');
276
-              }
277
-          });
278
-        }
279
-
280
-        gettelbalance();
281
-
282
-     } else if (provider == "Plivo") {
283
-
284
-          var getnexbalance = function() {
285
-
286
-            $('#currentbalance').addClass('icon-loading');
287
-
288
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
289
-
290
-            $.ajax({
291
-                url: getnexbalanceUrl + '/' + userid,
292
-                type: "POST",
293
-                data: { userid: userid },
294
-                cache: false,
295
-                processData: false,
296
-                contentType: false,
297
-                success: function(currentbalancenex) {
298
-
299
-                     $('#currentbalance').empty();
300
-                     $('#currentbalance').text(currentbalancenex);
301
-                     $('#currentbalance').removeClass('icon-loading');
302
-                }
303
-            });
304
-          }
305
-
306
-          getnexbalance();
307
-
308
-     } else if (provider == "Twilio") {
309
-
310
-          var gettwilbalance = function() {
311
-
312
-            $('#currentbalance').addClass('icon-loading');
313
-
314
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
315
-
316
-            $.ajax({
317
-                url: gettwilbalanceUrl + '/' + userid,
318
-                type: "POST",
319
-                data: { userid: userid },
320
-                cache: false,
321
-                processData: false,
322
-                contentType: false,
323
-                success: function(currentbalancetwil) {
324
-
325
-                     $('#currentbalance').empty();
326
-                     $('#currentbalance').text(currentbalancetwil);
327
-                     $('#currentbalance').removeClass('icon-loading');
328
-                }
329
-            });
330
-          }
331
-
332
-          gettwilbalance();
333
-
334
-     } else if (provider == "Flowroute") {
335
-
336
-          var getflowbalance = function() {
337
-
338
-            $('#currentbalance').addClass('icon-loading');
339
-
340
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
341
-
342
-            $.ajax({
343
-                url: getflowbalanceUrl + '/' + userid,
344
-                type: "POST",
345
-                data: { userid: userid },
346
-                cache: false,
347
-                processData: false,
348
-                contentType: false,
349
-                success: function(currentbalanceflow) {
350
-
351
-                     $('#currentbalance').empty();
352
-                     $('#currentbalance').text(currentbalanceflow);
353
-                     $('#currentbalance').removeClass('icon-loading');
354
-                }
355
-            });
356
-          }
357
-
358
-          getflowbalance();
359
-
360
-       } else if (provider == "") {
361
-                $('#currentbalance').text("");
362
-                $('#currentbalance').removeClass('icon-loading');
363
-       }
364
-  });
365
-
366
-
367
-  // If a Sender ID is selected
368
-  $("#currentsmsnmbrs").on("change", function () {
369
-
370
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
371
-
372
-              selectedid = $('#currentsmsnmbrs :selected').val();
373
-              var setIdsplit = selectedid.split(":");
374
-	      chosenProvider = setIdsplit[0];
375
-
376
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
377
-	      if (chosenProvider == "Tx") {
378
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
379
-		  // Maximum size of message text + files in KB
380
-		  maximumsize = 1024;
381
-                  maximumsizeinit = 1024;
382
-		  maxsizenonimage = 600;
383
-		  maximumfilenumber = 10;
384
-                  chosenProvFullName = "Telnyx";
385
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
386
-                                     or gif files, the size of all the files plus the size of the text should be \
387
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
388
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
389
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
390
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
391
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
392
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
393
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
394
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
395
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
396
-                  $("#tooltiptextfourth").html(infonotecontent);
397
-	      } else if (chosenProvider == "Pl") {
398
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
399
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
400
-		  // Maximum size of message text + files in KB
401
-		  maximumsize = 5120;
402
-                  maximumsizeinit = 5120;
403
-		  maxsizenonimage = 600;
404
-		  maximumfilenumber = 10;
405
-                  chosenProvFullName = "Plivo";
406
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
407
-                                     or gif files, the size of all the files plus the size of the text should be \
408
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
409
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
410
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
411
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
412
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
413
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
414
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
415
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
416
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
417
-                  $("#tooltiptextfourth").html(infonotecontent);
418
-	      } else if (chosenProvider == "Tw") {
419
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
420
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
421
-                                     "icalendar", "directory", "pdf", "pkpass"];
422
-		  // Maximum size of message text + files in KB
423
-		  maximumsize = 5120;
424
-                  maximumsizeinit = 5120;
425
-		  maxsizenonimage = 600;
426
-		  maximumfilenumber = 10;
427
-                  chosenProvFullName = "Twilio";
428
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
429
-                                     or gif files, the size of all the files plus the size of the text should be \
430
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
431
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
432
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
433
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
434
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
435
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
436
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
437
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
438
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
439
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
440
-                                     previewed in the adjoining pane."
441
-                  $("#tooltiptextfourth").html(infonotecontent);
442
-	      } else if (chosenProvider == "Fl") {
443
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
444
-		  // Maximum size of message text + files in KB
445
-		  maximumsize = 750;
446
-                  maximumsizeinit = 750;
447
-		  maxsizenonimage = 600;
448
-		  maximumfilenumber = 10;
449
-                  chosenProvFullName = "Flowroute";
450
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
451
-                                     png or gif files, the size of all the files plus the size of the text should be \
452
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
453
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
454
-                                     size of the files plus the size of the text should be 600 KB or less. \
455
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
456
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
457
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
458
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
459
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
460
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
461
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
462
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
463
-                  $("#tooltiptextfourth").html(infonotecontent);
464
-	      }
465
-
466
-          } else { selectedid = ''; }
467
-  });
468
-
469
-  // Check the checkbox to send SMS message to multiple recipients
470
-  $('#tomultchckbx').change(function() {
471
-      if ($(this).is(':checked')) {
472
-          $("#multiplerecivers").css("display", "block");
473
-          $("#smstodiv").css("visibility", "hidden");
474
-          $("#smsto").val("");
475
-
476
-          receiversNumbers.length = 0;
477
-
478
-      } else {
479
-          $("#multiplerecivers").css("display", "none");
480
-          $("#smstodiv").css("visibility", "visible");
481
-
482
-          // Remove the uploaded file(s) if any
483
-          $("#induploadfile").remove();
484
-
485
-          receiversNumbers.length = 0;
486
-      }
487
-  });
488
-
489
-  // Upload the file with the recipients' phone numbers
490
-  $("#uploadfileforsms").change(function(e) {
491
-
492
-     $("#fileuploadednm").empty();
493
-
494
-     receiversNumbers.length = 0;
495
-
496
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
497
-
498
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
499
-
500
-     var formData = new FormData();
501
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
502
-
503
-     var fileup = $('#uploadfileforsms').val();
504
-     var fileuptrim = fileup.split('\\').pop();
505
-
506
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
507
-
508
-     var extension = fileup.replace(/^.*\./, '');
509
-
510
-     if (extension == fileup) {
511
-         extension = "";
512
-     } else {
513
-         extension = extension.toLowerCase();
514
-     }
515
-
516
-     var validExtensionsmrec = ["txt", "csv"];
517
-
518
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
519
-
520
-       if (selectedid != '') {
521
-
522
-               $.ajax({
523
-                 url: baseUrl + '/' + userid,
524
-                 type: "POST",
525
-                 data: formData,
526
-                 cache: false,
527
-                 processData: false,
528
-                 contentType: false,
529
-                 success: function(numberarray) {
530
-
531
-		    if (numberarray.length > 0) {
532
-
533
-		        // Get the array of the receivers' phone numbers
534
-		        if (chosenProvider == "Tx") {
535
-
536
-		             for(key in numberarray) {
537
-		                 receiversNumbers.push("+"+numberarray[key]);
538
-		             }
539
-
540
-		        } else if (chosenProvider == "Pl") {
541
-
542
-		             for(key in numberarray) {
543
-		                 receiversNumbers.push(numberarray[key]);
544
-		             }
545
-
546
-		          } else if (chosenProvider == "Tw") {
547
-
548
-		             for(key in numberarray) {
549
-		                 receiversNumbers.push(numberarray[key]);
550
-		             }
551
-		          } else if (chosenProvider == "Fl") {
552
-
553
-		             for(key in numberarray) {
554
-		                 receiversNumbers.push(numberarray[key]);
555
-		             }
556
-		          }
557
-
558
-		    } else {
559
-//		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
560
-                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
561
-		    }
562
-                            
563
-                    // Preview the uploaded file
564
-                    var smsfilename = e.target.files[0].name;
565
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
566
-
567
-                    var reader = new FileReader();
568
-                    reader.readAsText(e.target.files[0]);
569
-                    reader.onload = function(e) {
570
-                          $("#smstables").empty();
571
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
572
-                    };
573
-
574
-                    $("#smstables").show();
575
-
576
-                    $('#sms_upload_msg').hide();
577
-                    $('#smstables').removeClass('icon-loading');
578
-
579
-                  },
580
-                  error: function() {
581
-//                     alert('Error!');
582
-                             showAlert("Error while uploading the file.");
583
-                  }
584
-               });
585
-
586
-        } else {
587
-//               alert("Please choose a Sender ID from the Set ID drop-down list!");
588
-               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
589
-               $('#sms_upload_msg').hide();
590
-               $('#smstables').removeClass('icon-loading');
591
-        }
592
-
593
-     } else {
594
-//          alert('The file type is not supported ! Supported formats are txt and csv.');
595
-          showAlert("The file type is not supported ! Supported formats are txt and csv.");
596
-          $('#pf_upload_msg').hide();
597
-          $('#smstables').removeClass('icon-loading');
598
-
599
-          $("#induploadfile").remove();
600
-          $("#sms_upload_msg").hide();
601
-     }
602
-
603
-     //Preview uploaded file when clicked
604
-     $("#indfilediv").on("click", function() {
605
-
606
-          var smsfilename = e.target.files[0].name;
607
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
608
-
609
-          var reader = new FileReader();
610
-          reader.readAsText(e.target.files[0]);
611
-          reader.onload = function(e) {
612
-                  $("#smstables").empty();
613
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
614
-          };
615
-
616
-          $("#smstables").show();
617
-          $('#sms_upload_msg').hide();
618
-          $('#smstables').removeClass('icon-loading');
619
-     });
620
-
621
-     // Remove selected file
622
-     $("#indivflremove").on("click", function() {
623
-
624
-          $("#induploadfile").remove();
625
-          $("#sms_upload_msg").hide();
626
-
627
-          receiversNumbers.length = 0;
628
-
629
-     });
630
-
631
-  });
632
-
633
-  // Show the number of characters entered in the SMS textarea and the text size in KB
634
-  $("#smstext").on('input', function() {
635
-
636
-     $("#char_count").css("display", "inline");
637
-
638
-     $("#mtextSize").css("display", "inline");
639
-
640
-     $(".maxmessagelength").css("display", "inline-block");
641
-
642
-     $("#countchnb").text($(this).val().length);
643
-
644
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
645
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
646
-     $("#textsizeinkb").text(textsizekb);
647
-
648
-     if ($(this).val().length > charcolorthr) {
649
-         $("#char_count").css("color", "#BB2E4B");
650
-     } else {
651
-         $("#char_count").css("color", "#4cbc86;");
652
-     }
653
-
654
-  });
655
-
656
-
657
-  // Check the checkbox to send file(s) as MMS
658
-  $('#mediafilechckbx').change(function() {
659
-
660
-      if ($(this).is(':checked')) {
661
-
662
-          isMMS = 1;
663
-          if (selectedid == '') {
664
-//              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
665
-              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
666
-              $(this).prop("checked", false);
667
-              isMMS = 0;
668
-              return;
669
-          }
670
-          $("#upmediafiles").css("display", "block");
671
-          $("#submitsms").prop("value", "Send MMS");
672
-
673
-      } else {
674
-
675
-          isMMS = 0;
676
-          $("#upmediafiles").css("display", "none");
677
-          $("#submitsms").prop("value", "Send SMS");
678
-
679
-          // Remove the uploaded file(s) if any
680
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
681
-          $(".indgenpckfls").each(function() { $(this).remove(); });
682
-
683
-          uploadedtomms = [];
684
-          n = 1;
685
-
686
-          msgtotalflsize = 0;
687
-
688
-          $("#filestotsize").hide();
689
-      }
690
-  });
691
-
692
-
693
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
694
-  function adjustMaximumSize(uploadedtomms) {
695
-				      
696
-      var nonimgcheck = 0;
697
-      for (var u = 0; u < uploadedtomms.length; u++) {
698
-	   var crupfl = uploadedtomms[u];
699
-	   var extensionup = crupfl.replace(/^.*\./, '');
700
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
701
-	       nonimgcheck = 1;
702
-	   }
703
-      }
704
-
705
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
706
-  }
707
-
708
-  // Upload files to be sent as MMS
709
-  $("#uploadfileformms").change(function(e) {
710
-
711
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
712
-     $('#smstables').addClass('icon-loading');
713
-     $('#filestotsize').show();
714
-
715
-     var userid = "<?php p($userId); ?>";
716
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
717
-
718
-     var formData = new FormData();
719
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
720
-
721
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
722
-
723
-     // Add the size of the current file to the total size of all the files
724
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
725
-
726
-     var fileup = $('#uploadfileformms').val();
727
-     var fileuptrim = fileup.split('\\').pop();
728
-
729
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
730
-         var duplicatescheck = 1;
731
-     } else { 
732
-         var duplicatescheck = 0;
733
-     }
734
-
735
-     var extension = fileup.replace(/^.*\./, '');
736
-
737
-     if (extension == fileup) {
738
-         extension = "";
739
-     } else {
740
-         extension = extension.toLowerCase();
741
-     }
742
-
743
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
744
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
745
-         maximumsize = maxsizenonimage;
746
-     }
747
-
748
-     if ($.inArray(extension, validExtensions) != -1) {
749
-
750
-       if (duplicatescheck == 0) {
751
-
752
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
753
-
754
-            if (n <= maximumfilenumber) {
755
-
756
-               $.ajax({
757
-                 url: baseUrl + '/' + userid,
758
-                 type: "POST",
759
-                 data: formData,
760
-                 cache: false,
761
-                 processData: false,
762
-                 contentType: false,
763
-                 success: function(totalflsize) {
764
-
765
-                   uploadedtomms.push(fileuptrim);
766
-
767
-                   $('#filessizetext').text(totalflsize);
768
-
769
-                   var rectotfilesz = parseFloat(totalflsize);
770
-
771
-                   if (rectotfilesz <= maximumsize) {
772
-                       $('#submitsms').attr("disabled", false);
773
-                       $('#filestotsize').css('color', '#189558');
774
-                   } else {
775
-                       $('#filestotsize').css('color', '#ba3555');
776
-//                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
777
-                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
778
-                       $('#submitsms').attr("disabled", true);
779
-                       $('#smstables').removeClass('icon-loading');
780
-                       $('#pf_upload_msg').hide();
781
-                   }
782
-
783
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
784
-                   n++;
785
-
786
-                   // Preview the file when you click on its name
787
-                   $("div:visible[id*='indfilediv']").each(function() {
788
-
789
-                        $(this).on("click", function(eventclck) {
790
-
791
-                           $("#mmsfoldersview").css("display", "inline-block");
792
-                           var mmsfilenameinit = $(this).text();
793
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
794
-                           var mmsfilename = mmsfilenamesec.replace("X","");
795
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
796
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
797
-
798
-                           if (extenlst == mmsfilename) {
799
-                               extenlst = "";
800
-                           } else {
801
-                               extenlst = extenlst.toLowerCase();
802
-                           }
803
-
804
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
805
-                                  $("#smstables").empty();
806
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
807
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
-                           } else if (extenlst == 'png') {
809
-                                  $("#smstables").empty();
810
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
811
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
812
-                           } else if (extenlst == 'gif') {
813
-                                  $("#smstables").empty();
814
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
815
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
816
-                           } else if (extenlst == 'bmp') {
817
-                                  $("#smstables").empty();
818
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
819
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
820
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
821
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
822
-                                  var xhr = new XMLHttpRequest();
823
-                                  xhr.responseType = 'arraybuffer';
824
-                                  xhr.open('GET', tiffile);
825
-                                  xhr.onload = function (evnt) {
826
-                                      var tiff = new Tiff({buffer: xhr.response});
827
-                                      var tifcanvas = tiff.toCanvas();
828
-                                      $("#smstables").empty();
829
-                                      $("#smstables").append(tifcanvas);
830
-                                  };
831
-                                  xhr.send();
832
-                           } else if (extenlst == 'pdf') {
833
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
834
-                                  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>');
835
-                                  $("#smstables").empty();
836
-                                  $("#smstables").append($iframe);
837
-                           } else if (extenlst == 'txt') {
838
-                                  $("#smstables").empty();
839
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
840
-                           } else if (extension == 'mp4') {
841
-                                  $("#smstables").empty();
842
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
843
-		           } else if (extension == 'ogg') {
844
-		                  $("#smstables").empty();
845
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
846
-		           } else if (extension == 'avi') {
847
-		                  $("#smstables").empty();
848
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
849
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
850
-		                  $("#smstables").empty();
851
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
852
-		           } else if (extension == 'wav' || extension == 'wave') {
853
-		                  $("#smstables").empty();
854
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
855
-		           } else if (extension == 'mp3') {
856
-		                  $("#smstables").empty();
857
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
858
-		           } else if (extension == 'midi') {
859
-		                  $("#smstables").empty();
860
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
861
-		           }
862
-
863
-                           $("#smstables").show();
864
-                           $("#mmsfoldersview").hide();
865
-                        });
866
-                   });
867
-
868
-                   // Remove uploaded files
869
-                   $('[class*="indupfldl"]').last().click(function() {
870
-
871
-                           var userid = "<?php p($userId); ?>";
872
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
873
-
874
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
875
-
876
-                           var removedfilesplit = removedfilenameinit.split(") ");
877
-                           var removedflnb = parseInt(removedfilesplit[0]);
878
-
879
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
880
-                           $(this).hide();
881
-
882
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
883
-
884
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
885
-                                           return value != removedfilename;
886
-                           });
887
-
888
-                           $.ajax({
889
-                                   url: baseUrl + '/' + userid,
890
-                                   type: "POST",
891
-                                   data: {removedfilename: removedfilename},
892
-                                   success: function(totalflsize) {
893
-
894
-                                      msgtotalflsize = totalflsize;
895
-                                      $('#filessizetext').text(totalflsize);
896
-
897
-                                      adjustMaximumSize(uploadedtomms);
898
-
899
-                                      // Check message size
900
-                                      var rectotfilesz = parseFloat(totalflsize);
901
-
902
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
903
-                                          $('#submitsms').attr("disabled", false);
904
-                                          $('#filestotsize').css('color', '#189558');
905
-                                      } else {
906
-                                          $('#filestotsize').css('color', '#ba3555');
907
-//                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
908
-                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
909
-                                          $('#submitsms').attr("disabled", true);
910
-                                      }
911
-
912
-                                      // Rewrite order numbers for files that follow
913
-                                      --n;
914
-                                      $("div:visible[id*='indfilediv']").each(function() {
915
-
916
-                                          var getdivtext =  $(this).text();
917
-                                          var splitdivtext = getdivtext.split(") ");
918
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
-                                          var newnbvalue = currentnbvalue - 1;
920
-
921
-                                          if (currentnbvalue > removedflnb) {
922
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
-                                              $(this).text(replacedstr);
924
-                                          }
925
-                                      });
926
-
927
-                                      $("div:visible[id*='indflpicked']").each(function() {
928
-
929
-                                          var getdivtext =  $(this).text();
930
-                                          var splitdivtext = getdivtext.split(") ");
931
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
932
-                                          var newnbvalue = currentnbvalue - 1;
933
-
934
-                                          if (currentnbvalue > removedflnb) {
935
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
936
-                                              $(this).text(replacedstr);
937
-                                          }
938
-                                      });
939
-
940
-                                   },
941
-                                   error: function() {
942
-//                                          alert('Error removing file(s)!');
943
-                                              showAlert("Error while removing the file(s).");
944
-                                   }
945
-                           });
946
-
947
-                           $('#smstables').removeClass('icon-loading');
948
-                           $("#smstables").empty();
949
-                   });
950
-
951
-                   // Preview the uploaded file
952
-                   $("#mmsfoldersview").css("display", "inline-block");
953
-                   var mmsfilename = e.target.files[0].name;
954
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
955
-
956
-
957
-                   if (extension == 'jpg' || extension == 'jpeg') {
958
-                              $("#smstables").empty();
959
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
960
-
961
-                              var reader = new FileReader();
962
-                              reader.onload = function (e) {
963
-                                  readjpg[mmsfilename] = e.target.result;
964
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
965
-                              }
966
-                              reader.readAsDataURL(e.target.files[0]);
967
-                   } else if (extension == 'png') {
968
-                              $("#smstables").empty();
969
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
970
-
971
-                              var reader = new FileReader();
972
-                              reader.onload = function (e) {
973
-                                  readpng[mmsfilename] = e.target.result;
974
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
975
-                              }
976
-                              reader.readAsDataURL(e.target.files[0]);
977
-
978
-                   } else if (extension == 'gif') {
979
-                              $("#smstables").empty();
980
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
981
-
982
-                              var reader = new FileReader();
983
-                              reader.onload = function (e) {
984
-                                  readgif[mmsfilename] = e.target.result;
985
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
986
-                              }
987
-                              reader.readAsDataURL(e.target.files[0]);
988
-
989
-                   } else if (extension == 'bmp') {
990
-                              $("#smstables").empty();
991
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
992
-
993
-                              var reader = new FileReader();
994
-                              reader.onload = function (e) {
995
-                                  readbmp[mmsfilename] = e.target.result;
996
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
997
-                              }
998
-                              reader.readAsDataURL(e.target.files[0]);
999
-
1000
-                   } else if (extension == 'tif' || extension == 'tiff') {
1001
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1002
-                              var xhr = new XMLHttpRequest();
1003
-                              xhr.responseType = 'arraybuffer';
1004
-                              xhr.open('GET', tiffile);
1005
-                              xhr.onload = function (e) {
1006
-                                  var tiff = new Tiff({buffer: xhr.response});
1007
-                                  var tifcanvas = tiff.toCanvas();
1008
-                                  $("#smstables").empty();
1009
-                                  $("#smstables").append(tifcanvas);
1010
-                              };
1011
-                              xhr.send();
1012
-
1013
-                   } else if (extension == 'pdf') {
1014
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1015
-                              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>');
1016
-                              $("#smstables").empty();
1017
-                              $("#smstables").append($iframe);
1018
-
1019
-                   } else if (extension == 'txt') {
1020
-                              var reader = new FileReader();
1021
-                              reader.readAsText(e.target.files[0]);
1022
-                              reader.onload = function(e) {
1023
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1024
-                                  $("#smstables").empty();
1025
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
1026
-                              };
1027
-                   } else if (extension == 'mp4') {
1028
-                              $("#smstables").empty();
1029
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1030
-                   } else if (extension == 'ogg') {
1031
-                              $("#smstables").empty();
1032
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1033
-                   } else if (extension == 'avi') {
1034
-                              $("#smstables").empty();
1035
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1036
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
1037
-                              $("#smstables").empty();
1038
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1039
-                   } else if (extension == 'wav' || extension == 'wave') {
1040
-                              $("#smstables").empty();
1041
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1042
-                   } else if (extension == 'mp3') {
1043
-                              $("#smstables").empty();
1044
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1045
-                   } else if (extension == 'midi') {
1046
-                              $("#smstables").empty();
1047
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1048
-                   }
1049
-
1050
-                   $("#smstables").show();
1051
-                   $('#pf_upload_msg').hide();
1052
-                   $('#smstables').removeClass('icon-loading');
1053
-                   $("#mmsfoldersview").hide();
1054
-                 },
1055
-                 error: function() {
1056
-//                     alert('Error uploading file!');
1057
-                              showAlert("Error while uploading the file.");
1058
-                 }
1059
-               });
1060
-
1061
-            } else {
1062
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1063
-                  adjustMaximumSize(uploadedtomms);
1064
-
1065
-//                  alert("Error ! You cannot send more than 10 files in one MMS !");
1066
-                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1067
-                  $('#pf_upload_msg').hide();
1068
-                  $('#smstables').removeClass('icon-loading');
1069
-            }
1070
-         } else {
1071
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1072
-              adjustMaximumSize(uploadedtomms);
1073
-
1074
-//              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
1075
-              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1076
-              $('#pf_upload_msg').hide();
1077
-              $('#smstables').removeClass('icon-loading');
1078
-         }
1079
-       } else {
1080
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1081
-            adjustMaximumSize(uploadedtomms);
1082
-
1083
-//            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
1084
-            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1085
-            $('#pf_upload_msg').hide();
1086
-            $('#smstables').removeClass('icon-loading');
1087
-       }
1088
-
1089
-     } else {
1090
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1091
-          adjustMaximumSize(uploadedtomms);
1092
-
1093
-//          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1094
-          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1095
-          $('#pf_upload_msg').hide();
1096
-          $('#smstables').removeClass('icon-loading');
1097
-     }
1098
-  });
1099
-
1100
-
1101
-  // Pick file(s) from Nextcloud, to send as MMS
1102
-  var mmsfilename = null;
1103
-
1104
-  $("#choosefilen").on("click", function(evn) {
1105
-
1106
-                OC.dialogs.filepicker(
1107
-                        t('settings', "Select a file to send as MMS."),
1108
-                        function (path) {
1109
-
1110
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1111
-                              $('#smstables').addClass('icon-loading');
1112
-                              $('#filestotsize').show();
1113
-
1114
-                              var userid = "<?php p($userId); ?>";
1115
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1116
-
1117
-                              mmsfilename = path.split('/').pop();
1118
-
1119
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1120
-                                  var duplicatescheck = 1;
1121
-                              } else var duplicatescheck = 0;
1122
-
1123
-                              var extension = mmsfilename.replace(/^.*\./, '');
1124
-
1125
-                              if (extension == mmsfilename) {
1126
-                                  extension = "";
1127
-                              } else {
1128
-                                  extension = extension.toLowerCase();
1129
-                              }
1130
-
1131
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1132
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1133
-				   maximumsize = maxsizenonimage;
1134
-			      }
1135
-
1136
-                              if ($.inArray(extension, validExtensions) != -1) {
1137
-
1138
-                                 if (duplicatescheck == 0) {
1139
-
1140
-                                    if (n <= maximumfilenumber) {
1141
-
1142
-                                       $.ajax({
1143
-                                          url: baseUrl + '/' + userid,
1144
-                                          type: "POST",
1145
-                                          data: { path: path },
1146
-                                          success: function(pickresult) {
1147
-
1148
-                                                uploadedtomms.push(mmsfilename);
1149
-
1150
-                                                var totalflsize = pickresult[0];
1151
-                                                var pickedflsize = pickresult[1];
1152
-
1153
-                                                // Check message size
1154
-                                                var rectotfilesz = parseFloat(totalflsize);
1155
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1156
-
1157
-                                                if (filesplustextsize <= maximumsize) {
1158
-
1159
-                                                    $("#mmsfoldersview").css("display", "inline-block");
1160
-
1161
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1162
-                                                    n++;
1163
-
1164
-                                                    msgtotalflsize = totalflsize;
1165
-                                                    $('#filessizetext').text(totalflsize);
1166
-                                                    $('#filestotsize').css('color', '#189558');
1167
-
1168
-                                                } else {
1169
-
1170
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1171
-                                                    $('#filestotsize').css('color', '#ba3555');
1172
-                                                    msgtotalflsize -= pickedflsize;
1173
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1174
-
1175
-                                                    $.ajax({
1176
-                                                        url: baseUrlindrm + '/' + userid,
1177
-                                                        type: "POST",
1178
-                                                        data: {removedfilename: mmsfilename},
1179
-                                                        success: function(totalflsize) {
1180
-
1181
-                                                                          $('#filessizetext').text(totalflsize);
1182
-                                                                          $('#filestotsize').css('color', '#189558');
1183
-                                                                          adjustMaximumSize(uploadedtomms);
1184
-
1185
-                                                        },
1186
-                                                        error: function(totalflsize) {
1187
-                                                                          $('#filessizetext').text(totalflsize);
1188
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1189
-                                                                              $('#filestotsize').css('color', '#ba3555');
1190
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1191
-//                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1192
-                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1193
-                                                        }
1194
-                                                    });
1195
-
1196
-//                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1197
-                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1198
-                                                }
1199
-
1200
-
1201
-                                                // Preview each file when you click on its name
1202
-                                                $("div:visible[id*='indflpicked']").each(function() {
1203
-                                                   $(this).on("click", function(event) {
1204
-
1205
-                                                      var mmsfilenameinit = $(this).text();
1206
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1207
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1208
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1209
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1210
-
1211
-                                                      if (extenlst == mmsfilenamesp) {
1212
-                                                           extenlst = "";
1213
-                                                      } else {
1214
-                                                           extenlst = extenlst.toLowerCase();
1215
-                                                      }
1216
-
1217
-
1218
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1219
-                                                              $("#smstables").empty();
1220
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1221
-                                                      } else if (extenlst == 'png') {
1222
-                                                              $("#smstables").empty();
1223
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1224
-                                                      } else if (extenlst == 'gif') {
1225
-                                                              $("#smstables").empty();
1226
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1227
-                                                      } else if (extenlst == 'bmp') {
1228
-                                                              $("#smstables").empty();
1229
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1230
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1231
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1232
-                                                              var xhr = new XMLHttpRequest();
1233
-                                                              xhr.responseType = 'arraybuffer';
1234
-                                                              xhr.open('GET', tiffile);
1235
-                                                              xhr.onload = function (evnt) {
1236
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1237
-                                                                  var tifcanvas = tiff.toCanvas();
1238
-                                                                  $("#smstables").empty();
1239
-                                                                  $("#smstables").append(tifcanvas);
1240
-                                                              };
1241
-                                                              xhr.send();
1242
-                                                      } else if (extenlst == 'pdf') {
1243
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1244
-                                                              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>');
1245
-                                                              $("#smstables").empty();
1246
-                                                              $("#smstables").append($iframe);
1247
-                                                      } else if (extenlst == 'txt') {
1248
-                                                              $("#smstables").empty();
1249
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1250
-                                                      } else if (extension == 'mp4') {
1251
-							      $("#smstables").empty();
1252
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1253
-						      } else if (extension == 'ogg') {
1254
-							      $("#smstables").empty();
1255
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1256
-						      } else if (extension == 'avi') {
1257
-							      $("#smstables").empty();
1258
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1259
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1260
-							      $("#smstables").empty();
1261
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1262
-						      } else if (extension == 'wav' || extension == 'wave') {
1263
-							      $("#smstables").empty();
1264
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1265
-						      } else if (extension == 'mp3') {
1266
-							      $("#smstables").empty();
1267
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1268
-						      } else if (extension == 'midi') {
1269
-							      $("#smstables").empty();
1270
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1271
-						      }
1272
-
1273
-
1274
-                                                      $("#smstables").show();
1275
-                                                      $("#mmsfoldersview").hide();
1276
-                                                   });
1277
-                                                });
1278
-
1279
-
1280
-                                                // Remove picked files
1281
-                                                $('[class*="indpckfldl"]').last().click(function() {
1282
-                                                    var userid = "<?php p($userId); ?>";
1283
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1284
-
1285
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1286
-
1287
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1288
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1289
-
1290
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1291
-                                                    $(this).hide();
1292
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1293
-
1294
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1295
-                                                             return value != removedfilename;
1296
-                                                    });
1297
-
1298
-                                                    $.ajax({
1299
-                                                        url: baseUrl + '/' + userid,
1300
-                                                        type: "POST",
1301
-                                                        data: {removedfilename: removedfilename},
1302
-                                                        success: function(totalflsize) {
1303
-
1304
-                                                             msgtotalflsize = totalflsize;
1305
-                                                             $('#filessizetext').text(totalflsize);
1306
-                                                             adjustMaximumSize(uploadedtomms);
1307
-
1308
-                                                             // Check message size
1309
-                                                             var rectotfilesz = parseFloat(totalflsize);
1310
-
1311
-                                                             if (rectotfilesz > maximumsize) {
1312
-                                                                 $('#filestotsize').css('color', '#ba3555');
1313
-//                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1314
-                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1315
-                                                                 $('#submitsms').attr("disabled", true);
1316
-                                                             } else {
1317
-                                                                 $('#submitsms').attr("disabled", false);
1318
-                                                                 $('#filestotsize').css('color', '#189558');
1319
-                                                               }
1320
-
1321
-                                                             // Rewrite order numbers for files that follow
1322
-                                                             --n;
1323
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1324
-
1325
-                                                                  var getdivtext =  $(this).text();
1326
-                                                                  var splitdivtext = getdivtext.split(") ");
1327
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1328
-                                                                  var newnbvalue = currentnbvalue - 1;
1329
-
1330
-                                                                  if (currentnbvalue > removedflnb) {
1331
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1332
-                                                                      $(this).text(replacedstr);
1333
-                                                                  }
1334
-                                                             });
1335
-                                                        },
1336
-                                                        error: function() {
1337
-//                                                             alert('Error !');
1338
-                                                                  showAlert("Error while removing the file.");
1339
-                                                        }
1340
-                                                    });
1341
-
1342
-                                                    $('#smstables').removeClass('icon-loading');
1343
-                                                    $("#smstables").empty();
1344
-                                                });
1345
-
1346
-
1347
-		                                // Preview the picked file
1348
-		                                $("#mmsfoldersview").css("display", "inline-block");
1349
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1350
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1351
-
1352
-
1353
-						if (extension == 'jpg' || extension == 'jpeg') {
1354
-
1355
-		                                            $("#smstables").empty();
1356
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1357
-
1358
-		                                } else if (extension == 'png') {
1359
-
1360
-		                                            $("#smstables").empty();
1361
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1362
-
1363
-		                                } else if (extension == 'gif') {
1364
-
1365
-		                                            $("#smstables").empty();
1366
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1367
-
1368
-		                                } else if (extension == 'bmp') {
1369
-
1370
-	                                                    $("#smstables").empty();
1371
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1372
-
1373
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1374
-
1375
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1376
-		                                       var xhr = new XMLHttpRequest();
1377
-		                                       xhr.responseType = 'arraybuffer';
1378
-		                                       xhr.open('GET', tiffile);
1379
-		                                       xhr.onload = function (event) {
1380
-		                                           var tiff = new Tiff({buffer: xhr.response});
1381
-		                                           var tifcanvas = tiff.toCanvas();
1382
-		                                           $("#smstables").empty();
1383
-		                                           $("#smstables").append(tifcanvas);
1384
-		                                       };
1385
-		                                       xhr.send();
1386
-
1387
-		                                } else if (extension == 'pdf') {
1388
-
1389
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1390
-		                                       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>');
1391
-		                                       $("#smstables").empty();
1392
-		                                       $("#smstables").append($iframe);
1393
-
1394
-		                                } else if (extension == 'txt') {
1395
-
1396
-							     $.get(flUrl, function(textdata) {
1397
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1398
-		                                               $("#smstables").empty();
1399
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1400
-							     });
1401
-
1402
-		                                } else if (extension == 'mp4') {
1403
-						       $("#smstables").empty();
1404
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1405
-						} else if (extension == 'ogg') {
1406
-						       $("#smstables").empty();
1407
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1408
-						} else if (extension == 'avi') {
1409
-						       $("#smstables").empty();
1410
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1411
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1412
-						       $("#smstables").empty();
1413
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1414
-						} else if (extension == 'wav' || extension == 'wave') {
1415
-						       $("#smstables").empty();
1416
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1417
-						} else if (extension == 'mp3') {
1418
-						       $("#smstables").empty();
1419
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1420
-						} else if (extension == 'midi') {
1421
-						       $("#smstables").empty();
1422
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1423
-						}
1424
-
1425
-
1426
-		                                $("#smstables").show();
1427
-
1428
-		                                $('#pf_choose_msg').hide();
1429
-		                                $('#smstables').removeClass('icon-loading');
1430
-		                                $("#mmsfoldersview").hide();
1431
-
1432
-                                          },
1433
-
1434
-                                          error: function(data){
1435
-//                                             alert('Error!');
1436
-                                                showAlert("Error while getting the file.");
1437
-                                          }
1438
-
1439
-                                       });
1440
-
1441
-                                    } else {
1442
-//                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1443
-                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1444
-                                        $('#pf_choose_msg').hide();
1445
-                                        $('#smstables').removeClass('icon-loading');
1446
-                                      }
1447
-                                 } else {
1448
-//                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1449
-                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1450
-                                      $('#pf_choose_msg').hide();
1451
-                                      $('#smstables').removeClass('icon-loading');
1452
-                                   }
1453
-
1454
-                              } else {
1455
-//                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1456
-                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1457
-                                   $('#pf_choose_msg').hide();
1458
-                                   $('#smstables').removeClass('icon-loading');
1459
-                                }
1460
-
1461
-                        }
1462
-                );
1463
-  });
1464
-
1465
-
1466
-
1467
-  // Send the SMS/MMS message
1468
-  $("#submitsms").on("click", function(event) {
1469
-
1470
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1471
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1472
-     $("#sms_submit_msg").css("display", "inline-block");
1473
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1474
-
1475
-     if (selectedid != '') { 
1476
-
1477
-         var sendersplit = selectedid.split(":");
1478
-         var providercap = sendersplit[0];
1479
-         var provsec = sendersplit[1];
1480
-
1481
-         if (/[a-zA-Z]/.test(provsec)) {
1482
-             var alphanumcheck = true;
1483
-         } else { var alphanumcheck = false; }
1484
-
1485
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1486
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1487
-             var selectedsender = "+" + senderproc;
1488
-             var providerUsed = "telnyx";
1489
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1490
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1491
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1492
-             var providerUsed = "plivo";
1493
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1494
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1495
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1496
-             var selectedsender = "+" + senderproc;
1497
-             var providerUsed = "twilio";
1498
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1499
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1500
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1501
-             var selectedsender = "+" + senderproc;
1502
-             var providerUsed = "flowroute";
1503
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1504
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1505
-             var selectedsender = provsec;
1506
-             var providerUsed = "telnyx";
1507
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1508
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1509
-             var selectedsender = provsec;
1510
-             var providerUsed = "plivo";
1511
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1512
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1513
-             var selectedsender = provsec;
1514
-             var providerUsed = "twilio";
1515
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1516
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1517
-             var selectedsender = provsec;
1518
-             var providerUsed = "flowroute";
1519
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1520
-         }
1521
-
1522
-         // Get the interval between message consecutive sending requests, if it's the case
1523
-         if ($('#tomultchckbx').is(':checked')) {
1524
-
1525
-             var numbersfile = 1;
1526
-             var initinterval = $("#multsmsinterval").val();
1527
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1528
-
1529
-             if (secinterval != '') {
1530
-                 var tertinterval = parseInt(secinterval);
1531
-                     waittime = tertinterval;
1532
-             }
1533
-
1534
-         } else {
1535
-
1536
-             var numbersfile = 0;
1537
-             var toNumberinit = $('#smsto').val();
1538
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1539
-             var toNumbersec = toNumber.split(",");
1540
-
1541
-                 for (var i = 0; i < toNumbersec.length; i++) {
1542
-                      toNumbersec[i] = "+" + toNumbersec[i];
1543
-                 }
1544
-
1545
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1546
-         }
1547
-
1548
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1549
-
1550
-         var smstext = $("#smstext").val();
1551
-
1552
-         if (receiversNumbers.length != 0) {
1553
-
1554
-              if (smstext != '') {
1555
-                  $.ajax({
1556
-                     url: relbaseUrl + '/' + userid,
1557
-                     type: "POST",
1558
-                     data: {
1559
-                           receiversPhoneNbs: receiversNumbers,
1560
-                           fromsender: selectedsender,
1561
-                           waitinterval: waittime,
1562
-                           sentsmstext: smstext,
1563
-                           ismms: isMMS,
1564
-                           mmsfiles: uploadedtomms
1565
-                         },
1566
-                     success: function() {
1567
-
1568
-                           if (receiversNumbers.length == 1) {
1569
-//                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1570
-                               showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1571
-                           } else {
1572
-//                               alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1573
-                               showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1574
-                           }
1575
-
1576
-                           $('#sms_submit_msg').hide();
1577
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1578
-                     },
1579
-                     error: function() {
1580
-//                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1581
-                           showAlert("Error! Please check the recipient's phone number and your settings!");
1582
-                           $('#sms_submit_msg').hide();
1583
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1584
-                     }
1585
-                  });
1586
-              } else {
1587
-//                     alert("Please enter a message in the text box !");
1588
-                     showAlert("Please enter a message in the text box !");
1589
-
1590
-                     $('#sms_submit_msg').hide();
1591
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1592
-              }
1593
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1594
-//                 alert("Please enter the recipient's phone number !");
1595
-                 showAlert("Please enter the recipient's phone number !");
1596
-                 $('#sms_submit_msg').hide();
1597
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1598
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1599
-//                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1600
-                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1601
-                 $('#sms_submit_msg').hide();
1602
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1603
-         }
1604
-     } else {
1605
-//           alert("Please choose a Sender ID from the Set ID drop-down list !");
1606
-           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1607
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1608
-           $('#sms_submit_msg').hide();
1609
-     }
1610
-
1611
-  });
1612
-
1613
-  // Check the checkbox to delete old messages from the database
1614
-  $('#deleteoldchckbox').change(function() {
1615
-     if ($(this).is(':checked')) {
1616
-         $("#deleteoldsms").css("display", "block");
1617
-     } else {
1618
-         $("#deleteoldsms").css("display", "none");
1619
-     }
1620
-  });
1621
-
1622
-  // Set the height of 3 info notes
1623
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1624
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1625
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1626
-
1627
-  $(window).resize(function() { 
1628
-     $('#setcalleridtp').css('height', $(window).height() - 160);
1629
-     $('#tonmbrformat').css('height', $(window).height() - 260);
1630
-     $('#uploadfileinfo').css('height', $(window).height() - 390);
1631
-  });
1632
-
1633
-
1634
-  function showAlert(alertText) {
1635
-
1636
-     let alertwnd = "<div id='alertMessage'>";
1637
-     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1638
-     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1639
-     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1640
-     alertwnd += "</div>";
1641
-
1642
-     $("#content").append("<div id='alertMsgOverlay'></div>");
1643
-     $("#content").append(alertwnd);
1644
-
1645
-     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1646
-     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1647
-     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1648
-
1649
-     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1650
-     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1651
-     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1652
-  }
Browse code

added files to implement pop-up windows, etc.

DoubleBastionAdmin authored on 20/05/2023 01:06:57
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1652 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+
58
+  // Get the available phone numbers associated with the API keys saved on the Settings page
59
+  $("#smsnumbersdiv").addClass('icon-loading');
60
+
61
+  var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
62
+
63
+  $.ajax({
64
+          url: getsmsnumbersUrl + '/' + userid,
65
+          type: "POST",
66
+          data: { userid: userid },
67
+          cache: false,
68
+          processData: false,
69
+          contentType: false,
70
+          success: function(currentnmbrs) {
71
+
72
+                     $('#currentsmsnmbrs').empty();
73
+
74
+                     if (currentnmbrs.length > 1) {
75
+
76
+                         $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>Choose an ID</option>");
77
+
78
+                         $.each(currentnmbrs, function(key, valsmsnmb) {
79
+                                $('#currentsmsnmbrs').append("<option value='"+ valsmsnmb +"' class='optselectsmsnb'>"+ valsmsnmb +"</option>");
80
+                         });
81
+
82
+                         // Append the available providers to the 'see balance' drop-down list
83
+                         var providerNm = [];
84
+                         for (var n = 0; n < currentnmbrs.length; n++) {
85
+
86
+                              var provfirstchr = currentnmbrs[n].split(": ")[0];
87
+                              if (provfirstchr == "Tx") {
88
+                                  if (providerNm.indexOf("Telnyx") === -1) {
89
+                                      providerNm.push("Telnyx");
90
+                                      $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
91
+                                  }
92
+                              } else if (provfirstchr == "Pl") {
93
+                                  if (providerNm.indexOf("Plivo") === -1) {
94
+                                      providerNm.push("Plivo");
95
+                                      $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
96
+                                  }
97
+                              } else if (provfirstchr == "Tw") {
98
+                                  if (providerNm.indexOf("Twilio") === -1) {
99
+                                      providerNm.push("Twilio");
100
+                                      $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
101
+                                  }
102
+                              } else if (provfirstchr == "Fl") {
103
+                                  if (providerNm.indexOf("Flowroute") === -1) {
104
+                                      providerNm.push("Flowroute");
105
+                                      $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
106
+                                  }
107
+                              }
108
+                         }
109
+
110
+//                         for (var b = 0; b < providerNm.length; b++) {
111
+//                              $("#smsprovider").append("<option value='"+ providerNm[b] +"' class='selectsmsprov'>"+ providerNm[b] +"</option>");
112
+//                         }
113
+
114
+                     } else if (currentnmbrs.length == 1) {
115
+
116
+                                $('#currentsmsnmbrs').append("<option value='"+ currentnmbrs[0] +"' class='optselectsmsnb' selected disabled>"+ currentnmbrs[0] +"</option>");
117
+
118
+                                selectedid = currentnmbrs[0];
119
+
120
+                                var unqprovider = currentnmbrs[0].split(": ")[0];
121
+
122
+                                if (unqprovider == 'Tx') {
123
+
124
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
125
+					  // Maximum size of message text + files in KB
126
+					  maximumsize = 1024;
127
+					  maximumsizeinit = 1024;
128
+					  maxsizenonimage = 600;
129
+					  maximumfilenumber = 10;
130
+					  chosenProvFullName = "Telnyx";
131
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
132
+						             or gif files, the size of all the files plus the size of the text should be \
133
+						             <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
134
+						             rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
135
+						             be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
136
+						             limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
137
+						             rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
138
+						             Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
139
+						             gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
140
+						             or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
141
+						             gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
142
+					  $("#tooltiptextfourth").html(infonotecontent);
143
+
144
+                                          // Append 'Telnyx' to the 'see balance' drop-down list
145
+                                          $("#smsprovider").append("<option value='Telnyx' class='selectsmsprov'>Telnyx</option>");
146
+
147
+                                } else if (unqprovider == 'Pl') {
148
+
149
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
150
+						             "icalendar", "csv", "txt", "pdf", "xls"];
151
+					  // Maximum size of message text + files in KB
152
+					  maximumsize = 5120;
153
+					  maximumsizeinit = 5120;
154
+					  maxsizenonimage = 600;
155
+					  maximumfilenumber = 10;
156
+					  chosenProvFullName = "Plivo";
157
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
158
+						             or gif files, the size of all the files plus the size of the text should be \
159
+						             <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
160
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
161
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
162
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
163
+						             3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
164
+						             device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
165
+						             achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
166
+						             only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
167
+						             only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
168
+					  $("#tooltiptextfourth").html(infonotecontent);
169
+
170
+                                          // Append 'Plivo' to the 'see balance' drop-down list
171
+                                          $("#smsprovider").append("<option value='Plivo' class='selectsmsprov'>Plivo</option>");
172
+
173
+                                } else if (unqprovider == 'Tw') {
174
+
175
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
176
+						             "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
177
+						             "icalendar", "directory", "pdf", "pkpass"];
178
+					  // Maximum size of message text + files in KB
179
+					  maximumsize = 5120;
180
+					  maximumsizeinit = 5120;
181
+					  maxsizenonimage = 600;
182
+					  maximumfilenumber = 10;
183
+					  chosenProvFullName = "Twilio";
184
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
185
+						             or gif files, the size of all the files plus the size of the text should be \
186
+						             <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
187
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
188
+						             of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
189
+						             style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
190
+						             wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
191
+						             ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
192
+						             can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
193
+						             with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
194
+						             numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
195
+						             specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
196
+						             previewed in the adjoining pane."
197
+					  $("#tooltiptextfourth").html(infonotecontent);
198
+
199
+                                          // Append 'Twilio' to the 'see balance' drop-down list
200
+                                          $("#smsprovider").append("<option value='Twilio' class='selectsmsprov'>Twilio</option>");
201
+
202
+                                } else if (unqprovider == 'Fl') {
203
+
204
+					  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
205
+					  // Maximum size of message text + files in KB
206
+					  maximumsize = 750;
207
+					  maximumsizeinit = 750;
208
+					  maxsizenonimage = 600;
209
+					  maximumfilenumber = 10;
210
+					  chosenProvFullName = "Flowroute";
211
+					  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
212
+							     png or gif files, the size of all the files plus the size of the text should be \
213
+							     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
214
+							     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
215
+							     size of the files plus the size of the text should be 600 KB or less. \
216
+							     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
217
+							     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
218
+							     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
219
+							     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
220
+							     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
221
+							     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
222
+							     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
223
+							     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
224
+					  $("#tooltiptextfourth").html(infonotecontent);
225
+
226
+                                          // Append 'Flowroute' to the 'see balance' drop-down list
227
+                                          $("#smsprovider").append("<option value='Flowroute' class='selectsmsprov'>Flowroute</option>");
228
+                                }
229
+                     } else {
230
+                                $('#currentsmsnmbrs').append("<option value='' class='optselectsmsnb' selected disabled>No IDs</option>");
231
+                     }
232
+
233
+                     $("#smsnumbersdiv").removeClass('icon-loading');
234
+          }
235
+  });
236
+     //  });
237
+
238
+
239
+  // Clean the SMS_Relentless/temp_files directory
240
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
241
+
242
+  $.ajax({
243
+          url: cleanflUrl + '/' + userid,
244
+          type: "POST",
245
+          data: { userid: userid },
246
+          cache: false,
247
+          processData: false,
248
+          contentType: false
249
+  });
250
+  
251
+  // Check the available balance
252
+  $("#smsprovider").on("change", function () {
253
+
254
+     var provider = $('#smsprovider :selected').val();
255
+
256
+     if (provider == "Telnyx") {
257
+
258
+        var gettelbalance = function() {
259
+
260
+          $('#currentbalance').addClass('icon-loading');
261
+
262
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
263
+
264
+          $.ajax({
265
+              url: gettelbalanceUrl + '/' + userid,
266
+              type: "POST",
267
+              data: { userid: userid },
268
+              cache: false,
269
+              processData: false,
270
+              contentType: false,
271
+              success: function(currentbalancetel) {
272
+
273
+                     $('#currentbalance').empty();
274
+                     $('#currentbalance').text(currentbalancetel);
275
+                     $('#currentbalance').removeClass('icon-loading');
276
+              }
277
+          });
278
+        }
279
+
280
+        gettelbalance();
281
+
282
+     } else if (provider == "Plivo") {
283
+
284
+          var getnexbalance = function() {
285
+
286
+            $('#currentbalance').addClass('icon-loading');
287
+
288
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
289
+
290
+            $.ajax({
291
+                url: getnexbalanceUrl + '/' + userid,
292
+                type: "POST",
293
+                data: { userid: userid },
294
+                cache: false,
295
+                processData: false,
296
+                contentType: false,
297
+                success: function(currentbalancenex) {
298
+
299
+                     $('#currentbalance').empty();
300
+                     $('#currentbalance').text(currentbalancenex);
301
+                     $('#currentbalance').removeClass('icon-loading');
302
+                }
303
+            });
304
+          }
305
+
306
+          getnexbalance();
307
+
308
+     } else if (provider == "Twilio") {
309
+
310
+          var gettwilbalance = function() {
311
+
312
+            $('#currentbalance').addClass('icon-loading');
313
+
314
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
315
+
316
+            $.ajax({
317
+                url: gettwilbalanceUrl + '/' + userid,
318
+                type: "POST",
319
+                data: { userid: userid },
320
+                cache: false,
321
+                processData: false,
322
+                contentType: false,
323
+                success: function(currentbalancetwil) {
324
+
325
+                     $('#currentbalance').empty();
326
+                     $('#currentbalance').text(currentbalancetwil);
327
+                     $('#currentbalance').removeClass('icon-loading');
328
+                }
329
+            });
330
+          }
331
+
332
+          gettwilbalance();
333
+
334
+     } else if (provider == "Flowroute") {
335
+
336
+          var getflowbalance = function() {
337
+
338
+            $('#currentbalance').addClass('icon-loading');
339
+
340
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
341
+
342
+            $.ajax({
343
+                url: getflowbalanceUrl + '/' + userid,
344
+                type: "POST",
345
+                data: { userid: userid },
346
+                cache: false,
347
+                processData: false,
348
+                contentType: false,
349
+                success: function(currentbalanceflow) {
350
+
351
+                     $('#currentbalance').empty();
352
+                     $('#currentbalance').text(currentbalanceflow);
353
+                     $('#currentbalance').removeClass('icon-loading');
354
+                }
355
+            });
356
+          }
357
+
358
+          getflowbalance();
359
+
360
+       } else if (provider == "") {
361
+                $('#currentbalance').text("");
362
+                $('#currentbalance').removeClass('icon-loading');
363
+       }
364
+  });
365
+
366
+
367
+  // If a Sender ID is selected
368
+  $("#currentsmsnmbrs").on("change", function () {
369
+
370
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
371
+
372
+              selectedid = $('#currentsmsnmbrs :selected').val();
373
+              var setIdsplit = selectedid.split(":");
374
+	      chosenProvider = setIdsplit[0];
375
+
376
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
377
+	      if (chosenProvider == "Tx") {
378
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
379
+		  // Maximum size of message text + files in KB
380
+		  maximumsize = 1024;
381
+                  maximumsizeinit = 1024;
382
+		  maxsizenonimage = 600;
383
+		  maximumfilenumber = 10;
384
+                  chosenProvFullName = "Telnyx";
385
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
386
+                                     or gif files, the size of all the files plus the size of the text should be \
387
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
388
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
389
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
390
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
391
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
392
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
393
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
394
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
395
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
396
+                  $("#tooltiptextfourth").html(infonotecontent);
397
+	      } else if (chosenProvider == "Pl") {
398
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
399
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
400
+		  // Maximum size of message text + files in KB
401
+		  maximumsize = 5120;
402
+                  maximumsizeinit = 5120;
403
+		  maxsizenonimage = 600;
404
+		  maximumfilenumber = 10;
405
+                  chosenProvFullName = "Plivo";
406
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
407
+                                     or gif files, the size of all the files plus the size of the text should be \
408
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
409
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
410
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
411
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
412
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
413
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
414
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
415
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
416
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
417
+                  $("#tooltiptextfourth").html(infonotecontent);
418
+	      } else if (chosenProvider == "Tw") {
419
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
420
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
421
+                                     "icalendar", "directory", "pdf", "pkpass"];
422
+		  // Maximum size of message text + files in KB
423
+		  maximumsize = 5120;
424
+                  maximumsizeinit = 5120;
425
+		  maxsizenonimage = 600;
426
+		  maximumfilenumber = 10;
427
+                  chosenProvFullName = "Twilio";
428
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
429
+                                     or gif files, the size of all the files plus the size of the text should be \
430
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
431
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
432
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
433
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
434
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
435
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
436
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
437
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
438
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
439
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
440
+                                     previewed in the adjoining pane."
441
+                  $("#tooltiptextfourth").html(infonotecontent);
442
+	      } else if (chosenProvider == "Fl") {
443
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
444
+		  // Maximum size of message text + files in KB
445
+		  maximumsize = 750;
446
+                  maximumsizeinit = 750;
447
+		  maxsizenonimage = 600;
448
+		  maximumfilenumber = 10;
449
+                  chosenProvFullName = "Flowroute";
450
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
451
+                                     png or gif files, the size of all the files plus the size of the text should be \
452
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
453
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
454
+                                     size of the files plus the size of the text should be 600 KB or less. \
455
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
456
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
457
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
458
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
459
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
460
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
461
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
462
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
463
+                  $("#tooltiptextfourth").html(infonotecontent);
464
+	      }
465
+
466
+          } else { selectedid = ''; }
467
+  });
468
+
469
+  // Check the checkbox to send SMS message to multiple recipients
470
+  $('#tomultchckbx').change(function() {
471
+      if ($(this).is(':checked')) {
472
+          $("#multiplerecivers").css("display", "block");
473
+          $("#smstodiv").css("visibility", "hidden");
474
+          $("#smsto").val("");
475
+
476
+          receiversNumbers.length = 0;
477
+
478
+      } else {
479
+          $("#multiplerecivers").css("display", "none");
480
+          $("#smstodiv").css("visibility", "visible");
481
+
482
+          // Remove the uploaded file(s) if any
483
+          $("#induploadfile").remove();
484
+
485
+          receiversNumbers.length = 0;
486
+      }
487
+  });
488
+
489
+  // Upload the file with the recipients' phone numbers
490
+  $("#uploadfileforsms").change(function(e) {
491
+
492
+     $("#fileuploadednm").empty();
493
+
494
+     receiversNumbers.length = 0;
495
+
496
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
497
+
498
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
499
+
500
+     var formData = new FormData();
501
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
502
+
503
+     var fileup = $('#uploadfileforsms').val();
504
+     var fileuptrim = fileup.split('\\').pop();
505
+
506
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
507
+
508
+     var extension = fileup.replace(/^.*\./, '');
509
+
510
+     if (extension == fileup) {
511
+         extension = "";
512
+     } else {
513
+         extension = extension.toLowerCase();
514
+     }
515
+
516
+     var validExtensionsmrec = ["txt", "csv"];
517
+
518
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
519
+
520
+       if (selectedid != '') {
521
+
522
+               $.ajax({
523
+                 url: baseUrl + '/' + userid,
524
+                 type: "POST",
525
+                 data: formData,
526
+                 cache: false,
527
+                 processData: false,
528
+                 contentType: false,
529
+                 success: function(numberarray) {
530
+
531
+		    if (numberarray.length > 0) {
532
+
533
+		        // Get the array of the receivers' phone numbers
534
+		        if (chosenProvider == "Tx") {
535
+
536
+		             for(key in numberarray) {
537
+		                 receiversNumbers.push("+"+numberarray[key]);
538
+		             }
539
+
540
+		        } else if (chosenProvider == "Pl") {
541
+
542
+		             for(key in numberarray) {
543
+		                 receiversNumbers.push(numberarray[key]);
544
+		             }
545
+
546
+		          } else if (chosenProvider == "Tw") {
547
+
548
+		             for(key in numberarray) {
549
+		                 receiversNumbers.push(numberarray[key]);
550
+		             }
551
+		          } else if (chosenProvider == "Fl") {
552
+
553
+		             for(key in numberarray) {
554
+		                 receiversNumbers.push(numberarray[key]);
555
+		             }
556
+		          }
557
+
558
+		    } else {
559
+//		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
560
+                          showAlert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
561
+		    }
562
+                            
563
+                    // Preview the uploaded file
564
+                    var smsfilename = e.target.files[0].name;
565
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
566
+
567
+                    var reader = new FileReader();
568
+                    reader.readAsText(e.target.files[0]);
569
+                    reader.onload = function(e) {
570
+                          $("#smstables").empty();
571
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
572
+                    };
573
+
574
+                    $("#smstables").show();
575
+
576
+                    $('#sms_upload_msg').hide();
577
+                    $('#smstables').removeClass('icon-loading');
578
+
579
+                  },
580
+                  error: function() {
581
+//                     alert('Error!');
582
+                             showAlert("Error while uploading the file.");
583
+                  }
584
+               });
585
+
586
+        } else {
587
+//               alert("Please choose a Sender ID from the Set ID drop-down list!");
588
+               showAlert("Please choose a Sender ID from the Set ID drop-down list!");
589
+               $('#sms_upload_msg').hide();
590
+               $('#smstables').removeClass('icon-loading');
591
+        }
592
+
593
+     } else {
594
+//          alert('The file type is not supported ! Supported formats are txt and csv.');
595
+          showAlert("The file type is not supported ! Supported formats are txt and csv.");
596
+          $('#pf_upload_msg').hide();
597
+          $('#smstables').removeClass('icon-loading');
598
+
599
+          $("#induploadfile").remove();
600
+          $("#sms_upload_msg").hide();
601
+     }
602
+
603
+     //Preview uploaded file when clicked
604
+     $("#indfilediv").on("click", function() {
605
+
606
+          var smsfilename = e.target.files[0].name;
607
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
608
+
609
+          var reader = new FileReader();
610
+          reader.readAsText(e.target.files[0]);
611
+          reader.onload = function(e) {
612
+                  $("#smstables").empty();
613
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
614
+          };
615
+
616
+          $("#smstables").show();
617
+          $('#sms_upload_msg').hide();
618
+          $('#smstables').removeClass('icon-loading');
619
+     });
620
+
621
+     // Remove selected file
622
+     $("#indivflremove").on("click", function() {
623
+
624
+          $("#induploadfile").remove();
625
+          $("#sms_upload_msg").hide();
626
+
627
+          receiversNumbers.length = 0;
628
+
629
+     });
630
+
631
+  });
632
+
633
+  // Show the number of characters entered in the SMS textarea and the text size in KB
634
+  $("#smstext").on('input', function() {
635
+
636
+     $("#char_count").css("display", "inline");
637
+
638
+     $("#mtextSize").css("display", "inline");
639
+
640
+     $(".maxmessagelength").css("display", "inline-block");
641
+
642
+     $("#countchnb").text($(this).val().length);
643
+
644
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
645
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
646
+     $("#textsizeinkb").text(textsizekb);
647
+
648
+     if ($(this).val().length > charcolorthr) {
649
+         $("#char_count").css("color", "#BB2E4B");
650
+     } else {
651
+         $("#char_count").css("color", "#4cbc86;");
652
+     }
653
+
654
+  });
655
+
656
+
657
+  // Check the checkbox to send file(s) as MMS
658
+  $('#mediafilechckbx').change(function() {
659
+
660
+      if ($(this).is(':checked')) {
661
+
662
+          isMMS = 1;
663
+          if (selectedid == '') {
664
+//              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
665
+              showAlert("Please, first choose a Sender ID from the Set ID drop-down list !");
666
+              $(this).prop("checked", false);
667
+              isMMS = 0;
668
+              return;
669
+          }
670
+          $("#upmediafiles").css("display", "block");
671
+          $("#submitsms").prop("value", "Send MMS");
672
+
673
+      } else {
674
+
675
+          isMMS = 0;
676
+          $("#upmediafiles").css("display", "none");
677
+          $("#submitsms").prop("value", "Send SMS");
678
+
679
+          // Remove the uploaded file(s) if any
680
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
681
+          $(".indgenpckfls").each(function() { $(this).remove(); });
682
+
683
+          uploadedtomms = [];
684
+          n = 1;
685
+
686
+          msgtotalflsize = 0;
687
+
688
+          $("#filestotsize").hide();
689
+      }
690
+  });
691
+
692
+
693
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
694
+  function adjustMaximumSize(uploadedtomms) {
695
+				      
696
+      var nonimgcheck = 0;
697
+      for (var u = 0; u < uploadedtomms.length; u++) {
698
+	   var crupfl = uploadedtomms[u];
699
+	   var extensionup = crupfl.replace(/^.*\./, '');
700
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
701
+	       nonimgcheck = 1;
702
+	   }
703
+      }
704
+
705
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
706
+  }
707
+
708
+  // Upload files to be sent as MMS
709
+  $("#uploadfileformms").change(function(e) {
710
+
711
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
712
+     $('#smstables').addClass('icon-loading');
713
+     $('#filestotsize').show();
714
+
715
+     var userid = "<?php p($userId); ?>";
716
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
717
+
718
+     var formData = new FormData();
719
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
720
+
721
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
722
+
723
+     // Add the size of the current file to the total size of all the files
724
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
725
+
726
+     var fileup = $('#uploadfileformms').val();
727
+     var fileuptrim = fileup.split('\\').pop();
728
+
729
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
730
+         var duplicatescheck = 1;
731
+     } else { 
732
+         var duplicatescheck = 0;
733
+     }
734
+
735
+     var extension = fileup.replace(/^.*\./, '');
736
+
737
+     if (extension == fileup) {
738
+         extension = "";
739
+     } else {
740
+         extension = extension.toLowerCase();
741
+     }
742
+
743
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
744
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
745
+         maximumsize = maxsizenonimage;
746
+     }
747
+
748
+     if ($.inArray(extension, validExtensions) != -1) {
749
+
750
+       if (duplicatescheck == 0) {
751
+
752
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
753
+
754
+            if (n <= maximumfilenumber) {
755
+
756
+               $.ajax({
757
+                 url: baseUrl + '/' + userid,
758
+                 type: "POST",
759
+                 data: formData,
760
+                 cache: false,
761
+                 processData: false,
762
+                 contentType: false,
763
+                 success: function(totalflsize) {
764
+
765
+                   uploadedtomms.push(fileuptrim);
766
+
767
+                   $('#filessizetext').text(totalflsize);
768
+
769
+                   var rectotfilesz = parseFloat(totalflsize);
770
+
771
+                   if (rectotfilesz <= maximumsize) {
772
+                       $('#submitsms').attr("disabled", false);
773
+                       $('#filestotsize').css('color', '#189558');
774
+                   } else {
775
+                       $('#filestotsize').css('color', '#ba3555');
776
+//                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
777
+                       showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
778
+                       $('#submitsms').attr("disabled", true);
779
+                       $('#smstables').removeClass('icon-loading');
780
+                       $('#pf_upload_msg').hide();
781
+                   }
782
+
783
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
784
+                   n++;
785
+
786
+                   // Preview the file when you click on its name
787
+                   $("div:visible[id*='indfilediv']").each(function() {
788
+
789
+                        $(this).on("click", function(eventclck) {
790
+
791
+                           $("#mmsfoldersview").css("display", "inline-block");
792
+                           var mmsfilenameinit = $(this).text();
793
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
794
+                           var mmsfilename = mmsfilenamesec.replace("X","");
795
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
796
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
797
+
798
+                           if (extenlst == mmsfilename) {
799
+                               extenlst = "";
800
+                           } else {
801
+                               extenlst = extenlst.toLowerCase();
802
+                           }
803
+
804
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
805
+                                  $("#smstables").empty();
806
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
807
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
+                           } else if (extenlst == 'png') {
809
+                                  $("#smstables").empty();
810
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
811
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
812
+                           } else if (extenlst == 'gif') {
813
+                                  $("#smstables").empty();
814
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
815
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
816
+                           } else if (extenlst == 'bmp') {
817
+                                  $("#smstables").empty();
818
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
819
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
820
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
821
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
822
+                                  var xhr = new XMLHttpRequest();
823
+                                  xhr.responseType = 'arraybuffer';
824
+                                  xhr.open('GET', tiffile);
825
+                                  xhr.onload = function (evnt) {
826
+                                      var tiff = new Tiff({buffer: xhr.response});
827
+                                      var tifcanvas = tiff.toCanvas();
828
+                                      $("#smstables").empty();
829
+                                      $("#smstables").append(tifcanvas);
830
+                                  };
831
+                                  xhr.send();
832
+                           } else if (extenlst == 'pdf') {
833
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
834
+                                  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>');
835
+                                  $("#smstables").empty();
836
+                                  $("#smstables").append($iframe);
837
+                           } else if (extenlst == 'txt') {
838
+                                  $("#smstables").empty();
839
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
840
+                           } else if (extension == 'mp4') {
841
+                                  $("#smstables").empty();
842
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
843
+		           } else if (extension == 'ogg') {
844
+		                  $("#smstables").empty();
845
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
846
+		           } else if (extension == 'avi') {
847
+		                  $("#smstables").empty();
848
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
849
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
850
+		                  $("#smstables").empty();
851
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
852
+		           } else if (extension == 'wav' || extension == 'wave') {
853
+		                  $("#smstables").empty();
854
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
855
+		           } else if (extension == 'mp3') {
856
+		                  $("#smstables").empty();
857
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
858
+		           } else if (extension == 'midi') {
859
+		                  $("#smstables").empty();
860
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
861
+		           }
862
+
863
+                           $("#smstables").show();
864
+                           $("#mmsfoldersview").hide();
865
+                        });
866
+                   });
867
+
868
+                   // Remove uploaded files
869
+                   $('[class*="indupfldl"]').last().click(function() {
870
+
871
+                           var userid = "<?php p($userId); ?>";
872
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
873
+
874
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
875
+
876
+                           var removedfilesplit = removedfilenameinit.split(") ");
877
+                           var removedflnb = parseInt(removedfilesplit[0]);
878
+
879
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
880
+                           $(this).hide();
881
+
882
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
883
+
884
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
885
+                                           return value != removedfilename;
886
+                           });
887
+
888
+                           $.ajax({
889
+                                   url: baseUrl + '/' + userid,
890
+                                   type: "POST",
891
+                                   data: {removedfilename: removedfilename},
892
+                                   success: function(totalflsize) {
893
+
894
+                                      msgtotalflsize = totalflsize;
895
+                                      $('#filessizetext').text(totalflsize);
896
+
897
+                                      adjustMaximumSize(uploadedtomms);
898
+
899
+                                      // Check message size
900
+                                      var rectotfilesz = parseFloat(totalflsize);
901
+
902
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
903
+                                          $('#submitsms').attr("disabled", false);
904
+                                          $('#filestotsize').css('color', '#189558');
905
+                                      } else {
906
+                                          $('#filestotsize').css('color', '#ba3555');
907
+//                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
908
+                                          showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
909
+                                          $('#submitsms').attr("disabled", true);
910
+                                      }
911
+
912
+                                      // Rewrite order numbers for files that follow
913
+                                      --n;
914
+                                      $("div:visible[id*='indfilediv']").each(function() {
915
+
916
+                                          var getdivtext =  $(this).text();
917
+                                          var splitdivtext = getdivtext.split(") ");
918
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
919
+                                          var newnbvalue = currentnbvalue - 1;
920
+
921
+                                          if (currentnbvalue > removedflnb) {
922
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
923
+                                              $(this).text(replacedstr);
924
+                                          }
925
+                                      });
926
+
927
+                                      $("div:visible[id*='indflpicked']").each(function() {
928
+
929
+                                          var getdivtext =  $(this).text();
930
+                                          var splitdivtext = getdivtext.split(") ");
931
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
932
+                                          var newnbvalue = currentnbvalue - 1;
933
+
934
+                                          if (currentnbvalue > removedflnb) {
935
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
936
+                                              $(this).text(replacedstr);
937
+                                          }
938
+                                      });
939
+
940
+                                   },
941
+                                   error: function() {
942
+//                                          alert('Error removing file(s)!');
943
+                                              showAlert("Error while removing the file(s).");
944
+                                   }
945
+                           });
946
+
947
+                           $('#smstables').removeClass('icon-loading');
948
+                           $("#smstables").empty();
949
+                   });
950
+
951
+                   // Preview the uploaded file
952
+                   $("#mmsfoldersview").css("display", "inline-block");
953
+                   var mmsfilename = e.target.files[0].name;
954
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
955
+
956
+
957
+                   if (extension == 'jpg' || extension == 'jpeg') {
958
+                              $("#smstables").empty();
959
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
960
+
961
+                              var reader = new FileReader();
962
+                              reader.onload = function (e) {
963
+                                  readjpg[mmsfilename] = e.target.result;
964
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
965
+                              }
966
+                              reader.readAsDataURL(e.target.files[0]);
967
+                   } else if (extension == 'png') {
968
+                              $("#smstables").empty();
969
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
970
+
971
+                              var reader = new FileReader();
972
+                              reader.onload = function (e) {
973
+                                  readpng[mmsfilename] = e.target.result;
974
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
975
+                              }
976
+                              reader.readAsDataURL(e.target.files[0]);
977
+
978
+                   } else if (extension == 'gif') {
979
+                              $("#smstables").empty();
980
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
981
+
982
+                              var reader = new FileReader();
983
+                              reader.onload = function (e) {
984
+                                  readgif[mmsfilename] = e.target.result;
985
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
986
+                              }
987
+                              reader.readAsDataURL(e.target.files[0]);
988
+
989
+                   } else if (extension == 'bmp') {
990
+                              $("#smstables").empty();
991
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
992
+
993
+                              var reader = new FileReader();
994
+                              reader.onload = function (e) {
995
+                                  readbmp[mmsfilename] = e.target.result;
996
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
997
+                              }
998
+                              reader.readAsDataURL(e.target.files[0]);
999
+
1000
+                   } else if (extension == 'tif' || extension == 'tiff') {
1001
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1002
+                              var xhr = new XMLHttpRequest();
1003
+                              xhr.responseType = 'arraybuffer';
1004
+                              xhr.open('GET', tiffile);
1005
+                              xhr.onload = function (e) {
1006
+                                  var tiff = new Tiff({buffer: xhr.response});
1007
+                                  var tifcanvas = tiff.toCanvas();
1008
+                                  $("#smstables").empty();
1009
+                                  $("#smstables").append(tifcanvas);
1010
+                              };
1011
+                              xhr.send();
1012
+
1013
+                   } else if (extension == 'pdf') {
1014
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1015
+                              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>');
1016
+                              $("#smstables").empty();
1017
+                              $("#smstables").append($iframe);
1018
+
1019
+                   } else if (extension == 'txt') {
1020
+                              var reader = new FileReader();
1021
+                              reader.readAsText(e.target.files[0]);
1022
+                              reader.onload = function(e) {
1023
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
1024
+                                  $("#smstables").empty();
1025
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
1026
+                              };
1027
+                   } else if (extension == 'mp4') {
1028
+                              $("#smstables").empty();
1029
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1030
+                   } else if (extension == 'ogg') {
1031
+                              $("#smstables").empty();
1032
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1033
+                   } else if (extension == 'avi') {
1034
+                              $("#smstables").empty();
1035
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1036
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
1037
+                              $("#smstables").empty();
1038
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1039
+                   } else if (extension == 'wav' || extension == 'wave') {
1040
+                              $("#smstables").empty();
1041
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1042
+                   } else if (extension == 'mp3') {
1043
+                              $("#smstables").empty();
1044
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1045
+                   } else if (extension == 'midi') {
1046
+                              $("#smstables").empty();
1047
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1048
+                   }
1049
+
1050
+                   $("#smstables").show();
1051
+                   $('#pf_upload_msg').hide();
1052
+                   $('#smstables').removeClass('icon-loading');
1053
+                   $("#mmsfoldersview").hide();
1054
+                 },
1055
+                 error: function() {
1056
+//                     alert('Error uploading file!');
1057
+                              showAlert("Error while uploading the file.");
1058
+                 }
1059
+               });
1060
+
1061
+            } else {
1062
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1063
+                  adjustMaximumSize(uploadedtomms);
1064
+
1065
+//                  alert("Error ! You cannot send more than 10 files in one MMS !");
1066
+                  showAlert("Error! You cannot send more than 10 files in one MMS !");
1067
+                  $('#pf_upload_msg').hide();
1068
+                  $('#smstables').removeClass('icon-loading');
1069
+            }
1070
+         } else {
1071
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1072
+              adjustMaximumSize(uploadedtomms);
1073
+
1074
+//              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
1075
+              showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot be greater than "+ maxsizenonimage +" KB !");
1076
+              $('#pf_upload_msg').hide();
1077
+              $('#smstables').removeClass('icon-loading');
1078
+         }
1079
+       } else {
1080
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1081
+            adjustMaximumSize(uploadedtomms);
1082
+
1083
+//            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
1084
+            showAlert("Error ! There is already a file named '"+ fileuptrim +"' in the 'SMS_Relentless/temp_files' folder !");
1085
+            $('#pf_upload_msg').hide();
1086
+            $('#smstables').removeClass('icon-loading');
1087
+       }
1088
+
1089
+     } else {
1090
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
1091
+          adjustMaximumSize(uploadedtomms);
1092
+
1093
+//          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1094
+          showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1095
+          $('#pf_upload_msg').hide();
1096
+          $('#smstables').removeClass('icon-loading');
1097
+     }
1098
+  });
1099
+
1100
+
1101
+  // Pick file(s) from Nextcloud, to send as MMS
1102
+  var mmsfilename = null;
1103
+
1104
+  $("#choosefilen").on("click", function(evn) {
1105
+
1106
+                OC.dialogs.filepicker(
1107
+                        t('settings', "Select a file to send as MMS."),
1108
+                        function (path) {
1109
+
1110
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
1111
+                              $('#smstables').addClass('icon-loading');
1112
+                              $('#filestotsize').show();
1113
+
1114
+                              var userid = "<?php p($userId); ?>";
1115
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
1116
+
1117
+                              mmsfilename = path.split('/').pop();
1118
+
1119
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
1120
+                                  var duplicatescheck = 1;
1121
+                              } else var duplicatescheck = 0;
1122
+
1123
+                              var extension = mmsfilename.replace(/^.*\./, '');
1124
+
1125
+                              if (extension == mmsfilename) {
1126
+                                  extension = "";
1127
+                              } else {
1128
+                                  extension = extension.toLowerCase();
1129
+                              }
1130
+
1131
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
1132
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
1133
+				   maximumsize = maxsizenonimage;
1134
+			      }
1135
+
1136
+                              if ($.inArray(extension, validExtensions) != -1) {
1137
+
1138
+                                 if (duplicatescheck == 0) {
1139
+
1140
+                                    if (n <= maximumfilenumber) {
1141
+
1142
+                                       $.ajax({
1143
+                                          url: baseUrl + '/' + userid,
1144
+                                          type: "POST",
1145
+                                          data: { path: path },
1146
+                                          success: function(pickresult) {
1147
+
1148
+                                                uploadedtomms.push(mmsfilename);
1149
+
1150
+                                                var totalflsize = pickresult[0];
1151
+                                                var pickedflsize = pickresult[1];
1152
+
1153
+                                                // Check message size
1154
+                                                var rectotfilesz = parseFloat(totalflsize);
1155
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
1156
+
1157
+                                                if (filesplustextsize <= maximumsize) {
1158
+
1159
+                                                    $("#mmsfoldersview").css("display", "inline-block");
1160
+
1161
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1162
+                                                    n++;
1163
+
1164
+                                                    msgtotalflsize = totalflsize;
1165
+                                                    $('#filessizetext').text(totalflsize);
1166
+                                                    $('#filestotsize').css('color', '#189558');
1167
+
1168
+                                                } else {
1169
+
1170
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1171
+                                                    $('#filestotsize').css('color', '#ba3555');
1172
+                                                    msgtotalflsize -= pickedflsize;
1173
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1174
+
1175
+                                                    $.ajax({
1176
+                                                        url: baseUrlindrm + '/' + userid,
1177
+                                                        type: "POST",
1178
+                                                        data: {removedfilename: mmsfilename},
1179
+                                                        success: function(totalflsize) {
1180
+
1181
+                                                                          $('#filessizetext').text(totalflsize);
1182
+                                                                          $('#filestotsize').css('color', '#189558');
1183
+                                                                          adjustMaximumSize(uploadedtomms);
1184
+
1185
+                                                        },
1186
+                                                        error: function(totalflsize) {
1187
+                                                                          $('#filessizetext').text(totalflsize);
1188
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1189
+                                                                              $('#filestotsize').css('color', '#ba3555');
1190
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1191
+//                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1192
+                                                                          showAlert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!");
1193
+                                                        }
1194
+                                                    });
1195
+
1196
+//                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1197
+                                                    showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1198
+                                                }
1199
+
1200
+
1201
+                                                // Preview each file when you click on its name
1202
+                                                $("div:visible[id*='indflpicked']").each(function() {
1203
+                                                   $(this).on("click", function(event) {
1204
+
1205
+                                                      var mmsfilenameinit = $(this).text();
1206
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1207
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1208
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1209
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1210
+
1211
+                                                      if (extenlst == mmsfilenamesp) {
1212
+                                                           extenlst = "";
1213
+                                                      } else {
1214
+                                                           extenlst = extenlst.toLowerCase();
1215
+                                                      }
1216
+
1217
+
1218
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1219
+                                                              $("#smstables").empty();
1220
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1221
+                                                      } else if (extenlst == 'png') {
1222
+                                                              $("#smstables").empty();
1223
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1224
+                                                      } else if (extenlst == 'gif') {
1225
+                                                              $("#smstables").empty();
1226
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1227
+                                                      } else if (extenlst == 'bmp') {
1228
+                                                              $("#smstables").empty();
1229
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1230
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1231
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1232
+                                                              var xhr = new XMLHttpRequest();
1233
+                                                              xhr.responseType = 'arraybuffer';
1234
+                                                              xhr.open('GET', tiffile);
1235
+                                                              xhr.onload = function (evnt) {
1236
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1237
+                                                                  var tifcanvas = tiff.toCanvas();
1238
+                                                                  $("#smstables").empty();
1239
+                                                                  $("#smstables").append(tifcanvas);
1240
+                                                              };
1241
+                                                              xhr.send();
1242
+                                                      } else if (extenlst == 'pdf') {
1243
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1244
+                                                              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>');
1245
+                                                              $("#smstables").empty();
1246
+                                                              $("#smstables").append($iframe);
1247
+                                                      } else if (extenlst == 'txt') {
1248
+                                                              $("#smstables").empty();
1249
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1250
+                                                      } else if (extension == 'mp4') {
1251
+							      $("#smstables").empty();
1252
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1253
+						      } else if (extension == 'ogg') {
1254
+							      $("#smstables").empty();
1255
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1256
+						      } else if (extension == 'avi') {
1257
+							      $("#smstables").empty();
1258
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1259
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1260
+							      $("#smstables").empty();
1261
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1262
+						      } else if (extension == 'wav' || extension == 'wave') {
1263
+							      $("#smstables").empty();
1264
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1265
+						      } else if (extension == 'mp3') {
1266
+							      $("#smstables").empty();
1267
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1268
+						      } else if (extension == 'midi') {
1269
+							      $("#smstables").empty();
1270
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1271
+						      }
1272
+
1273
+
1274
+                                                      $("#smstables").show();
1275
+                                                      $("#mmsfoldersview").hide();
1276
+                                                   });
1277
+                                                });
1278
+
1279
+
1280
+                                                // Remove picked files
1281
+                                                $('[class*="indpckfldl"]').last().click(function() {
1282
+                                                    var userid = "<?php p($userId); ?>";
1283
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1284
+
1285
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1286
+
1287
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1288
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1289
+
1290
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1291
+                                                    $(this).hide();
1292
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1293
+
1294
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1295
+                                                             return value != removedfilename;
1296
+                                                    });
1297
+
1298
+                                                    $.ajax({
1299
+                                                        url: baseUrl + '/' + userid,
1300
+                                                        type: "POST",
1301
+                                                        data: {removedfilename: removedfilename},
1302
+                                                        success: function(totalflsize) {
1303
+
1304
+                                                             msgtotalflsize = totalflsize;
1305
+                                                             $('#filessizetext').text(totalflsize);
1306
+                                                             adjustMaximumSize(uploadedtomms);
1307
+
1308
+                                                             // Check message size
1309
+                                                             var rectotfilesz = parseFloat(totalflsize);
1310
+
1311
+                                                             if (rectotfilesz > maximumsize) {
1312
+                                                                 $('#filestotsize').css('color', '#ba3555');
1313
+//                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1314
+                                                                 showAlert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1315
+                                                                 $('#submitsms').attr("disabled", true);
1316
+                                                             } else {
1317
+                                                                 $('#submitsms').attr("disabled", false);
1318
+                                                                 $('#filestotsize').css('color', '#189558');
1319
+                                                               }
1320
+
1321
+                                                             // Rewrite order numbers for files that follow
1322
+                                                             --n;
1323
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1324
+
1325
+                                                                  var getdivtext =  $(this).text();
1326
+                                                                  var splitdivtext = getdivtext.split(") ");
1327
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1328
+                                                                  var newnbvalue = currentnbvalue - 1;
1329
+
1330
+                                                                  if (currentnbvalue > removedflnb) {
1331
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1332
+                                                                      $(this).text(replacedstr);
1333
+                                                                  }
1334
+                                                             });
1335
+                                                        },
1336
+                                                        error: function() {
1337
+//                                                             alert('Error !');
1338
+                                                                  showAlert("Error while removing the file.");
1339
+                                                        }
1340
+                                                    });
1341
+
1342
+                                                    $('#smstables').removeClass('icon-loading');
1343
+                                                    $("#smstables").empty();
1344
+                                                });
1345
+
1346
+
1347
+		                                // Preview the picked file
1348
+		                                $("#mmsfoldersview").css("display", "inline-block");
1349
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1350
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1351
+
1352
+
1353
+						if (extension == 'jpg' || extension == 'jpeg') {
1354
+
1355
+		                                            $("#smstables").empty();
1356
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1357
+
1358
+		                                } else if (extension == 'png') {
1359
+
1360
+		                                            $("#smstables").empty();
1361
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1362
+
1363
+		                                } else if (extension == 'gif') {
1364
+
1365
+		                                            $("#smstables").empty();
1366
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1367
+
1368
+		                                } else if (extension == 'bmp') {
1369
+
1370
+	                                                    $("#smstables").empty();
1371
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1372
+
1373
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1374
+
1375
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1376
+		                                       var xhr = new XMLHttpRequest();
1377
+		                                       xhr.responseType = 'arraybuffer';
1378
+		                                       xhr.open('GET', tiffile);
1379
+		                                       xhr.onload = function (event) {
1380
+		                                           var tiff = new Tiff({buffer: xhr.response});
1381
+		                                           var tifcanvas = tiff.toCanvas();
1382
+		                                           $("#smstables").empty();
1383
+		                                           $("#smstables").append(tifcanvas);
1384
+		                                       };
1385
+		                                       xhr.send();
1386
+
1387
+		                                } else if (extension == 'pdf') {
1388
+
1389
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1390
+		                                       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>');
1391
+		                                       $("#smstables").empty();
1392
+		                                       $("#smstables").append($iframe);
1393
+
1394
+		                                } else if (extension == 'txt') {
1395
+
1396
+							     $.get(flUrl, function(textdata) {
1397
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1398
+		                                               $("#smstables").empty();
1399
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1400
+							     });
1401
+
1402
+		                                } else if (extension == 'mp4') {
1403
+						       $("#smstables").empty();
1404
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1405
+						} else if (extension == 'ogg') {
1406
+						       $("#smstables").empty();
1407
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1408
+						} else if (extension == 'avi') {
1409
+						       $("#smstables").empty();
1410
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1411
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1412
+						       $("#smstables").empty();
1413
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1414
+						} else if (extension == 'wav' || extension == 'wave') {
1415
+						       $("#smstables").empty();
1416
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1417
+						} else if (extension == 'mp3') {
1418
+						       $("#smstables").empty();
1419
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1420
+						} else if (extension == 'midi') {
1421
+						       $("#smstables").empty();
1422
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1423
+						}
1424
+
1425
+
1426
+		                                $("#smstables").show();
1427
+
1428
+		                                $('#pf_choose_msg').hide();
1429
+		                                $('#smstables').removeClass('icon-loading');
1430
+		                                $("#mmsfoldersview").hide();
1431
+
1432
+                                          },
1433
+
1434
+                                          error: function(data){
1435
+//                                             alert('Error!');
1436
+                                                showAlert("Error while getting the file.");
1437
+                                          }
1438
+
1439
+                                       });
1440
+
1441
+                                    } else {
1442
+//                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1443
+                                        showAlert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1444
+                                        $('#pf_choose_msg').hide();
1445
+                                        $('#smstables').removeClass('icon-loading');
1446
+                                      }
1447
+                                 } else {
1448
+//                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1449
+                                      showAlert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1450
+                                      $('#pf_choose_msg').hide();
1451
+                                      $('#smstables').removeClass('icon-loading');
1452
+                                   }
1453
+
1454
+                              } else {
1455
+//                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1456
+                                   showAlert("The file type is not supported! Supported extensions for "+ chosenProvFullName +" are: "+ validExtensions.join(", ") +".");
1457
+                                   $('#pf_choose_msg').hide();
1458
+                                   $('#smstables').removeClass('icon-loading');
1459
+                                }
1460
+
1461
+                        }
1462
+                );
1463
+  });
1464
+
1465
+
1466
+
1467
+  // Send the SMS/MMS message
1468
+  $("#submitsms").on("click", function(event) {
1469
+
1470
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1471
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1472
+     $("#sms_submit_msg").css("display", "inline-block");
1473
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1474
+
1475
+     if (selectedid != '') { 
1476
+
1477
+         var sendersplit = selectedid.split(":");
1478
+         var providercap = sendersplit[0];
1479
+         var provsec = sendersplit[1];
1480
+
1481
+         if (/[a-zA-Z]/.test(provsec)) {
1482
+             var alphanumcheck = true;
1483
+         } else { var alphanumcheck = false; }
1484
+
1485
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1486
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1487
+             var selectedsender = "+" + senderproc;
1488
+             var providerUsed = "telnyx";
1489
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1490
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1491
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1492
+             var providerUsed = "plivo";
1493
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1494
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1495
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1496
+             var selectedsender = "+" + senderproc;
1497
+             var providerUsed = "twilio";
1498
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1499
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1500
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1501
+             var selectedsender = "+" + senderproc;
1502
+             var providerUsed = "flowroute";
1503
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1504
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1505
+             var selectedsender = provsec;
1506
+             var providerUsed = "telnyx";
1507
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1508
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1509
+             var selectedsender = provsec;
1510
+             var providerUsed = "plivo";
1511
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1512
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1513
+             var selectedsender = provsec;
1514
+             var providerUsed = "twilio";
1515
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1516
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1517
+             var selectedsender = provsec;
1518
+             var providerUsed = "flowroute";
1519
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1520
+         }
1521
+
1522
+         // Get the interval between message consecutive sending requests, if it's the case
1523
+         if ($('#tomultchckbx').is(':checked')) {
1524
+
1525
+             var numbersfile = 1;
1526
+             var initinterval = $("#multsmsinterval").val();
1527
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1528
+
1529
+             if (secinterval != '') {
1530
+                 var tertinterval = parseInt(secinterval);
1531
+                     waittime = tertinterval;
1532
+             }
1533
+
1534
+         } else {
1535
+
1536
+             var numbersfile = 0;
1537
+             var toNumberinit = $('#smsto').val();
1538
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1539
+             var toNumbersec = toNumber.split(",");
1540
+
1541
+                 for (var i = 0; i < toNumbersec.length; i++) {
1542
+                      toNumbersec[i] = "+" + toNumbersec[i];
1543
+                 }
1544
+
1545
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1546
+         }
1547
+
1548
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1549
+
1550
+         var smstext = $("#smstext").val();
1551
+
1552
+         if (receiversNumbers.length != 0) {
1553
+
1554
+              if (smstext != '') {
1555
+                  $.ajax({
1556
+                     url: relbaseUrl + '/' + userid,
1557
+                     type: "POST",
1558
+                     data: {
1559
+                           receiversPhoneNbs: receiversNumbers,
1560
+                           fromsender: selectedsender,
1561
+                           waitinterval: waittime,
1562
+                           sentsmstext: smstext,
1563
+                           ismms: isMMS,
1564
+                           mmsfiles: uploadedtomms
1565
+                         },
1566
+                     success: function() {
1567
+
1568
+                           if (receiversNumbers.length == 1) {
1569
+//                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1570
+                               showAlert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1571
+                           } else {
1572
+//                               alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1573
+                               showAlert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1574
+                           }
1575
+
1576
+                           $('#sms_submit_msg').hide();
1577
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1578
+                     },
1579
+                     error: function() {
1580
+//                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1581
+                           showAlert("Error! Please check the recipient's phone number and your settings!");
1582
+                           $('#sms_submit_msg').hide();
1583
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1584
+                     }
1585
+                  });
1586
+              } else {
1587
+//                     alert("Please enter a message in the text box !");
1588
+                     showAlert("Please enter a message in the text box !");
1589
+
1590
+                     $('#sms_submit_msg').hide();
1591
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1592
+              }
1593
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1594
+//                 alert("Please enter the recipient's phone number !");
1595
+                 showAlert("Please enter the recipient's phone number !");
1596
+                 $('#sms_submit_msg').hide();
1597
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1598
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1599
+//                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1600
+                 showAlert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1601
+                 $('#sms_submit_msg').hide();
1602
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1603
+         }
1604
+     } else {
1605
+//           alert("Please choose a Sender ID from the Set ID drop-down list !");
1606
+           showAlert("Please choose a Sender ID from the Set ID drop-down list !");
1607
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1608
+           $('#sms_submit_msg').hide();
1609
+     }
1610
+
1611
+  });
1612
+
1613
+  // Check the checkbox to delete old messages from the database
1614
+  $('#deleteoldchckbox').change(function() {
1615
+     if ($(this).is(':checked')) {
1616
+         $("#deleteoldsms").css("display", "block");
1617
+     } else {
1618
+         $("#deleteoldsms").css("display", "none");
1619
+     }
1620
+  });
1621
+
1622
+  // Set the height of 3 info notes
1623
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1624
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1625
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1626
+
1627
+  $(window).resize(function() { 
1628
+     $('#setcalleridtp').css('height', $(window).height() - 160);
1629
+     $('#tonmbrformat').css('height', $(window).height() - 260);
1630
+     $('#uploadfileinfo').css('height', $(window).height() - 390);
1631
+  });
1632
+
1633
+
1634
+  function showAlert(alertText) {
1635
+
1636
+     let alertwnd = "<div id='alertMessage'>";
1637
+     alertwnd += "<a id='closeAlertWnd' title='Close this window'></a>";
1638
+     alertwnd += "<div id='alertTextWrap'>"+ alertText +"</div>";
1639
+     alertwnd += "<input type='submit' id='alertOk' value='OK'>";
1640
+     alertwnd += "</div>";
1641
+
1642
+     $("#content").append("<div id='alertMsgOverlay'></div>");
1643
+     $("#content").append(alertwnd);
1644
+
1645
+     let topDist = parseInt((window.innerHeight / 2).toFixed(2) - 152) +"px";
1646
+     let leftDist = parseInt((window.innerWidth / 2).toFixed(2) - 150) +"px";
1647
+     $("#alertMessage").css({ "top" : topDist, "left" : leftDist });
1648
+
1649
+     $("#closeAlertWnd").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1650
+     $("#alertMsgOverlay").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1651
+     $("#alertOk").click(function() { $("#alertMsgOverlay").remove(); $("#alertMessage").remove(); });
1652
+  }
Browse code

removed files to implement auto-reply fix, etc.

DoubleBastionAdmin authored on 20/05/2023 00:46:30
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1453 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-  // Clean the SMS_Relentless/temp_files directory
58
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
59
-
60
-  $.ajax({
61
-          url: cleanflUrl + '/' + userid,
62
-          type: "POST",
63
-          data: { userid: userid },
64
-          cache: false,
65
-          processData: false,
66
-          contentType: false
67
-  });
68
-  
69
-  // Check the available balance
70
-  $("#smsprovider").on("change", function () {
71
-
72
-     var provider = $('#smsprovider :selected').val();
73
-
74
-     if (provider == "Telnyx") {
75
-
76
-        var gettelbalance = function() {
77
-
78
-          $('#currentbalance').addClass('icon-loading');
79
-
80
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
81
-
82
-          $.ajax({
83
-              url: gettelbalanceUrl + '/' + userid,
84
-              type: "POST",
85
-              data: { userid: userid },
86
-              cache: false,
87
-              processData: false,
88
-              contentType: false,
89
-              success: function(currentbalancetel) {
90
-
91
-                     $('#currentbalance').empty();
92
-                     $('#currentbalance').text(currentbalancetel);
93
-                     $('#currentbalance').removeClass('icon-loading');
94
-              }
95
-          });
96
-        }
97
-
98
-        gettelbalance();
99
-
100
-     } else if (provider == "Plivo") {
101
-
102
-          var getnexbalance = function() {
103
-
104
-            $('#currentbalance').addClass('icon-loading');
105
-
106
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
107
-
108
-            $.ajax({
109
-                url: getnexbalanceUrl + '/' + userid,
110
-                type: "POST",
111
-                data: { userid: userid },
112
-                cache: false,
113
-                processData: false,
114
-                contentType: false,
115
-                success: function(currentbalancenex) {
116
-
117
-                     $('#currentbalance').empty();
118
-                     $('#currentbalance').text(currentbalancenex);
119
-                     $('#currentbalance').removeClass('icon-loading');
120
-                }
121
-            });
122
-          }
123
-
124
-          getnexbalance();
125
-
126
-     } else if (provider == "Twilio") {
127
-
128
-          var gettwilbalance = function() {
129
-
130
-            $('#currentbalance').addClass('icon-loading');
131
-
132
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
133
-
134
-            $.ajax({
135
-                url: gettwilbalanceUrl + '/' + userid,
136
-                type: "POST",
137
-                data: { userid: userid },
138
-                cache: false,
139
-                processData: false,
140
-                contentType: false,
141
-                success: function(currentbalancetwil) {
142
-
143
-                     $('#currentbalance').empty();
144
-                     $('#currentbalance').text(currentbalancetwil);
145
-                     $('#currentbalance').removeClass('icon-loading');
146
-                }
147
-            });
148
-          }
149
-
150
-          gettwilbalance();
151
-
152
-     } else if (provider == "Flowroute") {
153
-
154
-          var getflowbalance = function() {
155
-
156
-            $('#currentbalance').addClass('icon-loading');
157
-
158
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
159
-
160
-            $.ajax({
161
-                url: getflowbalanceUrl + '/' + userid,
162
-                type: "POST",
163
-                data: { userid: userid },
164
-                cache: false,
165
-                processData: false,
166
-                contentType: false,
167
-                success: function(currentbalanceflow) {
168
-
169
-                     $('#currentbalance').empty();
170
-                     $('#currentbalance').text(currentbalanceflow);
171
-                     $('#currentbalance').removeClass('icon-loading');
172
-                }
173
-            });
174
-          }
175
-
176
-          getflowbalance();
177
-
178
-       } else if (provider == "") {
179
-                $('#currentbalance').text("");
180
-                $('#currentbalance').removeClass('icon-loading');
181
-       }
182
-  });
183
-
184
-  // Select the Sender ID
185
-  $("#selectcalleridbttn").on("click", function(event) {
186
-
187
-     $('#selectcalleridbttn').addClass('icon-loading');
188
-
189
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
190
-
191
-     $.ajax({
192
-          url: getsmsnumbersUrl + '/' + userid,
193
-          type: "POST",
194
-          data: { userid: userid },
195
-          cache: false,
196
-          processData: false,
197
-          contentType: false,
198
-          success: function(currentnmbrs) {
199
-
200
-                     $('#currentsmsnmbrs').empty();
201
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
202
-
203
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
204
-                         var emptyinit = indsmsnmb.split(":");
205
-                         var emptysec = emptyinit[1];
206
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
207
-
208
-                         if (emptycheck != '') {
209
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
210
-                         }
211
-                     });
212
-
213
-                     $('#selectcalleridbttn').removeClass('icon-loading');
214
-          }
215
-     });
216
-  });
217
-
218
-  // If a Sender ID is selected, get it
219
-  $("#currentsmsnmbrs").on("change", function () {
220
-
221
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
222
-
223
-              selectedid = $('#currentsmsnmbrs :selected').val();
224
-              var setIdsplit = selectedid.split(":");
225
-	      chosenProvider = setIdsplit[0];
226
-
227
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
228
-	      if (chosenProvider == "Tx") {
229
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
230
-		  // Maximum size of message text + files in KB
231
-		  maximumsize = 1024;
232
-                  maximumsizeinit = 1024;
233
-		  maxsizenonimage = 600;
234
-		  maximumfilenumber = 10;
235
-                  chosenProvFullName = "Telnyx";
236
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
237
-                                     or gif files, the size of all the files plus the size of the text should be \
238
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
239
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
240
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
241
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
242
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
243
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
244
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
245
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
246
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
247
-                  $("#tooltiptextfourth").html(infonotecontent);
248
-	      } else if (chosenProvider == "Pl") {
249
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
250
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
251
-		  // Maximum size of message text + files in KB
252
-		  maximumsize = 5120;
253
-                  maximumsizeinit = 5120;
254
-		  maxsizenonimage = 600;
255
-		  maximumfilenumber = 10;
256
-                  chosenProvFullName = "Plivo";
257
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
258
-                                     or gif files, the size of all the files plus the size of the text should be \
259
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
260
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
261
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
262
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
263
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
264
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
265
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
266
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
267
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
268
-                  $("#tooltiptextfourth").html(infonotecontent);
269
-	      } else if (chosenProvider == "Tw") {
270
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
271
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
272
-                                     "icalendar", "directory", "pdf", "pkpass"];
273
-		  // Maximum size of message text + files in KB
274
-		  maximumsize = 5120;
275
-                  maximumsizeinit = 5120;
276
-		  maxsizenonimage = 600;
277
-		  maximumfilenumber = 10;
278
-                  chosenProvFullName = "Twilio";
279
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
280
-                                     or gif files, the size of all the files plus the size of the text should be \
281
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
282
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
283
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
284
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
285
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
286
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
287
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
288
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
289
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
290
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
291
-                                     previewed in the adjoining pane."
292
-                  $("#tooltiptextfourth").html(infonotecontent);
293
-	      } else if (chosenProvider == "Fl") {
294
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
295
-		  // Maximum size of message text + files in KB
296
-		  maximumsize = 750;
297
-                  maximumsizeinit = 750;
298
-		  maxsizenonimage = 600;
299
-		  maximumfilenumber = 10;
300
-                  chosenProvFullName = "Flowroute";
301
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
302
-                                     png or gif files, the size of all the files plus the size of the text should be \
303
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
304
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
305
-                                     size of the files plus the size of the text should be 600 KB or less. \
306
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
307
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
308
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
309
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
310
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
311
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
312
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
313
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
314
-                  $("#tooltiptextfourth").html(infonotecontent);
315
-	      }
316
-
317
-          } else { selectedid = ''; }
318
-  });
319
-
320
-  // Check the checkbox to send SMS message to multiple recipients
321
-  $('#tomultchckbx').change(function() {
322
-      if ($(this).is(':checked')) {
323
-          $("#multiplerecivers").css("display", "block");
324
-          $("#smstodiv").css("visibility", "hidden");
325
-          $("#smsto").val("");
326
-
327
-          receiversNumbers.length = 0;
328
-
329
-      } else {
330
-          $("#multiplerecivers").css("display", "none");
331
-          $("#smstodiv").css("visibility", "visible");
332
-
333
-          // Remove the uploaded file(s) if any
334
-          $("#induploadfile").remove();
335
-
336
-          receiversNumbers.length = 0;
337
-      }
338
-  });
339
-
340
-  // Upload the file with the recipients' phone numbers
341
-  $("#uploadfileforsms").change(function(e) {
342
-
343
-     $("#fileuploadednm").empty();
344
-
345
-     receiversNumbers.length = 0;
346
-
347
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
348
-
349
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
350
-
351
-     var formData = new FormData();
352
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
353
-
354
-     var fileup = $('#uploadfileforsms').val();
355
-     var fileuptrim = fileup.split('\\').pop();
356
-
357
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
358
-
359
-     var extension = fileup.replace(/^.*\./, '');
360
-
361
-     if (extension == fileup) {
362
-         extension = "";
363
-     } else {
364
-         extension = extension.toLowerCase();
365
-     }
366
-
367
-     var validExtensionsmrec = ["txt", "csv"];
368
-
369
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
370
-
371
-       if (selectedid != '') {
372
-
373
-               $.ajax({
374
-                 url: baseUrl + '/' + userid,
375
-                 type: "POST",
376
-                 data: formData,
377
-                 cache: false,
378
-                 processData: false,
379
-                 contentType: false,
380
-                 success: function(numberarray) {
381
-
382
-		    if (numberarray.length > 0) {
383
-
384
-		        // Get the array of the receivers' phone numbers
385
-		        if (chosenProvider == "Tx") {
386
-
387
-		             for(key in numberarray) {
388
-		                 receiversNumbers.push("+"+numberarray[key]);
389
-		             }
390
-
391
-		        } else if (chosenProvider == "Pl") {
392
-
393
-		             for(key in numberarray) {
394
-		                 receiversNumbers.push(numberarray[key]);
395
-		             }
396
-
397
-		          } else if (chosenProvider == "Tw") {
398
-
399
-		             for(key in numberarray) {
400
-		                 receiversNumbers.push(numberarray[key]);
401
-		             }
402
-		          } else if (chosenProvider == "Fl") {
403
-
404
-		             for(key in numberarray) {
405
-		                 receiversNumbers.push(numberarray[key]);
406
-		             }
407
-		          }
408
-
409
-		    } else {
410
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
411
-		    }
412
-                            
413
-                    // Preview the uploaded file
414
-                    var smsfilename = e.target.files[0].name;
415
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
416
-
417
-                    var reader = new FileReader();
418
-                    reader.readAsText(e.target.files[0]);
419
-                    reader.onload = function(e) {
420
-                          $("#smstables").empty();
421
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
422
-                    };
423
-
424
-                    $("#smstables").show();
425
-
426
-                    $('#sms_upload_msg').hide();
427
-                    $('#smstables').removeClass('icon-loading');
428
-
429
-                  },
430
-                  error: function(){
431
-                     alert('Error!');
432
-                  }
433
-               });
434
-
435
-        } else {
436
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
437
-               $('#sms_upload_msg').hide();
438
-               $('#smstables').removeClass('icon-loading');
439
-        }
440
-
441
-     } else {
442
-          alert('The file type is not supported ! Supported formats are txt and csv.');
443
-          $('#pf_upload_msg').hide();
444
-          $('#smstables').removeClass('icon-loading');
445
-
446
-          $("#induploadfile").remove();
447
-          $("#sms_upload_msg").hide();
448
-     }
449
-
450
-     //Preview uploaded file when clicked
451
-     $("#indfilediv").on("click", function() {
452
-
453
-          var smsfilename = e.target.files[0].name;
454
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
455
-
456
-          var reader = new FileReader();
457
-          reader.readAsText(e.target.files[0]);
458
-          reader.onload = function(e) {
459
-                  $("#smstables").empty();
460
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
461
-          };
462
-
463
-          $("#smstables").show();
464
-          $('#sms_upload_msg').hide();
465
-          $('#smstables').removeClass('icon-loading');
466
-     });
467
-
468
-     // Remove selected file
469
-     $("#indivflremove").on("click", function() {
470
-
471
-          $("#induploadfile").remove();
472
-          $("#sms_upload_msg").hide();
473
-
474
-          receiversNumbers.length = 0;
475
-
476
-     });
477
-
478
-  });
479
-
480
-  // Show the number of characters entered in the SMS textarea and the text size in KB
481
-  $("#smstext").on('input', function() {
482
-
483
-     $("#char_count").css("display", "inline");
484
-
485
-     $("#mtextSize").css("display", "inline");
486
-
487
-     $(".maxmessagelength").css("display", "inline-block");
488
-
489
-     $("#countchnb").text($(this).val().length);
490
-
491
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
492
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
493
-     $("#textsizeinkb").text(textsizekb);
494
-
495
-     if ($(this).val().length > charcolorthr) {
496
-         $("#char_count").css("color", "#BB2E4B");
497
-     } else {
498
-         $("#char_count").css("color", "#4cbc86;");
499
-     }
500
-
501
-  });
502
-
503
-
504
-  // Check the checkbox to send file(s) as MMS
505
-  $('#mediafilechckbx').change(function() {
506
-
507
-      if ($(this).is(':checked')) {
508
-
509
-          isMMS = 1;
510
-          if (selectedid == '') {
511
-              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
512
-              $(this).prop("checked", false);
513
-              isMMS = 0;
514
-              return;
515
-          }
516
-          $("#upmediafiles").css("display", "block");
517
-          $("#submitsms").prop("value", "Send MMS");
518
-
519
-      } else {
520
-
521
-          isMMS = 0;
522
-          $("#upmediafiles").css("display", "none");
523
-          $("#submitsms").prop("value", "Send SMS");
524
-
525
-          // Remove the uploaded file(s) if any
526
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
527
-          $(".indgenpckfls").each(function() { $(this).remove(); });
528
-
529
-          uploadedtomms = [];
530
-          n = 1;
531
-
532
-          msgtotalflsize = 0;
533
-
534
-          $("#filestotsize").hide();
535
-      }
536
-  });
537
-
538
-
539
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
540
-  function adjustMaximumSize(uploadedtomms) {
541
-				      
542
-      var nonimgcheck = 0;
543
-      for (var u = 0; u < uploadedtomms.length; u++) {
544
-	   var crupfl = uploadedtomms[u];
545
-	   var extensionup = crupfl.replace(/^.*\./, '');
546
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
547
-	       nonimgcheck = 1;
548
-	   }
549
-      }
550
-
551
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
552
-  }
553
-
554
-  // Upload files to be sent as MMS
555
-  $("#uploadfileformms").change(function(e) {
556
-
557
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
558
-     $('#smstables').addClass('icon-loading');
559
-     $('#filestotsize').show();
560
-
561
-     var userid = "<?php p($userId); ?>";
562
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
563
-
564
-     var formData = new FormData();
565
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
566
-
567
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
568
-
569
-     // Add the size of the current file to the total size of all the files
570
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
571
-
572
-     var fileup = $('#uploadfileformms').val();
573
-     var fileuptrim = fileup.split('\\').pop();
574
-
575
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
576
-         var duplicatescheck = 1;
577
-     } else { 
578
-         var duplicatescheck = 0;
579
-     }
580
-
581
-     var extension = fileup.replace(/^.*\./, '');
582
-
583
-     if (extension == fileup) {
584
-         extension = "";
585
-     } else {
586
-         extension = extension.toLowerCase();
587
-     }
588
-
589
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
590
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
591
-         maximumsize = maxsizenonimage;
592
-     }
593
-
594
-     if ($.inArray(extension, validExtensions) != -1) {
595
-
596
-       if (duplicatescheck == 0) {
597
-
598
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
599
-
600
-            if (n <= maximumfilenumber) {
601
-
602
-               $.ajax({
603
-                 url: baseUrl + '/' + userid,
604
-                 type: "POST",
605
-                 data: formData,
606
-                 cache: false,
607
-                 processData: false,
608
-                 contentType: false,
609
-                 success: function(totalflsize) {
610
-
611
-                   uploadedtomms.push(fileuptrim);
612
-
613
-                   $('#filessizetext').text(totalflsize);
614
-
615
-                   var rectotfilesz = parseFloat(totalflsize);
616
-
617
-                   if (rectotfilesz <= maximumsize) {
618
-                       $('#submitsms').attr("disabled", false);
619
-                       $('#filestotsize').css('color', '#189558');
620
-                   } else {
621
-                       $('#filestotsize').css('color', '#ba3555');
622
-                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
623
-                       $('#submitsms').attr("disabled", true);
624
-                       $('#smstables').removeClass('icon-loading');
625
-                       $('#pf_upload_msg').hide();
626
-                   }
627
-
628
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
629
-                   n++;
630
-
631
-                   // Preview the file when you click on its name
632
-                   $("div:visible[id*='indfilediv']").each(function() {
633
-
634
-                        $(this).on("click", function(eventclck) {
635
-
636
-                           $("#mmsfoldersview").css("display", "inline-block");
637
-                           var mmsfilenameinit = $(this).text();
638
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
639
-                           var mmsfilename = mmsfilenamesec.replace("X","");
640
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
641
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
642
-
643
-                           if (extenlst == mmsfilename) {
644
-                               extenlst = "";
645
-                           } else {
646
-                               extenlst = extenlst.toLowerCase();
647
-                           }
648
-
649
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
650
-                                  $("#smstables").empty();
651
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
652
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
653
-                           } else if (extenlst == 'png') {
654
-                                  $("#smstables").empty();
655
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
656
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
657
-                           } else if (extenlst == 'gif') {
658
-                                  $("#smstables").empty();
659
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
660
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
661
-                           } else if (extenlst == 'bmp') {
662
-                                  $("#smstables").empty();
663
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
664
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
665
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
666
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
667
-                                  var xhr = new XMLHttpRequest();
668
-                                  xhr.responseType = 'arraybuffer';
669
-                                  xhr.open('GET', tiffile);
670
-                                  xhr.onload = function (evnt) {
671
-                                      var tiff = new Tiff({buffer: xhr.response});
672
-                                      var tifcanvas = tiff.toCanvas();
673
-                                      $("#smstables").empty();
674
-                                      $("#smstables").append(tifcanvas);
675
-                                  };
676
-                                  xhr.send();
677
-                           } else if (extenlst == 'pdf') {
678
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
679
-                                  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>');
680
-                                  $("#smstables").empty();
681
-                                  $("#smstables").append($iframe);
682
-                           } else if (extenlst == 'txt') {
683
-                                  $("#smstables").empty();
684
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
685
-                           } else if (extension == 'mp4') {
686
-                                  $("#smstables").empty();
687
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
688
-		           } else if (extension == 'ogg') {
689
-		                  $("#smstables").empty();
690
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
691
-		           } else if (extension == 'avi') {
692
-		                  $("#smstables").empty();
693
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
694
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
695
-		                  $("#smstables").empty();
696
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
697
-		           } else if (extension == 'wav' || extension == 'wave') {
698
-		                  $("#smstables").empty();
699
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
700
-		           } else if (extension == 'mp3') {
701
-		                  $("#smstables").empty();
702
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
703
-		           } else if (extension == 'midi') {
704
-		                  $("#smstables").empty();
705
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
706
-		           }
707
-
708
-                           $("#smstables").show();
709
-                           $("#mmsfoldersview").hide();
710
-                        });
711
-                   });
712
-
713
-                   // Remove uploaded files
714
-                   $('[class*="indupfldl"]').last().click(function() {
715
-
716
-                           var userid = "<?php p($userId); ?>";
717
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
718
-
719
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
720
-
721
-                           var removedfilesplit = removedfilenameinit.split(") ");
722
-                           var removedflnb = parseInt(removedfilesplit[0]);
723
-
724
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
725
-                           $(this).hide();
726
-
727
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
728
-
729
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
730
-                                           return value != removedfilename;
731
-                           });
732
-
733
-                           $.ajax({
734
-                                   url: baseUrl + '/' + userid,
735
-                                   type: "POST",
736
-                                   data: {removedfilename: removedfilename},
737
-                                   success: function(totalflsize) {
738
-
739
-                                      msgtotalflsize = totalflsize;
740
-                                      $('#filessizetext').text(totalflsize);
741
-
742
-                                      adjustMaximumSize(uploadedtomms);
743
-
744
-                                      // Check message size
745
-                                      var rectotfilesz = parseFloat(totalflsize);
746
-
747
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
748
-                                          $('#submitsms').attr("disabled", false);
749
-                                          $('#filestotsize').css('color', '#189558');
750
-                                      } else {
751
-                                          $('#filestotsize').css('color', '#ba3555');
752
-                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
753
-                                          $('#submitsms').attr("disabled", true);
754
-                                      }
755
-
756
-                                      // Rewrite order numbers for files that follow
757
-                                      --n;
758
-                                      $("div:visible[id*='indfilediv']").each(function() {
759
-
760
-                                          var getdivtext =  $(this).text();
761
-                                          var splitdivtext = getdivtext.split(") ");
762
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
763
-                                          var newnbvalue = currentnbvalue - 1;
764
-
765
-                                          if (currentnbvalue > removedflnb) {
766
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
767
-                                              $(this).text(replacedstr);
768
-                                          }
769
-                                      });
770
-
771
-                                      $("div:visible[id*='indflpicked']").each(function() {
772
-
773
-                                          var getdivtext =  $(this).text();
774
-                                          var splitdivtext = getdivtext.split(") ");
775
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
776
-                                          var newnbvalue = currentnbvalue - 1;
777
-
778
-                                          if (currentnbvalue > removedflnb) {
779
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
780
-                                              $(this).text(replacedstr);
781
-                                          }
782
-                                      });
783
-
784
-                                   },
785
-                                   error: function() {
786
-                                          alert('Error removing file(s)!');
787
-                                   }
788
-                           });
789
-
790
-                           $('#smstables').removeClass('icon-loading');
791
-                           $("#smstables").empty();
792
-                   });
793
-
794
-                   // Preview the uploaded file
795
-                   $("#mmsfoldersview").css("display", "inline-block");
796
-                   var mmsfilename = e.target.files[0].name;
797
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
798
-
799
-
800
-                   if (extension == 'jpg' || extension == 'jpeg') {
801
-                              $("#smstables").empty();
802
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
803
-
804
-                              var reader = new FileReader();
805
-                              reader.onload = function (e) {
806
-                                  readjpg[mmsfilename] = e.target.result;
807
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
-                              }
809
-                              reader.readAsDataURL(e.target.files[0]);
810
-                   } else if (extension == 'png') {
811
-                              $("#smstables").empty();
812
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
813
-
814
-                              var reader = new FileReader();
815
-                              reader.onload = function (e) {
816
-                                  readpng[mmsfilename] = e.target.result;
817
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
818
-                              }
819
-                              reader.readAsDataURL(e.target.files[0]);
820
-
821
-                   } else if (extension == 'gif') {
822
-                              $("#smstables").empty();
823
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
824
-
825
-                              var reader = new FileReader();
826
-                              reader.onload = function (e) {
827
-                                  readgif[mmsfilename] = e.target.result;
828
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
829
-                              }
830
-                              reader.readAsDataURL(e.target.files[0]);
831
-
832
-                   } else if (extension == 'bmp') {
833
-                              $("#smstables").empty();
834
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
835
-
836
-                              var reader = new FileReader();
837
-                              reader.onload = function (e) {
838
-                                  readbmp[mmsfilename] = e.target.result;
839
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
840
-                              }
841
-                              reader.readAsDataURL(e.target.files[0]);
842
-
843
-                   } else if (extension == 'tif' || extension == 'tiff') {
844
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
-                              var xhr = new XMLHttpRequest();
846
-                              xhr.responseType = 'arraybuffer';
847
-                              xhr.open('GET', tiffile);
848
-                              xhr.onload = function (e) {
849
-                                  var tiff = new Tiff({buffer: xhr.response});
850
-                                  var tifcanvas = tiff.toCanvas();
851
-                                  $("#smstables").empty();
852
-                                  $("#smstables").append(tifcanvas);
853
-                              };
854
-                              xhr.send();
855
-
856
-                   } else if (extension == 'pdf') {
857
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
-                              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>');
859
-                              $("#smstables").empty();
860
-                              $("#smstables").append($iframe);
861
-
862
-                   } else if (extension == 'txt') {
863
-                              var reader = new FileReader();
864
-                              reader.readAsText(e.target.files[0]);
865
-                              reader.onload = function(e) {
866
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
867
-                                  $("#smstables").empty();
868
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
869
-                              };
870
-                   } else if (extension == 'mp4') {
871
-                              $("#smstables").empty();
872
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
873
-                   } else if (extension == 'ogg') {
874
-                              $("#smstables").empty();
875
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
876
-                   } else if (extension == 'avi') {
877
-                              $("#smstables").empty();
878
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
879
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
880
-                              $("#smstables").empty();
881
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
882
-                   } else if (extension == 'wav' || extension == 'wave') {
883
-                              $("#smstables").empty();
884
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
885
-                   } else if (extension == 'mp3') {
886
-                              $("#smstables").empty();
887
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
888
-                   } else if (extension == 'midi') {
889
-                              $("#smstables").empty();
890
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
891
-                   }
892
-
893
-                   $("#smstables").show();
894
-                   $('#pf_upload_msg').hide();
895
-                   $('#smstables').removeClass('icon-loading');
896
-                   $("#mmsfoldersview").hide();
897
-                 },
898
-                 error: function(data){
899
-                     alert('Error uploading file!');
900
-                 }
901
-               });
902
-
903
-            } else {
904
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
905
-                  adjustMaximumSize(uploadedtomms);
906
-
907
-                  alert("Error ! You cannot send more than 10 files in one MMS !");
908
-                  $('#pf_upload_msg').hide();
909
-                  $('#smstables').removeClass('icon-loading');
910
-            }
911
-         } else {
912
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
913
-              adjustMaximumSize(uploadedtomms);
914
-
915
-              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
916
-              $('#pf_upload_msg').hide();
917
-              $('#smstables').removeClass('icon-loading');
918
-         }
919
-       } else {
920
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
921
-            adjustMaximumSize(uploadedtomms);
922
-
923
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
924
-            $('#pf_upload_msg').hide();
925
-            $('#smstables').removeClass('icon-loading');
926
-       }
927
-
928
-     } else {
929
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
930
-          adjustMaximumSize(uploadedtomms);
931
-
932
-          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
933
-          $('#pf_upload_msg').hide();
934
-          $('#smstables').removeClass('icon-loading');
935
-     }
936
-  });
937
-
938
-
939
-  // Pick file(s) from Nextcloud, to send as MMS
940
-  var mmsfilename = null;
941
-
942
-  $("#choosefilen").on("click", function(evn) {
943
-
944
-                OC.dialogs.filepicker(
945
-                        t('settings', "Select a file to send as MMS."),
946
-                        function (path) {
947
-
948
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
949
-                              $('#smstables').addClass('icon-loading');
950
-                              $('#filestotsize').show();
951
-
952
-                              var userid = "<?php p($userId); ?>";
953
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
954
-
955
-                              mmsfilename = path.split('/').pop();
956
-
957
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
958
-                                  var duplicatescheck = 1;
959
-                              } else var duplicatescheck = 0;
960
-
961
-                              var extension = mmsfilename.replace(/^.*\./, '');
962
-
963
-                              if (extension == mmsfilename) {
964
-                                  extension = "";
965
-                              } else {
966
-                                  extension = extension.toLowerCase();
967
-                              }
968
-
969
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
970
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
971
-				   maximumsize = maxsizenonimage;
972
-			      }
973
-
974
-                              if ($.inArray(extension, validExtensions) != -1) {
975
-
976
-                                 if (duplicatescheck == 0) {
977
-
978
-                                    if (n <= maximumfilenumber) {
979
-
980
-                                       $.ajax({
981
-                                          url: baseUrl + '/' + userid,
982
-                                          type: "POST",
983
-                                          data: {path: path},
984
-                                          success: function(pickresult) {
985
-
986
-                                                uploadedtomms.push(mmsfilename);
987
-
988
-                                                var totalflsize = pickresult[0];
989
-                                                var pickedflsize = pickresult[1];
990
-
991
-                                                // Check message size
992
-                                                var rectotfilesz = parseFloat(totalflsize);
993
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
994
-
995
-                                                if (filesplustextsize <= maximumsize) {
996
-
997
-                                                    $("#mmsfoldersview").css("display", "inline-block");
998
-
999
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1000
-                                                    n++;
1001
-
1002
-                                                    msgtotalflsize = totalflsize;
1003
-                                                    $('#filessizetext').text(totalflsize);
1004
-                                                    $('#filestotsize').css('color', '#189558');
1005
-
1006
-                                                } else {
1007
-
1008
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1009
-                                                    $('#filestotsize').css('color', '#ba3555');
1010
-                                                    msgtotalflsize -= pickedflsize;
1011
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1012
-
1013
-                                                    $.ajax({
1014
-                                                        url: baseUrlindrm + '/' + userid,
1015
-                                                        type: "POST",
1016
-                                                        data: {removedfilename: mmsfilename},
1017
-                                                        success: function(totalflsize) {
1018
-
1019
-                                                                          $('#filessizetext').text(totalflsize);
1020
-                                                                          $('#filestotsize').css('color', '#189558');
1021
-                                                                          adjustMaximumSize(uploadedtomms);
1022
-
1023
-                                                        },
1024
-                                                        error: function(totalflsize) {
1025
-                                                                          $('#filessizetext').text(totalflsize);
1026
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1027
-                                                                              $('#filestotsize').css('color', '#ba3555');
1028
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1029
-                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1030
-                                                        }
1031
-                                                    });
1032
-
1033
-                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1034
-
1035
-                                                }
1036
-
1037
-
1038
-                                                // Preview each file when you click on its name
1039
-                                                $("div:visible[id*='indflpicked']").each(function() {
1040
-                                                   $(this).on("click", function(event) {
1041
-
1042
-                                                      var mmsfilenameinit = $(this).text();
1043
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
-
1048
-                                                      if (extenlst == mmsfilenamesp) {
1049
-                                                           extenlst = "";
1050
-                                                      } else {
1051
-                                                           extenlst = extenlst.toLowerCase();
1052
-                                                      }
1053
-
1054
-
1055
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
-                                                              $("#smstables").empty();
1057
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
-                                                      } else if (extenlst == 'png') {
1059
-                                                              $("#smstables").empty();
1060
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1061
-                                                      } else if (extenlst == 'gif') {
1062
-                                                              $("#smstables").empty();
1063
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1064
-                                                      } else if (extenlst == 'bmp') {
1065
-                                                              $("#smstables").empty();
1066
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1067
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1068
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1069
-                                                              var xhr = new XMLHttpRequest();
1070
-                                                              xhr.responseType = 'arraybuffer';
1071
-                                                              xhr.open('GET', tiffile);
1072
-                                                              xhr.onload = function (evnt) {
1073
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1074
-                                                                  var tifcanvas = tiff.toCanvas();
1075
-                                                                  $("#smstables").empty();
1076
-                                                                  $("#smstables").append(tifcanvas);
1077
-                                                              };
1078
-                                                              xhr.send();
1079
-                                                      } else if (extenlst == 'pdf') {
1080
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1081
-                                                              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>');
1082
-                                                              $("#smstables").empty();
1083
-                                                              $("#smstables").append($iframe);
1084
-                                                      } else if (extenlst == 'txt') {
1085
-                                                              $("#smstables").empty();
1086
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1087
-                                                      } else if (extension == 'mp4') {
1088
-							      $("#smstables").empty();
1089
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1090
-						      } else if (extension == 'ogg') {
1091
-							      $("#smstables").empty();
1092
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1093
-						      } else if (extension == 'avi') {
1094
-							      $("#smstables").empty();
1095
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1096
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1097
-							      $("#smstables").empty();
1098
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1099
-						      } else if (extension == 'wav' || extension == 'wave') {
1100
-							      $("#smstables").empty();
1101
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1102
-						      } else if (extension == 'mp3') {
1103
-							      $("#smstables").empty();
1104
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1105
-						      } else if (extension == 'midi') {
1106
-							      $("#smstables").empty();
1107
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1108
-						      }
1109
-
1110
-
1111
-                                                      $("#smstables").show();
1112
-                                                      $("#mmsfoldersview").hide();
1113
-                                                   });
1114
-                                                });
1115
-
1116
-
1117
-                                                // Remove picked files
1118
-                                                $('[class*="indpckfldl"]').last().click(function() {
1119
-                                                    var userid = "<?php p($userId); ?>";
1120
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1121
-
1122
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1123
-
1124
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1125
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1126
-
1127
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1128
-                                                    $(this).hide();
1129
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1130
-
1131
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1132
-                                                             return value != removedfilename;
1133
-                                                    });
1134
-
1135
-                                                    $.ajax({
1136
-                                                        url: baseUrl + '/' + userid,
1137
-                                                        type: "POST",
1138
-                                                        data: {removedfilename: removedfilename},
1139
-                                                        success: function(totalflsize) {
1140
-
1141
-                                                             msgtotalflsize = totalflsize;
1142
-                                                             $('#filessizetext').text(totalflsize);
1143
-                                                             adjustMaximumSize(uploadedtomms);
1144
-
1145
-                                                             // Check message size
1146
-                                                             var rectotfilesz = parseFloat(totalflsize);
1147
-
1148
-                                                             if (rectotfilesz > maximumsize) {
1149
-                                                                 $('#filestotsize').css('color', '#ba3555');
1150
-                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1151
-                                                                 $('#submitsms').attr("disabled", true);
1152
-                                                             } else {
1153
-                                                                 $('#submitsms').attr("disabled", false);
1154
-                                                                 $('#filestotsize').css('color', '#189558');
1155
-                                                               }
1156
-
1157
-                                                             // Rewrite order numbers for files that follow
1158
-                                                             --n;
1159
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1160
-
1161
-                                                                  var getdivtext =  $(this).text();
1162
-                                                                  var splitdivtext = getdivtext.split(") ");
1163
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1164
-                                                                  var newnbvalue = currentnbvalue - 1;
1165
-
1166
-                                                                  if (currentnbvalue > removedflnb) {
1167
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1168
-                                                                      $(this).text(replacedstr);
1169
-                                                                  }
1170
-                                                             });
1171
-                                                        },
1172
-                                                        error: function() {
1173
-                                                             alert('Error !');
1174
-                                                        }
1175
-                                                    });
1176
-
1177
-                                                    $('#smstables').removeClass('icon-loading');
1178
-                                                    $("#smstables").empty();
1179
-                                                });
1180
-
1181
-
1182
-		                                // Preview the picked file
1183
-		                                $("#mmsfoldersview").css("display", "inline-block");
1184
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1185
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1186
-
1187
-
1188
-						if (extension == 'jpg' || extension == 'jpeg') {
1189
-
1190
-		                                            $("#smstables").empty();
1191
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1192
-
1193
-		                                } else if (extension == 'png') {
1194
-
1195
-		                                            $("#smstables").empty();
1196
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1197
-
1198
-		                                } else if (extension == 'gif') {
1199
-
1200
-		                                            $("#smstables").empty();
1201
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1202
-
1203
-		                                } else if (extension == 'bmp') {
1204
-
1205
-	                                                    $("#smstables").empty();
1206
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1207
-
1208
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1209
-
1210
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1211
-		                                       var xhr = new XMLHttpRequest();
1212
-		                                       xhr.responseType = 'arraybuffer';
1213
-		                                       xhr.open('GET', tiffile);
1214
-		                                       xhr.onload = function (event) {
1215
-		                                           var tiff = new Tiff({buffer: xhr.response});
1216
-		                                           var tifcanvas = tiff.toCanvas();
1217
-		                                           $("#smstables").empty();
1218
-		                                           $("#smstables").append(tifcanvas);
1219
-		                                       };
1220
-		                                       xhr.send();
1221
-
1222
-		                                } else if (extension == 'pdf') {
1223
-
1224
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1225
-		                                       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>');
1226
-		                                       $("#smstables").empty();
1227
-		                                       $("#smstables").append($iframe);
1228
-
1229
-		                                } else if (extension == 'txt') {
1230
-
1231
-							     $.get(flUrl, function(textdata) {
1232
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1233
-		                                               $("#smstables").empty();
1234
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1235
-							     });
1236
-
1237
-		                                } else if (extension == 'mp4') {
1238
-						       $("#smstables").empty();
1239
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1240
-						} else if (extension == 'ogg') {
1241
-						       $("#smstables").empty();
1242
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
-						} else if (extension == 'avi') {
1244
-						       $("#smstables").empty();
1245
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1246
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1247
-						       $("#smstables").empty();
1248
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1249
-						} else if (extension == 'wav' || extension == 'wave') {
1250
-						       $("#smstables").empty();
1251
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1252
-						} else if (extension == 'mp3') {
1253
-						       $("#smstables").empty();
1254
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1255
-						} else if (extension == 'midi') {
1256
-						       $("#smstables").empty();
1257
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1258
-						}
1259
-
1260
-
1261
-		                                $("#smstables").show();
1262
-
1263
-		                                $('#pf_choose_msg').hide();
1264
-		                                $('#smstables').removeClass('icon-loading');
1265
-		                                $("#mmsfoldersview").hide();
1266
-
1267
-                                          },
1268
-
1269
-                                          error: function(data){
1270
-                                             alert('Error!');
1271
-                                          }
1272
-
1273
-                                       });
1274
-
1275
-                                    } else {
1276
-                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1277
-                                        $('#pf_choose_msg').hide();
1278
-                                        $('#smstables').removeClass('icon-loading');
1279
-                                      }
1280
-                                 } else {
1281
-                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1282
-                                      $('#pf_choose_msg').hide();
1283
-                                      $('#smstables').removeClass('icon-loading');
1284
-                                   }
1285
-
1286
-                              } else {
1287
-                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1288
-                                   $('#pf_choose_msg').hide();
1289
-                                   $('#smstables').removeClass('icon-loading');
1290
-                                }
1291
-
1292
-                        }
1293
-                );
1294
-  });
1295
-
1296
-
1297
-
1298
-  // Send the SMS/MMS message
1299
-  $("#submitsms").on("click", function(event) {
1300
-
1301
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1302
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1303
-     $("#sms_submit_msg").css("display", "inline-block");
1304
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1305
-
1306
-     if (selectedid != '') { 
1307
-
1308
-         var sendersplit = selectedid.split(":");
1309
-         var providercap = sendersplit[0];
1310
-         var provsec = sendersplit[1];
1311
-
1312
-         if (/[a-zA-Z]/.test(provsec)) {
1313
-             var alphanumcheck = true;
1314
-         } else { var alphanumcheck = false; }
1315
-
1316
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1317
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1318
-             var selectedsender = "+" + senderproc;
1319
-             var providerUsed = "telnyx";
1320
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1321
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1322
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1323
-             var providerUsed = "plivo";
1324
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1325
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1326
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1327
-             var selectedsender = "+" + senderproc;
1328
-             var providerUsed = "twilio";
1329
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1330
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1331
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1332
-             var selectedsender = "+" + senderproc;
1333
-             var providerUsed = "flowroute";
1334
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1335
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1336
-             var selectedsender = provsec;
1337
-             var providerUsed = "telnyx";
1338
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1339
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1340
-             var selectedsender = provsec;
1341
-             var providerUsed = "plivo";
1342
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1343
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1344
-             var selectedsender = provsec;
1345
-             var providerUsed = "twilio";
1346
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1347
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1348
-             var selectedsender = provsec;
1349
-             var providerUsed = "flowroute";
1350
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1351
-         }
1352
-
1353
-         // Get the interval between message consecutive sending requests, if it's the case
1354
-         if ($('#tomultchckbx').is(':checked')) {
1355
-
1356
-             var numbersfile = 1;
1357
-             var initinterval = $("#multsmsinterval").val();
1358
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1359
-
1360
-             if (secinterval != '') {
1361
-                 var tertinterval = parseInt(secinterval);
1362
-                     waittime = tertinterval;
1363
-             }
1364
-
1365
-         } else {
1366
-
1367
-             var numbersfile = 0;
1368
-             var toNumberinit = $('#smsto').val();
1369
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1370
-             var toNumbersec = toNumber.split(",");
1371
-
1372
-                 for (var i = 0; i < toNumbersec.length; i++) {
1373
-                      toNumbersec[i] = "+" + toNumbersec[i];
1374
-                 }
1375
-
1376
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1377
-         }
1378
-
1379
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1380
-
1381
-         var smstext = $("#smstext").val();
1382
-
1383
-         if (receiversNumbers.length != 0) {
1384
-
1385
-              if (smstext != '') {
1386
-                  $.ajax({
1387
-                     url: relbaseUrl + '/' + userid,
1388
-                     type: "POST",
1389
-                     data: {
1390
-                           receiversPhoneNbs: receiversNumbers,
1391
-                           fromsender: selectedsender,
1392
-                           waitinterval: waittime,
1393
-                           sentsmstext: smstext,
1394
-                           ismms: isMMS,
1395
-                           mmsfiles: uploadedtomms
1396
-                         },
1397
-                     success: function() {
1398
-
1399
-                           if (receiversNumbers.length == 1) {
1400
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1401
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1402
-
1403
-                           $('#sms_submit_msg').hide();
1404
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1405
-                     },
1406
-                     error: function() {
1407
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1408
-                           $('#sms_submit_msg').hide();
1409
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1410
-                     }
1411
-                  });
1412
-              } else {
1413
-                     alert("Please enter a message in the text box !");
1414
-                     $('#sms_submit_msg').hide();
1415
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1416
-              }
1417
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1418
-                 alert("Please enter the recipient's phone number !");
1419
-                 $('#sms_submit_msg').hide();
1420
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1421
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1422
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1423
-                 $('#sms_submit_msg').hide();
1424
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1425
-         }
1426
-     } else {
1427
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
1428
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1429
-           $('#sms_submit_msg').hide();
1430
-     }
1431
-
1432
-  });
1433
-
1434
-  // Check the checkbox to delete old messages from the database
1435
-  $('#deleteoldchckbox').change(function() {
1436
-     if ($(this).is(':checked')) {
1437
-         $("#deleteoldsms").css("display", "block");
1438
-     } else {
1439
-         $("#deleteoldsms").css("display", "none");
1440
-     }
1441
-  });
1442
-
1443
-  // Set the height of 3 info notes
1444
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1445
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1446
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1447
-
1448
-  $(window).resize(function() { 
1449
-    $('#setcalleridtp').css('height', $(window).height() - 160);
1450
-    $('#tonmbrformat').css('height', $(window).height() - 260);
1451
-    $('#uploadfileinfo').css('height', $(window).height() - 390);
1452
-  });
1453
-
Browse code

added changes for origination, auto-reply, etc.

DoubleBastionAdmin authored on 08/05/2023 20:50:18
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1453 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+  // Clean the SMS_Relentless/temp_files directory
58
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
59
+
60
+  $.ajax({
61
+          url: cleanflUrl + '/' + userid,
62
+          type: "POST",
63
+          data: { userid: userid },
64
+          cache: false,
65
+          processData: false,
66
+          contentType: false
67
+  });
68
+  
69
+  // Check the available balance
70
+  $("#smsprovider").on("change", function () {
71
+
72
+     var provider = $('#smsprovider :selected').val();
73
+
74
+     if (provider == "Telnyx") {
75
+
76
+        var gettelbalance = function() {
77
+
78
+          $('#currentbalance').addClass('icon-loading');
79
+
80
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
81
+
82
+          $.ajax({
83
+              url: gettelbalanceUrl + '/' + userid,
84
+              type: "POST",
85
+              data: { userid: userid },
86
+              cache: false,
87
+              processData: false,
88
+              contentType: false,
89
+              success: function(currentbalancetel) {
90
+
91
+                     $('#currentbalance').empty();
92
+                     $('#currentbalance').text(currentbalancetel);
93
+                     $('#currentbalance').removeClass('icon-loading');
94
+              }
95
+          });
96
+        }
97
+
98
+        gettelbalance();
99
+
100
+     } else if (provider == "Plivo") {
101
+
102
+          var getnexbalance = function() {
103
+
104
+            $('#currentbalance').addClass('icon-loading');
105
+
106
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
107
+
108
+            $.ajax({
109
+                url: getnexbalanceUrl + '/' + userid,
110
+                type: "POST",
111
+                data: { userid: userid },
112
+                cache: false,
113
+                processData: false,
114
+                contentType: false,
115
+                success: function(currentbalancenex) {
116
+
117
+                     $('#currentbalance').empty();
118
+                     $('#currentbalance').text(currentbalancenex);
119
+                     $('#currentbalance').removeClass('icon-loading');
120
+                }
121
+            });
122
+          }
123
+
124
+          getnexbalance();
125
+
126
+     } else if (provider == "Twilio") {
127
+
128
+          var gettwilbalance = function() {
129
+
130
+            $('#currentbalance').addClass('icon-loading');
131
+
132
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
133
+
134
+            $.ajax({
135
+                url: gettwilbalanceUrl + '/' + userid,
136
+                type: "POST",
137
+                data: { userid: userid },
138
+                cache: false,
139
+                processData: false,
140
+                contentType: false,
141
+                success: function(currentbalancetwil) {
142
+
143
+                     $('#currentbalance').empty();
144
+                     $('#currentbalance').text(currentbalancetwil);
145
+                     $('#currentbalance').removeClass('icon-loading');
146
+                }
147
+            });
148
+          }
149
+
150
+          gettwilbalance();
151
+
152
+     } else if (provider == "Flowroute") {
153
+
154
+          var getflowbalance = function() {
155
+
156
+            $('#currentbalance').addClass('icon-loading');
157
+
158
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
159
+
160
+            $.ajax({
161
+                url: getflowbalanceUrl + '/' + userid,
162
+                type: "POST",
163
+                data: { userid: userid },
164
+                cache: false,
165
+                processData: false,
166
+                contentType: false,
167
+                success: function(currentbalanceflow) {
168
+
169
+                     $('#currentbalance').empty();
170
+                     $('#currentbalance').text(currentbalanceflow);
171
+                     $('#currentbalance').removeClass('icon-loading');
172
+                }
173
+            });
174
+          }
175
+
176
+          getflowbalance();
177
+
178
+       } else if (provider == "") {
179
+                $('#currentbalance').text("");
180
+                $('#currentbalance').removeClass('icon-loading');
181
+       }
182
+  });
183
+
184
+  // Select the Sender ID
185
+  $("#selectcalleridbttn").on("click", function(event) {
186
+
187
+     $('#selectcalleridbttn').addClass('icon-loading');
188
+
189
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
190
+
191
+     $.ajax({
192
+          url: getsmsnumbersUrl + '/' + userid,
193
+          type: "POST",
194
+          data: { userid: userid },
195
+          cache: false,
196
+          processData: false,
197
+          contentType: false,
198
+          success: function(currentnmbrs) {
199
+
200
+                     $('#currentsmsnmbrs').empty();
201
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
202
+
203
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
204
+                         var emptyinit = indsmsnmb.split(":");
205
+                         var emptysec = emptyinit[1];
206
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
207
+
208
+                         if (emptycheck != '') {
209
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
210
+                         }
211
+                     });
212
+
213
+                     $('#selectcalleridbttn').removeClass('icon-loading');
214
+          }
215
+     });
216
+  });
217
+
218
+  // If a Sender ID is selected, get it
219
+  $("#currentsmsnmbrs").on("change", function () {
220
+
221
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
222
+
223
+              selectedid = $('#currentsmsnmbrs :selected').val();
224
+              var setIdsplit = selectedid.split(":");
225
+	      chosenProvider = setIdsplit[0];
226
+
227
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
228
+	      if (chosenProvider == "Tx") {
229
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
230
+		  // Maximum size of message text + files in KB
231
+		  maximumsize = 1024;
232
+                  maximumsizeinit = 1024;
233
+		  maxsizenonimage = 600;
234
+		  maximumfilenumber = 10;
235
+                  chosenProvFullName = "Telnyx";
236
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
237
+                                     or gif files, the size of all the files plus the size of the text should be \
238
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
239
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
240
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
241
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
242
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
243
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
244
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
245
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
246
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
247
+                  $("#tooltiptextfourth").html(infonotecontent);
248
+	      } else if (chosenProvider == "Pl") {
249
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
250
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
251
+		  // Maximum size of message text + files in KB
252
+		  maximumsize = 5120;
253
+                  maximumsizeinit = 5120;
254
+		  maxsizenonimage = 600;
255
+		  maximumfilenumber = 10;
256
+                  chosenProvFullName = "Plivo";
257
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
258
+                                     or gif files, the size of all the files plus the size of the text should be \
259
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
260
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
261
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
262
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
263
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
264
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
265
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
266
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
267
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
268
+                  $("#tooltiptextfourth").html(infonotecontent);
269
+	      } else if (chosenProvider == "Tw") {
270
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
271
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
272
+                                     "icalendar", "directory", "pdf", "pkpass"];
273
+		  // Maximum size of message text + files in KB
274
+		  maximumsize = 5120;
275
+                  maximumsizeinit = 5120;
276
+		  maxsizenonimage = 600;
277
+		  maximumfilenumber = 10;
278
+                  chosenProvFullName = "Twilio";
279
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
280
+                                     or gif files, the size of all the files plus the size of the text should be \
281
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
282
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
283
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
284
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
285
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
286
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
287
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
288
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
289
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
290
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
291
+                                     previewed in the adjoining pane."
292
+                  $("#tooltiptextfourth").html(infonotecontent);
293
+	      } else if (chosenProvider == "Fl") {
294
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
295
+		  // Maximum size of message text + files in KB
296
+		  maximumsize = 750;
297
+                  maximumsizeinit = 750;
298
+		  maxsizenonimage = 600;
299
+		  maximumfilenumber = 10;
300
+                  chosenProvFullName = "Flowroute";
301
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
302
+                                     png or gif files, the size of all the files plus the size of the text should be \
303
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
304
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
305
+                                     size of the files plus the size of the text should be 600 KB or less. \
306
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
307
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
308
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
309
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
310
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
311
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
312
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
313
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
314
+                  $("#tooltiptextfourth").html(infonotecontent);
315
+	      }
316
+
317
+          } else { selectedid = ''; }
318
+  });
319
+
320
+  // Check the checkbox to send SMS message to multiple recipients
321
+  $('#tomultchckbx').change(function() {
322
+      if ($(this).is(':checked')) {
323
+          $("#multiplerecivers").css("display", "block");
324
+          $("#smstodiv").css("visibility", "hidden");
325
+          $("#smsto").val("");
326
+
327
+          receiversNumbers.length = 0;
328
+
329
+      } else {
330
+          $("#multiplerecivers").css("display", "none");
331
+          $("#smstodiv").css("visibility", "visible");
332
+
333
+          // Remove the uploaded file(s) if any
334
+          $("#induploadfile").remove();
335
+
336
+          receiversNumbers.length = 0;
337
+      }
338
+  });
339
+
340
+  // Upload the file with the recipients' phone numbers
341
+  $("#uploadfileforsms").change(function(e) {
342
+
343
+     $("#fileuploadednm").empty();
344
+
345
+     receiversNumbers.length = 0;
346
+
347
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
348
+
349
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
350
+
351
+     var formData = new FormData();
352
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
353
+
354
+     var fileup = $('#uploadfileforsms').val();
355
+     var fileuptrim = fileup.split('\\').pop();
356
+
357
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
358
+
359
+     var extension = fileup.replace(/^.*\./, '');
360
+
361
+     if (extension == fileup) {
362
+         extension = "";
363
+     } else {
364
+         extension = extension.toLowerCase();
365
+     }
366
+
367
+     var validExtensionsmrec = ["txt", "csv"];
368
+
369
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
370
+
371
+       if (selectedid != '') {
372
+
373
+               $.ajax({
374
+                 url: baseUrl + '/' + userid,
375
+                 type: "POST",
376
+                 data: formData,
377
+                 cache: false,
378
+                 processData: false,
379
+                 contentType: false,
380
+                 success: function(numberarray) {
381
+
382
+		    if (numberarray.length > 0) {
383
+
384
+		        // Get the array of the receivers' phone numbers
385
+		        if (chosenProvider == "Tx") {
386
+
387
+		             for(key in numberarray) {
388
+		                 receiversNumbers.push("+"+numberarray[key]);
389
+		             }
390
+
391
+		        } else if (chosenProvider == "Pl") {
392
+
393
+		             for(key in numberarray) {
394
+		                 receiversNumbers.push(numberarray[key]);
395
+		             }
396
+
397
+		          } else if (chosenProvider == "Tw") {
398
+
399
+		             for(key in numberarray) {
400
+		                 receiversNumbers.push(numberarray[key]);
401
+		             }
402
+		          } else if (chosenProvider == "Fl") {
403
+
404
+		             for(key in numberarray) {
405
+		                 receiversNumbers.push(numberarray[key]);
406
+		             }
407
+		          }
408
+
409
+		    } else {
410
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
411
+		    }
412
+                            
413
+                    // Preview the uploaded file
414
+                    var smsfilename = e.target.files[0].name;
415
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
416
+
417
+                    var reader = new FileReader();
418
+                    reader.readAsText(e.target.files[0]);
419
+                    reader.onload = function(e) {
420
+                          $("#smstables").empty();
421
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
422
+                    };
423
+
424
+                    $("#smstables").show();
425
+
426
+                    $('#sms_upload_msg').hide();
427
+                    $('#smstables').removeClass('icon-loading');
428
+
429
+                  },
430
+                  error: function(){
431
+                     alert('Error!');
432
+                  }
433
+               });
434
+
435
+        } else {
436
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
437
+               $('#sms_upload_msg').hide();
438
+               $('#smstables').removeClass('icon-loading');
439
+        }
440
+
441
+     } else {
442
+          alert('The file type is not supported ! Supported formats are txt and csv.');
443
+          $('#pf_upload_msg').hide();
444
+          $('#smstables').removeClass('icon-loading');
445
+
446
+          $("#induploadfile").remove();
447
+          $("#sms_upload_msg").hide();
448
+     }
449
+
450
+     //Preview uploaded file when clicked
451
+     $("#indfilediv").on("click", function() {
452
+
453
+          var smsfilename = e.target.files[0].name;
454
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
455
+
456
+          var reader = new FileReader();
457
+          reader.readAsText(e.target.files[0]);
458
+          reader.onload = function(e) {
459
+                  $("#smstables").empty();
460
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
461
+          };
462
+
463
+          $("#smstables").show();
464
+          $('#sms_upload_msg').hide();
465
+          $('#smstables').removeClass('icon-loading');
466
+     });
467
+
468
+     // Remove selected file
469
+     $("#indivflremove").on("click", function() {
470
+
471
+          $("#induploadfile").remove();
472
+          $("#sms_upload_msg").hide();
473
+
474
+          receiversNumbers.length = 0;
475
+
476
+     });
477
+
478
+  });
479
+
480
+  // Show the number of characters entered in the SMS textarea and the text size in KB
481
+  $("#smstext").on('input', function() {
482
+
483
+     $("#char_count").css("display", "inline");
484
+
485
+     $("#mtextSize").css("display", "inline");
486
+
487
+     $(".maxmessagelength").css("display", "inline-block");
488
+
489
+     $("#countchnb").text($(this).val().length);
490
+
491
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
492
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
493
+     $("#textsizeinkb").text(textsizekb);
494
+
495
+     if ($(this).val().length > charcolorthr) {
496
+         $("#char_count").css("color", "#BB2E4B");
497
+     } else {
498
+         $("#char_count").css("color", "#4cbc86;");
499
+     }
500
+
501
+  });
502
+
503
+
504
+  // Check the checkbox to send file(s) as MMS
505
+  $('#mediafilechckbx').change(function() {
506
+
507
+      if ($(this).is(':checked')) {
508
+
509
+          isMMS = 1;
510
+          if (selectedid == '') {
511
+              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
512
+              $(this).prop("checked", false);
513
+              isMMS = 0;
514
+              return;
515
+          }
516
+          $("#upmediafiles").css("display", "block");
517
+          $("#submitsms").prop("value", "Send MMS");
518
+
519
+      } else {
520
+
521
+          isMMS = 0;
522
+          $("#upmediafiles").css("display", "none");
523
+          $("#submitsms").prop("value", "Send SMS");
524
+
525
+          // Remove the uploaded file(s) if any
526
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
527
+          $(".indgenpckfls").each(function() { $(this).remove(); });
528
+
529
+          uploadedtomms = [];
530
+          n = 1;
531
+
532
+          msgtotalflsize = 0;
533
+
534
+          $("#filestotsize").hide();
535
+      }
536
+  });
537
+
538
+
539
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
540
+  function adjustMaximumSize(uploadedtomms) {
541
+				      
542
+      var nonimgcheck = 0;
543
+      for (var u = 0; u < uploadedtomms.length; u++) {
544
+	   var crupfl = uploadedtomms[u];
545
+	   var extensionup = crupfl.replace(/^.*\./, '');
546
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
547
+	       nonimgcheck = 1;
548
+	   }
549
+      }
550
+
551
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
552
+  }
553
+
554
+  // Upload files to be sent as MMS
555
+  $("#uploadfileformms").change(function(e) {
556
+
557
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
558
+     $('#smstables').addClass('icon-loading');
559
+     $('#filestotsize').show();
560
+
561
+     var userid = "<?php p($userId); ?>";
562
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
563
+
564
+     var formData = new FormData();
565
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
566
+
567
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
568
+
569
+     // Add the size of the current file to the total size of all the files
570
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
571
+
572
+     var fileup = $('#uploadfileformms').val();
573
+     var fileuptrim = fileup.split('\\').pop();
574
+
575
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
576
+         var duplicatescheck = 1;
577
+     } else { 
578
+         var duplicatescheck = 0;
579
+     }
580
+
581
+     var extension = fileup.replace(/^.*\./, '');
582
+
583
+     if (extension == fileup) {
584
+         extension = "";
585
+     } else {
586
+         extension = extension.toLowerCase();
587
+     }
588
+
589
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
590
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
591
+         maximumsize = maxsizenonimage;
592
+     }
593
+
594
+     if ($.inArray(extension, validExtensions) != -1) {
595
+
596
+       if (duplicatescheck == 0) {
597
+
598
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
599
+
600
+            if (n <= maximumfilenumber) {
601
+
602
+               $.ajax({
603
+                 url: baseUrl + '/' + userid,
604
+                 type: "POST",
605
+                 data: formData,
606
+                 cache: false,
607
+                 processData: false,
608
+                 contentType: false,
609
+                 success: function(totalflsize) {
610
+
611
+                   uploadedtomms.push(fileuptrim);
612
+
613
+                   $('#filessizetext').text(totalflsize);
614
+
615
+                   var rectotfilesz = parseFloat(totalflsize);
616
+
617
+                   if (rectotfilesz <= maximumsize) {
618
+                       $('#submitsms').attr("disabled", false);
619
+                       $('#filestotsize').css('color', '#189558');
620
+                   } else {
621
+                       $('#filestotsize').css('color', '#ba3555');
622
+                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
623
+                       $('#submitsms').attr("disabled", true);
624
+                       $('#smstables').removeClass('icon-loading');
625
+                       $('#pf_upload_msg').hide();
626
+                   }
627
+
628
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
629
+                   n++;
630
+
631
+                   // Preview the file when you click on its name
632
+                   $("div:visible[id*='indfilediv']").each(function() {
633
+
634
+                        $(this).on("click", function(eventclck) {
635
+
636
+                           $("#mmsfoldersview").css("display", "inline-block");
637
+                           var mmsfilenameinit = $(this).text();
638
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
639
+                           var mmsfilename = mmsfilenamesec.replace("X","");
640
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
641
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
642
+
643
+                           if (extenlst == mmsfilename) {
644
+                               extenlst = "";
645
+                           } else {
646
+                               extenlst = extenlst.toLowerCase();
647
+                           }
648
+
649
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
650
+                                  $("#smstables").empty();
651
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
652
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
653
+                           } else if (extenlst == 'png') {
654
+                                  $("#smstables").empty();
655
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
656
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
657
+                           } else if (extenlst == 'gif') {
658
+                                  $("#smstables").empty();
659
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
660
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
661
+                           } else if (extenlst == 'bmp') {
662
+                                  $("#smstables").empty();
663
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
664
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
665
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
666
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
667
+                                  var xhr = new XMLHttpRequest();
668
+                                  xhr.responseType = 'arraybuffer';
669
+                                  xhr.open('GET', tiffile);
670
+                                  xhr.onload = function (evnt) {
671
+                                      var tiff = new Tiff({buffer: xhr.response});
672
+                                      var tifcanvas = tiff.toCanvas();
673
+                                      $("#smstables").empty();
674
+                                      $("#smstables").append(tifcanvas);
675
+                                  };
676
+                                  xhr.send();
677
+                           } else if (extenlst == 'pdf') {
678
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
679
+                                  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>');
680
+                                  $("#smstables").empty();
681
+                                  $("#smstables").append($iframe);
682
+                           } else if (extenlst == 'txt') {
683
+                                  $("#smstables").empty();
684
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
685
+                           } else if (extension == 'mp4') {
686
+                                  $("#smstables").empty();
687
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
688
+		           } else if (extension == 'ogg') {
689
+		                  $("#smstables").empty();
690
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
691
+		           } else if (extension == 'avi') {
692
+		                  $("#smstables").empty();
693
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
694
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
695
+		                  $("#smstables").empty();
696
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
697
+		           } else if (extension == 'wav' || extension == 'wave') {
698
+		                  $("#smstables").empty();
699
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
700
+		           } else if (extension == 'mp3') {
701
+		                  $("#smstables").empty();
702
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
703
+		           } else if (extension == 'midi') {
704
+		                  $("#smstables").empty();
705
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
706
+		           }
707
+
708
+                           $("#smstables").show();
709
+                           $("#mmsfoldersview").hide();
710
+                        });
711
+                   });
712
+
713
+                   // Remove uploaded files
714
+                   $('[class*="indupfldl"]').last().click(function() {
715
+
716
+                           var userid = "<?php p($userId); ?>";
717
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
718
+
719
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
720
+
721
+                           var removedfilesplit = removedfilenameinit.split(") ");
722
+                           var removedflnb = parseInt(removedfilesplit[0]);
723
+
724
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
725
+                           $(this).hide();
726
+
727
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
728
+
729
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
730
+                                           return value != removedfilename;
731
+                           });
732
+
733
+                           $.ajax({
734
+                                   url: baseUrl + '/' + userid,
735
+                                   type: "POST",
736
+                                   data: {removedfilename: removedfilename},
737
+                                   success: function(totalflsize) {
738
+
739
+                                      msgtotalflsize = totalflsize;
740
+                                      $('#filessizetext').text(totalflsize);
741
+
742
+                                      adjustMaximumSize(uploadedtomms);
743
+
744
+                                      // Check message size
745
+                                      var rectotfilesz = parseFloat(totalflsize);
746
+
747
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
748
+                                          $('#submitsms').attr("disabled", false);
749
+                                          $('#filestotsize').css('color', '#189558');
750
+                                      } else {
751
+                                          $('#filestotsize').css('color', '#ba3555');
752
+                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
753
+                                          $('#submitsms').attr("disabled", true);
754
+                                      }
755
+
756
+                                      // Rewrite order numbers for files that follow
757
+                                      --n;
758
+                                      $("div:visible[id*='indfilediv']").each(function() {
759
+
760
+                                          var getdivtext =  $(this).text();
761
+                                          var splitdivtext = getdivtext.split(") ");
762
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
763
+                                          var newnbvalue = currentnbvalue - 1;
764
+
765
+                                          if (currentnbvalue > removedflnb) {
766
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
767
+                                              $(this).text(replacedstr);
768
+                                          }
769
+                                      });
770
+
771
+                                      $("div:visible[id*='indflpicked']").each(function() {
772
+
773
+                                          var getdivtext =  $(this).text();
774
+                                          var splitdivtext = getdivtext.split(") ");
775
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
776
+                                          var newnbvalue = currentnbvalue - 1;
777
+
778
+                                          if (currentnbvalue > removedflnb) {
779
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
780
+                                              $(this).text(replacedstr);
781
+                                          }
782
+                                      });
783
+
784
+                                   },
785
+                                   error: function() {
786
+                                          alert('Error removing file(s)!');
787
+                                   }
788
+                           });
789
+
790
+                           $('#smstables').removeClass('icon-loading');
791
+                           $("#smstables").empty();
792
+                   });
793
+
794
+                   // Preview the uploaded file
795
+                   $("#mmsfoldersview").css("display", "inline-block");
796
+                   var mmsfilename = e.target.files[0].name;
797
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
798
+
799
+
800
+                   if (extension == 'jpg' || extension == 'jpeg') {
801
+                              $("#smstables").empty();
802
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
803
+
804
+                              var reader = new FileReader();
805
+                              reader.onload = function (e) {
806
+                                  readjpg[mmsfilename] = e.target.result;
807
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
+                              }
809
+                              reader.readAsDataURL(e.target.files[0]);
810
+                   } else if (extension == 'png') {
811
+                              $("#smstables").empty();
812
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
813
+
814
+                              var reader = new FileReader();
815
+                              reader.onload = function (e) {
816
+                                  readpng[mmsfilename] = e.target.result;
817
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
818
+                              }
819
+                              reader.readAsDataURL(e.target.files[0]);
820
+
821
+                   } else if (extension == 'gif') {
822
+                              $("#smstables").empty();
823
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
824
+
825
+                              var reader = new FileReader();
826
+                              reader.onload = function (e) {
827
+                                  readgif[mmsfilename] = e.target.result;
828
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
829
+                              }
830
+                              reader.readAsDataURL(e.target.files[0]);
831
+
832
+                   } else if (extension == 'bmp') {
833
+                              $("#smstables").empty();
834
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
835
+
836
+                              var reader = new FileReader();
837
+                              reader.onload = function (e) {
838
+                                  readbmp[mmsfilename] = e.target.result;
839
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
840
+                              }
841
+                              reader.readAsDataURL(e.target.files[0]);
842
+
843
+                   } else if (extension == 'tif' || extension == 'tiff') {
844
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
+                              var xhr = new XMLHttpRequest();
846
+                              xhr.responseType = 'arraybuffer';
847
+                              xhr.open('GET', tiffile);
848
+                              xhr.onload = function (e) {
849
+                                  var tiff = new Tiff({buffer: xhr.response});
850
+                                  var tifcanvas = tiff.toCanvas();
851
+                                  $("#smstables").empty();
852
+                                  $("#smstables").append(tifcanvas);
853
+                              };
854
+                              xhr.send();
855
+
856
+                   } else if (extension == 'pdf') {
857
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
+                              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>');
859
+                              $("#smstables").empty();
860
+                              $("#smstables").append($iframe);
861
+
862
+                   } else if (extension == 'txt') {
863
+                              var reader = new FileReader();
864
+                              reader.readAsText(e.target.files[0]);
865
+                              reader.onload = function(e) {
866
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
867
+                                  $("#smstables").empty();
868
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
869
+                              };
870
+                   } else if (extension == 'mp4') {
871
+                              $("#smstables").empty();
872
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
873
+                   } else if (extension == 'ogg') {
874
+                              $("#smstables").empty();
875
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
876
+                   } else if (extension == 'avi') {
877
+                              $("#smstables").empty();
878
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
879
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
880
+                              $("#smstables").empty();
881
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
882
+                   } else if (extension == 'wav' || extension == 'wave') {
883
+                              $("#smstables").empty();
884
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
885
+                   } else if (extension == 'mp3') {
886
+                              $("#smstables").empty();
887
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
888
+                   } else if (extension == 'midi') {
889
+                              $("#smstables").empty();
890
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
891
+                   }
892
+
893
+                   $("#smstables").show();
894
+                   $('#pf_upload_msg').hide();
895
+                   $('#smstables').removeClass('icon-loading');
896
+                   $("#mmsfoldersview").hide();
897
+                 },
898
+                 error: function(data){
899
+                     alert('Error uploading file!');
900
+                 }
901
+               });
902
+
903
+            } else {
904
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
905
+                  adjustMaximumSize(uploadedtomms);
906
+
907
+                  alert("Error ! You cannot send more than 10 files in one MMS !");
908
+                  $('#pf_upload_msg').hide();
909
+                  $('#smstables').removeClass('icon-loading');
910
+            }
911
+         } else {
912
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
913
+              adjustMaximumSize(uploadedtomms);
914
+
915
+              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
916
+              $('#pf_upload_msg').hide();
917
+              $('#smstables').removeClass('icon-loading');
918
+         }
919
+       } else {
920
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
921
+            adjustMaximumSize(uploadedtomms);
922
+
923
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
924
+            $('#pf_upload_msg').hide();
925
+            $('#smstables').removeClass('icon-loading');
926
+       }
927
+
928
+     } else {
929
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
930
+          adjustMaximumSize(uploadedtomms);
931
+
932
+          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
933
+          $('#pf_upload_msg').hide();
934
+          $('#smstables').removeClass('icon-loading');
935
+     }
936
+  });
937
+
938
+
939
+  // Pick file(s) from Nextcloud, to send as MMS
940
+  var mmsfilename = null;
941
+
942
+  $("#choosefilen").on("click", function(evn) {
943
+
944
+                OC.dialogs.filepicker(
945
+                        t('settings', "Select a file to send as MMS."),
946
+                        function (path) {
947
+
948
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
949
+                              $('#smstables').addClass('icon-loading');
950
+                              $('#filestotsize').show();
951
+
952
+                              var userid = "<?php p($userId); ?>";
953
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
954
+
955
+                              mmsfilename = path.split('/').pop();
956
+
957
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
958
+                                  var duplicatescheck = 1;
959
+                              } else var duplicatescheck = 0;
960
+
961
+                              var extension = mmsfilename.replace(/^.*\./, '');
962
+
963
+                              if (extension == mmsfilename) {
964
+                                  extension = "";
965
+                              } else {
966
+                                  extension = extension.toLowerCase();
967
+                              }
968
+
969
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
970
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
971
+				   maximumsize = maxsizenonimage;
972
+			      }
973
+
974
+                              if ($.inArray(extension, validExtensions) != -1) {
975
+
976
+                                 if (duplicatescheck == 0) {
977
+
978
+                                    if (n <= maximumfilenumber) {
979
+
980
+                                       $.ajax({
981
+                                          url: baseUrl + '/' + userid,
982
+                                          type: "POST",
983
+                                          data: {path: path},
984
+                                          success: function(pickresult) {
985
+
986
+                                                uploadedtomms.push(mmsfilename);
987
+
988
+                                                var totalflsize = pickresult[0];
989
+                                                var pickedflsize = pickresult[1];
990
+
991
+                                                // Check message size
992
+                                                var rectotfilesz = parseFloat(totalflsize);
993
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
994
+
995
+                                                if (filesplustextsize <= maximumsize) {
996
+
997
+                                                    $("#mmsfoldersview").css("display", "inline-block");
998
+
999
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1000
+                                                    n++;
1001
+
1002
+                                                    msgtotalflsize = totalflsize;
1003
+                                                    $('#filessizetext').text(totalflsize);
1004
+                                                    $('#filestotsize').css('color', '#189558');
1005
+
1006
+                                                } else {
1007
+
1008
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1009
+                                                    $('#filestotsize').css('color', '#ba3555');
1010
+                                                    msgtotalflsize -= pickedflsize;
1011
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1012
+
1013
+                                                    $.ajax({
1014
+                                                        url: baseUrlindrm + '/' + userid,
1015
+                                                        type: "POST",
1016
+                                                        data: {removedfilename: mmsfilename},
1017
+                                                        success: function(totalflsize) {
1018
+
1019
+                                                                          $('#filessizetext').text(totalflsize);
1020
+                                                                          $('#filestotsize').css('color', '#189558');
1021
+                                                                          adjustMaximumSize(uploadedtomms);
1022
+
1023
+                                                        },
1024
+                                                        error: function(totalflsize) {
1025
+                                                                          $('#filessizetext').text(totalflsize);
1026
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1027
+                                                                              $('#filestotsize').css('color', '#ba3555');
1028
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1029
+                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1030
+                                                        }
1031
+                                                    });
1032
+
1033
+                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1034
+
1035
+                                                }
1036
+
1037
+
1038
+                                                // Preview each file when you click on its name
1039
+                                                $("div:visible[id*='indflpicked']").each(function() {
1040
+                                                   $(this).on("click", function(event) {
1041
+
1042
+                                                      var mmsfilenameinit = $(this).text();
1043
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
+
1048
+                                                      if (extenlst == mmsfilenamesp) {
1049
+                                                           extenlst = "";
1050
+                                                      } else {
1051
+                                                           extenlst = extenlst.toLowerCase();
1052
+                                                      }
1053
+
1054
+
1055
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
+                                                              $("#smstables").empty();
1057
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
+                                                      } else if (extenlst == 'png') {
1059
+                                                              $("#smstables").empty();
1060
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1061
+                                                      } else if (extenlst == 'gif') {
1062
+                                                              $("#smstables").empty();
1063
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1064
+                                                      } else if (extenlst == 'bmp') {
1065
+                                                              $("#smstables").empty();
1066
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1067
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1068
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1069
+                                                              var xhr = new XMLHttpRequest();
1070
+                                                              xhr.responseType = 'arraybuffer';
1071
+                                                              xhr.open('GET', tiffile);
1072
+                                                              xhr.onload = function (evnt) {
1073
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1074
+                                                                  var tifcanvas = tiff.toCanvas();
1075
+                                                                  $("#smstables").empty();
1076
+                                                                  $("#smstables").append(tifcanvas);
1077
+                                                              };
1078
+                                                              xhr.send();
1079
+                                                      } else if (extenlst == 'pdf') {
1080
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1081
+                                                              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>');
1082
+                                                              $("#smstables").empty();
1083
+                                                              $("#smstables").append($iframe);
1084
+                                                      } else if (extenlst == 'txt') {
1085
+                                                              $("#smstables").empty();
1086
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1087
+                                                      } else if (extension == 'mp4') {
1088
+							      $("#smstables").empty();
1089
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1090
+						      } else if (extension == 'ogg') {
1091
+							      $("#smstables").empty();
1092
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1093
+						      } else if (extension == 'avi') {
1094
+							      $("#smstables").empty();
1095
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1096
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1097
+							      $("#smstables").empty();
1098
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1099
+						      } else if (extension == 'wav' || extension == 'wave') {
1100
+							      $("#smstables").empty();
1101
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1102
+						      } else if (extension == 'mp3') {
1103
+							      $("#smstables").empty();
1104
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1105
+						      } else if (extension == 'midi') {
1106
+							      $("#smstables").empty();
1107
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1108
+						      }
1109
+
1110
+
1111
+                                                      $("#smstables").show();
1112
+                                                      $("#mmsfoldersview").hide();
1113
+                                                   });
1114
+                                                });
1115
+
1116
+
1117
+                                                // Remove picked files
1118
+                                                $('[class*="indpckfldl"]').last().click(function() {
1119
+                                                    var userid = "<?php p($userId); ?>";
1120
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1121
+
1122
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1123
+
1124
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1125
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1126
+
1127
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1128
+                                                    $(this).hide();
1129
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1130
+
1131
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1132
+                                                             return value != removedfilename;
1133
+                                                    });
1134
+
1135
+                                                    $.ajax({
1136
+                                                        url: baseUrl + '/' + userid,
1137
+                                                        type: "POST",
1138
+                                                        data: {removedfilename: removedfilename},
1139
+                                                        success: function(totalflsize) {
1140
+
1141
+                                                             msgtotalflsize = totalflsize;
1142
+                                                             $('#filessizetext').text(totalflsize);
1143
+                                                             adjustMaximumSize(uploadedtomms);
1144
+
1145
+                                                             // Check message size
1146
+                                                             var rectotfilesz = parseFloat(totalflsize);
1147
+
1148
+                                                             if (rectotfilesz > maximumsize) {
1149
+                                                                 $('#filestotsize').css('color', '#ba3555');
1150
+                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1151
+                                                                 $('#submitsms').attr("disabled", true);
1152
+                                                             } else {
1153
+                                                                 $('#submitsms').attr("disabled", false);
1154
+                                                                 $('#filestotsize').css('color', '#189558');
1155
+                                                               }
1156
+
1157
+                                                             // Rewrite order numbers for files that follow
1158
+                                                             --n;
1159
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1160
+
1161
+                                                                  var getdivtext =  $(this).text();
1162
+                                                                  var splitdivtext = getdivtext.split(") ");
1163
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1164
+                                                                  var newnbvalue = currentnbvalue - 1;
1165
+
1166
+                                                                  if (currentnbvalue > removedflnb) {
1167
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1168
+                                                                      $(this).text(replacedstr);
1169
+                                                                  }
1170
+                                                             });
1171
+                                                        },
1172
+                                                        error: function() {
1173
+                                                             alert('Error !');
1174
+                                                        }
1175
+                                                    });
1176
+
1177
+                                                    $('#smstables').removeClass('icon-loading');
1178
+                                                    $("#smstables").empty();
1179
+                                                });
1180
+
1181
+
1182
+		                                // Preview the picked file
1183
+		                                $("#mmsfoldersview").css("display", "inline-block");
1184
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1185
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1186
+
1187
+
1188
+						if (extension == 'jpg' || extension == 'jpeg') {
1189
+
1190
+		                                            $("#smstables").empty();
1191
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1192
+
1193
+		                                } else if (extension == 'png') {
1194
+
1195
+		                                            $("#smstables").empty();
1196
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1197
+
1198
+		                                } else if (extension == 'gif') {
1199
+
1200
+		                                            $("#smstables").empty();
1201
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1202
+
1203
+		                                } else if (extension == 'bmp') {
1204
+
1205
+	                                                    $("#smstables").empty();
1206
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1207
+
1208
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1209
+
1210
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1211
+		                                       var xhr = new XMLHttpRequest();
1212
+		                                       xhr.responseType = 'arraybuffer';
1213
+		                                       xhr.open('GET', tiffile);
1214
+		                                       xhr.onload = function (event) {
1215
+		                                           var tiff = new Tiff({buffer: xhr.response});
1216
+		                                           var tifcanvas = tiff.toCanvas();
1217
+		                                           $("#smstables").empty();
1218
+		                                           $("#smstables").append(tifcanvas);
1219
+		                                       };
1220
+		                                       xhr.send();
1221
+
1222
+		                                } else if (extension == 'pdf') {
1223
+
1224
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1225
+		                                       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>');
1226
+		                                       $("#smstables").empty();
1227
+		                                       $("#smstables").append($iframe);
1228
+
1229
+		                                } else if (extension == 'txt') {
1230
+
1231
+							     $.get(flUrl, function(textdata) {
1232
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1233
+		                                               $("#smstables").empty();
1234
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1235
+							     });
1236
+
1237
+		                                } else if (extension == 'mp4') {
1238
+						       $("#smstables").empty();
1239
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1240
+						} else if (extension == 'ogg') {
1241
+						       $("#smstables").empty();
1242
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
+						} else if (extension == 'avi') {
1244
+						       $("#smstables").empty();
1245
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1246
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1247
+						       $("#smstables").empty();
1248
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1249
+						} else if (extension == 'wav' || extension == 'wave') {
1250
+						       $("#smstables").empty();
1251
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1252
+						} else if (extension == 'mp3') {
1253
+						       $("#smstables").empty();
1254
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1255
+						} else if (extension == 'midi') {
1256
+						       $("#smstables").empty();
1257
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1258
+						}
1259
+
1260
+
1261
+		                                $("#smstables").show();
1262
+
1263
+		                                $('#pf_choose_msg').hide();
1264
+		                                $('#smstables').removeClass('icon-loading');
1265
+		                                $("#mmsfoldersview").hide();
1266
+
1267
+                                          },
1268
+
1269
+                                          error: function(data){
1270
+                                             alert('Error!');
1271
+                                          }
1272
+
1273
+                                       });
1274
+
1275
+                                    } else {
1276
+                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1277
+                                        $('#pf_choose_msg').hide();
1278
+                                        $('#smstables').removeClass('icon-loading');
1279
+                                      }
1280
+                                 } else {
1281
+                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1282
+                                      $('#pf_choose_msg').hide();
1283
+                                      $('#smstables').removeClass('icon-loading');
1284
+                                   }
1285
+
1286
+                              } else {
1287
+                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1288
+                                   $('#pf_choose_msg').hide();
1289
+                                   $('#smstables').removeClass('icon-loading');
1290
+                                }
1291
+
1292
+                        }
1293
+                );
1294
+  });
1295
+
1296
+
1297
+
1298
+  // Send the SMS/MMS message
1299
+  $("#submitsms").on("click", function(event) {
1300
+
1301
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1302
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1303
+     $("#sms_submit_msg").css("display", "inline-block");
1304
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1305
+
1306
+     if (selectedid != '') { 
1307
+
1308
+         var sendersplit = selectedid.split(":");
1309
+         var providercap = sendersplit[0];
1310
+         var provsec = sendersplit[1];
1311
+
1312
+         if (/[a-zA-Z]/.test(provsec)) {
1313
+             var alphanumcheck = true;
1314
+         } else { var alphanumcheck = false; }
1315
+
1316
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1317
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1318
+             var selectedsender = "+" + senderproc;
1319
+             var providerUsed = "telnyx";
1320
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1321
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1322
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1323
+             var providerUsed = "plivo";
1324
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1325
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1326
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1327
+             var selectedsender = "+" + senderproc;
1328
+             var providerUsed = "twilio";
1329
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1330
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1331
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1332
+             var selectedsender = "+" + senderproc;
1333
+             var providerUsed = "flowroute";
1334
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1335
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1336
+             var selectedsender = provsec;
1337
+             var providerUsed = "telnyx";
1338
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1339
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1340
+             var selectedsender = provsec;
1341
+             var providerUsed = "plivo";
1342
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1343
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1344
+             var selectedsender = provsec;
1345
+             var providerUsed = "twilio";
1346
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1347
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1348
+             var selectedsender = provsec;
1349
+             var providerUsed = "flowroute";
1350
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1351
+         }
1352
+
1353
+         // Get the interval between message consecutive sending requests, if it's the case
1354
+         if ($('#tomultchckbx').is(':checked')) {
1355
+
1356
+             var numbersfile = 1;
1357
+             var initinterval = $("#multsmsinterval").val();
1358
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1359
+
1360
+             if (secinterval != '') {
1361
+                 var tertinterval = parseInt(secinterval);
1362
+                     waittime = tertinterval;
1363
+             }
1364
+
1365
+         } else {
1366
+
1367
+             var numbersfile = 0;
1368
+             var toNumberinit = $('#smsto').val();
1369
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1370
+             var toNumbersec = toNumber.split(",");
1371
+
1372
+                 for (var i = 0; i < toNumbersec.length; i++) {
1373
+                      toNumbersec[i] = "+" + toNumbersec[i];
1374
+                 }
1375
+
1376
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1377
+         }
1378
+
1379
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1380
+
1381
+         var smstext = $("#smstext").val();
1382
+
1383
+         if (receiversNumbers.length != 0) {
1384
+
1385
+              if (smstext != '') {
1386
+                  $.ajax({
1387
+                     url: relbaseUrl + '/' + userid,
1388
+                     type: "POST",
1389
+                     data: {
1390
+                           receiversPhoneNbs: receiversNumbers,
1391
+                           fromsender: selectedsender,
1392
+                           waitinterval: waittime,
1393
+                           sentsmstext: smstext,
1394
+                           ismms: isMMS,
1395
+                           mmsfiles: uploadedtomms
1396
+                         },
1397
+                     success: function() {
1398
+
1399
+                           if (receiversNumbers.length == 1) {
1400
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1401
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1402
+
1403
+                           $('#sms_submit_msg').hide();
1404
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1405
+                     },
1406
+                     error: function() {
1407
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1408
+                           $('#sms_submit_msg').hide();
1409
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1410
+                     }
1411
+                  });
1412
+              } else {
1413
+                     alert("Please enter a message in the text box !");
1414
+                     $('#sms_submit_msg').hide();
1415
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1416
+              }
1417
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1418
+                 alert("Please enter the recipient's phone number !");
1419
+                 $('#sms_submit_msg').hide();
1420
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1421
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1422
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1423
+                 $('#sms_submit_msg').hide();
1424
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1425
+         }
1426
+     } else {
1427
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
1428
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1429
+           $('#sms_submit_msg').hide();
1430
+     }
1431
+
1432
+  });
1433
+
1434
+  // Check the checkbox to delete old messages from the database
1435
+  $('#deleteoldchckbox').change(function() {
1436
+     if ($(this).is(':checked')) {
1437
+         $("#deleteoldsms").css("display", "block");
1438
+     } else {
1439
+         $("#deleteoldsms").css("display", "none");
1440
+     }
1441
+  });
1442
+
1443
+  // Set the height of 3 info notes
1444
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1445
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1446
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1447
+
1448
+  $(window).resize(function() { 
1449
+    $('#setcalleridtp').css('height', $(window).height() - 160);
1450
+    $('#tonmbrformat').css('height', $(window).height() - 260);
1451
+    $('#uploadfileinfo').css('height', $(window).height() - 390);
1452
+  });
1453
+
Browse code

removed a substantial number of files

DoubleBastionAdmin authored on 08/05/2023 20:27:04
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1453 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readjpg = [];
37
-  var readpng = [];
38
-  var readgif = [];
39
-  var readbmp = [];
40
-  var readtif = [];
41
-  var readmp4 = [];
42
-  var chosenProvider = '';
43
-  var chosenProvFullName = '';
44
-  var infonotecontent = '';
45
-  var validExtensions = [];
46
-  var maximumsize = 750;
47
-  var maxsizenonimage = 600;
48
-  var maximumfilenumber = 10;
49
-  var maximumsizeinit = 750;
50
-
51
-  // 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
52
-  var locHref = window.location.href;
53
-  var pathSplit = locHref.split('/');
54
-  var firstPathEl = '';
55
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
-
57
-  // Clean the SMS_Relentless/temp_files directory
58
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
59
-
60
-  $.ajax({
61
-          url: cleanflUrl + '/' + userid,
62
-          type: "POST",
63
-          data: { userid: userid },
64
-          cache: false,
65
-          processData: false,
66
-          contentType: false
67
-  });
68
-  
69
-  // Check the available balance
70
-  $("#smsprovider").on("change", function () {
71
-
72
-     var provider = $('#smsprovider :selected').val();
73
-
74
-     if (provider == "Telnyx") {
75
-
76
-        var gettelbalance = function() {
77
-
78
-          $('#currentbalance').addClass('icon-loading');
79
-
80
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
81
-
82
-          $.ajax({
83
-              url: gettelbalanceUrl + '/' + userid,
84
-              type: "POST",
85
-              data: { userid: userid },
86
-              cache: false,
87
-              processData: false,
88
-              contentType: false,
89
-              success: function(currentbalancetel) {
90
-
91
-                     $('#currentbalance').empty();
92
-                     $('#currentbalance').text(currentbalancetel);
93
-                     $('#currentbalance').removeClass('icon-loading');
94
-              }
95
-          });
96
-        }
97
-
98
-        gettelbalance();
99
-
100
-     } else if (provider == "Plivo") {
101
-
102
-          var getnexbalance = function() {
103
-
104
-            $('#currentbalance').addClass('icon-loading');
105
-
106
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
107
-
108
-            $.ajax({
109
-                url: getnexbalanceUrl + '/' + userid,
110
-                type: "POST",
111
-                data: { userid: userid },
112
-                cache: false,
113
-                processData: false,
114
-                contentType: false,
115
-                success: function(currentbalancenex) {
116
-
117
-                     $('#currentbalance').empty();
118
-                     $('#currentbalance').text(currentbalancenex);
119
-                     $('#currentbalance').removeClass('icon-loading');
120
-                }
121
-            });
122
-          }
123
-
124
-          getnexbalance();
125
-
126
-     } else if (provider == "Twilio") {
127
-
128
-          var gettwilbalance = function() {
129
-
130
-            $('#currentbalance').addClass('icon-loading');
131
-
132
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
133
-
134
-            $.ajax({
135
-                url: gettwilbalanceUrl + '/' + userid,
136
-                type: "POST",
137
-                data: { userid: userid },
138
-                cache: false,
139
-                processData: false,
140
-                contentType: false,
141
-                success: function(currentbalancetwil) {
142
-
143
-                     $('#currentbalance').empty();
144
-                     $('#currentbalance').text(currentbalancetwil);
145
-                     $('#currentbalance').removeClass('icon-loading');
146
-                }
147
-            });
148
-          }
149
-
150
-          gettwilbalance();
151
-
152
-     } else if (provider == "Flowroute") {
153
-
154
-          var getflowbalance = function() {
155
-
156
-            $('#currentbalance').addClass('icon-loading');
157
-
158
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
159
-
160
-            $.ajax({
161
-                url: getflowbalanceUrl + '/' + userid,
162
-                type: "POST",
163
-                data: { userid: userid },
164
-                cache: false,
165
-                processData: false,
166
-                contentType: false,
167
-                success: function(currentbalanceflow) {
168
-
169
-                     $('#currentbalance').empty();
170
-                     $('#currentbalance').text(currentbalanceflow);
171
-                     $('#currentbalance').removeClass('icon-loading');
172
-                }
173
-            });
174
-          }
175
-
176
-          getflowbalance();
177
-
178
-       } else if (provider == "") {
179
-                $('#currentbalance').text("");
180
-                $('#currentbalance').removeClass('icon-loading');
181
-       }
182
-  });
183
-
184
-  // Select the Sender ID
185
-  $("#selectcalleridbttn").on("click", function(event) {
186
-
187
-     $('#selectcalleridbttn').addClass('icon-loading');
188
-
189
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
190
-
191
-     $.ajax({
192
-          url: getsmsnumbersUrl + '/' + userid,
193
-          type: "POST",
194
-          data: { userid: userid },
195
-          cache: false,
196
-          processData: false,
197
-          contentType: false,
198
-          success: function(currentnmbrs) {
199
-
200
-                     $('#currentsmsnmbrs').empty();
201
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
202
-
203
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
204
-                         var emptyinit = indsmsnmb.split(":");
205
-                         var emptysec = emptyinit[1];
206
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
207
-
208
-                         if (emptycheck != '') {
209
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
210
-                         }
211
-                     });
212
-
213
-                     $('#selectcalleridbttn').removeClass('icon-loading');
214
-          }
215
-     });
216
-  });
217
-
218
-  // If a Sender ID is selected, get it
219
-  $("#currentsmsnmbrs").on("change", function () {
220
-
221
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
222
-
223
-              selectedid = $('#currentsmsnmbrs :selected').val();
224
-              var setIdsplit = selectedid.split(":");
225
-	      chosenProvider = setIdsplit[0];
226
-
227
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
228
-	      if (chosenProvider == "Tx") {
229
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
230
-		  // Maximum size of message text + files in KB
231
-		  maximumsize = 1024;
232
-                  maximumsizeinit = 1024;
233
-		  maxsizenonimage = 600;
234
-		  maximumfilenumber = 10;
235
-                  chosenProvFullName = "Telnyx";
236
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
237
-                                     or gif files, the size of all the files plus the size of the text should be \
238
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
239
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
240
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
241
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
242
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
243
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
244
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
245
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
246
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
247
-                  $("#tooltiptextfourth").html(infonotecontent);
248
-	      } else if (chosenProvider == "Pl") {
249
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
250
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
251
-		  // Maximum size of message text + files in KB
252
-		  maximumsize = 5120;
253
-                  maximumsizeinit = 5120;
254
-		  maxsizenonimage = 600;
255
-		  maximumfilenumber = 10;
256
-                  chosenProvFullName = "Plivo";
257
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
258
-                                     or gif files, the size of all the files plus the size of the text should be \
259
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
260
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
261
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
262
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
263
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
264
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
265
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
266
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
267
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
268
-                  $("#tooltiptextfourth").html(infonotecontent);
269
-	      } else if (chosenProvider == "Tw") {
270
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
271
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
272
-                                     "icalendar", "directory", "pdf", "pkpass"];
273
-		  // Maximum size of message text + files in KB
274
-		  maximumsize = 5120;
275
-                  maximumsizeinit = 5120;
276
-		  maxsizenonimage = 600;
277
-		  maximumfilenumber = 10;
278
-                  chosenProvFullName = "Twilio";
279
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
280
-                                     or gif files, the size of all the files plus the size of the text should be \
281
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
282
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
283
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
284
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
285
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
286
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
287
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
288
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
289
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
290
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
291
-                                     previewed in the adjoining pane."
292
-                  $("#tooltiptextfourth").html(infonotecontent);
293
-	      } else if (chosenProvider == "Fl") {
294
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
295
-		  // Maximum size of message text + files in KB
296
-		  maximumsize = 750;
297
-                  maximumsizeinit = 750;
298
-		  maxsizenonimage = 600;
299
-		  maximumfilenumber = 10;
300
-                  chosenProvFullName = "Flowroute";
301
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
302
-                                     png or gif files, the size of all the files plus the size of the text should be \
303
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
304
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
305
-                                     size of the files plus the size of the text should be 600 KB or less. \
306
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
307
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
308
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
309
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
310
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
311
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
312
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
313
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
314
-                  $("#tooltiptextfourth").html(infonotecontent);
315
-	      }
316
-
317
-          } else { selectedid = ''; }
318
-  });
319
-
320
-  // Check the checkbox to send SMS message to multiple recipients
321
-  $('#tomultchckbx').change(function() {
322
-      if ($(this).is(':checked')) {
323
-          $("#multiplerecivers").css("display", "block");
324
-          $("#smstodiv").css("visibility", "hidden");
325
-          $("#smsto").val("");
326
-
327
-          receiversNumbers.length = 0;
328
-
329
-      } else {
330
-          $("#multiplerecivers").css("display", "none");
331
-          $("#smstodiv").css("visibility", "visible");
332
-
333
-          // Remove the uploaded file(s) if any
334
-          $("#induploadfile").remove();
335
-
336
-          receiversNumbers.length = 0;
337
-      }
338
-  });
339
-
340
-  // Upload the file with the recipients' phone numbers
341
-  $("#uploadfileforsms").change(function(e) {
342
-
343
-     $("#fileuploadednm").empty();
344
-
345
-     receiversNumbers.length = 0;
346
-
347
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
348
-
349
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
350
-
351
-     var formData = new FormData();
352
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
353
-
354
-     var fileup = $('#uploadfileforsms').val();
355
-     var fileuptrim = fileup.split('\\').pop();
356
-
357
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
358
-
359
-     var extension = fileup.replace(/^.*\./, '');
360
-
361
-     if (extension == fileup) {
362
-         extension = "";
363
-     } else {
364
-         extension = extension.toLowerCase();
365
-     }
366
-
367
-     var validExtensionsmrec = ["txt", "csv"];
368
-
369
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
370
-
371
-       if (selectedid != '') {
372
-
373
-               $.ajax({
374
-                 url: baseUrl + '/' + userid,
375
-                 type: "POST",
376
-                 data: formData,
377
-                 cache: false,
378
-                 processData: false,
379
-                 contentType: false,
380
-                 success: function(numberarray) {
381
-
382
-		    if (numberarray.length > 0) {
383
-
384
-		        // Get the array of the receivers' phone numbers
385
-		        if (chosenProvider == "Tx") {
386
-
387
-		             for(key in numberarray) {
388
-		                 receiversNumbers.push("+"+numberarray[key]);
389
-		             }
390
-
391
-		        } else if (chosenProvider == "Pl") {
392
-
393
-		             for(key in numberarray) {
394
-		                 receiversNumbers.push(numberarray[key]);
395
-		             }
396
-
397
-		          } else if (chosenProvider == "Tw") {
398
-
399
-		             for(key in numberarray) {
400
-		                 receiversNumbers.push(numberarray[key]);
401
-		             }
402
-		          } else if (chosenProvider == "Fl") {
403
-
404
-		             for(key in numberarray) {
405
-		                 receiversNumbers.push(numberarray[key]);
406
-		             }
407
-		          }
408
-
409
-		    } else {
410
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
411
-		    }
412
-                            
413
-                    // Preview the uploaded file
414
-                    var smsfilename = e.target.files[0].name;
415
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
416
-
417
-                    var reader = new FileReader();
418
-                    reader.readAsText(e.target.files[0]);
419
-                    reader.onload = function(e) {
420
-                          $("#smstables").empty();
421
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
422
-                    };
423
-
424
-                    $("#smstables").show();
425
-
426
-                    $('#sms_upload_msg').hide();
427
-                    $('#smstables').removeClass('icon-loading');
428
-
429
-                  },
430
-                  error: function(){
431
-                     alert('Error!');
432
-                  }
433
-               });
434
-
435
-        } else {
436
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
437
-               $('#sms_upload_msg').hide();
438
-               $('#smstables').removeClass('icon-loading');
439
-        }
440
-
441
-     } else {
442
-          alert('The file type is not supported ! Supported formats are txt and csv.');
443
-          $('#pf_upload_msg').hide();
444
-          $('#smstables').removeClass('icon-loading');
445
-
446
-          $("#induploadfile").remove();
447
-          $("#sms_upload_msg").hide();
448
-     }
449
-
450
-     //Preview uploaded file when clicked
451
-     $("#indfilediv").on("click", function() {
452
-
453
-          var smsfilename = e.target.files[0].name;
454
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
455
-
456
-          var reader = new FileReader();
457
-          reader.readAsText(e.target.files[0]);
458
-          reader.onload = function(e) {
459
-                  $("#smstables").empty();
460
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
461
-          };
462
-
463
-          $("#smstables").show();
464
-          $('#sms_upload_msg').hide();
465
-          $('#smstables').removeClass('icon-loading');
466
-     });
467
-
468
-     // Remove selected file
469
-     $("#indivflremove").on("click", function() {
470
-
471
-          $("#induploadfile").remove();
472
-          $("#sms_upload_msg").hide();
473
-
474
-          receiversNumbers.length = 0;
475
-
476
-     });
477
-
478
-  });
479
-
480
-  // Show the number of characters entered in the SMS textarea and the text size in KB
481
-  $("#smstext").on('input', function() {
482
-
483
-     $("#char_count").css("display", "inline");
484
-
485
-     $("#mtextSize").css("display", "inline");
486
-
487
-     $(".maxmessagelength").css("display", "inline-block");
488
-
489
-     $("#countchnb").text($(this).val().length);
490
-
491
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
492
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
493
-     $("#textsizeinkb").text(textsizekb);
494
-
495
-     if ($(this).val().length > charcolorthr) {
496
-         $("#char_count").css("color", "#BB2E4B");
497
-     } else {
498
-         $("#char_count").css("color", "#4cbc86;");
499
-     }
500
-
501
-  });
502
-
503
-
504
-  // Check the checkbox to send file(s) as MMS
505
-  $('#mediafilechckbx').change(function() {
506
-
507
-      if ($(this).is(':checked')) {
508
-
509
-          isMMS = 1;
510
-          if (selectedid == '') {
511
-              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
512
-              $(this).prop("checked", false);
513
-              isMMS = 0;
514
-              return;
515
-          }
516
-          $("#upmediafiles").css("display", "block");
517
-          $("#submitsms").prop("value", "Send MMS");
518
-
519
-      } else {
520
-
521
-          isMMS = 0;
522
-          $("#upmediafiles").css("display", "none");
523
-          $("#submitsms").prop("value", "Send SMS");
524
-
525
-          // Remove the uploaded file(s) if any
526
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
527
-          $(".indgenpckfls").each(function() { $(this).remove(); });
528
-
529
-          uploadedtomms = [];
530
-          n = 1;
531
-
532
-          msgtotalflsize = 0;
533
-
534
-          $("#filestotsize").hide();
535
-      }
536
-  });
537
-
538
-
539
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
540
-  function adjustMaximumSize(uploadedtomms) {
541
-				      
542
-      var nonimgcheck = 0;
543
-      for (var u = 0; u < uploadedtomms.length; u++) {
544
-	   var crupfl = uploadedtomms[u];
545
-	   var extensionup = crupfl.replace(/^.*\./, '');
546
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
547
-	       nonimgcheck = 1;
548
-	   }
549
-      }
550
-
551
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
552
-  }
553
-
554
-  // Upload files to be sent as MMS
555
-  $("#uploadfileformms").change(function(e) {
556
-
557
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
558
-     $('#smstables').addClass('icon-loading');
559
-     $('#filestotsize').show();
560
-
561
-     var userid = "<?php p($userId); ?>";
562
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
563
-
564
-     var formData = new FormData();
565
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
566
-
567
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
568
-
569
-     // Add the size of the current file to the total size of all the files
570
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
571
-
572
-     var fileup = $('#uploadfileformms').val();
573
-     var fileuptrim = fileup.split('\\').pop();
574
-
575
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
576
-         var duplicatescheck = 1;
577
-     } else { 
578
-         var duplicatescheck = 0;
579
-     }
580
-
581
-     var extension = fileup.replace(/^.*\./, '');
582
-
583
-     if (extension == fileup) {
584
-         extension = "";
585
-     } else {
586
-         extension = extension.toLowerCase();
587
-     }
588
-
589
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
590
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
591
-         maximumsize = maxsizenonimage;
592
-     }
593
-
594
-     if ($.inArray(extension, validExtensions) != -1) {
595
-
596
-       if (duplicatescheck == 0) {
597
-
598
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
599
-
600
-            if (n <= maximumfilenumber) {
601
-
602
-               $.ajax({
603
-                 url: baseUrl + '/' + userid,
604
-                 type: "POST",
605
-                 data: formData,
606
-                 cache: false,
607
-                 processData: false,
608
-                 contentType: false,
609
-                 success: function(totalflsize) {
610
-
611
-                   uploadedtomms.push(fileuptrim);
612
-
613
-                   $('#filessizetext').text(totalflsize);
614
-
615
-                   var rectotfilesz = parseFloat(totalflsize);
616
-
617
-                   if (rectotfilesz <= maximumsize) {
618
-                       $('#submitsms').attr("disabled", false);
619
-                       $('#filestotsize').css('color', '#189558');
620
-                   } else {
621
-                       $('#filestotsize').css('color', '#ba3555');
622
-                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
623
-                       $('#submitsms').attr("disabled", true);
624
-                       $('#smstables').removeClass('icon-loading');
625
-                       $('#pf_upload_msg').hide();
626
-                   }
627
-
628
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
629
-                   n++;
630
-
631
-                   // Preview the file when you click on its name
632
-                   $("div:visible[id*='indfilediv']").each(function() {
633
-
634
-                        $(this).on("click", function(eventclck) {
635
-
636
-                           $("#mmsfoldersview").css("display", "inline-block");
637
-                           var mmsfilenameinit = $(this).text();
638
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
639
-                           var mmsfilename = mmsfilenamesec.replace("X","");
640
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
641
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
642
-
643
-                           if (extenlst == mmsfilename) {
644
-                               extenlst = "";
645
-                           } else {
646
-                               extenlst = extenlst.toLowerCase();
647
-                           }
648
-
649
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
650
-                                  $("#smstables").empty();
651
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
652
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
653
-                           } else if (extenlst == 'png') {
654
-                                  $("#smstables").empty();
655
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
656
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
657
-                           } else if (extenlst == 'gif') {
658
-                                  $("#smstables").empty();
659
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
660
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
661
-                           } else if (extenlst == 'bmp') {
662
-                                  $("#smstables").empty();
663
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
664
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
665
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
666
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
667
-                                  var xhr = new XMLHttpRequest();
668
-                                  xhr.responseType = 'arraybuffer';
669
-                                  xhr.open('GET', tiffile);
670
-                                  xhr.onload = function (evnt) {
671
-                                      var tiff = new Tiff({buffer: xhr.response});
672
-                                      var tifcanvas = tiff.toCanvas();
673
-                                      $("#smstables").empty();
674
-                                      $("#smstables").append(tifcanvas);
675
-                                  };
676
-                                  xhr.send();
677
-                           } else if (extenlst == 'pdf') {
678
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
679
-                                  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>');
680
-                                  $("#smstables").empty();
681
-                                  $("#smstables").append($iframe);
682
-                           } else if (extenlst == 'txt') {
683
-                                  $("#smstables").empty();
684
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
685
-                           } else if (extension == 'mp4') {
686
-                                  $("#smstables").empty();
687
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
688
-		           } else if (extension == 'ogg') {
689
-		                  $("#smstables").empty();
690
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
691
-		           } else if (extension == 'avi') {
692
-		                  $("#smstables").empty();
693
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
694
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
695
-		                  $("#smstables").empty();
696
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
697
-		           } else if (extension == 'wav' || extension == 'wave') {
698
-		                  $("#smstables").empty();
699
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
700
-		           } else if (extension == 'mp3') {
701
-		                  $("#smstables").empty();
702
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
703
-		           } else if (extension == 'midi') {
704
-		                  $("#smstables").empty();
705
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
706
-		           }
707
-
708
-                           $("#smstables").show();
709
-                           $("#mmsfoldersview").hide();
710
-                        });
711
-                   });
712
-
713
-                   // Remove uploaded files
714
-                   $('[class*="indupfldl"]').last().click(function() {
715
-
716
-                           var userid = "<?php p($userId); ?>";
717
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
718
-
719
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
720
-
721
-                           var removedfilesplit = removedfilenameinit.split(") ");
722
-                           var removedflnb = parseInt(removedfilesplit[0]);
723
-
724
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
725
-                           $(this).hide();
726
-
727
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
728
-
729
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
730
-                                           return value != removedfilename;
731
-                           });
732
-
733
-                           $.ajax({
734
-                                   url: baseUrl + '/' + userid,
735
-                                   type: "POST",
736
-                                   data: {removedfilename: removedfilename},
737
-                                   success: function(totalflsize) {
738
-
739
-                                      msgtotalflsize = totalflsize;
740
-                                      $('#filessizetext').text(totalflsize);
741
-
742
-                                      adjustMaximumSize(uploadedtomms);
743
-
744
-                                      // Check message size
745
-                                      var rectotfilesz = parseFloat(totalflsize);
746
-
747
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
748
-                                          $('#submitsms').attr("disabled", false);
749
-                                          $('#filestotsize').css('color', '#189558');
750
-                                      } else {
751
-                                          $('#filestotsize').css('color', '#ba3555');
752
-                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
753
-                                          $('#submitsms').attr("disabled", true);
754
-                                      }
755
-
756
-                                      // Rewrite order numbers for files that follow
757
-                                      --n;
758
-                                      $("div:visible[id*='indfilediv']").each(function() {
759
-
760
-                                          var getdivtext =  $(this).text();
761
-                                          var splitdivtext = getdivtext.split(") ");
762
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
763
-                                          var newnbvalue = currentnbvalue - 1;
764
-
765
-                                          if (currentnbvalue > removedflnb) {
766
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
767
-                                              $(this).text(replacedstr);
768
-                                          }
769
-                                      });
770
-
771
-                                      $("div:visible[id*='indflpicked']").each(function() {
772
-
773
-                                          var getdivtext =  $(this).text();
774
-                                          var splitdivtext = getdivtext.split(") ");
775
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
776
-                                          var newnbvalue = currentnbvalue - 1;
777
-
778
-                                          if (currentnbvalue > removedflnb) {
779
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
780
-                                              $(this).text(replacedstr);
781
-                                          }
782
-                                      });
783
-
784
-                                   },
785
-                                   error: function() {
786
-                                          alert('Error removing file(s)!');
787
-                                   }
788
-                           });
789
-
790
-                           $('#smstables').removeClass('icon-loading');
791
-                           $("#smstables").empty();
792
-                   });
793
-
794
-                   // Preview the uploaded file
795
-                   $("#mmsfoldersview").css("display", "inline-block");
796
-                   var mmsfilename = e.target.files[0].name;
797
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
798
-
799
-
800
-                   if (extension == 'jpg' || extension == 'jpeg') {
801
-                              $("#smstables").empty();
802
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
803
-
804
-                              var reader = new FileReader();
805
-                              reader.onload = function (e) {
806
-                                  readjpg[mmsfilename] = e.target.result;
807
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
-                              }
809
-                              reader.readAsDataURL(e.target.files[0]);
810
-                   } else if (extension == 'png') {
811
-                              $("#smstables").empty();
812
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
813
-
814
-                              var reader = new FileReader();
815
-                              reader.onload = function (e) {
816
-                                  readpng[mmsfilename] = e.target.result;
817
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
818
-                              }
819
-                              reader.readAsDataURL(e.target.files[0]);
820
-
821
-                   } else if (extension == 'gif') {
822
-                              $("#smstables").empty();
823
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
824
-
825
-                              var reader = new FileReader();
826
-                              reader.onload = function (e) {
827
-                                  readgif[mmsfilename] = e.target.result;
828
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
829
-                              }
830
-                              reader.readAsDataURL(e.target.files[0]);
831
-
832
-                   } else if (extension == 'bmp') {
833
-                              $("#smstables").empty();
834
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
835
-
836
-                              var reader = new FileReader();
837
-                              reader.onload = function (e) {
838
-                                  readbmp[mmsfilename] = e.target.result;
839
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
840
-                              }
841
-                              reader.readAsDataURL(e.target.files[0]);
842
-
843
-                   } else if (extension == 'tif' || extension == 'tiff') {
844
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
-                              var xhr = new XMLHttpRequest();
846
-                              xhr.responseType = 'arraybuffer';
847
-                              xhr.open('GET', tiffile);
848
-                              xhr.onload = function (e) {
849
-                                  var tiff = new Tiff({buffer: xhr.response});
850
-                                  var tifcanvas = tiff.toCanvas();
851
-                                  $("#smstables").empty();
852
-                                  $("#smstables").append(tifcanvas);
853
-                              };
854
-                              xhr.send();
855
-
856
-                   } else if (extension == 'pdf') {
857
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
-                              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>');
859
-                              $("#smstables").empty();
860
-                              $("#smstables").append($iframe);
861
-
862
-                   } else if (extension == 'txt') {
863
-                              var reader = new FileReader();
864
-                              reader.readAsText(e.target.files[0]);
865
-                              reader.onload = function(e) {
866
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
867
-                                  $("#smstables").empty();
868
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
869
-                              };
870
-                   } else if (extension == 'mp4') {
871
-                              $("#smstables").empty();
872
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
873
-                   } else if (extension == 'ogg') {
874
-                              $("#smstables").empty();
875
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
876
-                   } else if (extension == 'avi') {
877
-                              $("#smstables").empty();
878
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
879
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
880
-                              $("#smstables").empty();
881
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
882
-                   } else if (extension == 'wav' || extension == 'wave') {
883
-                              $("#smstables").empty();
884
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
885
-                   } else if (extension == 'mp3') {
886
-                              $("#smstables").empty();
887
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
888
-                   } else if (extension == 'midi') {
889
-                              $("#smstables").empty();
890
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
891
-                   }
892
-
893
-                   $("#smstables").show();
894
-                   $('#pf_upload_msg').hide();
895
-                   $('#smstables').removeClass('icon-loading');
896
-                   $("#mmsfoldersview").hide();
897
-                 },
898
-                 error: function(data){
899
-                     alert('Error uploading file!');
900
-                 }
901
-               });
902
-
903
-            } else {
904
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
905
-                  adjustMaximumSize(uploadedtomms);
906
-
907
-                  alert("Error ! You cannot send more than 10 files in one MMS !");
908
-                  $('#pf_upload_msg').hide();
909
-                  $('#smstables').removeClass('icon-loading');
910
-            }
911
-         } else {
912
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
913
-              adjustMaximumSize(uploadedtomms);
914
-
915
-              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
916
-              $('#pf_upload_msg').hide();
917
-              $('#smstables').removeClass('icon-loading');
918
-         }
919
-       } else {
920
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
921
-            adjustMaximumSize(uploadedtomms);
922
-
923
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
924
-            $('#pf_upload_msg').hide();
925
-            $('#smstables').removeClass('icon-loading');
926
-       }
927
-
928
-     } else {
929
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
930
-          adjustMaximumSize(uploadedtomms);
931
-
932
-          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
933
-          $('#pf_upload_msg').hide();
934
-          $('#smstables').removeClass('icon-loading');
935
-     }
936
-  });
937
-
938
-
939
-  // Pick file(s) from Nextcloud, to send as MMS
940
-  var mmsfilename = null;
941
-
942
-  $("#choosefilen").on("click", function(evn) {
943
-
944
-                OC.dialogs.filepicker(
945
-                        t('settings', "Select a file to send as MMS."),
946
-                        function (path) {
947
-
948
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
949
-                              $('#smstables').addClass('icon-loading');
950
-                              $('#filestotsize').show();
951
-
952
-                              var userid = "<?php p($userId); ?>";
953
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
954
-
955
-                              mmsfilename = path.split('/').pop();
956
-
957
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
958
-                                  var duplicatescheck = 1;
959
-                              } else var duplicatescheck = 0;
960
-
961
-                              var extension = mmsfilename.replace(/^.*\./, '');
962
-
963
-                              if (extension == mmsfilename) {
964
-                                  extension = "";
965
-                              } else {
966
-                                  extension = extension.toLowerCase();
967
-                              }
968
-
969
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
970
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
971
-				   maximumsize = maxsizenonimage;
972
-			      }
973
-
974
-                              if ($.inArray(extension, validExtensions) != -1) {
975
-
976
-                                 if (duplicatescheck == 0) {
977
-
978
-                                    if (n <= maximumfilenumber) {
979
-
980
-                                       $.ajax({
981
-                                          url: baseUrl + '/' + userid,
982
-                                          type: "POST",
983
-                                          data: {path: path},
984
-                                          success: function(pickresult) {
985
-
986
-                                                uploadedtomms.push(mmsfilename);
987
-
988
-                                                var totalflsize = pickresult[0];
989
-                                                var pickedflsize = pickresult[1];
990
-
991
-                                                // Check message size
992
-                                                var rectotfilesz = parseFloat(totalflsize);
993
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
994
-
995
-                                                if (filesplustextsize <= maximumsize) {
996
-
997
-                                                    $("#mmsfoldersview").css("display", "inline-block");
998
-
999
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1000
-                                                    n++;
1001
-
1002
-                                                    msgtotalflsize = totalflsize;
1003
-                                                    $('#filessizetext').text(totalflsize);
1004
-                                                    $('#filestotsize').css('color', '#189558');
1005
-
1006
-                                                } else {
1007
-
1008
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1009
-                                                    $('#filestotsize').css('color', '#ba3555');
1010
-                                                    msgtotalflsize -= pickedflsize;
1011
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1012
-
1013
-                                                    $.ajax({
1014
-                                                        url: baseUrlindrm + '/' + userid,
1015
-                                                        type: "POST",
1016
-                                                        data: {removedfilename: mmsfilename},
1017
-                                                        success: function(totalflsize) {
1018
-
1019
-                                                                          $('#filessizetext').text(totalflsize);
1020
-                                                                          $('#filestotsize').css('color', '#189558');
1021
-                                                                          adjustMaximumSize(uploadedtomms);
1022
-
1023
-                                                        },
1024
-                                                        error: function(totalflsize) {
1025
-                                                                          $('#filessizetext').text(totalflsize);
1026
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1027
-                                                                              $('#filestotsize').css('color', '#ba3555');
1028
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1029
-                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1030
-                                                        }
1031
-                                                    });
1032
-
1033
-                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1034
-
1035
-                                                }
1036
-
1037
-
1038
-                                                // Preview each file when you click on its name
1039
-                                                $("div:visible[id*='indflpicked']").each(function() {
1040
-                                                   $(this).on("click", function(event) {
1041
-
1042
-                                                      var mmsfilenameinit = $(this).text();
1043
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
-
1048
-                                                      if (extenlst == mmsfilenamesp) {
1049
-                                                           extenlst = "";
1050
-                                                      } else {
1051
-                                                           extenlst = extenlst.toLowerCase();
1052
-                                                      }
1053
-
1054
-
1055
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
-                                                              $("#smstables").empty();
1057
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
-                                                      } else if (extenlst == 'png') {
1059
-                                                              $("#smstables").empty();
1060
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1061
-                                                      } else if (extenlst == 'gif') {
1062
-                                                              $("#smstables").empty();
1063
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1064
-                                                      } else if (extenlst == 'bmp') {
1065
-                                                              $("#smstables").empty();
1066
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1067
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1068
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1069
-                                                              var xhr = new XMLHttpRequest();
1070
-                                                              xhr.responseType = 'arraybuffer';
1071
-                                                              xhr.open('GET', tiffile);
1072
-                                                              xhr.onload = function (evnt) {
1073
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1074
-                                                                  var tifcanvas = tiff.toCanvas();
1075
-                                                                  $("#smstables").empty();
1076
-                                                                  $("#smstables").append(tifcanvas);
1077
-                                                              };
1078
-                                                              xhr.send();
1079
-                                                      } else if (extenlst == 'pdf') {
1080
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1081
-                                                              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>');
1082
-                                                              $("#smstables").empty();
1083
-                                                              $("#smstables").append($iframe);
1084
-                                                      } else if (extenlst == 'txt') {
1085
-                                                              $("#smstables").empty();
1086
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1087
-                                                      } else if (extension == 'mp4') {
1088
-							      $("#smstables").empty();
1089
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1090
-						      } else if (extension == 'ogg') {
1091
-							      $("#smstables").empty();
1092
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1093
-						      } else if (extension == 'avi') {
1094
-							      $("#smstables").empty();
1095
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1096
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1097
-							      $("#smstables").empty();
1098
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1099
-						      } else if (extension == 'wav' || extension == 'wave') {
1100
-							      $("#smstables").empty();
1101
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1102
-						      } else if (extension == 'mp3') {
1103
-							      $("#smstables").empty();
1104
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1105
-						      } else if (extension == 'midi') {
1106
-							      $("#smstables").empty();
1107
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1108
-						      }
1109
-
1110
-
1111
-                                                      $("#smstables").show();
1112
-                                                      $("#mmsfoldersview").hide();
1113
-                                                   });
1114
-                                                });
1115
-
1116
-
1117
-                                                // Remove picked files
1118
-                                                $('[class*="indpckfldl"]').last().click(function() {
1119
-                                                    var userid = "<?php p($userId); ?>";
1120
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1121
-
1122
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1123
-
1124
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1125
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1126
-
1127
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1128
-                                                    $(this).hide();
1129
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1130
-
1131
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1132
-                                                             return value != removedfilename;
1133
-                                                    });
1134
-
1135
-                                                    $.ajax({
1136
-                                                        url: baseUrl + '/' + userid,
1137
-                                                        type: "POST",
1138
-                                                        data: {removedfilename: removedfilename},
1139
-                                                        success: function(totalflsize) {
1140
-
1141
-                                                             msgtotalflsize = totalflsize;
1142
-                                                             $('#filessizetext').text(totalflsize);
1143
-                                                             adjustMaximumSize(uploadedtomms);
1144
-
1145
-                                                             // Check message size
1146
-                                                             var rectotfilesz = parseFloat(totalflsize);
1147
-
1148
-                                                             if (rectotfilesz > maximumsize) {
1149
-                                                                 $('#filestotsize').css('color', '#ba3555');
1150
-                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1151
-                                                                 $('#submitsms').attr("disabled", true);
1152
-                                                             } else {
1153
-                                                                 $('#submitsms').attr("disabled", false);
1154
-                                                                 $('#filestotsize').css('color', '#189558');
1155
-                                                               }
1156
-
1157
-                                                             // Rewrite order numbers for files that follow
1158
-                                                             --n;
1159
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1160
-
1161
-                                                                  var getdivtext =  $(this).text();
1162
-                                                                  var splitdivtext = getdivtext.split(") ");
1163
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1164
-                                                                  var newnbvalue = currentnbvalue - 1;
1165
-
1166
-                                                                  if (currentnbvalue > removedflnb) {
1167
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1168
-                                                                      $(this).text(replacedstr);
1169
-                                                                  }
1170
-                                                             });
1171
-                                                        },
1172
-                                                        error: function() {
1173
-                                                             alert('Error !');
1174
-                                                        }
1175
-                                                    });
1176
-
1177
-                                                    $('#smstables').removeClass('icon-loading');
1178
-                                                    $("#smstables").empty();
1179
-                                                });
1180
-
1181
-
1182
-		                                // Preview the picked file
1183
-		                                $("#mmsfoldersview").css("display", "inline-block");
1184
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1185
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1186
-
1187
-
1188
-						if (extension == 'jpg' || extension == 'jpeg') {
1189
-
1190
-		                                            $("#smstables").empty();
1191
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1192
-
1193
-		                                } else if (extension == 'png') {
1194
-
1195
-		                                            $("#smstables").empty();
1196
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1197
-
1198
-		                                } else if (extension == 'gif') {
1199
-
1200
-		                                            $("#smstables").empty();
1201
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1202
-
1203
-		                                } else if (extension == 'bmp') {
1204
-
1205
-	                                                    $("#smstables").empty();
1206
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1207
-
1208
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1209
-
1210
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1211
-		                                       var xhr = new XMLHttpRequest();
1212
-		                                       xhr.responseType = 'arraybuffer';
1213
-		                                       xhr.open('GET', tiffile);
1214
-		                                       xhr.onload = function (event) {
1215
-		                                           var tiff = new Tiff({buffer: xhr.response});
1216
-		                                           var tifcanvas = tiff.toCanvas();
1217
-		                                           $("#smstables").empty();
1218
-		                                           $("#smstables").append(tifcanvas);
1219
-		                                       };
1220
-		                                       xhr.send();
1221
-
1222
-		                                } else if (extension == 'pdf') {
1223
-
1224
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1225
-		                                       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>');
1226
-		                                       $("#smstables").empty();
1227
-		                                       $("#smstables").append($iframe);
1228
-
1229
-		                                } else if (extension == 'txt') {
1230
-
1231
-							     $.get(flUrl, function(textdata) {
1232
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1233
-		                                               $("#smstables").empty();
1234
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1235
-							     });
1236
-
1237
-		                                } else if (extension == 'mp4') {
1238
-						       $("#smstables").empty();
1239
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1240
-						} else if (extension == 'ogg') {
1241
-						       $("#smstables").empty();
1242
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
-						} else if (extension == 'avi') {
1244
-						       $("#smstables").empty();
1245
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1246
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1247
-						       $("#smstables").empty();
1248
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1249
-						} else if (extension == 'wav' || extension == 'wave') {
1250
-						       $("#smstables").empty();
1251
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1252
-						} else if (extension == 'mp3') {
1253
-						       $("#smstables").empty();
1254
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1255
-						} else if (extension == 'midi') {
1256
-						       $("#smstables").empty();
1257
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1258
-						}
1259
-
1260
-
1261
-		                                $("#smstables").show();
1262
-
1263
-		                                $('#pf_choose_msg').hide();
1264
-		                                $('#smstables').removeClass('icon-loading');
1265
-		                                $("#mmsfoldersview").hide();
1266
-
1267
-                                          },
1268
-
1269
-                                          error: function(data){
1270
-                                             alert('Error!');
1271
-                                          }
1272
-
1273
-                                       });
1274
-
1275
-                                    } else {
1276
-                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1277
-                                        $('#pf_choose_msg').hide();
1278
-                                        $('#smstables').removeClass('icon-loading');
1279
-                                      }
1280
-                                 } else {
1281
-                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1282
-                                      $('#pf_choose_msg').hide();
1283
-                                      $('#smstables').removeClass('icon-loading');
1284
-                                   }
1285
-
1286
-                              } else {
1287
-                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1288
-                                   $('#pf_choose_msg').hide();
1289
-                                   $('#smstables').removeClass('icon-loading');
1290
-                                }
1291
-
1292
-                        }
1293
-                );
1294
-  });
1295
-
1296
-
1297
-
1298
-  // Send the SMS/MMS message
1299
-  $("#submitsms").on("click", function(event) {
1300
-
1301
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1302
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1303
-     $("#sms_submit_msg").css("display", "inline-block");
1304
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1305
-
1306
-     if (selectedid != '') { 
1307
-
1308
-         var sendersplit = selectedid.split(":");
1309
-         var providercap = sendersplit[0];
1310
-         var provsec = sendersplit[1];
1311
-
1312
-         if (/[a-zA-Z]/.test(provsec)) {
1313
-             var alphanumcheck = true;
1314
-         } else { var alphanumcheck = false; }
1315
-
1316
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1317
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1318
-             var selectedsender = "+" + senderproc;
1319
-             var providerUsed = "telnyx";
1320
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1321
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1322
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1323
-             var providerUsed = "plivo";
1324
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1325
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1326
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1327
-             var selectedsender = "+" + senderproc;
1328
-             var providerUsed = "twilio";
1329
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1330
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1331
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1332
-             var selectedsender = "+" + senderproc;
1333
-             var providerUsed = "flowroute";
1334
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1335
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1336
-             var selectedsender = provsec;
1337
-             var providerUsed = "telnyx";
1338
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1339
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1340
-             var selectedsender = provsec;
1341
-             var providerUsed = "plivo";
1342
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1343
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1344
-             var selectedsender = provsec;
1345
-             var providerUsed = "twilio";
1346
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1347
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1348
-             var selectedsender = provsec;
1349
-             var providerUsed = "flowroute";
1350
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1351
-         }
1352
-
1353
-         // Get the interval between message consecutive sending requests, if it's the case
1354
-         if ($('#tomultchckbx').is(':checked')) {
1355
-
1356
-             var numbersfile = 1;
1357
-             var initinterval = $("#multsmsinterval").val();
1358
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1359
-
1360
-             if (secinterval != '') {
1361
-                 var tertinterval = parseInt(secinterval);
1362
-                     waittime = tertinterval;
1363
-             }
1364
-
1365
-         } else {
1366
-
1367
-             var numbersfile = 0;
1368
-             var toNumberinit = $('#smsto').val();
1369
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1370
-             var toNumbersec = toNumber.split(",");
1371
-
1372
-                 for (var i = 0; i < toNumbersec.length; i++) {
1373
-                      toNumbersec[i] = "+" + toNumbersec[i];
1374
-                 }
1375
-
1376
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1377
-         }
1378
-
1379
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1380
-
1381
-         var smstext = $("#smstext").val();
1382
-
1383
-         if (receiversNumbers.length != 0) {
1384
-
1385
-              if (smstext != '') {
1386
-                  $.ajax({
1387
-                     url: relbaseUrl + '/' + userid,
1388
-                     type: "POST",
1389
-                     data: {
1390
-                           receiversPhoneNbs: receiversNumbers,
1391
-                           fromsender: selectedsender,
1392
-                           waitinterval: waittime,
1393
-                           sentsmstext: smstext,
1394
-                           ismms: isMMS,
1395
-                           mmsfiles: uploadedtomms
1396
-                         },
1397
-                     success: function() {
1398
-
1399
-                           if (receiversNumbers.length == 1) {
1400
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1401
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1402
-
1403
-                           $('#sms_submit_msg').hide();
1404
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1405
-                     },
1406
-                     error: function() {
1407
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1408
-                           $('#sms_submit_msg').hide();
1409
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1410
-                     }
1411
-                  });
1412
-              } else {
1413
-                     alert("Please enter a message in the text box !");
1414
-                     $('#sms_submit_msg').hide();
1415
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1416
-              }
1417
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1418
-                 alert("Please enter the recipient's phone number !");
1419
-                 $('#sms_submit_msg').hide();
1420
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1421
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1422
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1423
-                 $('#sms_submit_msg').hide();
1424
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1425
-         }
1426
-     } else {
1427
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
1428
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1429
-           $('#sms_submit_msg').hide();
1430
-     }
1431
-
1432
-  });
1433
-
1434
-  // Check the checkbox to delete old messages from the database
1435
-  $('#deleteoldchckbox').change(function() {
1436
-     if ($(this).is(':checked')) {
1437
-         $("#deleteoldsms").css("display", "block");
1438
-     } else {
1439
-         $("#deleteoldsms").css("display", "none");
1440
-     }
1441
-  });
1442
-
1443
-  // Set the height of 3 info notes
1444
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1445
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1446
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1447
-
1448
-  $(window).resize(function() { 
1449
-    $('#setcalleridtp').css('height', $(window).height() - 160);
1450
-    $('#tonmbrformat').css('height', $(window).height() - 260);
1451
-    $('#uploadfileinfo').css('height', $(window).height() - 390);
1452
-  });
1453
-
Browse code

added README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendsms.js

DoubleBastionAdmin authored on 05/09/2022 18:46:45
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1453 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readjpg = [];
37
+  var readpng = [];
38
+  var readgif = [];
39
+  var readbmp = [];
40
+  var readtif = [];
41
+  var readmp4 = [];
42
+  var chosenProvider = '';
43
+  var chosenProvFullName = '';
44
+  var infonotecontent = '';
45
+  var validExtensions = [];
46
+  var maximumsize = 750;
47
+  var maxsizenonimage = 600;
48
+  var maximumfilenumber = 10;
49
+  var maximumsizeinit = 750;
50
+
51
+  // 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
52
+  var locHref = window.location.href;
53
+  var pathSplit = locHref.split('/');
54
+  var firstPathEl = '';
55
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
56
+
57
+  // Clean the SMS_Relentless/temp_files directory
58
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
59
+
60
+  $.ajax({
61
+          url: cleanflUrl + '/' + userid,
62
+          type: "POST",
63
+          data: { userid: userid },
64
+          cache: false,
65
+          processData: false,
66
+          contentType: false
67
+  });
68
+  
69
+  // Check the available balance
70
+  $("#smsprovider").on("change", function () {
71
+
72
+     var provider = $('#smsprovider :selected').val();
73
+
74
+     if (provider == "Telnyx") {
75
+
76
+        var gettelbalance = function() {
77
+
78
+          $('#currentbalance').addClass('icon-loading');
79
+
80
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
81
+
82
+          $.ajax({
83
+              url: gettelbalanceUrl + '/' + userid,
84
+              type: "POST",
85
+              data: { userid: userid },
86
+              cache: false,
87
+              processData: false,
88
+              contentType: false,
89
+              success: function(currentbalancetel) {
90
+
91
+                     $('#currentbalance').empty();
92
+                     $('#currentbalance').text(currentbalancetel);
93
+                     $('#currentbalance').removeClass('icon-loading');
94
+              }
95
+          });
96
+        }
97
+
98
+        gettelbalance();
99
+
100
+     } else if (provider == "Plivo") {
101
+
102
+          var getnexbalance = function() {
103
+
104
+            $('#currentbalance').addClass('icon-loading');
105
+
106
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
107
+
108
+            $.ajax({
109
+                url: getnexbalanceUrl + '/' + userid,
110
+                type: "POST",
111
+                data: { userid: userid },
112
+                cache: false,
113
+                processData: false,
114
+                contentType: false,
115
+                success: function(currentbalancenex) {
116
+
117
+                     $('#currentbalance').empty();
118
+                     $('#currentbalance').text(currentbalancenex);
119
+                     $('#currentbalance').removeClass('icon-loading');
120
+                }
121
+            });
122
+          }
123
+
124
+          getnexbalance();
125
+
126
+     } else if (provider == "Twilio") {
127
+
128
+          var gettwilbalance = function() {
129
+
130
+            $('#currentbalance').addClass('icon-loading');
131
+
132
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
133
+
134
+            $.ajax({
135
+                url: gettwilbalanceUrl + '/' + userid,
136
+                type: "POST",
137
+                data: { userid: userid },
138
+                cache: false,
139
+                processData: false,
140
+                contentType: false,
141
+                success: function(currentbalancetwil) {
142
+
143
+                     $('#currentbalance').empty();
144
+                     $('#currentbalance').text(currentbalancetwil);
145
+                     $('#currentbalance').removeClass('icon-loading');
146
+                }
147
+            });
148
+          }
149
+
150
+          gettwilbalance();
151
+
152
+     } else if (provider == "Flowroute") {
153
+
154
+          var getflowbalance = function() {
155
+
156
+            $('#currentbalance').addClass('icon-loading');
157
+
158
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
159
+
160
+            $.ajax({
161
+                url: getflowbalanceUrl + '/' + userid,
162
+                type: "POST",
163
+                data: { userid: userid },
164
+                cache: false,
165
+                processData: false,
166
+                contentType: false,
167
+                success: function(currentbalanceflow) {
168
+
169
+                     $('#currentbalance').empty();
170
+                     $('#currentbalance').text(currentbalanceflow);
171
+                     $('#currentbalance').removeClass('icon-loading');
172
+                }
173
+            });
174
+          }
175
+
176
+          getflowbalance();
177
+
178
+       } else if (provider == "") {
179
+                $('#currentbalance').text("");
180
+                $('#currentbalance').removeClass('icon-loading');
181
+       }
182
+  });
183
+
184
+  // Select the Sender ID
185
+  $("#selectcalleridbttn").on("click", function(event) {
186
+
187
+     $('#selectcalleridbttn').addClass('icon-loading');
188
+
189
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
190
+
191
+     $.ajax({
192
+          url: getsmsnumbersUrl + '/' + userid,
193
+          type: "POST",
194
+          data: { userid: userid },
195
+          cache: false,
196
+          processData: false,
197
+          contentType: false,
198
+          success: function(currentnmbrs) {
199
+
200
+                     $('#currentsmsnmbrs').empty();
201
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
202
+
203
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
204
+                         var emptyinit = indsmsnmb.split(":");
205
+                         var emptysec = emptyinit[1];
206
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
207
+
208
+                         if (emptycheck != '') {
209
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
210
+                         }
211
+                     });
212
+
213
+                     $('#selectcalleridbttn').removeClass('icon-loading');
214
+          }
215
+     });
216
+  });
217
+
218
+  // If a Sender ID is selected, get it
219
+  $("#currentsmsnmbrs").on("change", function () {
220
+
221
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
222
+
223
+              selectedid = $('#currentsmsnmbrs :selected').val();
224
+              var setIdsplit = selectedid.split(":");
225
+	      chosenProvider = setIdsplit[0];
226
+
227
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
228
+	      if (chosenProvider == "Tx") {
229
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
230
+		  // Maximum size of message text + files in KB
231
+		  maximumsize = 1024;
232
+                  maximumsizeinit = 1024;
233
+		  maxsizenonimage = 600;
234
+		  maximumfilenumber = 10;
235
+                  chosenProvFullName = "Telnyx";
236
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
237
+                                     or gif files, the size of all the files plus the size of the text should be \
238
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
239
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
240
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
241
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
242
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
243
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
244
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
245
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
246
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
247
+                  $("#tooltiptextfourth").html(infonotecontent);
248
+	      } else if (chosenProvider == "Pl") {
249
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
250
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
251
+		  // Maximum size of message text + files in KB
252
+		  maximumsize = 5120;
253
+                  maximumsizeinit = 5120;
254
+		  maxsizenonimage = 600;
255
+		  maximumfilenumber = 10;
256
+                  chosenProvFullName = "Plivo";
257
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
258
+                                     or gif files, the size of all the files plus the size of the text should be \
259
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
260
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
261
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
262
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
263
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
264
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
265
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
266
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
267
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
268
+                  $("#tooltiptextfourth").html(infonotecontent);
269
+	      } else if (chosenProvider == "Tw") {
270
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
271
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
272
+                                     "icalendar", "directory", "pdf", "pkpass"];
273
+		  // Maximum size of message text + files in KB
274
+		  maximumsize = 5120;
275
+                  maximumsizeinit = 5120;
276
+		  maxsizenonimage = 600;
277
+		  maximumfilenumber = 10;
278
+                  chosenProvFullName = "Twilio";
279
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
280
+                                     or gif files, the size of all the files plus the size of the text should be \
281
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
282
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
283
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
284
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
285
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
286
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
287
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
288
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
289
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
290
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
291
+                                     previewed in the adjoining pane."
292
+                  $("#tooltiptextfourth").html(infonotecontent);
293
+	      } else if (chosenProvider == "Fl") {
294
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
295
+		  // Maximum size of message text + files in KB
296
+		  maximumsize = 750;
297
+                  maximumsizeinit = 750;
298
+		  maxsizenonimage = 600;
299
+		  maximumfilenumber = 10;
300
+                  chosenProvFullName = "Flowroute";
301
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
302
+                                     png or gif files, the size of all the files plus the size of the text should be \
303
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
304
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
305
+                                     size of the files plus the size of the text should be 600 KB or less. \
306
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
307
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
308
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
309
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
310
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
311
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
312
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
313
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
314
+                  $("#tooltiptextfourth").html(infonotecontent);
315
+	      }
316
+
317
+          } else { selectedid = ''; }
318
+  });
319
+
320
+  // Check the checkbox to send SMS message to multiple recipients
321
+  $('#tomultchckbx').change(function() {
322
+      if ($(this).is(':checked')) {
323
+          $("#multiplerecivers").css("display", "block");
324
+          $("#smstodiv").css("visibility", "hidden");
325
+          $("#smsto").val("");
326
+
327
+          receiversNumbers.length = 0;
328
+
329
+      } else {
330
+          $("#multiplerecivers").css("display", "none");
331
+          $("#smstodiv").css("visibility", "visible");
332
+
333
+          // Remove the uploaded file(s) if any
334
+          $("#induploadfile").remove();
335
+
336
+          receiversNumbers.length = 0;
337
+      }
338
+  });
339
+
340
+  // Upload the file with the recipients' phone numbers
341
+  $("#uploadfileforsms").change(function(e) {
342
+
343
+     $("#fileuploadednm").empty();
344
+
345
+     receiversNumbers.length = 0;
346
+
347
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
348
+
349
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
350
+
351
+     var formData = new FormData();
352
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
353
+
354
+     var fileup = $('#uploadfileforsms').val();
355
+     var fileuptrim = fileup.split('\\').pop();
356
+
357
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
358
+
359
+     var extension = fileup.replace(/^.*\./, '');
360
+
361
+     if (extension == fileup) {
362
+         extension = "";
363
+     } else {
364
+         extension = extension.toLowerCase();
365
+     }
366
+
367
+     var validExtensionsmrec = ["txt", "csv"];
368
+
369
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
370
+
371
+       if (selectedid != '') {
372
+
373
+               $.ajax({
374
+                 url: baseUrl + '/' + userid,
375
+                 type: "POST",
376
+                 data: formData,
377
+                 cache: false,
378
+                 processData: false,
379
+                 contentType: false,
380
+                 success: function(numberarray) {
381
+
382
+		    if (numberarray.length > 0) {
383
+
384
+		        // Get the array of the receivers' phone numbers
385
+		        if (chosenProvider == "Tx") {
386
+
387
+		             for(key in numberarray) {
388
+		                 receiversNumbers.push("+"+numberarray[key]);
389
+		             }
390
+
391
+		        } else if (chosenProvider == "Pl") {
392
+
393
+		             for(key in numberarray) {
394
+		                 receiversNumbers.push(numberarray[key]);
395
+		             }
396
+
397
+		          } else if (chosenProvider == "Tw") {
398
+
399
+		             for(key in numberarray) {
400
+		                 receiversNumbers.push(numberarray[key]);
401
+		             }
402
+		          } else if (chosenProvider == "Fl") {
403
+
404
+		             for(key in numberarray) {
405
+		                 receiversNumbers.push(numberarray[key]);
406
+		             }
407
+		          }
408
+
409
+		    } else {
410
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
411
+		    }
412
+                            
413
+                    // Preview the uploaded file
414
+                    var smsfilename = e.target.files[0].name;
415
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
416
+
417
+                    var reader = new FileReader();
418
+                    reader.readAsText(e.target.files[0]);
419
+                    reader.onload = function(e) {
420
+                          $("#smstables").empty();
421
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
422
+                    };
423
+
424
+                    $("#smstables").show();
425
+
426
+                    $('#sms_upload_msg').hide();
427
+                    $('#smstables').removeClass('icon-loading');
428
+
429
+                  },
430
+                  error: function(){
431
+                     alert('Error!');
432
+                  }
433
+               });
434
+
435
+        } else {
436
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
437
+               $('#sms_upload_msg').hide();
438
+               $('#smstables').removeClass('icon-loading');
439
+        }
440
+
441
+     } else {
442
+          alert('The file type is not supported ! Supported formats are txt and csv.');
443
+          $('#pf_upload_msg').hide();
444
+          $('#smstables').removeClass('icon-loading');
445
+
446
+          $("#induploadfile").remove();
447
+          $("#sms_upload_msg").hide();
448
+     }
449
+
450
+     //Preview uploaded file when clicked
451
+     $("#indfilediv").on("click", function() {
452
+
453
+          var smsfilename = e.target.files[0].name;
454
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
455
+
456
+          var reader = new FileReader();
457
+          reader.readAsText(e.target.files[0]);
458
+          reader.onload = function(e) {
459
+                  $("#smstables").empty();
460
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
461
+          };
462
+
463
+          $("#smstables").show();
464
+          $('#sms_upload_msg').hide();
465
+          $('#smstables').removeClass('icon-loading');
466
+     });
467
+
468
+     // Remove selected file
469
+     $("#indivflremove").on("click", function() {
470
+
471
+          $("#induploadfile").remove();
472
+          $("#sms_upload_msg").hide();
473
+
474
+          receiversNumbers.length = 0;
475
+
476
+     });
477
+
478
+  });
479
+
480
+  // Show the number of characters entered in the SMS textarea and the text size in KB
481
+  $("#smstext").on('input', function() {
482
+
483
+     $("#char_count").css("display", "inline");
484
+
485
+     $("#mtextSize").css("display", "inline");
486
+
487
+     $(".maxmessagelength").css("display", "inline-block");
488
+
489
+     $("#countchnb").text($(this).val().length);
490
+
491
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
492
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
493
+     $("#textsizeinkb").text(textsizekb);
494
+
495
+     if ($(this).val().length > charcolorthr) {
496
+         $("#char_count").css("color", "#BB2E4B");
497
+     } else {
498
+         $("#char_count").css("color", "#4cbc86;");
499
+     }
500
+
501
+  });
502
+
503
+
504
+  // Check the checkbox to send file(s) as MMS
505
+  $('#mediafilechckbx').change(function() {
506
+
507
+      if ($(this).is(':checked')) {
508
+
509
+          isMMS = 1;
510
+          if (selectedid == '') {
511
+              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
512
+              $(this).prop("checked", false);
513
+              isMMS = 0;
514
+              return;
515
+          }
516
+          $("#upmediafiles").css("display", "block");
517
+          $("#submitsms").prop("value", "Send MMS");
518
+
519
+      } else {
520
+
521
+          isMMS = 0;
522
+          $("#upmediafiles").css("display", "none");
523
+          $("#submitsms").prop("value", "Send SMS");
524
+
525
+          // Remove the uploaded file(s) if any
526
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
527
+          $(".indgenpckfls").each(function() { $(this).remove(); });
528
+
529
+          uploadedtomms = [];
530
+          n = 1;
531
+
532
+          msgtotalflsize = 0;
533
+
534
+          $("#filestotsize").hide();
535
+      }
536
+  });
537
+
538
+
539
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
540
+  function adjustMaximumSize(uploadedtomms) {
541
+				      
542
+      var nonimgcheck = 0;
543
+      for (var u = 0; u < uploadedtomms.length; u++) {
544
+	   var crupfl = uploadedtomms[u];
545
+	   var extensionup = crupfl.replace(/^.*\./, '');
546
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
547
+	       nonimgcheck = 1;
548
+	   }
549
+      }
550
+
551
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
552
+  }
553
+
554
+  // Upload files to be sent as MMS
555
+  $("#uploadfileformms").change(function(e) {
556
+
557
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
558
+     $('#smstables').addClass('icon-loading');
559
+     $('#filestotsize').show();
560
+
561
+     var userid = "<?php p($userId); ?>";
562
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
563
+
564
+     var formData = new FormData();
565
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
566
+
567
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
568
+
569
+     // Add the size of the current file to the total size of all the files
570
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
571
+
572
+     var fileup = $('#uploadfileformms').val();
573
+     var fileuptrim = fileup.split('\\').pop();
574
+
575
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
576
+         var duplicatescheck = 1;
577
+     } else { 
578
+         var duplicatescheck = 0;
579
+     }
580
+
581
+     var extension = fileup.replace(/^.*\./, '');
582
+
583
+     if (extension == fileup) {
584
+         extension = "";
585
+     } else {
586
+         extension = extension.toLowerCase();
587
+     }
588
+
589
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
590
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
591
+         maximumsize = maxsizenonimage;
592
+     }
593
+
594
+     if ($.inArray(extension, validExtensions) != -1) {
595
+
596
+       if (duplicatescheck == 0) {
597
+
598
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
599
+
600
+            if (n <= maximumfilenumber) {
601
+
602
+               $.ajax({
603
+                 url: baseUrl + '/' + userid,
604
+                 type: "POST",
605
+                 data: formData,
606
+                 cache: false,
607
+                 processData: false,
608
+                 contentType: false,
609
+                 success: function(totalflsize) {
610
+
611
+                   uploadedtomms.push(fileuptrim);
612
+
613
+                   $('#filessizetext').text(totalflsize);
614
+
615
+                   var rectotfilesz = parseFloat(totalflsize);
616
+
617
+                   if (rectotfilesz <= maximumsize) {
618
+                       $('#submitsms').attr("disabled", false);
619
+                       $('#filestotsize').css('color', '#189558');
620
+                   } else {
621
+                       $('#filestotsize').css('color', '#ba3555');
622
+                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
623
+                       $('#submitsms').attr("disabled", true);
624
+                       $('#smstables').removeClass('icon-loading');
625
+                       $('#pf_upload_msg').hide();
626
+                   }
627
+
628
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
629
+                   n++;
630
+
631
+                   // Preview the file when you click on its name
632
+                   $("div:visible[id*='indfilediv']").each(function() {
633
+
634
+                        $(this).on("click", function(eventclck) {
635
+
636
+                           $("#mmsfoldersview").css("display", "inline-block");
637
+                           var mmsfilenameinit = $(this).text();
638
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
639
+                           var mmsfilename = mmsfilenamesec.replace("X","");
640
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
641
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
642
+
643
+                           if (extenlst == mmsfilename) {
644
+                               extenlst = "";
645
+                           } else {
646
+                               extenlst = extenlst.toLowerCase();
647
+                           }
648
+
649
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
650
+                                  $("#smstables").empty();
651
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
652
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
653
+                           } else if (extenlst == 'png') {
654
+                                  $("#smstables").empty();
655
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
656
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
657
+                           } else if (extenlst == 'gif') {
658
+                                  $("#smstables").empty();
659
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
660
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
661
+                           } else if (extenlst == 'bmp') {
662
+                                  $("#smstables").empty();
663
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
664
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
665
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
666
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
667
+                                  var xhr = new XMLHttpRequest();
668
+                                  xhr.responseType = 'arraybuffer';
669
+                                  xhr.open('GET', tiffile);
670
+                                  xhr.onload = function (evnt) {
671
+                                      var tiff = new Tiff({buffer: xhr.response});
672
+                                      var tifcanvas = tiff.toCanvas();
673
+                                      $("#smstables").empty();
674
+                                      $("#smstables").append(tifcanvas);
675
+                                  };
676
+                                  xhr.send();
677
+                           } else if (extenlst == 'pdf') {
678
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
679
+                                  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>');
680
+                                  $("#smstables").empty();
681
+                                  $("#smstables").append($iframe);
682
+                           } else if (extenlst == 'txt') {
683
+                                  $("#smstables").empty();
684
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
685
+                           } else if (extension == 'mp4') {
686
+                                  $("#smstables").empty();
687
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
688
+		           } else if (extension == 'ogg') {
689
+		                  $("#smstables").empty();
690
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
691
+		           } else if (extension == 'avi') {
692
+		                  $("#smstables").empty();
693
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
694
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
695
+		                  $("#smstables").empty();
696
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
697
+		           } else if (extension == 'wav' || extension == 'wave') {
698
+		                  $("#smstables").empty();
699
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
700
+		           } else if (extension == 'mp3') {
701
+		                  $("#smstables").empty();
702
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
703
+		           } else if (extension == 'midi') {
704
+		                  $("#smstables").empty();
705
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
706
+		           }
707
+
708
+                           $("#smstables").show();
709
+                           $("#mmsfoldersview").hide();
710
+                        });
711
+                   });
712
+
713
+                   // Remove uploaded files
714
+                   $('[class*="indupfldl"]').last().click(function() {
715
+
716
+                           var userid = "<?php p($userId); ?>";
717
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
718
+
719
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
720
+
721
+                           var removedfilesplit = removedfilenameinit.split(") ");
722
+                           var removedflnb = parseInt(removedfilesplit[0]);
723
+
724
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
725
+                           $(this).hide();
726
+
727
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
728
+
729
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
730
+                                           return value != removedfilename;
731
+                           });
732
+
733
+                           $.ajax({
734
+                                   url: baseUrl + '/' + userid,
735
+                                   type: "POST",
736
+                                   data: {removedfilename: removedfilename},
737
+                                   success: function(totalflsize) {
738
+
739
+                                      msgtotalflsize = totalflsize;
740
+                                      $('#filessizetext').text(totalflsize);
741
+
742
+                                      adjustMaximumSize(uploadedtomms);
743
+
744
+                                      // Check message size
745
+                                      var rectotfilesz = parseFloat(totalflsize);
746
+
747
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
748
+                                          $('#submitsms').attr("disabled", false);
749
+                                          $('#filestotsize').css('color', '#189558');
750
+                                      } else {
751
+                                          $('#filestotsize').css('color', '#ba3555');
752
+                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
753
+                                          $('#submitsms').attr("disabled", true);
754
+                                      }
755
+
756
+                                      // Rewrite order numbers for files that follow
757
+                                      --n;
758
+                                      $("div:visible[id*='indfilediv']").each(function() {
759
+
760
+                                          var getdivtext =  $(this).text();
761
+                                          var splitdivtext = getdivtext.split(") ");
762
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
763
+                                          var newnbvalue = currentnbvalue - 1;
764
+
765
+                                          if (currentnbvalue > removedflnb) {
766
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
767
+                                              $(this).text(replacedstr);
768
+                                          }
769
+                                      });
770
+
771
+                                      $("div:visible[id*='indflpicked']").each(function() {
772
+
773
+                                          var getdivtext =  $(this).text();
774
+                                          var splitdivtext = getdivtext.split(") ");
775
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
776
+                                          var newnbvalue = currentnbvalue - 1;
777
+
778
+                                          if (currentnbvalue > removedflnb) {
779
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
780
+                                              $(this).text(replacedstr);
781
+                                          }
782
+                                      });
783
+
784
+                                   },
785
+                                   error: function() {
786
+                                          alert('Error removing file(s)!');
787
+                                   }
788
+                           });
789
+
790
+                           $('#smstables').removeClass('icon-loading');
791
+                           $("#smstables").empty();
792
+                   });
793
+
794
+                   // Preview the uploaded file
795
+                   $("#mmsfoldersview").css("display", "inline-block");
796
+                   var mmsfilename = e.target.files[0].name;
797
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
798
+
799
+
800
+                   if (extension == 'jpg' || extension == 'jpeg') {
801
+                              $("#smstables").empty();
802
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
803
+
804
+                              var reader = new FileReader();
805
+                              reader.onload = function (e) {
806
+                                  readjpg[mmsfilename] = e.target.result;
807
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
808
+                              }
809
+                              reader.readAsDataURL(e.target.files[0]);
810
+                   } else if (extension == 'png') {
811
+                              $("#smstables").empty();
812
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
813
+
814
+                              var reader = new FileReader();
815
+                              reader.onload = function (e) {
816
+                                  readpng[mmsfilename] = e.target.result;
817
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
818
+                              }
819
+                              reader.readAsDataURL(e.target.files[0]);
820
+
821
+                   } else if (extension == 'gif') {
822
+                              $("#smstables").empty();
823
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
824
+
825
+                              var reader = new FileReader();
826
+                              reader.onload = function (e) {
827
+                                  readgif[mmsfilename] = e.target.result;
828
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
829
+                              }
830
+                              reader.readAsDataURL(e.target.files[0]);
831
+
832
+                   } else if (extension == 'bmp') {
833
+                              $("#smstables").empty();
834
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
835
+
836
+                              var reader = new FileReader();
837
+                              reader.onload = function (e) {
838
+                                  readbmp[mmsfilename] = e.target.result;
839
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
840
+                              }
841
+                              reader.readAsDataURL(e.target.files[0]);
842
+
843
+                   } else if (extension == 'tif' || extension == 'tiff') {
844
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
845
+                              var xhr = new XMLHttpRequest();
846
+                              xhr.responseType = 'arraybuffer';
847
+                              xhr.open('GET', tiffile);
848
+                              xhr.onload = function (e) {
849
+                                  var tiff = new Tiff({buffer: xhr.response});
850
+                                  var tifcanvas = tiff.toCanvas();
851
+                                  $("#smstables").empty();
852
+                                  $("#smstables").append(tifcanvas);
853
+                              };
854
+                              xhr.send();
855
+
856
+                   } else if (extension == 'pdf') {
857
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
858
+                              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>');
859
+                              $("#smstables").empty();
860
+                              $("#smstables").append($iframe);
861
+
862
+                   } else if (extension == 'txt') {
863
+                              var reader = new FileReader();
864
+                              reader.readAsText(e.target.files[0]);
865
+                              reader.onload = function(e) {
866
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
867
+                                  $("#smstables").empty();
868
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
869
+                              };
870
+                   } else if (extension == 'mp4') {
871
+                              $("#smstables").empty();
872
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
873
+                   } else if (extension == 'ogg') {
874
+                              $("#smstables").empty();
875
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
876
+                   } else if (extension == 'avi') {
877
+                              $("#smstables").empty();
878
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
879
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
880
+                              $("#smstables").empty();
881
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
882
+                   } else if (extension == 'wav' || extension == 'wave') {
883
+                              $("#smstables").empty();
884
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
885
+                   } else if (extension == 'mp3') {
886
+                              $("#smstables").empty();
887
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
888
+                   } else if (extension == 'midi') {
889
+                              $("#smstables").empty();
890
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
891
+                   }
892
+
893
+                   $("#smstables").show();
894
+                   $('#pf_upload_msg').hide();
895
+                   $('#smstables').removeClass('icon-loading');
896
+                   $("#mmsfoldersview").hide();
897
+                 },
898
+                 error: function(data){
899
+                     alert('Error uploading file!');
900
+                 }
901
+               });
902
+
903
+            } else {
904
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
905
+                  adjustMaximumSize(uploadedtomms);
906
+
907
+                  alert("Error ! You cannot send more than 10 files in one MMS !");
908
+                  $('#pf_upload_msg').hide();
909
+                  $('#smstables').removeClass('icon-loading');
910
+            }
911
+         } else {
912
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
913
+              adjustMaximumSize(uploadedtomms);
914
+
915
+              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
916
+              $('#pf_upload_msg').hide();
917
+              $('#smstables').removeClass('icon-loading');
918
+         }
919
+       } else {
920
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
921
+            adjustMaximumSize(uploadedtomms);
922
+
923
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
924
+            $('#pf_upload_msg').hide();
925
+            $('#smstables').removeClass('icon-loading');
926
+       }
927
+
928
+     } else {
929
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
930
+          adjustMaximumSize(uploadedtomms);
931
+
932
+          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
933
+          $('#pf_upload_msg').hide();
934
+          $('#smstables').removeClass('icon-loading');
935
+     }
936
+  });
937
+
938
+
939
+  // Pick file(s) from Nextcloud, to send as MMS
940
+  var mmsfilename = null;
941
+
942
+  $("#choosefilen").on("click", function(evn) {
943
+
944
+                OC.dialogs.filepicker(
945
+                        t('settings', "Select a file to send as MMS."),
946
+                        function (path) {
947
+
948
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
949
+                              $('#smstables').addClass('icon-loading');
950
+                              $('#filestotsize').show();
951
+
952
+                              var userid = "<?php p($userId); ?>";
953
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
954
+
955
+                              mmsfilename = path.split('/').pop();
956
+
957
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
958
+                                  var duplicatescheck = 1;
959
+                              } else var duplicatescheck = 0;
960
+
961
+                              var extension = mmsfilename.replace(/^.*\./, '');
962
+
963
+                              if (extension == mmsfilename) {
964
+                                  extension = "";
965
+                              } else {
966
+                                  extension = extension.toLowerCase();
967
+                              }
968
+
969
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
970
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
971
+				   maximumsize = maxsizenonimage;
972
+			      }
973
+
974
+                              if ($.inArray(extension, validExtensions) != -1) {
975
+
976
+                                 if (duplicatescheck == 0) {
977
+
978
+                                    if (n <= maximumfilenumber) {
979
+
980
+                                       $.ajax({
981
+                                          url: baseUrl + '/' + userid,
982
+                                          type: "POST",
983
+                                          data: {path: path},
984
+                                          success: function(pickresult) {
985
+
986
+                                                uploadedtomms.push(mmsfilename);
987
+
988
+                                                var totalflsize = pickresult[0];
989
+                                                var pickedflsize = pickresult[1];
990
+
991
+                                                // Check message size
992
+                                                var rectotfilesz = parseFloat(totalflsize);
993
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
994
+
995
+                                                if (filesplustextsize <= maximumsize) {
996
+
997
+                                                    $("#mmsfoldersview").css("display", "inline-block");
998
+
999
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1000
+                                                    n++;
1001
+
1002
+                                                    msgtotalflsize = totalflsize;
1003
+                                                    $('#filessizetext').text(totalflsize);
1004
+                                                    $('#filestotsize').css('color', '#189558');
1005
+
1006
+                                                } else {
1007
+
1008
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1009
+                                                    $('#filestotsize').css('color', '#ba3555');
1010
+                                                    msgtotalflsize -= pickedflsize;
1011
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1012
+
1013
+                                                    $.ajax({
1014
+                                                        url: baseUrlindrm + '/' + userid,
1015
+                                                        type: "POST",
1016
+                                                        data: {removedfilename: mmsfilename},
1017
+                                                        success: function(totalflsize) {
1018
+
1019
+                                                                          $('#filessizetext').text(totalflsize);
1020
+                                                                          $('#filestotsize').css('color', '#189558');
1021
+                                                                          adjustMaximumSize(uploadedtomms);
1022
+
1023
+                                                        },
1024
+                                                        error: function(totalflsize) {
1025
+                                                                          $('#filessizetext').text(totalflsize);
1026
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1027
+                                                                              $('#filestotsize').css('color', '#ba3555');
1028
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1029
+                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1030
+                                                        }
1031
+                                                    });
1032
+
1033
+                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1034
+
1035
+                                                }
1036
+
1037
+
1038
+                                                // Preview each file when you click on its name
1039
+                                                $("div:visible[id*='indflpicked']").each(function() {
1040
+                                                   $(this).on("click", function(event) {
1041
+
1042
+                                                      var mmsfilenameinit = $(this).text();
1043
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
+
1048
+                                                      if (extenlst == mmsfilenamesp) {
1049
+                                                           extenlst = "";
1050
+                                                      } else {
1051
+                                                           extenlst = extenlst.toLowerCase();
1052
+                                                      }
1053
+
1054
+
1055
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
+                                                              $("#smstables").empty();
1057
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
+                                                      } else if (extenlst == 'png') {
1059
+                                                              $("#smstables").empty();
1060
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ baseUrl +'" />');
1061
+                                                      } else if (extenlst == 'gif') {
1062
+                                                              $("#smstables").empty();
1063
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ baseUrl +'" />');
1064
+                                                      } else if (extenlst == 'bmp') {
1065
+                                                              $("#smstables").empty();
1066
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ baseUrl +'" />');
1067
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1068
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1069
+                                                              var xhr = new XMLHttpRequest();
1070
+                                                              xhr.responseType = 'arraybuffer';
1071
+                                                              xhr.open('GET', tiffile);
1072
+                                                              xhr.onload = function (evnt) {
1073
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1074
+                                                                  var tifcanvas = tiff.toCanvas();
1075
+                                                                  $("#smstables").empty();
1076
+                                                                  $("#smstables").append(tifcanvas);
1077
+                                                              };
1078
+                                                              xhr.send();
1079
+                                                      } else if (extenlst == 'pdf') {
1080
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1081
+                                                              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>');
1082
+                                                              $("#smstables").empty();
1083
+                                                              $("#smstables").append($iframe);
1084
+                                                      } else if (extenlst == 'txt') {
1085
+                                                              $("#smstables").empty();
1086
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1087
+                                                      } else if (extension == 'mp4') {
1088
+							      $("#smstables").empty();
1089
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1090
+						      } else if (extension == 'ogg') {
1091
+							      $("#smstables").empty();
1092
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1093
+						      } else if (extension == 'avi') {
1094
+							      $("#smstables").empty();
1095
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1096
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1097
+							      $("#smstables").empty();
1098
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1099
+						      } else if (extension == 'wav' || extension == 'wave') {
1100
+							      $("#smstables").empty();
1101
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1102
+						      } else if (extension == 'mp3') {
1103
+							      $("#smstables").empty();
1104
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1105
+						      } else if (extension == 'midi') {
1106
+							      $("#smstables").empty();
1107
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1108
+						      }
1109
+
1110
+
1111
+                                                      $("#smstables").show();
1112
+                                                      $("#mmsfoldersview").hide();
1113
+                                                   });
1114
+                                                });
1115
+
1116
+
1117
+                                                // Remove picked files
1118
+                                                $('[class*="indpckfldl"]').last().click(function() {
1119
+                                                    var userid = "<?php p($userId); ?>";
1120
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1121
+
1122
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1123
+
1124
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1125
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1126
+
1127
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1128
+                                                    $(this).hide();
1129
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1130
+
1131
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1132
+                                                             return value != removedfilename;
1133
+                                                    });
1134
+
1135
+                                                    $.ajax({
1136
+                                                        url: baseUrl + '/' + userid,
1137
+                                                        type: "POST",
1138
+                                                        data: {removedfilename: removedfilename},
1139
+                                                        success: function(totalflsize) {
1140
+
1141
+                                                             msgtotalflsize = totalflsize;
1142
+                                                             $('#filessizetext').text(totalflsize);
1143
+                                                             adjustMaximumSize(uploadedtomms);
1144
+
1145
+                                                             // Check message size
1146
+                                                             var rectotfilesz = parseFloat(totalflsize);
1147
+
1148
+                                                             if (rectotfilesz > maximumsize) {
1149
+                                                                 $('#filestotsize').css('color', '#ba3555');
1150
+                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1151
+                                                                 $('#submitsms').attr("disabled", true);
1152
+                                                             } else {
1153
+                                                                 $('#submitsms').attr("disabled", false);
1154
+                                                                 $('#filestotsize').css('color', '#189558');
1155
+                                                               }
1156
+
1157
+                                                             // Rewrite order numbers for files that follow
1158
+                                                             --n;
1159
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1160
+
1161
+                                                                  var getdivtext =  $(this).text();
1162
+                                                                  var splitdivtext = getdivtext.split(") ");
1163
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1164
+                                                                  var newnbvalue = currentnbvalue - 1;
1165
+
1166
+                                                                  if (currentnbvalue > removedflnb) {
1167
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1168
+                                                                      $(this).text(replacedstr);
1169
+                                                                  }
1170
+                                                             });
1171
+                                                        },
1172
+                                                        error: function() {
1173
+                                                             alert('Error !');
1174
+                                                        }
1175
+                                                    });
1176
+
1177
+                                                    $('#smstables').removeClass('icon-loading');
1178
+                                                    $("#smstables").empty();
1179
+                                                });
1180
+
1181
+
1182
+		                                // Preview the picked file
1183
+		                                $("#mmsfoldersview").css("display", "inline-block");
1184
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1185
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1186
+
1187
+
1188
+						if (extension == 'jpg' || extension == 'jpeg') {
1189
+
1190
+		                                            $("#smstables").empty();
1191
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1192
+
1193
+		                                } else if (extension == 'png') {
1194
+
1195
+		                                            $("#smstables").empty();
1196
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1197
+
1198
+		                                } else if (extension == 'gif') {
1199
+
1200
+		                                            $("#smstables").empty();
1201
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1202
+
1203
+		                                } else if (extension == 'bmp') {
1204
+
1205
+	                                                    $("#smstables").empty();
1206
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1207
+
1208
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1209
+
1210
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1211
+		                                       var xhr = new XMLHttpRequest();
1212
+		                                       xhr.responseType = 'arraybuffer';
1213
+		                                       xhr.open('GET', tiffile);
1214
+		                                       xhr.onload = function (event) {
1215
+		                                           var tiff = new Tiff({buffer: xhr.response});
1216
+		                                           var tifcanvas = tiff.toCanvas();
1217
+		                                           $("#smstables").empty();
1218
+		                                           $("#smstables").append(tifcanvas);
1219
+		                                       };
1220
+		                                       xhr.send();
1221
+
1222
+		                                } else if (extension == 'pdf') {
1223
+
1224
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1225
+		                                       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>');
1226
+		                                       $("#smstables").empty();
1227
+		                                       $("#smstables").append($iframe);
1228
+
1229
+		                                } else if (extension == 'txt') {
1230
+
1231
+							     $.get(flUrl, function(textdata) {
1232
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1233
+		                                               $("#smstables").empty();
1234
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1235
+							     });
1236
+
1237
+		                                } else if (extension == 'mp4') {
1238
+						       $("#smstables").empty();
1239
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1240
+						} else if (extension == 'ogg') {
1241
+						       $("#smstables").empty();
1242
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1243
+						} else if (extension == 'avi') {
1244
+						       $("#smstables").empty();
1245
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1246
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1247
+						       $("#smstables").empty();
1248
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1249
+						} else if (extension == 'wav' || extension == 'wave') {
1250
+						       $("#smstables").empty();
1251
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1252
+						} else if (extension == 'mp3') {
1253
+						       $("#smstables").empty();
1254
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1255
+						} else if (extension == 'midi') {
1256
+						       $("#smstables").empty();
1257
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1258
+						}
1259
+
1260
+
1261
+		                                $("#smstables").show();
1262
+
1263
+		                                $('#pf_choose_msg').hide();
1264
+		                                $('#smstables').removeClass('icon-loading');
1265
+		                                $("#mmsfoldersview").hide();
1266
+
1267
+                                          },
1268
+
1269
+                                          error: function(data){
1270
+                                             alert('Error!');
1271
+                                          }
1272
+
1273
+                                       });
1274
+
1275
+                                    } else {
1276
+                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1277
+                                        $('#pf_choose_msg').hide();
1278
+                                        $('#smstables').removeClass('icon-loading');
1279
+                                      }
1280
+                                 } else {
1281
+                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1282
+                                      $('#pf_choose_msg').hide();
1283
+                                      $('#smstables').removeClass('icon-loading');
1284
+                                   }
1285
+
1286
+                              } else {
1287
+                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1288
+                                   $('#pf_choose_msg').hide();
1289
+                                   $('#smstables').removeClass('icon-loading');
1290
+                                }
1291
+
1292
+                        }
1293
+                );
1294
+  });
1295
+
1296
+
1297
+
1298
+  // Send the SMS/MMS message
1299
+  $("#submitsms").on("click", function(event) {
1300
+
1301
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1302
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1303
+     $("#sms_submit_msg").css("display", "inline-block");
1304
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1305
+
1306
+     if (selectedid != '') { 
1307
+
1308
+         var sendersplit = selectedid.split(":");
1309
+         var providercap = sendersplit[0];
1310
+         var provsec = sendersplit[1];
1311
+
1312
+         if (/[a-zA-Z]/.test(provsec)) {
1313
+             var alphanumcheck = true;
1314
+         } else { var alphanumcheck = false; }
1315
+
1316
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1317
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1318
+             var selectedsender = "+" + senderproc;
1319
+             var providerUsed = "telnyx";
1320
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1321
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1322
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1323
+             var providerUsed = "plivo";
1324
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1325
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1326
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1327
+             var selectedsender = "+" + senderproc;
1328
+             var providerUsed = "twilio";
1329
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1330
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1331
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1332
+             var selectedsender = "+" + senderproc;
1333
+             var providerUsed = "flowroute";
1334
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1335
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1336
+             var selectedsender = provsec;
1337
+             var providerUsed = "telnyx";
1338
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1339
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1340
+             var selectedsender = provsec;
1341
+             var providerUsed = "plivo";
1342
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1343
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1344
+             var selectedsender = provsec;
1345
+             var providerUsed = "twilio";
1346
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1347
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1348
+             var selectedsender = provsec;
1349
+             var providerUsed = "flowroute";
1350
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1351
+         }
1352
+
1353
+         // Get the interval between message consecutive sending requests, if it's the case
1354
+         if ($('#tomultchckbx').is(':checked')) {
1355
+
1356
+             var numbersfile = 1;
1357
+             var initinterval = $("#multsmsinterval").val();
1358
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1359
+
1360
+             if (secinterval != '') {
1361
+                 var tertinterval = parseInt(secinterval);
1362
+                     waittime = tertinterval;
1363
+             }
1364
+
1365
+         } else {
1366
+
1367
+             var numbersfile = 0;
1368
+             var toNumberinit = $('#smsto').val();
1369
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1370
+             var toNumbersec = toNumber.split(",");
1371
+
1372
+                 for (var i = 0; i < toNumbersec.length; i++) {
1373
+                      toNumbersec[i] = "+" + toNumbersec[i];
1374
+                 }
1375
+
1376
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1377
+         }
1378
+
1379
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1380
+
1381
+         var smstext = $("#smstext").val();
1382
+
1383
+         if (receiversNumbers.length != 0) {
1384
+
1385
+              if (smstext != '') {
1386
+                  $.ajax({
1387
+                     url: relbaseUrl + '/' + userid,
1388
+                     type: "POST",
1389
+                     data: {
1390
+                           receiversPhoneNbs: receiversNumbers,
1391
+                           fromsender: selectedsender,
1392
+                           waitinterval: waittime,
1393
+                           sentsmstext: smstext,
1394
+                           ismms: isMMS,
1395
+                           mmsfiles: uploadedtomms
1396
+                         },
1397
+                     success: function() {
1398
+
1399
+                           if (receiversNumbers.length == 1) {
1400
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1401
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1402
+
1403
+                           $('#sms_submit_msg').hide();
1404
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1405
+                     },
1406
+                     error: function() {
1407
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1408
+                           $('#sms_submit_msg').hide();
1409
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1410
+                     }
1411
+                  });
1412
+              } else {
1413
+                     alert("Please enter a message in the text box !");
1414
+                     $('#sms_submit_msg').hide();
1415
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1416
+              }
1417
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1418
+                 alert("Please enter the recipient's phone number !");
1419
+                 $('#sms_submit_msg').hide();
1420
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1421
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1422
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1423
+                 $('#sms_submit_msg').hide();
1424
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1425
+         }
1426
+     } else {
1427
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
1428
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1429
+           $('#sms_submit_msg').hide();
1430
+     }
1431
+
1432
+  });
1433
+
1434
+  // Check the checkbox to delete old messages from the database
1435
+  $('#deleteoldchckbox').change(function() {
1436
+     if ($(this).is(':checked')) {
1437
+         $("#deleteoldsms").css("display", "block");
1438
+     } else {
1439
+         $("#deleteoldsms").css("display", "none");
1440
+     }
1441
+  });
1442
+
1443
+  // Set the height of 3 info notes
1444
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1445
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1446
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1447
+
1448
+  $(window).resize(function() { 
1449
+    $('#setcalleridtp').css('height', $(window).height() - 160);
1450
+    $('#tonmbrformat').css('height', $(window).height() - 260);
1451
+    $('#uploadfileinfo').css('height', $(window).height() - 390);
1452
+  });
1453
+
Browse code

removed README.md CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/sendsms.js

DoubleBastionAdmin authored on 05/09/2022 18:43:29
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1455 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-  var selectedid = '';
30
-  var isMMS = 0;
31
-  var n = 1;
32
-  var textsizekb = 0;
33
-  var uploadedtomms = [];
34
-  var msgtotalflsize = 0;
35
-  var readtxtfile = [];
36
-  var readhtmlfile = [];
37
-  var readjpg = [];
38
-  var readpng = [];
39
-  var readgif = [];
40
-  var readbmp = [];
41
-  var readtif = [];
42
-  var readmp4 = [];
43
-  var chosenProvider = '';
44
-  var chosenProvFullName = '';
45
-  var infonotecontent = '';
46
-  var validExtensions = [];
47
-  var maximumsize = 750;
48
-  var maxsizenonimage = 600;
49
-  var maximumfilenumber = 10;
50
-  var maximumsizeinit = 750;
51
-
52
-  // 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
53
-  var locHref = window.location.href;
54
-  var pathSplit = locHref.split('/');
55
-  var firstPathEl = '';
56
-  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
57
-
58
-  // Clean the SMS_Relentless/temp_files directory
59
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
60
-
61
-  $.ajax({
62
-          url: cleanflUrl + '/' + userid,
63
-          type: "POST",
64
-          data: { userid: userid },
65
-          cache: false,
66
-          processData: false,
67
-          contentType: false
68
-  });
69
-  
70
-  // Check the available balance
71
-  $("#smsprovider").on("change", function () {
72
-
73
-     var provider = $('#smsprovider :selected').val();
74
-
75
-     if (provider == "Telnyx") {
76
-
77
-        var gettelbalance = function() {
78
-
79
-          $('#currentbalance').addClass('icon-loading');
80
-
81
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
82
-
83
-          $.ajax({
84
-              url: gettelbalanceUrl + '/' + userid,
85
-              type: "POST",
86
-              data: { userid: userid },
87
-              cache: false,
88
-              processData: false,
89
-              contentType: false,
90
-              success: function(currentbalancetel) {
91
-
92
-                     $('#currentbalance').empty();
93
-                     $('#currentbalance').text(currentbalancetel);
94
-                     $('#currentbalance').removeClass('icon-loading');
95
-              }
96
-          });
97
-        }
98
-
99
-        gettelbalance();
100
-
101
-     } else if (provider == "Plivo") {
102
-
103
-          var getnexbalance = function() {
104
-
105
-            $('#currentbalance').addClass('icon-loading');
106
-
107
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
108
-
109
-            $.ajax({
110
-                url: getnexbalanceUrl + '/' + userid,
111
-                type: "POST",
112
-                data: { userid: userid },
113
-                cache: false,
114
-                processData: false,
115
-                contentType: false,
116
-                success: function(currentbalancenex) {
117
-
118
-                     $('#currentbalance').empty();
119
-                     $('#currentbalance').text(currentbalancenex);
120
-                     $('#currentbalance').removeClass('icon-loading');
121
-                }
122
-            });
123
-          }
124
-
125
-          getnexbalance();
126
-
127
-     } else if (provider == "Twilio") {
128
-
129
-          var gettwilbalance = function() {
130
-
131
-            $('#currentbalance').addClass('icon-loading');
132
-
133
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
134
-
135
-            $.ajax({
136
-                url: gettwilbalanceUrl + '/' + userid,
137
-                type: "POST",
138
-                data: { userid: userid },
139
-                cache: false,
140
-                processData: false,
141
-                contentType: false,
142
-                success: function(currentbalancetwil) {
143
-
144
-                     $('#currentbalance').empty();
145
-                     $('#currentbalance').text(currentbalancetwil);
146
-                     $('#currentbalance').removeClass('icon-loading');
147
-                }
148
-            });
149
-          }
150
-
151
-          gettwilbalance();
152
-
153
-     } else if (provider == "Flowroute") {
154
-
155
-          var getflowbalance = function() {
156
-
157
-            $('#currentbalance').addClass('icon-loading');
158
-
159
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
160
-
161
-            $.ajax({
162
-                url: getflowbalanceUrl + '/' + userid,
163
-                type: "POST",
164
-                data: { userid: userid },
165
-                cache: false,
166
-                processData: false,
167
-                contentType: false,
168
-                success: function(currentbalanceflow) {
169
-
170
-                     $('#currentbalance').empty();
171
-                     $('#currentbalance').text(currentbalanceflow);
172
-                     $('#currentbalance').removeClass('icon-loading');
173
-                }
174
-            });
175
-          }
176
-
177
-          getflowbalance();
178
-
179
-       } else if (provider == "") {
180
-                $('#currentbalance').text("");
181
-                $('#currentbalance').removeClass('icon-loading');
182
-       }
183
-  });
184
-
185
-  // Select the Sender ID
186
-  $("#selectcalleridbttn").on("click", function(event) {
187
-
188
-     $('#selectcalleridbttn').addClass('icon-loading');
189
-
190
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
191
-
192
-     $.ajax({
193
-          url: getsmsnumbersUrl + '/' + userid,
194
-          type: "POST",
195
-          data: { userid: userid },
196
-          cache: false,
197
-          processData: false,
198
-          contentType: false,
199
-          success: function(currentnmbrs) {
200
-
201
-                     $('#currentsmsnmbrs').empty();
202
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
203
-
204
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
205
-                         var emptyinit = indsmsnmb.split(":");
206
-                         var emptysec = emptyinit[1];
207
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
208
-
209
-                         if (emptycheck != '') {
210
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
211
-                         }
212
-                     });
213
-
214
-                     $('#selectcalleridbttn').removeClass('icon-loading');
215
-          }
216
-     });
217
-  });
218
-
219
-  // If a Sender ID is selected, get it
220
-  $("#currentsmsnmbrs").on("change", function () {
221
-
222
-          if ($("#currentsmsnmbrs option[value='']").length > 0) {
223
-
224
-              selectedid = $('#currentsmsnmbrs :selected').val();
225
-              var setIdsplit = selectedid.split(":");
226
-	      chosenProvider = setIdsplit[0];
227
-
228
-              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
229
-	      if (chosenProvider == "Tx") {
230
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
231
-		  // Maximum size of message text + media files in KB
232
-		  maximumsize = 1024;
233
-                  maximumsizeinit = 1024;
234
-		  maxsizenonimage = 600;
235
-		  maximumfilenumber = 10;
236
-                  chosenProvFullName = "Telnyx";
237
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
238
-                                     or gif files, the size of all the files plus the size of the text should be \
239
-                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
240
-                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
241
-                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
242
-                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
243
-                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
244
-                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
245
-                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
246
-                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
247
-                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
248
-                  $("#tooltiptextfourth").html(infonotecontent);
249
-	      } else if (chosenProvider == "Pl") {
250
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
251
-                                     "icalendar", "csv", "txt", "pdf", "xls"];
252
-		  // Maximum size of message text + media files in KB
253
-		  maximumsize = 5120;
254
-                  maximumsizeinit = 5120;
255
-		  maxsizenonimage = 600;
256
-		  maximumfilenumber = 10;
257
-                  chosenProvFullName = "Plivo";
258
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
259
-                                     or gif files, the size of all the files plus the size of the text should be \
260
-                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
261
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
262
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
263
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
264
-                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
265
-                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
266
-                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
267
-                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
268
-                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
269
-                  $("#tooltiptextfourth").html(infonotecontent);
270
-	      } else if (chosenProvider == "Tw") {
271
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
272
-                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
273
-                                     "icalendar", "directory", "pdf", "pkpass"];
274
-		  // Maximum size of message text + media files in KB
275
-		  maximumsize = 5120;
276
-                  maximumsizeinit = 5120;
277
-		  maxsizenonimage = 600;
278
-		  maximumfilenumber = 10;
279
-                  chosenProvFullName = "Twilio";
280
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
281
-                                     or gif files, the size of all the files plus the size of the text should be \
282
-                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
283
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
284
-                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
285
-                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
286
-                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
287
-                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
288
-                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
289
-                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
290
-                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
291
-                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
292
-                                     previewed in the adjoining pane."
293
-                  $("#tooltiptextfourth").html(infonotecontent);
294
-	      } else if (chosenProvider == "Fl") {
295
-		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
296
-		  // Maximum size of message text + media files in KB
297
-		  maximumsize = 750;
298
-                  maximumsizeinit = 750;
299
-		  maxsizenonimage = 600;
300
-		  maximumfilenumber = 10;
301
-                  chosenProvFullName = "Flowroute";
302
-                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
303
-                                     png or gif files, the size of all the files plus the size of the text should be \
304
-                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
305
-                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
306
-                                     size of the files plus the size of the text should be 600 KB or less. \
307
-                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
308
-                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
309
-                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
310
-                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
311
-                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
312
-                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
313
-                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
314
-                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
315
-                  $("#tooltiptextfourth").html(infonotecontent);
316
-	      }
317
-
318
-          } else { selectedid = ''; }
319
-  });
320
-
321
-  // Check the checkbox to send SMS message to multiple recipients
322
-  $('#tomultchckbx').change(function() {
323
-      if ($(this).is(':checked')) {
324
-          $("#multiplerecivers").css("display", "block");
325
-          $("#smstodiv").css("visibility", "hidden");
326
-          $("#smsto").val("");
327
-
328
-          receiversNumbers.length = 0;
329
-
330
-      } else {
331
-          $("#multiplerecivers").css("display", "none");
332
-          $("#smstodiv").css("visibility", "visible");
333
-
334
-          // Remove the uploaded file(s) if any
335
-          $("#induploadfile").remove();
336
-
337
-          receiversNumbers.length = 0;
338
-      }
339
-  });
340
-
341
-  // Upload the file with the recipients' phone numbers
342
-  $("#uploadfileforsms").change(function(e) {
343
-
344
-     $("#fileuploadednm").empty();
345
-
346
-     receiversNumbers.length = 0;
347
-
348
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
349
-
350
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
351
-
352
-     var formData = new FormData();
353
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
354
-
355
-     var fileup = $('#uploadfileforsms').val();
356
-     var fileuptrim = fileup.split('\\').pop();
357
-
358
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
359
-
360
-     var extension = fileup.replace(/^.*\./, '');
361
-
362
-     if (extension == fileup) {
363
-         extension = "";
364
-     } else {
365
-         extension = extension.toLowerCase();
366
-     }
367
-
368
-     var validExtensionsmrec = ["txt", "csv"];
369
-
370
-     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
371
-
372
-       if (selectedid != '') {
373
-
374
-               $.ajax({
375
-                 url: baseUrl + '/' + userid,
376
-                 type: "POST",
377
-                 data: formData,
378
-                 cache: false,
379
-                 processData: false,
380
-                 contentType: false,
381
-                 success: function(numberarray) {
382
-
383
-		    if (numberarray.length > 0) {
384
-
385
-		        // Get the array of the receivers' phone numbers
386
-		        if (chosenProvider == "Tx") {
387
-
388
-		             for(key in numberarray) {
389
-		                 receiversNumbers.push("+"+numberarray[key]);
390
-		             }
391
-
392
-		        } else if (chosenProvider == "Pl") {
393
-
394
-		             for(key in numberarray) {
395
-		                 receiversNumbers.push(numberarray[key]);
396
-		             }
397
-
398
-		          } else if (chosenProvider == "Tw") {
399
-
400
-		             for(key in numberarray) {
401
-		                 receiversNumbers.push(numberarray[key]);
402
-		             }
403
-		          } else if (chosenProvider == "Fl") {
404
-
405
-		             for(key in numberarray) {
406
-		                 receiversNumbers.push(numberarray[key]);
407
-		             }
408
-		          }
409
-
410
-		    } else {
411
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
412
-		    }
413
-                            
414
-                    // Preview the uploaded file
415
-                    var smsfilename = e.target.files[0].name;
416
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
417
-
418
-                    var reader = new FileReader();
419
-                    reader.readAsText(e.target.files[0]);
420
-                    reader.onload = function(e) {
421
-                          $("#smstables").empty();
422
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
423
-                    };
424
-
425
-                    $("#smstables").show();
426
-
427
-                    $('#sms_upload_msg').hide();
428
-                    $('#smstables').removeClass('icon-loading');
429
-
430
-                  },
431
-                  error: function(){
432
-                     alert('Error!');
433
-                  }
434
-               });
435
-
436
-        } else {
437
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
438
-               $('#sms_upload_msg').hide();
439
-               $('#smstables').removeClass('icon-loading');
440
-        }
441
-
442
-     } else {
443
-          alert('The file type is not supported ! Supported formats are txt and csv.');
444
-          $('#pf_upload_msg').hide();
445
-          $('#smstables').removeClass('icon-loading');
446
-
447
-          $("#induploadfile").remove();
448
-          $("#sms_upload_msg").hide();
449
-     }
450
-
451
-     //Preview uploaded file when clicked
452
-     $("#indfilediv").on("click", function() {
453
-
454
-          var smsfilename = e.target.files[0].name;
455
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
456
-
457
-          var reader = new FileReader();
458
-          reader.readAsText(e.target.files[0]);
459
-          reader.onload = function(e) {
460
-                  $("#smstables").empty();
461
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
462
-          };
463
-
464
-          $("#smstables").show();
465
-          $('#sms_upload_msg').hide();
466
-          $('#smstables').removeClass('icon-loading');
467
-     });
468
-
469
-     // Remove selected file
470
-     $("#indivflremove").on("click", function() {
471
-
472
-          $("#induploadfile").remove();
473
-          $("#sms_upload_msg").hide();
474
-
475
-          receiversNumbers.length = 0;
476
-
477
-     });
478
-
479
-  });
480
-
481
-  // Show the number of characters entered in the SMS textarea and the text size in KB
482
-  $("#smstext").on('input', function() {
483
-
484
-     $("#char_count").css("display", "inline");
485
-
486
-     $("#mtextSize").css("display", "inline");
487
-
488
-     $(".maxmessagelength").css("display", "inline-block");
489
-
490
-     $("#countchnb").text($(this).val().length);
491
-
492
-     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
493
-     textsizekb = parseFloat(textsize/1024).toFixed(4);
494
-     $("#textsizeinkb").text(textsizekb);
495
-
496
-     if ($(this).val().length > charcolorthr) {
497
-         $("#char_count").css("color", "#BB2E4B");
498
-     } else {
499
-         $("#char_count").css("color", "#4cbc86;");
500
-     }
501
-
502
-  });
503
-
504
-
505
-  // Check the checkbox to send file(s) as MMS
506
-  $('#mediafilechckbx').change(function() {
507
-
508
-      if ($(this).is(':checked')) {
509
-
510
-          isMMS = 1;
511
-          if (selectedid == '') {
512
-              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
513
-              $(this).prop("checked", false);
514
-              isMMS = 0;
515
-              return;
516
-          }
517
-          $("#upmediafiles").css("display", "block");
518
-          $("#submitsms").prop("value", "Send MMS");
519
-
520
-      } else {
521
-
522
-          isMMS = 0;
523
-          $("#upmediafiles").css("display", "none");
524
-          $("#submitsms").prop("value", "Send SMS");
525
-
526
-          // Remove the uploaded file(s) if any
527
-          $(".indgenflclsmms").each(function() { $(this).remove(); });
528
-          $(".indgenpckfls").each(function() { $(this).remove(); });
529
-
530
-          uploadedtomms = [];
531
-          n = 1;
532
-
533
-          msgtotalflsize = 0;
534
-
535
-          $("#filestotsize").hide();
536
-      }
537
-  });
538
-
539
-
540
-  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
541
-  function adjustMaximumSize(uploadedtomms) {
542
-				      
543
-      var nonimgcheck = 0;
544
-      for (var u = 0; u < uploadedtomms.length; u++) {
545
-	   var crupfl = uploadedtomms[u];
546
-	   var extensionup = crupfl.replace(/^.*\./, '');
547
-	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
548
-	       nonimgcheck = 1;
549
-	   }
550
-      }
551
-
552
-      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
553
-  }
554
-
555
-  // Upload files to be sent as MMS
556
-  $("#uploadfileformms").change(function(e) {
557
-
558
-     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
559
-     $('#smstables').addClass('icon-loading');
560
-     $('#filestotsize').show();
561
-
562
-     var userid = "<?php p($userId); ?>";
563
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
564
-
565
-     var formData = new FormData();
566
-     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
567
-
568
-     var currentflsize = $('#uploadfileformms')[0].files[0].size;
569
-
570
-     // Add the size of the current file to the total size of all the files
571
-     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
572
-
573
-     var fileup = $('#uploadfileformms').val();
574
-     var fileuptrim = fileup.split('\\').pop();
575
-
576
-     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
577
-         var duplicatescheck = 1;
578
-     } else { 
579
-         var duplicatescheck = 0;
580
-     }
581
-
582
-     var extension = fileup.replace(/^.*\./, '');
583
-
584
-     if (extension == fileup) {
585
-         extension = "";
586
-     } else {
587
-         extension = extension.toLowerCase();
588
-     }
589
-
590
-     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
591
-     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
592
-         maximumsize = maxsizenonimage;
593
-     }
594
-
595
-     if ($.inArray(extension, validExtensions) != -1) {
596
-
597
-       if (duplicatescheck == 0) {
598
-
599
-         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
600
-
601
-            if (n <= maximumfilenumber) {
602
-
603
-               $.ajax({
604
-                 url: baseUrl + '/' + userid,
605
-                 type: "POST",
606
-                 data: formData,
607
-                 cache: false,
608
-                 processData: false,
609
-                 contentType: false,
610
-                 success: function(totalflsize) {
611
-
612
-                   uploadedtomms.push(fileuptrim);
613
-
614
-                   $('#filessizetext').text(totalflsize);
615
-
616
-                   var rectotfilesz = parseFloat(totalflsize);
617
-
618
-                   if (rectotfilesz <= maximumsize) {
619
-                       $('#submitsms').attr("disabled", false);
620
-                       $('#filestotsize').css('color', '#189558');
621
-                   } else {
622
-                       $('#filestotsize').css('color', '#ba3555');
623
-                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
624
-                       $('#submitsms').attr("disabled", true);
625
-                       $('#smstables').removeClass('icon-loading');
626
-                       $('#pf_upload_msg').hide();
627
-                   }
628
-
629
-                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
630
-                   n++;
631
-
632
-                   // Preview the file when you click on its name
633
-                   $("div:visible[id*='indfilediv']").each(function() {
634
-
635
-                        $(this).on("click", function(eventclck) {
636
-
637
-                           $("#mmsfoldersview").css("display", "inline-block");
638
-                           var mmsfilenameinit = $(this).text();
639
-                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
640
-                           var mmsfilename = mmsfilenamesec.replace("X","");
641
-                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
642
-                           var extenlst = mmsfilename.replace(/^.*\./, '');
643
-
644
-                           if (extenlst == mmsfilename) {
645
-                               extenlst = "";
646
-                           } else {
647
-                               extenlst = extenlst.toLowerCase();
648
-                           }
649
-
650
-                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
651
-                                  $("#smstables").empty();
652
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
653
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
654
-                           } else if (extenlst == 'png') {
655
-                                  $("#smstables").empty();
656
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
657
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
658
-                           } else if (extenlst == 'gif') {
659
-                                  $("#smstables").empty();
660
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
661
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
662
-                           } else if (extenlst == 'bmp') {
663
-                                  $("#smstables").empty();
664
-                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
665
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
666
-                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
667
-                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
668
-                                  var xhr = new XMLHttpRequest();
669
-                                  xhr.responseType = 'arraybuffer';
670
-                                  xhr.open('GET', tiffile);
671
-                                  xhr.onload = function (evnt) {
672
-                                      var tiff = new Tiff({buffer: xhr.response});
673
-                                      var tifcanvas = tiff.toCanvas();
674
-                                      $("#smstables").empty();
675
-                                      $("#smstables").append(tifcanvas);
676
-                                  };
677
-                                  xhr.send();
678
-                           } else if (extenlst == 'pdf') {
679
-                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
680
-                                  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>');
681
-                                  $("#smstables").empty();
682
-                                  $("#smstables").append($iframe);
683
-                           } else if (extenlst == 'txt') {
684
-                                  $("#smstables").empty();
685
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
686
-                           } else if (extension == 'mp4') {
687
-                                  $("#smstables").empty();
688
-                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
689
-		           } else if (extension == 'ogg') {
690
-		                  $("#smstables").empty();
691
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
692
-		           } else if (extension == 'avi') {
693
-		                  $("#smstables").empty();
694
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
695
-		           } else if (extension == 'mpg' || extension == 'mpeg') {
696
-		                  $("#smstables").empty();
697
-		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
698
-		           } else if (extension == 'wav' || extension == 'wave') {
699
-		                  $("#smstables").empty();
700
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
701
-		           } else if (extension == 'mp3') {
702
-		                  $("#smstables").empty();
703
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
704
-		           } else if (extension == 'midi') {
705
-		                  $("#smstables").empty();
706
-		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
707
-		           }
708
-
709
-                           $("#smstables").show();
710
-                           $("#mmsfoldersview").hide();
711
-                        });
712
-                   });
713
-
714
-                   // Remove uploaded files
715
-                   $('[class*="indupfldl"]').last().click(function() {
716
-
717
-                           var userid = "<?php p($userId); ?>";
718
-                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
719
-
720
-                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
721
-
722
-                           var removedfilesplit = removedfilenameinit.split(") ");
723
-                           var removedflnb = parseInt(removedfilesplit[0]);
724
-
725
-                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
726
-                           $(this).hide();
727
-
728
-                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
729
-
730
-                           uploadedtomms = $.grep(uploadedtomms, function(value) {
731
-                                           return value != removedfilename;
732
-                           });
733
-
734
-                           $.ajax({
735
-                                   url: baseUrl + '/' + userid,
736
-                                   type: "POST",
737
-                                   data: {removedfilename: removedfilename},
738
-                                   success: function(totalflsize) {
739
-
740
-                                      msgtotalflsize = totalflsize;
741
-                                      $('#filessizetext').text(totalflsize);
742
-
743
-                                      adjustMaximumSize(uploadedtomms);
744
-
745
-                                      // Check message size
746
-                                      var rectotfilesz = parseFloat(totalflsize);
747
-
748
-                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
749
-                                          $('#submitsms').attr("disabled", false);
750
-                                          $('#filestotsize').css('color', '#189558');
751
-                                      } else {
752
-                                          $('#filestotsize').css('color', '#ba3555');
753
-                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
754
-                                          $('#submitsms').attr("disabled", true);
755
-                                      }
756
-
757
-                                      // Rewrite order numbers for files that follow
758
-                                      --n;
759
-                                      $("div:visible[id*='indfilediv']").each(function() {
760
-
761
-                                          var getdivtext =  $(this).text();
762
-                                          var splitdivtext = getdivtext.split(") ");
763
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
764
-                                          var newnbvalue = currentnbvalue - 1;
765
-
766
-                                          if (currentnbvalue > removedflnb) {
767
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
768
-                                              $(this).text(replacedstr);
769
-                                          }
770
-                                      });
771
-
772
-                                      $("div:visible[id*='indflpicked']").each(function() {
773
-
774
-                                          var getdivtext =  $(this).text();
775
-                                          var splitdivtext = getdivtext.split(") ");
776
-                                          var currentnbvalue = parseInt(splitdivtext[0]);
777
-                                          var newnbvalue = currentnbvalue - 1;
778
-
779
-                                          if (currentnbvalue > removedflnb) {
780
-                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
781
-                                              $(this).text(replacedstr);
782
-                                          }
783
-                                      });
784
-
785
-                                   },
786
-                                   error: function() {
787
-                                          alert('Error removing file(s)!');
788
-                                   }
789
-                           });
790
-
791
-                           $('#smstables').removeClass('icon-loading');
792
-                           $("#smstables").empty();
793
-                   });
794
-
795
-                   // Preview the uploaded file
796
-                   $("#mmsfoldersview").css("display", "inline-block");
797
-                   var mmsfilename = e.target.files[0].name;
798
-                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
799
-
800
-
801
-                   if (extension == 'jpg' || extension == 'jpeg') {
802
-                              $("#smstables").empty();
803
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
804
-
805
-                              var reader = new FileReader();
806
-                              reader.onload = function (e) {
807
-                                  readjpg[mmsfilename] = e.target.result;
808
-                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
809
-                              }
810
-                              reader.readAsDataURL(e.target.files[0]);
811
-                   } else if (extension == 'png') {
812
-                              $("#smstables").empty();
813
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
814
-
815
-                              var reader = new FileReader();
816
-                              reader.onload = function (e) {
817
-                                  readpng[mmsfilename] = e.target.result;
818
-                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
819
-                              }
820
-                              reader.readAsDataURL(e.target.files[0]);
821
-
822
-                   } else if (extension == 'gif') {
823
-                              $("#smstables").empty();
824
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
825
-
826
-                              var reader = new FileReader();
827
-                              reader.onload = function (e) {
828
-                                  readgif[mmsfilename] = e.target.result;
829
-                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
830
-                              }
831
-                              reader.readAsDataURL(e.target.files[0]);
832
-
833
-                   } else if (extension == 'bmp') {
834
-                              $("#smstables").empty();
835
-                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
836
-
837
-                              var reader = new FileReader();
838
-                              reader.onload = function (e) {
839
-                                  readbmp[mmsfilename] = e.target.result;
840
-                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
841
-                              }
842
-                              reader.readAsDataURL(e.target.files[0]);
843
-
844
-                   } else if (extension == 'tif' || extension == 'tiff') {
845
-                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
846
-                              var xhr = new XMLHttpRequest();
847
-                              xhr.responseType = 'arraybuffer';
848
-                              xhr.open('GET', tiffile);
849
-                              xhr.onload = function (e) {
850
-                                  var tiff = new Tiff({buffer: xhr.response});
851
-                                  var tifcanvas = tiff.toCanvas();
852
-                                  $("#smstables").empty();
853
-                                  $("#smstables").append(tifcanvas);
854
-                              };
855
-                              xhr.send();
856
-
857
-                   } else if (extension == 'pdf') {
858
-                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
859
-                              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>');
860
-                              $("#smstables").empty();
861
-                              $("#smstables").append($iframe);
862
-
863
-                   } else if (extension == 'txt') {
864
-                              var reader = new FileReader();
865
-                              reader.readAsText(e.target.files[0]);
866
-                              reader.onload = function(e) {
867
-                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
868
-                                  $("#smstables").empty();
869
-                                  $("#smstables").append(readtxtfile[mmsfilename]);
870
-                              };
871
-                   } else if (extension == 'mp4') {
872
-                              $("#smstables").empty();
873
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
874
-                   } else if (extension == 'ogg') {
875
-                              $("#smstables").empty();
876
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
877
-                   } else if (extension == 'avi') {
878
-                              $("#smstables").empty();
879
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
880
-                   } else if (extension == 'mpg' || extension == 'mpeg') {
881
-                              $("#smstables").empty();
882
-                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
883
-                   } else if (extension == 'wav' || extension == 'wave') {
884
-                              $("#smstables").empty();
885
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
886
-                   } else if (extension == 'mp3') {
887
-                              $("#smstables").empty();
888
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
889
-                   } else if (extension == 'midi') {
890
-                              $("#smstables").empty();
891
-                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
892
-                   }
893
-
894
-                   $("#smstables").show();
895
-                   $('#pf_upload_msg').hide();
896
-                   $('#smstables').removeClass('icon-loading');
897
-                   $("#mmsfoldersview").hide();
898
-                 },
899
-                 error: function(data){
900
-                     alert('Error uploading file!');
901
-                 }
902
-               });
903
-
904
-            } else {
905
-                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
906
-                  adjustMaximumSize(uploadedtomms);
907
-
908
-                  alert("Error ! You cannot send more than 10 files in one MMS !");
909
-                  $('#pf_upload_msg').hide();
910
-                  $('#smstables').removeClass('icon-loading');
911
-            }
912
-         } else {
913
-              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
914
-              adjustMaximumSize(uploadedtomms);
915
-
916
-              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
917
-              $('#pf_upload_msg').hide();
918
-              $('#smstables').removeClass('icon-loading');
919
-         }
920
-       } else {
921
-            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
922
-            adjustMaximumSize(uploadedtomms);
923
-
924
-            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
925
-            $('#pf_upload_msg').hide();
926
-            $('#smstables').removeClass('icon-loading');
927
-       }
928
-
929
-     } else {
930
-          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
931
-          adjustMaximumSize(uploadedtomms);
932
-
933
-          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
934
-          $('#pf_upload_msg').hide();
935
-          $('#smstables').removeClass('icon-loading');
936
-     }
937
-  });
938
-
939
-
940
-  // Pick file(s) from Nextcloud, to send as MMS
941
-  var mmsfilename = null;
942
-
943
-  $("#choosefilen").on("click", function(evn) {
944
-
945
-                OC.dialogs.filepicker(
946
-                        t('settings', "Select a file to send as MMS."),
947
-                        function (path) {
948
-
949
-                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
950
-                              $('#smstables').addClass('icon-loading');
951
-                              $('#filestotsize').show();
952
-
953
-                              var userid = "<?php p($userId); ?>";
954
-                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
955
-
956
-                              mmsfilename = path.split('/').pop();
957
-
958
-                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
959
-                                  var duplicatescheck = 1;
960
-                              } else var duplicatescheck = 0;
961
-
962
-                              var extension = mmsfilename.replace(/^.*\./, '');
963
-
964
-                              if (extension == mmsfilename) {
965
-                                  extension = "";
966
-                              } else {
967
-                                  extension = extension.toLowerCase();
968
-                              }
969
-
970
-			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
971
-			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
972
-				   maximumsize = maxsizenonimage;
973
-			      }
974
-
975
-                              if ($.inArray(extension, validExtensions) != -1) {
976
-
977
-                                 if (duplicatescheck == 0) {
978
-
979
-                                    if (n <= maximumfilenumber) {
980
-
981
-                                       $.ajax({
982
-                                          url: baseUrl + '/' + userid,
983
-                                          type: "POST",
984
-                                          data: {path: path},
985
-                                          success: function(pickresult) {
986
-
987
-                                                uploadedtomms.push(mmsfilename);
988
-
989
-                                                var totalflsize = pickresult[0];
990
-                                                var pickedflsize = pickresult[1];
991
-
992
-                                                // Check message size
993
-                                                var rectotfilesz = parseFloat(totalflsize);
994
-                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
995
-
996
-                                                if (filesplustextsize <= maximumsize) {
997
-
998
-                                                    $("#mmsfoldersview").css("display", "inline-block");
999
-
1000
-                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1001
-                                                    n++;
1002
-
1003
-                                                    msgtotalflsize = totalflsize;
1004
-                                                    $('#filessizetext').text(totalflsize);
1005
-                                                    $('#filestotsize').css('color', '#189558');
1006
-
1007
-                                                } else {
1008
-
1009
-                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1010
-                                                    $('#filestotsize').css('color', '#ba3555');
1011
-                                                    msgtotalflsize -= pickedflsize;
1012
-                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1013
-
1014
-                                                    $.ajax({
1015
-                                                        url: baseUrlindrm + '/' + userid,
1016
-                                                        type: "POST",
1017
-                                                        data: {removedfilename: mmsfilename},
1018
-                                                        success: function(totalflsize) {
1019
-
1020
-                                                                          $('#filessizetext').text(totalflsize);
1021
-                                                                          $('#filestotsize').css('color', '#189558');
1022
-                                                                          adjustMaximumSize(uploadedtomms);
1023
-
1024
-                                                        },
1025
-                                                        error: function(totalflsize) {
1026
-                                                                          $('#filessizetext').text(totalflsize);
1027
-                                                                          if (parseFloat(totalflsize) > maximumsize) {
1028
-                                                                              $('#filestotsize').css('color', '#ba3555');
1029
-                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1030
-                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1031
-                                                        }
1032
-                                                    });
1033
-
1034
-                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1035
-
1036
-                                                }
1037
-
1038
-                                                // Preview each file when you click on its name
1039
-                                                $("div:visible[id*='indflpicked']").each(function() {
1040
-                                                   $(this).on("click", function(event) {
1041
-
1042
-                                                      var mmsfilenameinit = $(this).text();
1043
-                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
-                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
-                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
-                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
-
1048
-                                                      if (extenlst == mmsfilenamesp) {
1049
-                                                           extenlst = "";
1050
-                                                      } else {
1051
-                                                           extenlst = extenlst.toLowerCase();
1052
-                                                      }
1053
-
1054
-
1055
-                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
-                                                              $("#smstables").empty();
1057
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
-                                                              $("#uploadedjpg").attr('src', readjpg[mmsfilenamesp]);
1059
-                                                      } else if (extenlst == 'png') {
1060
-                                                              $("#smstables").empty();
1061
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
1062
-                                                              $("#uploadedpng").attr('src', readpng[mmsfilenamesp]);
1063
-                                                      } else if (extenlst == 'gif') {
1064
-                                                              $("#smstables").empty();
1065
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
1066
-                                                              $("#uploadedgif").attr('src', readgif[mmsfilenamesp]);
1067
-                                                      } else if (extenlst == 'bmp') {
1068
-                                                              $("#smstables").empty();
1069
-                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1070
-                                                              $("#uploadedbmp").attr('src', readbmp[mmsfilenamesp]);
1071
-                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1072
-                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1073
-                                                              var xhr = new XMLHttpRequest();
1074
-                                                              xhr.responseType = 'arraybuffer';
1075
-                                                              xhr.open('GET', tiffile);
1076
-                                                              xhr.onload = function (evnt) {
1077
-                                                                  var tiff = new Tiff({buffer: xhr.response});
1078
-                                                                  var tifcanvas = tiff.toCanvas();
1079
-                                                                  $("#smstables").empty();
1080
-                                                                  $("#smstables").append(tifcanvas);
1081
-                                                              };
1082
-                                                              xhr.send();
1083
-                                                      } else if (extenlst == 'pdf') {
1084
-                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1085
-                                                              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>');
1086
-                                                              $("#smstables").empty();
1087
-                                                              $("#smstables").append($iframe);
1088
-                                                      } else if (extenlst == 'txt') {
1089
-                                                              $("#smstables").empty();
1090
-                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1091
-                                                      } else if (extension == 'mp4') {
1092
-							      $("#smstables").empty();
1093
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1094
-						      } else if (extension == 'ogg') {
1095
-							      $("#smstables").empty();
1096
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1097
-						      } else if (extension == 'avi') {
1098
-							      $("#smstables").empty();
1099
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1100
-						      } else if (extension == 'mpg' || extension == 'mpeg') {
1101
-							      $("#smstables").empty();
1102
-							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1103
-						      } else if (extension == 'wav' || extension == 'wave') {
1104
-							      $("#smstables").empty();
1105
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1106
-						      } else if (extension == 'mp3') {
1107
-							      $("#smstables").empty();
1108
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1109
-						      } else if (extension == 'midi') {
1110
-							      $("#smstables").empty();
1111
-							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1112
-						      }
1113
-
1114
-
1115
-                                                      $("#smstables").show();
1116
-                                                      $("#mmsfoldersview").hide();
1117
-                                                   });
1118
-                                                });
1119
-
1120
-                                                // Remove picked files
1121
-                                                $('[class*="indpckfldl"]').last().click(function() {
1122
-                                                    var userid = "<?php p($userId); ?>";
1123
-                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1124
-
1125
-                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1126
-
1127
-                                                    var removedfilesplit = removedfilenameinit.split(") ");
1128
-                                                    var removedflnb = parseInt(removedfilesplit[0]);
1129
-
1130
-                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1131
-                                                    $(this).hide();
1132
-                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1133
-
1134
-                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1135
-                                                             return value != removedfilename;
1136
-                                                    });
1137
-
1138
-                                                    $.ajax({
1139
-                                                        url: baseUrl + '/' + userid,
1140
-                                                        type: "POST",
1141
-                                                        data: {removedfilename: removedfilename},
1142
-                                                        success: function(totalflsize) {
1143
-
1144
-                                                             msgtotalflsize = totalflsize;
1145
-                                                             $('#filessizetext').text(totalflsize);
1146
-                                                             adjustMaximumSize(uploadedtomms);
1147
-
1148
-                                                             // Check message size
1149
-                                                             var rectotfilesz = parseFloat(totalflsize);
1150
-
1151
-                                                             if (rectotfilesz > maximumsize) {
1152
-                                                                 $('#filestotsize').css('color', '#ba3555');
1153
-                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1154
-                                                                 $('#submitsms').attr("disabled", true);
1155
-                                                             } else {
1156
-                                                                 $('#submitsms').attr("disabled", false);
1157
-                                                                 $('#filestotsize').css('color', '#189558');
1158
-                                                               }
1159
-
1160
-                                                             // Rewrite order numbers for files that follow
1161
-                                                             --n;
1162
-                                                             $("div:visible[id*='indflpicked']").each(function() {
1163
-
1164
-                                                                  var getdivtext =  $(this).text();
1165
-                                                                  var splitdivtext = getdivtext.split(") ");
1166
-                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1167
-                                                                  var newnbvalue = currentnbvalue - 1;
1168
-
1169
-                                                                  if (currentnbvalue > removedflnb) {
1170
-                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1171
-                                                                      $(this).text(replacedstr);
1172
-                                                                  }
1173
-                                                             });
1174
-                                                        },
1175
-                                                        error: function() {
1176
-                                                             alert('Error !');
1177
-                                                        }
1178
-                                                    });
1179
-
1180
-                                                    $('#smstables').removeClass('icon-loading');
1181
-                                                    $("#smstables").empty();
1182
-                                                });
1183
-
1184
-		                                // Preview the picked file
1185
-		                                $("#mmsfoldersview").css("display", "inline-block");
1186
-		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1187
-		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1188
-
1189
-
1190
-						if (extension == 'jpg' || extension == 'jpeg') {
1191
-
1192
-		                                            $("#smstables").empty();
1193
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1194
-
1195
-		                                } else if (extension == 'png') {
1196
-
1197
-		                                            $("#smstables").empty();
1198
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1199
-
1200
-		                                } else if (extension == 'gif') {
1201
-
1202
-		                                            $("#smstables").empty();
1203
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1204
-
1205
-		                                } else if (extension == 'bmp') {
1206
-
1207
-	                                                    $("#smstables").empty();
1208
-		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1209
-
1210
-		                                } else if (extension == 'tif' || extension == 'tiff') {
1211
-
1212
-		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1213
-		                                       var xhr = new XMLHttpRequest();
1214
-		                                       xhr.responseType = 'arraybuffer';
1215
-		                                       xhr.open('GET', tiffile);
1216
-		                                       xhr.onload = function (event) {
1217
-		                                           var tiff = new Tiff({buffer: xhr.response});
1218
-		                                           var tifcanvas = tiff.toCanvas();
1219
-		                                           $("#smstables").empty();
1220
-		                                           $("#smstables").append(tifcanvas);
1221
-		                                       };
1222
-		                                       xhr.send();
1223
-
1224
-		                                } else if (extension == 'pdf') {
1225
-
1226
-		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1227
-		                                       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>');
1228
-		                                       $("#smstables").empty();
1229
-		                                       $("#smstables").append($iframe);
1230
-
1231
-		                                } else if (extension == 'txt') {
1232
-
1233
-							     $.get(flUrl, function(textdata) {
1234
-		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1235
-		                                               $("#smstables").empty();
1236
-							       $("#smstables").append(readtxtfile[mmsfilename]);
1237
-							     });
1238
-
1239
-		                                } else if (extension == 'mp4') {
1240
-						       $("#smstables").empty();
1241
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1242
-						} else if (extension == 'ogg') {
1243
-						       $("#smstables").empty();
1244
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1245
-						} else if (extension == 'avi') {
1246
-						       $("#smstables").empty();
1247
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1248
-						} else if (extension == 'mpg' || extension == 'mpeg') {
1249
-						       $("#smstables").empty();
1250
-						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1251
-						} else if (extension == 'wav' || extension == 'wave') {
1252
-						       $("#smstables").empty();
1253
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1254
-						} else if (extension == 'mp3') {
1255
-						       $("#smstables").empty();
1256
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1257
-						} else if (extension == 'midi') {
1258
-						       $("#smstables").empty();
1259
-						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1260
-						}
1261
-
1262
-
1263
-		                                $("#smstables").show();
1264
-
1265
-		                                $('#pf_choose_msg').hide();
1266
-		                                $('#smstables').removeClass('icon-loading');
1267
-		                                $("#mmsfoldersview").hide();
1268
-
1269
-                                          },
1270
-
1271
-                                          error: function(data){
1272
-                                             alert('Error!');
1273
-                                          }
1274
-
1275
-                                       });
1276
-
1277
-                                    } else {
1278
-                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1279
-                                        $('#pf_choose_msg').hide();
1280
-                                        $('#smstables').removeClass('icon-loading');
1281
-                                      }
1282
-                                 } else {
1283
-                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1284
-                                      $('#pf_choose_msg').hide();
1285
-                                      $('#smstables').removeClass('icon-loading');
1286
-                                   }
1287
-
1288
-                              } else {
1289
-                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1290
-                                   $('#pf_choose_msg').hide();
1291
-                                   $('#smstables').removeClass('icon-loading');
1292
-                                }
1293
-
1294
-                        }
1295
-                );
1296
-  });
1297
-
1298
-
1299
-
1300
-  // Send the SMS/MMS message
1301
-  $("#submitsms").on("click", function(event) {
1302
-
1303
-     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1304
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1305
-     $("#sms_submit_msg").css("display", "inline-block");
1306
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1307
-
1308
-     if (selectedid != '') { 
1309
-
1310
-         var sendersplit = selectedid.split(":");
1311
-         var providercap = sendersplit[0];
1312
-         var provsec = sendersplit[1];
1313
-
1314
-         if (/[a-zA-Z]/.test(provsec)) {
1315
-             var alphanumcheck = true;
1316
-         } else { var alphanumcheck = false; }
1317
-
1318
-         if (providercap == 'Tx' && alphanumcheck == false) {  
1319
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1320
-             var selectedsender = "+" + senderproc;
1321
-             var providerUsed = "telnyx";
1322
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1323
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
1324
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1325
-             var providerUsed = "plivo";
1326
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1327
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1328
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1329
-             var selectedsender = "+" + senderproc;
1330
-             var providerUsed = "twilio";
1331
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1332
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1333
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
1334
-             var selectedsender = "+" + senderproc;
1335
-             var providerUsed = "flowroute";
1336
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1337
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
1338
-             var selectedsender = provsec;
1339
-             var providerUsed = "telnyx";
1340
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1341
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
1342
-             var selectedsender = provsec;
1343
-             var providerUsed = "plivo";
1344
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1345
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
1346
-             var selectedsender = provsec;
1347
-             var providerUsed = "twilio";
1348
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1349
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
1350
-             var selectedsender = provsec;
1351
-             var providerUsed = "flowroute";
1352
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1353
-         }
1354
-
1355
-         // Get the interval between message consecutive sending requests, if it's the case
1356
-         if ($('#tomultchckbx').is(':checked')) {
1357
-
1358
-             var numbersfile = 1;
1359
-             var initinterval = $("#multsmsinterval").val();
1360
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
1361
-
1362
-             if (secinterval != '') {
1363
-                 var tertinterval = parseInt(secinterval);
1364
-                     waittime = tertinterval;
1365
-             }
1366
-
1367
-         } else {
1368
-
1369
-             var numbersfile = 0;
1370
-             var toNumberinit = $('#smsto').val();
1371
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1372
-             var toNumbersec = toNumber.split(",");
1373
-
1374
-                 for (var i = 0; i < toNumbersec.length; i++) {
1375
-                      toNumbersec[i] = "+" + toNumbersec[i];
1376
-                 }
1377
-
1378
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1379
-         }
1380
-
1381
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1382
-
1383
-         var smstext = $("#smstext").val();
1384
-
1385
-         if (receiversNumbers.length != 0) {
1386
-
1387
-              if (smstext != '') {
1388
-                  $.ajax({
1389
-                     url: relbaseUrl + '/' + userid,
1390
-                     type: "POST",
1391
-                     data: {
1392
-                           receiversPhoneNbs: receiversNumbers,
1393
-                           fromsender: selectedsender,
1394
-                           waitinterval: waittime,
1395
-                           sentsmstext: smstext,
1396
-                           ismms: isMMS,
1397
-                           mmsfiles: uploadedtomms
1398
-                         },
1399
-                     success: function() {
1400
-
1401
-                           if (receiversNumbers.length == 1) {
1402
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1403
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1404
-
1405
-                           $('#sms_submit_msg').hide();
1406
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1407
-                     },
1408
-                     error: function() {
1409
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1410
-                           $('#sms_submit_msg').hide();
1411
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1412
-                     }
1413
-                  });
1414
-              } else {
1415
-                     alert("Please enter a message in the text box !");
1416
-                     $('#sms_submit_msg').hide();
1417
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1418
-              }
1419
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1420
-                 alert("Please enter the recipient's phone number !");
1421
-                 $('#sms_submit_msg').hide();
1422
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1423
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1424
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1425
-                 $('#sms_submit_msg').hide();
1426
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1427
-         }
1428
-     } else {
1429
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
1430
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1431
-           $('#sms_submit_msg').hide();
1432
-     }
1433
-
1434
-  });
1435
-
1436
-  // Check the checkbox to delete old messages from the database
1437
-  $('#deleteoldchckbox').change(function() {
1438
-     if ($(this).is(':checked')) {
1439
-         $("#deleteoldsms").css("display", "block");
1440
-     } else {
1441
-         $("#deleteoldsms").css("display", "none");
1442
-     }
1443
-  });
1444
-
1445
-  // Set the height of 3 info notes
1446
-  $('#setcalleridtp').css('height', $(window).height() - 160);
1447
-  $('#tonmbrformat').css('height', $(window).height() - 260);
1448
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
1449
-
1450
-  $(window).resize(function() { 
1451
-    $('#setcalleridtp').css('height', $(window).height() - 160);
1452
-    $('#tonmbrformat').css('height', $(window).height() - 260);
1453
-    $('#uploadfileinfo').css('height', $(window).height() - 390);
1454
-  });
1455
-
Browse code

added README.md CHANGELOG.txt appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/settings.js js/sendsms.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php templates/navigation/index.php templates/content/index.php templates/settings.php js/tiff.min.js img/nextcloud_logo.svg img/nextcloud_logo_bright.svg img/sms_relentless_mms_sending.png

DoubleBastionAdmin authored on 02/09/2022 23:19:37
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1455 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+  var selectedid = '';
30
+  var isMMS = 0;
31
+  var n = 1;
32
+  var textsizekb = 0;
33
+  var uploadedtomms = [];
34
+  var msgtotalflsize = 0;
35
+  var readtxtfile = [];
36
+  var readhtmlfile = [];
37
+  var readjpg = [];
38
+  var readpng = [];
39
+  var readgif = [];
40
+  var readbmp = [];
41
+  var readtif = [];
42
+  var readmp4 = [];
43
+  var chosenProvider = '';
44
+  var chosenProvFullName = '';
45
+  var infonotecontent = '';
46
+  var validExtensions = [];
47
+  var maximumsize = 750;
48
+  var maxsizenonimage = 600;
49
+  var maximumfilenumber = 10;
50
+  var maximumsizeinit = 750;
51
+
52
+  // 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
53
+  var locHref = window.location.href;
54
+  var pathSplit = locHref.split('/');
55
+  var firstPathEl = '';
56
+  if (pathSplit.length == 7) { firstPathEl = '/' + pathSplit[3]; }
57
+
58
+  // Clean the SMS_Relentless/temp_files directory
59
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
60
+
61
+  $.ajax({
62
+          url: cleanflUrl + '/' + userid,
63
+          type: "POST",
64
+          data: { userid: userid },
65
+          cache: false,
66
+          processData: false,
67
+          contentType: false
68
+  });
69
+  
70
+  // Check the available balance
71
+  $("#smsprovider").on("change", function () {
72
+
73
+     var provider = $('#smsprovider :selected').val();
74
+
75
+     if (provider == "Telnyx") {
76
+
77
+        var gettelbalance = function() {
78
+
79
+          $('#currentbalance').addClass('icon-loading');
80
+
81
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
82
+
83
+          $.ajax({
84
+              url: gettelbalanceUrl + '/' + userid,
85
+              type: "POST",
86
+              data: { userid: userid },
87
+              cache: false,
88
+              processData: false,
89
+              contentType: false,
90
+              success: function(currentbalancetel) {
91
+
92
+                     $('#currentbalance').empty();
93
+                     $('#currentbalance').text(currentbalancetel);
94
+                     $('#currentbalance').removeClass('icon-loading');
95
+              }
96
+          });
97
+        }
98
+
99
+        gettelbalance();
100
+
101
+     } else if (provider == "Plivo") {
102
+
103
+          var getnexbalance = function() {
104
+
105
+            $('#currentbalance').addClass('icon-loading');
106
+
107
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
108
+
109
+            $.ajax({
110
+                url: getnexbalanceUrl + '/' + userid,
111
+                type: "POST",
112
+                data: { userid: userid },
113
+                cache: false,
114
+                processData: false,
115
+                contentType: false,
116
+                success: function(currentbalancenex) {
117
+
118
+                     $('#currentbalance').empty();
119
+                     $('#currentbalance').text(currentbalancenex);
120
+                     $('#currentbalance').removeClass('icon-loading');
121
+                }
122
+            });
123
+          }
124
+
125
+          getnexbalance();
126
+
127
+     } else if (provider == "Twilio") {
128
+
129
+          var gettwilbalance = function() {
130
+
131
+            $('#currentbalance').addClass('icon-loading');
132
+
133
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
134
+
135
+            $.ajax({
136
+                url: gettwilbalanceUrl + '/' + userid,
137
+                type: "POST",
138
+                data: { userid: userid },
139
+                cache: false,
140
+                processData: false,
141
+                contentType: false,
142
+                success: function(currentbalancetwil) {
143
+
144
+                     $('#currentbalance').empty();
145
+                     $('#currentbalance').text(currentbalancetwil);
146
+                     $('#currentbalance').removeClass('icon-loading');
147
+                }
148
+            });
149
+          }
150
+
151
+          gettwilbalance();
152
+
153
+     } else if (provider == "Flowroute") {
154
+
155
+          var getflowbalance = function() {
156
+
157
+            $('#currentbalance').addClass('icon-loading');
158
+
159
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
160
+
161
+            $.ajax({
162
+                url: getflowbalanceUrl + '/' + userid,
163
+                type: "POST",
164
+                data: { userid: userid },
165
+                cache: false,
166
+                processData: false,
167
+                contentType: false,
168
+                success: function(currentbalanceflow) {
169
+
170
+                     $('#currentbalance').empty();
171
+                     $('#currentbalance').text(currentbalanceflow);
172
+                     $('#currentbalance').removeClass('icon-loading');
173
+                }
174
+            });
175
+          }
176
+
177
+          getflowbalance();
178
+
179
+       } else if (provider == "") {
180
+                $('#currentbalance').text("");
181
+                $('#currentbalance').removeClass('icon-loading');
182
+       }
183
+  });
184
+
185
+  // Select the Sender ID
186
+  $("#selectcalleridbttn").on("click", function(event) {
187
+
188
+     $('#selectcalleridbttn').addClass('icon-loading');
189
+
190
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
191
+
192
+     $.ajax({
193
+          url: getsmsnumbersUrl + '/' + userid,
194
+          type: "POST",
195
+          data: { userid: userid },
196
+          cache: false,
197
+          processData: false,
198
+          contentType: false,
199
+          success: function(currentnmbrs) {
200
+
201
+                     $('#currentsmsnmbrs').empty();
202
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
203
+
204
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
205
+                         var emptyinit = indsmsnmb.split(":");
206
+                         var emptysec = emptyinit[1];
207
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
208
+
209
+                         if (emptycheck != '') {
210
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
211
+                         }
212
+                     });
213
+
214
+                     $('#selectcalleridbttn').removeClass('icon-loading');
215
+          }
216
+     });
217
+  });
218
+
219
+  // If a Sender ID is selected, get it
220
+  $("#currentsmsnmbrs").on("change", function () {
221
+
222
+          if ($("#currentsmsnmbrs option[value='']").length > 0) {
223
+
224
+              selectedid = $('#currentsmsnmbrs :selected').val();
225
+              var setIdsplit = selectedid.split(":");
226
+	      chosenProvider = setIdsplit[0];
227
+
228
+              // Set the valid MMS file extensions, maximum MMS message size, maximum message size when non-jpeg/png/gif files are included, maximum number of files and the info note content, for the chosen provider
229
+	      if (chosenProvider == "Tx") {
230
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "mp3", "ogg", "amr", "mp4", "3gpp", "pdf", "vcf", "vcard", "txt"];
231
+		  // Maximum size of message text + media files in KB
232
+		  maximumsize = 1024;
233
+                  maximumsizeinit = 1024;
234
+		  maxsizenonimage = 600;
235
+		  maximumfilenumber = 10;
236
+                  chosenProvFullName = "Telnyx";
237
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Telnyx, if you send only jpeg/jpg, png \
238
+                                     or gif files, the size of all the files plus the size of the text should be \
239
+                                     <a href='https://support.telnyx.com/en/articles/4450150-faqs-about-mms-at-telnyx' style='color:#1b60ba' target='_blank' \
240
+                                     rel='noreferrer noopener'>1024 KB</a> or less. If you send files of other formats, the total size of the files plus the size of the text should \
241
+                                     be 600 KB or less. Allowed formats are jpeg/jpg, png, gif, mp3, ogg, amr, mp4, 3gpp, pdf, vcf, vcard and txt. By default, Telnyx accounts are \
242
+                                     limited to <a href='https://support.telnyx.com/en/articles/3102823-mms-sending-and-receiving' style='color:#1b60ba' target='_blank' \
243
+                                     rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device of the receiver. \
244
+                                     Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or \
245
+                                     gif files, with a total message size of 600 KB or less. Telnyx allows sending MMS messages only from US or Canadian phone numbers to other US \
246
+                                     or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, \
247
+                                     gif, mp4, ogg, etc.) can be previewed in the adjoining pane.";
248
+                  $("#tooltiptextfourth").html(infonotecontent);
249
+	      } else if (chosenProvider == "Pl") {
250
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "wav", "wave", "mp4", "amr", "mpg", "mpeg", "3gpp", "3gpp2", "vcf", "vcard", "x-vcard", "ics", "ical", "ifb", 
251
+                                     "icalendar", "csv", "txt", "pdf", "xls"];
252
+		  // Maximum size of message text + media files in KB
253
+		  maximumsize = 5120;
254
+                  maximumsizeinit = 5120;
255
+		  maxsizenonimage = 600;
256
+		  maximumfilenumber = 10;
257
+                  chosenProvFullName = "Plivo";
258
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Plivo, if you send only jpeg/jpg, png \
259
+                                     or gif files, the size of all the files plus the size of the text should be \
260
+                                     <a href='https://support.plivo.com/hc/en-us/articles/360042280091-What-are-the-MMS-upload-size-limits-and-file-restrictions-' \
261
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
262
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://support.plivo.com/hc/en-us/articles/360042273051' \
263
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, wav/wave, mp4, amr, mpg, mpeg, 3gpp, \
264
+                                     3gpp2, vcf, vcard, x-vcard, ics, ical, ifb, icalendar, csv, txt, pdf and xls. Deliverability of MMS messages depends on the carrier and \
265
+                                     device of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is \
266
+                                     achieved when sending jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Plivo allows sending MMS messages \
267
+                                     only from US or Canadian phone numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, \
268
+                                     only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane.";
269
+                  $("#tooltiptextfourth").html(infonotecontent);
270
+	      } else if (chosenProvider == "Tw") {
271
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "tif", "au", "snd", "l16", "wav", "wave", "aiff", "pcm", "mp4", "ogg", "ra", "ram", "3gpp", 
272
+                                     "3gpp2", "ac3", "webm", "amr", "mpg", "mpeg", "mov", "qt", "h261", "h263", "h264", "vcf", "vcard", "x-vcard", "csv", "rtf", "ics", "ical", "ifb", 
273
+                                     "icalendar", "directory", "pdf", "pkpass"];
274
+		  // Maximum size of message text + media files in KB
275
+		  maximumsize = 5120;
276
+                  maximumsizeinit = 5120;
277
+		  maxsizenonimage = 600;
278
+		  maximumfilenumber = 10;
279
+                  chosenProvFullName = "Twilio";
280
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Twilio, if you send only jpeg/jpg, png \
281
+                                     or gif files, the size of all the files plus the size of the text should be \
282
+                                     <a href='https://support.twilio.com/hc/en-us/articles/360018832773-Twilio-Programmable-SMS-Supported-File-Types-and-Size-Limits-for-MMS-Media-Messages' \
283
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>5120 KB</a> or less. If you send files of other formats, the total size \
284
+                                     of the files plus the size of the text should be 600 KB or less. <a href='https://www.twilio.com/docs/sms/accepted-mime-types' \
285
+                                     style='color:#1b60ba' target='_blank' rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, tiff/tif, au, snd, l16, \
286
+                                     wav/wave, aiff, pcm, mp4, ogg, ra, ram, 3gpp, 3gpp2, ac3, webm, amr, mpg, mpeg, mov, qt, h261, h263, h264, vcf, vcard, x-vcard, csv, rtf, ics, \
287
+                                     ical, ifb, icalendar, directory, pdf and pkpass. Deliverability of MMS messages depends on the carrier and device of the receiver. Carriers \
288
+                                     can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending jpeg/jpg, png or gif files, \
289
+                                     with a total message size of 600 KB or less. Twilio allows sending MMS messages from US or Canadian phone numbers to other US or Canadian phone \
290
+                                     numbers. However, MMS messages sent internationally will be converted to SMS messages with URL links to the included files. Although all the \
291
+                                     specified file types can be added to the MMS, only the most common media file types (jpeg/jpg, png, gif, wav/wave, mp4, ogg, etc.) can be \
292
+                                     previewed in the adjoining pane."
293
+                  $("#tooltiptextfourth").html(infonotecontent);
294
+	      } else if (chosenProvider == "Fl") {
295
+		  validExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "3gp", "mp4", "avi", "amr", "midi", "wav", "wave", "ac3", "mp3"];
296
+		  // Maximum size of message text + media files in KB
297
+		  maximumsize = 750;
298
+                  maximumsizeinit = 750;
299
+		  maxsizenonimage = 600;
300
+		  maximumfilenumber = 10;
301
+                  chosenProvFullName = "Flowroute";
302
+                  infonotecontent = "To send an MMS, you can upload media files or pick them from Nextcloud. You can add up to 10 files. For Flowroute, if you send only jpeg/jpg, \
303
+                                     png or gif files, the size of all the files plus the size of the text should be \
304
+                                     <a href='https://developer.flowroute.com/api/messages/v2.1/send-an-mms/' style='color:#1b60ba' target='_blank' \
305
+                                     rel='noreferrer noopener'>750 KB</a> or less. If you send files of other formats, the total \
306
+                                     size of the files plus the size of the text should be 600 KB or less. \
307
+                                     <a href='https://support.flowroute.com/937402-What-file-types-does-Flowroute-MMS-support' style='color:#1b60ba' target='_blank' \
308
+                                     rel='noreferrer noopener'>Allowed formats</a> are jpeg/jpg, png, gif, bmp, 3gp, mp4, avi, amr, midi, wav/wave, ac3 and mp3. Flowroute accounts are \
309
+                                     limited to <a href='https://developer.flowroute.com/docs/sms-mms-best-practices/#sending-and-receiving-limitations' style='color:#1b60ba' \
310
+                                     target='_blank' rel='noreferrer noopener'>1 MMS message per second</a>. Deliverability of MMS messages depends on the carrier and device \
311
+                                     of the receiver. Carriers can reject MMS messages with files exceeding a certain size. The best deliverability is achieved when sending \
312
+                                     jpeg/jpg, png or gif files, with a total message size of 600 KB or less. Flowroute allows sending MMS messages only from US or Canadian phone \
313
+                                     numbers to other US or Canadian phone numbers. Although all the specified file types can be added to the MMS, only the most common media file \
314
+                                     types (jpeg/jpg, png, gif, wav/wave, mp4, etc.) can be previewed in the adjoining pane."
315
+                  $("#tooltiptextfourth").html(infonotecontent);
316
+	      }
317
+
318
+          } else { selectedid = ''; }
319
+  });
320
+
321
+  // Check the checkbox to send SMS message to multiple recipients
322
+  $('#tomultchckbx').change(function() {
323
+      if ($(this).is(':checked')) {
324
+          $("#multiplerecivers").css("display", "block");
325
+          $("#smstodiv").css("visibility", "hidden");
326
+          $("#smsto").val("");
327
+
328
+          receiversNumbers.length = 0;
329
+
330
+      } else {
331
+          $("#multiplerecivers").css("display", "none");
332
+          $("#smstodiv").css("visibility", "visible");
333
+
334
+          // Remove the uploaded file(s) if any
335
+          $("#induploadfile").remove();
336
+
337
+          receiversNumbers.length = 0;
338
+      }
339
+  });
340
+
341
+  // Upload the file with the recipients' phone numbers
342
+  $("#uploadfileforsms").change(function(e) {
343
+
344
+     $("#fileuploadednm").empty();
345
+
346
+     receiversNumbers.length = 0;
347
+
348
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
349
+
350
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
351
+
352
+     var formData = new FormData();
353
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
354
+
355
+     var fileup = $('#uploadfileforsms').val();
356
+     var fileuptrim = fileup.split('\\').pop();
357
+
358
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
359
+
360
+     var extension = fileup.replace(/^.*\./, '');
361
+
362
+     if (extension == fileup) {
363
+         extension = "";
364
+     } else {
365
+         extension = extension.toLowerCase();
366
+     }
367
+
368
+     var validExtensionsmrec = ["txt", "csv"];
369
+
370
+     if (jQuery.inArray(extension, validExtensionsmrec) != -1) {
371
+
372
+       if (selectedid != '') {
373
+
374
+               $.ajax({
375
+                 url: baseUrl + '/' + userid,
376
+                 type: "POST",
377
+                 data: formData,
378
+                 cache: false,
379
+                 processData: false,
380
+                 contentType: false,
381
+                 success: function(numberarray) {
382
+
383
+		    if (numberarray.length > 0) {
384
+
385
+		        // Get the array of the receivers' phone numbers
386
+		        if (chosenProvider == "Tx") {
387
+
388
+		             for(key in numberarray) {
389
+		                 receiversNumbers.push("+"+numberarray[key]);
390
+		             }
391
+
392
+		        } else if (chosenProvider == "Pl") {
393
+
394
+		             for(key in numberarray) {
395
+		                 receiversNumbers.push(numberarray[key]);
396
+		             }
397
+
398
+		          } else if (chosenProvider == "Tw") {
399
+
400
+		             for(key in numberarray) {
401
+		                 receiversNumbers.push(numberarray[key]);
402
+		             }
403
+		          } else if (chosenProvider == "Fl") {
404
+
405
+		             for(key in numberarray) {
406
+		                 receiversNumbers.push(numberarray[key]);
407
+		             }
408
+		          }
409
+
410
+		    } else {
411
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
412
+		    }
413
+                            
414
+                    // Preview the uploaded file
415
+                    var smsfilename = e.target.files[0].name;
416
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
417
+
418
+                    var reader = new FileReader();
419
+                    reader.readAsText(e.target.files[0]);
420
+                    reader.onload = function(e) {
421
+                          $("#smstables").empty();
422
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
423
+                    };
424
+
425
+                    $("#smstables").show();
426
+
427
+                    $('#sms_upload_msg').hide();
428
+                    $('#smstables').removeClass('icon-loading');
429
+
430
+                  },
431
+                  error: function(){
432
+                     alert('Error!');
433
+                  }
434
+               });
435
+
436
+        } else {
437
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
438
+               $('#sms_upload_msg').hide();
439
+               $('#smstables').removeClass('icon-loading');
440
+        }
441
+
442
+     } else {
443
+          alert('The file type is not supported ! Supported formats are txt and csv.');
444
+          $('#pf_upload_msg').hide();
445
+          $('#smstables').removeClass('icon-loading');
446
+
447
+          $("#induploadfile").remove();
448
+          $("#sms_upload_msg").hide();
449
+     }
450
+
451
+     //Preview uploaded file when clicked
452
+     $("#indfilediv").on("click", function() {
453
+
454
+          var smsfilename = e.target.files[0].name;
455
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
456
+
457
+          var reader = new FileReader();
458
+          reader.readAsText(e.target.files[0]);
459
+          reader.onload = function(e) {
460
+                  $("#smstables").empty();
461
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
462
+          };
463
+
464
+          $("#smstables").show();
465
+          $('#sms_upload_msg').hide();
466
+          $('#smstables').removeClass('icon-loading');
467
+     });
468
+
469
+     // Remove selected file
470
+     $("#indivflremove").on("click", function() {
471
+
472
+          $("#induploadfile").remove();
473
+          $("#sms_upload_msg").hide();
474
+
475
+          receiversNumbers.length = 0;
476
+
477
+     });
478
+
479
+  });
480
+
481
+  // Show the number of characters entered in the SMS textarea and the text size in KB
482
+  $("#smstext").on('input', function() {
483
+
484
+     $("#char_count").css("display", "inline");
485
+
486
+     $("#mtextSize").css("display", "inline");
487
+
488
+     $(".maxmessagelength").css("display", "inline-block");
489
+
490
+     $("#countchnb").text($(this).val().length);
491
+
492
+     var textsize = encodeURIComponent($(this).val()).replace(/%[A-F\d]{2}/g, 'U').length;
493
+     textsizekb = parseFloat(textsize/1024).toFixed(4);
494
+     $("#textsizeinkb").text(textsizekb);
495
+
496
+     if ($(this).val().length > charcolorthr) {
497
+         $("#char_count").css("color", "#BB2E4B");
498
+     } else {
499
+         $("#char_count").css("color", "#4cbc86;");
500
+     }
501
+
502
+  });
503
+
504
+
505
+  // Check the checkbox to send file(s) as MMS
506
+  $('#mediafilechckbx').change(function() {
507
+
508
+      if ($(this).is(':checked')) {
509
+
510
+          isMMS = 1;
511
+          if (selectedid == '') {
512
+              alert("Please, first choose a Sender ID from the Set ID drop-down list !");
513
+              $(this).prop("checked", false);
514
+              isMMS = 0;
515
+              return;
516
+          }
517
+          $("#upmediafiles").css("display", "block");
518
+          $("#submitsms").prop("value", "Send MMS");
519
+
520
+      } else {
521
+
522
+          isMMS = 0;
523
+          $("#upmediafiles").css("display", "none");
524
+          $("#submitsms").prop("value", "Send SMS");
525
+
526
+          // Remove the uploaded file(s) if any
527
+          $(".indgenflclsmms").each(function() { $(this).remove(); });
528
+          $(".indgenpckfls").each(function() { $(this).remove(); });
529
+
530
+          uploadedtomms = [];
531
+          n = 1;
532
+
533
+          msgtotalflsize = 0;
534
+
535
+          $("#filestotsize").hide();
536
+      }
537
+  });
538
+
539
+
540
+  // Check if the uploaded files' format is jpeg, png or gif and adjust the maximum cumulative size of files, if necessary
541
+  function adjustMaximumSize(uploadedtomms) {
542
+				      
543
+      var nonimgcheck = 0;
544
+      for (var u = 0; u < uploadedtomms.length; u++) {
545
+	   var crupfl = uploadedtomms[u];
546
+	   var extensionup = crupfl.replace(/^.*\./, '');
547
+	   if ($.inArray(extensionup, ["jpg", "jpeg", "png", "gif"]) === -1) {
548
+	       nonimgcheck = 1;
549
+	   }
550
+      }
551
+
552
+      if (nonimgcheck == 0) { maximumsize = maximumsizeinit; }
553
+  }
554
+
555
+  // Upload files to be sent as MMS
556
+  $("#uploadfileformms").change(function(e) {
557
+
558
+     OC.msg.startAction("#pf_upload_msg", t("sms_relentless", "Uploading ..."));
559
+     $('#smstables').addClass('icon-loading');
560
+     $('#filestotsize').show();
561
+
562
+     var userid = "<?php p($userId); ?>";
563
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/uploadfile");
564
+
565
+     var formData = new FormData();
566
+     formData.append('uploadfileformms', $('#uploadfileformms')[0].files[0]);
567
+
568
+     var currentflsize = $('#uploadfileformms')[0].files[0].size;
569
+
570
+     // Add the size of the current file to the total size of all the files
571
+     msgtotalflsize += Math.floor((currentflsize/1024) * 100)/100;
572
+
573
+     var fileup = $('#uploadfileformms').val();
574
+     var fileuptrim = fileup.split('\\').pop();
575
+
576
+     if ($.inArray(fileuptrim, uploadedtomms) != -1) {
577
+         var duplicatescheck = 1;
578
+     } else { 
579
+         var duplicatescheck = 0;
580
+     }
581
+
582
+     var extension = fileup.replace(/^.*\./, '');
583
+
584
+     if (extension == fileup) {
585
+         extension = "";
586
+     } else {
587
+         extension = extension.toLowerCase();
588
+     }
589
+
590
+     // If the uploaded file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
591
+     if (($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) && (msgtotalflsize <= Number(maximumsize) - Number(textsizekb))) {
592
+         maximumsize = maxsizenonimage;
593
+     }
594
+
595
+     if ($.inArray(extension, validExtensions) != -1) {
596
+
597
+       if (duplicatescheck == 0) {
598
+
599
+         if (msgtotalflsize <= Number(maximumsize) - Number(textsizekb)) {
600
+
601
+            if (n <= maximumfilenumber) {
602
+
603
+               $.ajax({
604
+                 url: baseUrl + '/' + userid,
605
+                 type: "POST",
606
+                 data: formData,
607
+                 cache: false,
608
+                 processData: false,
609
+                 contentType: false,
610
+                 success: function(totalflsize) {
611
+
612
+                   uploadedtomms.push(fileuptrim);
613
+
614
+                   $('#filessizetext').text(totalflsize);
615
+
616
+                   var rectotfilesz = parseFloat(totalflsize);
617
+
618
+                   if (rectotfilesz <= maximumsize) {
619
+                       $('#submitsms').attr("disabled", false);
620
+                       $('#filestotsize').css('color', '#189558');
621
+                   } else {
622
+                       $('#filestotsize').css('color', '#ba3555');
623
+                       alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
624
+                       $('#submitsms').attr("disabled", true);
625
+                       $('#smstables').removeClass('icon-loading');
626
+                       $('#pf_upload_msg').hide();
627
+                   }
628
+
629
+                   $('#mmsfileuploadednm').append("<div class='indgenflclsmms'><div id='"+n+"indfilediv' class='indivflcls'>" + n + ") " + fileuptrim + "</div><div class='indupfldl'>X</div></div>");
630
+                   n++;
631
+
632
+                   // Preview the file when you click on its name
633
+                   $("div:visible[id*='indfilediv']").each(function() {
634
+
635
+                        $(this).on("click", function(eventclck) {
636
+
637
+                           $("#mmsfoldersview").css("display", "inline-block");
638
+                           var mmsfilenameinit = $(this).text();
639
+                           var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
640
+                           var mmsfilename = mmsfilenamesec.replace("X","");
641
+                           var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
642
+                           var extenlst = mmsfilename.replace(/^.*\./, '');
643
+
644
+                           if (extenlst == mmsfilename) {
645
+                               extenlst = "";
646
+                           } else {
647
+                               extenlst = extenlst.toLowerCase();
648
+                           }
649
+
650
+                           if (extenlst == 'jpg' || extenlst == 'jpeg') {
651
+                                  $("#smstables").empty();
652
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
653
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
654
+                           } else if (extenlst == 'png') {
655
+                                  $("#smstables").empty();
656
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
657
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
658
+                           } else if (extenlst == 'gif') {
659
+                                  $("#smstables").empty();
660
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
661
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
662
+                           } else if (extenlst == 'bmp') {
663
+                                  $("#smstables").empty();
664
+                                  $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
665
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
666
+                           } else if (extenlst == 'tif' || extenlst == 'tiff') {
667
+                                  var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
668
+                                  var xhr = new XMLHttpRequest();
669
+                                  xhr.responseType = 'arraybuffer';
670
+                                  xhr.open('GET', tiffile);
671
+                                  xhr.onload = function (evnt) {
672
+                                      var tiff = new Tiff({buffer: xhr.response});
673
+                                      var tifcanvas = tiff.toCanvas();
674
+                                      $("#smstables").empty();
675
+                                      $("#smstables").append(tifcanvas);
676
+                                  };
677
+                                  xhr.send();
678
+                           } else if (extenlst == 'pdf') {
679
+                                  var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
680
+                                  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>');
681
+                                  $("#smstables").empty();
682
+                                  $("#smstables").append($iframe);
683
+                           } else if (extenlst == 'txt') {
684
+                                  $("#smstables").empty();
685
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
686
+                           } else if (extension == 'mp4') {
687
+                                  $("#smstables").empty();
688
+                                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
689
+		           } else if (extension == 'ogg') {
690
+		                  $("#smstables").empty();
691
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
692
+		           } else if (extension == 'avi') {
693
+		                  $("#smstables").empty();
694
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
695
+		           } else if (extension == 'mpg' || extension == 'mpeg') {
696
+		                  $("#smstables").empty();
697
+		                  $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
698
+		           } else if (extension == 'wav' || extension == 'wave') {
699
+		                  $("#smstables").empty();
700
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
701
+		           } else if (extension == 'mp3') {
702
+		                  $("#smstables").empty();
703
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
704
+		           } else if (extension == 'midi') {
705
+		                  $("#smstables").empty();
706
+		                  $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
707
+		           }
708
+
709
+                           $("#smstables").show();
710
+                           $("#mmsfoldersview").hide();
711
+                        });
712
+                   });
713
+
714
+                   // Remove uploaded files
715
+                   $('[class*="indupfldl"]').last().click(function() {
716
+
717
+                           var userid = "<?php p($userId); ?>";
718
+                           var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
719
+
720
+                           var removedfilenameinit = $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').text();
721
+
722
+                           var removedfilesplit = removedfilenameinit.split(") ");
723
+                           var removedflnb = parseInt(removedfilesplit[0]);
724
+
725
+                           $(this).closest('[class*="indgenflclsmms"]').find('[class*="indivflcls"]').hide();
726
+                           $(this).hide();
727
+
728
+                           var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
729
+
730
+                           uploadedtomms = $.grep(uploadedtomms, function(value) {
731
+                                           return value != removedfilename;
732
+                           });
733
+
734
+                           $.ajax({
735
+                                   url: baseUrl + '/' + userid,
736
+                                   type: "POST",
737
+                                   data: {removedfilename: removedfilename},
738
+                                   success: function(totalflsize) {
739
+
740
+                                      msgtotalflsize = totalflsize;
741
+                                      $('#filessizetext').text(totalflsize);
742
+
743
+                                      adjustMaximumSize(uploadedtomms);
744
+
745
+                                      // Check message size
746
+                                      var rectotfilesz = parseFloat(totalflsize);
747
+
748
+                                      if (rectotfilesz <= Number(maximumsize) - Number(textsizekb)) {
749
+                                          $('#submitsms').attr("disabled", false);
750
+                                          $('#filestotsize').css('color', '#189558');
751
+                                      } else {
752
+                                          $('#filestotsize').css('color', '#ba3555');
753
+                                          alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the total size of the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
754
+                                          $('#submitsms').attr("disabled", true);
755
+                                      }
756
+
757
+                                      // Rewrite order numbers for files that follow
758
+                                      --n;
759
+                                      $("div:visible[id*='indfilediv']").each(function() {
760
+
761
+                                          var getdivtext =  $(this).text();
762
+                                          var splitdivtext = getdivtext.split(") ");
763
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
764
+                                          var newnbvalue = currentnbvalue - 1;
765
+
766
+                                          if (currentnbvalue > removedflnb) {
767
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
768
+                                              $(this).text(replacedstr);
769
+                                          }
770
+                                      });
771
+
772
+                                      $("div:visible[id*='indflpicked']").each(function() {
773
+
774
+                                          var getdivtext =  $(this).text();
775
+                                          var splitdivtext = getdivtext.split(") ");
776
+                                          var currentnbvalue = parseInt(splitdivtext[0]);
777
+                                          var newnbvalue = currentnbvalue - 1;
778
+
779
+                                          if (currentnbvalue > removedflnb) {
780
+                                              var replacedstr = newnbvalue + ") " + splitdivtext[1];
781
+                                              $(this).text(replacedstr);
782
+                                          }
783
+                                      });
784
+
785
+                                   },
786
+                                   error: function() {
787
+                                          alert('Error removing file(s)!');
788
+                                   }
789
+                           });
790
+
791
+                           $('#smstables').removeClass('icon-loading');
792
+                           $("#smstables").empty();
793
+                   });
794
+
795
+                   // Preview the uploaded file
796
+                   $("#mmsfoldersview").css("display", "inline-block");
797
+                   var mmsfilename = e.target.files[0].name;
798
+                   var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
799
+
800
+
801
+                   if (extension == 'jpg' || extension == 'jpeg') {
802
+                              $("#smstables").empty();
803
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="#" />');
804
+
805
+                              var reader = new FileReader();
806
+                              reader.onload = function (e) {
807
+                                  readjpg[mmsfilename] = e.target.result;
808
+                                  $("#uploadedjpg").attr('src', readjpg[mmsfilename]);
809
+                              }
810
+                              reader.readAsDataURL(e.target.files[0]);
811
+                   } else if (extension == 'png') {
812
+                              $("#smstables").empty();
813
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
814
+
815
+                              var reader = new FileReader();
816
+                              reader.onload = function (e) {
817
+                                  readpng[mmsfilename] = e.target.result;
818
+                                  $("#uploadedpng").attr('src', readpng[mmsfilename]);
819
+                              }
820
+                              reader.readAsDataURL(e.target.files[0]);
821
+
822
+                   } else if (extension == 'gif') {
823
+                              $("#smstables").empty();
824
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
825
+
826
+                              var reader = new FileReader();
827
+                              reader.onload = function (e) {
828
+                                  readgif[mmsfilename] = e.target.result;
829
+                                  $("#uploadedgif").attr('src', readgif[mmsfilename]);
830
+                              }
831
+                              reader.readAsDataURL(e.target.files[0]);
832
+
833
+                   } else if (extension == 'bmp') {
834
+                              $("#smstables").empty();
835
+                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
836
+
837
+                              var reader = new FileReader();
838
+                              reader.onload = function (e) {
839
+                                  readbmp[mmsfilename] = e.target.result;
840
+                                  $("#uploadedbmp").attr('src', readbmp[mmsfilename]);
841
+                              }
842
+                              reader.readAsDataURL(e.target.files[0]);
843
+
844
+                   } else if (extension == 'tif' || extension == 'tiff') {
845
+                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
846
+                              var xhr = new XMLHttpRequest();
847
+                              xhr.responseType = 'arraybuffer';
848
+                              xhr.open('GET', tiffile);
849
+                              xhr.onload = function (e) {
850
+                                  var tiff = new Tiff({buffer: xhr.response});
851
+                                  var tifcanvas = tiff.toCanvas();
852
+                                  $("#smstables").empty();
853
+                                  $("#smstables").append(tifcanvas);
854
+                              };
855
+                              xhr.send();
856
+
857
+                   } else if (extension == 'pdf') {
858
+                              var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
859
+                              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>');
860
+                              $("#smstables").empty();
861
+                              $("#smstables").append($iframe);
862
+
863
+                   } else if (extension == 'txt') {
864
+                              var reader = new FileReader();
865
+                              reader.readAsText(e.target.files[0]);
866
+                              reader.onload = function(e) {
867
+                                  readtxtfile[mmsfilename] = e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>');
868
+                                  $("#smstables").empty();
869
+                                  $("#smstables").append(readtxtfile[mmsfilename]);
870
+                              };
871
+                   } else if (extension == 'mp4') {
872
+                              $("#smstables").empty();
873
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
874
+                   } else if (extension == 'ogg') {
875
+                              $("#smstables").empty();
876
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
877
+                   } else if (extension == 'avi') {
878
+                              $("#smstables").empty();
879
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
880
+                   } else if (extension == 'mpg' || extension == 'mpeg') {
881
+                              $("#smstables").empty();
882
+                              $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
883
+                   } else if (extension == 'wav' || extension == 'wave') {
884
+                              $("#smstables").empty();
885
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
886
+                   } else if (extension == 'mp3') {
887
+                              $("#smstables").empty();
888
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
889
+                   } else if (extension == 'midi') {
890
+                              $("#smstables").empty();
891
+                              $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
892
+                   }
893
+
894
+                   $("#smstables").show();
895
+                   $('#pf_upload_msg').hide();
896
+                   $('#smstables').removeClass('icon-loading');
897
+                   $("#mmsfoldersview").hide();
898
+                 },
899
+                 error: function(data){
900
+                     alert('Error uploading file!');
901
+                 }
902
+               });
903
+
904
+            } else {
905
+                  msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
906
+                  adjustMaximumSize(uploadedtomms);
907
+
908
+                  alert("Error ! You cannot send more than 10 files in one MMS !");
909
+                  $('#pf_upload_msg').hide();
910
+                  $('#smstables').removeClass('icon-loading');
911
+            }
912
+         } else {
913
+              msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
914
+              adjustMaximumSize(uploadedtomms);
915
+
916
+              alert('Error ! For '+ chosenProvFullName +', for the chosen files format, the size of all the included files plus the size of the text cannot be greater than '+ maxsizenonimage +' KB !');
917
+              $('#pf_upload_msg').hide();
918
+              $('#smstables').removeClass('icon-loading');
919
+         }
920
+       } else {
921
+            msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
922
+            adjustMaximumSize(uploadedtomms);
923
+
924
+            alert("Error ! There is already a file named '"+fileuptrim+"' in the 'SMS_Relentless/temp_files' folder !");
925
+            $('#pf_upload_msg').hide();
926
+            $('#smstables').removeClass('icon-loading');
927
+       }
928
+
929
+     } else {
930
+          msgtotalflsize -= Math.floor((currentflsize/1024) * 100)/100;
931
+          adjustMaximumSize(uploadedtomms);
932
+
933
+          alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
934
+          $('#pf_upload_msg').hide();
935
+          $('#smstables').removeClass('icon-loading');
936
+     }
937
+  });
938
+
939
+
940
+  // Pick file(s) from Nextcloud, to send as MMS
941
+  var mmsfilename = null;
942
+
943
+  $("#choosefilen").on("click", function(evn) {
944
+
945
+                OC.dialogs.filepicker(
946
+                        t('settings', "Select a file to send as MMS."),
947
+                        function (path) {
948
+
949
+                              OC.msg.startAction("#pf_choose_msg", t("sms_relentless", "Please wait ..."));
950
+                              $('#smstables').addClass('icon-loading');
951
+                              $('#filestotsize').show();
952
+
953
+                              var userid = "<?php p($userId); ?>";
954
+                              var baseUrl = OC.generateUrl("/apps/sms_relentless/user/pickfile");
955
+
956
+                              mmsfilename = path.split('/').pop();
957
+
958
+                              if ($.inArray(mmsfilename, uploadedtomms) != -1) {
959
+                                  var duplicatescheck = 1;
960
+                              } else var duplicatescheck = 0;
961
+
962
+                              var extension = mmsfilename.replace(/^.*\./, '');
963
+
964
+                              if (extension == mmsfilename) {
965
+                                  extension = "";
966
+                              } else {
967
+                                  extension = extension.toLowerCase();
968
+                              }
969
+
970
+			      // If the picked file's format is different from jpeg, png or gif, the maximum allowed size of the message will be lower
971
+			      if ($.inArray(extension, ["jpg", "jpeg", "png", "gif"]) === -1) {
972
+				   maximumsize = maxsizenonimage;
973
+			      }
974
+
975
+                              if ($.inArray(extension, validExtensions) != -1) {
976
+
977
+                                 if (duplicatescheck == 0) {
978
+
979
+                                    if (n <= maximumfilenumber) {
980
+
981
+                                       $.ajax({
982
+                                          url: baseUrl + '/' + userid,
983
+                                          type: "POST",
984
+                                          data: {path: path},
985
+                                          success: function(pickresult) {
986
+
987
+                                                uploadedtomms.push(mmsfilename);
988
+
989
+                                                var totalflsize = pickresult[0];
990
+                                                var pickedflsize = pickresult[1];
991
+
992
+                                                // Check message size
993
+                                                var rectotfilesz = parseFloat(totalflsize);
994
+                                                var filesplustextsize = Number(rectotfilesz) + Number(textsizekb);
995
+
996
+                                                if (filesplustextsize <= maximumsize) {
997
+
998
+                                                    $("#mmsfoldersview").css("display", "inline-block");
999
+
1000
+                                                    $('#filespickednc').append("<div class='indgenpckfls'><div id='"+n+"indflpicked' class='indivflpckd'>" + n + ") " + mmsfilename + "</div><div class='indpckfldl'>X</div></div>");
1001
+                                                    n++;
1002
+
1003
+                                                    msgtotalflsize = totalflsize;
1004
+                                                    $('#filessizetext').text(totalflsize);
1005
+                                                    $('#filestotsize').css('color', '#189558');
1006
+
1007
+                                                } else {
1008
+
1009
+                                                    uploadedtomms = uploadedtomms.filter(function(e) { return e !== mmsfilename });
1010
+                                                    $('#filestotsize').css('color', '#ba3555');
1011
+                                                    msgtotalflsize -= pickedflsize;
1012
+                                                    var baseUrlindrm = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1013
+
1014
+                                                    $.ajax({
1015
+                                                        url: baseUrlindrm + '/' + userid,
1016
+                                                        type: "POST",
1017
+                                                        data: {removedfilename: mmsfilename},
1018
+                                                        success: function(totalflsize) {
1019
+
1020
+                                                                          $('#filessizetext').text(totalflsize);
1021
+                                                                          $('#filestotsize').css('color', '#189558');
1022
+                                                                          adjustMaximumSize(uploadedtomms);
1023
+
1024
+                                                        },
1025
+                                                        error: function(totalflsize) {
1026
+                                                                          $('#filessizetext').text(totalflsize);
1027
+                                                                          if (parseFloat(totalflsize) > maximumsize) {
1028
+                                                                              $('#filestotsize').css('color', '#ba3555');
1029
+                                                                          } else { $('#filestotsize').css('color', '#189558'); }
1030
+                                                                          alert("Error while trying to remove the last picked file from the 'SMS_Relentless/temp_files' directory!"); 
1031
+                                                        }
1032
+                                                    });
1033
+
1034
+                                                    alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1035
+
1036
+                                                }
1037
+
1038
+                                                // Preview each file when you click on its name
1039
+                                                $("div:visible[id*='indflpicked']").each(function() {
1040
+                                                   $(this).on("click", function(event) {
1041
+
1042
+                                                      var mmsfilenameinit = $(this).text();
1043
+                                                      var mmsfilenamesec = mmsfilenameinit.substring(mmsfilenameinit.indexOf(" ") + 1);
1044
+                                                      var mmsfilenamesp = mmsfilenamesec.replace("X","");
1045
+                                                      var baseUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilenamesp;
1046
+                                                      var extenlst = mmsfilenamesp.replace(/^.*\./, '');
1047
+
1048
+                                                      if (extenlst == mmsfilenamesp) {
1049
+                                                           extenlst = "";
1050
+                                                      } else {
1051
+                                                           extenlst = extenlst.toLowerCase();
1052
+                                                      }
1053
+
1054
+
1055
+                                                      if (extenlst == 'jpg' || extenlst == 'jpeg') {
1056
+                                                              $("#smstables").empty();
1057
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ baseUrl +'" />');
1058
+                                                              $("#uploadedjpg").attr('src', readjpg[mmsfilenamesp]);
1059
+                                                      } else if (extenlst == 'png') {
1060
+                                                              $("#smstables").empty();
1061
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="#" />');
1062
+                                                              $("#uploadedpng").attr('src', readpng[mmsfilenamesp]);
1063
+                                                      } else if (extenlst == 'gif') {
1064
+                                                              $("#smstables").empty();
1065
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="#" />');
1066
+                                                              $("#uploadedgif").attr('src', readgif[mmsfilenamesp]);
1067
+                                                      } else if (extenlst == 'bmp') {
1068
+                                                              $("#smstables").empty();
1069
+                                                              $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="#" />');
1070
+                                                              $("#uploadedbmp").attr('src', readbmp[mmsfilenamesp]);
1071
+                                                      } else if (extenlst == 'tif' || extenlst == 'tiff') {
1072
+                                                              var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilenamesp;
1073
+                                                              var xhr = new XMLHttpRequest();
1074
+                                                              xhr.responseType = 'arraybuffer';
1075
+                                                              xhr.open('GET', tiffile);
1076
+                                                              xhr.onload = function (evnt) {
1077
+                                                                  var tiff = new Tiff({buffer: xhr.response});
1078
+                                                                  var tifcanvas = tiff.toCanvas();
1079
+                                                                  $("#smstables").empty();
1080
+                                                                  $("#smstables").append(tifcanvas);
1081
+                                                              };
1082
+                                                              xhr.send();
1083
+                                                      } else if (extenlst == 'pdf') {
1084
+                                                              var viewerclick = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: baseUrl});
1085
+                                                              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>');
1086
+                                                              $("#smstables").empty();
1087
+                                                              $("#smstables").append($iframe);
1088
+                                                      } else if (extenlst == 'txt') {
1089
+                                                              $("#smstables").empty();
1090
+                                                              $("#smstables").append(readtxtfile[mmsfilenamesp]);
1091
+                                                      } else if (extension == 'mp4') {
1092
+							      $("#smstables").empty();
1093
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1094
+						      } else if (extension == 'ogg') {
1095
+							      $("#smstables").empty();
1096
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1097
+						      } else if (extension == 'avi') {
1098
+							      $("#smstables").empty();
1099
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1100
+						      } else if (extension == 'mpg' || extension == 'mpeg') {
1101
+							      $("#smstables").empty();
1102
+							      $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1103
+						      } else if (extension == 'wav' || extension == 'wave') {
1104
+							      $("#smstables").empty();
1105
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1106
+						      } else if (extension == 'mp3') {
1107
+							      $("#smstables").empty();
1108
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1109
+						      } else if (extension == 'midi') {
1110
+							      $("#smstables").empty();
1111
+							      $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1112
+						      }
1113
+
1114
+
1115
+                                                      $("#smstables").show();
1116
+                                                      $("#mmsfoldersview").hide();
1117
+                                                   });
1118
+                                                });
1119
+
1120
+                                                // Remove picked files
1121
+                                                $('[class*="indpckfldl"]').last().click(function() {
1122
+                                                    var userid = "<?php p($userId); ?>";
1123
+                                                    var baseUrl = OC.generateUrl("/apps/sms_relentless/user/removeupfile");
1124
+
1125
+                                                    var removedfilenameinit = $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').text();
1126
+
1127
+                                                    var removedfilesplit = removedfilenameinit.split(") ");
1128
+                                                    var removedflnb = parseInt(removedfilesplit[0]);
1129
+
1130
+                                                    $(this).closest('[class*="indgenpckfls"]').find('[class*="indivflpckd"]').hide();
1131
+                                                    $(this).hide();
1132
+                                                    var removedfilename = removedfilenameinit.substring(removedfilenameinit.indexOf(" ") + 1);
1133
+
1134
+                                                    uploadedtomms = $.grep(uploadedtomms, function(value) {
1135
+                                                             return value != removedfilename;
1136
+                                                    });
1137
+
1138
+                                                    $.ajax({
1139
+                                                        url: baseUrl + '/' + userid,
1140
+                                                        type: "POST",
1141
+                                                        data: {removedfilename: removedfilename},
1142
+                                                        success: function(totalflsize) {
1143
+
1144
+                                                             msgtotalflsize = totalflsize;
1145
+                                                             $('#filessizetext').text(totalflsize);
1146
+                                                             adjustMaximumSize(uploadedtomms);
1147
+
1148
+                                                             // Check message size
1149
+                                                             var rectotfilesz = parseFloat(totalflsize);
1150
+
1151
+                                                             if (rectotfilesz > maximumsize) {
1152
+                                                                 $('#filestotsize').css('color', '#ba3555');
1153
+                                                                 alert("Error ! For "+ chosenProvFullName +", for the chosen files format, the size of all the included files plus the size of the text cannot exceed "+ maximumsize +" KB !");
1154
+                                                                 $('#submitsms').attr("disabled", true);
1155
+                                                             } else {
1156
+                                                                 $('#submitsms').attr("disabled", false);
1157
+                                                                 $('#filestotsize').css('color', '#189558');
1158
+                                                               }
1159
+
1160
+                                                             // Rewrite order numbers for files that follow
1161
+                                                             --n;
1162
+                                                             $("div:visible[id*='indflpicked']").each(function() {
1163
+
1164
+                                                                  var getdivtext =  $(this).text();
1165
+                                                                  var splitdivtext = getdivtext.split(") ");
1166
+                                                                  var currentnbvalue = parseInt(splitdivtext[0]);
1167
+                                                                  var newnbvalue = currentnbvalue - 1;
1168
+
1169
+                                                                  if (currentnbvalue > removedflnb) {
1170
+                                                                      var replacedstr = newnbvalue + ") " + splitdivtext[1];
1171
+                                                                      $(this).text(replacedstr);
1172
+                                                                  }
1173
+                                                             });
1174
+                                                        },
1175
+                                                        error: function() {
1176
+                                                             alert('Error !');
1177
+                                                        }
1178
+                                                    });
1179
+
1180
+                                                    $('#smstables').removeClass('icon-loading');
1181
+                                                    $("#smstables").empty();
1182
+                                                });
1183
+
1184
+		                                // Preview the picked file
1185
+		                                $("#mmsfoldersview").css("display", "inline-block");
1186
+		                                var flUrl = firstPathEl+"/remote.php/webdav/SMS_Relentless/temp_files/"+mmsfilename;
1187
+		                                var pickUrl = OC.generateUrl("/apps/sms_relentless/user/getpickedfile");
1188
+
1189
+
1190
+						if (extension == 'jpg' || extension == 'jpeg') {
1191
+
1192
+		                                            $("#smstables").empty();
1193
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedjpg" src="'+ flUrl +'" />');
1194
+
1195
+		                                } else if (extension == 'png') {
1196
+
1197
+		                                            $("#smstables").empty();
1198
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedpng" src="'+ flUrl +'" />');
1199
+
1200
+		                                } else if (extension == 'gif') {
1201
+
1202
+		                                            $("#smstables").empty();
1203
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedgif" src="'+ flUrl +'" />');
1204
+
1205
+		                                } else if (extension == 'bmp') {
1206
+
1207
+	                                                    $("#smstables").empty();
1208
+		                                            $("#smstables").append('<img style="width:auto;height:auto" id="uploadedbmp" src="'+ flUrl +'" />');
1209
+
1210
+		                                } else if (extension == 'tif' || extension == 'tiff') {
1211
+
1212
+		                                       var tiffile = '/remote.php/webdav/SMS_Relentless/temp_files/'+mmsfilename;
1213
+		                                       var xhr = new XMLHttpRequest();
1214
+		                                       xhr.responseType = 'arraybuffer';
1215
+		                                       xhr.open('GET', tiffile);
1216
+		                                       xhr.onload = function (event) {
1217
+		                                           var tiff = new Tiff({buffer: xhr.response});
1218
+		                                           var tifcanvas = tiff.toCanvas();
1219
+		                                           $("#smstables").empty();
1220
+		                                           $("#smstables").append(tifcanvas);
1221
+		                                       };
1222
+		                                       xhr.send();
1223
+
1224
+		                                } else if (extension == 'pdf') {
1225
+
1226
+		                                       var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {file: flUrl});
1227
+		                                       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>');
1228
+		                                       $("#smstables").empty();
1229
+		                                       $("#smstables").append($iframe);
1230
+
1231
+		                                } else if (extension == 'txt') {
1232
+
1233
+							     $.get(flUrl, function(textdata) {
1234
+		                                               readtxtfile[mmsfilename] = textdata.replace(/(?:\r\n|\r|\n)/g, '<br>');
1235
+		                                               $("#smstables").empty();
1236
+							       $("#smstables").append(readtxtfile[mmsfilename]);
1237
+							     });
1238
+
1239
+		                                } else if (extension == 'mp4') {
1240
+						       $("#smstables").empty();
1241
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmp4" src="'+ baseUrl +'"></video>');
1242
+						} else if (extension == 'ogg') {
1243
+						       $("#smstables").empty();
1244
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedogg" src="'+ baseUrl +'"></video>');
1245
+						} else if (extension == 'avi') {
1246
+						       $("#smstables").empty();
1247
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedavi" src="'+ baseUrl +'" type="video/avi"></video>');
1248
+						} else if (extension == 'mpg' || extension == 'mpeg') {
1249
+						       $("#smstables").empty();
1250
+						       $("#smstables").append('<video width="100%" height="auto" controls><source id="uploadedmpg" src="'+ baseUrl +'"></video>');
1251
+						} else if (extension == 'wav' || extension == 'wave') {
1252
+						       $("#smstables").empty();
1253
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedwav" src="'+ baseUrl +'"></audio>');
1254
+						} else if (extension == 'mp3') {
1255
+						       $("#smstables").empty();
1256
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmp3" src="'+ baseUrl +'" type="audio/mp3"></audio>');
1257
+						} else if (extension == 'midi') {
1258
+						       $("#smstables").empty();
1259
+						       $("#smstables").append('<audio width="100%" height="auto" controls><source id="uploadedmidi" src="'+ baseUrl +'" type="audio/midi"></audio>');
1260
+						}
1261
+
1262
+
1263
+		                                $("#smstables").show();
1264
+
1265
+		                                $('#pf_choose_msg').hide();
1266
+		                                $('#smstables').removeClass('icon-loading');
1267
+		                                $("#mmsfoldersview").hide();
1268
+
1269
+                                          },
1270
+
1271
+                                          error: function(data){
1272
+                                             alert('Error!');
1273
+                                          }
1274
+
1275
+                                       });
1276
+
1277
+                                    } else {
1278
+                                        alert("Error ! You cannot send more than "+ maximumfilenumber +" files in one MMS message !");
1279
+                                        $('#pf_choose_msg').hide();
1280
+                                        $('#smstables').removeClass('icon-loading');
1281
+                                      }
1282
+                                 } else {
1283
+                                      alert("Error ! There is already a file named '"+ mmsfilename +"' in the 'SMS_Relentless/temp_files' folder !");
1284
+                                      $('#pf_choose_msg').hide();
1285
+                                      $('#smstables').removeClass('icon-loading');
1286
+                                   }
1287
+
1288
+                              } else {
1289
+                                   alert('The file type is not supported ! Supported extensions for '+ chosenProvFullName +' are: '+ validExtensions.join(", ") +'.');
1290
+                                   $('#pf_choose_msg').hide();
1291
+                                   $('#smstables').removeClass('icon-loading');
1292
+                                }
1293
+
1294
+                        }
1295
+                );
1296
+  });
1297
+
1298
+
1299
+
1300
+  // Send the SMS/MMS message
1301
+  $("#submitsms").on("click", function(event) {
1302
+
1303
+     if (isMMS == 0) { var sendingtype = 'SMS'; } else { var sendingtype = 'MMS'; }
1304
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending "+ sendingtype +" ... Please wait !"));
1305
+     $("#sms_submit_msg").css("display", "inline-block");
1306
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
1307
+
1308
+     if (selectedid != '') { 
1309
+
1310
+         var sendersplit = selectedid.split(":");
1311
+         var providercap = sendersplit[0];
1312
+         var provsec = sendersplit[1];
1313
+
1314
+         if (/[a-zA-Z]/.test(provsec)) {
1315
+             var alphanumcheck = true;
1316
+         } else { var alphanumcheck = false; }
1317
+
1318
+         if (providercap == 'Tx' && alphanumcheck == false) {  
1319
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1320
+             var selectedsender = "+" + senderproc;
1321
+             var providerUsed = "telnyx";
1322
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1323
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
1324
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
1325
+             var providerUsed = "plivo";
1326
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1327
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
1328
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1329
+             var selectedsender = "+" + senderproc;
1330
+             var providerUsed = "twilio";
1331
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1332
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
1333
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
1334
+             var selectedsender = "+" + senderproc;
1335
+             var providerUsed = "flowroute";
1336
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1337
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
1338
+             var selectedsender = provsec;
1339
+             var providerUsed = "telnyx";
1340
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
1341
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
1342
+             var selectedsender = provsec;
1343
+             var providerUsed = "plivo";
1344
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
1345
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
1346
+             var selectedsender = provsec;
1347
+             var providerUsed = "twilio";
1348
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
1349
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
1350
+             var selectedsender = provsec;
1351
+             var providerUsed = "flowroute";
1352
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
1353
+         }
1354
+
1355
+         // Get the interval between message consecutive sending requests, if it's the case
1356
+         if ($('#tomultchckbx').is(':checked')) {
1357
+
1358
+             var numbersfile = 1;
1359
+             var initinterval = $("#multsmsinterval").val();
1360
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
1361
+
1362
+             if (secinterval != '') {
1363
+                 var tertinterval = parseInt(secinterval);
1364
+                     waittime = tertinterval;
1365
+             }
1366
+
1367
+         } else {
1368
+
1369
+             var numbersfile = 0;
1370
+             var toNumberinit = $('#smsto').val();
1371
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
1372
+             var toNumbersec = toNumber.split(",");
1373
+
1374
+                 for (var i = 0; i < toNumbersec.length; i++) {
1375
+                      toNumbersec[i] = "+" + toNumbersec[i];
1376
+                 }
1377
+
1378
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
1379
+         }
1380
+
1381
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
1382
+
1383
+         var smstext = $("#smstext").val();
1384
+
1385
+         if (receiversNumbers.length != 0) {
1386
+
1387
+              if (smstext != '') {
1388
+                  $.ajax({
1389
+                     url: relbaseUrl + '/' + userid,
1390
+                     type: "POST",
1391
+                     data: {
1392
+                           receiversPhoneNbs: receiversNumbers,
1393
+                           fromsender: selectedsender,
1394
+                           waitinterval: waittime,
1395
+                           sentsmstext: smstext,
1396
+                           ismms: isMMS,
1397
+                           mmsfiles: uploadedtomms
1398
+                         },
1399
+                     success: function() {
1400
+
1401
+                           if (receiversNumbers.length == 1) {
1402
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the button again.");
1403
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the button again."); }
1404
+
1405
+                           $('#sms_submit_msg').hide();
1406
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1407
+                     },
1408
+                     error: function() {
1409
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
1410
+                           $('#sms_submit_msg').hide();
1411
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1412
+                     }
1413
+                  });
1414
+              } else {
1415
+                     alert("Please enter a message in the text box !");
1416
+                     $('#sms_submit_msg').hide();
1417
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1418
+              }
1419
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
1420
+                 alert("Please enter the recipient's phone number !");
1421
+                 $('#sms_submit_msg').hide();
1422
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1423
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
1424
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
1425
+                 $('#sms_submit_msg').hide();
1426
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1427
+         }
1428
+     } else {
1429
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
1430
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
1431
+           $('#sms_submit_msg').hide();
1432
+     }
1433
+
1434
+  });
1435
+
1436
+  // Check the checkbox to delete old messages from the database
1437
+  $('#deleteoldchckbox').change(function() {
1438
+     if ($(this).is(':checked')) {
1439
+         $("#deleteoldsms").css("display", "block");
1440
+     } else {
1441
+         $("#deleteoldsms").css("display", "none");
1442
+     }
1443
+  });
1444
+
1445
+  // Set the height of 3 info notes
1446
+  $('#setcalleridtp').css('height', $(window).height() - 160);
1447
+  $('#tonmbrformat').css('height', $(window).height() - 260);
1448
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
1449
+
1450
+  $(window).resize(function() { 
1451
+    $('#setcalleridtp').css('height', $(window).height() - 160);
1452
+    $('#tonmbrformat').css('height', $(window).height() - 260);
1453
+    $('#uploadfileinfo').css('height', $(window).height() - 390);
1454
+  });
1455
+
Browse code

removed README.md CHANGELOG.txt appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/settings.js js/sendsms.js js/showsmstables.js lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php templates/navigation/index.php templates/content/index.php templates/settings.php

DoubleBastionAdmin authored on 02/09/2022 23:09:46
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,543 +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
-  var userid = "<?php p($userId); ?>";
24
-  var charcolorthr = 160;
25
-  var textread = '';
26
-  var providerUsed = '';
27
-  var receiversNumbers = [];
28
-  var waittime = 1000;
29
-
30
-  // Clean the temp_files directory
31
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
32
-
33
-  $.ajax({
34
-          url: cleanflUrl + '/' + userid,
35
-          type: "POST",
36
-          data: { userid: userid },
37
-          cache: false,
38
-          processData: false,
39
-          contentType: false
40
-  });
41
-  
42
-  // Check the available balance
43
-  $("#smsprovider").on("change", function () {
44
-
45
-     var provider = $('#smsprovider :selected').val();
46
-
47
-     if (provider == "Telnyx") {
48
-
49
-        var gettelbalance = function() {
50
-
51
-          $('#currentbalance').addClass('icon-loading');
52
-
53
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
54
-
55
-          $.ajax({
56
-              url: gettelbalanceUrl + '/' + userid,
57
-              type: "POST",
58
-              data: { userid: userid },
59
-              cache: false,
60
-              processData: false,
61
-              contentType: false,
62
-              success: function(currentbalancetel) {
63
-
64
-                     $('#currentbalance').empty();
65
-                     $('#currentbalance').text(currentbalancetel);
66
-                     $('#currentbalance').removeClass('icon-loading');
67
-              }
68
-          });
69
-        }
70
-
71
-        gettelbalance();
72
-
73
-     } else if (provider == "Plivo") {
74
-
75
-          var getnexbalance = function() {
76
-
77
-            $('#currentbalance').addClass('icon-loading');
78
-
79
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
80
-
81
-            $.ajax({
82
-                url: getnexbalanceUrl + '/' + userid,
83
-                type: "POST",
84
-                data: { userid: userid },
85
-                cache: false,
86
-                processData: false,
87
-                contentType: false,
88
-                success: function(currentbalancenex) {
89
-
90
-                     $('#currentbalance').empty();
91
-                     $('#currentbalance').text(currentbalancenex);
92
-                     $('#currentbalance').removeClass('icon-loading');
93
-                }
94
-            });
95
-          }
96
-
97
-          getnexbalance();
98
-
99
-     } else if (provider == "Twilio") {
100
-
101
-          var gettwilbalance = function() {
102
-
103
-            $('#currentbalance').addClass('icon-loading');
104
-
105
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
106
-
107
-            $.ajax({
108
-                url: gettwilbalanceUrl + '/' + userid,
109
-                type: "POST",
110
-                data: { userid: userid },
111
-                cache: false,
112
-                processData: false,
113
-                contentType: false,
114
-                success: function(currentbalancetwil) {
115
-
116
-                     $('#currentbalance').empty();
117
-                     $('#currentbalance').text(currentbalancetwil);
118
-                     $('#currentbalance').removeClass('icon-loading');
119
-                }
120
-            });
121
-          }
122
-
123
-          gettwilbalance();
124
-
125
-     } else if (provider == "Flowroute") {
126
-
127
-          var getflowbalance = function() {
128
-
129
-            $('#currentbalance').addClass('icon-loading');
130
-
131
-            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
132
-
133
-            $.ajax({
134
-                url: getflowbalanceUrl + '/' + userid,
135
-                type: "POST",
136
-                data: { userid: userid },
137
-                cache: false,
138
-                processData: false,
139
-                contentType: false,
140
-                success: function(currentbalanceflow) {
141
-
142
-                     $('#currentbalance').empty();
143
-                     $('#currentbalance').text(currentbalanceflow);
144
-                     $('#currentbalance').removeClass('icon-loading');
145
-                }
146
-            });
147
-          }
148
-
149
-          getflowbalance();
150
-
151
-       } else if (provider == "") {
152
-                $('#currentbalance').text("");
153
-                $('#currentbalance').removeClass('icon-loading');
154
-       }
155
-  });
156
-
157
-  // Select the Sender ID
158
-  $("#selectcalleridbttn").on("click", function(event) {
159
-
160
-     $('#selectcalleridbttn').addClass('icon-loading');
161
-
162
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
163
-
164
-     $.ajax({
165
-          url: getsmsnumbersUrl + '/' + userid,
166
-          type: "POST",
167
-          data: { userid: userid },
168
-          cache: false,
169
-          processData: false,
170
-          contentType: false,
171
-          success: function(currentnmbrs) {
172
-
173
-                     $('#currentsmsnmbrs').empty();
174
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
175
-
176
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
177
-                         var emptyinit = indsmsnmb.split(":");
178
-                         var emptysec = emptyinit[1];
179
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
180
-
181
-                         if (emptycheck != '') {
182
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
183
-                         }
184
-                     });
185
-
186
-                     $('#selectcalleridbttn').removeClass('icon-loading');
187
-          }
188
-     });
189
-  });
190
-
191
-  // Check the checkbox to send SMS message to multiple recipients
192
-  $('#tomultchckbx').change(function() {
193
-      if ($(this).is(':checked')) {
194
-          $("#multiplerecivers").css("display", "block");
195
-          $("#smstodiv").css("visibility", "hidden");
196
-          $("#smsto").val("");
197
-
198
-          receiversNumbers.length = 0;
199
-
200
-      } else {
201
-          $("#multiplerecivers").css("display", "none");
202
-          $("#smstodiv").css("visibility", "visible");
203
-
204
-          // Remove the uploaded file if any
205
-          $("#induploadfile").remove();
206
-
207
-          receiversNumbers.length = 0;
208
-
209
-          $.ajax({
210
-             url: cleanflUrl + '/' + userid,
211
-             type: "POST",
212
-             data: {userid: userid},
213
-             cache: false,
214
-             processData: false,
215
-             contentType: false
216
-          });
217
-      }
218
-  });
219
-
220
-  // Upload the file with the recipients' phone numbers
221
-  $("#uploadfileforsms").change(function(e) {
222
-
223
-     $("#fileuploadednm").empty();
224
-
225
-     receiversNumbers.length = 0;
226
-
227
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
228
-
229
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
230
-
231
-     var formData = new FormData();
232
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
233
-
234
-     var fileup = $('#uploadfileforsms').val();
235
-     var fileuptrim = fileup.split('\\').pop();
236
-
237
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
238
-
239
-     var extension = fileup.replace(/^.*\./, '');
240
-
241
-     if (extension == fileup) {
242
-         extension = "";
243
-     } else {
244
-         extension = extension.toLowerCase();
245
-     }
246
-
247
-     var validExtensions = ["txt", "csv"];
248
-
249
-     if (jQuery.inArray(extension, validExtensions) != -1) {
250
-
251
-	// Check if the Sender ID is set
252
-	if ($("#currentsmsnmbrs option[value='']").length > 0) {
253
-            var setId = $('#currentsmsnmbrs :selected').val();
254
-	} else { var setId = ''; }
255
-
256
-	if (setId != '') {
257
-
258
-               $.ajax({
259
-                 url: baseUrl + '/' + userid,
260
-                 type: "POST",
261
-                 data: formData,
262
-                 cache: false,
263
-                 processData: false,
264
-                 contentType: false,
265
-                 success: function(numberarray) {
266
-
267
-		    if (numberarray.length > 0) {
268
-
269
-		        // Get the array of the receivers' phone numbers
270
-		        var setIdsplit = setId.split(":");
271
-		        var smsProvider = setIdsplit[0];
272
-
273
-		        if (smsProvider == "Tx") {
274
-
275
-		             for(key in numberarray) {
276
-		                 receiversNumbers.push("+"+numberarray[key]);
277
-		             }
278
-
279
-		        } else if (smsProvider == "Pl") {
280
-
281
-		             for(key in numberarray) {
282
-		                 receiversNumbers.push(numberarray[key]);
283
-		             }
284
-
285
-		          } else if (smsProvider == "Tw") {
286
-
287
-		             for(key in numberarray) {
288
-		                 receiversNumbers.push(numberarray[key]);
289
-		             }
290
-		          }
291
-
292
-		    } else {
293
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
294
-		    }
295
-                            
296
-                    // Preview the uploaded file
297
-                    var smsfilename = e.target.files[0].name;
298
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
299
-
300
-                    var reader = new FileReader();
301
-                    reader.readAsText(e.target.files[0]);
302
-                    reader.onload = function(e) {
303
-                          $("#smstables").empty();
304
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
305
-                    };
306
-
307
-                    $("#smstables").show();
308
-
309
-                    $('#sms_upload_msg').hide();
310
-                    $('#smstables').removeClass('icon-loading');
311
-
312
-                  },
313
-                  error: function(){
314
-                     alert('Error!');
315
-                  }
316
-               });
317
-
318
-        } else {
319
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
320
-               $('#sms_upload_msg').hide();
321
-               $('#smstables').removeClass('icon-loading');
322
-        }
323
-
324
-     } else {
325
-          alert('The file type is not supported ! Supported formats are txt and csv.');
326
-          $('#pf_upload_msg').hide();
327
-          $('#smstables').removeClass('icon-loading');
328
-
329
-          $("#induploadfile").remove();
330
-          $("#sms_upload_msg").hide();
331
-     }
332
-
333
-     //Preview uploaded file when clicked
334
-     $("#indfilediv").on("click", function() {
335
-
336
-          var smsfilename = e.target.files[0].name;
337
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
338
-
339
-          var reader = new FileReader();
340
-          reader.readAsText(e.target.files[0]);
341
-          reader.onload = function(e) {
342
-                  $("#smstables").empty();
343
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
344
-          };
345
-
346
-          $("#smstables").show();
347
-          $('#sms_upload_msg').hide();
348
-          $('#smstables').removeClass('icon-loading');
349
-     });
350
-
351
-     // Remove selected file
352
-     $("#indivflremove").on("click", function() {
353
-
354
-          $("#induploadfile").remove();
355
-          $("#sms_upload_msg").hide();
356
-
357
-          receiversNumbers.length = 0;
358
-
359
-          $.ajax({
360
-             url: cleanflUrl + '/' + userid,
361
-             type: "POST",
362
-             data: {userid: userid},
363
-             cache: false,
364
-             processData: false,
365
-             contentType: false
366
-         });
367
-     });
368
-
369
-  });
370
-
371
-  // Count the characters in the SMS text area
372
-  $("#smstext").on('input', function() {
373
-     $("#char_count").css("display", "inline");
374
-     $(".maxmessagelength").css("display", "inline-block");
375
-
376
-     $("#countchnb").text($(this).val().length);
377
-
378
-     if ($(this).val().length > charcolorthr) {
379
-         $("#char_count").css("color", "#BB2E4B");
380
-     } else {
381
-         $("#char_count").css("color", "#4cbc86;");
382
-     }
383
-  });
384
-
385
-  // Send the SMS message
386
-  $("#submitsms").on("click", function(event) {
387
-
388
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
389
-     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
390
-
391
-     // Check if the Sender ID is set
392
-     if ($("#currentsmsnmbrs option[value='']").length > 0) {
393
-            var selectedid = $('#currentsmsnmbrs :selected').val();
394
-     } else { var selectedid = ''; }
395
-
396
-     if (selectedid != '') { 
397
-
398
-         var sendersplit = selectedid.split(":");
399
-         var providercap = sendersplit[0];
400
-         var provsec = sendersplit[1];
401
-
402
-         if (/[a-zA-Z]/.test(provsec)) {
403
-             var alphanumcheck = true;
404
-         } else { var alphanumcheck = false; }
405
-
406
-         if (providercap == 'Tx' && alphanumcheck == false) {  
407
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
408
-             var selectedsender = "+" + senderproc;
409
-             var providerUsed = "telnyx";
410
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
411
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
412
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
413
-             var providerUsed = "plivo";
414
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
415
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
416
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
417
-             var selectedsender = "+" + senderproc;
418
-             var providerUsed = "twilio";
419
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
420
-         } else if (providercap == 'Fl' && alphanumcheck == false) {  
421
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
422
-             var selectedsender = "+" + senderproc;
423
-             var providerUsed = "flowroute";
424
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
425
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
426
-             var selectedsender = provsec;
427
-             var providerUsed = "telnyx";
428
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
429
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
430
-             var selectedsender = provsec;
431
-             var providerUsed = "plivo";
432
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
433
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
434
-             var selectedsender = provsec;
435
-             var providerUsed = "twilio";
436
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
437
-         } else if (providercap == 'Fl' && alphanumcheck == true) {
438
-             var selectedsender = provsec;
439
-             var providerUsed = "flowroute";
440
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
441
-         }
442
-
443
-         // Get the interval between SMS consecutive sending requests, if it's the case
444
-         if ($('#tomultchckbx').is(':checked')) {
445
-
446
-             var numbersfile = 1;
447
-             var initinterval = $("#multsmsinterval").val();
448
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
449
-
450
-             if (secinterval != '') {
451
-                 var tertinterval = parseInt(secinterval);
452
-                     waittime = tertinterval;
453
-             }
454
-
455
-         } else {
456
-
457
-             var numbersfile = 0;
458
-             var toNumberinit = $('#smsto').val();
459
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
460
-             var toNumbersec = toNumber.split(",");
461
-
462
-                 for (var i = 0; i < toNumbersec.length; i++) {
463
-                      toNumbersec[i] = "+" + toNumbersec[i];
464
-                 }
465
-
466
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
467
-         }
468
-
469
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
470
-
471
-         var smstext = $("#smstext").val();
472
-
473
-         if (receiversNumbers.length != 0) {
474
-
475
-              if (smstext != '') {
476
-                  $.ajax({
477
-                     url: relbaseUrl + '/' + userid,
478
-                     type: "POST",
479
-                     data: {
480
-                           receiversPhoneNbs: receiversNumbers,
481
-                           fromsender: selectedsender,
482
-                           waitinterval: waittime,
483
-                           sentsmstext: smstext
484
-                         },
485
-                     success: function() {
486
-
487
-                           if (receiversNumbers.length == 1) {
488
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again.");
489
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again."); }
490
-
491
-                           $('#sms_submit_msg').hide();
492
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
493
-                     },
494
-                     error: function(){
495
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
496
-                           $('#sms_submit_msg').hide();
497
-                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
498
-                     }
499
-                  });
500
-              } else {
501
-                     alert("Please enter a message in the text box !");
502
-                     $('#sms_submit_msg').hide();
503
-                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
504
-              }
505
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
506
-                 alert("Please enter the recipient's phone number !");
507
-                 $('#sms_submit_msg').hide();
508
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
509
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
510
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
511
-                 $('#sms_submit_msg').hide();
512
-                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
513
-         }
514
-     } else {
515
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
516
-           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
517
-           $('#sms_submit_msg').hide();
518
-     }
519
-
520
-  });
521
-
522
-  // Check the checkbox to delete old SMS messages from the database
523
-  $('#deleteoldchckbox').change(function() {
524
-     if ($(this).is(':checked')) {
525
-         $("#deleteoldsms").css("display", "block");
526
-     } else {
527
-         $("#deleteoldsms").css("display", "none");
528
-     }
529
-  });
530
-
531
-  $('#tonmbrformat').css('height', $(window).height() - 260);
532
-  $('#setcalleridtp').css('height', $(window).height() - 160);
533
-  $('#uploadfileinfo').css('height', $(window).height() - 390);
534
-
535
-  $(window).resize(function() { 
536
-    $('#tonmbrformat').css('height', $(window).height() - 260);
537
-    $('#setcalleridtp').css('height', $(window).height() - 160);
538
-    $('#uploadfileinfo').css('height', $(window).height() - 390);
539
-  });
540
-
541
-
542
-
543
-
Browse code

added CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings.php lib/Migration/Version108Date20220818235106.php

DoubleBastionAdmin authored on 18/08/2022 21:30:17
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,543 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var charcolorthr = 160;
25
+  var textread = '';
26
+  var providerUsed = '';
27
+  var receiversNumbers = [];
28
+  var waittime = 1000;
29
+
30
+  // Clean the temp_files directory
31
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
32
+
33
+  $.ajax({
34
+          url: cleanflUrl + '/' + userid,
35
+          type: "POST",
36
+          data: { userid: userid },
37
+          cache: false,
38
+          processData: false,
39
+          contentType: false
40
+  });
41
+  
42
+  // Check the available balance
43
+  $("#smsprovider").on("change", function () {
44
+
45
+     var provider = $('#smsprovider :selected').val();
46
+
47
+     if (provider == "Telnyx") {
48
+
49
+        var gettelbalance = function() {
50
+
51
+          $('#currentbalance').addClass('icon-loading');
52
+
53
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
54
+
55
+          $.ajax({
56
+              url: gettelbalanceUrl + '/' + userid,
57
+              type: "POST",
58
+              data: { userid: userid },
59
+              cache: false,
60
+              processData: false,
61
+              contentType: false,
62
+              success: function(currentbalancetel) {
63
+
64
+                     $('#currentbalance').empty();
65
+                     $('#currentbalance').text(currentbalancetel);
66
+                     $('#currentbalance').removeClass('icon-loading');
67
+              }
68
+          });
69
+        }
70
+
71
+        gettelbalance();
72
+
73
+     } else if (provider == "Plivo") {
74
+
75
+          var getnexbalance = function() {
76
+
77
+            $('#currentbalance').addClass('icon-loading');
78
+
79
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
80
+
81
+            $.ajax({
82
+                url: getnexbalanceUrl + '/' + userid,
83
+                type: "POST",
84
+                data: { userid: userid },
85
+                cache: false,
86
+                processData: false,
87
+                contentType: false,
88
+                success: function(currentbalancenex) {
89
+
90
+                     $('#currentbalance').empty();
91
+                     $('#currentbalance').text(currentbalancenex);
92
+                     $('#currentbalance').removeClass('icon-loading');
93
+                }
94
+            });
95
+          }
96
+
97
+          getnexbalance();
98
+
99
+     } else if (provider == "Twilio") {
100
+
101
+          var gettwilbalance = function() {
102
+
103
+            $('#currentbalance').addClass('icon-loading');
104
+
105
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
106
+
107
+            $.ajax({
108
+                url: gettwilbalanceUrl + '/' + userid,
109
+                type: "POST",
110
+                data: { userid: userid },
111
+                cache: false,
112
+                processData: false,
113
+                contentType: false,
114
+                success: function(currentbalancetwil) {
115
+
116
+                     $('#currentbalance').empty();
117
+                     $('#currentbalance').text(currentbalancetwil);
118
+                     $('#currentbalance').removeClass('icon-loading');
119
+                }
120
+            });
121
+          }
122
+
123
+          gettwilbalance();
124
+
125
+     } else if (provider == "Flowroute") {
126
+
127
+          var getflowbalance = function() {
128
+
129
+            $('#currentbalance').addClass('icon-loading');
130
+
131
+            var getflowbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalanceflow");
132
+
133
+            $.ajax({
134
+                url: getflowbalanceUrl + '/' + userid,
135
+                type: "POST",
136
+                data: { userid: userid },
137
+                cache: false,
138
+                processData: false,
139
+                contentType: false,
140
+                success: function(currentbalanceflow) {
141
+
142
+                     $('#currentbalance').empty();
143
+                     $('#currentbalance').text(currentbalanceflow);
144
+                     $('#currentbalance').removeClass('icon-loading');
145
+                }
146
+            });
147
+          }
148
+
149
+          getflowbalance();
150
+
151
+       } else if (provider == "") {
152
+                $('#currentbalance').text("");
153
+                $('#currentbalance').removeClass('icon-loading');
154
+       }
155
+  });
156
+
157
+  // Select the Sender ID
158
+  $("#selectcalleridbttn").on("click", function(event) {
159
+
160
+     $('#selectcalleridbttn').addClass('icon-loading');
161
+
162
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
163
+
164
+     $.ajax({
165
+          url: getsmsnumbersUrl + '/' + userid,
166
+          type: "POST",
167
+          data: { userid: userid },
168
+          cache: false,
169
+          processData: false,
170
+          contentType: false,
171
+          success: function(currentnmbrs) {
172
+
173
+                     $('#currentsmsnmbrs').empty();
174
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
175
+
176
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
177
+                         var emptyinit = indsmsnmb.split(":");
178
+                         var emptysec = emptyinit[1];
179
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
180
+
181
+                         if (emptycheck != '') {
182
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
183
+                         }
184
+                     });
185
+
186
+                     $('#selectcalleridbttn').removeClass('icon-loading');
187
+          }
188
+     });
189
+  });
190
+
191
+  // Check the checkbox to send SMS message to multiple recipients
192
+  $('#tomultchckbx').change(function() {
193
+      if ($(this).is(':checked')) {
194
+          $("#multiplerecivers").css("display", "block");
195
+          $("#smstodiv").css("visibility", "hidden");
196
+          $("#smsto").val("");
197
+
198
+          receiversNumbers.length = 0;
199
+
200
+      } else {
201
+          $("#multiplerecivers").css("display", "none");
202
+          $("#smstodiv").css("visibility", "visible");
203
+
204
+          // Remove the uploaded file if any
205
+          $("#induploadfile").remove();
206
+
207
+          receiversNumbers.length = 0;
208
+
209
+          $.ajax({
210
+             url: cleanflUrl + '/' + userid,
211
+             type: "POST",
212
+             data: {userid: userid},
213
+             cache: false,
214
+             processData: false,
215
+             contentType: false
216
+          });
217
+      }
218
+  });
219
+
220
+  // Upload the file with the recipients' phone numbers
221
+  $("#uploadfileforsms").change(function(e) {
222
+
223
+     $("#fileuploadednm").empty();
224
+
225
+     receiversNumbers.length = 0;
226
+
227
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
228
+
229
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
230
+
231
+     var formData = new FormData();
232
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
233
+
234
+     var fileup = $('#uploadfileforsms').val();
235
+     var fileuptrim = fileup.split('\\').pop();
236
+
237
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
238
+
239
+     var extension = fileup.replace(/^.*\./, '');
240
+
241
+     if (extension == fileup) {
242
+         extension = "";
243
+     } else {
244
+         extension = extension.toLowerCase();
245
+     }
246
+
247
+     var validExtensions = ["txt", "csv"];
248
+
249
+     if (jQuery.inArray(extension, validExtensions) != -1) {
250
+
251
+	// Check if the Sender ID is set
252
+	if ($("#currentsmsnmbrs option[value='']").length > 0) {
253
+            var setId = $('#currentsmsnmbrs :selected').val();
254
+	} else { var setId = ''; }
255
+
256
+	if (setId != '') {
257
+
258
+               $.ajax({
259
+                 url: baseUrl + '/' + userid,
260
+                 type: "POST",
261
+                 data: formData,
262
+                 cache: false,
263
+                 processData: false,
264
+                 contentType: false,
265
+                 success: function(numberarray) {
266
+
267
+		    if (numberarray.length > 0) {
268
+
269
+		        // Get the array of the receivers' phone numbers
270
+		        var setIdsplit = setId.split(":");
271
+		        var smsProvider = setIdsplit[0];
272
+
273
+		        if (smsProvider == "Tx") {
274
+
275
+		             for(key in numberarray) {
276
+		                 receiversNumbers.push("+"+numberarray[key]);
277
+		             }
278
+
279
+		        } else if (smsProvider == "Pl") {
280
+
281
+		             for(key in numberarray) {
282
+		                 receiversNumbers.push(numberarray[key]);
283
+		             }
284
+
285
+		          } else if (smsProvider == "Tw") {
286
+
287
+		             for(key in numberarray) {
288
+		                 receiversNumbers.push(numberarray[key]);
289
+		             }
290
+		          }
291
+
292
+		    } else {
293
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
294
+		    }
295
+                            
296
+                    // Preview the uploaded file
297
+                    var smsfilename = e.target.files[0].name;
298
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
299
+
300
+                    var reader = new FileReader();
301
+                    reader.readAsText(e.target.files[0]);
302
+                    reader.onload = function(e) {
303
+                          $("#smstables").empty();
304
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
305
+                    };
306
+
307
+                    $("#smstables").show();
308
+
309
+                    $('#sms_upload_msg').hide();
310
+                    $('#smstables').removeClass('icon-loading');
311
+
312
+                  },
313
+                  error: function(){
314
+                     alert('Error!');
315
+                  }
316
+               });
317
+
318
+        } else {
319
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
320
+               $('#sms_upload_msg').hide();
321
+               $('#smstables').removeClass('icon-loading');
322
+        }
323
+
324
+     } else {
325
+          alert('The file type is not supported ! Supported formats are txt and csv.');
326
+          $('#pf_upload_msg').hide();
327
+          $('#smstables').removeClass('icon-loading');
328
+
329
+          $("#induploadfile").remove();
330
+          $("#sms_upload_msg").hide();
331
+     }
332
+
333
+     //Preview uploaded file when clicked
334
+     $("#indfilediv").on("click", function() {
335
+
336
+          var smsfilename = e.target.files[0].name;
337
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
338
+
339
+          var reader = new FileReader();
340
+          reader.readAsText(e.target.files[0]);
341
+          reader.onload = function(e) {
342
+                  $("#smstables").empty();
343
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
344
+          };
345
+
346
+          $("#smstables").show();
347
+          $('#sms_upload_msg').hide();
348
+          $('#smstables').removeClass('icon-loading');
349
+     });
350
+
351
+     // Remove selected file
352
+     $("#indivflremove").on("click", function() {
353
+
354
+          $("#induploadfile").remove();
355
+          $("#sms_upload_msg").hide();
356
+
357
+          receiversNumbers.length = 0;
358
+
359
+          $.ajax({
360
+             url: cleanflUrl + '/' + userid,
361
+             type: "POST",
362
+             data: {userid: userid},
363
+             cache: false,
364
+             processData: false,
365
+             contentType: false
366
+         });
367
+     });
368
+
369
+  });
370
+
371
+  // Count the characters in the SMS text area
372
+  $("#smstext").on('input', function() {
373
+     $("#char_count").css("display", "inline");
374
+     $(".maxmessagelength").css("display", "inline-block");
375
+
376
+     $("#countchnb").text($(this).val().length);
377
+
378
+     if ($(this).val().length > charcolorthr) {
379
+         $("#char_count").css("color", "#BB2E4B");
380
+     } else {
381
+         $("#char_count").css("color", "#4cbc86;");
382
+     }
383
+  });
384
+
385
+  // Send the SMS message
386
+  $("#submitsms").on("click", function(event) {
387
+
388
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
389
+     $('#smstables,#recSmsTable,#sentSmsTable').addClass('icon-loading');
390
+
391
+     // Check if the Sender ID is set
392
+     if ($("#currentsmsnmbrs option[value='']").length > 0) {
393
+            var selectedid = $('#currentsmsnmbrs :selected').val();
394
+     } else { var selectedid = ''; }
395
+
396
+     if (selectedid != '') { 
397
+
398
+         var sendersplit = selectedid.split(":");
399
+         var providercap = sendersplit[0];
400
+         var provsec = sendersplit[1];
401
+
402
+         if (/[a-zA-Z]/.test(provsec)) {
403
+             var alphanumcheck = true;
404
+         } else { var alphanumcheck = false; }
405
+
406
+         if (providercap == 'Tx' && alphanumcheck == false) {  
407
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
408
+             var selectedsender = "+" + senderproc;
409
+             var providerUsed = "telnyx";
410
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
411
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
412
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
413
+             var providerUsed = "plivo";
414
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
415
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
416
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
417
+             var selectedsender = "+" + senderproc;
418
+             var providerUsed = "twilio";
419
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
420
+         } else if (providercap == 'Fl' && alphanumcheck == false) {  
421
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
422
+             var selectedsender = "+" + senderproc;
423
+             var providerUsed = "flowroute";
424
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
425
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
426
+             var selectedsender = provsec;
427
+             var providerUsed = "telnyx";
428
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
429
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
430
+             var selectedsender = provsec;
431
+             var providerUsed = "plivo";
432
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
433
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
434
+             var selectedsender = provsec;
435
+             var providerUsed = "twilio";
436
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
437
+         } else if (providercap == 'Fl' && alphanumcheck == true) {
438
+             var selectedsender = provsec;
439
+             var providerUsed = "flowroute";
440
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsflow");
441
+         }
442
+
443
+         // Get the interval between SMS consecutive sending requests, if it's the case
444
+         if ($('#tomultchckbx').is(':checked')) {
445
+
446
+             var numbersfile = 1;
447
+             var initinterval = $("#multsmsinterval").val();
448
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
449
+
450
+             if (secinterval != '') {
451
+                 var tertinterval = parseInt(secinterval);
452
+                     waittime = tertinterval;
453
+             }
454
+
455
+         } else {
456
+
457
+             var numbersfile = 0;
458
+             var toNumberinit = $('#smsto').val();
459
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
460
+             var toNumbersec = toNumber.split(",");
461
+
462
+                 for (var i = 0; i < toNumbersec.length; i++) {
463
+                      toNumbersec[i] = "+" + toNumbersec[i];
464
+                 }
465
+
466
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
467
+         }
468
+
469
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
470
+
471
+         var smstext = $("#smstext").val();
472
+
473
+         if (receiversNumbers.length != 0) {
474
+
475
+              if (smstext != '') {
476
+                  $.ajax({
477
+                     url: relbaseUrl + '/' + userid,
478
+                     type: "POST",
479
+                     data: {
480
+                           receiversPhoneNbs: receiversNumbers,
481
+                           fromsender: selectedsender,
482
+                           waitinterval: waittime,
483
+                           sentsmstext: smstext
484
+                         },
485
+                     success: function() {
486
+
487
+                           if (receiversNumbers.length == 1) {
488
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again.");
489
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again."); }
490
+
491
+                           $('#sms_submit_msg').hide();
492
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
493
+                     },
494
+                     error: function(){
495
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
496
+                           $('#sms_submit_msg').hide();
497
+                           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
498
+                     }
499
+                  });
500
+              } else {
501
+                     alert("Please enter a message in the text box !");
502
+                     $('#sms_submit_msg').hide();
503
+                     $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
504
+              }
505
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
506
+                 alert("Please enter the recipient's phone number !");
507
+                 $('#sms_submit_msg').hide();
508
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
509
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
510
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
511
+                 $('#sms_submit_msg').hide();
512
+                 $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
513
+         }
514
+     } else {
515
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
516
+           $('#smstables,#recSmsTable,#sentSmsTable').removeClass('icon-loading');
517
+           $('#sms_submit_msg').hide();
518
+     }
519
+
520
+  });
521
+
522
+  // Check the checkbox to delete old SMS messages from the database
523
+  $('#deleteoldchckbox').change(function() {
524
+     if ($(this).is(':checked')) {
525
+         $("#deleteoldsms").css("display", "block");
526
+     } else {
527
+         $("#deleteoldsms").css("display", "none");
528
+     }
529
+  });
530
+
531
+  $('#tonmbrformat').css('height', $(window).height() - 260);
532
+  $('#setcalleridtp').css('height', $(window).height() - 160);
533
+  $('#uploadfileinfo').css('height', $(window).height() - 390);
534
+
535
+  $(window).resize(function() { 
536
+    $('#tonmbrformat').css('height', $(window).height() - 260);
537
+    $('#setcalleridtp').css('height', $(window).height() - 160);
538
+    $('#uploadfileinfo').css('height', $(window).height() - 390);
539
+  });
540
+
541
+
542
+
543
+
Browse code

deleted CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php templates/navigation/index.php templates/settings.php

DoubleBastionAdmin authored on 18/08/2022 21:08:00
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,518 +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
-  var userid = "<?php p($userId); ?>";
24
-  var telenctype = 'GSM-7';
25
-  var nexenctype = 'text';
26
-  var twilenctype = 'text';
27
-  var charcolorthr = 160;
28
-  var textread = '';
29
-  var providerUsed = '';
30
-  var receiversNumbers = [];
31
-  var waittime = 1000;
32
-
33
-  // Clean the temp_files directory
34
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
35
-
36
-  $.ajax({
37
-          url: cleanflUrl + '/' + userid,
38
-          type: "POST",
39
-          data: { userid: userid },
40
-          cache: false,
41
-          processData: false,
42
-          contentType: false
43
-  });
44
-  
45
-  // Check the available balance
46
-  $("#smsprovider").on("change", function () {
47
-
48
-     var provider = $('#smsprovider :selected').val();
49
-
50
-     if (provider == "Telnyx") {
51
-
52
-        var gettelbalance = function() {
53
-
54
-          $('#currentbalance').addClass('icon-loading');
55
-
56
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
57
-
58
-          $.ajax({
59
-              url: gettelbalanceUrl + '/' + userid,
60
-              type: "POST",
61
-              data: { userid: userid },
62
-              cache: false,
63
-              processData: false,
64
-              contentType: false,
65
-              success: function(currentbalancetel) {
66
-
67
-                     $('#currentbalance').empty();
68
-                     $('#currentbalance').text(currentbalancetel);
69
-                     $('#currentbalance').removeClass('icon-loading');
70
-              }
71
-          });
72
-        }
73
-
74
-        gettelbalance();
75
-
76
-     } else if (provider == "Plivo") {
77
-
78
-          var getnexbalance = function() {
79
-
80
-            $('#currentbalance').addClass('icon-loading');
81
-
82
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
83
-
84
-            $.ajax({
85
-                url: getnexbalanceUrl + '/' + userid,
86
-                type: "POST",
87
-                data: { userid: userid },
88
-                cache: false,
89
-                processData: false,
90
-                contentType: false,
91
-                success: function(currentbalancenex) {
92
-
93
-                     $('#currentbalance').empty();
94
-                     $('#currentbalance').text(currentbalancenex);
95
-                     $('#currentbalance').removeClass('icon-loading');
96
-                }
97
-            });
98
-          }
99
-
100
-          getnexbalance();
101
-
102
-     } else if (provider == "Twilio") {
103
-
104
-          var gettwilbalance = function() {
105
-
106
-            $('#currentbalance').addClass('icon-loading');
107
-
108
-            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
109
-
110
-            $.ajax({
111
-                url: gettwilbalanceUrl + '/' + userid,
112
-                type: "POST",
113
-                data: { userid: userid },
114
-                cache: false,
115
-                processData: false,
116
-                contentType: false,
117
-                success: function(currentbalancetwil) {
118
-
119
-                     $('#currentbalance').empty();
120
-                     $('#currentbalance').text(currentbalancetwil);
121
-                     $('#currentbalance').removeClass('icon-loading');
122
-                }
123
-            });
124
-          }
125
-
126
-          gettwilbalance();
127
-
128
-       } else if (provider == "") {
129
-                $('#currentbalance').text("");
130
-                $('#currentbalance').removeClass('icon-loading');
131
-       }
132
-  });
133
-
134
-  // Select the Sender ID
135
-  $("#selectcalleridbttn").on("click", function(event) {
136
-
137
-     $('#selectcalleridbttn').addClass('icon-loading');
138
-
139
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
140
-
141
-     $.ajax({
142
-          url: getsmsnumbersUrl + '/' + userid,
143
-          type: "POST",
144
-          data: { userid: userid },
145
-          cache: false,
146
-          processData: false,
147
-          contentType: false,
148
-          success: function(currentnmbrs) {
149
-
150
-                     $('#currentsmsnmbrs').empty();
151
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
152
-
153
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
154
-                         var emptyinit = indsmsnmb.split(":");
155
-                         var emptysec = emptyinit[1];
156
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
157
-
158
-                         if (emptycheck != '') {
159
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
160
-                         }
161
-                     });
162
-
163
-                     $('#selectcalleridbttn').removeClass('icon-loading');
164
-          }
165
-     });
166
-  });
167
-
168
-  // Check the checkbox to send SMS message to multiple recipients
169
-  $('#tomultchckbx').change(function() {
170
-      if ($(this).is(':checked')) {
171
-          $("#multiplerecivers").css("display", "block");
172
-          $("#smstodiv").css("visibility", "hidden");
173
-          $("#smsto").val("");
174
-
175
-          receiversNumbers.length = 0;
176
-
177
-      } else {
178
-          $("#multiplerecivers").css("display", "none");
179
-          $("#smstodiv").css("visibility", "visible");
180
-
181
-          // Remove the uploaded file if any
182
-          $("#induploadfile").remove();
183
-
184
-          receiversNumbers.length = 0;
185
-
186
-          $.ajax({
187
-             url: cleanflUrl + '/' + userid,
188
-             type: "POST",
189
-             data: {userid: userid},
190
-             cache: false,
191
-             processData: false,
192
-             contentType: false
193
-          });
194
-      }
195
-  });
196
-
197
-  // Upload the file with the recipients' phone numbers
198
-  $("#uploadfileforsms").change(function(e) {
199
-
200
-     $("#fileuploadednm").empty();
201
-
202
-     receiversNumbers.length = 0;
203
-
204
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
205
-
206
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
207
-
208
-     var formData = new FormData();
209
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
210
-
211
-     var fileup = $('#uploadfileforsms').val();
212
-     var fileuptrim = fileup.split('\\').pop();
213
-
214
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
215
-
216
-     var extension = fileup.replace(/^.*\./, '');
217
-
218
-     if (extension == fileup) {
219
-         extension = "";
220
-     } else {
221
-         extension = extension.toLowerCase();
222
-     }
223
-
224
-     var validExtensions = ["txt", "csv"];
225
-
226
-     if (jQuery.inArray(extension, validExtensions) != -1) {
227
-
228
-	// Check if the Sender ID is set
229
-	if ($("#currentsmsnmbrs option[value='']").length > 0) {
230
-            var setId = $('#currentsmsnmbrs :selected').val();
231
-	} else { var setId = ''; }
232
-
233
-	if (setId != '') {
234
-
235
-               $.ajax({
236
-                 url: baseUrl + '/' + userid,
237
-                 type: "POST",
238
-                 data: formData,
239
-                 cache: false,
240
-                 processData: false,
241
-                 contentType: false,
242
-                 success: function(numberarray) {
243
-
244
-		    if (numberarray.length > 0) {
245
-
246
-		        // Get the array of the receivers' phone numbers
247
-		        var setIdsplit = setId.split(":");
248
-		        var smsProvider = setIdsplit[0];
249
-
250
-		        if (smsProvider == "Tx") {
251
-
252
-		             for(key in numberarray) {
253
-		                 receiversNumbers.push("+"+numberarray[key]);
254
-		             }
255
-
256
-		        } else if (smsProvider == "Pl") {
257
-
258
-		             for(key in numberarray) {
259
-		                 receiversNumbers.push(numberarray[key]);
260
-		             }
261
-
262
-		          } else if (smsProvider == "Tw") {
263
-
264
-		             for(key in numberarray) {
265
-		                 receiversNumbers.push(numberarray[key]);
266
-		             }
267
-		          }
268
-
269
-		    } else {
270
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
271
-		    }
272
-                            
273
-                    // Preview the uploaded file
274
-                    var smsfilename = e.target.files[0].name;
275
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
276
-
277
-                    var reader = new FileReader();
278
-                    reader.readAsText(e.target.files[0]);
279
-                    reader.onload = function(e) {
280
-                          $("#smstables").empty();
281
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
282
-                    };
283
-
284
-                    $("#smstables").show();
285
-
286
-                    $('#sms_upload_msg').hide();
287
-                    $('#smstables').removeClass('icon-loading');
288
-
289
-                  },
290
-                  error: function(){
291
-                     alert('Error!');
292
-                  }
293
-               });
294
-
295
-        } else {
296
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
297
-               $('#sms_upload_msg').hide();
298
-               $('#smstables').removeClass('icon-loading');
299
-        }
300
-
301
-     } else {
302
-          alert('The file type is not supported ! Supported formats are txt and csv.');
303
-          $('#pf_upload_msg').hide();
304
-          $('#faxdocpreview').removeClass('icon-loading');
305
-
306
-          $("#induploadfile").remove();
307
-          $("#sms_upload_msg").hide();
308
-     }
309
-
310
-     //Preview uploaded file when clicked
311
-     $("#indfilediv").on("click", function() {
312
-
313
-          var smsfilename = e.target.files[0].name;
314
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
315
-
316
-          var reader = new FileReader();
317
-          reader.readAsText(e.target.files[0]);
318
-          reader.onload = function(e) {
319
-                  $("#smstables").empty();
320
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
321
-          };
322
-
323
-          $("#smstables").show();
324
-          $('#sms_upload_msg').hide();
325
-          $('#smstables').removeClass('icon-loading');
326
-     });
327
-
328
-     // Remove selected file
329
-     $("#indivflremove").on("click", function() {
330
-
331
-          $("#induploadfile").remove();
332
-          $("#sms_upload_msg").hide();
333
-
334
-          receiversNumbers.length = 0;
335
-
336
-          $.ajax({
337
-             url: cleanflUrl + '/' + userid,
338
-             type: "POST",
339
-             data: {userid: userid},
340
-             cache: false,
341
-             processData: false,
342
-             contentType: false
343
-         });
344
-     });
345
-
346
-  });
347
-
348
-  // Get the SMS encoding type
349
-  $('#unicodechckbx').change(function() {
350
-     if ($(this).is(':checked')) {
351
-           telenctype = 'UCS-2';
352
-           nexenctype = 'UCS-2';
353
-           twilenctype = 'UCS-2';
354
-           charcolorthr = 70;
355
-     } else {
356
-           telenctype = 'GSM-7';
357
-           nexenctype = 'GSM-7';
358
-           twilenctype = 'GSM-7';
359
-           charcolorthr = 160;
360
-     }
361
-  });
362
-
363
-  // Count the characters in the SMS text area
364
-  $("#smstext").on('input', function() {
365
-     $("#char_count").css("display", "inline");
366
-     $(".maxmessagelength").css("display", "inline-block");
367
-
368
-     $("#countchnb").text($(this).val().length);
369
-
370
-     if ($(this).val().length > charcolorthr) {
371
-         $("#char_count").css("color", "#BB2E4B");
372
-     } else {
373
-         $("#char_count").css("color", "#4cbc86;");
374
-     }
375
-  });
376
-
377
-  // Send the SMS message
378
-  $("#submitsms").on("click", function(event) {
379
-
380
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
381
-     $('#smstables').addClass('icon-loading');
382
-
383
-     // Check if the Sender ID is set
384
-     if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
-            var selectedid = $('#currentsmsnmbrs :selected').val();
386
-     } else { var selectedid = ''; }
387
-
388
-     if (selectedid != '') { 
389
-
390
-         var sendersplit = selectedid.split(":");
391
-         var providercap = sendersplit[0];
392
-         var provsec = sendersplit[1];
393
-
394
-         if (/[a-zA-Z]/.test(provsec)) {
395
-             var alphanumcheck = true;
396
-         } else { var alphanumcheck = false; }
397
-
398
-         if (providercap == 'Tx' && alphanumcheck == false) {  
399
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
400
-             var selectedsender = "+" + senderproc;
401
-             var providerUsed = "telnyx";
402
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
403
-             var enctype = telenctype;
404
-         } else if (providercap == 'Pl' && alphanumcheck == false) {
405
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
406
-             var providerUsed = "plivo";
407
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
408
-             var enctype = nexenctype;
409
-         } else if (providercap == 'Tw' && alphanumcheck == false) {  
410
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
411
-             var selectedsender = "+" + senderproc;
412
-             var providerUsed = "twilio";
413
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
414
-             var enctype = twilenctype;
415
-         } else if (providercap == 'Tx' && alphanumcheck == true) {
416
-             var selectedsender = provsec;
417
-             var providerUsed = "telnyx";
418
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
419
-             var enctype = telenctype;
420
-         } else if (providercap == 'Pl' && alphanumcheck == true) {
421
-             var selectedsender = provsec;
422
-             var providerUsed = "plivo";
423
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
424
-             var enctype = nexenctype;
425
-         } else if (providercap == 'Tw' && alphanumcheck == true) {
426
-             var selectedsender = provsec;
427
-             var providerUsed = "twilio";
428
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
429
-             var enctype = twilenctype;
430
-         }
431
-
432
-         // Get the interval between SMS consecutive sending requests, if it's the case
433
-         if ($('#tomultchckbx').is(':checked')) {
434
-
435
-             var numbersfile = 1;
436
-             var initinterval = $("#multsmsinterval").val();
437
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
438
-
439
-             if (secinterval != '') {
440
-                 var tertinterval = parseInt(secinterval);
441
-                     waittime = tertinterval;
442
-             }
443
-
444
-         } else {
445
-
446
-             var numbersfile = 0;
447
-             var toNumberinit = $('#smsto').val();
448
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
449
-             var toNumbersec = toNumber.split(",");
450
-
451
-                 for (var i = 0; i < toNumbersec.length; i++) {
452
-                      toNumbersec[i] = "+" + toNumbersec[i];
453
-                 }
454
-
455
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
456
-         }
457
-
458
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
459
-
460
-         var smstext = $("#smstext").val();
461
-
462
-         if (receiversNumbers.length != 0) {
463
-
464
-              if (smstext != '') {
465
-                  $.ajax({
466
-                     url: relbaseUrl + '/' + userid,
467
-                     type: "POST",
468
-                     data: {
469
-                           receiversPhoneNbs: receiversNumbers,
470
-                           fromsender: selectedsender,
471
-                           waitinterval: waittime,
472
-                           encoding: enctype,
473
-                           sentsmstext: smstext
474
-                         },
475
-                     success: function() {
476
-
477
-                           if (receiversNumbers.length == 1) {
478
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again.");
479
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again."); }
480
-
481
-                           $('#sms_submit_msg').hide();
482
-                           $('#smstables').removeClass('icon-loading');
483
-                     },
484
-                     error: function(){
485
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
486
-                           $('#sms_submit_msg').hide();
487
-                           $('#smstables').removeClass('icon-loading');
488
-                     }
489
-                  });
490
-              } else {
491
-                     alert("Please enter a message in the text box !");
492
-                     $('#sms_submit_msg').hide();
493
-                     $('#smstables').removeClass('icon-loading');
494
-              }
495
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
496
-                 alert("Please enter the recipient's phone number !");
497
-                 $('#sms_submit_msg').hide();
498
-                 $('#smstables').removeClass('icon-loading');
499
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
500
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
501
-                 $('#sms_submit_msg').hide();
502
-                 $('#smstables').removeClass('icon-loading');
503
-         }
504
-     } else {
505
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
506
-           $('#smstables').removeClass('icon-loading');
507
-           $('#sms_submit_msg').hide();
508
-     }
509
-  });
510
-
511
-  // Check the checkbox to delete old SMS messages from the database
512
-  $('#deleteoldchckbox').change(function() {
513
-     if ($(this).is(':checked')) {
514
-         $("#deleteoldsms").css("display", "block");
515
-     } else {
516
-         $("#deleteoldsms").css("display", "none");
517
-     }
518
-  });
Browse code

added CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css js/sendsms.js js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php img/sms_relentless_screenshot.png lib/Migration/Version106Date20220813144231.php

DoubleBastionAdmin authored on 13/08/2022 12:43:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,518 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var telenctype = 'GSM-7';
25
+  var nexenctype = 'text';
26
+  var twilenctype = 'text';
27
+  var charcolorthr = 160;
28
+  var textread = '';
29
+  var providerUsed = '';
30
+  var receiversNumbers = [];
31
+  var waittime = 1000;
32
+
33
+  // Clean the temp_files directory
34
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
35
+
36
+  $.ajax({
37
+          url: cleanflUrl + '/' + userid,
38
+          type: "POST",
39
+          data: { userid: userid },
40
+          cache: false,
41
+          processData: false,
42
+          contentType: false
43
+  });
44
+  
45
+  // Check the available balance
46
+  $("#smsprovider").on("change", function () {
47
+
48
+     var provider = $('#smsprovider :selected').val();
49
+
50
+     if (provider == "Telnyx") {
51
+
52
+        var gettelbalance = function() {
53
+
54
+          $('#currentbalance').addClass('icon-loading');
55
+
56
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
57
+
58
+          $.ajax({
59
+              url: gettelbalanceUrl + '/' + userid,
60
+              type: "POST",
61
+              data: { userid: userid },
62
+              cache: false,
63
+              processData: false,
64
+              contentType: false,
65
+              success: function(currentbalancetel) {
66
+
67
+                     $('#currentbalance').empty();
68
+                     $('#currentbalance').text(currentbalancetel);
69
+                     $('#currentbalance').removeClass('icon-loading');
70
+              }
71
+          });
72
+        }
73
+
74
+        gettelbalance();
75
+
76
+     } else if (provider == "Plivo") {
77
+
78
+          var getnexbalance = function() {
79
+
80
+            $('#currentbalance').addClass('icon-loading');
81
+
82
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
83
+
84
+            $.ajax({
85
+                url: getnexbalanceUrl + '/' + userid,
86
+                type: "POST",
87
+                data: { userid: userid },
88
+                cache: false,
89
+                processData: false,
90
+                contentType: false,
91
+                success: function(currentbalancenex) {
92
+
93
+                     $('#currentbalance').empty();
94
+                     $('#currentbalance').text(currentbalancenex);
95
+                     $('#currentbalance').removeClass('icon-loading');
96
+                }
97
+            });
98
+          }
99
+
100
+          getnexbalance();
101
+
102
+     } else if (provider == "Twilio") {
103
+
104
+          var gettwilbalance = function() {
105
+
106
+            $('#currentbalance').addClass('icon-loading');
107
+
108
+            var gettwilbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetwil");
109
+
110
+            $.ajax({
111
+                url: gettwilbalanceUrl + '/' + userid,
112
+                type: "POST",
113
+                data: { userid: userid },
114
+                cache: false,
115
+                processData: false,
116
+                contentType: false,
117
+                success: function(currentbalancetwil) {
118
+
119
+                     $('#currentbalance').empty();
120
+                     $('#currentbalance').text(currentbalancetwil);
121
+                     $('#currentbalance').removeClass('icon-loading');
122
+                }
123
+            });
124
+          }
125
+
126
+          gettwilbalance();
127
+
128
+       } else if (provider == "") {
129
+                $('#currentbalance').text("");
130
+                $('#currentbalance').removeClass('icon-loading');
131
+       }
132
+  });
133
+
134
+  // Select the Sender ID
135
+  $("#selectcalleridbttn").on("click", function(event) {
136
+
137
+     $('#selectcalleridbttn').addClass('icon-loading');
138
+
139
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
140
+
141
+     $.ajax({
142
+          url: getsmsnumbersUrl + '/' + userid,
143
+          type: "POST",
144
+          data: { userid: userid },
145
+          cache: false,
146
+          processData: false,
147
+          contentType: false,
148
+          success: function(currentnmbrs) {
149
+
150
+                     $('#currentsmsnmbrs').empty();
151
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
152
+
153
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
154
+                         var emptyinit = indsmsnmb.split(":");
155
+                         var emptysec = emptyinit[1];
156
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
157
+
158
+                         if (emptycheck != '') {
159
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
160
+                         }
161
+                     });
162
+
163
+                     $('#selectcalleridbttn').removeClass('icon-loading');
164
+          }
165
+     });
166
+  });
167
+
168
+  // Check the checkbox to send SMS message to multiple recipients
169
+  $('#tomultchckbx').change(function() {
170
+      if ($(this).is(':checked')) {
171
+          $("#multiplerecivers").css("display", "block");
172
+          $("#smstodiv").css("visibility", "hidden");
173
+          $("#smsto").val("");
174
+
175
+          receiversNumbers.length = 0;
176
+
177
+      } else {
178
+          $("#multiplerecivers").css("display", "none");
179
+          $("#smstodiv").css("visibility", "visible");
180
+
181
+          // Remove the uploaded file if any
182
+          $("#induploadfile").remove();
183
+
184
+          receiversNumbers.length = 0;
185
+
186
+          $.ajax({
187
+             url: cleanflUrl + '/' + userid,
188
+             type: "POST",
189
+             data: {userid: userid},
190
+             cache: false,
191
+             processData: false,
192
+             contentType: false
193
+          });
194
+      }
195
+  });
196
+
197
+  // Upload the file with the recipients' phone numbers
198
+  $("#uploadfileforsms").change(function(e) {
199
+
200
+     $("#fileuploadednm").empty();
201
+
202
+     receiversNumbers.length = 0;
203
+
204
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
205
+
206
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
207
+
208
+     var formData = new FormData();
209
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
210
+
211
+     var fileup = $('#uploadfileforsms').val();
212
+     var fileuptrim = fileup.split('\\').pop();
213
+
214
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
215
+
216
+     var extension = fileup.replace(/^.*\./, '');
217
+
218
+     if (extension == fileup) {
219
+         extension = "";
220
+     } else {
221
+         extension = extension.toLowerCase();
222
+     }
223
+
224
+     var validExtensions = ["txt", "csv"];
225
+
226
+     if (jQuery.inArray(extension, validExtensions) != -1) {
227
+
228
+	// Check if the Sender ID is set
229
+	if ($("#currentsmsnmbrs option[value='']").length > 0) {
230
+            var setId = $('#currentsmsnmbrs :selected').val();
231
+	} else { var setId = ''; }
232
+
233
+	if (setId != '') {
234
+
235
+               $.ajax({
236
+                 url: baseUrl + '/' + userid,
237
+                 type: "POST",
238
+                 data: formData,
239
+                 cache: false,
240
+                 processData: false,
241
+                 contentType: false,
242
+                 success: function(numberarray) {
243
+
244
+		    if (numberarray.length > 0) {
245
+
246
+		        // Get the array of the receivers' phone numbers
247
+		        var setIdsplit = setId.split(":");
248
+		        var smsProvider = setIdsplit[0];
249
+
250
+		        if (smsProvider == "Tx") {
251
+
252
+		             for(key in numberarray) {
253
+		                 receiversNumbers.push("+"+numberarray[key]);
254
+		             }
255
+
256
+		        } else if (smsProvider == "Pl") {
257
+
258
+		             for(key in numberarray) {
259
+		                 receiversNumbers.push(numberarray[key]);
260
+		             }
261
+
262
+		          } else if (smsProvider == "Tw") {
263
+
264
+		             for(key in numberarray) {
265
+		                 receiversNumbers.push(numberarray[key]);
266
+		             }
267
+		          }
268
+
269
+		    } else {
270
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
271
+		    }
272
+                            
273
+                    // Preview the uploaded file
274
+                    var smsfilename = e.target.files[0].name;
275
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
276
+
277
+                    var reader = new FileReader();
278
+                    reader.readAsText(e.target.files[0]);
279
+                    reader.onload = function(e) {
280
+                          $("#smstables").empty();
281
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
282
+                    };
283
+
284
+                    $("#smstables").show();
285
+
286
+                    $('#sms_upload_msg').hide();
287
+                    $('#smstables').removeClass('icon-loading');
288
+
289
+                  },
290
+                  error: function(){
291
+                     alert('Error!');
292
+                  }
293
+               });
294
+
295
+        } else {
296
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
297
+               $('#sms_upload_msg').hide();
298
+               $('#smstables').removeClass('icon-loading');
299
+        }
300
+
301
+     } else {
302
+          alert('The file type is not supported ! Supported formats are txt and csv.');
303
+          $('#pf_upload_msg').hide();
304
+          $('#faxdocpreview').removeClass('icon-loading');
305
+
306
+          $("#induploadfile").remove();
307
+          $("#sms_upload_msg").hide();
308
+     }
309
+
310
+     //Preview uploaded file when clicked
311
+     $("#indfilediv").on("click", function() {
312
+
313
+          var smsfilename = e.target.files[0].name;
314
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
315
+
316
+          var reader = new FileReader();
317
+          reader.readAsText(e.target.files[0]);
318
+          reader.onload = function(e) {
319
+                  $("#smstables").empty();
320
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
321
+          };
322
+
323
+          $("#smstables").show();
324
+          $('#sms_upload_msg').hide();
325
+          $('#smstables').removeClass('icon-loading');
326
+     });
327
+
328
+     // Remove selected file
329
+     $("#indivflremove").on("click", function() {
330
+
331
+          $("#induploadfile").remove();
332
+          $("#sms_upload_msg").hide();
333
+
334
+          receiversNumbers.length = 0;
335
+
336
+          $.ajax({
337
+             url: cleanflUrl + '/' + userid,
338
+             type: "POST",
339
+             data: {userid: userid},
340
+             cache: false,
341
+             processData: false,
342
+             contentType: false
343
+         });
344
+     });
345
+
346
+  });
347
+
348
+  // Get the SMS encoding type
349
+  $('#unicodechckbx').change(function() {
350
+     if ($(this).is(':checked')) {
351
+           telenctype = 'UCS-2';
352
+           nexenctype = 'UCS-2';
353
+           twilenctype = 'UCS-2';
354
+           charcolorthr = 70;
355
+     } else {
356
+           telenctype = 'GSM-7';
357
+           nexenctype = 'GSM-7';
358
+           twilenctype = 'GSM-7';
359
+           charcolorthr = 160;
360
+     }
361
+  });
362
+
363
+  // Count the characters in the SMS text area
364
+  $("#smstext").on('input', function() {
365
+     $("#char_count").css("display", "inline");
366
+     $(".maxmessagelength").css("display", "inline-block");
367
+
368
+     $("#countchnb").text($(this).val().length);
369
+
370
+     if ($(this).val().length > charcolorthr) {
371
+         $("#char_count").css("color", "#BB2E4B");
372
+     } else {
373
+         $("#char_count").css("color", "#4cbc86;");
374
+     }
375
+  });
376
+
377
+  // Send the SMS message
378
+  $("#submitsms").on("click", function(event) {
379
+
380
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
381
+     $('#smstables').addClass('icon-loading');
382
+
383
+     // Check if the Sender ID is set
384
+     if ($("#currentsmsnmbrs option[value='']").length > 0) {
385
+            var selectedid = $('#currentsmsnmbrs :selected').val();
386
+     } else { var selectedid = ''; }
387
+
388
+     if (selectedid != '') { 
389
+
390
+         var sendersplit = selectedid.split(":");
391
+         var providercap = sendersplit[0];
392
+         var provsec = sendersplit[1];
393
+
394
+         if (/[a-zA-Z]/.test(provsec)) {
395
+             var alphanumcheck = true;
396
+         } else { var alphanumcheck = false; }
397
+
398
+         if (providercap == 'Tx' && alphanumcheck == false) {  
399
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
400
+             var selectedsender = "+" + senderproc;
401
+             var providerUsed = "telnyx";
402
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
403
+             var enctype = telenctype;
404
+         } else if (providercap == 'Pl' && alphanumcheck == false) {
405
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
406
+             var providerUsed = "plivo";
407
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
408
+             var enctype = nexenctype;
409
+         } else if (providercap == 'Tw' && alphanumcheck == false) {  
410
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
411
+             var selectedsender = "+" + senderproc;
412
+             var providerUsed = "twilio";
413
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
414
+             var enctype = twilenctype;
415
+         } else if (providercap == 'Tx' && alphanumcheck == true) {
416
+             var selectedsender = provsec;
417
+             var providerUsed = "telnyx";
418
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
419
+             var enctype = telenctype;
420
+         } else if (providercap == 'Pl' && alphanumcheck == true) {
421
+             var selectedsender = provsec;
422
+             var providerUsed = "plivo";
423
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
424
+             var enctype = nexenctype;
425
+         } else if (providercap == 'Tw' && alphanumcheck == true) {
426
+             var selectedsender = provsec;
427
+             var providerUsed = "twilio";
428
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstwil");
429
+             var enctype = twilenctype;
430
+         }
431
+
432
+         // Get the interval between SMS consecutive sending requests, if it's the case
433
+         if ($('#tomultchckbx').is(':checked')) {
434
+
435
+             var numbersfile = 1;
436
+             var initinterval = $("#multsmsinterval").val();
437
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
438
+
439
+             if (secinterval != '') {
440
+                 var tertinterval = parseInt(secinterval);
441
+                     waittime = tertinterval;
442
+             }
443
+
444
+         } else {
445
+
446
+             var numbersfile = 0;
447
+             var toNumberinit = $('#smsto').val();
448
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
449
+             var toNumbersec = toNumber.split(",");
450
+
451
+                 for (var i = 0; i < toNumbersec.length; i++) {
452
+                      toNumbersec[i] = "+" + toNumbersec[i];
453
+                 }
454
+
455
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
456
+         }
457
+
458
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
459
+
460
+         var smstext = $("#smstext").val();
461
+
462
+         if (receiversNumbers.length != 0) {
463
+
464
+              if (smstext != '') {
465
+                  $.ajax({
466
+                     url: relbaseUrl + '/' + userid,
467
+                     type: "POST",
468
+                     data: {
469
+                           receiversPhoneNbs: receiversNumbers,
470
+                           fromsender: selectedsender,
471
+                           waitinterval: waittime,
472
+                           encoding: enctype,
473
+                           sentsmstext: smstext
474
+                         },
475
+                     success: function() {
476
+
477
+                           if (receiversNumbers.length == 1) {
478
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for this message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again.");
479
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the current status and the delivery receipt for each message. If they don't appear immediately, wait about 10 seconds and press the 'Sent SMS Messages' button again."); }
480
+
481
+                           $('#sms_submit_msg').hide();
482
+                           $('#smstables').removeClass('icon-loading');
483
+                     },
484
+                     error: function(){
485
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
486
+                           $('#sms_submit_msg').hide();
487
+                           $('#smstables').removeClass('icon-loading');
488
+                     }
489
+                  });
490
+              } else {
491
+                     alert("Please enter a message in the text box !");
492
+                     $('#sms_submit_msg').hide();
493
+                     $('#smstables').removeClass('icon-loading');
494
+              }
495
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
496
+                 alert("Please enter the recipient's phone number !");
497
+                 $('#sms_submit_msg').hide();
498
+                 $('#smstables').removeClass('icon-loading');
499
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
500
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
501
+                 $('#sms_submit_msg').hide();
502
+                 $('#smstables').removeClass('icon-loading');
503
+         }
504
+     } else {
505
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
506
+           $('#smstables').removeClass('icon-loading');
507
+           $('#sms_submit_msg').hide();
508
+     }
509
+  });
510
+
511
+  // Check the checkbox to delete old SMS messages from the database
512
+  $('#deleteoldchckbox').change(function() {
513
+     if ($(this).is(':checked')) {
514
+         $("#deleteoldsms").css("display", "block");
515
+     } else {
516
+         $("#deleteoldsms").css("display", "none");
517
+     }
518
+  });
Browse code

removed CHANGELOG.txt README.md appinfo/info.xml appinfo/routes.php appinfo/signature.json css/style.css lib/js/sendsms.js lib/js/settings.js lib/AppInfo/Application.php lib/Controller/AuthorApiController.php lib/Controller/SmsrelentlessController.php lib/Service/SmsrelentlessService.php img/sms_relentless_screenshot.png

DoubleBastionAdmin authored on 13/08/2022 12:33:36
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,472 +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
-  var userid = "<?php p($userId); ?>";
24
-  var telenctype = 'GSM-7';
25
-  var nexenctype = 'text';
26
-  var charcolorthr = 160;
27
-  var textread = '';
28
-  var providerUsed = '';
29
-  var receiversNumbers = [];
30
-  var waittime = 1000;
31
-
32
-  // Clean the temp_files directory
33
-  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
34
-
35
-  $.ajax({
36
-          url: cleanflUrl + '/' + userid,
37
-          type: "POST",
38
-          data: { userid: userid },
39
-          cache: false,
40
-          processData: false,
41
-          contentType: false
42
-  });
43
-  
44
-  // Check the available balance
45
-  $("#smsprovider").on("change", function () {
46
-
47
-     var provider = $('#smsprovider :selected').val();
48
-
49
-     if (provider == "Telnyx") {
50
-
51
-        var gettelbalance = function() {
52
-
53
-          $('#currentbalance').addClass('icon-loading');
54
-
55
-          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
56
-
57
-          $.ajax({
58
-              url: gettelbalanceUrl + '/' + userid,
59
-              type: "POST",
60
-              data: { userid: userid },
61
-              cache: false,
62
-              processData: false,
63
-              contentType: false,
64
-              success: function(currentbalancetel) {
65
-
66
-                     $('#currentbalance').empty();
67
-                     $('#currentbalance').text(currentbalancetel);
68
-                     $('#currentbalance').removeClass('icon-loading');
69
-              }
70
-          });
71
-        }
72
-
73
-        gettelbalance();
74
-
75
-     } else if (provider == "Plivo") {
76
-
77
-          var getnexbalance = function() {
78
-
79
-            $('#currentbalance').addClass('icon-loading');
80
-
81
-            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
82
-
83
-            $.ajax({
84
-                url: getnexbalanceUrl + '/' + userid,
85
-                type: "POST",
86
-                data: { userid: userid },
87
-                cache: false,
88
-                processData: false,
89
-                contentType: false,
90
-                success: function(currentbalancenex) {
91
-
92
-                     $('#currentbalance').empty();
93
-                     $('#currentbalance').text(currentbalancenex);
94
-                     $('#currentbalance').removeClass('icon-loading');
95
-                }
96
-            });
97
-          }
98
-
99
-          getnexbalance();
100
-
101
-       } else if (provider == "") {
102
-                $('#currentbalance').text("");
103
-                $('#currentbalance').removeClass('icon-loading');
104
-       }
105
-  });
106
-
107
-  // Select the Sender ID
108
-  $("#selectcalleridbttn").on("click", function(event) {
109
-
110
-     $('#selectcalleridbttn').addClass('icon-loading');
111
-
112
-     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
113
-
114
-     $.ajax({
115
-          url: getsmsnumbersUrl + '/' + userid,
116
-          type: "POST",
117
-          data: { userid: userid },
118
-          cache: false,
119
-          processData: false,
120
-          contentType: false,
121
-          success: function(currentnmbrs) {
122
-
123
-                     $('#currentsmsnmbrs').empty();
124
-                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
125
-
126
-                     $.each(currentnmbrs, function(key, indsmsnmb) {
127
-                         var emptyinit = indsmsnmb.split(":");
128
-                         var emptysec = emptyinit[1];
129
-                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
130
-
131
-                         if (emptycheck != '') {
132
-                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
133
-                         }
134
-                     });
135
-
136
-                     $('#selectcalleridbttn').removeClass('icon-loading');
137
-          }
138
-     });
139
-  });
140
-
141
-  // Check the checkbox to send SMS message to multiple recipients
142
-  $('#tomultchckbx').change(function() {
143
-      if ($(this).is(':checked')) {
144
-          $("#multiplerecivers").css("display", "block");
145
-          $("#smstodiv").css("visibility", "hidden");
146
-          $("#smsto").val("");
147
-
148
-          receiversNumbers.length = 0;
149
-
150
-      } else {
151
-          $("#multiplerecivers").css("display", "none");
152
-          $("#smstodiv").css("visibility", "visible");
153
-
154
-          // Remove the uploaded file if any
155
-          $("#induploadfile").remove();
156
-
157
-          receiversNumbers.length = 0;
158
-
159
-          $.ajax({
160
-             url: cleanflUrl + '/' + userid,
161
-             type: "POST",
162
-             data: {userid: userid},
163
-             cache: false,
164
-             processData: false,
165
-             contentType: false
166
-          });
167
-      }
168
-  });
169
-
170
-  // Upload the file with the recipients' phone numbers
171
-  $("#uploadfileforsms").change(function(e) {
172
-
173
-     $("#fileuploadednm").empty();
174
-
175
-     receiversNumbers.length = 0;
176
-
177
-     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
178
-
179
-     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
180
-
181
-     var formData = new FormData();
182
-     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
183
-
184
-     var fileup = $('#uploadfileforsms').val();
185
-     var fileuptrim = fileup.split('\\').pop();
186
-
187
-     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
188
-
189
-     var extension = fileup.replace(/^.*\./, '');
190
-
191
-     if (extension == fileup) {
192
-         extension = "";
193
-     } else {
194
-         extension = extension.toLowerCase();
195
-     }
196
-
197
-     var validExtensions = ["txt", "csv"];
198
-
199
-     if (jQuery.inArray(extension, validExtensions) != -1) {
200
-
201
-	// Check if the Sender ID is set
202
-	if ($("#currentsmsnmbrs option[value='']").length > 0) {
203
-            var setId = $('#currentsmsnmbrs :selected').val();
204
-	} else { var setId = ''; }
205
-
206
-	if (setId != '') {
207
-
208
-               $.ajax({
209
-                 url: baseUrl + '/' + userid,
210
-                 type: "POST",
211
-                 data: formData,
212
-                 cache: false,
213
-                 processData: false,
214
-                 contentType: false,
215
-                 success: function(numberarray) {
216
-
217
-		    if (numberarray.length > 0) {
218
-
219
-		        // Get the array of the receivers' phone numbers
220
-		        var setIdsplit = setId.split(":");
221
-		        var smsProvider = setIdsplit[0];
222
-
223
-		        if (smsProvider == "T") {
224
-
225
-		             for(key in numberarray) {
226
-		                 receiversNumbers.push("+"+numberarray[key]);
227
-		             }
228
-
229
-		        } else if (smsProvider == "P") {
230
-
231
-		             for(key in numberarray) {
232
-		                 receiversNumbers.push(numberarray[key]);
233
-		             }
234
-		          }
235
-
236
-		    } else {
237
-		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
238
-		    }
239
-                            
240
-                    // Preview the uploaded file
241
-                    var smsfilename = e.target.files[0].name;
242
-                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
243
-
244
-                    var reader = new FileReader();
245
-                    reader.readAsText(e.target.files[0]);
246
-                    reader.onload = function(e) {
247
-                          $("#smstables").empty();
248
-                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
249
-                    };
250
-
251
-                    $("#smstables").show();
252
-
253
-                    $('#sms_upload_msg').hide();
254
-                    $('#smstables').removeClass('icon-loading');
255
-
256
-                  },
257
-                  error: function(){
258
-                     alert('Error!');
259
-                  }
260
-               });
261
-
262
-        } else {
263
-               alert("Please choose a Sender ID from the Set ID drop-down list!");
264
-               $('#sms_upload_msg').hide();
265
-               $('#smstables').removeClass('icon-loading');
266
-        }
267
-
268
-     } else {
269
-          alert('The file type is not supported ! Supported formats are txt and csv.');
270
-          $('#pf_upload_msg').hide();
271
-          $('#faxdocpreview').removeClass('icon-loading');
272
-
273
-          $("#induploadfile").remove();
274
-          $("#sms_upload_msg").hide();
275
-     }
276
-
277
-     //Preview uploaded file when clicked
278
-     $("#indfilediv").on("click", function() {
279
-
280
-          var smsfilename = e.target.files[0].name;
281
-          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
282
-
283
-          var reader = new FileReader();
284
-          reader.readAsText(e.target.files[0]);
285
-          reader.onload = function(e) {
286
-                  $("#smstables").empty();
287
-                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
288
-          };
289
-
290
-          $("#smstables").show();
291
-          $('#sms_upload_msg').hide();
292
-          $('#smstables').removeClass('icon-loading');
293
-     });
294
-
295
-     // Remove selected file
296
-     $("#indivflremove").on("click", function() {
297
-
298
-          $("#induploadfile").remove();
299
-          $("#sms_upload_msg").hide();
300
-
301
-          receiversNumbers.length = 0;
302
-
303
-          $.ajax({
304
-             url: cleanflUrl + '/' + userid,
305
-             type: "POST",
306
-             data: {userid: userid},
307
-             cache: false,
308
-             processData: false,
309
-             contentType: false
310
-         });
311
-     });
312
-
313
-  });
314
-
315
-  // Get the SMS encoding type
316
-  $('#unicodechckbx').change(function() {
317
-     if ($(this).is(':checked')) {
318
-           telenctype = 'UCS-2';
319
-           nexenctype = 'UCS-2';
320
-           charcolorthr = 70;
321
-     } else {
322
-           telenctype = 'GSM-7';
323
-           nexenctype = 'GSM-7';
324
-           charcolorthr = 160;
325
-     }
326
-  });
327
-
328
-  // Count the characters in the SMS text area
329
-  $("#smstext").on('input', function() {
330
-     $("#char_count").css("display", "inline");
331
-     $(".maxmessagelength").css("display", "inline-block");
332
-
333
-     $("#countchnb").text($(this).val().length);
334
-
335
-     if ($(this).val().length > charcolorthr) {
336
-         $("#char_count").css("color", "#BB2E4B");
337
-     } else {
338
-         $("#char_count").css("color", "#4cbc86;");
339
-     }
340
-  });
341
-
342
-  // Send the SMS message
343
-  $("#submitsms").on("click", function(event) {
344
-
345
-     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
346
-     $('#smstables').addClass('icon-loading');
347
-
348
-     // Check if the Sender ID is set
349
-     if ($("#currentsmsnmbrs option[value='']").length > 0) {
350
-            var selectedid = $('#currentsmsnmbrs :selected').val();
351
-     } else { var selectedid = ''; }
352
-
353
-     if (selectedid != '') { 
354
-
355
-         var sendersplit = selectedid.split(":");
356
-         var providercap = sendersplit[0];
357
-         var provsec = sendersplit[1];
358
-
359
-         if (/[a-zA-Z]/.test(provsec)) {
360
-             var alphanumcheck = true;
361
-         } else { var alphanumcheck = false; }
362
-
363
-         if (providercap == 'T' && alphanumcheck == false) {  
364
-             var senderproc = selectedid.replace(/[^0-9]/g, "");
365
-             var selectedsender = "+" + senderproc;
366
-             var providerUsed = "telnyx";
367
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
368
-             var enctype = telenctype;
369
-         } else if (providercap == 'P' && alphanumcheck == false) {
370
-             var selectedsender = selectedid.replace(/[^0-9]/g, "");
371
-             var providerUsed = "plivo";
372
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
373
-             var enctype = nexenctype;
374
-         } else if (providercap == 'T' && alphanumcheck == true) {
375
-             var selectedsender = provsec;
376
-             var providerUsed = "telnyx";
377
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
378
-             var enctype = telenctype;
379
-         } else if (providercap == 'P' && alphanumcheck == true) {
380
-             var selectedsender = provsec;
381
-             var providerUsed = "plivo";
382
-             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
383
-             var enctype = nexenctype;
384
-         }
385
-
386
-         // Get the interval between SMS consecutive sending requests, if it's the case
387
-         if ($('#tomultchckbx').is(':checked')) {
388
-
389
-             var numbersfile = 1;
390
-             var initinterval = $("#multsmsinterval").val();
391
-             var secinterval = initinterval.replace(/[^0-9]/g, "");
392
-
393
-             if (secinterval != '') {
394
-                 var tertinterval = parseInt(secinterval);
395
-                     waittime = tertinterval;
396
-             }
397
-
398
-         } else {
399
-
400
-             var numbersfile = 0;
401
-             var toNumberinit = $('#smsto').val();
402
-             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
403
-             var toNumbersec = toNumber.split(",");
404
-
405
-                 for (var i = 0; i < toNumbersec.length; i++) {
406
-                      toNumbersec[i] = "+" + toNumbersec[i];
407
-                 }
408
-
409
-                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
410
-         }
411
-
412
-         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
413
-
414
-         var smstext = $("#smstext").val();
415
-
416
-         if (receiversNumbers.length != 0) {
417
-
418
-              if (smstext != '') {
419
-                  $.ajax({
420
-                     url: relbaseUrl + '/' + userid,
421
-                     type: "POST",
422
-                     data: {
423
-                           receiversPhoneNbs: receiversNumbers,
424
-                           fromsender: selectedsender,
425
-                           waitinterval: waittime,
426
-                           encoding: enctype,
427
-                           sentsmstext: smstext
428
-                         },
429
-                     success: function() {
430
-
431
-                           if (receiversNumbers.length == 1) {
432
-                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the actual status and the delivery receit for this message. Please note that the price and the delivery receipt for the message that has just been sent will not be available immediately. Wait about 30 seconds, then check again.");
433
-                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the actual status and the delivery receit for each message. Please note that the price and the delivery receipt for each message will not be available immediately. Wait about 30 seconds, then check again."); }
434
-
435
-                           $('#sms_submit_msg').hide();
436
-                           $('#smstables').removeClass('icon-loading');
437
-                     },
438
-                     error: function(){
439
-                           alert("An error occurred! Please check the recipient's phone number and your settings !");
440
-                           $('#sms_submit_msg').hide();
441
-                           $('#smstables').removeClass('icon-loading');
442
-                     }
443
-                  });
444
-              } else {
445
-                     alert("Please enter a message in the text box !");
446
-                     $('#sms_submit_msg').hide();
447
-                     $('#smstables').removeClass('icon-loading');
448
-              }
449
-         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
450
-                 alert("Please enter the recipient's phone number !");
451
-                 $('#sms_submit_msg').hide();
452
-                 $('#smstables').removeClass('icon-loading');
453
-         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
454
-                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
455
-                 $('#sms_submit_msg').hide();
456
-                 $('#smstables').removeClass('icon-loading');
457
-         }
458
-     } else {
459
-           alert("Please choose a Sender ID from the Set ID drop-down list !");
460
-           $('#smstables').removeClass('icon-loading');
461
-           $('#sms_submit_msg').hide();
462
-     }
463
-  });
464
-
465
-  // Check the checkbox to delete old SMS messages from the database
466
-  $('#deleteoldchckbox').change(function() {
467
-     if ($(this).is(':checked')) {
468
-         $("#deleteoldsms").css("display", "block");
469
-     } else {
470
-         $("#deleteoldsms").css("display", "none");
471
-     }
472
-  });
Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:47:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,472 @@
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
+  var userid = "<?php p($userId); ?>";
24
+  var telenctype = 'GSM-7';
25
+  var nexenctype = 'text';
26
+  var charcolorthr = 160;
27
+  var textread = '';
28
+  var providerUsed = '';
29
+  var receiversNumbers = [];
30
+  var waittime = 1000;
31
+
32
+  // Clean the temp_files directory
33
+  var cleanflUrl = OC.generateUrl("/apps/sms_relentless/user/cleantempdir");
34
+
35
+  $.ajax({
36
+          url: cleanflUrl + '/' + userid,
37
+          type: "POST",
38
+          data: { userid: userid },
39
+          cache: false,
40
+          processData: false,
41
+          contentType: false
42
+  });
43
+  
44
+  // Check the available balance
45
+  $("#smsprovider").on("change", function () {
46
+
47
+     var provider = $('#smsprovider :selected').val();
48
+
49
+     if (provider == "Telnyx") {
50
+
51
+        var gettelbalance = function() {
52
+
53
+          $('#currentbalance').addClass('icon-loading');
54
+
55
+          var gettelbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancetel");
56
+
57
+          $.ajax({
58
+              url: gettelbalanceUrl + '/' + userid,
59
+              type: "POST",
60
+              data: { userid: userid },
61
+              cache: false,
62
+              processData: false,
63
+              contentType: false,
64
+              success: function(currentbalancetel) {
65
+
66
+                     $('#currentbalance').empty();
67
+                     $('#currentbalance').text(currentbalancetel);
68
+                     $('#currentbalance').removeClass('icon-loading');
69
+              }
70
+          });
71
+        }
72
+
73
+        gettelbalance();
74
+
75
+     } else if (provider == "Plivo") {
76
+
77
+          var getnexbalance = function() {
78
+
79
+            $('#currentbalance').addClass('icon-loading');
80
+
81
+            var getnexbalanceUrl = OC.generateUrl("/apps/sms_relentless/user/getbalancenex");
82
+
83
+            $.ajax({
84
+                url: getnexbalanceUrl + '/' + userid,
85
+                type: "POST",
86
+                data: { userid: userid },
87
+                cache: false,
88
+                processData: false,
89
+                contentType: false,
90
+                success: function(currentbalancenex) {
91
+
92
+                     $('#currentbalance').empty();
93
+                     $('#currentbalance').text(currentbalancenex);
94
+                     $('#currentbalance').removeClass('icon-loading');
95
+                }
96
+            });
97
+          }
98
+
99
+          getnexbalance();
100
+
101
+       } else if (provider == "") {
102
+                $('#currentbalance').text("");
103
+                $('#currentbalance').removeClass('icon-loading');
104
+       }
105
+  });
106
+
107
+  // Select the Sender ID
108
+  $("#selectcalleridbttn").on("click", function(event) {
109
+
110
+     $('#selectcalleridbttn').addClass('icon-loading');
111
+
112
+     var getsmsnumbersUrl = OC.generateUrl("/apps/sms_relentless/user/getsmsnumbers");
113
+
114
+     $.ajax({
115
+          url: getsmsnumbersUrl + '/' + userid,
116
+          type: "POST",
117
+          data: { userid: userid },
118
+          cache: false,
119
+          processData: false,
120
+          contentType: false,
121
+          success: function(currentnmbrs) {
122
+
123
+                     $('#currentsmsnmbrs').empty();
124
+                     $('#currentsmsnmbrs').append("<option value='' selected='selected' disabled class='optselectsmsnb'>Choose an ID</option>");
125
+
126
+                     $.each(currentnmbrs, function(key, indsmsnmb) {
127
+                         var emptyinit = indsmsnmb.split(":");
128
+                         var emptysec = emptyinit[1];
129
+                         var emptycheck = emptysec.replace(" ", "").replace("+", "");
130
+
131
+                         if (emptycheck != '') {
132
+                             $('#currentsmsnmbrs').append("<option value='"+indsmsnmb+"' class='optselectsmsnb'>"+indsmsnmb+"</option>");
133
+                         }
134
+                     });
135
+
136
+                     $('#selectcalleridbttn').removeClass('icon-loading');
137
+          }
138
+     });
139
+  });
140
+
141
+  // Check the checkbox to send SMS message to multiple recipients
142
+  $('#tomultchckbx').change(function() {
143
+      if ($(this).is(':checked')) {
144
+          $("#multiplerecivers").css("display", "block");
145
+          $("#smstodiv").css("visibility", "hidden");
146
+          $("#smsto").val("");
147
+
148
+          receiversNumbers.length = 0;
149
+
150
+      } else {
151
+          $("#multiplerecivers").css("display", "none");
152
+          $("#smstodiv").css("visibility", "visible");
153
+
154
+          // Remove the uploaded file if any
155
+          $("#induploadfile").remove();
156
+
157
+          receiversNumbers.length = 0;
158
+
159
+          $.ajax({
160
+             url: cleanflUrl + '/' + userid,
161
+             type: "POST",
162
+             data: {userid: userid},
163
+             cache: false,
164
+             processData: false,
165
+             contentType: false
166
+          });
167
+      }
168
+  });
169
+
170
+  // Upload the file with the recipients' phone numbers
171
+  $("#uploadfileforsms").change(function(e) {
172
+
173
+     $("#fileuploadednm").empty();
174
+
175
+     receiversNumbers.length = 0;
176
+
177
+     OC.msg.startAction("#sms_upload_msg", t("sms_relentless", "Uploading ..."));
178
+
179
+     var baseUrl = OC.generateUrl("/apps/sms_relentless/user/upload_numbers_file");
180
+
181
+     var formData = new FormData();
182
+     formData.append('uploadfileforsms', $('#uploadfileforsms')[0].files[0]);
183
+
184
+     var fileup = $('#uploadfileforsms').val();
185
+     var fileuptrim = fileup.split('\\').pop();
186
+
187
+     $('#fileuploadednm').append("<div id='induploadfile' class='indgenflcls'><div id='indfilediv' class='indivflcls'>" + fileuptrim + "</div><div id='indivflremove' class='indupfldl'>X</div></div><br>");
188
+
189
+     var extension = fileup.replace(/^.*\./, '');
190
+
191
+     if (extension == fileup) {
192
+         extension = "";
193
+     } else {
194
+         extension = extension.toLowerCase();
195
+     }
196
+
197
+     var validExtensions = ["txt", "csv"];
198
+
199
+     if (jQuery.inArray(extension, validExtensions) != -1) {
200
+
201
+	// Check if the Sender ID is set
202
+	if ($("#currentsmsnmbrs option[value='']").length > 0) {
203
+            var setId = $('#currentsmsnmbrs :selected').val();
204
+	} else { var setId = ''; }
205
+
206
+	if (setId != '') {
207
+
208
+               $.ajax({
209
+                 url: baseUrl + '/' + userid,
210
+                 type: "POST",
211
+                 data: formData,
212
+                 cache: false,
213
+                 processData: false,
214
+                 contentType: false,
215
+                 success: function(numberarray) {
216
+
217
+		    if (numberarray.length > 0) {
218
+
219
+		        // Get the array of the receivers' phone numbers
220
+		        var setIdsplit = setId.split(":");
221
+		        var smsProvider = setIdsplit[0];
222
+
223
+		        if (smsProvider == "T") {
224
+
225
+		             for(key in numberarray) {
226
+		                 receiversNumbers.push("+"+numberarray[key]);
227
+		             }
228
+
229
+		        } else if (smsProvider == "P") {
230
+
231
+		             for(key in numberarray) {
232
+		                 receiversNumbers.push(numberarray[key]);
233
+		             }
234
+		          }
235
+
236
+		    } else {
237
+		          alert("The uploaded file doesn't seem to contain any valid phone numbers. Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines.");
238
+		    }
239
+                            
240
+                    // Preview the uploaded file
241
+                    var smsfilename = e.target.files[0].name;
242
+                    var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
243
+
244
+                    var reader = new FileReader();
245
+                    reader.readAsText(e.target.files[0]);
246
+                    reader.onload = function(e) {
247
+                          $("#smstables").empty();
248
+                          $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
249
+                    };
250
+
251
+                    $("#smstables").show();
252
+
253
+                    $('#sms_upload_msg').hide();
254
+                    $('#smstables').removeClass('icon-loading');
255
+
256
+                  },
257
+                  error: function(){
258
+                     alert('Error!');
259
+                  }
260
+               });
261
+
262
+        } else {
263
+               alert("Please choose a Sender ID from the Set ID drop-down list!");
264
+               $('#sms_upload_msg').hide();
265
+               $('#smstables').removeClass('icon-loading');
266
+        }
267
+
268
+     } else {
269
+          alert('The file type is not supported ! Supported formats are txt and csv.');
270
+          $('#pf_upload_msg').hide();
271
+          $('#faxdocpreview').removeClass('icon-loading');
272
+
273
+          $("#induploadfile").remove();
274
+          $("#sms_upload_msg").hide();
275
+     }
276
+
277
+     //Preview uploaded file when clicked
278
+     $("#indfilediv").on("click", function() {
279
+
280
+          var smsfilename = e.target.files[0].name;
281
+          var baseUrl = OC.generateUrl("/remote.php/webdav/SMS_Relentless/temp_files/"+smsfilename);
282
+
283
+          var reader = new FileReader();
284
+          reader.readAsText(e.target.files[0]);
285
+          reader.onload = function(e) {
286
+                  $("#smstables").empty();
287
+                  $("#smstables").append(e.target.result.replace(/(?:\r\n|\r|\n)/g, '<br>'));
288
+          };
289
+
290
+          $("#smstables").show();
291
+          $('#sms_upload_msg').hide();
292
+          $('#smstables').removeClass('icon-loading');
293
+     });
294
+
295
+     // Remove selected file
296
+     $("#indivflremove").on("click", function() {
297
+
298
+          $("#induploadfile").remove();
299
+          $("#sms_upload_msg").hide();
300
+
301
+          receiversNumbers.length = 0;
302
+
303
+          $.ajax({
304
+             url: cleanflUrl + '/' + userid,
305
+             type: "POST",
306
+             data: {userid: userid},
307
+             cache: false,
308
+             processData: false,
309
+             contentType: false
310
+         });
311
+     });
312
+
313
+  });
314
+
315
+  // Get the SMS encoding type
316
+  $('#unicodechckbx').change(function() {
317
+     if ($(this).is(':checked')) {
318
+           telenctype = 'UCS-2';
319
+           nexenctype = 'UCS-2';
320
+           charcolorthr = 70;
321
+     } else {
322
+           telenctype = 'GSM-7';
323
+           nexenctype = 'GSM-7';
324
+           charcolorthr = 160;
325
+     }
326
+  });
327
+
328
+  // Count the characters in the SMS text area
329
+  $("#smstext").on('input', function() {
330
+     $("#char_count").css("display", "inline");
331
+     $(".maxmessagelength").css("display", "inline-block");
332
+
333
+     $("#countchnb").text($(this).val().length);
334
+
335
+     if ($(this).val().length > charcolorthr) {
336
+         $("#char_count").css("color", "#BB2E4B");
337
+     } else {
338
+         $("#char_count").css("color", "#4cbc86;");
339
+     }
340
+  });
341
+
342
+  // Send the SMS message
343
+  $("#submitsms").on("click", function(event) {
344
+
345
+     OC.msg.startAction("#sms_submit_msg", t("sms_relentless", "Sending SMS ... Please wait !"));
346
+     $('#smstables').addClass('icon-loading');
347
+
348
+     // Check if the Sender ID is set
349
+     if ($("#currentsmsnmbrs option[value='']").length > 0) {
350
+            var selectedid = $('#currentsmsnmbrs :selected').val();
351
+     } else { var selectedid = ''; }
352
+
353
+     if (selectedid != '') { 
354
+
355
+         var sendersplit = selectedid.split(":");
356
+         var providercap = sendersplit[0];
357
+         var provsec = sendersplit[1];
358
+
359
+         if (/[a-zA-Z]/.test(provsec)) {
360
+             var alphanumcheck = true;
361
+         } else { var alphanumcheck = false; }
362
+
363
+         if (providercap == 'T' && alphanumcheck == false) {  
364
+             var senderproc = selectedid.replace(/[^0-9]/g, "");
365
+             var selectedsender = "+" + senderproc;
366
+             var providerUsed = "telnyx";
367
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
368
+             var enctype = telenctype;
369
+         } else if (providercap == 'P' && alphanumcheck == false) {
370
+             var selectedsender = selectedid.replace(/[^0-9]/g, "");
371
+             var providerUsed = "plivo";
372
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
373
+             var enctype = nexenctype;
374
+         } else if (providercap == 'T' && alphanumcheck == true) {
375
+             var selectedsender = provsec;
376
+             var providerUsed = "telnyx";
377
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmstel");
378
+             var enctype = telenctype;
379
+         } else if (providercap == 'P' && alphanumcheck == true) {
380
+             var selectedsender = provsec;
381
+             var providerUsed = "plivo";
382
+             var relbaseUrl = OC.generateUrl("/apps/sms_relentless/user/sendsmsnex");
383
+             var enctype = nexenctype;
384
+         }
385
+
386
+         // Get the interval between SMS consecutive sending requests, if it's the case
387
+         if ($('#tomultchckbx').is(':checked')) {
388
+
389
+             var numbersfile = 1;
390
+             var initinterval = $("#multsmsinterval").val();
391
+             var secinterval = initinterval.replace(/[^0-9]/g, "");
392
+
393
+             if (secinterval != '') {
394
+                 var tertinterval = parseInt(secinterval);
395
+                     waittime = tertinterval;
396
+             }
397
+
398
+         } else {
399
+
400
+             var numbersfile = 0;
401
+             var toNumberinit = $('#smsto').val();
402
+             var toNumber = toNumberinit.replace(/[^0-9,]/g, "");
403
+             var toNumbersec = toNumber.split(",");
404
+
405
+                 for (var i = 0; i < toNumbersec.length; i++) {
406
+                      toNumbersec[i] = "+" + toNumbersec[i];
407
+                 }
408
+
409
+                 receiversNumbers = toNumbersec.filter(function(v){return v!==""});
410
+         }
411
+
412
+         if (numbersfile == 0 && $('#smsto').val().trim() == '') { receiversNumbers.length = 0; }
413
+
414
+         var smstext = $("#smstext").val();
415
+
416
+         if (receiversNumbers.length != 0) {
417
+
418
+              if (smstext != '') {
419
+                  $.ajax({
420
+                     url: relbaseUrl + '/' + userid,
421
+                     type: "POST",
422
+                     data: {
423
+                           receiversPhoneNbs: receiversNumbers,
424
+                           fromsender: selectedsender,
425
+                           waitinterval: waittime,
426
+                           encoding: enctype,
427
+                           sentsmstext: smstext
428
+                         },
429
+                     success: function() {
430
+
431
+                           if (receiversNumbers.length == 1) {
432
+                               alert("The message has been sent ! You can press the 'Sent SMS Messages' button to check the actual status and the delivery receit for this message. Please note that the price and the delivery receipt for the message that has just been sent will not be available immediately. Wait about 30 seconds, then check again.");
433
+                           } else { alert("The messages have been sent ! You can press the 'Sent SMS Messages' button to check the actual status and the delivery receit for each message. Please note that the price and the delivery receipt for each message will not be available immediately. Wait about 30 seconds, then check again."); }
434
+
435
+                           $('#sms_submit_msg').hide();
436
+                           $('#smstables').removeClass('icon-loading');
437
+                     },
438
+                     error: function(){
439
+                           alert("An error occurred! Please check the recipient's phone number and your settings !");
440
+                           $('#sms_submit_msg').hide();
441
+                           $('#smstables').removeClass('icon-loading');
442
+                     }
443
+                  });
444
+              } else {
445
+                     alert("Please enter a message in the text box !");
446
+                     $('#sms_submit_msg').hide();
447
+                     $('#smstables').removeClass('icon-loading');
448
+              }
449
+         } else if (receiversNumbers.length == 0 && !($('#tomultchckbx').is(':checked'))) {
450
+                 alert("Please enter the recipient's phone number !");
451
+                 $('#sms_submit_msg').hide();
452
+                 $('#smstables').removeClass('icon-loading');
453
+         } else if (receiversNumbers.length == 0 && $('#tomultchckbx').is(':checked')) {
454
+                 alert("Please upload a txt or csv file that contains phone numbers separated by commas, semicolons, vertical bars or new lines !");
455
+                 $('#sms_submit_msg').hide();
456
+                 $('#smstables').removeClass('icon-loading');
457
+         }
458
+     } else {
459
+           alert("Please choose a Sender ID from the Set ID drop-down list !");
460
+           $('#smstables').removeClass('icon-loading');
461
+           $('#sms_submit_msg').hide();
462
+     }
463
+  });
464
+
465
+  // Check the checkbox to delete old SMS messages from the database
466
+  $('#deleteoldchckbox').change(function() {
467
+     if ($(this).is(':checked')) {
468
+         $("#deleteoldsms").css("display", "block");
469
+     } else {
470
+         $("#deleteoldsms").css("display", "none");
471
+     }
472
+  });