save_settings(); } // Récupérer les paramètres actuels $settings = get_option('almaweb_settings', array()); // Enqueue inline script pour les actions AJAX $settings_script = 'jQuery(document).ready(function($) { $("#cleanup-old-logs").on("click", function() { if (confirm("' . esc_js(__('Are you sure you want to clean old logs?', 'almaweb-ai-visitor-analytics')) . '")) { $.post(ajaxurl, { action: "Almaweb_cleanup", nonce: "' . wp_create_nonce('Almaweb_cleanup') . '" }, function(response) { if (response.success) { alert(response.data.message); location.reload(); } else { alert("Erreur: " + response.data.message); } }); } }); $("#reset-all-data").on("click", function() { if (confirm("' . esc_js(__('WARNING: This will delete ALL data! Are you absolutely sure?', 'almaweb-ai-visitor-analytics')) . '")) { if (confirm("' . esc_js(__('Final confirmation: This action is IRREVERSIBLE!', 'almaweb-ai-visitor-analytics')) . '")) { var $button = $(this); $button.prop("disabled", true).text("' . esc_js(__('Deleting...', 'almaweb-ai-visitor-analytics')) . '"); $.post(ajaxurl, { action: "Almaweb_reset", nonce: "' . wp_create_nonce('Almaweb_reset') . '" }, function(response) { if (response.success) { alert(response.data.message); location.reload(); } else { alert("Erreur: " + response.data.message); $button.prop("disabled", false).text("' . esc_js(__('Delete all', 'almaweb-ai-visitor-analytics')) . '"); } }).fail(function(xhr, status, error) { alert("Erreur de connexion: " + error); console.error("AJAX Error:", xhr.responseText); $button.prop("disabled", false).text("' . esc_js(__('⚠️ Delete all', 'almaweb-ai-visitor-analytics')) . '"); }); } } }); });'; wp_add_inline_script('almaweb-ai-visitor-analytics-admin', $settings_script); ?>

db_version()); ?>
get_total_logs()); ?>
isset($_POST['track_enabled']) ? true : false, 'track_registered_users' => isset($_POST['track_registered_users']) ? true : false, 'retention_days' => isset($_POST['retention_days']) ? intval(wp_unslash($_POST['retention_days'])) : 90, ); update_option('almaweb_settings', $settings); add_settings_error( 'Almaweb_settings', 'settings_updated', __('Settings saved successfully.', 'almaweb-ai-visitor-analytics'), 'updated' ); settings_errors('Almaweb_settings'); } } // Ajouter les actions AJAX add_action('wp_ajax_Almaweb_cleanup', 'Almaweb_ajax_cleanup'); add_action('wp_ajax_Almaweb_reset', 'Almaweb_ajax_reset'); function Almaweb_ajax_cleanup() { check_ajax_referer('Almaweb_cleanup', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'Unauthorized')); } $settings = get_option('almaweb_settings'); $database = new Almaweb_Database(); $deleted = $database->cleanup_old_logs($settings['retention_days'] ?? 90); wp_send_json_success(array( // translators: %d is the number of deleted logs 'message' => sprintf(__('%d logs deleted.', 'almaweb-ai-visitor-analytics'), $deleted) )); } function Almaweb_ajax_reset() { check_ajax_referer('Almaweb_reset', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'Unauthorized')); } global $wpdb; $table_name = $wpdb->prefix . 'ai_monitor_logs'; $wpdb->query("TRUNCATE TABLE {$table_name}"); wp_send_json_success(array( 'message' => __('All data has been deleted.', 'almaweb-ai-visitor-analytics') )); }