Domnovi popravki
Deploy to Test Server / deploy (push) Failing after 58s
Details
Deploy to Test Server / deploy (push) Failing after 58s
Details
This commit is contained in:
parent
d77be150d9
commit
5210c9d2e6
|
|
@ -1,7 +1,3 @@
|
|||
# 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.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||
|
||||
if (!empty($name) && $wheel_id > 0) {
|
||||
$result = $wpdb->insert(
|
||||
|
|
@ -35,8 +36,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
'discount_value' => $discount_value,
|
||||
'email_subject' => $email_subject,
|
||||
'email_template' => $email_template,
|
||||
'is_try_again' => $is_try_again
|
||||
],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s']
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d']
|
||||
);
|
||||
|
||||
if ($result !== false) {
|
||||
|
|
@ -62,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||
|
||||
if (!empty($name) && $prize_id > 0 && $wheel_id > 0) {
|
||||
$result = $wpdb->update(
|
||||
|
|
@ -77,9 +80,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
'discount_value' => $discount_value,
|
||||
'email_subject' => $email_subject,
|
||||
'email_template' => $email_template,
|
||||
'is_try_again' => $is_try_again
|
||||
],
|
||||
['id' => $prize_id],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s'],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d'],
|
||||
['%d']
|
||||
);
|
||||
|
||||
|
|
@ -193,29 +197,6 @@ 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 '<div class="notice notice-success is-dismissible"><p>' . __('Wheel settings updated!', 'wheel-of-fortune') . '</p></div>';
|
||||
// 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';
|
||||
|
|
@ -254,26 +235,15 @@ if (class_exists('WooCommerce')) {
|
|||
|
||||
<hr class="wp-header-end">
|
||||
|
||||
<div class="wheel-card">
|
||||
<h2><?php _e('Wheel Settings', 'wheel-of-fortune'); ?></h2>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field('wheel_edit_settings_nonce'); ?>
|
||||
<input type="hidden" name="action" value="update_wheel_settings">
|
||||
<input type="hidden" name="wheel_id" value="<?php echo esc_attr($wheel_id); ?>">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Daily Free Spin', 'wheel-of-fortune'); ?></th>
|
||||
<td>
|
||||
<label for="has_daily_spin">
|
||||
<input name="has_daily_spin" type="checkbox" id="has_daily_spin" value="1" <?php checked(isset($wheel['has_daily_spin']) && $wheel['has_daily_spin'], 1); ?>>
|
||||
<?php _e('Enable 1 free daily spin for all logged-in users on this wheel.', 'wheel-of-fortune'); ?>
|
||||
</label>
|
||||
<p class="description"><?php _e('If checked, users can spin this wheel once per day for free, regardless of their purchased spins.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Wheel Settings', 'wheel-of-fortune'); ?>"></p>
|
||||
</form>
|
||||
<!-- Gumb za migracijo is_try_again stolpca -->
|
||||
<div class="notice notice-info">
|
||||
<p><strong><?php _e('Database Migration', 'wheel-of-fortune'); ?>:</strong>
|
||||
<?php _e('If you encounter "Unknown column is_try_again" error, click the button below to add the missing column to the database.', 'wheel-of-fortune'); ?>
|
||||
<button id="migrate-try-again-btn" class="button button-secondary" style="margin-left: 10px;">
|
||||
<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>
|
||||
</button>
|
||||
<span id="migrate-result" style="margin-left: 10px;"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="wheel-card">
|
||||
|
|
@ -399,12 +369,12 @@ if (class_exists('WooCommerce')) {
|
|||
<table class="wheel-form-table">
|
||||
<tr><th scope="row"><label for="edit-prize-name"><?php _e('Prize Name', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-name" name="prize_name" class="regular-text" required></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-description"><?php _e('Description', 'wheel-of-fortune'); ?></label></th><td><textarea id="edit-prize-description" name="prize_description" rows="3" class="large-text"></textarea></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-probability"><?php _e('Probability (Paid Spin)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-probability" name="prize_probability" step="any" min="0" max="1" required><p class="description"><?php _e('Enter a value between 0 and 1. Use 0 for prizes that cannot be won.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-daily-spin-probability"><?php _e('Probability (Daily Spin)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-daily-spin-probability" name="prize_daily_spin_probability" step="any" min="0" max="1"><p class="description"><?php _e('Chance for a FREE daily spin. Leave empty to use the same probability as the paid spin.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-probability"><?php _e('Probability', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-probability" name="prize_probability" step="any" min="0" max="1" required><p class="description"><?php _e('Enter a value between 0 and 1. Use 0 for prizes that cannot be won.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><?php _e('Status', 'wheel-of-fortune'); ?></th><td><label for="edit-prize-is-active"><input type="checkbox" id="edit-prize-is-active" name="prize_is_active" value="1"><?php _e('Prize is active', 'wheel-of-fortune'); ?></label></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-redemption-code"><?php _e('Redemption Code', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-redemption-code" name="prize_redemption_code" class="regular-text"><p class="description"><?php _e('Optional code for the user to redeem the prize.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-is-discount"><?php _e('Is Discount?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-discount" name="prize_is_discount" value="1"><p class="description"><?php _e('Check if the prize is a discount.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-discount-value"><?php _e('Discount Value (%)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-discount-value" name="prize_discount_value" step="0.01" min="0" max="100"><p class="description"><?php _e('Enter the discount value in %.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-is-try-again"><?php _e('Is Try Again?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-try-again" name="prize_is_try_again" value="1"><p class="description"><?php _e('Check if the prize is a try again.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-email-subject"><?php _e('Email Subject', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-email-subject" name="prize_email_subject" class="large-text"><p class="description"><?php _e('Subject for this prize\'s email. If empty, the default subject will be used.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-email-template"><?php _e('Email Template', 'wheel-of-fortune'); ?></label></th><td><textarea id="edit-prize-email-template" name="prize_email_template" rows="10" class="large-text code"></textarea><p class="description"><?php _e('Available template tags:', 'wheel-of-fortune'); ?> <code>{user_name}</code>, <code>{prize_name}</code>, etc.</p></td></tr>
|
||||
</table>
|
||||
|
|
@ -463,4 +433,41 @@ jQuery(document).ready(function($) {
|
|||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
// Gumb za migracijo is_try_again stolpca
|
||||
$('#migrate-try-again-btn').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const button = $(this);
|
||||
const resultSpan = $('#migrate-result');
|
||||
|
||||
button.prop('disabled', true).text('<?php _e('Running migration...', 'wheel-of-fortune'); ?>');
|
||||
resultSpan.html('');
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: {
|
||||
action: 'wheel_migrate_try_again',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce('wheel_admin_nonce'); ?>'
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
resultSpan.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
|
||||
button.text('<?php _e('Migration Completed', 'wheel-of-fortune'); ?>').addClass('button-primary');
|
||||
} else {
|
||||
resultSpan.html('<span style="color: red;">✗ ' + (response.data.message || '<?php _e('Migration failed', 'wheel-of-fortune'); ?>') + '</span>');
|
||||
button.prop('disabled', false).text('<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
resultSpan.html('<span style="color: red;">✗ <?php _e('Network error occurred', 'wheel-of-fortune'); ?></span>');
|
||||
button.prop('disabled', false).text('<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -65,13 +65,13 @@ 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));
|
||||
$('#edit-prize-discount-value').val(prize.discount_value);
|
||||
$('#edit-prize-email-subject').val(prize.email_subject);
|
||||
$('#edit-prize-email-template').val(prize.email_template);
|
||||
$('#edit-prize-is-try-again').prop('checked', parseInt(prize.is_try_again, 10));
|
||||
|
||||
modal.show();
|
||||
} else {
|
||||
|
|
@ -95,13 +95,13 @@ 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,
|
||||
discount_value: $('#edit-prize-discount-value').val(),
|
||||
email_subject: $('#edit-prize-email-subject').val(),
|
||||
email_template: $('#edit-prize-email-template').val(),
|
||||
is_try_again: $('#edit-prize-is-try-again').is(':checked') ? 1 : 0,
|
||||
};
|
||||
|
||||
// Debug: preveri wheel_id
|
||||
|
|
|
|||
|
|
@ -13,19 +13,12 @@ if (!defined('ABSPATH')) exit;
|
|||
<td><textarea id="prize_description" name="prize_description" rows="3" class="large-text"></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="prize_probability"><?php _e('Probability (Paid Spin)', 'wheel-of-fortune'); ?></label></th>
|
||||
<th scope="row"><label for="prize_probability"><?php _e('Probability', 'wheel-of-fortune'); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="prize_probability" name="prize_probability" step="any" min="0" max="1" required>
|
||||
<p class="description"><?php _e('Enter a value between 0 and 1 (e.g., 0.1 for 10% chance). Use 0 for prizes that cannot be won.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="prize_daily_spin_probability"><?php _e('Probability (Daily Spin)', 'wheel-of-fortune'); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="prize_daily_spin_probability" name="prize_daily_spin_probability" step="any" min="0" max="1">
|
||||
<p class="description"><?php _e('Chance for a FREE daily spin. Leave empty to use the same probability as the paid spin.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Status', 'wheel-of-fortune'); ?></th>
|
||||
<td>
|
||||
|
|
@ -73,4 +66,11 @@ if (!defined('ABSPATH')) exit;
|
|||
<input type="number" id="prize_discount_value" name="prize_discount_value" step="0.01" min="0" max="100">
|
||||
<p class="description"><?php _e('Vnesi vrednost popusta v %.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="prize_is_try_again"><?php _e('Try Again?', 'wheel-of-fortune'); ?></label></th>
|
||||
<td>
|
||||
<input type="checkbox" id="prize_is_try_again" name="prize_is_try_again" value="1">
|
||||
<p class="description"><?php _e('Označi, če je ta nagrada "Try Again" (ponovni poskus).', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -8,6 +8,8 @@ if (!defined('ABSPATH')) {
|
|||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// Preveri, če ima uporabnik pravice za dostop
|
||||
if (!current_user_can('manage_options')) {
|
||||
return;
|
||||
|
|
@ -67,6 +69,10 @@ if (isset($_POST['wheel_save_settings']) && check_admin_referer('wheel_settings_
|
|||
}
|
||||
update_option('wheel_spin_products', $spin_products);
|
||||
|
||||
// Dnevni spin - shrani izbrano kolo
|
||||
$daily_spin_wheel_id = isset($_POST['wof_daily_spin_wheel_id']) ? intval($_POST['wof_daily_spin_wheel_id']) : '';
|
||||
update_option('wof_daily_spin_wheel_id', $daily_spin_wheel_id);
|
||||
|
||||
// Prikaži sporočilo o uspehu
|
||||
add_settings_error('wheel_settings', 'settings_updated', __('Nastavitve so bile uspešno shranjene.', 'wheel-of-fortune'), 'updated');
|
||||
}
|
||||
|
|
@ -79,6 +85,11 @@ $max_spins = get_option('wheel_max_spins', 0);
|
|||
$send_emails = get_option('wheel_send_emails', false);
|
||||
$spin_products = get_option('wheel_spin_products', array());
|
||||
|
||||
// Pridobi vsa kolesa za dropdown
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRAY_A);
|
||||
$daily_spin_wheel_id = get_option('wof_daily_spin_wheel_id', '');
|
||||
|
||||
// Prikaži sporočila o napakah/uspehu
|
||||
settings_errors('wheel_settings');
|
||||
?>
|
||||
|
|
@ -118,6 +129,20 @@ settings_errors('wheel_settings');
|
|||
<p class="description"><?php echo esc_html__('Maksimalno število spinov, ki jih lahko ima uporabnik. Vrednost 0 pomeni brez omejitve.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wof_daily_spin_wheel_id"><?php echo esc_html__('Kolo za dnevni spin', 'wheel-of-fortune'); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select id="wof_daily_spin_wheel_id" name="wof_daily_spin_wheel_id">
|
||||
<option value=""><?php echo esc_html__('Izberi kolo', 'wheel-of-fortune'); ?></option>
|
||||
<?php foreach ($wheels as $wheel): ?>
|
||||
<option value="<?php echo esc_attr($wheel['id']); ?>" <?php selected($daily_spin_wheel_id, $wheel['id']); ?>><?php echo esc_html($wheel['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<p class="description"><?php echo esc_html__('Vsi registrirani uporabniki bodo vsakih 24 ur prejeli 1 spin na izbranem kolesu.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Možnost za pošiljanje e-pošte je odstranjena, saj se e-pošta pošlje vedno -->
|
||||
<input type="hidden" name="wheel_send_emails" value="1" />
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -128,12 +128,12 @@
|
|||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
/* Simple gradients for cross-browser compatibility */
|
||||
.wheel-segment-yellow { fill: #ffdd00; }
|
||||
.wheel-segment-green { fill: #88ff00; }
|
||||
.wheel-segment-red { fill: #ff5500; }
|
||||
.wheel-segment-pink { fill: #ff44aa; }
|
||||
.wheel-segment-blue { fill: #00ccff; }
|
||||
/* Simple solid fills for segment color classes */
|
||||
.wheel-segment-red { fill: #ff3131; }
|
||||
.wheel-segment-green { fill: #7ed957; }
|
||||
.wheel-segment-purple { fill: #8c52ff; }
|
||||
.wheel-segment-orange { fill: #ff914d; }
|
||||
.wheel-segment-blue { fill: #1da3e7; }
|
||||
|
||||
/* Divider between segments */
|
||||
.wheel-divider {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ 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
|
||||
|
|
@ -59,12 +58,22 @@ jQuery(document).ready(function($) {
|
|||
showPrizePopup(prize);
|
||||
isSpinning = false;
|
||||
|
||||
updateButtonState();
|
||||
if (wheelSpins > 0) {
|
||||
spinButton.prop('disabled', false).text(l10n.spin_button);
|
||||
} else {
|
||||
spinButton.prop('disabled', true).text(l10n.no_spins_left);
|
||||
}
|
||||
}
|
||||
|
||||
// Prikaz nagrade
|
||||
function showPrizePopup(prize) {
|
||||
var html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
||||
var isTryAgain = window.wof_spin_result.is_try_again === 1 || prize.is_try_again === 1;
|
||||
var html = '';
|
||||
if (isTryAgain) {
|
||||
html = '<p><strong>' + prize.name + '</strong></p>';
|
||||
} else {
|
||||
html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
||||
}
|
||||
if (window.wof_spin_result.discount_code) {
|
||||
html += '<p>' + l10n.discount_code_sent + '</p>';
|
||||
}
|
||||
|
|
@ -78,31 +87,9 @@ 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) 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
|
||||
}
|
||||
if (isSpinning || wheelSpins <= 0) return;
|
||||
|
||||
isSpinning = true;
|
||||
spinButton.prop('disabled', true).text(l10n.spinning);
|
||||
|
|
@ -116,16 +103,10 @@ 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();
|
||||
|
||||
|
|
@ -156,13 +137,17 @@ jQuery(document).ready(function($) {
|
|||
function handleError(message) {
|
||||
resultDiv.html('<p>' + message + '</p>').addClass('error').fadeIn(300);
|
||||
isSpinning = false;
|
||||
updateButtonState();
|
||||
if(wheelSpins > 0){
|
||||
spinButton.prop('disabled', false).text(l10n.spin_button);
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializacija
|
||||
function init() {
|
||||
updateSpinsCounter();
|
||||
updateButtonState();
|
||||
if (wheelSpins <= 0) {
|
||||
spinButton.prop('disabled', true).text(l10n.no_spins_left);
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
|
|||
169
code_export.txt
169
code_export.txt
|
|
@ -1,9 +1,5 @@
|
|||
"./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.
|
||||
|
|
@ -1135,6 +1131,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||
|
||||
if (!empty($name) && $wheel_id > 0) {
|
||||
$result = $wpdb->insert(
|
||||
|
|
@ -1150,8 +1147,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
'discount_value' => $discount_value,
|
||||
'email_subject' => $email_subject,
|
||||
'email_template' => $email_template,
|
||||
'is_try_again' => $is_try_again
|
||||
],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s']
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d']
|
||||
);
|
||||
|
||||
if ($result !== false) {
|
||||
|
|
@ -1177,6 +1175,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||
|
||||
if (!empty($name) && $prize_id > 0 && $wheel_id > 0) {
|
||||
$result = $wpdb->update(
|
||||
|
|
@ -1192,9 +1191,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||
'discount_value' => $discount_value,
|
||||
'email_subject' => $email_subject,
|
||||
'email_template' => $email_template,
|
||||
'is_try_again' => $is_try_again
|
||||
],
|
||||
['id' => $prize_id],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s'],
|
||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d'],
|
||||
['%d']
|
||||
);
|
||||
|
||||
|
|
@ -1474,6 +1474,7 @@ if (class_exists('WooCommerce')) {
|
|||
<tr><th scope="row"><label for="edit-prize-redemption-code"><?php _e('Redemption Code', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-redemption-code" name="prize_redemption_code" class="regular-text"><p class="description"><?php _e('Optional code for the user to redeem the prize.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-is-discount"><?php _e('Is Discount?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-discount" name="prize_is_discount" value="1"><p class="description"><?php _e('Check if the prize is a discount.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-discount-value"><?php _e('Discount Value (%)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-discount-value" name="prize_discount_value" step="0.01" min="0" max="100"><p class="description"><?php _e('Enter the discount value in %.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-is-try-again"><?php _e('Is Try Again?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-try-again" name="prize_is_try_again" value="1"><p class="description"><?php _e('Check if the prize is a try again.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-email-subject"><?php _e('Email Subject', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-email-subject" name="prize_email_subject" class="large-text"><p class="description"><?php _e('Subject for this prize\'s email. If empty, the default subject will be used.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||
<tr><th scope="row"><label for="edit-prize-email-template"><?php _e('Email Template', 'wheel-of-fortune'); ?></label></th><td><textarea id="edit-prize-email-template" name="prize_email_template" rows="10" class="large-text code"></textarea><p class="description"><?php _e('Available template tags:', 'wheel-of-fortune'); ?> <code>{user_name}</code>, <code>{prize_name}</code>, etc.</p></td></tr>
|
||||
</table>
|
||||
|
|
@ -1610,6 +1611,7 @@ jQuery(document).ready(function($) {
|
|||
$('#edit-prize-discount-value').val(prize.discount_value);
|
||||
$('#edit-prize-email-subject').val(prize.email_subject);
|
||||
$('#edit-prize-email-template').val(prize.email_template);
|
||||
$('#edit-prize-is-try-again').prop('checked', parseInt(prize.is_try_again, 10));
|
||||
|
||||
modal.show();
|
||||
} else {
|
||||
|
|
@ -1639,6 +1641,7 @@ jQuery(document).ready(function($) {
|
|||
discount_value: $('#edit-prize-discount-value').val(),
|
||||
email_subject: $('#edit-prize-email-subject').val(),
|
||||
email_template: $('#edit-prize-email-template').val(),
|
||||
is_try_again: $('#edit-prize-is-try-again').is(':checked') ? 1 : 0,
|
||||
};
|
||||
|
||||
// Debug: preveri wheel_id
|
||||
|
|
@ -2055,6 +2058,13 @@ if (!defined('ABSPATH')) exit;
|
|||
<input type="number" id="prize_discount_value" name="prize_discount_value" step="0.01" min="0" max="100">
|
||||
<p class="description"><?php _e('Vnesi vrednost popusta v %.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="prize_is_try_again"><?php _e('Try Again?', 'wheel-of-fortune'); ?></label></th>
|
||||
<td>
|
||||
<input type="checkbox" id="prize_is_try_again" name="prize_is_try_again" value="1">
|
||||
<p class="description"><?php _e('Označi, če je ta nagrada "Try Again" (ponovni poskus).', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>"""
|
||||
|
||||
|
||||
|
|
@ -2070,6 +2080,8 @@ if (!defined('ABSPATH')) {
|
|||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// Preveri, če ima uporabnik pravice za dostop
|
||||
if (!current_user_can('manage_options')) {
|
||||
return;
|
||||
|
|
@ -2129,6 +2141,10 @@ if (isset($_POST['wheel_save_settings']) && check_admin_referer('wheel_settings_
|
|||
}
|
||||
update_option('wheel_spin_products', $spin_products);
|
||||
|
||||
// Dnevni spin - shrani izbrano kolo
|
||||
$daily_spin_wheel_id = isset($_POST['wof_daily_spin_wheel_id']) ? intval($_POST['wof_daily_spin_wheel_id']) : '';
|
||||
update_option('wof_daily_spin_wheel_id', $daily_spin_wheel_id);
|
||||
|
||||
// Prikaži sporočilo o uspehu
|
||||
add_settings_error('wheel_settings', 'settings_updated', __('Nastavitve so bile uspešno shranjene.', 'wheel-of-fortune'), 'updated');
|
||||
}
|
||||
|
|
@ -2141,6 +2157,11 @@ $max_spins = get_option('wheel_max_spins', 0);
|
|||
$send_emails = get_option('wheel_send_emails', false);
|
||||
$spin_products = get_option('wheel_spin_products', array());
|
||||
|
||||
// Pridobi vsa kolesa za dropdown
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRAY_A);
|
||||
$daily_spin_wheel_id = get_option('wof_daily_spin_wheel_id', '');
|
||||
|
||||
// Prikaži sporočila o napakah/uspehu
|
||||
settings_errors('wheel_settings');
|
||||
?>
|
||||
|
|
@ -2180,6 +2201,20 @@ settings_errors('wheel_settings');
|
|||
<p class="description"><?php echo esc_html__('Maksimalno število spinov, ki jih lahko ima uporabnik. Vrednost 0 pomeni brez omejitve.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wof_daily_spin_wheel_id"><?php echo esc_html__('Kolo za dnevni spin', 'wheel-of-fortune'); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<select id="wof_daily_spin_wheel_id" name="wof_daily_spin_wheel_id">
|
||||
<option value=""><?php echo esc_html__('Izberi kolo', 'wheel-of-fortune'); ?></option>
|
||||
<?php foreach ($wheels as $wheel): ?>
|
||||
<option value="<?php echo esc_attr($wheel['id']); ?>" <?php selected($daily_spin_wheel_id, $wheel['id']); ?>><?php echo esc_html($wheel['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<p class="description"><?php echo esc_html__('Vsi registrirani uporabniki bodo vsakih 24 ur prejeli 1 spin na izbranem kolesu.', 'wheel-of-fortune'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Možnost za pošiljanje e-pošte je odstranjena, saj se e-pošta pošlje vedno -->
|
||||
<input type="hidden" name="wheel_send_emails" value="1" />
|
||||
</table>
|
||||
|
|
@ -4345,7 +4380,13 @@ jQuery(document).ready(function($) {
|
|||
|
||||
// Prikaz nagrade
|
||||
function showPrizePopup(prize) {
|
||||
var html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
||||
var isTryAgain = window.wof_spin_result.is_try_again === 1 || prize.is_try_again === 1;
|
||||
var html = '';
|
||||
if (isTryAgain) {
|
||||
html = '<p><strong>' + prize.name + '</strong></p>';
|
||||
} else {
|
||||
html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
||||
}
|
||||
if (window.wof_spin_result.discount_code) {
|
||||
html += '<p>' + l10n.discount_code_sent + '</p>';
|
||||
}
|
||||
|
|
@ -5484,6 +5525,12 @@ class WheelOfFortune {
|
|||
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
||||
register_activation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'activate'));
|
||||
register_deactivation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'deactivate'));
|
||||
|
||||
// --- CRON: filter in akcija vedno aktivna ---
|
||||
add_filter('cron_schedules', array($this, 'add_custom_cron_schedules'));
|
||||
add_action('wof_daily_spin_event', array($this, 'execute_daily_spin_cron'));
|
||||
// ------------------------------------------
|
||||
|
||||
add_action('admin_menu', array($this, 'admin_menu'));
|
||||
add_action('rest_api_init', array($this, 'register_rest_routes'));
|
||||
add_shortcode('wheel_of_fortune', array($this, 'shortcode'));
|
||||
|
|
@ -5610,30 +5657,19 @@ class WheelOfFortune {
|
|||
$this->run_migration();
|
||||
$this->set_default_options();
|
||||
$this->add_default_prizes();
|
||||
|
||||
// Debug: Preveri, ali se tabela za kolesa ustvari
|
||||
global $wpdb;
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products';
|
||||
|
||||
$wheels_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheels_table'") == $wheels_table;
|
||||
$products_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheel_products_table'") == $wheel_products_table;
|
||||
|
||||
error_log("=== ACTIVATION DEBUG ===");
|
||||
error_log("Wheels table exists: " . ($wheels_exists ? 'YES' : 'NO'));
|
||||
error_log("Products table exists: " . ($products_exists ? 'YES' : 'NO'));
|
||||
|
||||
if (!$wheels_exists) {
|
||||
error_log('Wheel of Fortune: Wheels table was not created properly during activation.');
|
||||
} else {
|
||||
error_log('Wheel of Fortune: Wheels table created successfully.');
|
||||
// --- TUKAJ OSTANE SAMO NAČRTOVANJE DOGODKA ---
|
||||
if (!wp_next_scheduled('wof_daily_spin_event')) {
|
||||
wp_schedule_event(time(), 'daily', 'wof_daily_spin_event');
|
||||
error_log("Wheel of Fortune: Cron job 'wof_daily_spin_event' scheduled.");
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
flush_rewrite_rules();
|
||||
error_log("Wheel of Fortune: Aktivacija končana.");
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
wp_clear_scheduled_hook('wof_daily_spin_event');
|
||||
error_log("Wheel of Fortune: Cron job 'wof_daily_spin_event' cleared.");
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
|
|
@ -5916,11 +5952,26 @@ class WheelOfFortune {
|
|||
array($this, 'edit_wheel_page')
|
||||
);
|
||||
|
||||
// Dodam podstran za nastavitve
|
||||
add_submenu_page(
|
||||
'wof-wheels',
|
||||
__('Settings', 'wheel-of-fortune'),
|
||||
__('Settings', 'wheel-of-fortune'),
|
||||
'manage_options',
|
||||
'wof-settings',
|
||||
array($this, 'settings_page')
|
||||
);
|
||||
|
||||
// Statistika in uporabniki
|
||||
add_submenu_page('wof-wheels', __('Statistics', 'wheel-of-fortune'), __('Statistics', 'wheel-of-fortune'), 'manage_options', 'wof-stats', array($this, 'stats_page'));
|
||||
add_submenu_page('wof-wheels', __('Users & Spins', 'wheel-of-fortune'), __('Users & Spins', 'wheel-of-fortune'), 'manage_options', 'wof-users', array($this, 'users_page'));
|
||||
}
|
||||
|
||||
// Dodam funkcijo za prikaz strani z nastavitvami
|
||||
public function settings_page() {
|
||||
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/settings-page.php';
|
||||
}
|
||||
|
||||
public function wheels_page() {
|
||||
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/wheels-page.php';
|
||||
}
|
||||
|
|
@ -6004,7 +6055,13 @@ class WheelOfFortune {
|
|||
$this->send_prize_email($user_id, $prize);
|
||||
}
|
||||
|
||||
$response_data = [ 'prize' => $prize, 'degree' => $degree, 'remaining_spins' => $new_spins, 'discount_code' => $redemption_code ];
|
||||
$response_data = [
|
||||
'prize' => $prize,
|
||||
'degree' => $degree,
|
||||
'remaining_spins' => $new_spins,
|
||||
'discount_code' => $redemption_code,
|
||||
'is_try_again' => isset($prize['is_try_again']) ? (int)$prize['is_try_again'] : 0
|
||||
];
|
||||
|
||||
return new WP_REST_Response(['success' => true, 'data' => $response_data], 200);
|
||||
}
|
||||
|
|
@ -6649,7 +6706,8 @@ class WheelOfFortune {
|
|||
update_post_meta($coupon_id, 'usage_limit_per_user', '1');
|
||||
update_post_meta($coupon_id, 'customer_email', array($user->user_email));
|
||||
update_post_meta($coupon_id, 'description', __('Wheel of Fortune', 'wheel-of-fortune'));
|
||||
|
||||
// Nastavi veljavnost 10 dni
|
||||
update_post_meta($coupon_id, 'date_expires', strtotime('+10 days'));
|
||||
return $coupon_id;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -6677,12 +6735,9 @@ class WheelOfFortune {
|
|||
$coupon->set_usage_limit(1);
|
||||
$coupon->set_usage_limit_per_user(1);
|
||||
$coupon->set_email_restrictions(array($user->user_email));
|
||||
|
||||
// Dodatna nastavitev
|
||||
$coupon->set_date_expires(strtotime('+30 days'));
|
||||
|
||||
// Nastavi veljavnost 10 dni
|
||||
$coupon->set_date_expires(strtotime('+10 days'));
|
||||
$coupon_id = $coupon->save();
|
||||
|
||||
// Preveri, ali je kupon res ustvarjen
|
||||
if ($coupon_id) {
|
||||
$verification_id = wc_get_coupon_id_by_code($code);
|
||||
|
|
@ -6699,7 +6754,6 @@ class WheelOfFortune {
|
|||
// Metoda 4: Neposredno vstavljanje v podatkovno bazo
|
||||
try {
|
||||
global $wpdb;
|
||||
|
||||
// Ustvari nov post tipa shop_coupon
|
||||
$wpdb->insert(
|
||||
$wpdb->posts,
|
||||
|
|
@ -6714,9 +6768,7 @@ class WheelOfFortune {
|
|||
'post_date_gmt' => current_time('mysql', 1)
|
||||
)
|
||||
);
|
||||
|
||||
$coupon_id = $wpdb->insert_id;
|
||||
|
||||
if ($coupon_id) {
|
||||
// Dodaj meta podatke za kupon
|
||||
$meta_data = array(
|
||||
|
|
@ -6726,9 +6778,10 @@ class WheelOfFortune {
|
|||
'usage_limit' => '1',
|
||||
'usage_limit_per_user' => '1',
|
||||
'customer_email' => serialize(array($user->user_email)),
|
||||
'description' => __('Wheel of Fortune', 'wheel-of-fortune')
|
||||
'description' => __('Wheel of Fortune', 'wheel-of-fortune'),
|
||||
// Nastavi veljavnost 10 dni
|
||||
'date_expires' => strtotime('+10 days')
|
||||
);
|
||||
|
||||
foreach ($meta_data as $meta_key => $meta_value) {
|
||||
$wpdb->insert(
|
||||
$wpdb->postmeta,
|
||||
|
|
@ -6739,7 +6792,6 @@ class WheelOfFortune {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $coupon_id;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -6760,8 +6812,9 @@ class WheelOfFortune {
|
|||
$coupon->set_usage_limit(1);
|
||||
$coupon->set_usage_limit_per_user(1);
|
||||
$coupon->set_email_restrictions(array($user->user_email));
|
||||
// Nastavi veljavnost 10 dni
|
||||
$coupon->set_date_expires(strtotime('+10 days'));
|
||||
$coupon_id = $coupon->save();
|
||||
|
||||
if ($coupon_id) {
|
||||
return $coupon_id;
|
||||
}
|
||||
|
|
@ -6930,6 +6983,44 @@ class WheelOfFortune {
|
|||
}
|
||||
wp_send_json_error(__('Napaka pri brisanju.', 'wheel-of-fortune'));
|
||||
}
|
||||
|
||||
// --- NOVE METODE ZA CRON ---
|
||||
public function add_custom_cron_schedules($schedules) {
|
||||
// Lahko pustiš custom interval, če ga uporabljaš še kje drugje, sicer ni potreben
|
||||
// $schedules['every_2_minutes'] = array(
|
||||
// 'interval' => 120,
|
||||
// 'display' => __('Every 2 minutes', 'wheel-of-fortune')
|
||||
// );
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
public function execute_daily_spin_cron() {
|
||||
wheel_of_fortune_debug_log('CRON: "wof_daily_spin_event" triggered.');
|
||||
$wheel_id = get_option('wof_daily_spin_wheel_id');
|
||||
if (empty($wheel_id)) {
|
||||
wheel_of_fortune_debug_log('CRON: No wheel selected for daily spin. Aborting.');
|
||||
return;
|
||||
}
|
||||
$users = get_users(array('fields' => 'ID'));
|
||||
wheel_of_fortune_debug_log('CRON: Found ' . count($users) . ' users to process for wheel ID ' . $wheel_id);
|
||||
foreach ($users as $user_id) {
|
||||
$last_given_meta_key = '_wof_daily_spin_last_given_' . $wheel_id;
|
||||
$last_given_timestamp = get_user_meta($user_id, $last_given_meta_key, true);
|
||||
// Sprememba: 24 ur (23*HOUR_IN_SECONDS)
|
||||
if (empty($last_given_timestamp) || (time() - $last_given_timestamp > 23 * HOUR_IN_SECONDS)) {
|
||||
$ok = wheel_of_fortune_add_spins($user_id, 1, $wheel_id);
|
||||
if ($ok) {
|
||||
update_user_meta($user_id, $last_given_meta_key, time());
|
||||
wheel_of_fortune_debug_log("CRON: Assigned spin to user $user_id for wheel $wheel_id. Result: " . var_export($ok, true));
|
||||
} else {
|
||||
wheel_of_fortune_debug_log("CRON: Failed to assign spin to user $user_id for wheel $wheel_id.");
|
||||
}
|
||||
} else {
|
||||
wheel_of_fortune_debug_log("CRON: User $user_id already received a spin recently. Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----------------------------
|
||||
}
|
||||
|
||||
// Initialize plugin
|
||||
|
|
|
|||
|
|
@ -105,6 +105,12 @@ class WheelOfFortune {
|
|||
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
||||
register_activation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'activate'));
|
||||
register_deactivation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'deactivate'));
|
||||
|
||||
// --- CRON: filter in akcija vedno aktivna ---
|
||||
add_filter('cron_schedules', array($this, 'add_custom_cron_schedules'));
|
||||
add_action('wof_daily_spin_event', array($this, 'execute_daily_spin_cron'));
|
||||
// ------------------------------------------
|
||||
|
||||
add_action('admin_menu', array($this, 'admin_menu'));
|
||||
add_action('rest_api_init', array($this, 'register_rest_routes'));
|
||||
add_shortcode('wheel_of_fortune', array($this, 'shortcode'));
|
||||
|
|
@ -125,8 +131,10 @@ class WheelOfFortune {
|
|||
add_action('wp_ajax_wheel_get_product', array($this, 'ajax_get_product'));
|
||||
add_action('wp_ajax_wheel_test_email', array($this, 'ajax_test_email'));
|
||||
add_action('wp_ajax_wheel_get_prizes', array($this, 'ajax_get_prizes'));
|
||||
add_action('wp_ajax_ajax_update_wheel_product_spins', array($this, 'ajax_update_wheel_product_spins'));
|
||||
add_action('wp_ajax_wof_delete_wheel_product', array($this, 'ajax_delete_wheel_product'));
|
||||
add_action('wp_ajax_wof_update_wheel_product_spins', array($this, 'ajax_update_wheel_product_spins'));
|
||||
add_action('wp_ajax_wheel_migrate_try_again', array($this, 'ajax_migrate_try_again'));
|
||||
add_action('wp_ajax_wheel_reset_spins_wheel', array($this, 'ajax_reset_spins_wheel'));
|
||||
|
||||
// Vključi testno skripto za kupone
|
||||
if (is_admin()) {
|
||||
|
|
@ -226,35 +234,22 @@ class WheelOfFortune {
|
|||
}
|
||||
|
||||
public function activate() {
|
||||
error_log("Wheel of Fortune: Aktivacija plugina...");
|
||||
$this->create_database_tables();
|
||||
$this->run_migration();
|
||||
$this->set_default_options();
|
||||
$this->add_default_prizes();
|
||||
|
||||
// Debug: Preveri, ali se tabela za kolesa ustvari
|
||||
global $wpdb;
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products';
|
||||
|
||||
$wheels_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheels_table'") == $wheels_table;
|
||||
$products_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheel_products_table'") == $wheel_products_table;
|
||||
|
||||
error_log("=== ACTIVATION DEBUG ===");
|
||||
error_log("Wheels table exists: " . ($wheels_exists ? 'YES' : 'NO'));
|
||||
error_log("Products table exists: " . ($products_exists ? 'YES' : 'NO'));
|
||||
|
||||
if (!$wheels_exists) {
|
||||
error_log('Wheel of Fortune: Wheels table was not created properly during activation.');
|
||||
} else {
|
||||
error_log('Wheel of Fortune: Wheels table created successfully.');
|
||||
// Dodaj cron opravilo za dnevne spine
|
||||
if (!wp_next_scheduled('wheel_daily_spins_cron')) {
|
||||
wp_schedule_event(time(), 'wheel_daily', 'wheel_daily_spins_cron');
|
||||
}
|
||||
|
||||
flush_rewrite_rules();
|
||||
error_log("Wheel of Fortune: Aktivacija končana.");
|
||||
// Izvedi migracijo za is_try_again stolpec
|
||||
$this->migrate_add_is_try_again_column();
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
wp_clear_scheduled_hook('wof_daily_spin_event');
|
||||
error_log("Wheel of Fortune: Cron job 'wof_daily_spin_event' cleared.");
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +291,6 @@ class WheelOfFortune {
|
|||
id mediumint(9) NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255) NOT NULL,
|
||||
slug varchar(100) NOT NULL,
|
||||
has_daily_spin tinyint(1) NOT NULL DEFAULT 0,
|
||||
created_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY slug (slug)
|
||||
|
|
@ -320,7 +314,6 @@ class WheelOfFortune {
|
|||
name varchar(255) NOT NULL,
|
||||
description text DEFAULT '',
|
||||
probability float NOT NULL,
|
||||
daily_spin_probability float DEFAULT NULL,
|
||||
is_active tinyint(1) NOT NULL DEFAULT 1,
|
||||
image_url varchar(255) DEFAULT '',
|
||||
email_subject varchar(255) DEFAULT '',
|
||||
|
|
@ -328,6 +321,7 @@ class WheelOfFortune {
|
|||
redemption_code varchar(100) DEFAULT '',
|
||||
is_discount tinyint(1) NOT NULL DEFAULT 0,
|
||||
discount_value float DEFAULT 0,
|
||||
is_try_again tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
KEY wheel_id (wheel_id)
|
||||
) $charset_collate;";
|
||||
|
|
@ -387,6 +381,29 @@ class WheelOfFortune {
|
|||
} else {
|
||||
error_log("Wheel of Fortune: Tabela $wheel_products_table uspešno ustvarjena.");
|
||||
}
|
||||
|
||||
// Migracija: dodaj stolpec is_try_again v obstoječe tabele
|
||||
$this->migrate_add_is_try_again_column();
|
||||
}
|
||||
|
||||
private function migrate_add_is_try_again_column() {
|
||||
global $wpdb;
|
||||
$table_prizes = $wpdb->prefix . 'wheel_prizes';
|
||||
|
||||
// Preveri, če stolpec is_try_again že obstaja
|
||||
$column_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_prizes LIKE 'is_try_again'");
|
||||
|
||||
if (empty($column_exists)) {
|
||||
// Dodaj stolpec is_try_again
|
||||
$result = $wpdb->query("ALTER TABLE $table_prizes ADD COLUMN is_try_again tinyint(1) NOT NULL DEFAULT 0");
|
||||
if ($result !== false) {
|
||||
error_log("Wheel of Fortune: Stolpec is_try_again uspešno dodan v tabelo $table_prizes");
|
||||
} else {
|
||||
error_log("Wheel of Fortune: Napaka pri dodajanju stolpca is_try_again v tabelo $table_prizes");
|
||||
}
|
||||
} else {
|
||||
error_log("Wheel of Fortune: Stolpec is_try_again že obstaja v tabeli $table_prizes");
|
||||
}
|
||||
}
|
||||
|
||||
private function run_migration() {
|
||||
|
|
@ -539,11 +556,26 @@ class WheelOfFortune {
|
|||
array($this, 'edit_wheel_page')
|
||||
);
|
||||
|
||||
// Dodam podstran za nastavitve
|
||||
add_submenu_page(
|
||||
'wof-wheels',
|
||||
__('Settings', 'wheel-of-fortune'),
|
||||
__('Settings', 'wheel-of-fortune'),
|
||||
'manage_options',
|
||||
'wof-settings',
|
||||
array($this, 'settings_page')
|
||||
);
|
||||
|
||||
// Statistika in uporabniki
|
||||
add_submenu_page('wof-wheels', __('Statistics', 'wheel-of-fortune'), __('Statistics', 'wheel-of-fortune'), 'manage_options', 'wof-stats', array($this, 'stats_page'));
|
||||
add_submenu_page('wof-wheels', __('Users & Spins', 'wheel-of-fortune'), __('Users & Spins', 'wheel-of-fortune'), 'manage_options', 'wof-users', array($this, 'users_page'));
|
||||
}
|
||||
|
||||
// Dodam funkcijo za prikaz strani z nastavitvami
|
||||
public function settings_page() {
|
||||
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/settings-page.php';
|
||||
}
|
||||
|
||||
public function wheels_page() {
|
||||
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/wheels-page.php';
|
||||
}
|
||||
|
|
@ -578,65 +610,29 @@ class WheelOfFortune {
|
|||
}
|
||||
|
||||
$wheel_id = $request->get_param('wheel_id');
|
||||
$spin_type = $request->get_param('spin_type') === 'daily' ? 'daily' : 'paid'; // NOVO
|
||||
|
||||
if (empty($wheel_id)) {
|
||||
return new WP_Error('no_wheel_id', __('Wheel ID is missing.', 'wheel-of-fortune'), ['status' => 400]);
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$wheel_data = $wpdb->get_row($wpdb->prepare("SELECT has_daily_spin FROM $wheels_table WHERE id = %d", $wheel_id), ARRAY_A);
|
||||
|
||||
$spins_left = 0;
|
||||
$is_eligible_for_daily = false;
|
||||
|
||||
// Preverjanje za DNEVNI SPIN
|
||||
if ($spin_type === 'daily') {
|
||||
if (!empty($wheel_data) && $wheel_data['has_daily_spin']) {
|
||||
$last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
|
||||
$last_spin_timestamp = get_user_meta($user_id, $last_spin_meta_key, true);
|
||||
|
||||
if (empty($last_spin_timestamp) || strtotime('today') > $last_spin_timestamp) {
|
||||
$is_eligible_for_daily = true;
|
||||
}
|
||||
}
|
||||
if (!$is_eligible_for_daily) {
|
||||
return new WP_Error('daily_spin_used', __('You have already used your free daily spin today.', 'wheel-of-fortune'), ['status' => 403]);
|
||||
}
|
||||
}
|
||||
// Preverjanje za PLAČAN SPIN
|
||||
else {
|
||||
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||
$user_spins = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
|
||||
$spins_left = $user_spins ? intval($user_spins->spins_available) : 0;
|
||||
|
||||
if ($spins_left <= 0) {
|
||||
return new WP_Error('no_spins', __('You have no spins left.', 'wheel-of-fortune'), ['status' => 403]);
|
||||
}
|
||||
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||
$user_spins = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
|
||||
$spins = $user_spins ? intval($user_spins->spins_available) : 0;
|
||||
|
||||
if ($spins <= 0) {
|
||||
return new WP_Error('no_spins', __('You have no spins left.', 'wheel-of-fortune'), ['status' => 403]);
|
||||
}
|
||||
|
||||
// Nadaljuj z logiko vrtenja
|
||||
$prizes = $this->get_wheel_prizes($wheel_id, $is_eligible_for_daily);
|
||||
$prizes = $this->get_wheel_prizes($wheel_id);
|
||||
if (empty($prizes)) {
|
||||
return new WP_Error('no_prizes', __('No prizes available.', 'wheel-of-fortune'), ['status' => 500]);
|
||||
}
|
||||
|
||||
// Uporabi delujočo logiko za izbiro nagrade
|
||||
$prize = $this->select_random_prize($prizes);
|
||||
$new_spins = $spins - 1;
|
||||
|
||||
// Zmanjšaj spine ali zabeleži dnevni spin
|
||||
if ($spin_type === 'daily') {
|
||||
$last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
|
||||
update_user_meta($user_id, $last_spin_meta_key, time());
|
||||
// Pridobimo trenutno število spinov za response
|
||||
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||
$user_spins_obj = $wpdb->get_row($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
|
||||
$new_spins = $user_spins_obj ? intval($user_spins_obj->spins_available) : 0;
|
||||
} else {
|
||||
$new_spins = $spins_left - 1;
|
||||
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||
$wpdb->update($spins_table, ['spins_available' => $new_spins, 'last_spin_date' => current_time('mysql')], ['user_id' => $user_id, 'wheel_id' => $wheel_id]);
|
||||
}
|
||||
$wpdb->update($spins_table, ['spins_available' => $new_spins, 'last_spin_date' => current_time('mysql')], ['user_id' => $user_id, 'wheel_id' => $wheel_id]);
|
||||
|
||||
$log_table = $wpdb->prefix . 'wheel_log';
|
||||
$wpdb->insert($log_table, ['user_id' => $user_id, 'wheel_id' => $wheel_id, 'prize_id' => $prize['id'], 'spin_date' => current_time('mysql'), 'redeemed' => 0]);
|
||||
|
|
@ -659,37 +655,26 @@ class WheelOfFortune {
|
|||
}
|
||||
}
|
||||
|
||||
if (get_option('wheel_send_emails', true)) {
|
||||
// Pošlji email samo, če ni "try again" nagrada
|
||||
if (get_option('wheel_send_emails', true) && (!isset($prize['is_try_again']) || $prize['is_try_again'] != 1)) {
|
||||
$this->send_prize_email($user_id, $prize);
|
||||
}
|
||||
|
||||
$response_data = [
|
||||
'prize' => $prize,
|
||||
'degree' => $degree,
|
||||
'remaining_spins' => $new_spins,
|
||||
$response_data = [
|
||||
'prize' => $prize,
|
||||
'degree' => $degree,
|
||||
'remaining_spins' => $new_spins,
|
||||
'discount_code' => $redemption_code,
|
||||
'spin_type' => $spin_type
|
||||
'is_try_again' => isset($prize['is_try_again']) ? (int)$prize['is_try_again'] : 0
|
||||
];
|
||||
|
||||
return new WP_REST_Response(['success' => true, 'data' => $response_data], 200);
|
||||
}
|
||||
|
||||
public function get_wheel_prizes($wheel_id = 1, $is_daily_spin = false) {
|
||||
public function get_wheel_prizes($wheel_id = 1) {
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wheel_prizes';
|
||||
$prizes = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE wheel_id = %d AND is_active = 1 ORDER BY id ASC", $wheel_id), ARRAY_A);
|
||||
|
||||
if ($is_daily_spin) {
|
||||
foreach ($prizes as &$prize) {
|
||||
// Če je daily_spin_probability nastavljena, jo uporabi. Sicer uporabi standardno.
|
||||
if (isset($prize['daily_spin_probability']) && $prize['daily_spin_probability'] !== null) {
|
||||
$prize['probability'] = $prize['daily_spin_probability'];
|
||||
}
|
||||
}
|
||||
unset($prize); // Prekini referenco
|
||||
}
|
||||
|
||||
return $prizes;
|
||||
return $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE wheel_id = %d AND is_active = 1 ORDER BY id ASC", $wheel_id), ARRAY_A);
|
||||
}
|
||||
|
||||
private function select_random_prize($prizes) {
|
||||
|
|
@ -795,23 +780,11 @@ class WheelOfFortune {
|
|||
$spins_left = $wpdb->get_var($wpdb->prepare("SELECT spins_available FROM $spins_table WHERE user_id = %d AND wheel_id = %d", $user_id, $wheel_id));
|
||||
$spins_left = ($spins_left === null) ? 0 : (int)$spins_left;
|
||||
|
||||
// Preveri, ali je dnevni spin na voljo
|
||||
$daily_spin_available = false;
|
||||
if (isset($wheel['has_daily_spin']) && $wheel['has_daily_spin']) {
|
||||
$last_spin_meta_key = '_wof_last_daily_spin_' . $wheel_id;
|
||||
$last_spin_timestamp = get_user_meta($user_id, $last_spin_meta_key, true);
|
||||
|
||||
if (empty($last_spin_timestamp) || strtotime('today') > $last_spin_timestamp) {
|
||||
$daily_spin_available = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Definiramo polje za prevode, da bo dostopno v PHP in JS
|
||||
$l10n = [
|
||||
'spin_button' => __('SPIN', 'wheel-of-fortune'),
|
||||
'spinning' => __('Spinning...', 'wheel-of-fortune'),
|
||||
'no_spins_left' => __('No More Spins', 'wheel-of-fortune'),
|
||||
'free_daily_spin' => __('FREE DAILY SPIN', 'wheel-of-fortune'),
|
||||
'congratulations' => __('Congratulations!', 'wheel-of-fortune'),
|
||||
'you_won' => __('You won:', 'wheel-of-fortune'),
|
||||
'close' => __('Close', 'wheel-of-fortune'),
|
||||
|
|
@ -825,7 +798,6 @@ class WheelOfFortune {
|
|||
'nonce' => wp_create_nonce('wp_rest'),
|
||||
'wheel_id' => $wheel_id,
|
||||
'spins_left' => $spins_left,
|
||||
'daily_spin_available' => $daily_spin_available,
|
||||
'prizes' => $prizes,
|
||||
'l10n' => $l10n // Uporabimo definirano polje
|
||||
));
|
||||
|
|
@ -899,7 +871,8 @@ class WheelOfFortune {
|
|||
$text_paths = '';
|
||||
|
||||
// Generate segments and text paths
|
||||
$segment_colors = ['#00dfe9', '#ff00c4', '#0cf101'];
|
||||
// Updated segment color palette
|
||||
$segment_colors = ['#ff3131', '#7ed957', '#8c52ff', '#ff914d', '#1da3e7'];
|
||||
for ($i = 0; $i < $num_prizes; $i++) {
|
||||
$prize = $prizes[$i];
|
||||
$start_angle = $i * $angle;
|
||||
|
|
@ -999,13 +972,13 @@ class WheelOfFortune {
|
|||
$name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : '';
|
||||
$description = isset($_POST['description']) ? sanitize_textarea_field($_POST['description']) : '';
|
||||
$probability = isset($_POST['probability']) ? floatval($_POST['probability']) : 0;
|
||||
$daily_spin_probability = isset($_POST['daily_spin_probability']) && $_POST['daily_spin_probability'] !== '' ? floatval($_POST['daily_spin_probability']) : null;
|
||||
$is_active = isset($_POST['is_active']) ? intval($_POST['is_active']) : 0;
|
||||
$redemption_code = isset($_POST['redemption_code']) ? sanitize_text_field($_POST['redemption_code']) : '';
|
||||
$is_discount = isset($_POST['is_discount']) ? intval($_POST['is_discount']) : 0;
|
||||
$email_subject = isset($_POST['email_subject']) ? sanitize_text_field($_POST['email_subject']) : '';
|
||||
$email_template = isset($_POST['email_template']) ? wp_kses_post($_POST['email_template']) : '';
|
||||
$discount_value = isset($_POST['discount_value']) ? floatval($_POST['discount_value']) : 0;
|
||||
$is_try_again = isset($_POST['is_try_again']) ? intval($_POST['is_try_again']) : 0;
|
||||
|
||||
if (empty($name)) {
|
||||
wp_send_json_error(['message' => __('Prize name is required.', 'wheel-of-fortune')]);
|
||||
|
|
@ -1019,10 +992,6 @@ class WheelOfFortune {
|
|||
wp_send_json_error(['message' => __('Probability must be between 0 and 1.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
if ($daily_spin_probability !== null && ($daily_spin_probability < 0 || $daily_spin_probability > 1)) {
|
||||
wp_send_json_error(['message' => __('Daily spin probability must be between 0 and 1.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wheel_prizes';
|
||||
|
||||
|
|
@ -1031,16 +1000,16 @@ class WheelOfFortune {
|
|||
'name' => $name,
|
||||
'description' => $description,
|
||||
'probability' => $probability,
|
||||
'daily_spin_probability' => $daily_spin_probability,
|
||||
'is_active' => $is_active,
|
||||
'redemption_code' => $redemption_code,
|
||||
'is_discount' => $is_discount,
|
||||
'email_subject' => $email_subject,
|
||||
'email_template' => $email_template,
|
||||
'discount_value' => $discount_value,
|
||||
'is_try_again' => $is_try_again,
|
||||
];
|
||||
|
||||
$format = ['%d', '%s', '%s', '%f', '%f', '%d', '%s', '%d', '%s', '%s', '%f'];
|
||||
$format = ['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%s', '%s', '%f', '%d'];
|
||||
|
||||
if ($prize_id > 0) {
|
||||
$result = $wpdb->update($table_name, $data, ['id' => $prize_id], $format, ['%d']);
|
||||
|
|
@ -1345,7 +1314,8 @@ class WheelOfFortune {
|
|||
update_post_meta($coupon_id, 'usage_limit_per_user', '1');
|
||||
update_post_meta($coupon_id, 'customer_email', array($user->user_email));
|
||||
update_post_meta($coupon_id, 'description', __('Wheel of Fortune', 'wheel-of-fortune'));
|
||||
|
||||
// Nastavi veljavnost 10 dni
|
||||
update_post_meta($coupon_id, 'date_expires', strtotime('+10 days'));
|
||||
return $coupon_id;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -1373,12 +1343,9 @@ class WheelOfFortune {
|
|||
$coupon->set_usage_limit(1);
|
||||
$coupon->set_usage_limit_per_user(1);
|
||||
$coupon->set_email_restrictions(array($user->user_email));
|
||||
|
||||
// Dodatna nastavitev
|
||||
$coupon->set_date_expires(strtotime('+30 days'));
|
||||
|
||||
// Nastavi veljavnost 10 dni
|
||||
$coupon->set_date_expires(strtotime('+10 days'));
|
||||
$coupon_id = $coupon->save();
|
||||
|
||||
// Preveri, ali je kupon res ustvarjen
|
||||
if ($coupon_id) {
|
||||
$verification_id = wc_get_coupon_id_by_code($code);
|
||||
|
|
@ -1395,7 +1362,6 @@ class WheelOfFortune {
|
|||
// Metoda 4: Neposredno vstavljanje v podatkovno bazo
|
||||
try {
|
||||
global $wpdb;
|
||||
|
||||
// Ustvari nov post tipa shop_coupon
|
||||
$wpdb->insert(
|
||||
$wpdb->posts,
|
||||
|
|
@ -1410,9 +1376,7 @@ class WheelOfFortune {
|
|||
'post_date_gmt' => current_time('mysql', 1)
|
||||
)
|
||||
);
|
||||
|
||||
$coupon_id = $wpdb->insert_id;
|
||||
|
||||
if ($coupon_id) {
|
||||
// Dodaj meta podatke za kupon
|
||||
$meta_data = array(
|
||||
|
|
@ -1422,9 +1386,10 @@ class WheelOfFortune {
|
|||
'usage_limit' => '1',
|
||||
'usage_limit_per_user' => '1',
|
||||
'customer_email' => serialize(array($user->user_email)),
|
||||
'description' => __('Wheel of Fortune', 'wheel-of-fortune')
|
||||
'description' => __('Wheel of Fortune', 'wheel-of-fortune'),
|
||||
// Nastavi veljavnost 10 dni
|
||||
'date_expires' => strtotime('+10 days')
|
||||
);
|
||||
|
||||
foreach ($meta_data as $meta_key => $meta_value) {
|
||||
$wpdb->insert(
|
||||
$wpdb->postmeta,
|
||||
|
|
@ -1435,7 +1400,6 @@ class WheelOfFortune {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $coupon_id;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -1456,8 +1420,9 @@ class WheelOfFortune {
|
|||
$coupon->set_usage_limit(1);
|
||||
$coupon->set_usage_limit_per_user(1);
|
||||
$coupon->set_email_restrictions(array($user->user_email));
|
||||
// Nastavi veljavnost 10 dni
|
||||
$coupon->set_date_expires(strtotime('+10 days'));
|
||||
$coupon_id = $coupon->save();
|
||||
|
||||
if ($coupon_id) {
|
||||
return $coupon_id;
|
||||
}
|
||||
|
|
@ -1478,6 +1443,12 @@ class WheelOfFortune {
|
|||
* @param array $prize The prize details array.
|
||||
*/
|
||||
public function send_prize_email($user_id, $prize) {
|
||||
// Ne pošlji emaila, če je nagrada "try again"
|
||||
if (isset($prize['is_try_again']) && $prize['is_try_again'] == 1) {
|
||||
wheel_of_fortune_debug_log("send_prize_email: Email ni poslan za 'try again' nagrado: {$prize['name']}");
|
||||
return;
|
||||
}
|
||||
|
||||
$user = get_userdata($user_id);
|
||||
if (!$user) {
|
||||
wheel_of_fortune_debug_log("send_prize_email: Uporabnik z ID {$user_id} ni bil najden.");
|
||||
|
|
@ -1599,33 +1570,123 @@ class WheelOfFortune {
|
|||
}
|
||||
|
||||
public function ajax_delete_wheel_product() {
|
||||
check_ajax_referer('wof_delete_wheel_product');
|
||||
check_ajax_referer('wof_delete_wheel_product', '_ajax_nonce');
|
||||
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error(__('Nimaš dovoljenja.', 'wheel-of-fortune'));
|
||||
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||
}
|
||||
global $wpdb;
|
||||
|
||||
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
||||
|
||||
// Debug informacije
|
||||
error_log("=== AJAX DELETE WHEEL PRODUCT DEBUG ===");
|
||||
error_log("POST data: " . print_r($_POST, true));
|
||||
error_log("ID to delete: " . $id);
|
||||
if (!$id) {
|
||||
wp_send_json_error(['message' => __('Invalid ID.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
if ($id > 0) {
|
||||
$table = $wpdb->prefix . 'wheel_of_fortune_products';
|
||||
error_log("Table: " . $table);
|
||||
|
||||
$result = $wpdb->delete($table, ['id' => $id], ['%d']);
|
||||
error_log("Delete result: " . $result);
|
||||
error_log("Last SQL query: " . $wpdb->last_query);
|
||||
error_log("Last SQL error: " . $wpdb->last_error);
|
||||
|
||||
if ($result !== false) {
|
||||
wp_send_json_success();
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wheel_of_fortune_products';
|
||||
|
||||
$result = $wpdb->delete($table_name, ['id' => $id]);
|
||||
|
||||
if ($result !== false) {
|
||||
wp_send_json_success(['message' => __('Product deleted successfully.', 'wheel-of-fortune')]);
|
||||
} else {
|
||||
wp_send_json_error(['message' => __('Failed to delete product.', 'wheel-of-fortune')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajax_migrate_try_again() {
|
||||
check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
|
||||
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
$this->migrate_add_is_try_again_column();
|
||||
|
||||
wp_send_json_success(['message' => __('Migration completed successfully. The is_try_again column has been added to the database.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
public function ajax_reset_spins_wheel() {
|
||||
check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
|
||||
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
$wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0;
|
||||
|
||||
if (!$wheel_id) {
|
||||
wp_send_json_error(['message' => __('Wheel ID is required.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||
|
||||
// Preveri, če kolo obstaja
|
||||
$wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wheels_table WHERE id = %d", $wheel_id));
|
||||
|
||||
if (!$wheel_exists) {
|
||||
wp_send_json_error(['message' => __('Selected wheel does not exist.', 'wheel-of-fortune')]);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
wp_send_json_success([
|
||||
'message' => sprintf(__('All spins for wheel ID %d have been successfully reset to 0.', 'wheel-of-fortune'), $wheel_id),
|
||||
'affected_users' => $result
|
||||
]);
|
||||
} else {
|
||||
wp_send_json_error(['message' => __('An error occurred while resetting spins.', 'wheel-of-fortune')]);
|
||||
}
|
||||
}
|
||||
|
||||
// --- NOVE METODE ZA CRON ---
|
||||
public function add_custom_cron_schedules($schedules) {
|
||||
// Lahko pustiš custom interval, če ga uporabljaš še kje drugje, sicer ni potreben
|
||||
// $schedules['every_2_minutes'] = array(
|
||||
// 'interval' => 120,
|
||||
// 'display' => __('Every 2 minutes', 'wheel-of-fortune')
|
||||
// );
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
public function execute_daily_spin_cron() {
|
||||
wheel_of_fortune_debug_log('CRON: "wof_daily_spin_event" triggered.');
|
||||
$wheel_id = get_option('wof_daily_spin_wheel_id');
|
||||
if (empty($wheel_id)) {
|
||||
wheel_of_fortune_debug_log('CRON: No wheel selected for daily spin. Aborting.');
|
||||
return;
|
||||
}
|
||||
$users = get_users(array('fields' => 'ID'));
|
||||
wheel_of_fortune_debug_log('CRON: Found ' . count($users) . ' users to process for wheel ID ' . $wheel_id);
|
||||
foreach ($users as $user_id) {
|
||||
$last_given_meta_key = '_wof_daily_spin_last_given_' . $wheel_id;
|
||||
$last_given_timestamp = get_user_meta($user_id, $last_given_meta_key, true);
|
||||
// Sprememba: 24 ur (23*HOUR_IN_SECONDS)
|
||||
if (empty($last_given_timestamp) || (time() - $last_given_timestamp > 23 * HOUR_IN_SECONDS)) {
|
||||
$ok = wheel_of_fortune_add_spins($user_id, 1, $wheel_id);
|
||||
if ($ok) {
|
||||
update_user_meta($user_id, $last_given_meta_key, time());
|
||||
wheel_of_fortune_debug_log("CRON: Assigned spin to user $user_id for wheel $wheel_id. Result: " . var_export($ok, true));
|
||||
} else {
|
||||
wheel_of_fortune_debug_log("CRON: Failed to assign spin to user $user_id for wheel $wheel_id.");
|
||||
}
|
||||
} else {
|
||||
wheel_of_fortune_debug_log("CRON: User $user_id already received a spin recently. Skipping.");
|
||||
}
|
||||
}
|
||||
wp_send_json_error(__('Napaka pri brisanju.', 'wheel-of-fortune'));
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
}
|
||||
|
||||
// Initialize plugin
|
||||
|
|
|
|||
Loading…
Reference in New Issue