PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.4
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.4
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / assets / js / wpdbbkp-admin.js

wpdbbkp-admin.js in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.4, at assets/js/wpdbbkp-admin.js

487 lines 17.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 $(".wpdbbkp-send-query").on("click", function(e){
3 e.preventDefault();
4 var message = $("#wpdbbkp_query_message").val();
5 var email = $("#wpdbbkp_query_email").val();
6
7 if($.trim(message) !='' && $.trim(email) !='' && wpdbbkpIsEmail(email) == true){
8 $(".wpdbbkp-send-query").text('Sending request...');
9 $.ajax({
10 type: "POST",
11 url:ajaxurl,
12 dataType: "json",
13 data:{action:"wpdbbkp_send_query_message",message:message,email:email,wpdbbkp_security_nonce:wpdbbkp_script_vars.nonce},
14 success:function(response){
15 if(response['status'] =='t'){
16 $(".wpdbbkp-query-success").show();
17 $(".wpdbbkp-query-error").hide();
18 $(".wpdbbkp-send-query").text(' Send Support Request ');
19 }else{
20 $(".wpdbbkp-query-success").hide();
21 $(".wpdbbkp-query-error").show();
22 $(".wpdbbkp-send-query").text(' Send Support Request ');
23 }
24 },
25 error: function(response){
26 console.log(response);
27 alert('Request was not sent. Please try again.');
28 $(".wpdbbkp-send-query").text(' Resend Support Request ');
29 }
30 });
31 }else{
32
33 if($.trim(message) =='' && $.trim(email) ==''){
34 alert('Please enter the message, email');
35 }else{
36
37 if($.trim(message) == ''){
38 alert('Please enter the message');
39 }
40 if($.trim(email) == ''){
41 alert('Please enter the email');
42 }
43 if(wpdbbkpIsEmail(email) == false){
44 alert('Please enter a valid email');
45 }
46
47 }
48
49 }
50
51 });
52 if (history.replaceState) {
53 const url = new URL(window.location.href);
54 url.searchParams.delete("notification");
55 url.searchParams.delete("_wpnonce");
56 history.replaceState(null, null,url);
57 }
58 });
59
60 function wpdbbkpIsEmail(email) {
61 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
62 return regex.test(email);
63 }
64
65 // Javascript to enable link to tab
66 var wpdbbkp_hash = document.location.hash;
67 var wpdbbkp_prefix = "tab_";
68 if (wpdbbkp_hash) {
69 if(jQuery('.nav-tabs a[href="'+wpdbbkp_hash.replace(wpdbbkp_prefix,"")+'"]').length){
70 jQuery('.nav-tabs a[href="'+wpdbbkp_hash.replace(wpdbbkp_prefix,"")+'"]').tab('show');
71 window.scrollTo(0, 0);
72 }
73
74 }
75 // Change hash for click
76 jQuery('.wbdbbkp_has_nav a').on('click', function (e) {
77 if(jQuery('.nav-tabs a[href="'+e.target.hash.replace(wpdbbkp_prefix,"")+'"]').length){
78 window.location.hash = e.target.hash.replace("#", "#" + wpdbbkp_prefix);
79 jQuery('.nav-tabs a[href="'+e.target.hash.replace(wpdbbkp_prefix,"")+'"]').tab('show');
80 window.scrollTo(0, 0);
81 }
82 });
83
84 jQuery('.toplevel_page_wp-database-backup a').on('click', function (e) {
85 if(e.target.hash && jQuery('.nav-tabs a[href="'+e.target.hash.replace(wpdbbkp_prefix,"")+'"]').length){
86 window.location.hash = e.target.hash.replace("#", "#" + wpdbbkp_prefix);
87 jQuery('.nav-tabs a[href="'+e.target.hash.replace(wpdbbkp_prefix,"")+'"]').tab('show');
88 window.scrollTo(0, 0);
89 }
90 });
91
92 // Change hash for page-reload
93 jQuery('.nav-tabs a ').on('shown', function (e) {
94 if(e.target.hash.replace("#","").length){
95 window.location.hash = e.target.hash.replace("#", "#" + wpdbbkp_prefix);
96 window.scrollTo(0, 0);
97 }
98
99
100 });
101
102
103 var wpdbbkp_modal = document.getElementById("wpdbbkpModal");
104
105 if(wpdbbkp_modal){
106 window.onclick = function(event) {
107 if (event.target == wpdbbkp_modal) {
108 wpdbbkp_modal.style.display = "none";
109 }
110 }
111 }
112
113 function wpdbbkp_restore_backup(ele){
114 var wpdbbkp_span = document.getElementsByClassName("wpdbbkp-close");
115 let data_title = ele.getAttribute('data-title');
116 let data_href = ele.getAttribute('data-href');
117 let data_msg = ele.getAttribute('data-msg');
118 for(var i=0;i<wpdbbkp_span.length;i++){
119 wpdbbkp_span[i].onclick = function() {
120 wpdbbkp_modal.style.display = "none";
121 }
122 }
123 jQuery('#wpdbbkp-modal-header-title').text(data_title);
124 jQuery('#wpdbbkp-modal-body-text').text(data_msg);
125 jQuery('#wpdbbkp-proceed-btn').prop('href',data_href);
126 wpdbbkp_modal.style.display = "block";
127
128
129 }
130
131 function wpdbbkp_schduler_switch(){
132 var db_backups =document.getElementById('enable_autobackups');
133 if(db_backups){
134 if(db_backups.checked){
135 document.querySelector('.autobackup_type').style.display="block";
136 let autobackup_frequency = jQuery('#autobackup_frequency').val();
137 if(autobackup_frequency){
138 jQuery('.autobackup_frequency').show();
139 if(autobackup_frequency=='daily'){
140 jQuery('.autobackup_daily_lite').show();
141 jQuery('.autobackup_daily_lite').parent().show();
142 }else if(autobackup_frequency=='weekly'){
143 jQuery('.autobackup_weekly_lite').show();
144 jQuery('.autobackup_weekly_lite').parent().show();
145 }
146 else if(autobackup_frequency=='monthly'){
147 jQuery('.autobackup_monthly_lite').show();
148 jQuery('.autobackup_monthly_lite').parent().show();
149 }
150 }
151
152 }else{
153 document.querySelector('.autobackup_type').style.display="none";
154 jQuery('.autobackup_frequency_pro').hide();
155 jQuery('.autobackup_frequency_lite').hide();
156 jQuery('.autobackup_frequency').hide();
157 jQuery('.database_autobackup').hide();
158
159 }
160 }
161 }
162 jQuery('#enable_autobackups').change(function(){
163 wpdbbkp_schduler_switch();
164 });
165
166 function wpdbbkp_autobackup_type_switch(){
167 var enable_autobackups =document.getElementById('enable_autobackups');
168 if(enable_autobackups && !enable_autobackups.checked){
169
170 document.querySelector('.autobackup_frequency').style.display="none";
171 document.querySelector('.autobackup_daily_lite').style.display="none";
172 return false;
173
174 }
175 var db_backups =document.getElementById('autobackup_type');
176 if(db_backups.value){
177 document.querySelector('.autobackup_frequency').style.display="block";
178 document.querySelector('.autobackup_daily_lite').style.display="block";
179
180 }else{
181 jQuery('.autobackup_frequency_lite').hide();
182 document.querySelector('.autobackup_frequency').style.display="none";
183 document.querySelector('.autobackup_daily_lite').style.display="none";
184 if( document.querySelector('.autobackup_frequency_lite') && document.querySelector('.autobackup_frequency_lite').length){
185 document.querySelector('.autobackup_frequency_lite').style.display="none";
186 }
187 if( document.querySelector('.autobackup_frequency_pro') && document.querySelector('.autobackup_frequency_pro').length){
188 document.querySelector('.autobackup_frequency_pro').style.display="none";
189 }
190 }
191 }
192 jQuery('#autobackup_type').change(function(){
193 wpdbbkp_autobackup_type_switch();
194 autobackup_frequency_info();
195 });
196
197
198 function wpdbbkp_autobackup_frequency_switch(){
199 var db_backups =document.getElementById('autobackup_type');
200 if(db_backups.value){
201 document.querySelector('.autobackup_frequency').style.display="block";
202 }else{
203 document.querySelector('.autobackup_frequency').style.display="none";
204 }
205 }
206
207
208 jQuery('#autobackup_frequency').change(function(){
209 autobackup_frequency_info();
210 });
211
212 function autobackup_frequency_info(){
213 var autobackup_frequency = jQuery('#autobackup_frequency').val();
214 if(jQuery('.autobackup_time').length==0){
215 if(autobackup_frequency=='daily'){
216 jQuery('.autobackup_frequency_lite').hide();
217 jQuery('.autobackup_daily_lite').parent().show();
218 }else if(autobackup_frequency=='weekly'){
219 jQuery('.autobackup_frequency_lite').hide();
220 jQuery('.autobackup_weekly_lite').parent().show();
221 } else if(autobackup_frequency=='monthly'){
222 jQuery('.autobackup_frequency_lite').hide();
223 jQuery('.autobackup_monthly_lite').parent().show();
224 }else{
225 jQuery('.autobackup_frequency_lite').hide();
226 }
227
228 }
229 }
230
231 function modify_backup_frequency(){
232 if(jQuery('.autobackup_time').length==0){
233 var wpdbbkp_span = document.getElementsByClassName("wpdbbkp-close");
234 let data_title = 'Upgrade to unlock this feature';
235 let data_href = 'https://backupforwp.com/pricing#price';
236 let data_href_txt = 'Upgrade to Pro';
237 let data_msg = 'Upgrade to Pro version and unlock many features including Data anonimization , timed backup , prority support';
238 for(var i=0;i<wpdbbkp_span.length;i++){
239 wpdbbkp_span[i].onclick = function() {
240 wpdbbkp_modal.style.display = "none";
241 }
242 }
243 jQuery('#wpdbbkp-modal-header-title').text(data_title);
244 jQuery('#wpdbbkp-modal-body-text').text(data_msg);
245 jQuery('#wpdbbkp-proceed-btn').prop('href',data_href);
246 jQuery('#wpdbbkp-proceed-btn').prop('onclick',"");
247 jQuery('#wpdbbkp-proceed-btn').text(data_href_txt);
248 wpdbbkp_modal.style.display = "block";
249 }
250 else{
251 modify_backup_frequency_pro();
252 }
253 }
254
255 wpdbbkp_schduler_switch();
256 wpdbbkp_autobackup_type_switch();
257
258 jQuery('#wpdbbkp_sftp_auth_select').change(function(){
259 if(jQuery(this).val()=='key'){
260 jQuery('#wpdbbkp_sftp_sshkey_password').parent().parent().show();
261 jQuery('#wp_db_backup_sftp_key').parent().parent().show();
262 jQuery('#wpdbbkp_sftp_password').parent().parent().hide();
263 }else{
264 jQuery('#wpdbbkp_sftp_sshkey_password').parent().parent().hide();
265 jQuery('#wp_db_backup_sftp_key').parent().parent().hide();
266 jQuery('#wpdbbkp_sftp_password').parent().parent().show();
267 }
268 });
269
270 document.querySelector('#wpdbbkp_sftp_sshkey').addEventListener('input', function() {
271 const file = this.files[0]
272 let fr = new FileReader()
273 fr.readAsText(file)
274 fr.onload = () => {
275 document.querySelector('#wp_db_backup_sftp_key').value=btoa(fr.result);
276 console.log('key upload success');
277 }
278 fr.onerror = () => {
279 console.log(fr.error);
280 }
281 })
282
283 if(jQuery("#create_backup")){
284
285 jQuery("#create_backup").click(function(event) {
286 if(!bkpforwp_token_check()){
287 event.preventDefault();
288 let wpdbbkp_offer_modal = jQuery('#wpdbbkp_offer_modal').modal({ keyboard: true , backdrop: 'true',});
289 wpdbbkp_offer_modal.show();
290 // When the user selects an option, set the cookie and hide the modal
291 document.getElementById("wpdbbkp_server_backup").addEventListener("click", function() {
292 wpdbbkp_offer_modal.hide();
293 jQuery(".wpdbbkp_notification").hide();
294 jQuery("#backup_process").show();
295 jQuery("#create_backup").attr("disabled", true);
296 window.location.href = jQuery("#create_backup").attr("href");
297 });
298
299 document.getElementById("wpdbbkp_remote_backup").addEventListener("click", function() {
300 let register_url = 'https://app.backupforwp.com/register?token='+wpdbbkp_script_vars.siteurl+'&un='+wpdbbkp_script_vars.ud.name+'&ue='+wpdbbkp_script_vars.ud.email;
301 let loginWindow = window.open(register_url, '_blank', 'width=800,height=600,resizable=yes,scrollbars=yes,top=100,left=200');
302
303 window.addEventListener('message', function(event) {
304 // Check the origin of the message to ensure it's from the expected source
305 if (event.origin === 'https://app.backupforwp.com') {
306 let token = event.data;
307 $.ajax({
308 type: 'POST',
309 url: wpdbbkp_localize_admin_data.ajax_url,
310 data: {action: 'wpdbbkp_save_remote_token', token: token, wpdbbkp_security_nonce:wpdbbkp_localize_admin_data.wpdbbkp_admin_security_nonce},
311 success: function(response){
312 response = JSON.parse(response);
313 console.log(response);
314 if(response.status=='success'){
315 loginWindow.close();
316 window.location.href = jQuery("#create_backup").attr("href");
317
318 }
319 },
320 error: function(response){
321 console.log(response);
322 }
323
324 });
325 }
326 });
327
328 });
329 }
330
331
332 });
333 }
334
335
336 function bkpforwp_anonymization_logic(){
337 var anon_enable =document.getElementById('enable_anonymization');
338 if(anon_enable){
339 var anon_type = document.getElementById('anonymization_type_div');
340 if(anon_enable.checked){
341 if(anon_type){
342 anon_type.style.display="block";
343 }
344 }
345 else{
346 if(anon_type){
347 anon_type.style.display="none";
348 }
349 }
350 anon_enable.addEventListener('change',function(e){
351 bkpforwp_anonymization_logic();
352 });
353 }
354 }
355
356 function bkpforwp_anonymization_encypt_logic(){
357 var anon_type =document.getElementById('anonymization_type');
358 var anon_enable =document.getElementById('enable_anonymization');
359 var anon_ip =document.getElementById('anonymization_enc_ip');
360 if(anon_type && anon_enable){
361 if(anon_type.value=='encrypted_data' && anon_enable.checked){
362 if(anon_ip){
363 anon_ip.style.display="block";
364 }
365 }
366 else{
367 if(anon_ip){
368 anon_ip.style.display="none";
369 }
370 }
371 anon_type.addEventListener('change',function(e){
372 bkpforwp_anonymization_encypt_logic();
373 });
374 }
375 }
376 function bkpforwp_backup_encypt_logic(){
377 var anon_enable =document.getElementById('enable_backup_encryption');
378 if(anon_enable){
379 var anon_type = document.getElementById('encryption_pass_div');
380 if(anon_enable.checked){
381 if(anon_type){
382 anon_type.style.display="block";
383 }
384 }
385 else{
386 if(anon_type){
387 anon_type.style.display="none";
388 }
389 }
390 anon_enable.addEventListener('change',function(e){
391 bkpforwp_backup_encypt_logic();
392 });
393 }
394 }
395
396
397
398 // Javascript to enable link to tab
399 var hash = document.location.hash;
400 var prefix = "tab_";
401 if (hash) {
402 jQuery('.nav-tabs a[href="'+hash.replace(prefix,"")+'"]').tab('show');
403 }
404
405 // Change hash for page-reload
406 jQuery('.nav-tabs a').on('shown', function (e) {
407 window.location.hash = e.target.hash.replace("#", "#" + prefix);
408 });
409 jQuery('.nav-tabs a').on('click', function (e) {
410 window.location.hash = e.target.hash.replace("#", "#" + prefix);
411 });
412
413
414 function bkpforwp_database_schduler(){
415 var db_backups =document.getElementById('enable_autobackups');
416 if(db_backups){
417 if(db_backups.checked){
418 var autobackup_frequency = jQuery('#autobackup_frequency').val();
419 if(autobackup_frequency=='daily'){
420 jQuery('.database_autobackup').hide();
421 jQuery('.autobackup_time').show();
422 }else if(autobackup_frequency=='weekly'){
423 jQuery('.database_autobackup').hide();
424 jQuery('.autobackup_days').show();
425 jQuery('.autobackup_time').show();
426 }
427 else if(autobackup_frequency=='monthly'){
428 jQuery('.database_autobackup').hide();
429 jQuery('.autobackup_date').show();
430 jQuery('.autobackup_time').show();
431 }
432 else{
433 jQuery('.database_autobackup').hide();
434 }
435 }
436 else{
437 jQuery('.database_autobackup').hide();
438 }
439 }
440
441 }
442
443 function modify_backup_frequency_pro(){
444 bkpforwp_database_schduler();
445 }
446
447 jQuery('#enable_autobackups').change(function(){
448 bkpforwp_database_schduler();
449 });
450
451 jQuery('#autobackup_frequency').change(function(){
452 autobackup_frequency_info_();
453 });
454
455 function autobackup_frequency_info_(){
456 var autobackup_frequency = jQuery('#autobackup_frequency').val();
457 if(jQuery('.autobackup_time').length>0){
458 if(autobackup_frequency=='daily'){
459 jQuery('.autobackup_frequency_pro').hide();
460 jQuery('.autobackup_daily_pro').parent().show();
461 }else if(autobackup_frequency=='weekly'){
462 jQuery('.autobackup_frequency_pro').hide();
463 jQuery('.autobackup_weekly_pro').parent().show();
464 } else if(autobackup_frequency=='monthly'){
465 jQuery('.autobackup_frequency_pro').hide();
466 jQuery('.autobackup_monthly_pro').parent().show();
467 }else{
468 jQuery('.autobackup_frequency_pro').hide();
469 }
470 jQuery('.database_autobackup').hide();
471
472
473 }
474 }
475
476 bkpforwp_anonymization_logic();
477 bkpforwp_anonymization_encypt_logic();
478 bkpforwp_backup_encypt_logic();
479 bkpforwp_database_schduler();
480
481 function bkpforwp_token_check() {
482 var wpdb_clouddrive_token = document.getElementById('wpdb_clouddrive_token');
483 if (wpdb_clouddrive_token && wpdb_clouddrive_token.value) {
484 return true;
485 }
486 return false;
487 }