email template

This commit is contained in:
Mark Poljansek committed 2025-06-23 17:14:41 +02:00
1 parent 101d8bc623
commit e11fa6fa5b
10 files changed
+1367 -7127

No files matched your search

+47 -55
View File
@@ -21,6 +21,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$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']) : '';
// Dodaj nova polja
$email_template_id = isset($_POST['email_template_id']) ? intval($_POST['email_template_id']) : 0;
$funded_account_name = isset($_POST['funded_account_name']) ? sanitize_text_field($_POST['funded_account_name']) : null;
$funded_account_value = isset($_POST['funded_account_value']) ? floatval($_POST['funded_account_value']) : null;
if (!empty($name) && $wheel_id > 0) {
$result = $wpdb->insert(
$prizes_table,
@@ -35,8 +40,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
'discount_value' => $discount_value,
'email_subject' => $email_subject,
'email_template' => $email_template,
// Dodaj nova polja
'email_template_id' => $email_template_id,
'funded_account_name' => $funded_account_name,
'funded_account_value' => $funded_account_value
],
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s']
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d', '%s', '%f']
);
if ($result !== false) {
@@ -63,6 +73,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$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']) : '';
// Dodaj nova polja
$email_template_id = isset($_POST['email_template_id']) ? intval($_POST['email_template_id']) : 0;
$funded_account_name = isset($_POST['funded_account_name']) ? sanitize_text_field($_POST['funded_account_name']) : null;
$funded_account_value = isset($_POST['funded_account_value']) ? floatval($_POST['funded_account_value']) : null;
if (!empty($name) && $prize_id > 0 && $wheel_id > 0) {
$result = $wpdb->update(
$prizes_table,
@@ -77,9 +92,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
'discount_value' => $discount_value,
'email_subject' => $email_subject,
'email_template' => $email_template,
// Dodaj nova polja
'email_template_id' => $email_template_id,
'funded_account_name' => $funded_account_name,
'funded_account_value' => $funded_account_value
],
['id' => $prize_id],
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s'],
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d', '%s', '%f'],
['%d']
);
@@ -356,65 +376,37 @@ if (class_exists('WooCommerce')) {
<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', '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>
<!-- DODAJ NOVA POLJA ZA FUNDED ACCOUNT -->
<tr><th scope="row"><label for="edit-funded-account-name"><?php _e('Funded Account Name', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-funded-account-name" name="funded_account_name" class="regular-text"><p class="description"><?php _e('e.g., Funded7 $50k. Used for the {funded_account_name} tag.', 'wheel-of-fortune'); ?></p></td></tr>
<tr><th scope="row"><label for="edit-funded-account-value"><?php _e('Funded Account Value', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-funded-account-value" name="funded_account_value" step="any" min="0"><p class="description"><?php _e('e.g., 50000. Used for the {funded_account_value} tag.', 'wheel-of-fortune'); ?></p></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>
<!-- SPREMENI SEKCIJO ZA EMAIL -->
<tr>
<th scope="row"><label for="edit-prize-email-template-id"><?php _e('Email Content', 'wheel-of-fortune'); ?></label></th>
<td>
<select id="edit-prize-email-template-id" name="email_template_id">
<option value="0"><?php _e('-- Custom Email --', 'wheel-of-fortune'); ?></option>
<?php
global $wpdb;
$email_templates = $wpdb->get_results("SELECT id, name FROM {$wpdb->prefix}wheel_email_templates ORDER BY name ASC", ARRAY_A);
foreach ($email_templates as $template) : ?>
<option value="<?php echo esc_attr($template['id']); ?>"><?php echo esc_html($template['name']); ?></option>
<?php endforeach; ?>
</select>
<p class="description"><?php _e('Choose a pre-written template or select "Custom Email" to write your own below.', 'wheel-of-fortune'); ?></p>
</td>
</tr>
<tr class="custom-email-fields-edit"><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. Only used if "Custom Email" is selected.', 'wheel-of-fortune'); ?></p></td></tr>
<tr class="custom-email-fields-edit"><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>, <code>{prize_description}</code>, <code>{redemption_code}</code>, <code>{site_name}</code>, <code>{site_url}</code>, <code>{date}</code>, <code>{time}</code>, <strong><code>{funded_account_name}</code></strong>, <strong><code>{funded_account_value}</code></strong></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-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>
<p class="submit"><input type="submit" class="button button-primary" value="<?php esc_attr_e('Save Changes', 'wheel-of-fortune'); ?>"></p>
</form>
</div>
</div>
<script>
jQuery(document).ready(function($) {
$('.delete-wheel-product').on('click', function(e) {
e.preventDefault();
if (!confirm('Ali res želiš izbrisati ta produkt?')) return;
var row = $(this).closest('tr');
var id = $(this).data('id');
$.post(ajaxurl, {
action: 'wof_delete_wheel_product',
id: id,
_ajax_nonce: '<?php echo wp_create_nonce('wof_delete_wheel_product'); ?>'
}, function(response) {
if (response.success) {
row.fadeOut(300, function() { $(this).remove(); });
} else {
alert(response.data || 'Napaka pri brisanju.');
}
});
});
$('.spins-editable').on('click', function() {
var td = $(this);
if (td.find('input').length) return;
var current = td.text();
var id = td.data('id');
var input = $('<input type="number" min="1" style="width:60px;">').val(current);
td.html(input);
input.focus();
input.on('blur', function() {
var val = input.val();
if (val && val != current) {
$.post(ajaxurl, {
action: 'wof_update_wheel_product_spins',
id: id,
spins: val,
_ajax_nonce: '<?php echo wp_create_nonce('wof_update_wheel_product_spins'); ?>'
}, function(response) {
if (response.success) {
td.text(val);
} else {
alert(response.data || 'Napaka pri shranjevanju.');
td.text(current);
}
});
} else {
td.text(current);
}
});
});
});
</script>