Viewing File: /home/quiczmwg/wealthwisenetwork.org/withdraw.php

<?php
// Start the session
session_start();

// Check if the 'userid' session is not set
if (!isset($_SESSION['userid'])) {
    header("Location: ./login.php");
    exit();
}

// Include database connection and other necessary files
include_once('_db.php');

// Set the user ID from the session variable
$userid = $_SESSION['userid'];

// Check if form data is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve user ID
    $userid = $_POST['userid'];

    // Retrieve withdrawal amount
    $withdrawalAmount = $_POST['amount'];
    $withdrawalMethod = $_POST['withdrawal_method']; // Wallet or Bank
    $bankName = $_POST['bank_name'] ?? ''; // Bank Name
    $accountNumber = $_POST['account_number'] ?? ''; // Bank Account Number
    $sortCode = $_POST['sort_code'] ?? ''; // Bank Sort Code or similar field

    // Query to retrieve user's account balance
    $stmt = $conn->prepare("SELECT account_balance FROM user_login WHERE userid = ?");
    $stmt->bind_param("s", $userid);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();

    // Check if withdrawal amount is greater than account balance
    if ($withdrawalAmount > $row['account_balance']) {
        // Insufficient balance, display error message
        $_SESSION['withdrawal_error'] = "Insufficient balance. Please enter an amount less than or equal to your account balance.";
    } else {
        // Sufficient balance, proceed with withdrawal process
        // Example code for withdrawal: 
        // Update balance, save withdrawal record, etc.
        $_SESSION['withdrawal_success'] = "Withdrawal successful!";

        // Optionally, handle withdrawal to Bank or Wallet based on the method selected
        if ($withdrawalMethod == 'bank') {
            // Store bank details in database or process accordingly
        }

        // Deduct the amount from the account balance
        $newBalance = $row['account_balance'] - $withdrawalAmount;
        $stmt = $conn->prepare("UPDATE user_login SET account_balance = ? WHERE userid = ?");
        $stmt->bind_param("ds", $newBalance, $userid);
        $stmt->execute();
    }

    // Close statement
    $stmt->close();
}
?>


<!DOCTYPE html>
<html lang="zxx">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1200px">
    <link href="assets/css/font-awesome-all.css" rel="stylesheet">
    <link href="assets/css/flaticon.css" rel="stylesheet">
    <link href="assets/css/owl.css" rel="stylesheet">
    <link href="assets/css/bootstrap.css" rel="stylesheet">
    <link href="assets/css/jquery.fancybox.min.css" rel="stylesheet">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/color.css" rel="stylesheet">
    <link href="assets/css/rtl.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/responsive.css" rel="stylesheet">
    <link rel="stylesheet" href="users/assets/css/bootstrap.min.css">

    <link rel="stylesheet" href="users/assets/css/boxicons.min.css">

    <link rel="stylesheet" href="users/assets/css/meanmenu.css">

    <link rel="stylesheet" href="users/assets/css/animate.min.css">

    <link rel="stylesheet" href="users/assets/css/owl.carousel.min.css">
    <link rel="stylesheet" href="users/assets/css/owl.theme.default.min.css">

    <link rel="stylesheet" href="users/assets/fonts/flaticon.css">

    <link rel="stylesheet" href="users/assets/css/modal-video.min.css">

    <link rel="stylesheet" href="users/assets/css/odometer.min.css">

    <link rel="stylesheet" href="users/assets/css/style.css">

    <link rel="stylesheet" href="users/assets/css/responsive.css">
    <title>wealthwisenetwork.org</title>
    <link rel="icon" type="image/png" href="users/assets/img/favicon.png">
    <style>
        th {
            background: #ff6a40 !important;
            color: #fff;
        }
    </style>
</head>
<style>
    .container {
        display: flex;
        justify-content: space-between;
    }

    .work-item {
        border: 1px solid #ddd;
        border-radius: 10px;
        overflow: hidden;
    }

    .box-header {
        text-align: center;
        padding: 20px;
        background-color: transparent;
        /* No background color by default */
    }

    .account-box-header,
    .profit-box-header,
    .withdrawal-box-header {
        background-color: #001f3d;
        /* Navy blue background for image part */
        border-radius: 10px 10px 0 0;
    }

    .box-content {
        padding: 20px;
        text-align: center;
    }

    .box-content h4 {
        margin-bottom: 10px;
    }

    .box-content p {
        font-size: 1.2em;
    }
