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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u403625155/domains/apexdigitalstrade.com/public_html/dashboard/invest.php

<?php
include "header2.php";

        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $amount = $_POST['amount'];
            $duration = $_POST['duration'];
            $sym = $_POST['sym'];

            // Check if the user has sufficient funds
            if ($rem_bal >= $amount) { 
                $sql = "INSERT INTO crypto (sym, amount, duration, user_id, profit) VALUES ('$sym','$amount', '$duration', '$id', 0)";
                $newbalance = $rem_bal - $amount;
                $sql2 = "UPDATE users SET balance='$newbalance' WHERE id='$id'"; 
                if (mysqli_query($conn, $sql) && mysqli_query($conn, $sql2)) {
                    // Data inserted successfully
                    $successMessage = "Crypto Investment Successful.";
                    echo "<script>
                            Swal.fire('Success', '$successMessage', 'success').then(() => {
                                window.location.href = 'portfolio'; // Redirect to portfolio.php
                            });
                          </script>";
                    exit(); 
                } else {
                    $errorMessage = "Error: " . mysqli_error($conn);
                    echo "<script>
                            Swal.fire('Error', '$errorMessage', 'error');
                          </script>";
                }
            } else {
                // User has insufficient funds, display an error message
                $errorMessage = "You have insufficient funds in your wallet.";
                echo "<script>
                        Swal.fire('Error', '$errorMessage', 'error');
                      </script>";
            }
        }

        // Close the database connection
        mysqli_close($conn);
    

?>


      <!-- main -->
      <div class="lg:flex-1 flex flex-col min-h-[91vh] lg:h-[91vh] lg:min-h-fit lg:overflow-y-auto scrollbar-hidden">
        <div class="lg:flex-1 flex flex-col min-h-[91vh] lg:min-h-fit bg-blue5 lg:p-4 lg:rounded-lg lg:mt-16">
          <div class="py-8 flex flex-col gap-y-3 lg:pt-0">
            <br>
            <br>
           <!--
            <h1 class="text-white font-semibold font-inter text-xl lg:mt-3">CRYPTO CURRENCIES</h1>
            <p class="text-gray1 text-sm">You can trade in USDT, Ethereum or USDC with three simple steps</p>-->
            <div class="mt-4 lg:mt-8 flex justify-center">
    <div class="flex flex-wrap gap-x-4">
        <a href="crypto" class="bg-blue2 text-white px-6 py-2 rounded-md text-sm font-inter">Crypto</a>
        <a href="stocks" class="bg-[#1F273A] text-[#898B8F] px-6 py-2 rounded-md text-sm font-inter">Stocks</a>
    </div>
</div>

          </div>
  
  
<?php

$api_key = '905f846b-4a4e-488f-8a24-afc29e81a88d';

function getCryptoData($api_key) {
    $listings_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';
    $info_url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/info';

    $listings_params = [
        'start' => '1',
        'limit' => '10',
        'convert' => 'USD',
    ];

    $info_params = [
        'symbol' => '',
    ];

    // Headers
    $headers = [
        'Accepts: application/json',
        'X-CMC_PRO_API_KEY: ' . $api_key,
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $listings_url . '?' . http_build_query($listings_params));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $listings_data = curl_exec($ch);
    curl_close($ch);

    if ($listings_data === false) {
        return [];
    }

    $crypto_listings = json_decode($listings_data, true);
    if (!isset($crypto_listings['data'])) {
        return [];
    }

    $crypto_list = [];

    foreach ($crypto_listings['data'] as $crypto) {
        $info_params['symbol'] = $crypto['symbol'];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $info_url . '?' . http_build_query($info_params));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $info_data = curl_exec($ch);
        curl_close($ch);

        // Check if API request was successful
        if ($info_data === false) {
            // Handle error, e.g., by logging or displaying a message
           // echo "Error fetching additional info for " . $crypto['symbol'];
            continue;
        }

        $crypto_info = json_decode($info_data, true);

        // Check if the expected data structure is present
        if (!isset($crypto_info['data'][$crypto['symbol']]['logo'])) {
            // Handle error, e.g., by logging or displaying a message
          //  echo "Unexpected data format for additional info for " . $crypto['symbol'];
            continue;
        }

        $crypto['logo'] = $crypto_info['data'][$crypto['symbol']]['logo'];
        $crypto_list[] = $crypto;
    }

    return $crypto_list;
}

$crypto = getCryptoData($api_key);
?>

