Editing: /home/goacom/public_html/scratch_extract/lifting.php
<?php /* * 1. START SESSION & CHECK LOGIN */ session_start(); // If the user is not logged in, redirect them to the login page if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } /* * DATABASE CONFIGURATION */ $host = 'localhost'; $db = 'tishanw1_melbets'; $user = 'tishanw1_melbets'; $pass = 'tishanw1_melbets'; $charset = 'utf8mb4'; // Get the REAL logged-in user ID from the session $current_user_id = $_SESSION['user_id']; // Database Connection $mysqli = new mysqli($host, $user, $pass, $db); if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } // --- PROCESS SUBMISSION --- $message = ""; $error = false; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $amount = $_POST['amount'] ?? 0; // 1. Validate Amount if ($amount < 200 || $amount > 30000) { $message = "Amount must be between 200 and 30,000."; $error = true; } else { // 2. Validate Transaction Password // Check if user has a transaction password set $stmt_check_pass = $mysqli->prepare("SELECT transaction_password FROM user_transaction_passwords WHERE user_id = ?"); $stmt_check_pass->bind_param("i", $current_user_id); $stmt_check_pass->execute(); $pass_result = $stmt_check_pass->get_result(); $trans_data = $pass_result->fetch_assoc(); $has_trans_pass = ($trans_data !== null); $input_trans_pass = $_POST['transaction_password'] ?? ''; if (!$has_trans_pass) { $message = "Transaction password not set. Please set it in Security Center first."; $error = true; } elseif (empty($input_trans_pass)) { $message = "Please enter your transaction password."; $error = true; } elseif (!password_verify($input_trans_pass, $trans_data['transaction_password'])) { $message = "Incorrect transaction password."; $error = true; } else { // 3. If all valid, Process Withdrawal $method_name = $_POST['method_name'] ?? 'E-wallet'; $account_num = $_POST['account_number'] ?? ''; $stmt = $mysqli->prepare("INSERT INTO deposit_withdrawal_history (user_id, type, amount, status, payment_method, account_number, created_at) VALUES (?, 'withdrawal', ?, 'pending', ?, ?, NOW())"); $stmt->bind_param("idss", $current_user_id, $amount, $method_name, $account_num); if ($stmt->execute()) { $message = "Withdrawal request submitted successfully!"; // Redirect to avoid resubmission on refresh echo "<script>window.location.href='lifting.php';</script>"; exit(); } else { $message = "Error submitting request."; $error = true; } } } } // --- FETCH DATA --- // 1. Get User Methods (Specific to logged-in user) $check_method = $mysqli->prepare("SELECT * FROM user_withdrawal_methods WHERE user_id = ?"); $check_method->bind_param("i", $current_user_id); $check_method->execute(); $methods_result = $check_method->get_result(); $methods = $methods_result->fetch_all(MYSQLI_ASSOC); $has_wallet = !empty($methods); $method_count = count($methods); // 2. Get User Balance (Specific to logged-in user) $user_stmt = $mysqli->prepare("SELECT balance FROM users WHERE id = ?"); $user_stmt->bind_param("i", $current_user_id); $user_stmt->execute(); $user_balance = $user_stmt->get_result()->fetch_assoc()['balance'] ?? 0; // 3. Calculate Stats (Specific to logged-in user) $sql_main = "SELECT (SELECT COALESCE(SUM(amount),0) FROM deposit_withdrawal_history WHERE user_id=? AND type='deposit') + (SELECT COALESCE(SUM(amount),0) FROM transactions WHERE user_id=? AND type='win') - (SELECT COALESCE(SUM(amount),0) FROM deposit_withdrawal_history WHERE user_id=? AND type='withdrawal') as main_wallet"; $stmt_main = $mysqli->prepare($sql_main); $stmt_main->bind_param("iii", $current_user_id, $current_user_id, $current_user_id); $stmt_main->execute(); $main_wallet = $stmt_main->get_result()->fetch_assoc()['main_wallet'] ?? 0; // Daily Withdrawal Limit Logic (Specific to logged-in user) $today = date('Y-m-d'); $sql_limit = "SELECT COUNT(*) as count FROM deposit_withdrawal_history WHERE user_id = ? AND type = 'withdrawal' AND DATE(created_at) = ?"; $stmt_limit = $mysqli->prepare($sql_limit); $stmt_limit->bind_param("is", $current_user_id, $today); $stmt_limit->execute(); $withdrawn_count = $stmt_limit->get_result()->fetch_assoc()['count']; $limit_total = 10; $remaining = $limit_total - $withdrawn_count; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="MELBETE - Withdrawal" /> <title>MELBETE - Withdrawal</title> <link rel="stylesheet" href="index.css" /> <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap" rel="stylesheet" /> <style> body { margin: 0; padding: 0; font-family: 'Outfit', sans-serif; background-color: #f5f5f5; } .text-cricxo { color: rgb(240, 104, 39); } .border-cricxo { border-color: rgb(240, 104, 39); } .msg-box { padding: 10px; text-align: center; background: #d1fae5; color: #065f46; border-radius: 5px; margin-bottom: 10px; } .msg-box.error { background: #fee2e2; color: #991b1b; } /* Card Slider Styles */ .slider-container { overflow: hidden; position: relative; } .slider-track { display: flex; transition: transform 0.3s ease-in-out; width: 100%; } .slide-item { min-width: 100%; height: 192px; position: relative; } /* Helper for hiding/showing checkmark */ .check-icon { display: none; } .active-card .check-icon { display: block; } </style> </head> <body> <div id="root"> <div class="w-full bg-bodyColor"> <div class="max-w-[1000px] mx-auto"> <!-- Header --> <div class="flex justify-between items-center h-12" style="background: rgb(240, 104, 39);"> <svg onclick="history.back()" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" class="text-white cursor-pointer text-[26px] w-16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M217.9 256L345 129c9.4-9.4 9.4-24.6 0-33.9-9.4-9.4-24.6-9.3-34 0L167 239c-9.1 9.1-9.3 23.7-.7 33.1L310.9 417c4.7 4.7 10.9 7 17 7s12.3-2.3 17-7c9.4-9.4 9.4-24.6 0-33.9L217.9 256z"></path></svg> <div class="w-full text-white text-[19px] text-center">Withdrawal</div> </div> <div class="flex flex-col bg-white text-gray-800 p-4" style="margin: 0px auto;"> <!-- Message --> <?php if($message): ?> <div class="msg-box <?php echo ($error) ? 'error' : ''; ?>"><?php echo $message; ?></div> <?php endif; ?> <!-- Header Info --> <div class="flex items-center justify-center gap-2 w-full mb-4 pb-2" style="border-bottom: 3px solid rgb(240, 104, 39);"> <img height="35" width="35" alt="" src="/ewallet.webp"> <h1 class="text-lg text-cricxo">E-wallet</h1> </div> <p class="text-lg text-gray-600 mb-2"> Connected e-wallets (<?php echo $method_count; ?>) </p> <!-- Plus Button Condition --> <?php if($method_count < 3): ?> <div class="py-2 flex flex-1 justify-end relative"> <span class="absolute top-[50%] h-px w-full bg-gray-300"></span> <a href="add.php" class="bg-[#f06827] rounded-full p-3 shadow-md z-10 my-2 block text-white"> <img alt="" height="24" width="24" src="/plus.svg"> </a> </div> <?php endif; ?> <!-- CONDITIONAL DISPLAY: WALLET EXISTS --> <?php if($has_wallet): ?> <div class="relative mb-6"> <div class="relative h-48 overflow-hidden rounded-xl slider-container"> <div id="cardSlider" class="slider-track"> <?php foreach($methods as $index => $m): $masked_num = '***' . substr($m['account_number'], -3); $bg_image = '/withdrawalCardBg.png'; $is_active = ($index === 0) ? 'active-card border-4 border-cricxo border-opacity-80' : ''; ?> <div class="slide-item"> <div onclick="selectCard(<?php echo $index; ?>, '<?php echo addslashes($m['method_name']); ?>', '<?php echo $m['account_number']; ?>', this)" class="absolute inset-0 transition-transform duration-300 ease-in-out cursor-pointer <?php echo $is_active; ?>" style="background-image: url('<?php echo $bg_image; ?>'); background-size: 100% 100%; background-position: center center; border-radius: 1.5rem;"> <!-- Checkmark (Hidden by default, shown via JS active-card class) --> <div class="check-icon absolute top-2 right-2 bg-green-500 rounded-full p-1 z-10"> <svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path></svg> </div> <div class="p-4 h-full flex flex-col justify-between text-white"> <div class="pl-10 pt-3"> <p class="text-sm"><?php echo htmlspecialchars($m['method_name']); ?></p> <p class="text-lg font-bold"><?php echo $masked_num; ?></p> </div> <div> <p class="text-xs"><?php echo date('Y-m-d', strtotime($m['created_at'])); ?></p> </div> </div> </div> </div> <?php endforeach; ?> </div> </div> <!-- Dots Indicator --> <div class="flex justify-center mt-2 space-x-2"> <?php foreach($methods as $index => $m): ?> <button onclick="goToSlide(<?php echo $index; ?>)" class="w-2 h-2 rounded-full <?php echo ($index === 0) ? 'bg-red-600' : 'bg-gray-300'; ?>" id="dot-<?php echo $index; ?>"></button> <?php endforeach; ?> </div> </div> <!-- STATE 1: NO WALLET --> <?php else: ?> <div class="relative w-full flex flex-col items-center py-8 mb-6" style="background: url('/assets/img/empty-wallet.png') 0% 0% / cover; height: 192px;"> <div class="w-48 h-28 rounded-xl flex items-end justify-center text-gray-400 text-sm"> Connect an e-wallet </div> </div> <?php endif; ?> <!-- Stats --> <div class="w-full mt-4"> <p class="text-xs text-gray-500 mb-2">Lifting time : 9 am to 11 pm</p> <p class="text-xs text-gray-500 mb-1"> Daily Withdrawal Limit : <?php echo $limit_total; ?> (Times), Remaining Withdrawal : <?php echo $remaining; ?> (Times) </p> <p class="text-sm mb-3">Main wallet : ৳ <?php echo number_format($main_wallet, 2); ?></p> <p class="text-sm mb-3">Available amount : ৳ <?php echo number_format($user_balance, 2); ?></p> <button class="flex items-center justify-center gap-2 border rounded-full px-4 py-2 text-sm font-medium text-gray-300 mb-4 mx-auto" style="color: rgb(240, 104, 39);"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path><path d="M3 3v5h5"></path><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"></path><path d="M16 16h5v5"></path></svg> Restore balance </button> </div> <!-- Withdrawal Form --> <div> <p class="py-2">Withdrawal amount :</p> <form action="lifting.php" method="POST" id="withdrawForm"> <!-- Hidden inputs --> <input type="hidden" id="input_method_name" name="method_name" value="<?php echo $methods[0]['method_name'] ?? ''; ?>"> <input type="hidden" id="input_account_number" name="account_number" value="<?php echo $methods[0]['account_number'] ?? ''; ?>"> <!-- Hidden Transaction Password (Populated by JS) --> <input type="hidden" id="hidden_trans_pass" name="transaction_password" value=""> <div class="space-y-3"> <div class="relative"> <span class="max-w-20 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 text-sm">Quantity</span> <input id="withdrawAmount" name="amount" placeholder="200 ~ 30,000" class="w-full border rounded-lg px-3 py-4 pl-32 text-sm focus:outline-none focus:ring-2 focus:ring-red-500" type="number" value="" <?php echo (!$has_wallet) ? 'disabled' : ''; ?>> </div> </div> <!-- Submit Button (Type Button to intercept click) --> <button id="submitBtn" type="button" onclick="openWithdrawModal()" class="w-full mt-6 py-4 rounded-lg text-sm font-medium bg-gray-300 text-gray-500 cursor-not-allowed"> Withdraw </button> </form> </div> <!-- Video Embed --> <div style="width: 100%; height: 500px; position: relative; padding-top: 1rem; margin-top: 20px;"> <iframe width="100%" height="500" src="https://www.youtube.com/embed/6vr6nSVYmaA?autoplay=1&mute=0&playsinline=1" title="Deposit" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe> </div> </div> </div> </div> </div> <!-- TRANSACTION PASSWORD MODAL --> <div id="transPassModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50" style="display:none;"> <div class="bg-white rounded-lg p-6 w-80 relative"> <h3 class="text-lg font-bold mb-4 text-center">Security Check</h3> <p class="text-sm text-gray-600 mb-4 text-center">Enter your transaction password to confirm withdrawal.</p> <div class="mb-4"> <label class="block text-sm text-gray-700 mb-1">Transaction Password</label> <input type="password" id="modalTransPass" class="w-full border rounded px-3 py-2" placeholder="Enter password"> </div> <div class="flex justify-between gap-2"> <button type="button" onclick="closeWithdrawModal()" class="flex-1 bg-gray-300 text-white py-2 rounded">Cancel</button> <button type="button" onclick="confirmWithdrawal()" class="flex-1 bg-[#f06827] text-white py-2 rounded">Confirm</button> </div> </div> </div> <script> let currentSlide = 0; const totalSlides = <?php echo $method_count; ?>; const userBalance = <?php echo $user_balance; ?>; // Slider Logic function goToSlide(index) { if (index < 0 || index >= totalSlides) return; currentSlide = index; updateSlider(); } function updateSlider() { const track = document.getElementById('cardSlider'); if(track) { track.style.transform = 'translateX(-' + (currentSlide * 100) + '%)'; } // Update Dots for (let i = 0; i < totalSlides; i++) { const dot = document.getElementById('dot-' + i); if(dot) { if (i === currentSlide) { dot.classList.remove('bg-gray-300'); dot.classList.add('bg-red-600'); } else { dot.classList.remove('bg-red-600'); dot.classList.add('bg-gray-300'); } } } } function selectCard(index, method, number, cardElement) { // 1. Visual Highlight const allCards = document.querySelectorAll('.slide-item > div'); allCards.forEach(card => { card.classList.remove('active-card', 'border-4', 'border-cricxo', 'border-opacity-80'); const check = card.querySelector('.check-icon'); if(check) check.style.display = 'none'; }); // Add highlight to clicked card cardElement.classList.add('active-card', 'border-4', 'border-cricxo', 'border-opacity-80'); const check = cardElement.querySelector('.check-icon'); if(check) check.style.display = 'block'; // 2. Update Form Data document.getElementById('input_method_name').value = method; document.getElementById('input_account_number').value = number; // 3. Slide to this card goToSlide(index); // 4. Trigger validation check validateAmount(); } // Form Validation Logic const input = document.getElementById('withdrawAmount'); const submitBtn = document.getElementById('submitBtn'); function validateAmount() { const val = parseFloat(input.value); // Validation: Between 200 & 30000, and within balance const isValid = (val >= 200 && val <= 30000 && val <= userBalance && val > 0 && !isNaN(val)); if (isValid) { submitBtn.disabled = false; submitBtn.classList.remove('bg-gray-300', 'text-gray-500', 'cursor-not-allowed'); submitBtn.classList.add('bg-[#f06827]', 'text-white', 'cursor-pointer'); } else { submitBtn.disabled = true; submitBtn.classList.add('bg-gray-300', 'text-gray-500', 'cursor-not-allowed'); submitBtn.classList.remove('bg-[#f06827]', 'text-white', 'cursor-pointer'); } return isValid; } // Listen for typing if(input) { input.addEventListener('input', validateAmount); input.addEventListener('keyup', validateAmount); } // --- NEW: Modal Logic --- function openWithdrawModal() { // Final validation check before opening modal if(!validateAmount()) return; // Show modal document.getElementById('transPassModal').style.display = 'flex'; // Clear previous password input document.getElementById('modalTransPass').value = ''; } function closeWithdrawModal() { document.getElementById('transPassModal').style.display = 'none'; } function confirmWithdrawal() { const pass = document.getElementById('modalTransPass').value; if(pass === "") { alert("Please enter your transaction password."); return; } // Set the password to the hidden input in the form document.getElementById('hidden_trans_pass').value = pass; // Submit the form document.getElementById('withdrawForm').submit(); } </script> </body> </html>
💾 Save