</style>



<style>
    #google_translate_element {

        color: transparent;
    }

    #google_translate_element a {

        display: none;
    }

    select.google_translate_element {

        color: black;
    }

    div.goog-te-gadget {

        color: transparent;
    }

    div.goog-te-gadget {
        display: table-caption;
        color: transparent !important;
    }

    .goog-te-gadget .goog-te-combo {
        padding: 11px 10px;
        font-size: 15px;
        font-weight: 500;
        background: #f8952c;
        border: 1px solid #f8952c;
        color: #fff !important;
        cursor: pointer;
        outline: none;
        font-family: 'Poppins', sans-serif;
        border-radius: 5px;
        margin: 0;
    }
</style>


<!-- page wrapper -->

<body class="boxed_wrapper ltr">




    <!-- main header -->
    <header class="main-header style-one style-six">
        <div class="header-top">
            <div class="auto-container">
                <div class="top-inner clearfix">
                    <ul class="info top-left pull-left">
                        <li><i class="fas fa-map-marker-alt"></i>26 Scrutton Street, London, England, EC2A 4RJ</li>

                    </ul>
                    <div class="top-right pull-right">
                        <ul class="social-links clearfix">
                            <li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
                            <li><a href="#"><i class="fab fa-google-plus-g"></i></a></li>
                            <li><a href="#"><i class="fab fa-twitter"></i></a></li>
                            <li><a href="#"><i class="fab fa-linkedin-in"></i></a></li>
                            <li><a href="#"><i class="fab fa-instagram"></i></a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="header-lower">
            <div class="auto-container">
                <div class="outer-box clearfix">
                    <div class="logo-box pull-left">
                        <figure class="logo">
                            <a href="index.php"><img src="images/wealthwise.png" alt="" width="200px"></a>
                        </figure>
                    </div>
                    <div class="menu-area pull-right">
                        <!--Mobile Navigation Toggler-->
                        <div class="mobile-nav-toggler">
                            <i class="icon-bar"></i>
                            <i class="icon-bar"></i>
                            <i class="icon-bar"></i>
                        </div>
                        <nav class="main-menu navbar-expand-md navbar-light">
                            <div class="collapse navbar-collapse show clearfix" id="navbarSupportedContent">
                                <ul class="navigation clearfix">
                                    <li><a href="index.php">HOME</a></li>
                                    <li><a href="about.php">ABOUT</a></li>
                                    <li><a href="faq.php">FAQ</a></li>
                                    <li><a href="team.php">TEAM</a></li>
                                    <li><a href="contact.php">CONTACT</a></li>
                                    <!-- Conditional rendering -->
                                    <?php if (isset($_SESSION['userid'])) : ?>
                                        <li><a href="dashboard.php">DASHBOARD</a></li>
                                        <li><a href="logout.php">LOGOUT</a></li>
                                    <?php else : ?>
                                        <li><a href="register.php">SIGNUP</a></li>
                                        <li><a href="login.php">LOGIN</a></li>
                                    <?php endif; ?>
                                </ul>
                            </div>
                        </nav>
                        <div class="menu-right-content clearfix">
                            <div class="btn-box">
                                <a href="https://t.me/Loreengilbert" class="theme-btn style-two">Telegram Group</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!--sticky Header-->
        <div class="sticky-header">
            <div class="auto-container">
                <div class="outer-box clearfix">
                    <div class="logo-box pull-left">
                        <figure class="logo"><a href="index.php"><img src="images/wealthwise.png" alt="" width="250px"></a></figure>
                    </div>
                    <div class="menu-area pull-right">
                        <nav class="main-menu clearfix">
                            <!--Keep This Empty / Menu will come through Javascript-->
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </header>
    <!-- main-header end -->

    <!-- Mobile Menu  -->
    <div class="mobile-menu">
        <div class="menu-backdrop"></div>
        <div class="close-btn"><i class="fas fa-times"></i></div>

        <nav class="menu-box">
            <div class="nav-logo"><a href="index.php"><img src="images/fqmarket.png" alt="" title=""></a></div>
            <div class="menu-outer"><!--Here Menu Will Come Automatically Via Javascript / Same Menu as in Header--></div>
            <div class="contact-info">
                <h4>Contact Info</h4>
                <ul>
                    <li>26 Scrutton Street, London, England, EC2A 4RJ</li>
                    <li><a href="tel:+">+88 Coming Soon</a></li>
                    <li><a href="mailto:Wealthwiseinvestments1@gmail.com">Wealthwiseinvestments1@gmail.com</a></li>
                </ul>
            </div>
            <div class="social-links">
                <ul class="clearfix">
                    <li><a href="#"><span class="fab fa-twitter"></span></a></li>
                    <li><a href="#"><span class="fab fa-facebook-square"></span></a></li>
                    <li><a href="#"><span class="fab fa-pinterest-p"></span></a></li>
                    <li><a href="#"><span class="fab fa-instagram"></span></a></li>
                    <li><a href="#"><span class="fab fa-youtube"></span></a></li>
                </ul>
            </div>
        </nav>
    </div><!-- End Mobile Menu -->
    <!--Page Title-->
    <section class="page-title centred" style="background-image: url(assets/images/background/page-title-5.jpg);">
        <div class="auto-container">
            <div class="content-box clearfix">

                <h1>Withdraw Now</h1>
                <ul class="bread-crumb clearfix">
                    <li><a href="index.php">Home</a></li>
                    <li>Withdraw </li>
                </ul>
            </div>
        </div>
    </section>
    <!--End Page Title-->


    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <div class="blog-details-area ptb-100">
        <div class="container">
            <div class="row mt-5" style="display: flex; align-items: stretch;">
                <!-- Sidebar Column -->
                <?php include 'sidebar.php' ?>

                <!-- User Data Column -->
                <div class="col-lg-9 mt-3" style="display: flex; flex-direction: column;">
                    <div class="single_blog_header">
                        <div class="single_blog_img1">
    <?php
