MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.31
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/royaltuning/public_html/public/wp-content/plugins/zero-spam/assets/js/network-stats.js
/**
 * Network Statistics Page JavaScript
 */

(function ($) {
	'use strict';

	$(document).ready(function () {
		// Period change
		$('#period-select').on('change', function () {
			const period = $(this).val();
			window.location.href = window.location.pathname + '?page=wordpress-zero-spam-network-stats&period=' + period;
		});

		// Export CSV
		$('.export-stats').on('click', function (e) {
			e.preventDefault();

			const period = $('#period-select').val();

			$.ajax({
				url: zerospamNetworkStats.ajaxUrl,
				type: 'POST',
				data: {
					action: 'zerospam_export_network_stats',
					nonce: zerospamNetworkStats.nonce,
					period: period,
				},
				success: function (response) {
					if (response.success && response.data.csv) {
						// Convert to CSV string
						let csvContent = '';
						response.data.csv.forEach(function (row) {
							csvContent += row.map(val => `"${val}"`).join(',') + '\n';
						});

						// Download
						const blob = new Blob([csvContent], { type: 'text/csv' });
						const url = window.URL.createObjectURL(blob);
						const a = document.createElement('a');
						a.href = url;
						a.download = response.data.filename;
						document.body.appendChild(a);
						a.click();
						document.body.removeChild(a);
						window.URL.revokeObjectURL(url);
					} else {
						alert('Failed to export data');
					}
				},
				error: function () {
					alert('Failed to export data');
				},
			});
		});
	});
})(jQuery);