diff --git a/admin/edit-wheel-page.php b/admin/edit-wheel-page.php index 32235b9..7ae67c3 100644 --- a/admin/edit-wheel-page.php +++ b/admin/edit-wheel-page.php @@ -193,6 +193,29 @@ if ( } } +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_wheel_settings') { + if (check_admin_referer('wheel_edit_settings_nonce')) { + global $wpdb; + $wheels_table = $wpdb->prefix . 'wof_wheels'; + + $wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0; + $has_daily_spin = isset($_POST['has_daily_spin']) ? 1 : 0; + + if ($wheel_id > 0) { + $wpdb->update( + $wheels_table, + ['has_daily_spin' => $has_daily_spin], + ['id' => $wheel_id], + ['%d'], + ['%d'] + ); + echo '

' . __('Wheel settings updated!', 'wheel-of-fortune') . '

'; + // Osvežimo podatke o kolesu po shranjevanju + $wheel = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wheels_table WHERE id = %d", $wheel_id), ARRAY_A); + } + } +} + global $wpdb; $wheels_table = $wpdb->prefix . 'wof_wheels'; $prizes_table = $wpdb->prefix . 'wheel_prizes'; @@ -231,6 +254,28 @@ if (class_exists('WooCommerce')) {
+
+

+
+ + + + + + + + +
+ +

+
+

+
+
+

@@ -354,7 +399,8 @@ if (class_exists('WooCommerce')) { - + + diff --git a/admin/js/admin.js b/admin/js/admin.js index ba20346..11b8fb3 100644 --- a/admin/js/admin.js +++ b/admin/js/admin.js @@ -65,6 +65,7 @@ jQuery(document).ready(function($) { $('#edit-prize-name').val(prize.name); $('#edit-prize-description').val(prize.description); $('#edit-prize-probability').val(prize.probability); + $('#edit-prize-daily-spin-probability').val(prize.daily_spin_probability); $('#edit-prize-is-active').prop('checked', parseInt(prize.is_active, 10)); $('#edit-prize-redemption-code').val(prize.redemption_code); $('#edit-prize-is-discount').prop('checked', parseInt(prize.is_discount, 10)); @@ -94,6 +95,7 @@ jQuery(document).ready(function($) { name: $('#edit-prize-name').val(), description: $('#edit-prize-description').val(), probability: $('#edit-prize-probability').val(), + daily_spin_probability: $('#edit-prize-daily-spin-probability').val(), is_active: $('#edit-prize-is-active').is(':checked') ? 1 : 0, redemption_code: $('#edit-prize-redemption-code').val(), is_discount: $('#edit-prize-is-discount').is(':checked') ? 1 : 0, diff --git a/admin/partials/prize-form-fields.php b/admin/partials/prize-form-fields.php index fab7749..20de789 100644 --- a/admin/partials/prize-form-fields.php +++ b/admin/partials/prize-form-fields.php @@ -13,12 +13,19 @@ if (!defined('ABSPATH')) exit; - + + + + +

+ +

+
diff --git a/assets/js/wheel.js b/assets/js/wheel.js index ec60fb5..3277070 100644 --- a/assets/js/wheel.js +++ b/assets/js/wheel.js @@ -20,6 +20,7 @@ jQuery(document).ready(function($) { var isSpinning = false; var accumulatedRotation = 0; var wheelSpins = wof_data.spins_left; + var dailySpinAvailable = wof_data.daily_spin_available; var l10n = wof_data.l10n; // Nastavitve animacije @@ -58,11 +59,7 @@ jQuery(document).ready(function($) { showPrizePopup(prize); isSpinning = false; - if (wheelSpins > 0) { - spinButton.prop('disabled', false).text(l10n.spin_button); - } else { - spinButton.prop('disabled', true).text(l10n.no_spins_left); - } + updateButtonState(); } // Prikaz nagrade @@ -81,9 +78,31 @@ jQuery(document).ready(function($) { } } + // Posodobitev stanja gumba + function updateButtonState() { + if (isSpinning) return; + + if (dailySpinAvailable) { + spinButton.prop('disabled', false).text(l10n.free_daily_spin || 'FREE DAILY SPIN'); + } else if (wheelSpins > 0) { + spinButton.prop('disabled', false).text(l10n.spin_button); + } else { + spinButton.prop('disabled', true).text(l10n.no_spins_left); + } + } + // Klik na gumb za vrtenje spinButton.on('click', function() { - if (isSpinning || wheelSpins <= 0) return; + if (isSpinning) return; + + var spinType = 'paid'; // Privzeto je plačan + + // Preveri, ali najprej porabimo dnevnega + if (dailySpinAvailable) { + spinType = 'daily'; + } else if (wheelSpins <= 0) { + return; // Ničesar za porabiti + } isSpinning = true; spinButton.prop('disabled', true).text(l10n.spinning); @@ -97,10 +116,16 @@ jQuery(document).ready(function($) { }, data: { wheel_id: wof_data.wheel_id, + spin_type: spinType }, success: function(response) { if (response.success) { window.wof_spin_result = response.data; + + // Posodobimo stanje + if (spinType === 'daily') { + dailySpinAvailable = false; + } wheelSpins = response.data.remaining_spins; updateSpinsCounter(); @@ -131,17 +156,13 @@ jQuery(document).ready(function($) { function handleError(message) { resultDiv.html('

' + message + '

').addClass('error').fadeIn(300); isSpinning = false; - if(wheelSpins > 0){ - spinButton.prop('disabled', false).text(l10n.spin_button); - } + updateButtonState(); } // Inicializacija function init() { updateSpinsCounter(); - if (wheelSpins <= 0) { - spinButton.prop('disabled', true).text(l10n.no_spins_left); - } + updateButtonState(); } init(); diff --git a/code_export.txt b/code_export.txt index 63fada5..848eeaf 100644 --- a/code_export.txt +++ b/code_export.txt @@ -1,5 +1,9 @@ "./README.md" : """ +# Wheel of Fortune Plugin + +Test posodobitve za preverjanje Gitea workflow. + # Wheel of Fortune - WordPress Plugin Vtičnik "Kolo Sreče" (Wheel of Fortune) omogoča uporabnikom vrtenje kolesa za nagrade. Povezan je z WooCommerce za dodeljevanje spinov ob nakupu izdelkov. @@ -1351,6 +1355,8 @@ if (class_exists('WooCommerce')) {

' . esc_html($total_probability) . ''); ?>

+

+ @@ -1364,7 +1370,7 @@ if (class_exists('WooCommerce')) { - + @@ -1451,7 +1457,7 @@ if (class_exists('WooCommerce')) { -