| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704 |
- <?php
- /**
- * Admin Media Page for QDR Temporary Shared Storage
- *
- * @package QDR_Temporary_Shared_Storage
- */
- // If this file is called directly, abort.
- if (!defined('WPINC')) {
- die;
- }
- /**
- * Render the Media | Shared Storage admin page
- */
- function qdr_tss_render_media_page() {
- // Get current settings
- $settings = get_option('qdr_tss_settings', array(
- 'api_key' => '',
- 'media_category' => 'shared-storage',
- 'max_upload_size' => 1073741824, // 1GB default
- ));
-
- // Get total storage usage
- global $wpdb;
- $table_name = $wpdb->prefix . QDR_TSS_PLUGIN_TABLE;
- $total_size = $wpdb->get_var("SELECT SUM(file_size) FROM $table_name");
- $total_size = $total_size ? intval($total_size) : 0;
-
- $max_size = isset($settings['max_upload_size']) ? intval($settings['max_upload_size']) : 1073741824;
- $usage_percent = ($max_size > 0) ? min(100, ($total_size / $max_size) * 100) : 0;
- ?>
- <div class="wrap qdr-tss-admin">
- <h1><?php esc_html_e('Shared Storage', 'qdr-temporary-shared-storage'); ?></h1>
-
- <div class="qdr-tss-storage-summary">
- <h2><?php esc_html_e('Storage Usage', 'qdr-temporary-shared-storage'); ?></h2>
- <div class="qdr-tss-storage-bar">
- <div class="qdr-tss-storage-used" style="width: <?php echo esc_attr($usage_percent); ?>%"></div>
- </div>
- <p>
- <?php echo esc_html(qdr_tss_format_bytes($total_size)); ?> / <?php echo esc_html(qdr_tss_format_bytes($max_size)); ?>
- (<?php echo number_format($usage_percent, 1); ?>%)
- </p>
- </div>
-
- <div class="qdr-tss-toolbar">
- <div class="qdr-tss-search">
- <input type="text" id="qdr-tss-search-filename" placeholder="<?php esc_attr_e('Search by filename', 'qdr-temporary-shared-storage'); ?>">
- <input type="text" id="qdr-tss-search-reference" placeholder="<?php esc_attr_e('Search by reference', 'qdr-temporary-shared-storage'); ?>">
- <button class="button" id="qdr-tss-search-button">
- <span class="dashicons dashicons-search"></span> <?php esc_html_e('Search', 'qdr-temporary-shared-storage'); ?>
- </button>
- <button class="button" id="qdr-tss-reset-search">
- <span class="dashicons dashicons-dismiss"></span> <?php esc_html_e('Reset', 'qdr-temporary-shared-storage'); ?>
- </button>
- </div>
-
- <div class="qdr-tss-actions">
- <button class="button button-primary" id="qdr-tss-refresh">
- <span class="dashicons dashicons-update"></span> <?php esc_html_e('Refresh', 'qdr-temporary-shared-storage'); ?>
- </button>
- </div>
- </div>
-
- <div class="qdr-tss-table-container">
- <table class="wp-list-table widefat fixed striped qdr-tss-table">
- <thead>
- <tr>
- <th class="column-media-id sortable" data-sort="media_id"><?php esc_html_e('Media ID', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-filename sortable" data-sort="original_file_name"><?php esc_html_e('File Name', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-description"><?php esc_html_e('Description', 'qdr-temporary-shared-storage'); ?></th>
- <th class="column-message"><?php esc_html_e('Message', 'qdr-temporary-shared-storage'); ?></th>
- <th class="column-active-from sortable" data-sort="active_from"><?php esc_html_e('Active From', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-active-to sortable" data-sort="active_to"><?php esc_html_e('Active To', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-reference sortable" data-sort="reference"><?php esc_html_e('Reference', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-upload-date sortable" data-sort="upload_date"><?php esc_html_e('Upload Date', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-download-count sortable" data-sort="download_count"><?php esc_html_e('Downloads', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-last-download sortable" data-sort="last_download"><?php esc_html_e('Last Download', 'qdr-temporary-shared-storage'); ?> <span class="sorting-indicator"></span></th>
- <th class="column-actions"><?php esc_html_e('Actions', 'qdr-temporary-shared-storage'); ?></th>
- </tr>
- </thead>
- <tbody id="qdr-tss-items-list">
- <tr>
- <td colspan="11" class="qdr-tss-loading">
- <span class="spinner is-active"></span> <?php esc_html_e('Loading...', 'qdr-temporary-shared-storage'); ?>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
-
- <div class="qdr-tss-pagination">
- <div class="qdr-tss-pagination-info"></div>
- <div class="qdr-tss-pagination-controls"></div>
- </div>
- </div>
-
- <!-- Edit Item Modal -->
- <div id="qdr-tss-edit-modal" class="qdr-tss-modal">
- <div class="qdr-tss-modal-content">
- <span class="qdr-tss-modal-close">×</span>
- <h2><?php esc_html_e('Edit Shared File', 'qdr-temporary-shared-storage'); ?></h2>
-
- <form id="qdr-tss-edit-form">
- <input type="hidden" id="qdr-tss-edit-id" name="id">
-
- <div class="qdr-tss-form-row">
- <label for="qdr-tss-edit-description"><?php esc_html_e('Description', 'qdr-temporary-shared-storage'); ?></label>
- <textarea id="qdr-tss-edit-description" name="description" rows="3"></textarea>
- </div>
-
- <div class="qdr-tss-form-row">
- <label for="qdr-tss-edit-message"><?php esc_html_e('Message', 'qdr-temporary-shared-storage'); ?></label>
- <textarea id="qdr-tss-edit-message" name="message" rows="3"></textarea>
- </div>
-
- <div class="qdr-tss-form-row">
- <label for="qdr-tss-edit-active-from"><?php esc_html_e('Active From', 'qdr-temporary-shared-storage'); ?></label>
- <input type="text" id="qdr-tss-edit-active-from" name="active_from" class="qdr-tss-datepicker" autocomplete="off">
- </div>
-
- <div class="qdr-tss-form-row">
- <label for="qdr-tss-edit-active-to"><?php esc_html_e('Active To', 'qdr-temporary-shared-storage'); ?></label>
- <input type="text" id="qdr-tss-edit-active-to" name="active_to" class="qdr-tss-datepicker" autocomplete="off">
- </div>
-
- <div class="qdr-tss-form-row">
- <label for="qdr-tss-edit-reference"><?php esc_html_e('Reference', 'qdr-temporary-shared-storage'); ?></label>
- <input type="text" id="qdr-tss-edit-reference" name="reference">
- </div>
-
- <div class="qdr-tss-form-actions">
- <button type="submit" class="button button-primary"><?php esc_html_e('Save Changes', 'qdr-temporary-shared-storage'); ?></button>
- <button type="button" class="button qdr-tss-modal-cancel"><?php esc_html_e('Cancel', 'qdr-temporary-shared-storage'); ?></button>
- </div>
- </form>
-
- <div id="qdr-tss-edit-status"></div>
- </div>
- </div>
-
- <!-- View Details Modal -->
- <div id="qdr-tss-details-modal" class="qdr-tss-modal">
- <div class="qdr-tss-modal-content">
- <span class="qdr-tss-modal-close">×</span>
- <h2><?php esc_html_e('File Details', 'qdr-temporary-shared-storage'); ?></h2>
-
- <div class="qdr-tss-details-content">
- <table class="widefat striped">
- <tr>
- <th><?php esc_html_e('Media ID', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-media-id"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('File Name', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-filename"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Description', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-description"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Message', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-message"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Reference', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-reference"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Active Period', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-active-period"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('File Size', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-filesize"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Download Count', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-download-count"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Last Download', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-last-download"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Permalink', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-permalink"></td>
- </tr>
- <tr>
- <th><?php esc_html_e('Shortcode', 'qdr-temporary-shared-storage'); ?></th>
- <td id="qdr-tss-details-shortcode"></td>
- </tr>
- </table>
- </div>
-
- <div class="qdr-tss-form-actions">
- <button type="button" class="button button-secondary qdr-tss-copy-shortcode"><?php esc_html_e('Copy Shortcode', 'qdr-temporary-shared-storage'); ?></button>
- <button type="button" class="button button-secondary qdr-tss-copy-permalink"><?php esc_html_e('Copy Permalink', 'qdr-temporary-shared-storage'); ?></button>
- <button type="button" class="button qdr-tss-modal-cancel"><?php esc_html_e('Close', 'qdr-temporary-shared-storage'); ?></button>
- </div>
- </div>
- </div>
-
- <!-- Confirm Delete Modal -->
- <div id="qdr-tss-confirm-delete-modal" class="qdr-tss-modal">
- <div class="qdr-tss-modal-content qdr-tss-modal-sm">
- <span class="qdr-tss-modal-close">×</span>
- <h2><?php esc_html_e('Confirm Delete', 'qdr-temporary-shared-storage'); ?></h2>
-
- <p><?php esc_html_e('Are you sure you want to delete this file? This action cannot be undone.', 'qdr-temporary-shared-storage'); ?></p>
-
- <div class="qdr-tss-form-actions">
- <button type="button" class="button button-primary qdr-tss-confirm-delete-button"><?php esc_html_e('Delete', 'qdr-temporary-shared-storage'); ?></button>
- <button type="button" class="button qdr-tss-modal-cancel"><?php esc_html_e('Cancel', 'qdr-temporary-shared-storage'); ?></button>
- </div>
-
- <input type="hidden" id="qdr-tss-delete-id">
- </div>
- </div>
-
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- var currentPage = 1;
- var perPage = 10;
- var totalPages = 1;
- var currentOrderBy = 'upload_date';
- var currentOrder = 'DESC';
- var currentSearchFilename = '';
- var currentSearchReference = '';
-
- // Load items
- function loadItems() {
- var data = {
- action: 'qdr_tss_get_items',
- nonce: qdr_tss.nonce,
- page: currentPage,
- per_page: perPage,
- orderby: currentOrderBy,
- order: currentOrder,
- original_file_name: currentSearchFilename,
- reference: currentSearchReference
- };
-
- // Show loading indicator
- $('#qdr-tss-items-list').html('<tr><td colspan="11" class="qdr-tss-loading"><span class="spinner is-active"></span> <?php esc_html_e('Loading...', 'qdr-temporary-shared-storage'); ?></td></tr>');
-
- $.post(ajaxurl, data, function(response) {
- if (response.success) {
- renderItems(response.data.items);
- renderPagination(response.data.total, response.data.total_pages);
- } else {
- alert(response.data.message || '<?php esc_html_e('Error loading items.', 'qdr-temporary-shared-storage'); ?>');
- }
- }).fail(function() {
- $('#qdr-tss-items-list').html('<tr><td colspan="11"><?php esc_html_e('Error loading items. Please try again.', 'qdr-temporary-shared-storage'); ?></td></tr>');
- });
- }
-
- // Render items
- function renderItems(items) {
- var $tbody = $('#qdr-tss-items-list');
- $tbody.empty();
-
- if (!items || items.length === 0) {
- $tbody.append('<tr><td colspan="11"><?php esc_html_e('No items found.', 'qdr-temporary-shared-storage'); ?></td></tr>');
- return;
- }
-
- $.each(items, function(index, item) {
- var statusClass = '';
- var now = new Date();
- var activeFrom = new Date(item.active_from);
- var activeTo = new Date(item.active_to);
-
- if (now < activeFrom) {
- statusClass = 'qdr-tss-status-pending';
- } else if (now > activeTo) {
- statusClass = 'qdr-tss-status-expired';
- } else {
- statusClass = 'qdr-tss-status-active';
- }
-
- var row = '<tr data-id="' + item.id + '" class="' + statusClass + '">';
-
- row += '<td>' + item.media_id + '</td>';
- row += '<td>' + escapeHtml(item.original_file_name) + '</td>';
- row += '<td>' + escapeHtml(item.description || '') + '</td>';
- row += '<td>' + escapeHtml(item.message || '') + '</td>';
- row += '<td>' + formatDate(item.active_from) + '</td>';
- row += '<td>' + formatDate(item.active_to) + '</td>';
- row += '<td>' + escapeHtml(item.reference || '') + '</td>';
- row += '<td>' + formatDate(item.upload_date) + '</td>';
- row += '<td>' + item.download_count + '</td>';
- row += '<td>' + (item.last_download ? formatDate(item.last_download) : '-') + '</td>';
-
- row += '<td class="column-actions">';
- row += '<div class="qdr-tss-action-buttons">';
- row += '<button class="button qdr-tss-view-button" data-id="' + item.id + '" title="<?php esc_attr_e('View Details', 'qdr-temporary-shared-storage'); ?>"><span class="dashicons dashicons-visibility"></span></button>';
- row += '<button class="button qdr-tss-edit-button" data-id="' + item.id + '" title="<?php esc_attr_e('Edit', 'qdr-temporary-shared-storage'); ?>"><span class="dashicons dashicons-edit"></span></button>';
- row += '<button class="button qdr-tss-delete-button" data-id="' + item.id + '" title="<?php esc_attr_e('Delete', 'qdr-temporary-shared-storage'); ?>"><span class="dashicons dashicons-trash"></span></button>';
- row += '</div>';
- row += '</td>';
-
- row += '</tr>';
-
- $tbody.append(row);
- });
-
- // Initialize action buttons
- initActionButtons();
-
- // Update sorting indicators
- updateSortIndicators();
- }
-
- // Initialize action buttons
- function initActionButtons() {
- // View button
- $('.qdr-tss-view-button').on('click', function() {
- var id = $(this).data('id');
- viewItem(id);
- });
-
- // Edit button
- $('.qdr-tss-edit-button').on('click', function() {
- var id = $(this).data('id');
- editItem(id);
- });
-
- // Delete button
- $('.qdr-tss-delete-button').on('click', function() {
- var id = $(this).data('id');
- showDeleteConfirmation(id);
- });
- }
-
- // Format date
- function formatDate(dateString) {
- if (!dateString || dateString === '0000-00-00 00:00:00') {
- return '-';
- }
-
- var date = new Date(dateString);
-
- // Check if date is valid
- if (isNaN(date.getTime())) {
- return dateString;
- }
-
- return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
- }
-
- // Format file size
- function formatFileSize(bytes) {
- if (bytes === 0) return '0 Bytes';
-
- var k = 1024;
- var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
- var i = Math.floor(Math.log(bytes) / Math.log(k));
-
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
- }
-
- // Escape HTML
- function escapeHtml(text) {
- if (!text) return '';
-
- var map = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '"',
- "'": '''
- };
-
- return text.toString().replace(/[&<>"']/g, function(m) { return map[m]; });
- }
-
- // Render pagination
- function renderPagination(total, totalPages) {
- var $info = $('.qdr-tss-pagination-info');
- var $controls = $('.qdr-tss-pagination-controls');
-
- // Update info
- var startItem = (currentPage - 1) * perPage + 1;
- var endItem = Math.min(currentPage * perPage, total);
-
- if (total === 0) {
- $info.html('<?php esc_html_e('No items', 'qdr-temporary-shared-storage'); ?>');
- $controls.empty();
- return;
- }
-
- $info.html('<?php esc_html_e('Showing', 'qdr-temporary-shared-storage'); ?> ' + startItem + ' - ' + endItem + ' <?php esc_html_e('of', 'qdr-temporary-shared-storage'); ?> ' + total);
-
- // Update controls
- $controls.empty();
-
- if (totalPages <= 1) {
- return;
- }
-
- // First page
- if (currentPage > 1) {
- $controls.append('<button class="button qdr-tss-page-button" data-page="1" title="<?php esc_attr_e('First Page', 'qdr-temporary-shared-storage'); ?>">«</button>');
- }
-
- // Previous page
- if (currentPage > 1) {
- $controls.append('<button class="button qdr-tss-page-button" data-page="' + (currentPage - 1) + '" title="<?php esc_attr_e('Previous Page', 'qdr-temporary-shared-storage'); ?>">‹</button>');
- }
-
- // Page numbers
- var startPage = Math.max(1, currentPage - 2);
- var endPage = Math.min(totalPages, startPage + 4);
-
- if (endPage - startPage < 4) {
- startPage = Math.max(1, endPage - 4);
- }
-
- for (var i = startPage; i <= endPage; i++) {
- var activeClass = i === currentPage ? 'button-primary' : '';
- $controls.append('<button class="button qdr-tss-page-button ' + activeClass + '" data-page="' + i + '">' + i + '</button>');
- }
-
- // Next page
- if (currentPage < totalPages) {
- $controls.append('<button class="button qdr-tss-page-button" data-page="' + (currentPage + 1) + '" title="<?php esc_attr_e('Next Page', 'qdr-temporary-shared-storage'); ?>">›</button>');
- }
-
- // Last page
- if (currentPage < totalPages) {
- $controls.append('<button class="button qdr-tss-page-button" data-page="' + totalPages + '" title="<?php esc_attr_e('Last Page', 'qdr-temporary-shared-storage'); ?>">»</button>');
- }
-
- // Bind click event to page buttons
- $('.qdr-tss-page-button').on('click', function() {
- currentPage = parseInt($(this).data('page'));
- loadItems();
- });
- }
-
- // Update sort indicators
- function updateSortIndicators() {
- // Remove all indicators
- $('.qdr-tss-table th').removeClass('sorted asc desc');
-
- // Add indicator to current sort column
- var $th = $('.qdr-tss-table th[data-sort="' + currentOrderBy + '"]');
- $th.addClass('sorted ' + currentOrder.toLowerCase());
- }
-
- // View item details
- function viewItem(id) {
- // Find item in the table
- var $row = $('tr[data-id="' + id + '"]');
- if ($row.length === 0) return;
-
- var $cells = $row.find('td');
-
- var mediaId = $cells.eq(0).text();
- var fileName = $cells.eq(1).text();
- var description = $cells.eq(2).text();
- var message = $cells.eq(3).text();
- var activeFrom = $cells.eq(4).text();
- var activeTo = $cells.eq(5).text();
- var reference = $cells.eq(6).text();
- var uploadDate = $cells.eq(7).text();
- var downloadCount = $cells.eq(8).text();
- var lastDownload = $cells.eq(9).text();
-
- // Get additional data via AJAX
- var data = {
- action: 'qdr_tss_get_item_details',
- nonce: qdr_tss.nonce,
- id: id,
- media_id: mediaId
- };
-
- $.post(ajaxurl, data, function(response) {
- if (response.success) {
- var item = response.data.item;
-
- // Populate details
- $('#qdr-tss-details-media-id').text(mediaId);
- $('#qdr-tss-details-filename').text(fileName);
- $('#qdr-tss-details-description').text(description || '-');
- $('#qdr-tss-details-message').text(message || '-');
- $('#qdr-tss-details-reference').text(reference || '-');
- $('#qdr-tss-details-active-period').text(activeFrom + ' - ' + activeTo);
- $('#qdr-tss-details-filesize').text(formatFileSize(item.file_size));
- $('#qdr-tss-details-download-count').text(downloadCount);
- $('#qdr-tss-details-last-download').text(lastDownload);
-
- // Permalink and shortcode
- var permalink = '<?php echo esc_url(site_url('shared-file-download/')); ?>' + mediaId;
- var shortcode = '[qdr_tss_download id="' + mediaId + '"]';
-
- $('#qdr-tss-details-permalink').html('<a href="' + permalink + '" target="_blank">' + permalink + '</a>');
- $('#qdr-tss-details-shortcode').html('<code>' + shortcode + '</code>');
-
- // Show modal
- $('#qdr-tss-details-modal').show();
- } else {
- alert(response.data.message || '<?php esc_html_e('Error loading item details.', 'qdr-temporary-shared-storage'); ?>');
- }
- }).fail(function() {
- alert('<?php esc_html_e('Error loading item details. Please try again.', 'qdr-temporary-shared-storage'); ?>');
- });
- }
-
- // Edit item
- function editItem(id) {
- // Find item in the table
- var $row = $('tr[data-id="' + id + '"]');
- if ($row.length === 0) return;
-
- var $cells = $row.find('td');
-
- // Populate form fields
- $('#qdr-tss-edit-id').val(id);
- $('#qdr-tss-edit-description').val($cells.eq(2).text());
- $('#qdr-tss-edit-message').val($cells.eq(3).text());
-
- // Parse dates for datepicker
- var activeFrom = $cells.eq(4).text();
- var activeTo = $cells.eq(5).text();
-
- $('#qdr-tss-edit-active-from').val(activeFrom !== '-' ? activeFrom : '');
- $('#qdr-tss-edit-active-to').val(activeTo !== '-' ? activeTo : '');
- $('#qdr-tss-edit-reference').val($cells.eq(6).text());
-
- // Clear status
- $('#qdr-tss-edit-status').html('');
-
- // Show modal
- $('#qdr-tss-edit-modal').show();
-
- // Initialize datepickers
- $('.qdr-tss-datepicker').datepicker({
- dateFormat: 'yy-mm-dd',
- changeMonth: true,
- changeYear: true
- });
- }
-
- // Show delete confirmation
- function showDeleteConfirmation(id) {
- $('#qdr-tss-delete-id').val(id);
- $('#qdr-tss-confirm-delete-modal').show();
- }
-
- // Delete item
- function deleteItem(id) {
- var data = {
- action: 'qdr_tss_delete_item',
- nonce: qdr_tss.nonce,
- id: id
- };
-
- $.post(ajaxurl, data, function(response) {
- if (response.success) {
- // Hide modal
- $('#qdr-tss-confirm-delete-modal').hide();
-
- // Show success message
- alert(response.data.message || '<?php esc_html_e('File deleted successfully.', 'qdr-temporary-shared-storage'); ?>');
-
- // Reload items
- loadItems();
- } else {
- alert(response.data.message || '<?php esc_html_e('Error deleting file.', 'qdr-temporary-shared-storage'); ?>');
- }
- }).fail(function() {
- alert('<?php esc_html_e('Error deleting file. Please try again.', 'qdr-temporary-shared-storage'); ?>');
- });
- }
-
- // Copy text to clipboard
- function copyToClipboard(text) {
- var $temp = $('<input>');
- $('body').append($temp);
- $temp.val(text).select();
- document.execCommand('copy');
- $temp.remove();
- }
-
- // Handle form submission
- $('#qdr-tss-edit-form').on('submit', function(e) {
- e.preventDefault();
-
- // Show loading status
- $('#qdr-tss-edit-status').html('<div class="qdr-tss-loading"><span class="spinner is-active"></span> <?php esc_html_e('Saving...', 'qdr-temporary-shared-storage'); ?></div>');
-
- var data = {
- action: 'qdr_tss_edit_item',
- nonce: qdr_tss.nonce,
- id: $('#qdr-tss-edit-id').val(),
- description: $('#qdr-tss-edit-description').val(),
- message: $('#qdr-tss-edit-message').val(),
- active_from: $('#qdr-tss-edit-active-from').val(),
- active_to: $('#qdr-tss-edit-active-to').val(),
- reference: $('#qdr-tss-edit-reference').val()
- };
-
- $.post(ajaxurl, data, function(response) {
- if (response.success) {
- // Show success status
- $('#qdr-tss-edit-status').html('<div class="notice notice-success inline"><p>' + (response.data.message || '<?php esc_html_e('Changes saved successfully.', 'qdr-temporary-shared-storage'); ?>') + '</p></div>');
-
- // Hide modal after a delay
- setTimeout(function() {
- $('#qdr-tss-edit-modal').hide();
-
- // Reload items
- loadItems();
- }, 1000);
- } else {
- // Show error status
- $('#qdr-tss-edit-status').html('<div class="notice notice-error inline"><p>' + (response.data.message || '<?php esc_html_e('Error saving changes.', 'qdr-temporary-shared-storage'); ?>') + '</p></div>');
- }
- }).fail(function() {
- // Show error status
- $('#qdr-tss-edit-status').html('<div class="notice notice-error inline"><p><?php esc_html_e('Error saving changes. Please try again.', 'qdr-temporary-shared-storage'); ?></p></div>');
- });
- });
-
- // Handle sorting
- $('.qdr-tss-table th.sortable').on('click', function() {
- var column = $(this).data('sort');
-
- if (currentOrderBy === column) {
- currentOrder = currentOrder === 'ASC' ? 'DESC' : 'ASC';
- } else {
- currentOrderBy = column;
- currentOrder = 'ASC';
- }
-
- loadItems();
- });
-
- // Handle search
- $('#qdr-tss-search-button').on('click', function() {
- currentSearchFilename = $('#qdr-tss-search-filename').val();
- currentSearchReference = $('#qdr-tss-search-reference').val();
- currentPage = 1;
- loadItems();
- });
-
- // Handle search reset
- $('#qdr-tss-reset-search').on('click', function() {
- $('#qdr-tss-search-filename').val('');
- $('#qdr-tss-search-reference').val('');
- currentSearchFilename = '';
- currentSearchReference = '';
- currentPage = 1;
- loadItems();
- });
-
- // Handle refresh button
- $('#qdr-tss-refresh').on('click', function() {
- loadItems();
- });
-
- // Handle modal close
- $('.qdr-tss-modal-close, .qdr-tss-modal-cancel').on('click', function() {
- $('.qdr-tss-modal').hide();
- });
-
- // Close modal when clicking outside
- $(window).on('click', function(e) {
- if ($(e.target).hasClass('qdr-tss-modal')) {
- $('.qdr-tss-modal').hide();
- }
- });
-
- // Handle copy shortcode
- $('.qdr-tss-copy-shortcode').on('click', function() {
- var shortcode = $('#qdr-tss-details-shortcode code').text();
- copyToClipboard(shortcode);
- alert('<?php esc_html_e('Shortcode copied to clipboard.', 'qdr-temporary-shared-storage'); ?>');
- });
-
- // Handle copy permalink
- $('.qdr-tss-copy-permalink').on('click', function() {
- var permalink = $('#qdr-tss-details-permalink a').attr('href');
- copyToClipboard(permalink);
- alert('<?php esc_html_e('Permalink copied to clipboard.', 'qdr-temporary-shared-storage'); ?>');
- });
-
- // Handle confirm delete
- $('.qdr-tss-confirm-delete-button').on('click', function() {
- var id = $('#qdr-tss-delete-id').val();
- deleteItem(id);
- });
-
- // Initial load
- loadItems();
- });
- </script>
- <?php
- }
|