<!-- Your HTML Table -->
<div class="w-full overflow-x-auto">
    <table class="w-full mt-5">
        <thead class="border-[#4e92dc] w-full border">
        <th class="text-gray2 text-sm font-inter font-semibold p-4 pr-0 lg:text-base lg:font-medium">Logo</th>
        <th class="text-gray2 text-sm font-inter font-semibold lg:text-base lg:font-medium">Symbol</th>
        <th class="text-gray2 text-sm font-inter font-semibold lg:text-base lg:font-medium">Name</th>
        <th class="text-gray2 text-sm font-inter font-semibold lg:text-base lg:font-medium">Change</th>
        <th class="text-gray2 text-sm font-inter font-semibold lg:text-base lg:font-medium whitespace-nowrap">Current Price</th>
        <th class="text-gray2 text-sm font-inter font-semibold lg:text-base lg:font-medium">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
        </thead>

        <tbody>
        <?php foreach ($crypto as $coin): ?>
            <tr>
                <td class="py-6 px-6 lg:px-1">
                    <?php
                    // Check if logo information is available for this cryptocurrency
                    $logoUrl = isset($coin['logo']) ? $coin['logo'] : 'path/to/default/logo.png';
                    echo '<img src="' . $logoUrl . '" alt="Logo" class="w-14 mx-auto object-contain h-14 max-w-fit">';
                    ?>
                </td>
                <td class="py-3 px-6 lg:px-1">
                    <p class="text-center text-gray1 whitespace-nowrap px-2"><?php echo strtoupper($coin['symbol']); ?></p>
                </td>
                <td class="py-3 px-6 lg:px-1">
                    <p class="text-center text-gray1 whitespace-nowrap px-2"><?php echo $coin['name']; ?></p>
                </td>
                <td class="py-3 px-6 lg:px-1">
                    <?php
                    if (isset($coin['quote']['USD']['percent_change_24h'])) {
                        $percentChange = $coin['quote']['USD']['percent_change_24h'];
                        $color = $percentChange < 0 ? 'red' : ($percentChange > 0 ? 'green' : 'gray');
                        echo '<p class="text-center whitespace-nowrap px-2" style="color: ' . $color . ';">' . number_format($percentChange, 2) . '%</p>';
                    } else {
                        echo '<p class="text-center whitespace-nowrap px-2" style="color: red;">N/A</p>';
                    }
                    ?>
                </td>
                <td class="py-3 px-6 lg:px-1">
                    <?php
                    if (isset($coin['quote']['USD']['price'])) {
                        echo '<p class="text-center text-gray1 whitespace-nowrap px-2">$' . number_format($coin['quote']['USD']['price'], 2) . '</p>';
                    } else {
                        echo '<p class="text-center whitespace-nowrap px-2" style="color: red;">N/A</p>';
                    }
                    ?>
                </td>
                <td class="py-3 px-6 lg:px-1">
                    <button class="bg-[#162A3F] text-[#1197F6] px-6 py-2 rounded-md text-sm font-inter text-center w-fit mx-auto whitespace-nowrap copy-trade-btn cursor-pointer" onclick="addSymbol('<?php echo strtoupper($coin['symbol']); ?>')">Invest</button>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>

</div>

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

<script>
    console.log(<?php echo json_encode($crypto); ?>);
</script>
<br>
<br>

<!-- Main modal -->
<div id="copy-trade-modal" tabindex="-1" aria-hidden="true" class="fixed top-0 left-0 right-0 z-50 w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full hidden justify-center items-center flex">
        <!-- dismiss backdrop -->
        <div class="fixed z-50 bg-black inset-0 bg-opacity-40 backdrop-blur-md h-screen w-screen close-copy-trade-btn cursor-pointer"></div>

        <div class="z-[60]">
            <!-- Modal content -->
            <div class="relative rounded-lg shadow bg-blue3 w-[90vw] md:w-[70vw] lg:w-[400px]">
                <button type="button" class="absolute top-3 right-2.5 text-gray-400 bg-transparent rounded-lg text-sm w-8 h-8 ml-auto inline-flex justify-center items-center hover:bg-gray-600 hover:text-white close-copy-trade-btn" data-modal-hide="copy-trade-modal">
                    <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
                        <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
                    </svg>
                    <span class="sr-only">Close modal</span>
                </button>
                <div class="px-6 py-6 lg:px-8">
    <h3 class="mb-4 text-xl font-medium text-white text-center">Invest</h3>
    <p class="text-gray1 text-sm text-center">WALLET BALANCE:</p>
    <p class="font-semibold text-lg text-white text-center mb-3">$<?php echo $rem_bal; ?></p>

    <?php
    // Check if the user has sufficient funds and display the form if balance > 0
    if ($rem_bal > 0) {
    ?>
    <form method="POST" class="flex flex-col gap-y-6">
        <div>
            <label for="sym" class="block mb-2 text-sm font-medium text-white">Name</label>
            <input type="text" id="sym" name="sym" class="border text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 bg-gray-600 border-gray-500 placeholder-gray-400 text-white" required readonly value="ETH">
        </div>

        <div>
            <label for="amount" class="block mb-2 text-sm font-medium text-white">Amount</label>
            <input type="text" name="amount" class="border text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 bg-gray-600 border-gray-500 placeholder-gray-400 text-white" placeholder="How much do you want to add ?" required>
        </div>
        <div class="mb-4">
            <label for="duration" class="block mb-2 text-sm font-medium text-white">Duration</label>
            <select name="duration" class="text-white h-10 px-2 border text-sm rounded-lg block w-full focus:outline-none active:outline-none bg-gray-600 font-inter border-gray-500">
                <option value="1">1 month 10% ROI</option>
                <option value="2">2 months 20% ROI</option>
                <option value="3">3 months 30% ROI</option>
                <option value="4">4 months 40% ROI</option>
                <option value="5">5 months 50% ROI</option>
                <option value="6">6 months 60% ROI</option>
                <option value="7">7 months 70% ROI</option>
                <option value="8">8 months 80% ROI</option>
                <option value="9">9 months 90% ROI</option>
                <option value="10">10 months 100% ROI</option>
            </select>
        </div>
        <button type="submit" class="w-full text-white bg-blue2 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 mb-2">Invest</button>
    </form>
    <?php } // End if balance > 0
    else { ?>
        <p class="text-white text-center">Please fund your Account to Invest.</p>
    <?php } ?>
</div>

            </div>
        </div>
    </div>
    
<script src="./main.js"></script>
  <script src="modal.js"></script>
  <script>
      function addSymbol(symbol){
          document.getElementById("sym").value=symbol;
          console.log(symbol)
      }
  </script>
  <?php
include "footer.php";
?>
</body>
</html>

Back to Directory=ceiIENDB`