| @@ -1,285 +1,423 @@ | ||
| 1 | -jQuery(document).ready(function(){ | |
| 2 | - 'use strict' | |
| 3 | - //start new-update-for-codecanyon | |
| 4 | - jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('focusout', function(){ | |
| 5 | - qc_chatsessions_set_plugin_license_fields(); | |
| 6 | - }); | |
| 7 | - | |
| 8 | - jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('keypress',function (e) { | |
| 9 | - qc_chatsessions_set_plugin_license_fields(); | |
| 10 | - }); | |
| 11 | - | |
| 12 | - jQuery('#qc-license-form input[type="submit"]').on('click', function(){ | |
| 13 | - qc_chatsessions_set_plugin_license_fields(); | |
| 14 | - jQuery('#qc-license-form').removeAttr('onsubmit').submit(); | |
| 15 | - }); | |
| 16 | - | |
| 17 | - function qc_chatsessions_set_plugin_license_fields(){ | |
| 18 | - var license_input = jQuery('#qcld_chatsessions_enter_license_or_purchase_key').val(); | |
| 19 | - if( /^(\w{8})-((\w{4})-){3}(\w{12})$/.test(license_input) ){ | |
| 20 | - jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('codecanyon'); | |
| 21 | - jQuery('input[name="qcld_chatsessions_enter_envato_key"]').val(license_input); | |
| 22 | - }else{ | |
| 23 | - jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('quantumcloud'); | |
| 24 | - jQuery('input[name="qcld_chatsessions_enter_license_key"]').val(license_input); | |
| 25 | - } | |
| 26 | - } | |
| 27 | - function htmlspecialchars_decode(text) { | |
| 28 | - const parser = new DOMParser(); | |
| 29 | - const doc = parser.parseFromString(text, 'text/html'); | |
| 30 | - return doc.documentElement.textContent; | |
| 31 | - } | |
| 32 | - var session_hover_state = ''; | |
| 33 | - const modal = document.getElementById("session_details_modal"); | |
| 34 | - jQuery('.session_detail_hover').hover(function(e) { | |
| 35 | - var self = this; | |
| 36 | - var hoverTimer = ''; | |
| 37 | - const modal = document.getElementById("session_details_modal"); | |
| 38 | - | |
| 39 | - window.onclick = function(event) { | |
| 40 | - if (event.target == modal) { | |
| 41 | - modal.style.display = "none"; | |
| 42 | - } | |
| 43 | - } | |
| 44 | - if(session_hover_state == ''){ | |
| 45 | - session_hover_state = 1; | |
| 46 | - modal.style.display = "none"; | |
| 47 | - jQuery('.details_modal_body').html(''); | |
| 48 | - modal.style.left = (jQuery('.session_detail_hover').width() * 2)+'px'; | |
| 49 | - setTimeout(function() { | |
| 50 | - modal.style.display = "block"; | |
| 51 | - jQuery('.loader-mask').show(); | |
| 52 | - jQuery('.loader').show(); | |
| 53 | - jQuery.ajax({ | |
| 54 | - url: ajax_object.ajax_url, | |
| 55 | - type: 'POST', | |
| 56 | - dataType: "JSON", | |
| 57 | - data: { | |
| 58 | - action : 'wpbot_session_hover_details', | |
| 59 | - session_id: jQuery(self).attr('data-id'), | |
| 60 | - }, | |
| 61 | - success: function (response) { | |
| 62 | - jQuery('.loader').fadeOut(); | |
| 63 | - jQuery('.loader-mask').delay(350).fadeOut('slow'); | |
| 64 | - let htmlString = response.conversation; | |
| 65 | - const doc = htmlspecialchars_decode(htmlString); | |
| 66 | - jQuery('.details_modal_body').html(doc) | |
| 67 | - session_hover_state = ''; | |
| 68 | - // location.reload(); | |
| 69 | - }, | |
| 70 | - }); | |
| 71 | - }, 100); | |
| 72 | - } | |
| 73 | - }); | |
| 74 | - jQuery('#chatsession-table').on('click', '.show_details_click', function(e) { | |
| 75 | - var self = this; | |
| 76 | - const modal = document.getElementById("session_details_modal"); | |
| 77 | - | |
| 78 | - window.onclick = function(event) { | |
| 79 | - if (event.target == modal) { | |
| 80 | - modal.style.display = "none"; | |
| 81 | - } | |
| 82 | - } | |
| 83 | - if(session_hover_state == ''){ | |
| 84 | - session_hover_state = 1; | |
| 85 | - modal.style.display = "none"; | |
| 86 | - jQuery('.details_modal_body').html(''); | |
| 87 | - modal.style.left = (jQuery('.session_detail_hover').width() * 2)+'px'; | |
| 88 | - setTimeout(function() { | |
| 89 | - modal.style.display = "block"; | |
| 90 | - jQuery('.loader-mask').show(); | |
| 91 | - jQuery('.loader').show(); | |
| 92 | - jQuery.ajax({ | |
| 93 | - url: ajax_object.ajax_url, | |
| 94 | - type: 'POST', | |
| 95 | - dataType: "JSON", | |
| 96 | - data: { | |
| 97 | - action : 'wpbot_session_hover_details', | |
| 98 | - session_id: jQuery(self).attr('data-id'), | |
| 99 | - }, | |
| 100 | - success: function (response) { | |
| 101 | - jQuery('.loader').fadeOut(); | |
| 102 | - jQuery('.loader-mask').delay(350).fadeOut('slow'); | |
| 103 | - let htmlString = response.conversation; | |
| 104 | - const doc = htmlspecialchars_decode(htmlString); | |
| 105 | - jQuery('.details_modal_body').html(doc) | |
| 106 | - session_hover_state = ''; | |
| 107 | - // location.reload(); | |
| 108 | - }, | |
| 109 | - }); | |
| 110 | - }, 100); | |
| 111 | - } | |
| 112 | - }); | |
| 113 | - jQuery('#session_details_modal').on('click','.details_session_close',function(){ | |
| 114 | - const modal = document.getElementById("session_details_modal"); | |
| 115 | - modal.style.display = "none"; | |
| 116 | - }) | |
| 117 | - jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){ | |
| 118 | - Swal.showLoading(); | |
| 119 | - if (jQuery('#is_ai_enabled').is(":checked")){ | |
| 120 | - var is_ai_enabled = 1; | |
| 121 | - }else{ | |
| 122 | - var is_ai_enabled = 0; | |
| 123 | - } | |
| 124 | - var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val(); | |
| 125 | - var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val(); | |
| 126 | - var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val(); | |
| 127 | - jQuery.ajax({ | |
| 128 | - url: ajax_object.ajax_url, | |
| 129 | - type: 'POST', | |
| 130 | - dataType: "JSON", | |
| 131 | - data: { | |
| 132 | - action : 'wpbot_seesion_corn_save', | |
| 133 | - ai_enabled: is_ai_enabled, | |
| 134 | - corn_schedule_interval: corn_schedule_interval, | |
| 135 | - qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime, | |
| 136 | - qcld_wpsession_corn_promt: qcld_wpsession_corn_promt, | |
| 137 | - }, | |
| 138 | - success: function (response) { | |
| 139 | - var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 140 | - var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 141 | - Swal.fire({ | |
| 142 | - title: cleanMsg, | |
| 143 | - text: cleanResponse, | |
| 144 | - icon: response.icon, | |
| 145 | - width: 450, | |
| 146 | - confirmButtonText: 'Got it', | |
| 147 | - confirmButtonWidth: 100, | |
| 148 | - confirmButtonClass: 'btn btn-lg' | |
| 149 | - }).then(() => { | |
| 150 | - // location.reload(); | |
| 151 | - }) | |
| 152 | - | |
| 153 | - }, | |
| 154 | - }); | |
| 155 | - }) | |
| 156 | - jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){ | |
| 157 | - Swal.showLoading(); | |
| 158 | - var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val(); | |
| 159 | - jQuery.ajax({ | |
| 160 | - url: ajax_object.ajax_url, | |
| 161 | - type: 'POST', | |
| 162 | - dataType: "JSON", | |
| 163 | - data: { | |
| 164 | - action : 'qcld_chatbot_session_mannual_scraper', | |
| 165 | - wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number, | |
| 166 | - }, | |
| 167 | - success: function (response) { | |
| 168 | - var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 169 | - var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 170 | - Swal.fire({ | |
| 171 | - title: cleanMsg, | |
| 172 | - text: cleanResponse, | |
| 173 | - icon: response.icon, | |
| 174 | - width: 450, | |
| 175 | - confirmButtonText: 'Got it', | |
| 176 | - confirmButtonWidth: 100, | |
| 177 | - confirmButtonClass: 'btn btn-lg' | |
| 178 | - }).then(() => { | |
| 179 | - // location.reload(); | |
| 180 | - }) | |
| 181 | - }, | |
| 182 | - }); | |
| 183 | - }) | |
| 184 | - | |
| 185 | - //end new-update-for-codecanyon | |
| 186 | - jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() { | |
| 187 | - if(this.checked) { | |
| 188 | - jQuery.ajax({ | |
| 189 | - url: ajax_object.ajax_url, | |
| 190 | - type: 'POST', | |
| 191 | - dataType: "JSON", | |
| 192 | - data: { | |
| 193 | - action : 'session_email_notification_update', | |
| 194 | - email_notification: 'checked', | |
| 195 | - }, | |
| 196 | - success: function (response) { | |
| 197 | - location.reload(); | |
| 198 | - }, | |
| 199 | - }); | |
| 200 | - }else{ | |
| 201 | - jQuery.ajax({ | |
| 202 | - url: ajax_object.ajax_url, | |
| 203 | - type: 'POST', | |
| 204 | - dataType: "JSON", | |
| 205 | - data: { | |
| 206 | - action : 'session_email_notification_update', | |
| 207 | - email_notification: '', | |
| 208 | - }, | |
| 209 | - success: function (response) { | |
| 210 | - location.reload(); | |
| 211 | - }, | |
| 212 | - }); | |
| 213 | - } | |
| 214 | - }); | |
| 215 | - | |
| 216 | - jQuery('#chatsession-table').on('click', '.forward_session', function () { | |
| 217 | - setTimeout(function() { | |
| 218 | - var detailselement = document.getElementById("wp-chatbot-messages-container"); | |
| 219 | - detailselement.remove(); | |
| 220 | - }, 500); | |
| 221 | - const forwardModal = document.getElementById("session_foward_modal"); | |
| 222 | - if (forwardModal) { | |
| 223 | - forwardModal.style.display = "block"; | |
| 224 | - jQuery('#details_session_id').val(jQuery(this).attr('data-id')); | |
| 225 | - } | |
| 226 | - | |
| 227 | - }); | |
| 228 | - jQuery('#session_foward_modal').on('click', '.forward_session_close', function () { | |
| 229 | - const forwardModal = document.getElementById("session_foward_modal"); | |
| 230 | - if (forwardModal) { | |
| 231 | - forwardModal.style.display = "none"; | |
| 232 | - } | |
| 233 | - }); | |
| 234 | - | |
| 235 | - jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () { | |
| 236 | - var session_id = jQuery('#details_session_id').val(); | |
| 237 | - jQuery.ajax({ | |
| 238 | - url: ajax_object.ajax_url, | |
| 239 | - type: 'POST', | |
| 240 | - dataType: "JSON", | |
| 241 | - data: { | |
| 242 | - action : 'forward_session_to_email', | |
| 243 | - session_id: session_id, | |
| 244 | - email: jQuery('#details_session_email').val(), | |
| 245 | - subject: jQuery('#details_session_subject').val(), | |
| 246 | - }, | |
| 247 | - success: function (response) { | |
| 248 | - jQuery('#session_foward_modal').hide() | |
| 249 | - } | |
| 250 | - }); | |
| 251 | - }); | |
| 252 | - jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () { | |
| 253 | - | |
| 254 | - var session_id = jQuery('#details_session_id').val(); | |
| 255 | - jQuery.ajax({ | |
| 256 | - url: ajax_object.ajax_url, | |
| 257 | - type: 'POST', | |
| 258 | - dataType: "JSON", | |
| 259 | - data: { | |
| 260 | - action : 'forward_session_to_email', | |
| 261 | - session_id: session_id, | |
| 262 | - email: jQuery('#details_session_email').val(), | |
| 263 | - subject: jQuery('#details_session_subject').val(), | |
| 264 | - }, | |
| 265 | - success: function (response) { | |
| 266 | - if(response.success){ | |
| 267 | - Swal.fire({ | |
| 268 | - title: 'Success', | |
| 269 | - text: response.message, | |
| 270 | - icon: 'success', | |
| 271 | - confirmButtonText: 'OK' | |
| 272 | - }); | |
| 273 | - } else { | |
| 274 | - Swal.fire({ | |
| 275 | - title: 'Error', | |
| 276 | - text: response.message, | |
| 277 | - icon: 'error', | |
| 278 | - confirmButtonText: 'OK' | |
| 279 | - }); | |
| 280 | - } | |
| 281 | - } | |
| 282 | - }); | |
| 283 | - }); | |
| 284 | - | |
| 285 | -}); | |
| 1 | +jQuery(document).ready(function(){ | |
| 2 | + 'use strict' | |
| 3 | + //start new-update-for-codecanyon | |
| 4 | + jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('focusout', function(){ | |
| 5 | + qc_chatsessions_set_plugin_license_fields(); | |
| 6 | + }); | |
| 7 | + | |
| 8 | + jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('keypress',function (e) { | |
| 9 | + qc_chatsessions_set_plugin_license_fields(); | |
| 10 | + }); | |
| 11 | + | |
| 12 | + jQuery('#qc-license-form input[type="submit"]').on('click', function(){ | |
| 13 | + qc_chatsessions_set_plugin_license_fields(); | |
| 14 | + jQuery('#qc-license-form').removeAttr('onsubmit').submit(); | |
| 15 | + }); | |
| 16 | + | |
| 17 | + function qc_chatsessions_set_plugin_license_fields(){ | |
| 18 | + var license_input = jQuery('#qcld_chatsessions_enter_license_or_purchase_key').val(); | |
| 19 | + if( /^(\w{8})-((\w{4})-){3}(\w{12})$/.test(license_input) ){ | |
| 20 | + jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('codecanyon'); | |
| 21 | + jQuery('input[name="qcld_chatsessions_enter_envato_key"]').val(license_input); | |
| 22 | + }else{ | |
| 23 | + jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('quantumcloud'); | |
| 24 | + jQuery('input[name="qcld_chatsessions_enter_license_key"]').val(license_input); | |
| 25 | + } | |
| 26 | + } | |
| 27 | + function htmlspecialchars_decode(text) { | |
| 28 | + const parser = new DOMParser(); | |
| 29 | + const doc = parser.parseFromString(text, 'text/html'); | |
| 30 | + return doc.documentElement.textContent; | |
| 31 | + } | |
| 32 | + var session_hover_state = ''; | |
| 33 | + const modal = document.getElementById("session_details_modal"); | |
| 34 | + jQuery('.session_detail_hover').hover(function(e) { | |
| 35 | + var self = this; | |
| 36 | + var hoverTimer = ''; | |
| 37 | + const modal = document.getElementById("session_details_modal"); | |
| 38 | + | |
| 39 | + window.onclick = function(event) { | |
| 40 | + if (event.target == modal) { | |
| 41 | + modal.style.display = "none"; | |
| 42 | + } | |
| 43 | + } | |
| 44 | + if(session_hover_state == ''){ | |
| 45 | + session_hover_state = 1; | |
| 46 | + modal.style.display = "none"; | |
| 47 | + jQuery('.details_modal_body').html(''); | |
| 48 | + modal.style.left = ''; | |
| 49 | + modal.style.top = ''; | |
| 50 | + setTimeout(function() { | |
| 51 | + modal.style.display = "block"; | |
| 52 | + jQuery('.loader-mask').show(); | |
| 53 | + jQuery('.loader').show(); | |
| 54 | + jQuery.ajax({ | |
| 55 | + url: ajax_object.ajax_url, | |
| 56 | + type: 'POST', | |
| 57 | + dataType: "JSON", | |
| 58 | + data: { | |
| 59 | + action : 'wpbot_session_hover_details', | |
| 60 | + security: ajax_object.ajax_nonce, | |
| 61 | + session_id: jQuery(self).attr('data-id'), | |
| 62 | + }, | |
| 63 | + success: function (response) { | |
| 64 | + jQuery('.loader').fadeOut(); | |
| 65 | + jQuery('.loader-mask').delay(350).fadeOut('slow'); | |
| 66 | + // SECURITY FIX: Server now returns sanitized HTML (wp_kses output). | |
| 67 | + // Do NOT run htmlspecialchars_decode() on conversation data before .html(); | |
| 68 | + // that decode-then-inject pattern was the DOM XSS sink. | |
| 69 | + let htmlString = response.conversation; | |
| 70 | + let doc = '<div class="session-details-sction-modal">' ; | |
| 71 | + doc += htmlString; | |
| 72 | + doc += '</div>'; | |
| 73 | + if (response.email) { | |
| 74 | + doc += '<div class="email-reply-container">' + | |
| 75 | + '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + response.email + ' <strong>From:</strong> <input type="email" id="reply_from_email" class="form-control" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + | |
| 76 | + '<div class="form-group mb-2">' + | |
| 77 | + '<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' + | |
| 78 | + '</div>' + | |
| 79 | + '<div class="form-group mb-2">' + | |
| 80 | + '<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + | |
| 81 | + '</div>' + | |
| 82 | + '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + | |
| 83 | + '</div>'; | |
| 84 | + } else { | |
| 85 | + doc += '<div class="email-reply-container">' + | |
| 86 | + '<p class="email-reply-warning">Enable Asking for Email to get email reply option</p>' + | |
| 87 | + '</div>'; | |
| 88 | + } | |
| 89 | + jQuery('.details_modal_body').html(doc); | |
| 90 | + session_hover_state = ''; | |
| 91 | + // location.reload(); | |
| 92 | + }, | |
| 93 | + }); | |
| 94 | + }, 100); | |
| 95 | + } | |
| 96 | + }); | |
| 97 | + jQuery('#chatsession-table').on('click', '.show_details_click', function(e) { | |
| 98 | + var self = this; | |
| 99 | + const modal = document.getElementById("session_details_modal"); | |
| 100 | + | |
| 101 | + window.onclick = function(event) { | |
| 102 | + if (event.target == modal) { | |
| 103 | + modal.style.display = "none"; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + if(session_hover_state == ''){ | |
| 107 | + session_hover_state = 1; | |
| 108 | + modal.style.display = "none"; | |
| 109 | + jQuery('.details_modal_body').html(''); | |
| 110 | + modal.style.left = ''; | |
| 111 | + modal.style.top = ''; | |
| 112 | + | |
| 113 | + if (typeof Swal !== 'undefined') { | |
| 114 | + Swal.fire({ | |
| 115 | + html: '<div class="qcld-save-settings-spinner"></div>', | |
| 116 | + allowOutsideClick: false, | |
| 117 | + allowEscapeKey: false, | |
| 118 | + showConfirmButton: false, | |
| 119 | + background: 'transparent', | |
| 120 | + customClass: { | |
| 121 | + popup: 'qcld-swal-loading-only' | |
| 122 | + } | |
| 123 | + }); | |
| 124 | + } | |
| 125 | + | |
| 126 | + jQuery.ajax({ | |
| 127 | + url: ajax_object.ajax_url, | |
| 128 | + type: 'POST', | |
| 129 | + dataType: "JSON", | |
| 130 | + data: { | |
| 131 | + action : 'wpbot_session_hover_details', | |
| 132 | + security: ajax_object.ajax_nonce, | |
| 133 | + session_id: jQuery(self).attr('data-id'), | |
| 134 | + }, | |
| 135 | + success: function (response) { | |
| 136 | + if (typeof Swal !== 'undefined') { | |
| 137 | + Swal.close(); | |
| 138 | + } | |
| 139 | + // SECURITY FIX: Server now returns sanitized HTML (wp_kses output). | |
| 140 | + // Do NOT run htmlspecialchars_decode() on conversation data before .html(); | |
| 141 | + // that decode-then-inject pattern was the DOM XSS sink. | |
| 142 | + let htmlString = response.conversation; | |
| 143 | + let doc = '<div class="session-details-sction-modal">' ; | |
| 144 | + doc += htmlString; | |
| 145 | + doc += '</div>'; | |
| 146 | + if (response.email) { | |
| 147 | + var replyEmail = response.email || ''; | |
| 148 | + var replyEmailText = jQuery('<div>').text(replyEmail).html(); | |
| 149 | + var replyEmailLink = '<a href="mailto:' + encodeURIComponent(replyEmail) + '">' + replyEmailText + '</a>'; | |
| 150 | + doc += '<div class="email-reply-container">' + | |
| 151 | + '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + replyEmailLink + ' <strong>From:</strong> <input type="email" id="reply_from_email" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + | |
| 152 | + '<div class="form-group mb-2">' + | |
| 153 | + '<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' + | |
| 154 | + '</div>' + | |
| 155 | + '<div class="form-group mb-2">' + | |
| 156 | + '<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + | |
| 157 | + '</div>' + | |
| 158 | + '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + | |
| 159 | + '</div>'; | |
| 160 | + } else { | |
| 161 | + doc += '<div class="email-reply-container">' + | |
| 162 | + '<p class="email-reply-warning">To email this user and chat session, enable Asking for Email in General Settings</p>' + | |
| 163 | + '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + (response.email || '') + ' <strong>From:</strong> <input type="email" id="reply_from_email" disabled value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' + | |
| 164 | + '<div class="form-group mb-2">' + | |
| 165 | + '<input type="text" id="reply_subject" disabled class="form-control" placeholder="Reply to your chat session">' + | |
| 166 | + '</div>' + | |
| 167 | + '<div class="form-group mb-2">' + | |
| 168 | + '<textarea id="reply_message" disabled class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' + | |
| 169 | + '</div>' + | |
| 170 | + '<button type="button" disabled class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' + | |
| 171 | + '</div>'; | |
| 172 | + } | |
| 173 | + jQuery('.details_modal_body').html(doc); | |
| 174 | + modal.style.display = "block"; | |
| 175 | + session_hover_state = ''; | |
| 176 | + }, | |
| 177 | + error: function () { | |
| 178 | + if (typeof Swal !== 'undefined') { | |
| 179 | + Swal.close(); | |
| 180 | + } | |
| 181 | + session_hover_state = ''; | |
| 182 | + } | |
| 183 | + }); | |
| 184 | + } | |
| 185 | + }); | |
| 186 | + jQuery('#session_details_modal').on('click','.details_session_close',function(){ | |
| 187 | + const modal = document.getElementById("session_details_modal"); | |
| 188 | + modal.style.display = "none"; | |
| 189 | + }); | |
| 190 | + | |
| 191 | + jQuery(document).on('click', '#btn_send_reply_email', function () { | |
| 192 | + var email = jQuery(this).attr('data-email'); | |
| 193 | + var container = jQuery(this).closest('.email-reply-container'); | |
| 194 | + var fromEmail = container.find('#reply_from_email').val(); | |
| 195 | + var subject = container.find('#reply_subject').val(); | |
| 196 | + var message = container.find('#reply_message').val(); | |
| 197 | + var btn = jQuery(this); | |
| 198 | + | |
| 199 | + if (!message.trim()) { | |
| 200 | + alert('Please enter a message.'); | |
| 201 | + return; | |
| 202 | + } | |
| 203 | + | |
| 204 | + btn.prop('disabled', true).text('Sending...'); | |
| 205 | + | |
| 206 | + jQuery.ajax({ | |
| 207 | + url: ajax_object.ajax_url, | |
| 208 | + type: 'POST', | |
| 209 | + dataType: "JSON", | |
| 210 | + data: { | |
| 211 | + action: 'wpbot_send_reply_email', | |
| 212 | + security: ajax_object.ajax_nonce, | |
| 213 | + email: email, | |
| 214 | + from_email: fromEmail, | |
| 215 | + subject: subject, | |
| 216 | + message: message | |
| 217 | + }, | |
| 218 | + success: function (response) { | |
| 219 | + btn.prop('disabled', false).text('Send Reply'); | |
| 220 | + if (response.success) { | |
| 221 | + if (typeof Swal !== 'undefined') { | |
| 222 | + Swal.fire({ | |
| 223 | + title: 'Success', | |
| 224 | + text: response.msg, | |
| 225 | + icon: 'success', | |
| 226 | + confirmButtonText: 'OK' | |
| 227 | + }); | |
| 228 | + } else { | |
| 229 | + alert(response.msg); | |
| 230 | + } | |
| 231 | + container.find('#reply_message').val(''); | |
| 232 | + } else { | |
| 233 | + if (typeof Swal !== 'undefined') { | |
| 234 | + Swal.fire({ | |
| 235 | + title: 'Error', | |
| 236 | + text: response.msg, | |
| 237 | + icon: 'error', | |
| 238 | + confirmButtonText: 'OK' | |
| 239 | + }); | |
| 240 | + } else { | |
| 241 | + alert(response.msg); | |
| 242 | + } | |
| 243 | + } | |
| 244 | + }, | |
| 245 | + error: function() { | |
| 246 | + btn.prop('disabled', false).text('Send Reply'); | |
| 247 | + alert('An error occurred. Please try again.'); | |
| 248 | + } | |
| 249 | + }); | |
| 250 | + }); | |
| 251 | + jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){ | |
| 252 | + Swal.showLoading(); | |
| 253 | + if (jQuery('#is_ai_enabled').is(":checked")){ | |
| 254 | + var is_ai_enabled = 1; | |
| 255 | + }else{ | |
| 256 | + var is_ai_enabled = 0; | |
| 257 | + } | |
| 258 | + var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val(); | |
| 259 | + var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val(); | |
| 260 | + var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val(); | |
| 261 | + jQuery.ajax({ | |
| 262 | + url: ajax_object.ajax_url, | |
| 263 | + type: 'POST', | |
| 264 | + dataType: "JSON", | |
| 265 | + data: { | |
| 266 | + action : 'wpbot_seesion_corn_save', | |
| 267 | + security: ajax_object.ajax_nonce, | |
| 268 | + ai_enabled: is_ai_enabled, | |
| 269 | + corn_schedule_interval: corn_schedule_interval, | |
| 270 | + qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime, | |
| 271 | + qcld_wpsession_corn_promt: qcld_wpsession_corn_promt, | |
| 272 | + }, | |
| 273 | + success: function (response) { | |
| 274 | + var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 275 | + var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 276 | + Swal.fire({ | |
| 277 | + title: cleanMsg, | |
| 278 | + text: cleanResponse, | |
| 279 | + icon: response.icon, | |
| 280 | + width: 450, | |
| 281 | + confirmButtonText: 'Got it', | |
| 282 | + confirmButtonWidth: 100, | |
| 283 | + confirmButtonClass: 'btn btn-lg' | |
| 284 | + }).then(() => { | |
| 285 | + // location.reload(); | |
| 286 | + }) | |
| 287 | + | |
| 288 | + }, | |
| 289 | + }); | |
| 290 | + }) | |
| 291 | + jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){ | |
| 292 | + Swal.showLoading(); | |
| 293 | + var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val(); | |
| 294 | + jQuery.ajax({ | |
| 295 | + url: ajax_object.ajax_url, | |
| 296 | + type: 'POST', | |
| 297 | + dataType: "JSON", | |
| 298 | + data: { | |
| 299 | + action : 'qcld_chatbot_session_mannual_scraper', | |
| 300 | + security: ajax_object.ajax_nonce, | |
| 301 | + wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number, | |
| 302 | + }, | |
| 303 | + success: function (response) { | |
| 304 | + var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 305 | + var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : ""; | |
| 306 | + Swal.fire({ | |
| 307 | + title: cleanMsg, | |
| 308 | + text: cleanResponse, | |
| 309 | + icon: response.icon, | |
| 310 | + width: 450, | |
| 311 | + confirmButtonText: 'Got it', | |
| 312 | + confirmButtonWidth: 100, | |
| 313 | + confirmButtonClass: 'btn btn-lg' | |
| 314 | + }).then(() => { | |
| 315 | + // location.reload(); | |
| 316 | + }) | |
| 317 | + }, | |
| 318 | + }); | |
| 319 | + }) | |
| 320 | + | |
| 321 | + //end new-update-for-codecanyon | |
| 322 | + jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() { | |
| 323 | + if(this.checked) { | |
| 324 | + jQuery.ajax({ | |
| 325 | + url: ajax_object.ajax_url, | |
| 326 | + type: 'POST', | |
| 327 | + dataType: "JSON", | |
| 328 | + data: { | |
| 329 | + action : 'session_email_notification_update', | |
| 330 | + security: ajax_object.ajax_nonce, | |
| 331 | + email_notification: 'checked', | |
| 332 | + }, | |
| 333 | + success: function (response) { | |
| 334 | + location.reload(); | |
| 335 | + }, | |
| 336 | + }); | |
| 337 | + }else{ | |
| 338 | + jQuery.ajax({ | |
| 339 | + url: ajax_object.ajax_url, | |
| 340 | + type: 'POST', | |
| 341 | + dataType: "JSON", | |
| 342 | + data: { | |
| 343 | + action : 'session_email_notification_update', | |
| 344 | + security: ajax_object.ajax_nonce, | |
| 345 | + email_notification: '', | |
| 346 | + }, | |
| 347 | + success: function (response) { | |
| 348 | + location.reload(); | |
| 349 | + }, | |
| 350 | + }); | |
| 351 | + } | |
| 352 | + }); | |
| 353 | + | |
| 354 | + jQuery('#chatsession-table').on('click', '.forward_session', function () { | |
| 355 | + jQuery('.details_modal_body').html(''); | |
| 356 | + | |
| 357 | + const forwardModal = document.getElementById("session_foward_modal"); | |
| 358 | + if (forwardModal) { | |
| 359 | + forwardModal.style.display = "block"; | |
| 360 | + jQuery('#details_session_id').val(jQuery(this).attr('data-id')); | |
| 361 | + } | |
| 362 | + | |
| 363 | + }); | |
| 364 | + jQuery('#session_foward_modal').on('click', '.forward_session_close', function () { | |
| 365 | + const forwardModal = document.getElementById("session_foward_modal"); | |
| 366 | + if (forwardModal) { | |
| 367 | + forwardModal.style.display = "none"; | |
| 368 | + } | |
| 369 | + }); | |
| 370 | + | |
| 371 | + jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () { | |
| 372 | + var session_id = jQuery('#details_session_id').val(); | |
| 373 | + jQuery.ajax({ | |
| 374 | + url: ajax_object.ajax_url, | |
| 375 | + type: 'POST', | |
| 376 | + dataType: "JSON", | |
| 377 | + data: { | |
| 378 | + action : 'forward_session_to_email', | |
| 379 | + security: ajax_object.ajax_nonce, | |
| 380 | + session_id: session_id, | |
| 381 | + email: jQuery('#details_session_email').val(), | |
| 382 | + subject: jQuery('#details_session_subject').val(), | |
| 383 | + }, | |
| 384 | + success: function (response) { | |
| 385 | + jQuery('#session_foward_modal').hide() | |
| 386 | + } | |
| 387 | + }); | |
| 388 | + }); | |
| 389 | + jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () { | |
| 390 | + | |
| 391 | + var session_id = jQuery('#details_session_id').val(); | |
| 392 | + jQuery.ajax({ | |
| 393 | + url: ajax_object.ajax_url, | |
| 394 | + type: 'POST', | |
| 395 | + dataType: "JSON", | |
| 396 | + data: { | |
| 397 | + action : 'forward_session_to_email', | |
| 398 | + security: ajax_object.ajax_nonce, | |
| 399 | + session_id: session_id, | |
| 400 | + email: jQuery('#details_session_email').val(), | |
| 401 | + subject: jQuery('#details_session_subject').val(), | |
| 402 | + }, | |
| 403 | + success: function (response) { | |
| 404 | + if(response.success){ | |
| 405 | + Swal.fire({ | |
| 406 | + title: 'Success', | |
| 407 | + text: response.message, | |
| 408 | + icon: 'success', | |
| 409 | + confirmButtonText: 'OK' | |
| 410 | + }); | |
| 411 | + } else { | |
| 412 | + Swal.fire({ | |
| 413 | + title: 'Error', | |
| 414 | + text: response.message, | |
| 415 | + icon: 'error', | |
| 416 | + confirmButtonText: 'OK' | |
| 417 | + }); | |
| 418 | + } | |
| 419 | + } | |
| 420 | + }); | |
| 421 | + }); | |
| 422 | + | |
| 423 | +}); | |