<?php require_once "../app/headl.php" ?>

<?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['user'];
            $id_user = $u['cuid'];
            $userID = $u['cuid'];
            $token_id = isset($u['token_id']) ? $u['token_id'] : false;
            $level = isset($u['level']) ? $u['level'] : false;

            $sql_balance = mysqli_query($conn, "SELECT * FROM `tb_balance` WHERE userID = '$userID'") or die(mysqli_error());
            $sb = mysqli_fetch_array($sql_balance);
        ?>

<body>

<?php require_once "../app/menul.php" ?>

        <div class="clearfix"></div>
        <style>
            body {
                font-size: 12px;
                color: #FFFFFF;
                background-color: #1b1b1b;
            }

            .btn {
                margin-bottom: 2px;
                font-size: 12px;
                font-weight: bold;
            }

            .container {
                width: 100%;
            }

            .glyphicon {
                margin-right: 5px;
            }

            .no-gutter>[class*='col-'] {
                padding-right: 5px;
                padding-left: 5px;
                padding-top: 5px;
                padding-bottom: 5px;
            }

            .tengahBaris {
                vertical-align: middle;
            }

            table {
                padding-bottom: 0px;
            }

            .panel {
                box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.3);
            }

            input[readonly] {
                background-color: #fff0c4 !important;
                /* any other styles */
            }


            .panel-danger>.panel-heading,
            .panel-warning>.panel-heading,
            .btn-warning {
                color: #000000;
                font-weight: bold;
                border-color: rgba(0, 0, 0, 0.6);
                background-image: -webkit-linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-image: -o-linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#eee791), color-stop(60%, #9d8b3d), to(#9f8435));
                background-image: linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-repeat: no-repeat;
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff484e55', endColorstr='#ff313539', GradientType=0);
                -webkit-filter: none;
                filter: none
            }

            .btn-warning:hover {
                color: #000000;
                font-weight: bold;
                border-color: rgba(0, 0, 0, 0.6);
                background-image: -webkit-linear-gradient(#d7a001, #d7a001 60%, #d7a001);
                background-image: -o-linear-gradient(#d7a001, #d7a001 60%, #d7a001);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#d7a001), color-stop(60%, #d7a001), to(#d7a001));
                background-image: linear-gradient(#d7a001, #d7a001 60%, #d7a001);
                background-repeat: no-repeat;
            }

            .login {
                color: #000000;
                font-weight: bold;
                border-color: rgba(0, 0, 0, 0.6);
                background-image: -webkit-linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-image: -o-linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#eee791), color-stop(60%, #9d8b3d), to(#9f8435));
                background-image: linear-gradient(#eee791, #9d8b3d 60%, #9f8435);
                background-repeat: no-repeat;
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff484e55', endColorstr='#ff313539', GradientType=0);
                -webkit-filter: none;
                filter: none
            }


            .panel-default>.panel-heading {
                color: #ffffff;
                border-color: rgba(0, 0, 0, 0.6)
            }

            .navbar-default {
                background-color: #000000;
                border-color: #2b2e32
            }

            .well {
                background: #111 !important;
            }


            input[readonly] {
                background-color: #eeeecd !important;
                /* any other styles */
            }

            textarea[readonly] {
                background-color: #eeeecd !important;
                /* any other styles */
            }

            .form-control {
                height: 40px !important;
                border-radius: 3px !important;
            }

            .form-control#validasi {
                height: 50px !important;
                border-radius: 3px !important;
            }

            .form-control-login {
                height: 40px !important;
                border-radius: 3px !important;
            }

            .form-control#reg_username,
            #reg_pass,
            #reg_passcon,
            #reg_email,
            #reg_telpon,
            #reg_bank,
            #reg_rek,
            #reg_nama,
            #reg_ref,
            #reg_dari,
            #reg_lain {
                height: 45px !important;
                border-radius: 3px !important;
            }


            textarea {
                height: 100px !important;
                width: 100%;
                padding: 10px;
                border-radius: 5px !important;
            }

            td {
                padding-top: 5px !important;
                padding-bottom: 5px !important;
            }

            .borderbottom {
                border-bottom: 2px solid #c2c2c2;
                border-top: 2px solid #c2c2c2;
            }

            @media (max-width: 1200px) {
                .navbar {
                    background: #32363b;
                }

                .navbar-header {
                    float: none;
                }

                .navbar-left,
                .navbar-right {
                    float: none !important;
                }

                .navbar-toggle {
                    display: block;
                }

                .navbar-collapse {
                    border-top: 1px solid transparent;
                    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
                }

                .navbar-fixed-top {
                    top: 0;
                    border-width: 0 0 1px;
                }

                .navbar-collapse.collapse {
                    display: none !important;
                }

                .navbar-nav {
                    float: none !important;
                    margin-top: 7.5px;
                }

                .navbar-nav>li {
                    float: none;
                }

                .navbar-nav>li>a {
                    padding-top: 10px;
                    padding-bottom: 10px;
                }

                .collapse.in {
                    display: block !important;
                }


                @media (min-width: 320px) {

                    /* iPhone SE,6/7/8/X, Galaxy S5,  */
                    .fadein {
                        position: relative;
                        width: 100%;
                        height: 160px;
                    }

                    .fadein img {
                        position: absolute;
                        left: 0;
                        top: 0;
                    }

                }

                @media (min-width: 400px) {

                    /* iPhone 6/7/8 Plus, Pixel 2,Pixel 2 XL,  */
                    .fadein {
                        position: relative;
                        width: 100%;
                        height: 200px;
                    }

                    .fadein img {
                        position: absolute;
                        left: 0;
                        top: 0;
                    }


                }

                @media (min-width: 700px) {

                    /* iPad  */
                    .fadein {
                        position: relative;
                        width: 100%;
                        height: 380px;
                    }

                    .fadein img {
                        position: absolute;
                        left: 0;
                        top: 0;
                    }

                }

                @media (min-width: 1000px) {
                    .fadein {
                        position: relative;
                        width: 100%;
                        height: 480px;
                    }

                    .fadein img {
                        position: absolute;
                        left: 0;
                        top: 0;
                    }

                }

            }

            textarea {
                height: 100px !important;
                width: 100%;
                padding: 10px;
                border-radius: 5px !important;
            }

            .form-control {
                height: 25px !important;
                border-radius: 3px !important;
            }

            td {
                padding-top: 5px !important;
                padding-bottom: 5px !important;
                padding-left: 3px !important;
                padding-right: 3px !important;
            }

            .grabgtab {
                font-weight: bold;
                border-color: rgba(0, 0, 0, 0.6);
                background-image: -webkit-linear-gradient(#1b1b1b, #1b1b1b 60%, #10100e);
                background-image: -o-linear-gradient(#1b1b1b, #1b1b1b 60%, #10100e);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#1b1b1b), color-stop(60%, #1b1b1b), to(#10100e));
                background-image: linear-gradient(#1b1b1b, #1b1b1b 60%, #10100e);
                background-repeat: no-repeat;
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1b1b1b', endColorstr='#10100e', GradientType=0);
                -webkit-filter: none;
                filter: none
            }

            .grabgtabbottom {
                font-weight: bold;
                border-color: rgba(0, 0, 0, 0.6);
                background-image: -webkit-linear-gradient(#3e444c, #1b1b1b 60%, #1b1b1b);
                background-image: -o-linear-gradient(#3e444c, #1b1b1b 60%, #1b1b1b);
                background-image: -webkit-gradient(linear, left top, left bottom, from(#3e444c), color-stop(60%, #1b1b1b), to(#1b1b1b));
                background-image: linear-gradient(#3e444c, #1b1b1b 60%, #1b1b1b);
                background-repeat: no-repeat;
                filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1b1b1b', endColorstr='#1b1b1b', GradientType=0);
                -webkit-filter: none;
                filter: none
            }

            .abel {
                font-family: 'Abel';
            }
              
/* Dark mode untuk card dan tabel */
.card, .panel, .table {
    background-color: #1e1e1e !important;
    color: #fff !important;
}
.table-striped>tbody>tr:nth-of-type(odd) {
    background-color: #2a2a2a;
}
.table-hover>tbody>tr:hover {
    background-color: #333;
}

/* Tombol salin modern */
.btn-copy {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    border: none;
    background-color: #007bff;
    color: #fff;
}
.btn-copy i {
    margin-left: 5px;
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745; /* hijau untuk sukses */
    color: #fff;
    padding: 10px 15px;
    border-radius: 5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 9999;
}
.toast.show {
    opacity: 1;
    pointer-events: auto;
}
</style>

        <!-- MAIN TAB -->

        <?php require_once "../app/game.php" ?>

        <div style="height:10px; background-color:#FFF" class="grabgtabbottom"></div>


        <div class="tab-content">

            <div id="dashboard_wrap" class="tab-pane fade in active">
                <div class="row" style="margin-bottom:0px">
                    <div class="col-xs-3" style="padding-right:2px">
                        <a class="btn btn-default btn-block " href="index.php"><span class="glyphicon glyphicon-calendar"></span>Statement</a>
                    </div>
                    <div class="col-xs-3" style="padding-right:1px; padding-left: 1px;">
                        <a class="btn btn-default btn-block " href="history.php"><span class="glyphicon glyphicon-calendar"></span>History</a>
                    </div>
                    <div class="col-xs-3" style="padding-right:1px; padding-left: 2px;">
                        <a class="btn btn-default btn-block " href="memo.php"><span class="glyphicon glyphicon-edit"></span>Memo<span class="badge badgeTotal" style="margin-left:5px; margin-right:10px; font-size:9px; font-weight:bold"></span></a>
                    </div>
                    <div class="col-xs-3" style="padding-left:2px">
                        <a class="btn btn-default btn-block active" href="refferal.php"><span class="glyphicon glyphicon-user"></span>Referal</a>
                    </div>
                </div>
                <div class="row" style="margin-bottom:10px">
                    <div class="col-xs-3" style="padding-right:2px">
                        <a class="btn btn-default btn-block " href="deposit.php"><span class="glyphicon glyphicon-import"></span>Deposit</a>
                    </div>
                    <div class="col-xs-3" style="padding-left:1px; padding-right:1px;">
                        <a class="btn btn-default btn-block " href="withdraw.php"><span class="glyphicon glyphicon-export"></span>Withdraw</a>
                    </div>
                    <div class="col-xs-3" style="padding-left:2px; padding-right:1px">
                        <a class="btn btn-default btn-block " href="rekening.php"><span class="glyphicon glyphicon-briefcase"></span>Rekening<span style="position:absolute; font-size: 10px; margin-top: -8px; margin-left:-85px">⭐</span></a>
                    </div>
                    <div class="col-xs-3" style="padding-left:2px">
                        <a class="btn btn-default btn-block " href="password.php"><span class="glyphicon glyphicon-user"></span>Password</a>
                    </div>
                </div>

    <div id="referal_content">
    <div class="panel panel-danger">
        <div class="panel-heading">
            <strong><span class="glyphicon glyphicon-tasks"></span>List Referral</strong>
            <span style="float:right; margin-top:-4px; width:190px; display:inline">
                <form class="form-group-sm">
                    <label style="float:left; margin-top:3px; margin-right:10px;">Sort</label>
                    <select class="form-control" id="refsort" page="1" style="width:150px; height:25px; border-radius:3px; float:right">
                        <option value="j" selected>Join Date</option>
                        <option value="u">Username</option>
                        <option value="b">Bonus Referral</option>
                    </select>
                </form>
            </span>
        </div>
        <div class="panel-body">
            <table border="1" cellpadding="5" cellspacing="0" style="width:100%; color:white; text-align:center; border-collapse: collapse;">
                <thead style="background-color:#333;">
                    <tr>
                        <th>No</th>
                        <th>User Referral</th>
                        <th>Join Date</th>
                        <th>Bonus Referral</th>
                        <th>Jumblah Deposit</th>
                        <th>Keterangan Deposit</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        $sql_refferal = mysqli_query($conn,"
                        SELECT * FROM tb_user 
                        WHERE uplineID = '$userID' 
                        AND cuid != '$userID' 
                        ORDER BY cuid DESC
                    ") or die(mysqli_error($conn));

                    $no = 1; // Nomor urut
                    while($sr = mysqli_fetch_array($sql_refferal)) {
                        $reffID = $sr['cuid']; // ID user referral

                        // Hitung bonus referral (jenis = 3 misalnya)
                        $hitungKomisi = mysqli_query($conn,"
                            SELECT SUM(total) AS komisi 
                            FROM tb_transaksi 
                            WHERE userID = '$reffID' 
                            AND jenis = '3' 
                            AND status = 1
                        ");
                        
                         $hk = mysqli_fetch_array($hitungKomisi);
                        $komisi1 = $hk['komisi'] ?? 0; // default 0 jika kosong

                        // Hitung total deposit (jenis = 1)
                        $cekDeposit = mysqli_query($conn,"
                            SELECT SUM(total) AS totalDeposit 
                            FROM tb_transaksi 
                            WHERE userID = '$reffID' 
                            AND jenis = '1' 
                            AND status = 1
                        ");
                        $cd = mysqli_fetch_array($cekDeposit);
                        
                        if ($cd['totalDeposit'] > 0) {
                            $jumblahDeposit = number_format($cd['totalDeposit'], 0, ',', '.');
                            $statusDeposit = "<span style='color:#00ff00; font-weight:bold;'>Deposit</span>";
                        } else {
                            $jumblahDeposit = "0";
                            $statusDeposit = "<span style='color:#ff4444; font-weight:bold;'>Belum Deposit</span>";
                        }
                    ?>
                        <tr style="background-color:#222;">
                            <td><?php echo $no++; ?></td>
                            <td><?php echo $sr['user']; ?></td>
                            <td><?php echo $sr['join_date']; ?></td>
                            <td>IDR <?php echo number_format($komisi1, 0, ',', '.'); ?></td>
                            <td>IDR <?php echo $jumblahDeposit; ?></td>
                            <td><?php echo $statusDeposit; ?></td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
       <div class="panel panel-danger">
                    <div class="panel-heading"><strong><span class="glyphicon glyphicon-user"></span>REFERAL</strong>
                    </div>
                    <div class="panel-body" style="padding:10px">

    Ini adalah URL referral anda: 
    <span class="text-warning" id="refLink" style="font-weight:bold;">
        <?php echo $urlweb; ?>/?ref=<?php echo $u['user']; ?>
    </span>
    <button class="btn-copy" onclick="copyReferral()">
        Salin <i class="fa fa-clipboard"></i>
    </button>
</p>

<!-- Toast notifikasi -->
<div id="toast" class="toast">URL referral berhasil disalin!</div>
         <br>
                        Anda akan mendapatkan Bonus Referal:
                        <br>
                        <br>
                        <div class="row">


                            <div class="col-xs-6" style="padding-right:5px;">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr style="background:none;">
                                            <th colspan="2">TOGEL</th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;4D/3D/2D</td>
                                            <td width="60"><strong>1.00% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Colok Bebas</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Colok Macau</td>
                                            <td width="60"><strong>1.00% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Colok Naga</td>
                                            <td width="60"><strong>1.00% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Colok Jitu</td>
                                            <td width="60"><strong>1.00% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;5050 Umum</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;5050 Special</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;5050 Kombinasi</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Kombinasi</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Dasar</td>
                                            <td width="60"><strong>0.50% </strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Shio</td>
                                            <td width="60"><strong>1.00% </strong></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>

                            <div class="col-xs-6" style="padding-left:5px;">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr style="background:none;">
                                            <th colspan="2">SLOT</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Pragmatic</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;PGSoft</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Habanero</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Joker Gaming</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Spade Gaming</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;JILI</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;FastSpin</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;PlayStar</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;CQ9</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Micro Gaming</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;TopTrend Gaming</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                    </tbody>
                                </table>

                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr style="background:none;">
                                            <th colspan="2">LIVE GAME</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Pragmatic Live</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;ION Casino</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Evolution</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Sexy Gaming</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;AllBet</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;SA GAming</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Micro Gaming Live</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Opus Live</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;SBO Casino</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                    </tbody>
                                </table>

                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr style="background:none;">
                                            <th colspan="2">SPORT</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;Saba Sport</td>
                                            <td width="60"><strong> 0.1%</strong></td>
                                        </tr>
                                        <tr>
                                            <td class="text-success">&nbsp;&nbsp;SBO Sport</td>
                                            <td width="60"><strong> 0%</strong></td>
                                        </tr>
                                    </tbody>
                                </table>

                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr style="background:none;">
                                            <th colspan="2">ESPORT</th>
                                        </tr>
                                    </thead>
                                </table>

                            </div>
                        </div>

                        <div style="clear:both"></div>
                        
                    </div>
                </div>
            
            <ul class="pagination"></ul>
                    <script>
                        $(document).ready(function() {
                            $('[data-toggle="tooltip"]').tooltip();
                        });
                    </script>
                </div>

                <a class="btn btn-primary btn-block" 
   href="/m/index.php" 
   role="button" 
   style="font-weight:bold; margin-top:20px">
   <span class="glyphicon glyphicon-menu-left"></span> Kembali
</a>

 <script>
   $(document).ready(function() {
    getReferal(1, 'j');
});
                    
// Fungsi copy dan tampilkan toast
function copyReferral() {
    var copyText = document.getElementById("refLink").innerText;

    var tempInput = document.createElement("input");
    tempInput.value = copyText;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand("copy");
    document.body.removeChild(tempInput);

    // Tampilkan toast
    var toast = document.getElementById("toast");
    toast.classList.add("show");
    setTimeout(function() {
        toast.classList.remove("show");
    }, 2000); // toast hilang setelah 2 detik
}

</script>



                


    <?php require_once "../app/footer.php" ?>






</body>

</html>
<?php } ?>