<?php
ob_start();
session_start();
date_default_timezone_set("Asia/Jakarta");
include('../config/koneksi.php');
$sid = session_id();
$sql_0 = mysqli_query($conn,"SELECT * FROM `tb_seo` WHERE cuid = 1") or die(mysqli_error());
$s0 = mysqli_fetch_array($sql_0);
$urlweb = $s0['urlweb'];
$urlwebs = $s0['urlweb'];
$pengguna = $s0['user'];
$sql_1a = mysqli_query($conn,"SELECT * FROM `tb_social` WHERE user = '$pengguna'") or die(mysqli_error());
$s1a = mysqli_fetch_array($sql_1a);
$sql_1b = mysqli_query($conn,"SELECT * FROM `tb_user` WHERE user = '$pengguna'") or die(mysqli_error());
$s1b = mysqli_fetch_array($sql_1b);
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('Y-m-d');
$stat = mysqli_query($conn,"INSERT INTO `tb_stat` (`ip`, `date`, `hits`, `page`, `user`) VALUES ('$ip', '$date', 1, 'Beranda', '$pengguna')") or die (mysqli_error());
if (!isset($_SESSION['show_modal'])) {
    $_SESSION['show_modal'] = true;
} else {
    $_SESSION['show_modal'] = false;
}

?>

<html lang="en">

<head>
    <title><?php echo $s0['instansi']; ?>: User Area</title>

    <!-- Meta -->
    <meta charset="utf-8">
    <!-- <meta content="width=device-width, initial-scale=1.0" name="viewport"> -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=0.65, maximum-scale=1, minimum-scale=0.65">
    <meta name="theme-color" content="#272b30">

    <!-- Favicon -->
    <link rel="icon" type="image/png" href="<?php echo $urlwebs; ?>/upload/favicon.png">

    <!-- CSS Global Compulsory -->

    <link rel="stylesheet" href="<?php echo $urlwebs; ?>/assets/home/bootstrap.web.min.css">
    <link href="https://fonts.googleapis.com/css?family=Abel" rel="stylesheet">
    <style>
        .blink_me {
            animation: blinker 1s step-start infinite;
        }

        @keyframes blinker {
            20% {
                opacity: 0.2;
            }
        }
    </style>
    <!-- JS Global Compulsory -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="<?php echo $urlwebs; ?>/js/4dv5.js"></script>
    <script>
        function secondtominute(d) {
            var m = Math.floor(d / (60));
            var s = d - (m * 60);
            if (s < 10) s = '0' + s;
            return m + ':' + s;
        }
    </script>

</head>


<body>

<?php include('uptop.php'); ?>


    

        <div class="clearfix"></div>
        <link rel="stylesheet" href="<?php echo $urlwebs; ?>/assets/home/m.css">


        <!-- MAIN TAB -->
        <?php include('navtab.php'); ?>
        


        <div class="tab-content">

      

                <div class="panel panel-danger">
                    
                    

                        

                        <a class="btn btn-danger btn-block" href="/" role="button" style="font-weight:bold; margin-top:20px"><span class="glyphicon glyphicon-menu-left"></span>Log out</a>
                        <div style="margin-top:20px">

                            <div class="well well-sm" style="padding-top: 5px; padding-bottom:2px;">
                                <marquee><span class="broadcast" style="color: #white; width: 100%"><?php echo $s0['news']; ?></span></marquee>
                            </div>
                            <div class="well well-sm bankOnline" style="margin-top:-10px; text-align:center"><span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>BCA</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>Mandiri</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>BNI</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>BRI</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>CIMB</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>PANIN</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>DANA</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>OVO</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>GOPAY</strong> : <span class="text-success">ONLINE</span></span>
                                <span style="margin-left:10px; margin-right:10px; white-space:nowrap"><strong>LinkAja</strong> : <span class="text-success">ONLINE</span></span>
                            </div>
                            <div class="well well-sm" style="margin-top:-10px; padding-bottom:2px;">  
  <marquee>
    <span class="listkeluaran" style="white-space:nowrap">
      <span style="margin-left:30px;">
        <span style="color:#FC0">HK SIANG </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>2757</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">SG METRO </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>5708</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">SYDNEY </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>4454</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">HAIPHONG </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>7076</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">SINGAPORE </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>1263</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">MALAYSIA </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>7084</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">MACAU </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>5292</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">QATAR </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>2516</strong>
      </span>

      <span style="margin-left:30px;">
        <span style="color:#FC0">HONGKONG </span>
        <span class="tgl" style="color:#CCC"></span>
        <strong>6022</strong>
      </span>

      <div style="clear:both"></div>
    </span>
  </marquee>
</div>

