This commit is contained in:
1 parent
d77be150d9
commit
5210c9d2e6
11 files changed
+732
-284
No files matched your search
+54
-47
@@ -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>
|
||||
Reference in new issue
Block a user