| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- if (!defined('WPINC')) {
- die;
- }
- /** @var array $records */
- /** @var int $total */
- /** @var int $total_pages */
- /** @var int $current_page */
- /** @var string $current_status */
- /** @var int $current_product */
- /** @var int $current_order */
- /** @var string $current_search */
- /** @var int $per_page */
- /** @var array $fpp_products */
- /** @var string $current_orderby */
- /** @var string $current_order_dir */
- $base_url = admin_url('edit.php?post_type=product&page=studiou-fpp-summary');
- // Build the base filter state that must survive on sort/pagination links
- $filter_state = array(
- 'post_type' => 'product',
- 'page' => 'studiou-fpp-summary',
- );
- if ($current_status) $filter_state['status'] = $current_status;
- if ($current_product) $filter_state['product_id'] = $current_product;
- if ($current_order) $filter_state['order_id'] = $current_order;
- if ($current_search) $filter_state['s'] = $current_search;
- /**
- * Produce a <th> cell for a sortable column: toggles asc/desc and preserves filters.
- */
- $sort_header = function ($column_key, $label) use ($filter_state, $current_orderby, $current_order_dir) {
- $is_active = ($current_orderby === $column_key);
- $next_dir = ($is_active && $current_order_dir === 'ASC') ? 'DESC' : 'ASC';
- if ($is_active && $current_order_dir === 'DESC') {
- // If currently DESC, next click should flip to ASC
- $next_dir = 'ASC';
- } elseif (!$is_active) {
- // Fresh click on a non-active column defaults to DESC for date/order, ASC feels odd
- $next_dir = ($column_key === 'created_at' || $column_key === 'order_id') ? 'DESC' : 'ASC';
- }
- $args = $filter_state;
- $args['orderby'] = $column_key;
- $args['order'] = $next_dir;
- $url = add_query_arg($args, admin_url('edit.php'));
- $th_class = 'manage-column column-' . esc_attr($column_key) . ' sortable ';
- if ($is_active) {
- $th_class .= 'sorted ' . strtolower($current_order_dir);
- } else {
- $th_class .= 'desc';
- }
- ?>
- <th class="<?php echo $th_class; ?>">
- <a href="<?php echo esc_url($url); ?>">
- <span><?php echo esc_html($label); ?></span>
- <span class="sorting-indicator"></span>
- </a>
- </th>
- <?php
- };
- ?>
- <div class="wrap studiou-fpp-admin-wrap">
- <h1><?php esc_html_e('Free Photo Files', 'studiou-wc-free-photo-product'); ?></h1>
- <div class="studiou-fpp-admin-notice-area"></div>
- <!-- Filters -->
- <div class="studiou-fpp-filters">
- <form method="get" action="<?php echo esc_url(admin_url('edit.php')); ?>">
- <input type="hidden" name="post_type" value="product" />
- <input type="hidden" name="page" value="studiou-fpp-summary" />
- <input type="hidden" name="orderby" value="<?php echo esc_attr($current_orderby); ?>" />
- <input type="hidden" name="order" value="<?php echo esc_attr($current_order_dir); ?>" />
- <select name="status">
- <option value=""><?php esc_html_e('All Statuses', 'studiou-wc-free-photo-product'); ?></option>
- <option value="ready" <?php selected($current_status, 'ready'); ?>><?php esc_html_e('Ready', 'studiou-wc-free-photo-product'); ?></option>
- <option value="downloaded" <?php selected($current_status, 'downloaded'); ?>><?php esc_html_e('Downloaded', 'studiou-wc-free-photo-product'); ?></option>
- <option value="solved" <?php selected($current_status, 'solved'); ?>><?php esc_html_e('Solved', 'studiou-wc-free-photo-product'); ?></option>
- </select>
- <select name="product_id">
- <option value=""><?php esc_html_e('All Products', 'studiou-wc-free-photo-product'); ?></option>
- <?php foreach ($fpp_products as $pid => $pname) : ?>
- <option value="<?php echo esc_attr($pid); ?>" <?php selected($current_product, $pid); ?>><?php echo esc_html($pname); ?></option>
- <?php endforeach; ?>
- </select>
- <input type="number" name="order_id" min="0" step="1" value="<?php echo $current_order ? esc_attr($current_order) : ''; ?>" placeholder="<?php esc_attr_e('Order #', 'studiou-wc-free-photo-product'); ?>" class="studiou-fpp-filter-order" />
- <input type="search" name="s" value="<?php echo esc_attr($current_search); ?>" placeholder="<?php esc_attr_e('Search file name...', 'studiou-wc-free-photo-product'); ?>" />
- <button type="submit" class="button"><?php esc_html_e('Filter', 'studiou-wc-free-photo-product'); ?></button>
- </form>
- </div>
- <!-- Bulk actions -->
- <div class="studiou-fpp-bulk-actions">
- <select id="studiou-fpp-bulk-action">
- <option value=""><?php esc_html_e('Bulk Actions', 'studiou-wc-free-photo-product'); ?></option>
- <option value="download_zip"><?php esc_html_e('Download ZIP', 'studiou-wc-free-photo-product'); ?></option>
- <option value="download_csv"><?php esc_html_e('Download as CSV', 'studiou-wc-free-photo-product'); ?></option>
- <option value="status_ready"><?php esc_html_e('Set Status: Ready', 'studiou-wc-free-photo-product'); ?></option>
- <option value="status_downloaded"><?php esc_html_e('Set Status: Downloaded', 'studiou-wc-free-photo-product'); ?></option>
- <option value="status_solved"><?php esc_html_e('Set Status: Solved', 'studiou-wc-free-photo-product'); ?></option>
- <option value="delete"><?php esc_html_e('Delete', 'studiou-wc-free-photo-product'); ?></option>
- </select>
- <button type="button" class="button" id="studiou-fpp-bulk-apply"><?php esc_html_e('Apply', 'studiou-wc-free-photo-product'); ?></button>
- <span class="spinner" id="studiou-fpp-bulk-spinner"></span>
- <span class="studiou-fpp-total-count">
- <?php echo esc_html(sprintf(
- _n('%d file', '%d files', $total, 'studiou-wc-free-photo-product'),
- $total
- )); ?>
- </span>
- </div>
- <!-- Files table -->
- <table class="wp-list-table widefat fixed striped studiou-fpp-files-table">
- <thead>
- <tr>
- <td class="manage-column column-cb check-column">
- <input type="checkbox" id="studiou-fpp-select-all" />
- </td>
- <th class="column-thumbnail"><?php esc_html_e('Preview', 'studiou-wc-free-photo-product'); ?></th>
- <th class="column-filename"><?php esc_html_e('File Name', 'studiou-wc-free-photo-product'); ?></th>
- <th class="column-product"><?php esc_html_e('Product', 'studiou-wc-free-photo-product'); ?></th>
- <?php $sort_header('order_id', __('Order', 'studiou-wc-free-photo-product')); ?>
- <th class="column-customer"><?php esc_html_e('Customer', 'studiou-wc-free-photo-product'); ?></th>
- <?php $sort_header('status', __('Status', 'studiou-wc-free-photo-product')); ?>
- <?php $sort_header('created_at', __('Date', 'studiou-wc-free-photo-product')); ?>
- <th class="column-actions"><?php esc_html_e('Actions', 'studiou-wc-free-photo-product'); ?></th>
- </tr>
- </thead>
- <tbody>
- <?php if (empty($records)) : ?>
- <tr>
- <td colspan="9"><?php esc_html_e('No files found.', 'studiou-wc-free-photo-product'); ?></td>
- </tr>
- <?php else : ?>
- <?php foreach ($records as $record) :
- $attachment_url = wp_get_attachment_url($record->attachment_id);
- $thumb = wp_get_attachment_image_src($record->attachment_id, 'thumbnail');
- $thumb_url = $thumb ? $thumb[0] : wp_mime_type_icon($record->attachment_id);
- $product_title = get_the_title($record->product_id);
- $customer_name = '';
- if ($record->customer_id > 0) {
- $user = get_userdata($record->customer_id);
- $customer_name = $user ? $user->display_name : '#' . $record->customer_id;
- } else {
- $customer_name = __('Guest', 'studiou-wc-free-photo-product');
- }
- $order_link = '';
- if ($record->order_id > 0) {
- $order_url = Studiou_WC_FPP_Admin::get_order_edit_url($record->order_id);
- $order_link = '<a href="' . esc_url($order_url) . '">#' . esc_html($record->order_id) . '</a>';
- } else {
- $order_link = '<span class="studiou-fpp-no-order">—</span>';
- }
- // Download URL that also marks file as downloaded
- $download_url = add_query_arg(array(
- 'studiou_fpp_download_file' => 1,
- 'file_record_id' => $record->id,
- 'attachment_id' => $record->attachment_id,
- '_wpnonce' => wp_create_nonce('studiou-fpp-download-file'),
- ), admin_url('admin.php'));
- ?>
- <tr data-file-id="<?php echo esc_attr($record->id); ?>">
- <th scope="row" class="check-column">
- <input type="checkbox" class="studiou-fpp-file-cb" value="<?php echo esc_attr($record->id); ?>" />
- </th>
- <td class="column-thumbnail">
- <img src="<?php echo esc_url($thumb_url); ?>" alt="" class="studiou-fpp-thumb" />
- </td>
- <td class="column-filename">
- <?php if ($attachment_url) : ?>
- <a href="<?php echo esc_url($attachment_url); ?>" target="_blank"><?php echo esc_html($record->file_name); ?></a>
- <?php else : ?>
- <?php echo esc_html($record->file_name); ?>
- <?php endif; ?>
- </td>
- <td class="column-product">
- <a href="<?php echo esc_url(get_edit_post_link($record->product_id)); ?>"><?php echo esc_html($product_title); ?></a>
- </td>
- <td class="column-order">
- <?php echo $order_link; ?>
- </td>
- <td class="column-customer">
- <?php echo esc_html($customer_name); ?>
- </td>
- <td class="column-status">
- <select class="studiou-fpp-status-select" data-file-id="<?php echo esc_attr($record->id); ?>">
- <option value="ready" <?php selected($record->status, 'ready'); ?>><?php esc_html_e('Ready', 'studiou-wc-free-photo-product'); ?></option>
- <option value="downloaded" <?php selected($record->status, 'downloaded'); ?>><?php esc_html_e('Downloaded', 'studiou-wc-free-photo-product'); ?></option>
- <option value="solved" <?php selected($record->status, 'solved'); ?>><?php esc_html_e('Solved', 'studiou-wc-free-photo-product'); ?></option>
- </select>
- </td>
- <td class="column-date">
- <?php echo esc_html(date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($record->created_at))); ?>
- </td>
- <td class="column-actions">
- <?php if ($attachment_url) : ?>
- <a href="<?php echo esc_url($download_url); ?>" class="button button-small" title="<?php esc_attr_e('Download', 'studiou-wc-free-photo-product'); ?>">
- <span class="dashicons dashicons-download" style="line-height:1.4;"></span>
- </a>
- <?php endif; ?>
- <button type="button" class="button button-small studiou-fpp-delete-single" data-file-id="<?php echo esc_attr($record->id); ?>" title="<?php esc_attr_e('Delete', 'studiou-wc-free-photo-product'); ?>">
- <span class="dashicons dashicons-trash" style="line-height:1.4;color:#b32d2e;"></span>
- </button>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php endif; ?>
- </tbody>
- </table>
- <!-- Pagination -->
- <?php if ($total_pages > 1) : ?>
- <div class="tablenav bottom">
- <div class="tablenav-pages">
- <span class="displaying-num">
- <?php echo esc_html(sprintf(
- _n('%d file', '%d files', $total, 'studiou-wc-free-photo-product'),
- $total
- )); ?>
- </span>
- <?php
- // Preserve filters + active sort across pagination
- $pagination_args = $filter_state;
- $pagination_args['orderby'] = $current_orderby;
- $pagination_args['order'] = $current_order_dir;
- $pagination = paginate_links(array(
- 'base' => add_query_arg('paged', '%#%', admin_url('edit.php?' . http_build_query($pagination_args))),
- 'format' => '',
- 'current' => $current_page,
- 'total' => $total_pages,
- 'prev_text' => '«',
- 'next_text' => '»',
- ));
- if ($pagination) {
- echo $pagination;
- }
- ?>
- </div>
- </div>
- <?php endif; ?>
- </div>
|