$db->get_total_agents(), 'published_agents' => $db->get_published_agents(), 'unique_users' => $db->get_unique_users($timezone, $from, $to), 'total_interactions' => $db->get_total_interactions($timezone, $from, $to), ]; wp_send_json_success($data); } public function get_dashboard_timeseries() { if (!check_ajax_referer('aizl_dashboard', 'nonce', false)) { wp_send_json_error('Invalid nonce.'); return; } if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized', 403); } $timezone = isset($_POST['timezone']) ? sanitize_text_field(wp_unslash($_POST['timezone'])) : 'UTC'; $from = isset($_POST['from']) ? sanitize_text_field(wp_unslash($_POST['from'])) : null; $to = isset($_POST['to']) ? sanitize_text_field(wp_unslash($_POST['to'])) : null; $bucket = isset($_POST['bucket']) ? sanitize_text_field(wp_unslash($_POST['bucket'])) : 'day'; $db = new DBHandler(); $result = $db->get_timeseries_data($timezone, $from, $to, $bucket); wp_send_json_success($result); } public function get_agents_dashboard() { if (!check_ajax_referer('aizl_dashboard', 'nonce', false)) { wp_send_json_error('Invalid nonce.'); return; } if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized', 403); } $aizl_search = isset($_POST['search']) ? sanitize_text_field(wp_unslash($_POST['search'])) : ''; $aizl_sort = isset($_POST['sort']) ? sanitize_text_field(wp_unslash($_POST['sort'])) : 'name'; $aizl_order = isset($_POST['order']) ? sanitize_text_field(wp_unslash($_POST['order'])) : 'ASC'; $aizl_page = isset($_POST['page']) ? intval($_POST['page']) : 1; $aizl_per_page = isset($_POST['per_page']) ? intval($_POST['per_page']) : 10; $aizl_db = new DBHandler(); $aizl_result = $aizl_db->get_agents_dashboard($aizl_search, $aizl_sort, $aizl_order, $aizl_page, $aizl_per_page); wp_send_json_success($aizl_result); } public function get_conversation_history() { if (!check_ajax_referer('aizl_dashboard', 'nonce', false)) { wp_send_json_error('Invalid nonce.'); return; } if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized', 403); } $agent_id = isset($_POST['agent_id']) ? intval($_POST['agent_id']) : 0; if (!$agent_id) { wp_send_json_error('Missing agent_id', 400); } $timezone = isset($_POST['timezone']) ? sanitize_text_field(wp_unslash($_POST['timezone'])) : 'UTC'; $from = isset($_POST['from']) ? sanitize_text_field(wp_unslash($_POST['from'])) : null; $to = isset($_POST['to']) ? sanitize_text_field(wp_unslash($_POST['to'])) : null; $db = new DBHandler(); $result = $db->get_conversations($agent_id, $timezone, $from, $to); wp_send_json_success($result); } }