// Start session and check login
session_start();
if (!isset($_SESSION['userid'])) {
    header("Location: login.php");
    exit();
}

// Database connection
include_once('_db.php');

// Fetch account balance from database
$userid = $_SESSION['userid'];
$stmt = $conn->prepare("SELECT account_balance FROM user_login WHERE userid = ?");
$stmt->bind_param("s", $userid);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$account_balance = $row['account_balance'];
$stmt->close();
?>

<!-- Display messages -->
<?php if (isset($_SESSION['withdrawal_success'])): ?>
    <div class="alert alert-success" style="background-color: #d4edda; border-color: #c3e6cb; color: #155724;">
        <?= $_SESSION['withdrawal_success']; unset($_SESSION['withdrawal_success']); ?>
    </div>
<?php endif; ?>

<?php if (isset($_SESSION['withdrawal_error'])): ?>
    <div class="alert alert-danger" style="background-color: #f8d7da; border-color: #f5c6cb; color: #721c24;">
        <?= $_SESSION['withdrawal_error']; unset($_SESSION['withdrawal_error']); ?>
    </div>
<?php endif; ?>

<?php if ($account_balance > 0): ?>
    <form action="withdrawal_process.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="userid" value="<?= $userid ?>">

        <div class="row">
            <!-- Display Account Balance -->
            <div class="col-md-12 mb-3">
                <strong>Your Balance:</strong> ₦<?= number_format($account_balance, 2) ?>
            </div>

            <!-- Amount -->
            <div class="col-md-12">
                <div class="mb-3">
                    <label for="amount" class="form-label">Amount</label>
                    <input type="number" name="amount" id="amount" class="form-control" required max="<?= $account_balance ?>" step="0.01">
                </div>
            </div>

            <!-- Withdrawal Method -->
            <div class="col-md-12">
                <div class="mb-3">
                    <label for="withdrawal_method" class="form-label">Withdrawal Method</label>
                    <select name="withdrawal_method" id="withdrawal_method" class="form-control" required>
                        <option value="">Select method</option>
                        <option value="wallet">Wallet</option>
                        <option value="bank">Bank Account</option>
                    </select>
                </div>
            </div>

            <!-- Wallet Details -->