<script>
  // Ambil tanggal hari ini
  const today = new Date();
  const dd = String(today.getDate()).padStart(2, '0');
  const mm = String(today.getMonth() + 1).padStart(2, '0');
  const formattedDate = dd + "/" + mm;

  // Update semua span class="tgl"
  document.querySelectorAll(".tgl").forEach(el => {
    el.textContent = formattedDate + " ";
  });
</script>


                        </div>

                        

                    </div>





                    <div id="games_wrap" class="tab-pane fade in ">

                    </div>















                </div>



            </div>
            
            
            
            
            
            
            
            
            <!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">
  
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title"><span class="glyphicon glyphicon-info-sign"></span> Syarat dan Ketentuan</h4>
      </div>
      <div class="modal-body" style="max-height:400px; overflow-y:auto;">
        <ol>
          <li>MINIMAL USIA ADALAH 18 TAHUN</li>
          <li>Harap memperhatikan jam tutup setiap pasaran karena jam tutup berbeda-beda.</li>
          <li>Semua pasangan dianggap sah jika terjadi sebelum jam tutup.</li>
          <li>Pasangan yang sudah dikonfirmasi tidak bisa dibatalkan.</li>
          <li>Pasangan harap dicek kembali di menu history transaksi.</li>
          <li>Semua betting yang telah dibeli adalah sah dan tidak bisa dibatalkan.</li>
          <li>Setiap Member bertanggung jawab pada user account masing-masing.</li>
          <li>Semua pasangan akan dibatalkan oleh pihak Kami jika terdeteksi adanya kecurangan.</li>
          <li>Pasaran dan hadiah setiap pasaran berbeda-beda dan dapat berubah sewaktu-waktu.</li>
          <li>Jika terjadi kecurangan deposit, maka akun akan ditutup permanen.</li>
          <li>Deposit dapat dilakukan setiap hari 24 jam kecuali bank OFFLINE.</li>
          <li>Withdraw dapat dilakukan setiap hari 24 jam kecuali bank OFFLINE.</li>
          <li>TIDAK MENERIMA PEMAIN INVEST DI PASARAN HONGKONG MALAM.</li>
          <li>BATAS MAXIMAL INVEST DENGAN NOMINAL BET YANG SAMA:  
            <br>40 LINE (2D),  
            <br>400 LINE (3D),  
            <br>3000 LINE (4D).  
            <br>Jika melanggar → akun bisa diblokir permanen dan saldo tidak dikembalikan.
          </li>
          <li>Dengan bergabung sebagai member Kami berarti anda telah menyetujui syarat dan peraturan Kami.  
          <br>SELAMAT BERMAIN DAN TERIMA KASIH.</li>
        </ol>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" data-dismiss="modal" onclick="agreeModal()">
  <span class="glyphicon glyphicon-ok-sign"></span> Setuju
</button>

<script>
function agreeModal(){
  $.get("/agree_modal.php"); // bikin file kecil utk reset session
}
</script>
        <button type="button" class="btn btn-warning pull-left" onclick="logout()">
          <span class="glyphicon glyphicon-remove-sign"></span> Tidak Setuju
        </button>
      </div>
    </div>
    
  </div>
</div>

<!-- Script untuk auto show modal -->
<script>
$(document).ready(function(){
  <?php if ($_SESSION['show_modal'] === true) : ?>
    $('#myModal').modal({
      backdrop: 'static',
      keyboard: false
    });
    $('#myModal').modal('show');
  <?php endif; ?>
});

function logout(){
  window.location.href = "/m/logout.php";
}
</script>       
            
            
            
            
            
            
            
            <div class="well well-sm container-fluid text-center" style="margin:0px; padding:5px; border-radius:0px; padding-bottom: 55px">
               © 2018 - 2025 Copyright <?php echo $s0['instansi']; ?>. All Rights Reserved.
            </div>

<!--tampilan /m/ versi mobile bawah trakhir alias footer--><!--next halaman footer-->
<?php include('footer.php'); ?>
            


