Refactor: delete import csv

This commit is contained in:
2026-04-22 13:38:38 +02:00
parent b5b8fde31f
commit cb30dff841
5 changed files with 61 additions and 108 deletions
-31
View File
@@ -36,24 +36,6 @@ function statpress_add_admin_menu() {
'statpress_add_new_page' // Funkcja renderująca stronę dodawania 'statpress_add_new_page' // Funkcja renderująca stronę dodawania
); );
$statpress_plugin_hooks[] = add_submenu_page(
'statpress-dashboard',
'Typy Wydarzeń',
'Typy wydarzeń',
'manage_options',
'statpress-event-types',
'statpress_event_types_page'
);
$statpress_plugin_hooks[] = add_submenu_page(
'statpress-dashboard',
'Sprzęt',
'Sprzęt',
'manage_options',
'statpress-equipment',
'statpress_equipment_page'
);
$statpress_plugin_hooks[] = add_submenu_page( $statpress_plugin_hooks[] = add_submenu_page(
'statpress-dashboard', 'statpress-dashboard',
'Cele', 'Cele',
@@ -63,10 +45,6 @@ function statpress_add_admin_menu() {
'statpress_goals_page' 'statpress_goals_page'
); );
$statpress_plugin_hooks[] = add_submenu_page(
null, 'Dziennik Serwisowy', 'Dziennik Serwisowy', 'manage_options', 'statpress-equipment-details', 'statpress_equipment_details_page'
);
$statpress_plugin_hooks[] = add_submenu_page( $statpress_plugin_hooks[] = add_submenu_page(
null, // Ukryta strona, nie pojawia się w menu null, // Ukryta strona, nie pojawia się w menu
'Szczegóły Treningu', // Tytuł strony 'Szczegóły Treningu', // Tytuł strony
@@ -103,15 +81,6 @@ function statpress_add_admin_menu() {
'statpress_infographic_page' // Funkcja renderująca 'statpress_infographic_page' // Funkcja renderująca
); );
$statpress_plugin_hooks[] = add_submenu_page(
'statpress-dashboard', // Slug rodzica
'Import CSV', // Tytuł strony
'Import CSV', // Tytuł w podmenu
'manage_options', // Wymagane uprawnienia
'statpress-import-csv', // Slug podmenu
'statpress_import_csv_page' // Funkcja renderująca
);
$statpress_plugin_hooks[] = add_submenu_page( $statpress_plugin_hooks[] = add_submenu_page(
'statpress-dashboard', // Slug rodzica 'statpress-dashboard', // Slug rodzica
'Ustawienia', // Tytuł strony 'Ustawienia', // Tytuł strony
+4 -6
View File
@@ -91,8 +91,7 @@ function statpress_equipment_page() {
eq.status ASC, eq.name ASC" eq.status ASC, eq.name ASC"
); );
?> ?>
<div class="wrap"> <div class="statpress-tab-wrapper">
<h1>Zarządzaj Sprzętem</h1>
<?php if ( ! empty( $message ) ) : ?> <?php if ( ! empty( $message ) ) : ?>
<div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div> <div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div>
<?php endif; ?> <?php endif; ?>
@@ -124,7 +123,7 @@ function statpress_equipment_page() {
<tbody> <tbody>
<?php foreach ( $equipment_list as $item ) : ?> <?php foreach ( $equipment_list as $item ) : ?>
<?php <?php
$details_url = admin_url( 'admin.php?page=statpress-equipment-details&id=' . $item->id ); $details_url = admin_url( 'admin.php?page=statpress-settings&tab=equipment_details&id=' . $item->id );
?> ?>
<tr> <tr>
<td><strong><a href="<?php echo esc_url( $details_url ); ?>"><?php echo esc_html( $item->name ); ?></a></strong><br><small><?php echo esc_html( $item->type ); ?></small></td> <td><strong><a href="<?php echo esc_url( $details_url ); ?>"><?php echo esc_html( $item->name ); ?></a></strong><br><small><?php echo esc_html( $item->type ); ?></small></td>
@@ -215,9 +214,8 @@ function statpress_equipment_details_page() {
$log_types = array( 'Naprawa', 'Zakup części', 'Przegląd', 'Modyfikacja', 'Inne' ); $log_types = array( 'Naprawa', 'Zakup części', 'Przegląd', 'Modyfikacja', 'Inne' );
?> ?>
<div class="wrap"> <div class="statpress-tab-wrapper">
<h1>Dziennik serwisowy: <?php echo esc_html( $equipment->name ); ?></h1> <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=statpress-settings&tab=equipment' ) ); ?>" class="button">&larr; Powrót do listy sprzętu</a></p>
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=statpress-equipment' ) ); ?>">&larr; Powrót do listy sprzętu</a></p>
<?php if ( ! empty( $message ) ) : ?> <?php if ( ! empty( $message ) ) : ?>
<div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div> <div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div>
+1 -2
View File
@@ -47,8 +47,7 @@ function statpress_event_types_page() {
$event_types = $wpdb->get_results( "SELECT * FROM $table_event_types ORDER BY name ASC" ); $event_types = $wpdb->get_results( "SELECT * FROM $table_event_types ORDER BY name ASC" );
?> ?>
<div class="wrap"> <div class="statpress-tab-wrapper">
<h1>Typy Wydarzeń</h1>
<?php if ( ! empty( $message ) ) : ?> <?php if ( ! empty( $message ) ) : ?>
<div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div> <div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div>
<?php endif; ?> <?php endif; ?>
+56 -43
View File
@@ -4,70 +4,77 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
function statpress_settings_page() { function statpress_settings_page() {
$active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
?> ?>
<div class="wrap"> <div class="wrap">
<?php
if ( get_transient( 'statpress_migration_reset_notice' ) ) {
echo '<div class="notice notice-success is-dismissible"><p>Status migracji został zresetowany. Wróć do <a href="' . esc_url( admin_url( 'admin.php?page=statpress-dashboard' ) ) . '">głównego panelu</a>, aby ponownie uruchomić migrację.</p></div>';
delete_transient( 'statpress_migration_reset_notice' );
}
?>
<h1>Ustawienia Wtyczki Statystyk</h1> <h1>Ustawienia Wtyczki Statystyk</h1>
<form method="post" action="options.php"> <h2 class="nav-tab-wrapper">
<a href="?page=statpress-settings&tab=general" class="nav-tab <?php echo 'general' === $active_tab ? 'nav-tab-active' : ''; ?>">Ogólne i API</a>
<a href="?page=statpress-settings&tab=event_types" class="nav-tab <?php echo 'event_types' === $active_tab ? 'nav-tab-active' : ''; ?>">Typy wydarzeń</a>
<a href="?page=statpress-settings&tab=equipment" class="nav-tab <?php echo in_array( $active_tab, array( 'equipment', 'equipment_details' ), true ) ? 'nav-tab-active' : ''; ?>">Sprzęt i Dziennik</a>
</h2>
<div class="statpress-tab-content" style="margin-top: 20px;">
<?php <?php
settings_fields( 'statpress_settings_group' ); if ( 'general' === $active_tab ) {
do_settings_sections( 'statpress_settings_page' ); statpress_settings_general_tab();
submit_button(); } elseif ( 'event_types' === $active_tab ) {
if ( function_exists( 'statpress_event_types_page' ) ) {
statpress_event_types_page();
} else {
echo '<p>Brak funkcji zarządzania typami wydarzeń.</p>';
}
} elseif ( 'equipment' === $active_tab ) {
statpress_equipment_page();
} elseif ( 'equipment_details' === $active_tab ) {
statpress_equipment_details_page();
}
?> ?>
</form>
<hr>
<h2>Narzędzia deweloperskie</h2>
<div class="postbox">
<div class="postbox-header"><h3 class="hndle">Resetowanie migracji</h3></div>
<div class="inside">
<p>Jeśli migracja danych nie powiodła się, a przycisk do jej ponownego uruchomienia zniknął, możesz użyć tego narzędzia, aby zresetować status migracji. Po kliknięciu, przycisk w głównym panelu wtyczki pojawi się ponownie.</p>
<form method="post">
<input type="hidden" name="statpress_action" value="reset_migration"><?php wp_nonce_field( 'statpress_reset_migration_nonce', '_wpnonce' ); ?><?php submit_button( 'Zresetuj status migracji', 'delete' ); ?></form>
</div>
</div> </div>
</div>
<?php
}
function statpress_settings_general_tab() {
?>
<div class="postbox">
<div class="postbox-header"><h2 class="hndle">Konfiguracja główna</h2></div>
<div class="inside">
<form method="post" action="options.php">
<?php
settings_fields( 'statpress_privacy_settings' );
do_settings_sections( 'statpress-privacy-section' );
settings_fields( 'statpress_api_settings' );
do_settings_sections( 'statpress-api-section' );
?>
<hr>
<?php submit_button( 'Zapisz ustawienia' ); ?>
</form>
</div>
</div> </div>
<?php <?php
} }
function statpress_register_settings() { function statpress_register_settings() {
// Define a single group and page for all settings on this form.
$option_group = 'statpress_settings_group';
$page_slug = 'statpress_settings_page';
// Register Privacy settings under the main group.
register_setting( register_setting(
$option_group, 'statpress_privacy_settings',
'statpress_privacy_options', 'statpress_privacy_options',
'statpress_sanitize_privacy_options' 'statpress_sanitize_privacy_options'
); );
// Register API settings under the same main group.
register_setting(
$option_group,
'statpress_api_options',
'statpress_sanitize_api_options'
);
// Add the Privacy section to the main page.
add_settings_section( add_settings_section(
'statpress_privacy_zone_section', 'statpress_privacy_zone_section',
'Strefa Prywatności GPX', 'Strefa Prywatności GPX',
'statpress_privacy_section_callback', 'statpress_privacy_section_callback',
$page_slug 'statpress-privacy-section'
); );
add_settings_field( add_settings_field(
'statpress_privacy_latitude', 'statpress_privacy_latitude',
'Szerokość geograficzna (Latitude)', 'Szerokość geograficzna (Latitude)',
'statpress_render_lat_field', 'statpress_render_lat_field',
$page_slug, 'statpress-privacy-section',
'statpress_privacy_zone_section' 'statpress_privacy_zone_section'
); );
@@ -75,7 +82,7 @@ function statpress_register_settings() {
'statpress_privacy_longitude', 'statpress_privacy_longitude',
'Długość geograficzna (Longitude)', 'Długość geograficzna (Longitude)',
'statpress_render_lon_field', 'statpress_render_lon_field',
$page_slug, 'statpress-privacy-section',
'statpress_privacy_zone_section' 'statpress_privacy_zone_section'
); );
@@ -83,24 +90,30 @@ function statpress_register_settings() {
'statpress_privacy_radius', 'statpress_privacy_radius',
'Promień strefy (w metrach)', 'Promień strefy (w metrach)',
'statpress_render_radius_field', 'statpress_render_radius_field',
$page_slug, 'statpress-privacy-section',
'statpress_privacy_zone_section' 'statpress_privacy_zone_section'
); );
// Add the API section to the same main page. // API Settings
register_setting(
'statpress_api_settings',
'statpress_api_options',
'statpress_sanitize_api_options'
);
add_settings_section( add_settings_section(
'statpress_api_section', 'statpress_api_section',
'Ustawienia API', 'Ustawienia API',
'statpress_api_section_callback', 'statpress_api_section_callback',
$page_slug 'statpress-api-section'
); );
add_settings_field( add_settings_field(
'statpress_enable_api', 'statpress_enable_api',
'REST API', 'REST API',
'statpress_render_enable_api_field', 'statpress_render_enable_api_field',
$page_slug, 'statpress-privacy-section',
'statpress_api_section' 'statpress_privacy_zone_section'
); );
} }
-26
View File
@@ -34,7 +34,6 @@ require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-goals.php';
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-settings.php'; require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-settings.php';
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-yearly-summary.php'; require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-yearly-summary.php';
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-infographic.php'; require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-infographic.php';
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-import-csv.php';
global $statpress_plugin_hooks; global $statpress_plugin_hooks;
$statpress_plugin_hooks = array(); $statpress_plugin_hooks = array();
@@ -74,7 +73,6 @@ function statpress_enqueue_frontend_material_assets() {
// --- 5. MIGRACJA DANYCH (jednorazowa) --- // --- 5. MIGRACJA DANYCH (jednorazowa) ---
add_action( 'admin_init', 'statpress_handle_data_migration' ); add_action( 'admin_init', 'statpress_handle_data_migration' );
add_action( 'admin_init', 'statpress_handle_admin_tools' );
/** /**
* Handles the one-time data migration from 'mystat_' tables to 'statpress_' tables. * Handles the one-time data migration from 'mystat_' tables to 'statpress_' tables.
@@ -156,27 +154,3 @@ function statpress_handle_data_migration() {
wp_safe_redirect( admin_url( 'admin.php?page=statpress-dashboard' ) ); wp_safe_redirect( admin_url( 'admin.php?page=statpress-dashboard' ) );
exit; exit;
} }
/**
* Handles various admin tool actions, like resetting the migration flag.
*/
function statpress_handle_admin_tools() {
// Check if the reset migration action is triggered
if ( isset( $_POST['statpress_action'] ) && 'reset_migration' === $_POST['statpress_action'] ) {
// Verify nonce and permissions
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'statpress_reset_migration_nonce' ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Delete the option that hides the migration button
delete_option( 'statpress_migration_complete' );
// Set a transient to show a success notice on the settings page
set_transient( 'statpress_migration_reset_notice', true, 60 );
wp_safe_redirect( admin_url( 'admin.php?page=statpress-settings' ) );
exit;
}
}