<!doctype html>
<html lang="en" class="w-[640px]">
   <head>
      <?php echo view('user/layout/head');?>
   </head>
   <style>
      .para
      {
      text-align:justify;
      color:#fff;
      }
      .ref-copy .copyLink {
      color:#fff;
      top: 50%;
      right: 25px;
      cursor: pointer;
      transform: translateY(-50%);
      }
      .ref-copy .copyLink:hover:after {
      opacity: 1;
      transform: translateY(0) translateX(-50%);
      }
      .ref-copy .copyLink:after {
      content: attr(tooltip);
      width: 140px;
      /* bottom: -13px; */
      /* left: 50%; */
      padding: 5px;
      border-radius: 4px;
      font-size: 0.8rem;
      opacity: 0;
      pointer-events: none;
      position: absolute;
      background:#0d6efd;
      color: #fff;
      transform: translateY(-10px) translateX(-50%);
      transition: all 300ms ease;
      text-align: center;
      }
      .referral .title p
      {
      font-size:13px;
      }
   </style>
   <?php 
      $user_ag = $_SERVER['HTTP_USER_AGENT'];
      
       if(preg_match('/(Mobile|Android|Tablet|GoBrowser|[0-9]x[0-9]*|uZardWeb\/|Mini|Doris\/|Skyfire\/|iPhone|Fennec\/|Maemo|Iris\/|CLDC\-|Mobi\/)/uis',$user_ag))
       {
       	$deviceType='mobile';
       }
       else
       {
       	$deviceType='computer';
       }
       ?>
   <?php 
      if($deviceType=='computer')
      {
      ?>
   <style>
      .referral .title
      {
      padding: 0px 64px;
      }
   </style>
   <?php 
      }
      else
      {
      ?>
   <style>
      .referral .title
      {
      padding: 0px;
      }
   </style>
   <?php 
      }
      ?>
   <body class="section-overflow">
      <!--banner start -->
      <section class="banner-bg overall-bg ">
         <div class="container">
            <?php echo view('user/layout/header');?>
         </div>
         <?php 
            use App\Libraries\MyEncrypt;
            use App\Helpers\site_helper;
            use App\Libraries\WalletCoreAPI;
            $this->session = \Config\Services::session();
            $this->db = db_connect();
            $session = session();
            
            $this->form_validation =  \Config\Services::validation();
            $list = \Config\Services::validation()->listErrors();
                    
            $coinid='1';
            $buy_bal=curbalance($this->session->get('uusersid'),$coinid);
            
            
            function sign($params){
              ksort($params);
              $string = "";
              foreach($params as $value){
              $string .= $value;
              }
              $sha1Encrypt = sha1($string);
              $encryptedstring = md5($sha1Encrypt);
              return $encryptedstring;
              }
              function encryptAll($params)
              {
                  $paramsEncrypt=array(
                      'merchantId'=>$params['merchantId'],
                      'chainTypeId'=>encrypt($params['chainTypeId'], $params['secretKey'])
                      );
                      return $paramsEncrypt;
              }
              function encrypt($data, $secret)
              {
                  //Take first 8 bytes of $key and append them to the end of $key.
                  $subkey = substr($secret, 0, 8);
                  // Encrypt data
                  $encData = openssl_encrypt($data, "DES-EDE3-CBC", $secret, OPENSSL_RAW_DATA, $subkey);
                  return bin2hex($encData);
              }        
            
              
            $bal=str_replace(",","", $buy_bal);
            
            $public_data=$this->db->query("select * from payment_controls where payment_id='9' and payment_key='private_key'")->getRow();
            $private_data=$this->db->query("select * from payment_controls where payment_id='9' and payment_key='public_key'")->getRow();
            $private_key = $public_data->payment_value;
            $public_key = $private_data->payment_value;
            
            $get_user_info=$this->db->query("select * from uusers where uusersid='".$this->session->get('uusersid')."'")->getRow();
            
            if($get_user_info->new_entry=='0')
            {
              $get_verification=$this->db->query("select * from payment_controls where payment_id='17' and payment_key='pay_mode'")->getRow();
              $public_data=$this->db->query("select * from payment_controls where payment_id='17' and payment_key='merchant_id'")->getRow();
              $private_data=$this->db->query("select * from payment_controls where payment_id='17' and payment_key='secret_key'")->getRow();
            
            }
            else
            {
              $get_verification=$this->db->query("select * from payment_controls where payment_id='18' and payment_key='pay_mode'")->getRow();
              $public_data=$this->db->query("select * from payment_controls where payment_id='18' and payment_key='merchant_id'")->getRow();
              $private_data=$this->db->query("select * from payment_controls where payment_id='18' and payment_key='secret_key'")->getRow();
            
            }
            
            $payment_mode=$get_verification->payment_value;
            
            if($payment_mode=='manual')
            {  
              $get_address=$this->db->query("select * from payment_controls where payment_id='17' and payment_key='address'")->getRow();
              $address=$get_address->payment_value;
              
              $get_address1=$this->db->query("select * from payment_controls where payment_id='18' and payment_key='address'")->getRow();
              $address1=$get_address1->payment_value;
            
            }
            else
            {
              $merchantID = $public_data->payment_value;
              $secretKey = $private_data->payment_value;
              $address='';
              $error='No Address available';
            
              $uusersid = $this->session->get('uusersid');
              $get_user_address=$this->db->query("select * from pay_address where userid='".$uusersid."' and payment_type='1'")->getRow();
              if($get_user_address)
              {  
                    $address=$get_user_address->address;
              }
              else
              {
            
                 $date = date('Y/m/d h:i:s a', time());
                 $date = (int) filter_var($date, FILTER_SANITIZE_NUMBER_INT);
                 $params=array(
                 'merchantId'=>$merchantID,
                 'chainTypeId'=>5,
                 'secretKey'=>$secretKey,
                 );
                 
                 $paramEncrypt = encryptAll($params);
                 $signature = sign($paramEncrypt);
                 $paramEncrypt['sign'] = $signature;
            
                 $ch = curl_init("https://en-payment.pay-mate.co/CW/createorder");
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $paramEncrypt);
            
                 $response = curl_exec($ch);
                 
                
                 if($response)
                 {
                     $response=json_decode($response,true);
                    
                       
                       if(!empty($response['Success']))
                       {
                       
                            $address=$response['WalletAddress'];
            
                            if($address!='')
                            {
                                 $this->db->query("insert into pay_address set address='".$address."', userid='".$uusersid."',payment_id='17',payment_type='1',date='".date("Y-m-d H:i:s")."'");
                            }
                       }
                       else
                       {
                           $error=$response['Message'];
                       }
                     
                 }
                 else
                 {
                    $error="No response received from End point";
                 }
                 
                 // close the connection, release resources used
                 curl_close($ch);
               }
              
            
            }
            
            
            
            ?>
         <?php 
            $session = \Config\Services::session();
            if($session->getFlashData('success_message')) 
            {
            ?>
         <div class="success-msg input-msg">
            <img src="<?php echo base_url();?>/assets/images/success.png">
            <p class="text-white fw-medium ms-2 mb-0"><?php echo $session->getFlashData('success_message');?></p>
         </div>
         <?php 
            } 
            else if($session->getFlashData('error_message')) 
            { 
            ?>
         <div class="error-msg input-msg">
            <img src="<?php echo base_url();?>/assets/images/error.png">
            <p class="text-white fw-medium ms-2 mb-0"><?php echo $session->getFlashData('error_message');?></p>
         </div>
         <?php 
            } 
            ?>
         <section class="dash-wrap referral">
            <div class="container">
               <div class="row">
                  <div class="col-12">
                     <div class="quantify-header d-flex align-items-center text-white justify-content-between">
                        <div class="trade-content ms-2">
                           <h6 class="text-white fw-semibold aleo mb-0 align-items-center">Balance Account USDT
                           </h6>
                        </div>
                        <div class="repeat-icon d-flex align-items-center">
                           <h5 class="text-white me-2 fw-bold "><?php echo number_format($bal,4);?> USDT
                           </h5>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="text-center">
                  <h6 class="text-white mt-5">Network Chain : USDT</h6>
               </div>
               <div class="row">
                  <div class="col-lg-12">
                     <!--<div class="qr-code text-center">
                        <?php 
                           if($address!='')
                           {
                           ?>
                        <br>
                        <div class="qr-code text-center">
                           <img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=<?php echo $address;?>" alt="deposit address" style="border:1px solid;margin-bottom:10px;">
                        </div>
                        <?php 
                           }
                           ?>
                     </div>-->
                  </div>
                  <div class="col-lg-12">
                     <div class="title text-center">
                        <div class="ref-form-list">
                           <div class="ref-form d-flex align-items-center">
                              <?php 
                                 if($address!='')
                                 {
                                 ?>
                              <div class="ref-content text-start">
                                 <p class="text-white mb-0">BEP20 - USDT Address</p>
                                 <p class="text-white" id="test"><?php echo $address;?></p>
                              </div>
                              <div class="ref-sec-copy ref-copy">
                                 <a href="javascript:void(0);" class="text-decoration-none copyLink" id="copy"><i class="fa-regular fa-copy "></i></a>
                              </div>
                              <?php 
                                 }
                                 else
                                 {
                                    echo "<p style='color:red;'>".$error."</p>";
                                 }
                                 ?>
                           </div>
                        </div>
                        <div class="ref-form-list">
                           <div class="ref-form d-flex align-items-center">
                              <?php 
                                 if($address1!='')
                                 {
                                 ?>
                              <div class="ref-content text-start">
                                 <p class="text-white mb-0">TRC20 - USDT Address</p>
                                 <p class="text-white" id="test1"><?php echo $address1;?></p>
                              </div>
                              <div class="ref-sec-copy ref-copy">
                                 <a href="javascript:void(0);" class="text-decoration-none copyLink" id="copy1"><i class="fa-regular fa-copy "></i></a>
                              </div>
                              <?php 
                                 }
                                 else
                                 {
                                    echo "<p style='color:red;'>".$error."</p>";
                                 }
                                 ?>
                           </div>
                        </div>
                     </div>
                  </div>
 
                  <div class="col-lg-10 offset-lg-1">
                     <form class="steps-validation transfer" method="post"  id="pin" action="" enctype="multipart/form-data">
                           <div class=" team-profit-content" style="text-align:start !important">
                              <div class="row">
                                 <div class="col-sm-12">
                                    <div class="form-block form-group position-relative">
                                    <label class="form-label  text-white">Amount</label>
                                       <input name="amount" class="form-control" type="text" id="amount" placeholder="Deposit Amount" value="" >
                                 
                                    </div>
                                    <div id="amount_error" style="color:red;font-size:13px;"></div>
                                    <?php echo $this->form_validation->getError('amount', '<span class="help-block">', '</span>'); ?>

                                    <div class="form-block form-group position-relative">
                                    <label class="form-label  text-white" for="">Attach Transaction Proof</label>
                                    <input name="attachment" class="form-control"   type="file" id="attachment"  placeholder="Receiver ID" value="" />
                                    </div>
                                    <span id="name-error" style="color:red"></span>
                                    <?php echo $this->form_validation->getError('recv_id', '<span class="help-block">', '</span>'); ?>
                                 
                                 
                                    <div class="form-btn my-4 text-center">
                                    <button type="button" id="trans" name="trans" class="btn btn-primary mb-5" Onclick="makedeposit();">Deposit Request</button>
                                    </div>
                                 </div>
                              </div>
                           </div>
                     </form>
                  </div>

                  <div class="title para" style="margin-top:20px">
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        Do not deposit any non-USDT assets to the above address, otherwise the assets will not be retrieved. 
                     </p>
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        After recharging to the provided address, please confirm the entire network node. Your account will be credited after 3 network confirmations. 
                     </p>
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        Minimum deposit amount: 50 USDT. Deposits below the minimum amount will not be credited to the account and cannot be refunded. 
                     </p>
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        Please note: transferring and recharging the block reward (Coinbase) is not supported, and such transfers will not be credited to your account. 
                     </p>
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        Your recharge address will remain stable and will not change frequently; you can continue to recharge as usual. In the event of any changes, we will make every effort to notify you through website announcements or email. 
                     </p>
                     <p>
                        <iconify-icon icon="clarity:success-standard-solid" class="me-2"></iconify-icon>
                        Please ensure the security of your computer and browser to prevent any tampering or leakage of information. 
                     </p>
                  </div>
                
                  

               </div>
            </div>
         </section>
         <!--footer start -->
         <?php echo view('user/layout/footer');?>
         <!--footer end -->
      </section>
      <?php echo view('user/layout/footer-script');?>
      <script>
         AOS.init({
         });
      </script>
      <script type="text/javascript">
         const input = document.getElementById("test");
         console.log(input);
         const copyButton = document.getElementById("copy");
         const copyText = (e) => {
         var temp = $("<input>");
         $("body").append(temp);
         temp.val($(input).html()).select();
         document.execCommand("copy");
         e.currentTarget.setAttribute("tooltip", "Copied!");
         };
         const resetTooltip = (e) => {
         e.currentTarget.setAttribute("tooltip", "Copy to clipboard");
         };
         copyButton.addEventListener("click", (e) => copyText(e));
         copyButton.addEventListener("mouseover", (e) => resetTooltip(e));
      </script>
      <script type="text/javascript">
         const input1 = document.getElementById("test1");
         console.log(input1);
         const copyButton1 = document.getElementById("copy1");
         const copyText1 = (g) => {
         var temp1 = $("<input1>");
         $("body1").append(temp1);
         temp1.val($(input1).html()).select();
         document.execCommand("copy1");
         g.currentTarget.setAttribute("tooltip", "Copied!");
         };
         const resetTooltip1 = (g) => {
         g.currentTarget.setAttribute("tooltip", "Copy to clipboard");
         };
         copyButton1.addEventListener("click", (g) => copyText1(g));
         copyButton1.addEventListener("mouseover", (g) => resetTooltip1(g));
      </script>
          <script>
         function makedeposit()
         {
            var amount = $("#amount").val();
            if(amount=='0' || amount=='')
            {
               $("#amount_error").html('Please Enter Deposit amount');
            }
            else
            {
               var l=/^[0-9.]+$/;
               
               if(l.test(amount))
               {
                  if(parseFloat(amount) < 1)
                  {
                     $("#amount_error").html('Minium 1 USDT Deposit Needed');
                  }  
                  else
                  {
                     $("#pin").submit();
                  }
               }
               else
               {
                  $("#amount_error").html('Amount must be numeric values');
               }
         
            }
              
                  
         }
         
      </script>
   </body>
</html>
