prefix . 'wheel_prizes'; $wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0; $name = isset($_POST['prize_name']) ? sanitize_text_field($_POST['prize_name']) : ''; $description = isset($_POST['prize_description']) ? sanitize_textarea_field($_POST['prize_description']) : ''; $probability = isset($_POST['prize_probability']) ? floatval($_POST['prize_probability']) : 0; $is_active = isset($_POST['prize_is_active']) ? 1 : 0; $redemption_code = isset($_POST['prize_redemption_code']) ? sanitize_text_field($_POST['prize_redemption_code']) : ''; $is_discount = isset($_POST['prize_is_discount']) ? 1 : 0; $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( $prizes_table, [ 'wheel_id' => $wheel_id, 'name' => $name, 'description' => $description, 'probability' => $probability, 'is_active' => $is_active, 'redemption_code' => $redemption_code, 'is_discount' => $is_discount, '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'] ); if ($result !== false) { echo '

' . __('Prize added successfully!', 'wheel-of-fortune') . '

'; } else { echo '

' . __('Error adding prize. Please try again.', 'wheel-of-fortune') . '

'; } } else { echo '

' . __('Please fill in all required fields.', 'wheel-of-fortune') . '

'; } } elseif ($_POST['action'] === 'edit_prize' && check_admin_referer('wheel_prizes_nonce')) { global $wpdb; $prizes_table = $wpdb->prefix . 'wheel_prizes'; $prize_id = isset($_POST['prize_id']) ? intval($_POST['prize_id']) : 0; $wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0; $name = isset($_POST['prize_name']) ? sanitize_text_field($_POST['prize_name']) : ''; $description = isset($_POST['prize_description']) ? sanitize_textarea_field($_POST['prize_description']) : ''; $probability = isset($_POST['prize_probability']) ? floatval($_POST['prize_probability']) : 0; $is_active = isset($_POST['prize_is_active']) ? 1 : 0; $redemption_code = isset($_POST['prize_redemption_code']) ? sanitize_text_field($_POST['prize_redemption_code']) : ''; $is_discount = isset($_POST['prize_is_discount']) ? 1 : 0; $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( $prizes_table, [ 'wheel_id' => $wheel_id, 'name' => $name, 'description' => $description, 'probability' => $probability, 'is_active' => $is_active, 'redemption_code' => $redemption_code, 'is_discount' => $is_discount, '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'], ['%d'] ); if ($result !== false) { echo '

' . __('Prize updated successfully!', 'wheel-of-fortune') . '

'; } else { echo '

' . __('Error updating prize. Please try again.', 'wheel-of-fortune') . '

'; } } else { echo '

' . __('Please fill in all required fields.', 'wheel-of-fortune') . '

'; } } } if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && in_array($_POST['action'], ['add_wheel_product', 'delete_wheel_product']) ) { global $wpdb; $wheels_table = $wpdb->prefix . 'wof_wheels'; $wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products'; if ($_POST['action'] === 'add_wheel_product' && check_admin_referer('wheel_products_nonce')) { $wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0; $product_id = isset($_POST['product_id']) ? intval($_POST['product_id']) : 0; $spins_per_purchase = isset($_POST['spins_per_purchase']) ? intval($_POST['spins_per_purchase']) : 1; // Debug informacije error_log("=== WHEEL PRODUCT DEBUG ==="); error_log("POST data: " . print_r($_POST, true)); error_log("Wheel ID: " . $wheel_id); error_log("Product ID: " . $product_id); error_log("Spins per purchase: " . $spins_per_purchase); error_log("Table name: " . $wheel_products_table); // Preveri, ali tabela obstaja $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheel_products_table'") == $wheel_products_table; error_log("Table exists: " . ($table_exists ? 'YES' : 'NO')); if (!$table_exists) { error_log("ERROR: Tabela $wheel_products_table ne obstaja!"); echo '

' . __('Napaka: Tabela za produkte ne obstaja. Prosimo, deaktivirajte in ponovno aktivirajte plugin.', 'wheel-of-fortune') . '

'; return; } if ($wheel_id > 0 && $product_id > 0 && $spins_per_purchase > 0) { // Preveri, ali kolo obstaja $wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wheels_table WHERE id = %d", $wheel_id)); error_log("Wheel exists: " . $wheel_exists); if (!$wheel_exists) { error_log("ERROR: Kolo z ID $wheel_id ne obstaja!"); echo '

' . __('Napaka: Izbrano kolo ne obstaja.', 'wheel-of-fortune') . '

'; return; } // Preveri, ali produkt obstaja if (class_exists('WooCommerce')) { $product = wc_get_product($product_id); if (!$product) { error_log("ERROR: Produkt z ID $product_id ne obstaja!"); echo '

' . __('Napaka: Izbrani produkt ne obstaja.', 'wheel-of-fortune') . '

'; return; } } $data = [ 'wheel_id' => $wheel_id, 'product_id' => $product_id, 'spins_per_purchase' => $spins_per_purchase ]; error_log("Data to insert: " . print_r($data, true)); // Preveri, ali je produkt že povezan s tem kolesom $existing_product = $wpdb->get_var($wpdb->prepare( "SELECT id FROM $wheel_products_table WHERE wheel_id = %d AND product_id = %d", $wheel_id, $product_id )); if ($existing_product) { error_log("Product already exists for this wheel, updating..."); } else { error_log("Adding new product to wheel..."); } $result = $wpdb->replace( $wheel_products_table, $data, ['%d', '%d', '%d'] ); error_log("SQL result: " . $result); error_log("Last SQL query: " . $wpdb->last_query); error_log("Last SQL error: " . $wpdb->last_error); if ($result !== false) { echo '

' . __('Produkt je bil uspešno dodan ali posodobljen.', 'wheel-of-fortune') . '

'; } else { echo '

' . __('Napaka pri dodajanju produkta. Preveri vnos.', 'wheel-of-fortune') . '

'; } } else { error_log("Validation failed - Wheel ID: $wheel_id, Product ID: $product_id, Spins: $spins_per_purchase"); echo '

' . __('Napaka pri dodajanju produkta. Preveri vnos.', 'wheel-of-fortune') . '

'; } } elseif ($_POST['action'] === 'delete_wheel_product' && check_admin_referer('wheel_products_nonce')) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; if ($id > 0) { $wpdb->delete($wheel_products_table, ['id' => $id], ['%d']); echo '

' . __('Produkt je bil izbrisan.', 'wheel-of-fortune') . '

'; } } } global $wpdb; $wheels_table = $wpdb->prefix . 'wof_wheels'; $prizes_table = $wpdb->prefix . 'wheel_prizes'; // Get the current wheel ID from URL $wheel_id = isset($_GET['wheel_id']) ? intval($_GET['wheel_id']) : 0; // Fetch wheel data $wheel = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wheels_table WHERE id = %d", $wheel_id), ARRAY_A); if (!$wheel) { echo '

' . __('Wheel not found.', 'wheel-of-fortune') . '

'; return; } // Fetch prizes for this specific wheel $prizes = $wpdb->get_results($wpdb->prepare("SELECT * FROM $prizes_table WHERE wheel_id = %d ORDER BY id ASC", $wheel_id), ARRAY_A); $total_probability = array_sum(wp_list_pluck($prizes, 'probability')); // Fetch povezane produkte za to kolo $wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products'; $products = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wheel_products_table WHERE wheel_id = %d", $wheel_id), ARRAY_A); // Pridobi vse WooCommerce produkte za dropdown if (class_exists('WooCommerce')) { $all_products = wc_get_products(array('limit' => -1, 'status' => 'publish')); } else { $all_products = array(); } ?>


:

1): ?>

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

0 && $total_probability < 1): ?>

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

get_name()) : esc_html($prod['product_id']); ?>