Editing: /home/goacom/public_html/scratch_extract/rescue-fund.php
<?php /* * 1. START SESSION & CHECK LOGIN */ session_start(); // If not logged in, redirect if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } // Database Config $host = 'localhost'; $db = 'tishanw1_melbets'; $user = 'tishanw1_melbets'; $pass = 'tishanw1_melbets'; $user_id = $_SESSION['user_id']; // Connect $conn = new mysqli($host, $user, $pass, $db); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // --- PROCESS CLAIM --- $message = ""; $msg_type = ""; // success or error if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'claim') { $claim_amount = $_POST['amount']; if ($claim_amount > 0) { // 1. Add to User Balance $update = $conn->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); $update->bind_param("di", $claim_amount, $user_id); $update->execute(); // 2. Log Transaction $insert_trx = $conn->prepare("INSERT INTO transactions (user_id, type, amount, status) VALUES (?, 'win', ?, 'completed')"); $insert_trx->bind_param("id", $user_id, $claim_amount); $insert_trx->execute(); // 3. Log Claim $insert_claim = $conn->prepare("INSERT INTO rescue_fund_claims (user_id, amount) VALUES (?, ?)"); $insert_claim->bind_param("id", $user_id, $claim_amount); $insert_claim->execute(); $message = "Rescue fund claimed successfully!"; $msg_type = "success"; } } // --- FETCH DATA & CALCULATE STATS --- // 1. User Info $stmt_user = $conn->prepare("SELECT phone, balance FROM users WHERE id = ?"); $stmt_user->bind_param("i", $user_id); $stmt_user->execute(); $user_result = $stmt_user->get_result(); $user_data = $user_result->fetch_assoc(); $phone = $user_data['phone']; $balance = number_format($user_data['balance'], 2); // 2. Calculate Net Loss // Logic: (Total Bets) - (Total Wins) = Net Loss $sql_loss = "SELECT (SELECT COALESCE(SUM(amount),0) FROM transactions WHERE user_id = ? AND type = 'bet') - (SELECT COALESCE(SUM(amount),0) FROM transactions WHERE user_id = ? AND type = 'win') as net_loss"; $stmt_loss = $conn->prepare($sql_loss); $stmt_loss->bind_param("ii", $user_id, $user_id); $stmt_loss->execute(); $loss_data = $stmt_loss->get_result()->fetch_assoc(); $net_loss = $loss_data['net_loss'] ?? 0; // 3. Calculate Rescue Percentage based on Tiers $percentage = 0; if ($net_loss >= 10000000) { $percentage = 39; } elseif ($net_loss >= 5000000) { $percentage = 19; } elseif ($net_loss >= 1000000) { $percentage = 10; } elseif ($net_loss >= 300000) { $percentage = 9; } elseif ($net_loss >= 100000) { $percentage = 8; } elseif ($net_loss >= 30000) { $percentage = 7; } elseif ($net_loss >= 3000) { $percentage = 6; } elseif ($net_loss >= 300) { $percentage = 5; } // 4. Calculate Available Amount $available_rescue = $net_loss * ($percentage / 100); ?> <!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 - Official Gaming & Betting Platform." /> <title>MELBETE - Rescue Fund</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" /> <!-- Swiper CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" /> <style> /* Simple inline styles for modal toggle */ .hidden { display: none; } .block { display: flex; } </style> </head> <body> <div id="root"> <div class="w-full bg-bodyColor"> <div class="max-w-[1000px] mx-auto"> <div class="w-full bg-[#f5f5f9] min-h-screen"> <!-- Header --> <div class="bg-black w-full"> <div class="flex justify-between items-center h-12" style="background: rgb(240, 104, 39);"> <a href="reward-center.php" class="text-white cursor-pointer text-[26px] w-16 flex items-center justify-center"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" 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> </a> <div class="w-full text-white text-[19px] text-center"> Rescue Fund </div> </div> </div> <!-- Profile Header Area --> <div class="w-full h-[158px]" style="background-image: url("/assets/mall-bg-DpNY8vgf.jpg"); background-size: cover; background-repeat: no-repeat;"> <div class="pt-7 pl-6 flex items-center w-full"> <img alt="profile" class="w-14 h-14 rounded-full border-2 border-white" src="./assets/img/user.png"> <div class="ml-3"> <h3 class="font-medium text-white"> <?php echo $phone; ?> </h3> <p class="text-base font-bold text-white"> ৳ <?php echo $balance; ?> </p> </div> </div> </div> <!-- Main Content: Stats --> <div class="p-6 mt-4"> <div class="bg-white rounded-xl shadow-md p-6 text-center mb-4"> <p class="text-sm text-gray-500 uppercase tracking-wide">Total Net Loss</p> <h2 class="text-3xl font-bold text-gray-800 mb-2"> ৳ <?php echo number_format($net_loss, 2); ?> </h2> <div class="w-full h-px bg-gray-100 my-4"></div> <p class="text-sm text-gray-500 uppercase tracking-wide mb-1">Rescue Fund Percentage</p> <p class="text-xl font-bold text-orange-500 mb-4"><?php echo $percentage; ?>%</p> <?php if($available_rescue > 0): ?> <form method="POST"> <input type="hidden" name="action" value="claim"> <input type="hidden" name="amount" value="<?php echo $available_rescue; ?>"> <button type="submit" class="w-full bg-orange-500 text-white py-3 rounded-lg font-bold text-lg shadow hover:bg-orange-600 transition-colors"> Claim ৳ <?php echo number_format($available_rescue, 2); ?> </button> </form> <?php else: ?> <p class="text-gray-400 text-sm">No funds available to claim yet.</p> <?php endif; ?> </div> <!-- Button to open Modal --> <button onclick="document.getElementById('rulesModal').classList.remove('hidden')" class="w-full border border-orange-500 text-orange-500 py-3 rounded-lg font-bold hover:bg-orange-50 transition-colors"> View Rescue Rules </button> <!-- Message --> <?php if($message): ?> <div class="mt-4 p-3 rounded text-center text-white <?php echo $msg_type == 'success' ? 'bg-green-600' : 'bg-red-600'; ?>"> <?php echo $message; ?> </div> <?php endif; ?> </div> <!-- MODAL (Bottom Sheet) - Initially Hidden --> <div id="rulesModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-end justify-center"> <div class="bg-white w-full shadow-lg transform transition-transform duration-300 ease-out h-[50vh] translate-y-0 rounded-t-2xl" style="max-height: 80vh; overflow-y: auto;"> <!-- Modal Header --> <div class="flex items-center justify-between p-4 border-b sticky top-0 bg-white z-10"> <h3 class="text-xl font-semibold text-gray-800">Rescue fund rules</h3> <button onclick="document.getElementById('rulesModal').classList.add('hidden')" class="text-gray-500 hover:text-gray-700 text-2xl"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke-miterlimit="10" stroke-width="32" d="M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z"></path><path fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M320 320 192 192m0 128 128-128"></path></svg> </button> </div> <!-- Modal Content --> <div class="p-4"> <div class="rescue-content"> <table class="w-full border-collapse" style="line-height: 1.5;"> <thead> <tr class="border-b"> <th class="text-left py-2 px-3 font-medium text-gray-700">Product</th> <th class="text-left py-2 px-3 font-medium text-gray-700">Net loss</th> <th class="text-left py-2 px-3 font-medium text-gray-700">Amount available</th> </tr> </thead> <tbody> <!-- Fish Games --> <tr class="border-b border-gray-100"> <td class="py-2 px-3 text-gray-800 font-medium align-top border-r" rowspan="8">Fish</td> <td class="py-2 px-3 text-gray-700">≥300.00</td> <td class="py-2 px-3 text-gray-700">5%</td> </tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥3,000.00</td><td class="py-2 px-3 text-gray-700">6%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥30,000.00</td><td class="py-2 px-3 text-gray-700">7%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥100,000.00</td><td class="py-2 px-3 text-gray-700">8%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥300,000.00</td><td class="py-2 px-3 text-gray-700">9%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥1,000,000.00</td><td class="py-2 px-3 text-gray-700">10%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥5,000,000.00</td><td class="py-2 px-3 text-gray-700">19%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥10,000,000.00</td><td class="py-2 px-3 text-gray-700">39%</td></tr> <!-- Slot Games --> <tr class="border-b border-gray-100"> <td class="py-2 px-3 text-gray-800 font-medium align-top border-r" rowspan="8">Slot</td> <td class="py-2 px-3 text-gray-700">≥300.00</td> <td class="py-2 px-3 text-gray-700">5%</td> </tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥3,000.00</td><td class="py-2 px-3 text-gray-700">6%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥30,000.00</td><td class="py-2 px-3 text-gray-700">7%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥100,000.00</td><td class="py-2 px-3 text-gray-700">8%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥300,000.00</td><td class="py-2 px-3 text-gray-700">9%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥1,000,000.00</td><td class="py-2 px-3 text-gray-700">10%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥5,000,000.00</td><td class="py-2 px-3 text-gray-700">19%</td></tr> <tr class="border-b border-gray-100"><td class="py-2 px-3 text-gray-700">≥10,000,000.00</td><td class="py-2 px-3 text-gray-700">39%</td></tr> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </div> <section class="Toastify" aria-live="polite" aria-atomic="false" aria-relevant="additions text" aria-label="Notifications Alt+T"></section> </body> </html> <?php $conn->close(); ?>
💾 Save