| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! current_user_can( 'administrator' ) ) { |
| 7 |
wp_die( esc_html__( 'You do not have permission to view this page.', 'mlsimport' ) ); |
| 8 |
} |
| 9 |
|
| 10 |
// Load WP_List_Table base class (admin-only; must not be loaded in mlsimport.php). |
| 11 |
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 12 |
// __FILE__ = mlsimport/admin/partials/mlsimport-history.php — dirname x3 = plugin root. |
| 13 |
require_once dirname( __FILE__, 3 ) . '/includes/class-mlsimport-activity-list-table.php'; |
| 14 |
|
| 15 |
// Filter GET keys — MUST match the keys read in Mlsimport_Activity_List_Table::prepare_items(). |
| 16 |
// 'mlsimport_action' = action filter; 'mlsimport_item' = import-task filter. |
| 17 |
$filter_action = isset( $_GET['mlsimport_action'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 18 |
? sanitize_text_field( wp_unslash( $_GET['mlsimport_action'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 19 |
: ''; |
| 20 |
|
| 21 |
$filter_item = isset( $_GET['mlsimport_item'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 22 |
? absint( $_GET['mlsimport_item'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 23 |
: 0; |
| 24 |
|
| 25 |
// Search term — matches Listing ID or ListingKey. Key 'mlsimport_s' MUST match prepare_items(). |
| 26 |
$filter_search = isset( $_GET['mlsimport_s'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 27 |
? trim( sanitize_text_field( wp_unslash( $_GET['mlsimport_s'] ) ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 28 |
: ''; |
| 29 |
|
| 30 |
$list_table = new Mlsimport_Activity_List_Table(); |
| 31 |
$list_table->prepare_items(); |
| 32 |
|
| 33 |
$import_task_options = $list_table->get_import_task_options(); |
| 34 |
?> |
| 35 |
<div class="wrap"> |
| 36 |
<h1><?php echo esc_html__( 'Import History', 'mlsimport' ); ?></h1> |
| 37 |
<p><?php echo esc_html__( 'Showing import activity from the last 30 days.', 'mlsimport' ); ?></p> |
| 38 |
|
| 39 |
<form method="get" action="" class="notice notice-info mlsimport-history-filters"> |
| 40 |
<input type="hidden" name="page" value="mlsimport_history"> |
| 41 |
|
| 42 |
<label for="mlsimport-search"><?php echo esc_html__( 'Search:', 'mlsimport' ); ?></label> |
| 43 |
<input type="search" id="mlsimport-search" name="mlsimport_s" value="<?php echo esc_attr( $filter_search ); ?>" placeholder="<?php echo esc_attr__( 'Listing ID or ListingKey', 'mlsimport' ); ?>"> |
| 44 |
|
| 45 |
<label for="mlsimport-action-filter"><?php echo esc_html__( 'Action:', 'mlsimport' ); ?></label> |
| 46 |
<select id="mlsimport-action-filter" name="mlsimport_action"> |
| 47 |
<option value=""><?php echo esc_html__( 'All', 'mlsimport' ); ?></option> |
| 48 |
<option value="added" <?php selected( $filter_action, 'added' ); ?>><?php echo esc_html__( 'Added', 'mlsimport' ); ?></option> |
| 49 |
<option value="edited" <?php selected( $filter_action, 'edited' ); ?>><?php echo esc_html__( 'Edited', 'mlsimport' ); ?></option> |
| 50 |
<option value="deleted" <?php selected( $filter_action, 'deleted' ); ?>><?php echo esc_html__( 'Deleted', 'mlsimport' ); ?></option> |
| 51 |
</select> |
| 52 |
|
| 53 |
<?php if ( ! empty( $import_task_options ) ) : ?> |
| 54 |
<label for="mlsimport-item-filter"><?php echo esc_html__( 'Import Task:', 'mlsimport' ); ?></label> |
| 55 |
<select id="mlsimport-item-filter" name="mlsimport_item"> |
| 56 |
<option value=""><?php echo esc_html__( 'All', 'mlsimport' ); ?></option> |
| 57 |
<?php foreach ( $import_task_options as $task_id => $task_title ) : ?> |
| 58 |
<?php |
| 59 |
// Skip any entry with an empty title — defensive guard (import_item_id=0 is excluded by get_import_task_options()). |
| 60 |
if ( '' === trim( (string) $task_title ) ) { |
| 61 |
continue; |
| 62 |
} |
| 63 |
?> |
| 64 |
<option value="<?php echo esc_attr( (string) $task_id ); ?>" <?php selected( $filter_item, $task_id ); ?>> |
| 65 |
<?php echo esc_html( $task_title ); ?> |
| 66 |
</option> |
| 67 |
<?php endforeach; ?> |
| 68 |
</select> |
| 69 |
<?php endif; ?> |
| 70 |
|
| 71 |
<?php submit_button( __( 'Filter', 'mlsimport' ), 'secondary', 'submit', false ); ?> |
| 72 |
</form> |
| 73 |
|
| 74 |
<?php $list_table->display(); ?> |
| 75 |
</div> |
| 76 |
|