public function get_log_detail_ajax() { check_ajax_referer( 'gmtp_ai_log_detail', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $log = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $log_id ) ); if ( ! $log ) { wp_send_json_error( 'Log not found' ); } $html = '
Session: ' . esc_html( $log->session_id ) . '
'; $html .= 'Time: ' . $log->created_at . '
'; $html .= 'IP: ' . esc_html( $log->visitor_ip ) . '
'; $html .= 'User Agent: ' . esc_html( $log->visitor_agent ) . '
'; $html .= 'User Message:
' . nl2br( esc_html( $log->user_message ) ) . '
Bot Reply:
' . nl2br( esc_html( $log->bot_message ) ) . '
Intent: ' . esc_html( $log->intent ) . '
'; wp_send_json_success( $html ); } public function get_log_for_edit_ajax() { check_ajax_referer( 'gmtp_ai_edit_log', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $log = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $log_id ) ); if ( ! $log ) { wp_send_json_error( 'Log not found' ); } $data = array( 'id' => $log->id, 'user_message' => $log->user_message, 'bot_message' => $log->bot_message, 'intent' => $log->intent, 'visitor_ip' => $log->visitor_ip, 'visitor_agent' => $log->visitor_agent, ); wp_send_json_success( $data ); } public function edit_log_ajax() { check_ajax_referer( 'gmtp_ai_edit_log', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); $user_message = sanitize_textarea_field( $_POST['user_message'] ); $bot_message = sanitize_textarea_field( $_POST['bot_message'] ); $intent = sanitize_text_field( $_POST['intent'] ); $visitor_ip = sanitize_text_field( $_POST['visitor_ip'] ); $visitor_agent = sanitize_text_field( $_POST['visitor_agent'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $result = $wpdb->update( $table, array( 'user_message' => $user_message, 'bot_message' => $bot_message, 'intent' => $intent, 'visitor_ip' => $visitor_ip, 'visitor_agent' => $visitor_agent, ), array( 'id' => $log_id ), array( '%s', '%s', '%s', '%s', '%s' ), array( '%d' ) ); if ( $result !== false ) { wp_send_json_success( 'Log updated.' ); } else { wp_send_json_error( 'Database error.' ); } }public function get_log_detail_ajax() { check_ajax_referer( 'gmtp_ai_log_detail', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $log = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $log_id ) ); if ( ! $log ) { wp_send_json_error( 'Log not found' ); } $html = 'Session: ' . esc_html( $log->session_id ) . '
'; $html .= 'Time: ' . $log->created_at . '
'; $html .= 'IP: ' . esc_html( $log->visitor_ip ) . '
'; $html .= 'User Agent: ' . esc_html( $log->visitor_agent ) . '
'; $html .= 'User Message:
' . nl2br( esc_html( $log->user_message ) ) . '
Bot Reply:
' . nl2br( esc_html( $log->bot_message ) ) . '
Intent: ' . esc_html( $log->intent ) . '
'; wp_send_json_success( $html ); } public function get_log_for_edit_ajax() { check_ajax_referer( 'gmtp_ai_edit_log', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $log = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $log_id ) ); if ( ! $log ) { wp_send_json_error( 'Log not found' ); } $data = array( 'id' => $log->id, 'user_message' => $log->user_message, 'bot_message' => $log->bot_message, 'intent' => $log->intent, 'visitor_ip' => $log->visitor_ip, 'visitor_agent' => $log->visitor_agent, ); wp_send_json_success( $data ); } public function edit_log_ajax() { check_ajax_referer( 'gmtp_ai_edit_log', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'Unauthorized' ); } $log_id = intval( $_POST['log_id'] ); $user_message = sanitize_textarea_field( $_POST['user_message'] ); $bot_message = sanitize_textarea_field( $_POST['bot_message'] ); $intent = sanitize_text_field( $_POST['intent'] ); $visitor_ip = sanitize_text_field( $_POST['visitor_ip'] ); $visitor_agent = sanitize_text_field( $_POST['visitor_agent'] ); global $wpdb; $table = $wpdb->prefix . 'gmtp_ai_chat_logs'; $result = $wpdb->update( $table, array( 'user_message' => $user_message, 'bot_message' => $bot_message, 'intent' => $intent, 'visitor_ip' => $visitor_ip, 'visitor_agent' => $visitor_agent, ), array( 'id' => $log_id ), array( '%s', '%s', '%s', '%s', '%s' ), array( '%d' ) ); if ( $result !== false ) { wp_send_json_success( 'Log updated.' ); } else { wp_send_json_error( 'Database error.' ); } }