/* ========================= UPDATE STATUS (AJAX) ========================= */ public function update_status() { if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } if (!isset($_POST['id']) || !isset($_POST['status'])) { wp_send_json_error('Missing data'); } global $wpdb; $table = $wpdb->prefix . 'bnl_inquiries'; $updated = $wpdb->update( $table, [ 'status' => sanitize_text_field($_POST['status']) ], [ 'id' => intval($_POST['id']) ] ); if ($updated !== false) { wp_send_json_success(); } else { wp_send_json_error('Database update failed'); } } /* ========================= DELETE INQUIRY ========================= */ public function delete_inquiry() { if (!current_user_can('manage_options')) { wp_die('Unauthorized'); } if (!isset($_GET['id'])) { wp_die('Missing ID'); } global $wpdb; $table = $wpdb->prefix . 'bnl_inquiries'; $wpdb->delete( $table, [ 'id' => intval($_GET['id']) ] ); wp_redirect(admin_url('admin.php?page=bnlpro_inquiries')); exit; } /* ========================= EXPORT INQUIRIES (CSV) ========================= */ public function export_inquiries() { if (!current_user_can('manage_options')) { wp_die('Unauthorized'); } global $wpdb; $table = $wpdb->prefix . 'bnl_inquiries'; $rows = $wpdb->get_results("SELECT * FROM $table ORDER BY created_at DESC", ARRAY_A); if (empty($rows)) { wp_die('No data available'); } header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=bnl-inquiries-' . date('Y-m-d') . '.csv'); $output = fopen('php://output', 'w'); // Headers fputcsv($output, array_keys($rows[0])); // Rows foreach ($rows as $row) { fputcsv($output, $row); } fclose($output); exit; }