<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include 'inc/navbar.php';?>

<?php
$tarih          =   date("Y-m-d H:i:s");
$sontarih=date('Y-m-d 23:59:59', strtotime($tarih . "-30 days" ));
$log_sil = $dbh->prepare("DELETE FROM visitor_tracking WHERE timestamp < ?");
$log_sil->execute([$sontarih]);


?>

<div class="modal fade" id="exampleModalDanger" tabindex="-1" role="dialog" aria-labelledby="exampleModalDanger" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header bg-danger">
                <h6 class="modal-title m-0 text-white" id="exampleModalDanger">Toplu Silme İşlemi</h6>
                <button type="button" class="close " data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true"><i class="la la-times text-white"></i></span>
                </button>
            </div><!--end modal-header-->
            <div class="modal-body">
                <div class="row"> 
                    <div class="col-lg-12">
                        <h5>Ziyaretçi kayıtlarında yer alan tüm kayıtları silmek üzeresiniz bu işlemi yapmak istiyormusunuz ?</h5>

                        <ul class="mt-3 mb-0">
                            <li>Bu veri silinirse geri döndürülemez.</li> 
                        </ul>
                    </div><!--end col-->
                </div><!--end row-->                                                     
            </div><!--end modal-body-->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Kapat</button>
                <a href="islem.php?islem=ziyaretci-sil"><button type="button" class="btn btn-danger btn-sm">Evet, Sil</button></a>
            </div><!--end modal-footer-->
        </div><!--end modal-content-->
    </div><!--end modal-dialog-->
</div><!--end modal-->
<!-- Page Content-->
<div class="page-content">
    <div class="container-fluid">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="page-title-box">
                    <div class="row">
                        <div class="col">
                            <h4 class="page-title">Ziyaretçi Kayıtları</h4>
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="index.php">Anasayfa</a></li> 
                                <li class="breadcrumb-item active">Ziyaretçi Kayıtları</li>
                            </ol>
                        </div><!--end col--> 
                        <div class="col-auto align-self-center"> 
                            <button type="button" class="btn btn-outline-primary waves-effect waves-light" data-toggle="modal" data-target="#exampleModalDanger"> <i data-feather="alert-octagon"></i></i> Tümünü Sil</button>   
                        </div>
                    </div><!--end row-->                                                              
                </div><!--end page-title-box-->
            </div><!--end col-->
        </div><!--end row-->
        <!-- end page title end breadcrumb -->

        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">Ziyaretçi Kayıtları</h4>
                        <p class="text-muted mb-0">Değerli kullanıcı, bu alan sayesinde sitenize giren herkezi kayıt altına alabilir ve inceleme fırsatı yakalabilirsiniz.
                        </p>
                    </div><!--end card-header-->
                    <style type="text/css">
                        i {
                            color:#fff;
                            font-size: 16px;
                        }
                    </style>
                    <div class="card-body">  
                        <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;"> 
                            <thead>
                                <tr>
                                    <th>#</th> 
                                    <th>Ziyaretçi Kimlik No</th>
                                    <th>İp Adresi</th>
                                    <th>Ziyaret Ettiği Sayfa</th> 
                                    <th>Tarih</th> 
                                </tr>
                            </thead>


                            <tbody>
                               <?php
                               $ebultensorgu = $dbh->prepare("SELECT * FROM visitor_tracking ORDER BY entry_id DESC ");
                               $ebultensorgu->execute();

                               while ($ebultensonuc = $ebultensorgu->fetch()) {

                                $entry_id = $ebultensonuc['entry_id'];
                                $visitor_id = $ebultensonuc['visitor_id']; 
                                $ip_address = $ebultensonuc['ip_address']; 
                                $page_name = $ebultensonuc['page_name'];
                                $date = $ebultensonuc['timestamp'];
                                $phpdate = strtotime( $date );
                                $mysqldate = date( 'd-m-Y h.i.s ', $phpdate ); 
                                ?>
                                <tr>
                                    <td ><?=$ebultensonuc['entry_id'];?></td> 
                                    <td >xxxxx</td> 
                                    <td ><?=$ebultensonuc['ip_address'];?></td> 
                                    <td ><?=$ebultensonuc['page_name'];?></td> 
                                    <td ><?=$mysqldate?></td>

                                </tr> 

                            <?php } ?> 
                        </tbody>
                    </table>        
                </div>
            </div>
        </div> <!-- end col -->
    </div> <!-- end row -->



</div><!-- container -->

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