| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/****************************************** |
| 7 |
* Add Helper Functions File |
| 8 |
******************************************/ |
| 9 |
require_once QCLD_WPCHATBOT_HISTORY_DIR_PATH . '/reports/reporting-helper-functions.php'; |
| 10 |
|
| 11 |
|
| 12 |
/****************************************** |
| 13 |
* Add Reporting Menu |
| 14 |
*/ |
| 15 |
add_action( 'admin_menu', 'qcld_history_reporting_menu_func' ); |
| 16 |
add_action( 'admin_enqueue_scripts', 'qcld_wpbot_reporting_enqueue_assets' ); |
| 17 |
|
| 18 |
function qcld_wpbot_reporting_enqueue_assets( $hook ) { |
| 19 |
if ( strpos( $hook, 'wbcs-botsessions-reports' ) === false ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
wp_enqueue_script( |
| 24 |
'qcld-wp-apexcharts', |
| 25 |
QCLD_wpCHATBOT_HISTORY_PLUGIN_URL . 'reports/view/assets/apexcharts.min.js', |
| 26 |
array( 'jquery' ), |
| 27 |
QCLD_wpCHATBOT_VERSION, |
| 28 |
true |
| 29 |
); |
| 30 |
|
| 31 |
$inline_script = <<<'JS' |
| 32 |
jQuery(document).ready(function($) { |
| 33 |
$(".feedback-card").on("click", function() { |
| 34 |
let type = $(this).data("type"); |
| 35 |
$("#feedback-results").html("<p>Loading...</p>"); |
| 36 |
|
| 37 |
$.post(ajaxurl, { |
| 38 |
action: "wpbot_get_feedback_ajax", |
| 39 |
feedback_type: type |
| 40 |
}, function(response) { |
| 41 |
if (response.success) { |
| 42 |
$("#feedback-results").html(response.data.html); |
| 43 |
} else { |
| 44 |
$("#feedback-results").html("<p>No results found.</p>"); |
| 45 |
} |
| 46 |
}); |
| 47 |
}); |
| 48 |
}); |
| 49 |
jQuery(document).on("click", ".wpbot-page-link", function(e) { |
| 50 |
e.preventDefault(); |
| 51 |
|
| 52 |
let page = jQuery(this).data("page"); |
| 53 |
let type = jQuery(this).data("type"); |
| 54 |
|
| 55 |
jQuery.post(ajaxurl, { |
| 56 |
action: "wpbot_get_feedback_ajax", |
| 57 |
feedback_type: type, |
| 58 |
page: page |
| 59 |
}, function(response) { |
| 60 |
if (response.success) { |
| 61 |
jQuery("#feedback-results").html(response.data.html); |
| 62 |
} |
| 63 |
}); |
| 64 |
}); |
| 65 |
jQuery(document).on("click", "#wpbot-clear-feedback", function(e) { |
| 66 |
e.preventDefault(); |
| 67 |
|
| 68 |
if (!confirm("Are you sure you want to delete all feedback?")) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
jQuery.post(ajaxurl, { |
| 73 |
action: "wpbot_clear_all_feedback" |
| 74 |
}, function(response) { |
| 75 |
if (response.success) { |
| 76 |
jQuery("#wpbot-clear-feedback-msg").text(response.data.message).css("color", "green"); |
| 77 |
location.reload(); |
| 78 |
} else { |
| 79 |
jQuery("#wpbot-clear-feedback-msg").text(response.data.message).css("color", "red"); |
| 80 |
} |
| 81 |
}); |
| 82 |
}); |
| 83 |
JS; |
| 84 |
|
| 85 |
wp_add_inline_script( 'qcld-wp-apexcharts', $inline_script ); |
| 86 |
} |
| 87 |
|
| 88 |
function qcld_history_reporting_menu_func() { |
| 89 |
$capability = function_exists( 'qcld_wpbot_get_menu_capability' ) ? qcld_wpbot_get_menu_capability( 'sessions' ) : 'publish_posts'; |
| 90 |
|
| 91 |
if ( current_user_can( $capability ) ) { |
| 92 |
add_submenu_page( 'wbcs-botsessions-page', 'Bot - Reports', 'Bot - Reports', $capability, 'wbcs-botsessions-reports', 'qcld_wpbot_reporting_page_cb' ); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
// Callback function for "Bot - Reports" menu |
| 97 |
function qcld_wpbot_reporting_page_cb() { |
| 98 |
require_once QCLD_WPCHATBOT_HISTORY_DIR_PATH . '/reports/view/reporting-highlights.php'; |
| 99 |
} |
| 100 |
|