<?php include 'header.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
<script type="text/javascript">
    
function sikayetUpdate(sikayet_id,type){


var url = "api.php";
    var bilgi = {
        type: 'sikayetUpdate',
        sikayet_id: sikayet_id,
        islemType: type
    }

    $.post(url, bilgi, function(response) {
        var json = JSON.parse(response);
        if (json.result == "1") {

                  Swal.fire({
                                        type: 'success',
                                        title: 'Başarılı!',
                                        html: 'İşlem Tamamlandı.',
                                        confirmButtonText: 'Tamam'
                                    }).then((result) => {
                                        if (result.value) {

                                            location.reload();

                                        }
                                    })

        }
    });


}

</script>

<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">
<div class="row">
                    <div id="recent-transactions" class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Şikayet Edilen Profiller</h4>
                                <a class="heading-elements-toggle"><i class="la la-ellipsis-v font-medium-3"></i></a>

                            </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">ID</th>
                                                <th class="border-top-0">Taraflar</th>
                                                <th class="border-top-0">Sebep</th>
                                             <!--    <th class="border-top-0">Açıklama</th> -->
                                                <th class="border-top-0">Tarih</th>
                                                <th class="border-top-0">Durum</th>
                                                <th class="border-top-0">İşlem</th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php

// OPTIMIZE EDİLDİ: JOIN ile tek sorgu - 2N sorgu yerine 1 sorgu!
$query = $db->query("
    SELECT 
        s.*,
        u_from.user_fullname as u_from_fullname,
        u_from.user_picture as u_from_picture,
        u_to.user_fullname as u_to_fullname,
        u_to.user_picture as u_to_picture,
        u_to.user_bot as u_to_bot
    FROM sikayetler s
    LEFT JOIN kullanicilar u_from ON s.u_from = u_from.user_id
    LEFT JOIN kullanicilar u_to ON s.u_to = u_to.user_id
    ORDER BY s.id DESC
", PDO::FETCH_ASSOC);

foreach ($query as $veri) {

// Bot şikayetlerini atla
if($veri['u_to_bot'] == 1){
    continue;
}

$tooltip = 'data-toggle="tooltip" data-placement="left"
                    title="'.$veri['comment'].'"';

if($veri['status']==0){
    $durum = '<span '.$tooltip.' class="badge badge-info">Bekliyor</span>';
}elseif($veri['status']==1){
    $durum = '<span '.$tooltip.' class="badge badge-success">Sonuçlandı</span>';
}elseif($veri['status']==2){
    $durum = '<span '.$tooltip.' class="badge badge-danger">Hesap Yasaklandı</span>';
}elseif($veri['status']==3){
    $durum = '<span '.$tooltip.' class="badge badge-warning">Resim Kaldırıldı</span>';
}


if($veri['type']=="spam"){
    $sitype = "Şüpheli veya Spam";
}elseif($veri['type']=="taklit"){
    $sitype = "Taklit Hesap";
}elseif($veri['type']=="taciz"){
    $sitype = "Taciz veya Nefret";
}elseif($veri['type']=="diger"){
    $sitype = "Diğer";
}

?>
<tr>
    <td class="text-truncate p-2">
                                                    
                                                    <span><i class="la la-dot-circle-o success font-medium-1"></i> <b><?=$veri['id']?></b></span>
                                                </td>



                                                <td class="text-truncate p-1">

                                                   <div class="d-flex align-items-center">



                                    <div class="chat-sidebar-name">
                                        <h6 class="mb-0"><b><a style="color: inherit; text-decoration: none;" target="_blank" href="../profil.php?id=<?=$veri['u_from']?>"><?=$veri['u_from_fullname']?></a></h6><span class="text-muted"><a style="color: inherit; text-decoration: none;" target="_blank" href="../profil.php?id=<?=$veri['u_to']?>"><?=$veri['u_to_fullname']?></a></b></span>
                                    </div>
                                </div>
                                                </td>

                                                <td class="text-truncate p-2">
                                                    <?=$sitype?>                                               </td>
                                          <!--       <td class="text-truncate p-2"><?=$veri['comment']?></td> -->
                                                
                                                 <td class="text-truncate p-2"><?=date('d.m.Y - H:i:s', $veri['zaman'])?></td>
                                                 <td class="text-truncate p-2"><?=$durum?></td>

                                                 <td class="text-truncate p-2">
                                                 <button class="btn btn-sm btn-info round dropdown-toggle" id="btnGroupDrop1" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="ft-settings icon-left"></i> İşlemler</button>
                        <div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
                            <a class="dropdown-item" onclick="sikayetUpdate(<?=$veri['id']?>,1);" href="javascript:void(0)">Hesabı Yasakla</a>
                            <a class="dropdown-item" onclick="sikayetUpdate(<?=$veri['id']?>,2);" href="javascript:void(0)">Profil Resmi Kaldır</a>
                            <a class="dropdown-item" onclick="sikayetUpdate(<?=$veri['id']?>,3);" href="javascript:void(0);">İşlem Yapma</a>
                            <!-- <a class="dropdown-item" onclick="banla(<?=$veri['user_id']?>);" href="javascript:void(0)">Yasakla</a></div></td> -->

<!--                                                 <td class="text-truncate p-2">
                                                    <span class="badge badge-success">Ödendi</span>    
                                                </td> -->

                                               
                                            </tr>


                                            <?php

                                        }

                                        ?>
                                               
                                  
                                                                                    </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                  </div>   </div>   </div>   </div>

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