</html>
<?php
error_reporting(0);
if($s0['onoff'] == 1){
    header('location:'.$urlweb.'mtweb.php');
}
if(isset($_SESSION['user'])){
  $user =mysqli_query($conn,"SELECT * FROM `tb_user` WHERE user = '".$_SESSION['user']."'") or die (mysqli_error());
  $u = mysqli_fetch_array($user);
  $users = $u['user'];
  $userID = $u['cuid'];
  $getPlayer = mysqli_query($conn,"SELECT * FROM `tb_ppplayer` WHERE userID = '$userID'") or die(mysqli_error());
  while($gp = mysqli_fetch_array($getPlayer)){
    $providernya = $gp['provider'];
    $externalPlayerId = $gp['externalPlayerId'];
    $balance = $gp['balance'];

    $kode_unik = substr(str_shuffle(1234567890),0,3);
    $kd_transaksi = date('Ymds').$kode_unik;
    $requestID = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz123456789'),0,8);
    $requestIDD = $requestID.date('s');
    $created_date = date('Y-m-d H:i:s');

    $sql_provider = mysqli_query($conn,"SELECT * FROM `tb_tripayapi` WHERE provider = '$providernya'") or die(mysqli_error());
    $sp = mysqli_fetch_array($sql_provider);
    $providerID = $sp['cuid'];
    $urlRequest = $sp['urlRequest'];
    $gameUrl = $sp['urlResponse'];
    $secureLogin = $sp['api_key']; //apiKey
    $secretKey = $sp['secret_key']; //brandID

    if($providernya == 'PragmaticPlay'){
      $catatan = 'PragmaticPlay Transfer Back';
      $params = 'externalPlayerId='.$externalPlayerId.'&secureLogin='.$secureLogin.$secretKey;
      $hashNeed = md5($params);
      $curl = curl_init();
                                                      
      curl_setopt_array($curl, array(
        CURLOPT_URL => $urlRequest.'/balance/current',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "secureLogin=".$secureLogin."&externalPlayerId=".$externalPlayerId."&hash=".$hashNeed,
        CURLOPT_HTTPHEADER => array(
          "Content-Type: application/x-www-form-urlencoded",
          "Cache-Control: no-cache"
        ),
      ));
                                                                  
      $response = curl_exec($curl);
      //echo $response;
      curl_close($curl);
      $hasil = json_decode($response, true);
      $newSaldo = $hasil['balance'];
      if($newSaldo > 0){
        $updatePlayerSaldo = mysqli_query($conn,"UPDATE `tb_ppplayer` SET `balance` = '$newSaldo' WHERE userID = '$userID' AND provider = 'PragmaticPlay'") or die(mysqli_error());
        sleep(2);
        $params1 = 'amount=-'.$newSaldo.'&externalPlayerId='.$externalPlayerId.'&externalTransactionId='.$kd_transaksi.'&secureLogin='.$secureLogin.$secretKey;
        $hashNeed1 = md5($params1);
        $curl1 = curl_init();
                                    
        curl_setopt_array($curl1, array(
          CURLOPT_URL => $urlRequest.'/balance/transfer',
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => "",
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => "POST",
          CURLOPT_POSTFIELDS => "secureLogin=".$secureLogin."&externalPlayerId=".$externalPlayerId."&externalTransactionId=".$kd_transaksi."&amount=-".$newSaldo."&hash=".$hashNeed1,
          CURLOPT_HTTPHEADER => array(
            "Content-Type: application/x-www-form-urlencoded",
            "Cache-Control: no-cache"
          ),
        ));
                                           
        $response1 = curl_exec($curl1);
        //echo $response1;
        curl_close($curl1);
        $hasil1 = json_decode($response1, true);
        if($hasil1['description'] == 'OK'){
          $getBalancePlayer = mysqli_query($conn,"SELECT * FROM `tb_ppplayer` WHERE userID = '$userID' AND provider = 'PragmaticPlay'") or die(mysqli_error());
          $gbp = mysqli_fetch_array($getBalancePlayer);
          $balances = $gbp['balance'];
          $insert_transaksi = mysqli_query($conn,"INSERT INTO `tb_transaksi` (`kd_transaksi`, `date`, `transaksi`, `total`, `saldo`, `note`, `gameid`, `providerID`, `jenis`, `metode`, `pay_from`, `userID`, `status`) VALUES ('$kd_transaksi','$created_date','Transfer','$balances',0, '$catatan', '', '1','6','0','1','$userID',1)") or die(mysqli_error($conn));
          $updateBalance = mysqli_query($conn,"UPDATE `tb_balance` SET `active` = '$balances' WHERE userID = '$userID'") or die(mysqli_error($conn));
          $updatePlayer = mysqli_query($conn,"UPDATE `tb_ppplayer` SET `status` = 0, `balance` = balance - '$balances' WHERE userID = '$userID' AND provider = 'PragmaticPlay'") or die(mysqli_error($conn));
            
          $params2 = 'externalPlayerId='.$externalPlayerId.'&secureLogin='.$secureLogin.$secretKey;
          $hashNeed2 = md5($params2);
          $curl2 = curl_init();
                                          
          curl_setopt_array($curl2, array(
            CURLOPT_URL => $urlRequest.'/game/session/terminate',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => "secureLogin=".$secureLogin."&externalPlayerId=".$externalPlayerId."&hash=".$hashNeed2,
            CURLOPT_HTTPHEADER => array(
              "Content-Type: application/x-www-form-urlencoded",
              "Cache-Control: no-cache"
            ),
          ));
                                                  
          $response2 = curl_exec($curl2);
          //echo $response1;
          curl_close($curl2);
     
        }
      }
    }
  }
}
?>
<!-- End Session -->