<!doctype html>
<html lang="en" translate="no" class="w-[640px] mx-auto md:w-full">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>TradePilot -Dashboard</title>
    <?php echo view('user/layout/head');?>
   <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/styles/web_style/css/jquery.dataTables.min.css" />
   <style>
      table.dataTable thead { background: linear-gradient(180deg, rgba(179,137,34,1) 0%, rgba(140,98,10,1) 50%, rgba(179,137,34,1) 100%, rgba(14,72,62,1) 100%); color:#fff; font-size:13px;}
      table.dataTable tbody tr { background:transparent; color:#fff;}
      .table-striped > tbody > tr:nth-of-type(2n+1) > *{ color:#fff;}
      .change-success{ background:green;color:#fff;font-size:12px;padding:5px;}
      .change-danger{ background:red;color:#fff;font-size:12px;padding:5px;}
      .dataTables_length {display:none;}
      .dataTables_paginate {display:none;}
      .dataTables_info {display:none;}
      .dataTables_filter { margin-bottom:10px;}
      table.dataTable tbody td {font-size: 13px;}
      label {
         display: inline-block;
         color: #fff !important;
         margin-top: 10px;
      }
      .dataTables_wrapper .dataTables_filter input {
         margin-left: 0.5em;
         border: 1px solid #ddd;
         height: 30px;
         border-radius: 10px;
      }
      .news {
	background:linear-gradient(180deg, rgba(179,137,34,1) 0%, rgba(140,98,10,1) 50%, rgba(179,137,34,1) 100%, rgba(14,72,62,1) 100%);
	border-radius: 5px;
	padding: 7px 5px;
}

.blink {
      animation: blink-animation 0.5s linear;
   }
   @keyframes blink-animation {
      50% {
            opacity: 0;
      }
   }

   .spin {
      animation: spin 1s infinite;
    }

    @keyframes spin {
      from { transform: rotate(0deg); }
      to { transform: rotate(360deg); }
    }

    
     .swal2-title {
        font-size: 15px; 
    }

    .swal2-html-container p {
        font-size: 13px !important; /* Adjust the font size for the content text */
        white-space: pre-line; /* Display text content line by line */
        line-height:15px !important;
    }
    
     .custom-list-item {
            position: relative;
            list-style: none;
        }
        .custom-list-item::before {
            content: '•';
            font-weight: bold;
            position: absolute;
            left: -20px; /* Adjust as needed */
            top: 50%; /* Adjust as needed */
            transform: translateY(-50%);
            font-size: 1.5em; /* Adjust as needed */
        }
        .icon-top-notify {
            position: absolute;
            left: -40px; /* Adjust as needed */
            top: 0;
            font-size: 1.5em; /* Adjust as needed */
        }
   </style>
   </head>
   <body class="reg-overflow">
      <?php 
         $this->db = db_connect();
         $this->session = session();
         $uusersid = $this->session->get('uusersid');
         $exchange_id = $this->session->get('exchange');
         if($exchange_id=='')
         {
            $array = array(
               "exchange" => '1'
            );
            $this->session->set($array);
         }
         function formatTradingPair($pair) 
         {
            $base = substr($pair, 0, -4);  // Extract the base currency (all but the last 4 characters)
            $quote = substr($pair, -4);    // Extract the quote currency (last 4 characters)
            return strtoupper($base) . '/' . strtoupper($quote); // Combine and convert to lowercase
          }
         ?>
      <section class="dash-banner-bg banner-bg">
         <div class="container">
         <!---header start---->
         <header class="pb-1 ">
            <div class="banner-nav ">
               <div class="row bg-black">
                  <div class="col-3">
                     <div class="header-sec-one">
                     
                        <div class="header-dropdown" style="margin-top:10px;">
                           <!--<div class="dropdown">
                              <button onclick="myFunction()" class="dropbtn dropdown-toggle">
                                 <iconify-icon icon="simple-icons:binance" class="text-primary "></iconify-icon>
                              </button>
                              <div id="myDropdown" class="dropdown-content">
                                 <a href="#"><iconify-icon icon="simple-icons:binance" class="text-primary "></iconify-icon>Huboi</a>
                                 <a href="#">Bybit</a>
                              </div>
                           </div>-->

                            <div class="dropdown">
                              <button onclick="myFunction()" class="dropbtn dropdown-toggle">
                                 <?php
                                 $image='';
                                 if($exchange_id=='1')
                                    $image="binance.svg";
                                 else if($exchange_id=='7')
                                    $image="kucoin.png"; 
                                 else if($exchange_id=='5')
                                 $image="bybit.svg"; 
                                 ?>
                                <img src="<?php echo base_url();?>/styles/web_style/images/<?php echo $image;?>" class="api_logo">
                              </button>
                              <div id="myDropdown" class="dropdown-content">

                              <?php 
                              foreach($exchange_list as $row)
                              { ?>
                                 <a href="javascript:void(0);" onclick="change(<?php echo $row->id;?>)"><img src="<?php echo base_url();?>/styles/web_style/images/<?php echo $row->image;?>" width="50px"> &nbsp;<?php echo $row->coin;?></a>

                                 <?php } ?>
                                
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-5">
                     <div class="logo text-center" style="margin-top:10px;">
                        <a href="">
                        <img src="<?php echo base_url();?>/styles/web_style/images/tp-logo.png" alt="" style="width:100%;">
                        </a>
                     </div>
                  </div>
                  <div class="col-4">
                     <div class="header-icons text-end">
                        <a href="<?php echo base_url();?>/user/asset">
                           <iconify-icon icon="solar:wallet-linear"></iconify-icon>
                        </a>
                        <a href="<?php echo base_url();?>/news">
                           <iconify-icon icon="akar-icons:bell"></iconify-icon>
                        </a>
                     </div>
                  </div>
               </div>
         </header>
         <!---header end---->
         <!---banner start---->
         <div class="dash-wrap">
         <div class="title text-center py-2">
         <h2 class="text-primary ">Welcome To TradePilot</h2>
         </div>
         <div class="row">
         <div class="col-lg-12">
         <div class="dash-heading">
         <div class="news d-flex align-items-center">
         <div class="news-ico me-1">
         <iconify-icon icon="radix-icons:speaker-loud"></iconify-icon>
         </div>
         <div class="news-content">
         <marquee behavior="" direction="" class="text-secondary" style="color:#000 !important;">Central Banks Explore Digital Currency Implementations</marquee>
         </div>
         </div>
         </div>
         </div>
         </div>
         <div class="row">
         <div class="col-lg-12">
         <div class="acct-list owl-carousel mt-4">

         <?php

            $this->common_model = model('CommonModel');
            $condition = "status = '1' ";
            $slider_data = $this->common_model->GetResults('slider_controls', $condition);
       

         if($slider_data)
         {
       
            foreach($slider_data as $row)
            {
         ?>
         <div class="slider-image">
         <img src="<?php echo base_url();?>/content/slider/<?php echo $row->image;?>" alt="" class="img-fluid">
         </div>

         <?php } } ?>
      
         </div>
         </div>
         </div>
         <!---banner end---->
         <!---statistic start---->
         <div class="row">
         <div class="col-lg-12">
         <ul class=" list-unstyled static dash-static mt-4 mb-0 text-center">
         <li><a href="<?php echo base_url();?>/apikeylist" class="text-decoration-none"><iconify-icon icon="mdi:robot-outline"></iconify-icon>     <h6 class="text-white-50">API binding</h6></a>
         </li>
         <li><a href="<?php echo base_url();?>/revenue" class="text-decoration-none"><iconify-icon icon="tdesign:currency-exchange"></iconify-icon>   <h6 class="text-white-50">Revenue Details</h6></a>
         </li>
         <!--<li class="custom-list-item">
        <iconify-icon icon="mdi:bell" class="icon-top-notify"></iconify-icon>
        <a href="https://revotechbot.com/revenue" class="text-decoration-none">
            <iconify-icon icon="tdesign:currency-exchange"></iconify-icon>   
            <h6 class="text-white-50">Revenue Details</h6>
        </a>
    </li>-->
         <li><a href="<?php echo base_url();?>/user/asset" class="text-decoration-none"><iconify-icon icon="carbon:chart-pie"></iconify-icon>       <h6 class="text-white-50">Assets</h6></a>
         </li>
         <li><a href="<?php echo base_url();?>/rewardhistory" class="text-decoration-none"><iconify-icon icon="fluent:notepad-edit-16-regular"></iconify-icon>     <h6 class="text-white-50">Reward details</h6></a>
         </li>
         <!--<li><a href="<?php echo base_url();?>/user/invite" class="text-decoration-none"><iconify-icon icon="material-symbols:group-add-outline"></iconify-icon>    <h6 class="text-white-50">Invite friends </h6></a>
         </li>-->
         <li></li>
         <li><a href="<?php echo base_url();?>/trade_orders" class="text-decoration-none"><iconify-icon icon="gravity-ui:files"></iconify-icon>   <h6 class="text-white-50">Trading Records </h6></a>
         </li>
         <!--<li><a href="#" class="text-decoration-none"><iconify-icon icon="hugeicons:mentoring"></iconify-icon>    <h6 class="text-white-50">Mentor support </h6></a>
         </li>-->
         <li><a href="<?php echo base_url();?>/allhistory" class="text-decoration-none"><iconify-icon icon="hugeicons:mentoring"></iconify-icon>    <h6 class="text-white-50">All Transactions</h6></a>
         </li>
         <li><a href="<?php echo base_url();?>/user/profile" class="text-decoration-none"><iconify-icon icon="hugeicons:menu-square"></iconify-icon>  <h6 class="text-white-50">More details </h6></a>
         </li>
         </ul>
         </div>
         </div>
         <!---statistic end---->
         <!---trading profit start---->
          <?php 
          $today_profit='0';
          $total_profit='0';
          $total_asset=0;
          $CommonModel = model('CommonModel');
          $gas_wallet=gas_wallet_bal($uusersid);
          
          if($exchange_id=='1')
          {
            $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='1'")->getRow();
              if($get_api_bind)
              {
                 $exchange_name='Binance';
                 $key = $get_api_bind->api_key;
                 $secret = $get_api_bind->secret_key;
                 /*$api = new Binance\API($key,$secret);
                 
                 $ticker='';
                 $balances = $api->balances($ticker);*/
                 $balances=binance_balance($key,$secret);
                if($balances)
                {
                    $total_asset = $balances;
                }
                else
                   $total_asset='0';
    
              }
              else
              {
                 //$key = "XgTJQ5j5IwABkQvRJdxYYLubL5fqo4wt12VCnLBBhQC9MmnfQs8XqXpun7ECmfzH";
                 //$secret = "VdVMJL6yfIgvrh8hOBojfV2E5NQpCQw3SvsptvZzayZKeRzrhzokhgLycRHPJD0S";
    
                 //$api = new Binance\API($key,$secret);
                 $total_asset=0;
              }
          }
          else if($exchange_id=="5")
         {
            $exchange_name="Bybit";
            $total_asset=0;
            $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='5'")->getRow();
            if($get_api_bind)
            {
              $key = $get_api_bind->api_key;
              $secret = $get_api_bind->secret_key;
              $account = $get_api_bind->account;
              $acc_type = $account == 1 ? 'CONTRACT' : 'UNIFIED';
              $bybitApi = new App\Libraries\BybitApi($key, $secret);
             
              $total_asset = $bybitApi->getBalance('USDT',$acc_type);
              
            }

         }
           $buy_bal=curbalance($uusersid);
             $profit=$CommonModel->total_profit($uusersid);
             $bal=str_replace(",","", $buy_bal);
             $today_earnings=$CommonModel->today_profit($uusersid);
         ?>
         <div class="team-profit-content">
                           <div class="row">
                              <div class="col-lg-12">
                                 <h5 class="text-primary py-2 fs-4 text-center">Balance Information</h5>
                              </div>
                              <div class="col-lg-6 col-sm-6">
                                 
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0"><?php echo $exchange_name;?> Exchange (USDT) <i class="fa fa-refresh" id="balance_load" style="float:right;color:#fff;"></i></p>
                                    <h4 class="fw-bold text-white" id="balance_update"><?php echo number_format($total_asset,2);?></h4>
                                    
                                 </div>
                              </div>
                             <div class="col-lg-6  col-sm-6">
                                  <a href="<?php echo base_url();?>/assetwallet"><div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Total Assets Balance (USDT) <i class="fa fa-arrow-right" style="float:right;color:#fff;"></i></p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($bal,2);?></h4>
                                 </div></a>
                              </div>
                              
                              <div class="col-lg-6 col-sm-6" style="margin-top:20px;">
                                  <a href="<?php echo base_url();?>/revenue"> <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Total Earnings (USDT) <i class="fa fa-arrow-right" style="float:right;color:#fff;"></i></p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($profit,2);?></h4>
                                 </div></a>
                              </div>

                              <div class="col-lg-6 col-sm-6" style="margin-top:20px;">
                               <a href="<?php echo base_url();?>/revenue">  <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Today Earnings (USDT) <i class="fa fa-arrow-right" style="float:right;color:#fff;"></i></p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($today_earnings,2);?></h4>
                                 </div></a>
                              </div>
                              
                              <div class="col-lg-6 col-sm-6" style="margin-top:20px;">
                                 <a href="<?php echo base_url();?>/gaswallet"><div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Gas Wallet Balance (USDT) <i class="fa fa-arrow-right" style="float:right;color:#fff;"></i></p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($gas_wallet,2);?></h4>
                                 </div></a>
                              </div>
                              
                           </div>
                        </div>

                         <div class="row ">
                         <div class="col-12">
                         <div class="dash-notify  pt-3">
                         <a  class="d-flex align-items-center justify-content-center"><iconify-icon icon="material-symbols:notification-multiple-rounded" class="text-primary fs"></iconify-icon> <span class="text-white" id="retrive"> [to sa*******312] Spot Martigle USDT profit 12.34%</span></a>
                         </div>
                         <div class="go-company mt-4 d-flex align-items-center justify-content-between">
                         <div class="go-company-cotent d-flex align-items-center">
                         <div class="select-type">
                         <h4 class="text-primary "><?php echo $exchange_name;?></h4>
                         <p class="fs-5 fw-normal text-white"><?php echo $exchange_name;?> invite you to join </p>
                         </div>
                         </div>
                         <div class="login-logo">
                         <a href="">
                         <iconify-icon icon="simple-icons:binance" class="text-primary"></iconify-icon>
                         </a>
                         </div>
                         </div>
                         </div>
                         </div>
                     <!---trading profit end---->
                     <div class="team-tab">
                   
         <div class="tab-content" id="pills-tabContent">
         <div class="tab-pane fade show active" id="pills-dep1" role="tabpanel" aria-labelledby="pills-dep1-tab">
         <div class="row">
         <div class=" col-sm-12">
         <div class="table-responsive trans position-relative">
         <!--<div class="head_trans my-2">
         <h4 class="fw-bold text-primary"> USDT</h4>
         </div>-->
         <table id="example" class="table table-striped">
         <thead>
         <tr>
         <th class="th" style="text-align:left;">Trading pair</th>
         <th clas="th" style="text-align:center;">Last Price</th>
         <th class="th" style="text-align:center;">Change</th>
         </tr>
         </thead>
         <tbody>
         <?php 
           
        
              $get_pairs=$this->db->query("select * from tradepair_list where status='1'")->getResult();
           
               $required_pairs=array();
               if($get_pairs)
               {
                   foreach($get_pairs as $get_pairs)
                   {
                      $required_pairs[]=$get_pairs->pair_name;
                   }
               }

                if($exchange_id=='1')
                {
                     $i=0;
                     //$data_binance = json_decode(@file_get_contents('https://revotechbot.com/trading_pairs.json'), true);
                     $data_binance=getpairs($exchange_id);
                    
                     if($data_binance) 
                     {
                          foreach($required_pairs as $pair) 
                          {
                                $symbol_find = $pair . 'USDT';
                                foreach($data_binance as $data) 
                                {
                                     if($data['symbol'] == $symbol_find) 
                                     {
                                            $output[$i]['symbol'] = $data['symbol'];
                                          $output[$i]['price'] = $data['lastPrice'];
                                         $output[$i]['change'] = $data['priceChangePercentage'];
                                        $i++;        
                                     }
                                    
                                    
                                }
                          }
                     }
                }
                else
                {
                     $get_api_bind=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."' and type='5'")->getRow();
                      if($get_api_bind)
                      {
                      $key = $get_api_bind->api_key;
                       $secret = $get_api_bind->secret_key;
                      }
                      else
                      {
                         $key='of3MneVy7FCSAvxAXl';
                         $secret='VpcyfXxVZyBwQZqJ3D3SNonEoPGDgLaav8vN';
                      }
    
                      $bybitApi = new App\Libraries\BybitApi($key, $secret);
                      $lists = $bybitApi->ticker(['category' => 'linear', 'baseCoin' => 'USDT']); 
                      $output=[];
                      $b=0;
                      if($lists){
                         foreach ($lists as  $value) {
                         if(substr($value['symbol'], -4) == "USDT"){
                            if(in_array(substr_replace($value['symbol'] ,"",-4), $required_pairs)){
                               $output[$b]['symbol'] = $value['symbol'];
                               $output[$b]['price'] = $value['lastPrice'];
                               $output[$b]['change'] = $value['price24hPcnt'];
    
                               $b++; 
                            } 
                         
                         }
                      }
                   }
                    
                }
             
             
             $k = 0;
             if($output)
             {
               foreach ($output as $key => $value) {
                 $output[$k] = $value;
                 $k++;
               }
               $output =  array_unique($output,SORT_REGULAR);
             }
            
            $sno=0;
             if($output)
             {
               foreach ($output as $key => $value) 
               {
                 $symbol = formatTradingPair($value['symbol']);
            
                 if($value['change'] > 0)
                 {
                     $class = "change-success";
                     $change = $value['change'];
                     $arrow='fa fa-caret-up';
                 }
                 else
                 {
                     $class = 'change-danger';
                     $change = $value['change'];
                     $arrow='fa fa-caret-down';

                 }
                 $price_class='';
                 $sno++;
                
               ?>
         <tr>
         <td style="text-align:left;"><a href="<?php echo base_url('tradedetails/'.$value['symbol']);?>"><?php echo $symbol;?></a></td>
         <td style="text-align:center;"><?php echo number_format($value['price'],6);?></td>
         <td><lable class="<?php echo $class;?>"><i class="<?php echo $arrow;?>"></i> &nbsp;<?php echo $change;?></lable></td>
         </tr>
         <?php 
         }
        }
        ?>
         </tbody>
         </table>
         </div>
         </div>
         </div>
         </div>
         </div>
         </div>
         </div>
         </div>
         </div>
      </section>
      <?php echo view('user/layout/footer');?> 
      <?php echo view('user/layout/footer-script');?>
      <script src="<?php echo base_url();?>/styles/web_style/js/jquery.dataTables.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<?php       
   
      if (session()->get('isLoggedIn') == 1) {
          unset($_SESSION['isLoggedIn']);
     
?>
<script>
Swal.fire({
title: " <i class='fa fa-bell text-secondary'></i> Announcement: Update new IP address for binding API ",
html: `
<div style="text-align: left;">
<p>Dear Valued Customers,</p>
<p><strong>If you have already binded your API, please go to the API page to check for the latest IP address to be updated in your API authorisation. </strong></p>
<p>During this time, we kindly ask for your cooperation and understanding. If you encounter any problems or issues, please share your feedback with us so we can enhance our system.</p>
<p>Your feedback is crucial for us to improve and provide you with a better experience. We are committed to making TradePilot the best it can be and appreciate your support in this process.</p>
<p>Thank you for your support and cooperation.</p>
<p>Best regards,<br>The APFM Team <?php echo $this->session->get('isLoggedIn');?></p>
</div>
`,

showCancelButton: true,
cancelButtonText: 'Close',
cancelButtonColor: '#d33',
showConfirmButton: false

});
</script>
<?php } ?>



      <script>

        // Array of texts to display randomly
        const texts = [
            "[to exchange*******mail.com] Spot Martingale USDT profit 12.34%",
            "[to john*******mail.com] Spot Martingale USDT profit 15.67%",
            "[to sam*******mail.com] Spot Martingale USDT profit 10.89%",
            "[to ander*******mail.com] Spot Martingale USDT profit 9.23%",
            "[to azheem*******mail.com] Spot Martingale USDT profit 10.03%",
            "[to mohnammed*******mail.com] Spot Martingale USDT profit 11.48%",
            "[to jackob*******mail.com] Spot Martingale USDT profit 09.26%",
            "[to andruse*******mail.com] Spot Martingale USDT profit 11.26%",
            "[to yancey*******mail.com] Spot Martingale USDT profit 13.23%",
            "[to jasmine*******mail.com] Spot Martingale USDT profit 14.92%",
            "[to hendry*******mail.com] Spot Martingale USDT profit 14.56%",
            "[to zarch*******mail.com] Spot Martingale USDT profit 14.56%",
            "[to flower*******mail.com] Spot Martingale USDT profit 13.78%",
            "[to Ashif*******mail.com] Spot Martingale USDT profit 14.63%",
            "[to alikan*******mail.com] Spot Martingale USDT profit 11.56%",
            "[to kalis*******mail.com] Spot Martingale USDT profit 13.41%",
            "[to kelvin*******mail.com] Spot Martingale USDT profit 11.39%",
            "[to abu*******mail.com] Spot Martingale USDT profit 12.16%",
            "[to irfan*******mail.com] Spot Martingale USDT profit 14.09%",
            "[to danny*******mail.com] Spot Martingale USDT profit 10.26%",
            "[to miller*******mail.com] Spot Martingale USDT profit 11.56%",
            "[to randy*******mail.com] Spot Martingale USDT profit 14.82%",
            "[to zesu*******mail.com] Spot Martingale USDT profit 14.02%",
            "[to marsh*******mail.com] Spot Martingale USDT profit 11.02%"
            
            
            
        ];
// Function to update the text content randomly with a blink effect
function updateText() {
            const spanElement = document.getElementById('retrive');
            spanElement.classList.add('blink'); // Add the blink class to trigger the animation
            const randomIndex = Math.floor(Math.random() * texts.length);
            spanElement.textContent = texts[randomIndex];

            // Remove the blink class after the animation completes
            setTimeout(() => {
                spanElement.classList.remove('blink');
            }, 500); // 0.5s matches the duration of the blink animation
        }

        // Set interval to update text every 5 seconds (5000 milliseconds)
        setInterval(updateText, 5000);

        // Initial call to display text immediately on load
        updateText();
    </script>
    <script type="text/javascript">

document.getElementById('balance_load').addEventListener('click', function() {

   
      this.classList.add('spin');
      read_function();
      setTimeout(() => {
      
        this.classList.remove('spin');
      }, 1000); // Duration of the animation in milliseconds
    });

    function read_function()
    {
      var uusersid='<?php echo $this->session->get('uusersid');?>';
      var exchange='<?php echo $exchange_id;?>';
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/balance_update");?>',
         data:{'exchange':exchange,'uusersid':uusersid},
        success:function(msg)
        {
         $("#balance_update").html(msg);
        }
      })
    }
    
        function change(value) {
    var baseUrl = "<?php echo base_url(); ?>";
    var redirectUrl = baseUrl + '/user/dashboard/changeSession/' + value;

    console.log('Redirect URL:', redirectUrl);

    // Redirect to the constructed URL
    window.location.href = redirectUrl;
   }
  </script>
    
   </body>
</html>