<?php include 'header.php';
include 'detaylar.php';
 ?> 


<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-database.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
<script type="text/javascript">
    
  var firebaseConfig = {
   apiKey: "AIzaSyAX6glbRFOQ7IS-k9VPx6eeum-fvBtXdrk",
    authDomain: "hupvo-app-b2674.firebaseapp.com",
    projectId: "hupvo-app-b2674",
    storageBucket: "hupvo-app-b2674.appspot.com",
    messagingSenderId: "968466563284",
    appId: "1:968466563284:web:67387d40a67294f736bb41"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();


// firebase'e insert ediyoruz
function aramaGonder(gonderici_id, user_id) {

    const database = firebase.database();
    const ref = database.ref('aramalar');

    var sezerref = ref.child("arama_" + user_id);
    var x = sezerref.set({
        gonderici: gonderici_id,
        alici: user_id,
        msj: "arama"
    });

    var useridx = parseInt(user_id);
    var gondericiidx = parseInt(gonderici_id);

    
    setTimeout(function() {
        sezerref.remove();
    }, 500);

}

$(document).ready(function() {

    randUser('aktif');
    randUser('jetonlu');
    randUser('normal');

    var oncekiVeriler = {
        bugunKazanc: '<?=number_format($bugunKazanc, 2, '.', '')?>',
        bugunUye: '',
        genelUye: ''
    };

    // Satış yapıldığında ses oynatmak için ses dosyasını tanımla
    var notificationSound = new Audio('mixkit-software-interface-remove-2576.wav'); // Ses dosyasının yolunu buraya ekleyin

    // Satış yapıldığını belirten bir bayrak
    var satisYapildi = false;

    // Her 2 saniyede bir AJAX isteği gönder
    setInterval(function () {
        $.post('bk.php', function (response) {
            var data = response;

            // Eğer gelen veri bir önceki veri ile aynı değilse ve değişiklik varsa
            if (data.bugunKazanc !== oncekiVeriler.bugunKazanc) {
                // Yeni veriyi uygun olan div'e yerleştir
                $('#bkid').html(data.bugunKazanc);

                // Değişiklik olduğunu belirtmek için bir alert göster
                Swal.fire({
                    type: 'success',
                    title: 'Satış Var!',
                    html: 'Yeni Bir Satış Geldi!',
                    confirmButtonText: 'Tamam'
                }).then((result) => {
                    if (result.value) {
                        //location.reload();
                    }
                });

                // Ses dosyasını oynat
                notificationSound.play();

                // Önceki veriyi güncelle
                oncekiVeriler.bugunKazanc = data.bugunKazanc;

                // Satış yapıldı bayrağını true yap
                satisYapildi = true;

                // Satış yapıldı bayrağı false ise ve farklı sekmede isen (!) ekleyerek title'ı güncelle
                if (satisYapildi) {
                    document.title = '(!) ' + document.title;
                    satisYapildi = false; // Satış yapıldı bayrağını sıfırla
                }
            } 

            // Sayfa görünürlüğü değiştiğinde (!) işaretini kaldır
            document.addEventListener("visibilitychange", function () {
                // Sayfa görünür olduğunda (!) işareti kaldır
                document.title = document.title.replace('(!) ', '');
            });

            // Diğer verileri de güncelle
            $('#bugunid').html(data.bugunUye);
            $('#genelid').html(data.genelUye);
            $('#aktifid').html(data.randomAktifSayi);
        }, 'json'); // response'ı JSON formatında bekliyoruz
    }, 2500);
});

</script> 

<style type="text/css">
    
    @media only screen and (max-width: 760px) {
  .gzl { display: none; }
}

</style>
  <!-- BEGIN: Content-->
    <div class="app-content container center-layout mt-2">
        <div class="content-overlay"></div>
        <div class="content-wrapper">
            <div class="content-header row">
            </div>
            <div class="content-body">




                <!-- eCommerce statistic -->
                <div class="row">
                    <div class="col-xl-3 col-lg-6 col-12">
                        <div class="card pull-up">
                            <div class="card-content">
                                <div class="card-body">
                                    <div class="media d-flex">
                                        <div class="media-body text-left">
                                            <h3 class="info" style="font-size:1.41rem;"><a href="satislar.php">Bugün: <c id="bkid"><?=number_format($bugunKazanc, 2, '.', '')?></c> TL</a></h3>
                                            <h6>Dün: <?=number_format($dunKazanc, 2, '.', '')?> TL</h6>
                                        </div>
                                        <div>
                                            <i class="icon-basket-loaded info font-large-2 float-right"></i>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm mt-1 mb-0 box-shadow-2">
                                        <div class="progress-bar bg-gradient-x-info" role="progressbar" style="width: 80%" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-xl-3 col-lg-6 col-12">
                        <div class="card pull-up">
                            <div class="card-content">
                                <div class="card-body">
                                    <div class="media d-flex">
                                        <div class="media-body text-left">
                                            <h3 class="success"><a style="color: #28d094 !important;" href="uyeler.php"><c id="genelid"><?=$toplamUser?></c> Üye</a></h3>
                                            <h6><c id="bugunid"><?=$bugunUser?></c> Bugün Kaydolan</h6>
                                        </div>
                                        <div>
                                            <i class="icon-user-follow success font-large-2 float-right"></i>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm mt-1 mb-0 box-shadow-2">
                                        <div class="progress-bar bg-gradient-x-success" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="gzl col-xl-3 col-lg-6 col-12">
                        <div class="card pull-up">
                            <div class="card-content">
                                <div class="card-body">
                                    <div class="media d-flex">
                                        <div class="media-body text-left">
                                            <h3 class="warning"><a style="color: #ff9149 !important;" href="uyeler.php">Dünkü Üyeler</a></h3>
                                            <h6><?=$dunUser?> Dün Kaydolan</h6>
                                        </div>
                                        <div>
                                            <i class="icon-envelope warning font-large-2 float-right"></i>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm mt-1 mb-0 box-shadow-2">
                                        <div class="progress-bar bg-gradient-x-warning" role="progressbar" style="width: 65%" aria-valuenow="65" aria-valuemin="0" aria-valuemax="100"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="gzl col-xl-3 col-lg-6 col-12">
                        <div class="card pull-up">
                            <div class="card-content">
                                <div class="card-body">
                                    <div class="media d-flex">
                                        <div class="media-body text-left">
                                            <h3 class="danger"><?=$botUser?></h3>
                                            <h6>Toplam Bot Sayısı</h6>
                                        </div>
                                        <div>
                                            <i class="icon-ghost danger font-large-2 float-right"></i>
                                        </div>
                                    </div>
                                    <div class="progress progress-sm mt-1 mb-0 box-shadow-2">
                                        <div class="progress-bar bg-gradient-x-danger" role="progressbar" style="width: 85%" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ eCommerce statistic -->


                <!-- Products sell and New Orders -->
                <div class="row">
                    <div class="col-xl-4 col-lg-12">
                        <div class="card">
                            <div class="card-header mb-0">
                                <h4 class="card-title">Rastgele Aktif Üye (<c id="aktifid"><?=$randomsayisi?></c>)</h4>
                                <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
                                <div class="heading-elements">
                                    <ul class="list-inline mb-0">
                                        <li><a onclick="topluArama();"><i class="ft-phone"></i></a></li>
                                        <li><a onclick="randUser('aktif')"><i class="ft-rotate-cw"></i></a></li>
                                        <li><a data-action="close"><i class="ft-x"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="card-content collapse show">
                                <div class="card-body py-0 px-0">
                                    <div class="list-group" id="aktif">
                                        <center><img src="3loading.gif"></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="gzl col-xl-4 col-lg-12">
                        <div class="card">
                            <div class="card-header mb-0">
                                <h4 class="card-title">Rastgele Jetonlu Üye</h4>
                                <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
                                <div class="heading-elements">
                                    <ul class="list-inline mb-0">
                                        <li><a data-action="collapse"><i class="ft-minus"></i></a></li>
                                        <li><a onclick="randUser('jetonlu')"><i class="ft-rotate-cw"></i></a></li>
                                        <li><a data-action="close"><i class="ft-x"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="card-content collapse show">
                                <div class="card-body py-0 px-0">
                                    <div class="list-group" id="jetonlu">
                                        <center><img src="3loading.gif"></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="gzl col-xl-4 col-lg-12">
                        <div class="card">
                            <div class="card-header mb-0">
                                <h4 class="card-title">Rastgele Normal Üye</h4>
                                <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
                                <div class="heading-elements">
                                    <ul class="list-inline mb-0">
                                        <li><a data-action="collapse"><i class="ft-minus"></i></a></li>
                                        <li><a onclick="randUser('normal')"><i class="ft-rotate-cw"></i></a></li>
                                        <li><a data-action="close"><i class="ft-x"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="card-content collapse show">
                                <div class="card-body py-0 px-0">
                                    <div class="list-group" id="normal">
                                        <center><img src="3loading.gif"></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Products sell and New Orders -->

                <!-- Recent Transactions -->
                <div class="row">
                    <div id="recent-transactions" class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Kaydolan Son 25 Üye</h4>
                                <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>
                                <div class="heading-elements">
                                    <ul class="list-inline mb-0">
                                        <li><a class="btn btn-sm btn-danger box-shadow-2 round btn-min-width pull-right" href="uyeler.php" target="_blank">Tüm Üyeler</a></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="card-content">
                                <div class="table-responsive">
                                    <table id="recent-orders" class="table table-hover table-xl mb-0">
                                        <thead>
                                            <tr>
                                                <th class="border-top-0">Üye ID</th>
                                                <th class="border-top-0">İsim Soyisim</th>
                                                <th class="border-top-0">Kayıt Tarihi</th>
                                                <th class="border-top-0">Jeton Sayısı</th>
                                                <th class="border-top-0">İşlem</th>
                                            </tr>
                                        </thead>
                                        <tbody>

<?php

$query = $db->query("SELECT * FROM kullanicilar WHERE user_bot = 0 AND user_sehir <> '' AND user_cinsiyet = 'erkek' AND user_deaktif = 0 ORDER BY id DESC LIMIT 25", PDO::FETCH_ASSOC);

foreach ($query as $veri) {

if($veri['user_call']!=0){
    $aramapaket = 'style="border: 3px solid #00FF00;"';
}else{
    $aramapaket = '';
}

if($veri['user_regtype']=="google"){
    $regt = '<span class="badge badge-warning">G</span>';
}else{
    $regt = '<span class="badge badge-info">M</span>';
}

echo '<tr>
    <td class="text-truncate p-2"><i class="la la-dot-circle-o success font-medium-1 mr-1"></i> '.$veri['user_id'].'</td>
    <td class="text-truncate p-1">
        <div class="d-flex align-items-center">
            <div class="avatar m-0 mr-50" '.$aramapaket.'><img src="/'.$veri['user_picture'].'" height="36" width="36" alt="sidebar user image">
                <span class="avatar-status-online"></span>
            </div>
            <div class="chat-sidebar-name">
                <h6 class="mb-0">'.$veri['user_fullname'].' '.$regt.'</h6><span class="text-muted">'.$veri['user_email'].'</span>
            </div>
        </div>
    </td>
    <td class="text-truncate p-1">
        '.date('d.m.Y - H:i:s', $veri['user_kayit']).'
        <br/>
        Son Aktivite: '.date('H:i:s', $veri['user_songiris']).'
    </td>
    <td class="p-2">
        <button type="button" class="btn btn-sm btn-outline-warning round">'.$veri['user_jeton'].' Jeton</button>
    </td>
    <td class="p-2">
        <button type="button" onclick="tekil_mesaj_bot('.$veri['user_id'].')" data-toggle="modal" data-target="#bootstrap" class="btn btn-sm btn-outline-info round">Mesaj Yaz</button>
    </td>
</tr>';

}

?>

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Recent Transactions -->
            </div>
        </div>
    </div>
    <!-- END: Content-->


    <div class="sidenav-overlay"></div>
    <div class="drag-target"></div>


    <?php include 'footer.php'; ?>