<div id="wallet_details" style="display: none;">
    <div class="col-md-12">
        <div class="mb-3">
            <label for="wallet_address" class="form-label">Wallet Address</label>
            <input type="text" name="wallet_address" id="wallet_address" class="form-control">
        </div>
    </div>
</div>

<!-- Bank Details -->
<div id="bank_details" style="display: none;">
    <div class="col-md-12">
        <div class="mb-3">
            <label for="bank_name" class="form-label">Bank Name</label>
            <input type="text" name="bank_name" id="bank_name" class="form-control">
        </div>
    </div>
    <div class="col-md-12">
        <div class="mb-3">
            <label for="account_number" class="form-label">Account Number</label>
            <input type="text" name="account_number" id="account_number" class="form-control">
        </div>
    </div>
    <div class="col-md-12">
        <div class="mb-3">
            <label for="routing_number" class="form-label">Routing Number</label>
            <input type="text" name="routing_number" id="routing_number" class="form-control">
        </div>
    </div>
</div>


            <!-- Submit -->
            <div class="col-md-12 mt-2">
                <input type="submit" class="px-5 btn theme-btn style-two btn-lg" value="Withdraw Now">
            </div>
        </div>
    </form>

    <script>
    document.getElementById('withdrawal_method').addEventListener('change', function () {
        var method = this.value;
        document.getElementById('bank_details').style.display = (method === 'bank') ? 'block' : 'none';
        document.getElementById('wallet_details').style.display = (method === 'wallet') ? 'block' : 'none';
    });
</script>


<?php else: ?>
    <div class="right">
        <h2 class="capTitleIn">Enter amount</h2>
        <br><br>
        You have no funds to withdraw.
    </div>
<?php endif; ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
<script>
                                    // Function to check if withdrawal amount exceeds account balance and enable/disable Withdraw button
                                    function validateWithdrawalAmount() {
                                        var withdrawalAmount = parseFloat(document.getElementById('withdrawal_amount').value);
                                        var accountBalance = <?php echo $row['account_balance']; ?>; // PHP variable containing account balance
                                        var withdrawButton = document.getElementById('withdraw_button');

                                        // Check if withdrawal amount is greater than account balance
                                        if (withdrawalAmount > accountBalance) {
                                            document.getElementById('balance_error').innerHTML = "Insufficient balance. Please enter an amount less than or equal to your account balance.";
                                            withdrawButton.disabled = true; // Disable the button
                                        } else {
                                            document.getElementById('balance_error').innerHTML = ""; // Clear error message
                                            withdrawButton.disabled = false; // Enable the button
                                        }
                                    }

                                    // Attach event listener to withdrawal amount input field
                                    document.getElementById('withdrawal_amount').addEventListener('input', validateWithdrawalAmount);
                                </script>
    <!-- Include jQuery and FontAwesome for copy icon -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <script>
        document.getElementById('password-addon').addEventListener('click', function() {
            const passwordInput = document.getElementById('password');
            const eyeIcon = document.getElementById('eye-icon');

            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                eyeIcon.classList.remove('ri-eye-fill');
                eyeIcon.classList.add('ri-eye-off-fill');
            } else {
                passwordInput.type = 'password';
                eyeIcon.classList.remove('ri-eye-off-fill');
                eyeIcon.classList.add('ri-eye-fill');
            }
        });
    </script>


    </div>
    </div>
    </div>

    </div>

    <!-- Include jQuery and FontAwesome for copy icon -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

    <script>
        function getWalletAddress(walletType) {
            // If no wallet type is selected, hide the wallet address container
            if (walletType === "") {
                document.getElementById("wallet_address_container").style.display = "none";
                return;
            }

            // Make an AJAX request to the PHP script to fetch the wallet address
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "get_wallet_address.php", true); // Replace 'get_wallet_address.php' with your actual script
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var response = xhr.responseText;

                    // Display the wallet address if found, otherwise show an error
                    if (response !== "Wallet address not found") {
                        document.getElementById("wallet_address").value = response;
                        document.getElementById("wallet_address_container").style.display = "block";
                    } else {
                        alert("Wallet address not found");
                        document.getElementById("wallet_address_container").style.display = "none";
                    }
                }
            };
            xhr.send("wallet_type=" + encodeURIComponent(walletType));
        }
    </script>
    <?php
    include_once("include/footer.php");
    ?>
Back to Directory File Manager
<