admin-summary.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. if (!defined('WPINC')) {
  3. die;
  4. }
  5. /** @var array $records */
  6. /** @var int $total */
  7. /** @var int $total_pages */
  8. /** @var int $current_page */
  9. /** @var string $current_status */
  10. /** @var int $current_product */
  11. /** @var string $current_search */
  12. /** @var int $per_page */
  13. /** @var array $fpp_products */
  14. $base_url = admin_url('edit.php?post_type=product&page=studiou-fpp-summary');
  15. ?>
  16. <div class="wrap studiou-fpp-admin-wrap">
  17. <h1><?php esc_html_e('Free Photo Files', 'studiou-wc-free-photo-product'); ?></h1>
  18. <div class="studiou-fpp-admin-notice-area"></div>
  19. <!-- Filters -->
  20. <div class="studiou-fpp-filters">
  21. <form method="get" action="<?php echo esc_url(admin_url('edit.php')); ?>">
  22. <input type="hidden" name="post_type" value="product" />
  23. <input type="hidden" name="page" value="studiou-fpp-summary" />
  24. <select name="status">
  25. <option value=""><?php esc_html_e('All Statuses', 'studiou-wc-free-photo-product'); ?></option>
  26. <option value="ready" <?php selected($current_status, 'ready'); ?>><?php esc_html_e('Ready', 'studiou-wc-free-photo-product'); ?></option>
  27. <option value="downloaded" <?php selected($current_status, 'downloaded'); ?>><?php esc_html_e('Downloaded', 'studiou-wc-free-photo-product'); ?></option>
  28. <option value="solved" <?php selected($current_status, 'solved'); ?>><?php esc_html_e('Solved', 'studiou-wc-free-photo-product'); ?></option>
  29. </select>
  30. <select name="product_id">
  31. <option value=""><?php esc_html_e('All Products', 'studiou-wc-free-photo-product'); ?></option>
  32. <?php foreach ($fpp_products as $pid => $pname) : ?>
  33. <option value="<?php echo esc_attr($pid); ?>" <?php selected($current_product, $pid); ?>><?php echo esc_html($pname); ?></option>
  34. <?php endforeach; ?>
  35. </select>
  36. <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'); ?>" />
  37. <button type="submit" class="button"><?php esc_html_e('Filter', 'studiou-wc-free-photo-product'); ?></button>
  38. </form>
  39. </div>
  40. <!-- Bulk actions -->
  41. <div class="studiou-fpp-bulk-actions">
  42. <select id="studiou-fpp-bulk-action">
  43. <option value=""><?php esc_html_e('Bulk Actions', 'studiou-wc-free-photo-product'); ?></option>
  44. <option value="download_zip"><?php esc_html_e('Download ZIP', 'studiou-wc-free-photo-product'); ?></option>
  45. <option value="status_ready"><?php esc_html_e('Set Status: Ready', 'studiou-wc-free-photo-product'); ?></option>
  46. <option value="status_downloaded"><?php esc_html_e('Set Status: Downloaded', 'studiou-wc-free-photo-product'); ?></option>
  47. <option value="status_solved"><?php esc_html_e('Set Status: Solved', 'studiou-wc-free-photo-product'); ?></option>
  48. <option value="delete"><?php esc_html_e('Delete', 'studiou-wc-free-photo-product'); ?></option>
  49. </select>
  50. <button type="button" class="button" id="studiou-fpp-bulk-apply"><?php esc_html_e('Apply', 'studiou-wc-free-photo-product'); ?></button>
  51. <span class="spinner" id="studiou-fpp-bulk-spinner"></span>
  52. <span class="studiou-fpp-total-count">
  53. <?php echo esc_html(sprintf(
  54. _n('%d file', '%d files', $total, 'studiou-wc-free-photo-product'),
  55. $total
  56. )); ?>
  57. </span>
  58. </div>
  59. <!-- Files table -->
  60. <table class="wp-list-table widefat fixed striped studiou-fpp-files-table">
  61. <thead>
  62. <tr>
  63. <td class="manage-column column-cb check-column">
  64. <input type="checkbox" id="studiou-fpp-select-all" />
  65. </td>
  66. <th class="column-thumbnail"><?php esc_html_e('Preview', 'studiou-wc-free-photo-product'); ?></th>
  67. <th class="column-filename"><?php esc_html_e('File Name', 'studiou-wc-free-photo-product'); ?></th>
  68. <th class="column-product"><?php esc_html_e('Product', 'studiou-wc-free-photo-product'); ?></th>
  69. <th class="column-order"><?php esc_html_e('Order', 'studiou-wc-free-photo-product'); ?></th>
  70. <th class="column-customer"><?php esc_html_e('Customer', 'studiou-wc-free-photo-product'); ?></th>
  71. <th class="column-status"><?php esc_html_e('Status', 'studiou-wc-free-photo-product'); ?></th>
  72. <th class="column-date"><?php esc_html_e('Date', 'studiou-wc-free-photo-product'); ?></th>
  73. <th class="column-actions"><?php esc_html_e('Actions', 'studiou-wc-free-photo-product'); ?></th>
  74. </tr>
  75. </thead>
  76. <tbody>
  77. <?php if (empty($records)) : ?>
  78. <tr>
  79. <td colspan="9"><?php esc_html_e('No files found.', 'studiou-wc-free-photo-product'); ?></td>
  80. </tr>
  81. <?php else : ?>
  82. <?php foreach ($records as $record) :
  83. $attachment_url = wp_get_attachment_url($record->attachment_id);
  84. $thumb = wp_get_attachment_image_src($record->attachment_id, 'thumbnail');
  85. $thumb_url = $thumb ? $thumb[0] : wp_mime_type_icon($record->attachment_id);
  86. $product_title = get_the_title($record->product_id);
  87. $customer_name = '';
  88. if ($record->customer_id > 0) {
  89. $user = get_userdata($record->customer_id);
  90. $customer_name = $user ? $user->display_name : '#' . $record->customer_id;
  91. } else {
  92. $customer_name = __('Guest', 'studiou-wc-free-photo-product');
  93. }
  94. $order_link = '';
  95. if ($record->order_id > 0) {
  96. $order_url = Studiou_WC_FPP_Admin::get_order_edit_url($record->order_id);
  97. $order_link = '<a href="' . esc_url($order_url) . '">#' . esc_html($record->order_id) . '</a>';
  98. } else {
  99. $order_link = '<span class="studiou-fpp-no-order">—</span>';
  100. }
  101. // Download URL that also marks file as downloaded
  102. $download_url = add_query_arg(array(
  103. 'studiou_fpp_download_file' => 1,
  104. 'file_record_id' => $record->id,
  105. 'attachment_id' => $record->attachment_id,
  106. '_wpnonce' => wp_create_nonce('studiou-fpp-download-file'),
  107. ), admin_url('admin.php'));
  108. ?>
  109. <tr data-file-id="<?php echo esc_attr($record->id); ?>">
  110. <th scope="row" class="check-column">
  111. <input type="checkbox" class="studiou-fpp-file-cb" value="<?php echo esc_attr($record->id); ?>" />
  112. </th>
  113. <td class="column-thumbnail">
  114. <img src="<?php echo esc_url($thumb_url); ?>" alt="" class="studiou-fpp-thumb" />
  115. </td>
  116. <td class="column-filename">
  117. <?php if ($attachment_url) : ?>
  118. <a href="<?php echo esc_url($attachment_url); ?>" target="_blank"><?php echo esc_html($record->file_name); ?></a>
  119. <?php else : ?>
  120. <?php echo esc_html($record->file_name); ?>
  121. <?php endif; ?>
  122. </td>
  123. <td class="column-product">
  124. <a href="<?php echo esc_url(get_edit_post_link($record->product_id)); ?>"><?php echo esc_html($product_title); ?></a>
  125. </td>
  126. <td class="column-order">
  127. <?php echo $order_link; ?>
  128. </td>
  129. <td class="column-customer">
  130. <?php echo esc_html($customer_name); ?>
  131. </td>
  132. <td class="column-status">
  133. <select class="studiou-fpp-status-select" data-file-id="<?php echo esc_attr($record->id); ?>">
  134. <option value="ready" <?php selected($record->status, 'ready'); ?>><?php esc_html_e('Ready', 'studiou-wc-free-photo-product'); ?></option>
  135. <option value="downloaded" <?php selected($record->status, 'downloaded'); ?>><?php esc_html_e('Downloaded', 'studiou-wc-free-photo-product'); ?></option>
  136. <option value="solved" <?php selected($record->status, 'solved'); ?>><?php esc_html_e('Solved', 'studiou-wc-free-photo-product'); ?></option>
  137. </select>
  138. </td>
  139. <td class="column-date">
  140. <?php echo esc_html(date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($record->created_at))); ?>
  141. </td>
  142. <td class="column-actions">
  143. <?php if ($attachment_url) : ?>
  144. <a href="<?php echo esc_url($download_url); ?>" class="button button-small" title="<?php esc_attr_e('Download', 'studiou-wc-free-photo-product'); ?>">
  145. <span class="dashicons dashicons-download" style="line-height:1.4;"></span>
  146. </a>
  147. <?php endif; ?>
  148. <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'); ?>">
  149. <span class="dashicons dashicons-trash" style="line-height:1.4;color:#b32d2e;"></span>
  150. </button>
  151. </td>
  152. </tr>
  153. <?php endforeach; ?>
  154. <?php endif; ?>
  155. </tbody>
  156. </table>
  157. <!-- Pagination -->
  158. <?php if ($total_pages > 1) : ?>
  159. <div class="tablenav bottom">
  160. <div class="tablenav-pages">
  161. <span class="displaying-num">
  162. <?php echo esc_html(sprintf(
  163. _n('%d file', '%d files', $total, 'studiou-wc-free-photo-product'),
  164. $total
  165. )); ?>
  166. </span>
  167. <?php
  168. // Preserve filters in pagination links
  169. $pagination_args = array(
  170. 'post_type' => 'product',
  171. 'page' => 'studiou-fpp-summary',
  172. );
  173. if ($current_status) $pagination_args['status'] = $current_status;
  174. if ($current_product) $pagination_args['product_id'] = $current_product;
  175. if ($current_search) $pagination_args['s'] = $current_search;
  176. $pagination = paginate_links(array(
  177. 'base' => add_query_arg('paged', '%#%', admin_url('edit.php?' . http_build_query($pagination_args))),
  178. 'format' => '',
  179. 'current' => $current_page,
  180. 'total' => $total_pages,
  181. 'prev_text' => '&laquo;',
  182. 'next_text' => '&raquo;',
  183. ));
  184. if ($pagination) {
  185. echo $pagination;
  186. }
  187. ?>
  188. </div>
  189. </div>
  190. <?php endif; ?>
  191. </div>