This commit is contained in:
1 parent
d77be150d9
commit
5210c9d2e6
11 files changed
+732
-284
No files matched your search
+285
-2
@@ -81,6 +81,41 @@ if (isset($_POST['mark_redeemed']) && isset($_POST['prize_id'])) {
|
||||
'</p></div>';
|
||||
}
|
||||
|
||||
// Ponastavi spine na 0 za vse uporabnike na izbranem kolesu
|
||||
if (isset($_POST['reset_all_spins_wheel']) && isset($_POST['wheel_id'])) {
|
||||
check_admin_referer('reset_spins_wheel_nonce', 'reset_spins_wheel_nonce');
|
||||
|
||||
$wheel_id = intval($_POST['wheel_id']);
|
||||
|
||||
// Preveri, če kolo obstaja
|
||||
$wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wheels_table WHERE id = %d", $wheel_id));
|
||||
|
||||
if ($wheel_exists) {
|
||||
// Ponastavi spine na 0 za vse uporabnike na tem kolesu
|
||||
$result = $wpdb->update(
|
||||
$spins_table,
|
||||
array('spins_available' => 0),
|
||||
array('wheel_id' => $wheel_id),
|
||||
array('%d'),
|
||||
array('%d')
|
||||
);
|
||||
|
||||
if ($result !== false) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' .
|
||||
sprintf(__('Vsi spini za kolo ID %d so bili uspešno ponastavljeni na 0.', 'wheel-of-fortune'), $wheel_id) .
|
||||
'</p></div>';
|
||||
} else {
|
||||
echo '<div class="notice notice-error is-dismissible"><p>' .
|
||||
__('Prišlo je do napake pri ponastavitvi spinov.', 'wheel-of-fortune') .
|
||||
'</p></div>';
|
||||
}
|
||||
} else {
|
||||
echo '<div class="notice notice-error is-dismissible"><p>' .
|
||||
__('Izbrano kolo ne obstaja.', 'wheel-of-fortune') .
|
||||
'</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Izberi uporabnika za podrobnosti
|
||||
$selected_user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
|
||||
|
||||
@@ -106,6 +141,22 @@ if ($selected_user_id > 0) {
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html__('Statistika Kolesa Sreče', 'wheel-of-fortune'); ?></h1>
|
||||
|
||||
<!-- Gumb za ponastavitev spinov za izbrano kolo -->
|
||||
<div class="notice notice-warning" style="margin: 20px 0;">
|
||||
<p>
|
||||
<strong><?php echo esc_html__('Ponastavitev spinov', 'wheel-of-fortune'); ?>:</strong>
|
||||
<?php echo esc_html__('To dejanje bo ponastavilo vse spine na 0 za vse uporabnike na izbranem kolesu. To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune'); ?>
|
||||
<form method="post" style="display: inline-block; margin-left: 10px;">
|
||||
<?php wp_nonce_field('reset_spins_wheel_nonce', 'reset_spins_wheel_nonce'); ?>
|
||||
<input type="hidden" name="wheel_id" value="<?php echo esc_attr($selected_wheel_id); ?>">
|
||||
<button type="submit" name="reset_all_spins_wheel" class="button button-secondary"
|
||||
onclick="return confirm('<?php echo esc_js(__('Ste prepričani, da želite ponastaviti vse spine na 0 za vse uporabnike na tem kolesu? To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune')); ?>')">
|
||||
<?php echo esc_html__('Ponastavi vse spine na 0 za to kolo', 'wheel-of-fortune'); ?>
|
||||
</button>
|
||||
</form>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Izbira kolesa -->
|
||||
<div class="tablenav top">
|
||||
<div class="alignleft actions">
|
||||
@@ -132,9 +183,45 @@ if ($selected_user_id > 0) {
|
||||
<br class="clear">
|
||||
</div>
|
||||
|
||||
|
||||
<h2><?php echo sprintf(esc_html__('Seznam uporabnikov s spini za kolo: %s', 'wheel-of-fortune'), esc_html($selected_wheel['name'])); ?></h2>
|
||||
|
||||
<table class="wp-list-table widefat fixed striped">
|
||||
<!-- Filtriranje uporabnikov -->
|
||||
<div class="user-filters" style="margin: 20px 0; padding: 15px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 5px;">
|
||||
<h4><?php echo esc_html__('Filtriranje uporabnikov', 'wheel-of-fortune'); ?></h4>
|
||||
<div style="display: flex; gap: 15px; align-items: center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<label for="filter-spins"><?php echo esc_html__('Preostali spini:', 'wheel-of-fortune'); ?></label>
|
||||
<select id="filter-spins" style="margin-left: 5px;">
|
||||
<option value=""><?php echo esc_html__('Vsi', 'wheel-of-fortune'); ?></option>
|
||||
<option value="0"><?php echo esc_html__('0 spinov (porabili)', 'wheel-of-fortune'); ?></option>
|
||||
<option value="1"><?php echo esc_html__('1 spin', 'wheel-of-fortune'); ?></option>
|
||||
<option value="2"><?php echo esc_html__('2 spina', 'wheel-of-fortune'); ?></option>
|
||||
<option value="3"><?php echo esc_html__('3 spini', 'wheel-of-fortune'); ?></option>
|
||||
<option value="4"><?php echo esc_html__('4 spini', 'wheel-of-fortune'); ?></option>
|
||||
<option value="5"><?php echo esc_html__('5+ spinov', 'wheel-of-fortune'); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="filter-total-spins"><?php echo esc_html__('Skupno spinov:', 'wheel-of-fortune'); ?></label>
|
||||
<select id="filter-total-spins" style="margin-left: 5px;">
|
||||
<option value=""><?php echo esc_html__('Vsi', 'wheel-of-fortune'); ?></option>
|
||||
<option value="0"><?php echo esc_html__('0', 'wheel-of-fortune'); ?></option>
|
||||
<option value="1"><?php echo esc_html__('1', 'wheel-of-fortune'); ?></option>
|
||||
<option value="2-5"><?php echo esc_html__('2-5', 'wheel-of-fortune'); ?></option>
|
||||
<option value="6-10"><?php echo esc_html__('6-10', 'wheel-of-fortune'); ?></option>
|
||||
<option value="11+"><?php echo esc_html__('11+', 'wheel-of-fortune'); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" onclick="filterUsers()" class="button button-primary"><?php echo esc_html__('Potrdi filtriranje', 'wheel-of-fortune'); ?></button>
|
||||
<button type="button" onclick="clearFilters()" class="button" style="margin-left: 10px;"><?php echo esc_html__('Počisti filtre', 'wheel-of-fortune'); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="filter-results" style="margin-top: 10px; font-weight: bold; color: #0073aa;"></div>
|
||||
</div>
|
||||
|
||||
<table class="wp-list-table widefat fixed striped" id="users-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php echo esc_html__('ID', 'wheel-of-fortune'); ?></th>
|
||||
@@ -254,4 +341,200 @@ if ($selected_user_id > 0) {
|
||||
<p><?php echo esc_html__('Uporabnik ni bil najden.', 'wheel-of-fortune'); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Funkcija za filtriranje uporabnikov
|
||||
function filterUsers() {
|
||||
const filterSpins = document.getElementById('filter-spins').value;
|
||||
const filterTotalSpins = document.getElementById('filter-total-spins').value;
|
||||
const table = document.getElementById('users-table');
|
||||
const tbody = table.getElementsByTagName('tbody')[0];
|
||||
|
||||
if (!tbody) {
|
||||
console.error('Tabela ni najdena');
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = tbody.getElementsByTagName('tr');
|
||||
let visibleCount = 0;
|
||||
|
||||
console.log('Filtriranje uporabnikov:', { filterSpins, filterTotalSpins, totalRows: rows.length });
|
||||
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
const cells = row.getElementsByTagName('td');
|
||||
|
||||
if (cells.length < 4) {
|
||||
console.log('Preskočena vrstica (premalo stolpcev):', cells.length);
|
||||
continue; // Preskoči header vrstice ali vrstice brez dovolj stolpcev
|
||||
}
|
||||
|
||||
// Debug: prikaži vsebino vseh stolpcev
|
||||
console.log(`Vrstica ${i} stolpci:`, {
|
||||
stolpec0: cells[0] ? cells[0].textContent.trim() : 'N/A',
|
||||
stolpec1: cells[1] ? cells[1].textContent.trim() : 'N/A',
|
||||
stolpec2: cells[2] ? cells[2].textContent.trim() : 'N/A',
|
||||
stolpec3: cells[3] ? cells[3].textContent.trim() : 'N/A',
|
||||
stolpec4: cells[4] ? cells[4].textContent.trim() : 'N/A',
|
||||
stolpec5: cells[5] ? cells[5].textContent.trim() : 'N/A'
|
||||
});
|
||||
|
||||
const currentSpins = parseInt(cells[3].textContent.trim()) || 0; // Preostali spini (4. stolpec)
|
||||
const totalSpins = parseInt(cells[2].textContent.trim()) || 0; // Skupno št. spinov (3. stolpec)
|
||||
|
||||
console.log(`Vrstica ${i}: currentSpins=${currentSpins}, totalSpins=${totalSpins}`);
|
||||
|
||||
let showRow = true;
|
||||
|
||||
// Filtriranje po preostalih spinih
|
||||
if (filterSpins !== '') {
|
||||
if (filterSpins === '0') {
|
||||
showRow = showRow && (currentSpins === 0);
|
||||
} else if (filterSpins === '1') {
|
||||
showRow = showRow && (currentSpins === 1);
|
||||
} else if (filterSpins === '2') {
|
||||
showRow = showRow && (currentSpins === 2);
|
||||
} else if (filterSpins === '3') {
|
||||
showRow = showRow && (currentSpins === 3);
|
||||
} else if (filterSpins === '4') {
|
||||
showRow = showRow && (currentSpins === 4);
|
||||
} else if (filterSpins === '5') {
|
||||
showRow = showRow && (currentSpins >= 5);
|
||||
}
|
||||
}
|
||||
|
||||
// Filtriranje po skupnem številu spinov
|
||||
if (filterTotalSpins !== '') {
|
||||
if (filterTotalSpins === '0') {
|
||||
showRow = showRow && (totalSpins === 0);
|
||||
} else if (filterTotalSpins === '1') {
|
||||
showRow = showRow && (totalSpins === 1);
|
||||
} else if (filterTotalSpins === '2-5') {
|
||||
showRow = showRow && (totalSpins >= 2 && totalSpins <= 5);
|
||||
} else if (filterTotalSpins === '6-10') {
|
||||
showRow = showRow && (totalSpins >= 6 && totalSpins <= 10);
|
||||
} else if (filterTotalSpins === '11+') {
|
||||
showRow = showRow && (totalSpins >= 11);
|
||||
}
|
||||
}
|
||||
|
||||
// Prikaži/skrij vrstico
|
||||
if (showRow) {
|
||||
row.style.display = '';
|
||||
visibleCount++;
|
||||
console.log(`Prikazana vrstica ${i}`);
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
console.log(`Skrita vrstica ${i}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Filtriranje končano: ${visibleCount} od ${rows.length} vrstic prikazanih`);
|
||||
|
||||
// Posodobi števec rezultatov
|
||||
updateFilterResults(visibleCount, rows.length);
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
document.getElementById('filter-spins').value = '';
|
||||
document.getElementById('filter-total-spins').value = '';
|
||||
filterUsers();
|
||||
}
|
||||
|
||||
function updateFilterResults(visible, total) {
|
||||
const resultsDiv = document.getElementById('filter-results');
|
||||
if (visible === total) {
|
||||
resultsDiv.innerHTML = '<?php echo esc_js(__('Prikazani vsi uporabniki:', 'wheel-of-fortune')); ?> ' + total;
|
||||
} else {
|
||||
resultsDiv.innerHTML = '<?php echo esc_js(__('Prikazano:', 'wheel-of-fortune')); ?> ' + visible + ' <?php echo esc_js(__('od', 'wheel-of-fortune')); ?> ' + total + ' <?php echo esc_js(__('uporabnikov', 'wheel-of-fortune')); ?>';
|
||||
}
|
||||
}
|
||||
|
||||
// Testna funkcija za preverjanje strukture tabele
|
||||
function testTableStructure() {
|
||||
const table = document.getElementById('users-table');
|
||||
if (!table) {
|
||||
console.log('Tabela ni najdena!');
|
||||
return;
|
||||
}
|
||||
|
||||
const tbody = table.getElementsByTagName('tbody')[0];
|
||||
if (!tbody) {
|
||||
console.log('Tbody ni najden!');
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = tbody.getElementsByTagName('tr');
|
||||
console.log(`Najdenih ${rows.length} vrstic v tabeli`);
|
||||
|
||||
if (rows.length > 0) {
|
||||
const firstRow = rows[0];
|
||||
const cells = firstRow.getElementsByTagName('td');
|
||||
console.log(`Prva vrstica ima ${cells.length} stolpcev`);
|
||||
|
||||
for (let i = 0; i < cells.length; i++) {
|
||||
console.log(`Stolpec ${i}: "${cells[i].textContent.trim()}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializiraj števec rezultatov ob nalaganju strani
|
||||
jQuery(document).ready(function($) {
|
||||
// Gumb za ponastavitev spinov preko AJAX
|
||||
$('button[name="reset_all_spins_wheel"]').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const button = $(this);
|
||||
const originalText = button.text();
|
||||
const wheelId = $('input[name="wheel_id"]').val();
|
||||
|
||||
if (!confirm('<?php echo esc_js(__('Ste prepričani, da želite ponastaviti vse spine na 0 za vse uporabnike na tem kolesu? To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune')); ?>')) {
|
||||
return;
|
||||
}
|
||||
|
||||
button.prop('disabled', true).text('<?php echo esc_js(__('Ponastavljam spine...', 'wheel-of-fortune')); ?>');
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: {
|
||||
action: 'wheel_reset_spins_wheel',
|
||||
wheel_id: wheelId,
|
||||
_ajax_nonce: '<?php echo wp_create_nonce('wheel_admin_nonce'); ?>'
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
// Prikaži uspešno sporočilo
|
||||
$('<div class="notice notice-success is-dismissible"><p>' + response.data.message + '</p></div>')
|
||||
.insertAfter('h1')
|
||||
.delay(3000)
|
||||
.fadeOut();
|
||||
|
||||
// Osveži stran po 2 sekundah
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
} else {
|
||||
alert(response.data.message || '<?php echo esc_js(__('Prišlo je do napake.', 'wheel-of-fortune')); ?>');
|
||||
button.prop('disabled', false).text(originalText);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('<?php echo esc_js(__('Prišlo je do napake pri komunikaciji s strežnikom.', 'wheel-of-fortune')); ?>');
|
||||
button.prop('disabled', false).text(originalText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Posodobi števec rezultatov ob nalaganju strani
|
||||
const table = document.getElementById('users-table');
|
||||
if (table) {
|
||||
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||
updateFilterResults(rows.length, rows.length);
|
||||
|
||||
// Testiraj strukturo tabele
|
||||
testTableStructure();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user