<?php
session_start();

if( !isset($_SESSION["admin_login"])){
    header("Location: ../login/login.php");
}

require '../functions.php';

?>

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    <link rel="stylesheet" href="admin.css">

    <!-- my font -->
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

    <title>villahayati.</title>
</head>
<body>
    <!-- navbar -->
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a class="navbar-brand" href="#"><span class="stay">villa</span>hayati.</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
                    <div class="navbar-nav ml-auto">
                    <a class="nav-link active" href="update.php">Edit villa</a>
                    <a class="nav-link" href="approval.php">Payment Check</a>
                    <a class="nav-link" href="paymentLog.php">Payment Log</a>
                    <a class="nav-link" href="bookLog.php">Book Log</a>
                    <a href="../logout.php" class="btn btn-danger ml-5">Logout</a>
                </div>
            </div>
        </div>
    </nav>
    <!-- end of navbar -->


    <!-- villa table -->
    <section class="villa">
        <div class="container">
            <div class="row mt-5">
                <div class="col-md-12">
                    <h4>Booking Data Center</h4>
                    <p class="sub">Menampilkan Data Sesuai Rentang Tanggal</p>
                </div>
            </div>
            <div class="row mt-0">    
                <div class="col-md-12 ">
                <form method="post">
                        <td>
                            <td>Dari Tanggal  </td>
                            <td><input type="date" name="dari_tgl" required="required"></td>
                            <td>  Sampai Tanggal  </td>
                            <td><input type="date" name="sampai_tgl" required="required"></td>
                            <td><input type="submit" class="btn btn-primary" name="filter" value="filter"></td>
                            <br></br>
                        </td>
                        <?php
            if (isset ($_POST['filter'])) {
                $dari_tgl = mysqli_real_escape_string($conn, $_POST['dari_tgl']);
                $sampai_tgl = mysqli_real_escape_string($conn, $_POST['sampai_tgl']);
                echo "Data Booking Dari Tanggal " .$dari_tgl. " Sampai Tanggal " .$sampai_tgl;
            }
            ?>
            <?php
                        $i = 1;
                        if (isset($_POST['filter'])) {
                            $dari_tgl = mysqli_real_escape_string($conn, $_POST['dari_tgl']);
                            $sampai_tgl = mysqli_real_escape_string($conn, $_POST['sampai_tgl']);
                            $book_log = mysqli_query($conn,"SELECT * tb_booklog.nama, tb_booklog.email, tb_booklog.nomer, tb_booklog.tanggal_pesan, tb_booklog.tanggal_pulang FROM tb_booklog WHERE tanggal_pesan BETWEEN '$dari_tgl' AND '$sampai_tgl' JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id");
                            $url_cetak = "print.php?dari_tgl=".$dari_tgl."&sampai_tgl=".$sampai_tgl;
                        }else{
                            $book_log = mysqli_query($conn, "SELECT * tb_booklog.nama, tb_booklog.email, tb_booklog.nomer, tb_booklog.tanggal_pesan, tb_booklog.tanggal_pulang FROM tb_booklog JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id");
                            $url_cetak = "print.php";
                        }
                        while ($book = mysqli_fetch_array($book_log)) {
                        ?> 
                        <?php } ?>
            <div style="margin-top: 2px;">
            <a href="<?php echo $url_cetak ?>">CETAK PDF</a>
            </div>
                </div>
            </div>
            
            <div class="row mb-5">
                <div class="col-md-12">
                    <table class="table table-striped table-hover">
                        <thead class="thead-dark text-center">
                            <tr>
                                <th scope="col">No.</th>
                                <th scope="col">Name</th>
                                <th scope="col">Email</th>
                                <th scope="col">Phone Number</th>
                                <th scope="col">Check-in</th>
                                <th scope="col">Check-out</th>
                                <th scope="col">Jumlah Bayar</th>
                                <!-- <th scope="col">villa Id</th> -->
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        $i = 1;
                        if (isset($_POST['filter'])) {
                            $dari_tgl = mysqli_real_escape_string($conn, $_POST['dari_tgl']);
                            $sampai_tgl = mysqli_real_escape_string($conn, $_POST['sampai_tgl']);
                            $book_log = mysqli_query($conn,"SELECT * tb_booklog.nama, tb_booklog.email, tb_booklog.nomer, tb_booklog.tanggal_pesan, tb_booklog.tanggal_pulang FROM tb_booklog WHERE tanggal_pesan BETWEEN '$dari_tgl' AND '$sampai_tgl' JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id");
                            $url_cetak = "print.php?dari_tgl=".$dari_tgl."&sampai_tgl=".$sampai_tgl;
                        }else{
                            $book_log = mysqli_query($conn, "SELECT * tb_booklog.nama, tb_booklog.email, tb_booklog.nomer, tb_booklog.tanggal_pesan, tb_booklog.tanggal_pulang FROM tb_booklog JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id");
                            $url_cetak = "print.php";
                        }
                        while ($book = mysqli_fetch_array($book_log)) {
                        ?> 
                            <tr>
                                <th class="text-center" scope="row"><?= $i++; ?></th>
                                <td class="text-center"><?= $book["nama"] ?></td>
                                <td class="text-center"><?= $book["email"] ?></td>
                                <td class="text-center"><?= $book["nomer"] ?></td>
                                <td class="text-center"><?= $book["tanggal_pesan"] ?></td>
                                <td class="text-center"><?= $book["tanggal_pulang"] ?></td>
                                <td class="text-center"><?= $book["jumlah_bayar"] ?></td>
                                
                            </tr>
                        <?php } ?>
                       
                        </tbody>
                    </table>
                </div>
            </div>
        </div>        
    </section>
    <!-- end of table -->

    

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <!-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> -->

    <!-- Option 2: jQuery, Popper.js, and Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
</body>
</html>
